Bug 1220564 - Update and remove obsolete JS reftests. (r=Waldo)

This commit is contained in:
Shu-yu Guo 2016-01-06 16:02:15 -08:00
Родитель fee40646f2
Коммит f7ec8ae7a3
60 изменённых файлов: 42 добавлений и 2431 удалений

Просмотреть файл

@ -1,27 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 352009;
var summary = 'Do not assert [1 for (y in [3])]';
var actual = 'No Crash';
var expect = 'No Crash';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
[1 for (y in [3])];
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,36 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 350417;
var summary = 'Do not crash decompiling "is not function" msg';
var actual = 'No Crash';
var expect = 'No Crash';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
expect = 'TypeError: [] is not a function';
try
{
eval('y = {}; (y.a = [2 for each (p in [])])();');
}
catch(ex)
{
actual = ex + '';
}
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,26 +0,0 @@
// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 475144;
var summary = 'TM: Do not assert: !JS_ON_TRACE(cx)';
var actual = '';
var expect = '';
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
function a() {}
function b() {}
function c() {}
eval("this.__defineGetter__(\"\", function(){ return new Function } )");
[[].some for each (x in this) for each (y in /x/g)];
jit(false);
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,27 +0,0 @@
// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 455982;
var summary = 'Do not assert with JIT: with generator as getter';
var actual = 'No Crash';
var expect = 'No Crash';
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
for (let i=0;i<5;++i)
this["y" + i] = (function(){});
this.__defineGetter__('e', function (x2) { yield; });
[1 for each (a in this) for (b in {})];
jit(false);
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,27 +0,0 @@
// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 455982;
var summary = 'Do not assert with JIT: with generator as getter';
var actual = 'No Crash';
var expect = 'No Crash';
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
for (let i=0;i<5;++i)
this["y" + i] = (function(){});
this.__defineGetter__('e', function (x2) { yield; });
[1 for each (a in this) for (b in {p:1,q:2,r:3})];
jit(false);
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,26 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = "(none)";
var summary = "Array comprehensions evens example from http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7"
var actual, expect;
printBugNumber(BUGNUMBER);
printStatus(summary);
/**************
* BEGIN TEST *
**************/
function range(begin, end) {
for (let i = begin; i < end; ++i) {
yield i;
}
}
var evens = [i for (i in range(0, 21)) if (i % 2 == 0)];
reportCompare("object", typeof evens, summary);
reportCompare("0,2,4,6,8,10,12,14,16,18,20", "" + evens, summary);

Просмотреть файл

@ -1,52 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 345736;
var summary = 'for each in array comprehensions';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
var arr;
arr=[x+x for (x in ["a","b","c"])];
expect = '00,11,22';
actual = arr.toString();
reportCompare(expect, actual, summary);
arr=[x+x for each (x in ["a","b","c"])];
expect = 'aa,bb,cc';
actual = arr.toString();
reportCompare(expect, actual, summary);
// Before JS1.7's destructuring for…in was fixed to match JS1.8's,
// the expected result was 'aa,bb,cc'.
arr=[x+x for ([,x] in ["a","b","c"])];
expect = 'NaN,NaN,NaN';
actual = arr.toString();
reportCompare(expect, actual, summary);
// Before JS1.7's destructuring for…in was fixed to match JS1.8's,
// the expected result was '0a,1b,2c'.
arr=[x+y for ([x,y] in ["a","b","c"])];
expect = '0undefined,1undefined,2undefined';
actual = arr.toString();
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,36 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 412467;
var summary = 'Iterator values in array comprehension';
var actual = '';
var expect = 'typeof(iterand) == undefined, ';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
function g() { yield 1; yield 2; }
var a = [iterand for (iterand in g())];
expect = true;
actual = typeof iterand == 'undefined';
reportCompare(expect, actual, summary + ': typeof iterand == \'undefined\'');
expect = true;
actual = a.length == 2 && a.toString() == '1,2';
reportCompare(expect, actual, summary + ': a.length == 2 && a.toString() == \'1,2\'');
exitFunc ('test');
}

Просмотреть файл

@ -1,28 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 428706;
var summary = 'Do not assert: regs.sp < vp';
var actual = 'No Crash';
var expect = 'No Crash';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
[1 for ([,,] in [])];
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,32 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 461235;
var summary = 'Do not assert: pos == GET_UINT16(pc)';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
print(function() { [1 for (b in [])]; var c; });
jit(false);
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,32 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 461945;
var summary = 'Do not assert: !ti->stackTypeMap.matches(ti_other->stackTypeMap)';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
[1 for each (x in {a:1, b:1, c:"", d:"", e:1, f:"", g:""}) if (0)];
jit(false);
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,34 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 385393;
var summary = 'Regression test for bug 385393';
var actual = 'No Crash';
var expect = 'No Crash';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
try
{
[].map(1 for (x in []));
}
catch(ex)
{
}
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,34 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 385393;
var summary = 'Regression test for bug 385393';
var actual = 'No Crash';
var expect = 'No Crash';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
try
{
[1 for (x in [])].watch();
}
catch(ex)
{
}
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,35 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 385393;
var summary = 'Regression test for bug 385393';
var actual = 'No Crash';
var expect = 'No Crash';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
try
{
var n = null;
[1 for (x in [])](n.b());
}
catch(ex)
{
}
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,30 +0,0 @@
// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452476;
var summary = 'Do not assert with JIT: !cx->runningJittedCode';
var actual = 'No Crash';
var expect = 'No Crash';
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
for (var j = 0; j < 10; j++)
{
for (var i = 0; i < j; ++i)
this["n" + i] = 1;
this.__defineGetter__('w', (function(){}));
[1 for each (g in this) for each (t in /x/g)];
}
jit(false);
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,29 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 455973;
var summary = 'Do not assert: !cx->throwing';
var actual = '';
var expect = '';
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
try
{
for (let i = 0; i < 5; ++i) void (this["y" + i] = "");
this.__defineGetter__("z", function () { throw 2; });
for (let j = 0; j < 2; ++j) { [1 for each (q in this) if ('')]; }
}
catch(ex)
{
}
jit(false);
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,27 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributor:
* Jeff Walden <jwalden+code@mit.edu>
*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 721322;
var summary = 'Allow f.arguments in generator expressions';
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
eval("(function() { return (f.arguments for (x in [1])); })()");
eval("(function() { var f = { arguments: 12 }; return [f.arguments for (x in [1])]; })()");
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

Просмотреть файл

Просмотреть файл

@ -1,93 +0,0 @@
/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 349331;
var summary = 'generator.close without GeneratorExit';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
var catch1, catch2, catch3, finally1, finally2, finally3;
var iter;
function gen()
{
yield 1;
try {
try {
try {
yield 2;
} catch (e) {
catch1 = true;
} finally {
finally1 = true;
}
} catch (e) {
catch2 = true;
} finally {
finally2 = true;
}
} catch (e) {
catch3 = true;
} finally {
finally3 = true;
}
}
// test explicit close call
catch1 = catch2 = catch3 = finally1 = finally2 = finally3 = false;
iter = gen();
iter.next();
iter.next();
iter.close();
var passed = !catch1 && !catch2 && !catch3 && finally1 && finally2 &&
finally3;
if (!passed) {
print("Failed!");
print("catch1=" + catch1 + " catch2=" + catch2 + " catch3=" +
catch3);
print("finally1=" + finally1 + " finally2=" + finally2 +
" finally3=" + finally3);
}
reportCompare(true, passed, 'test explicit close call');
// test for-in invoked close
catch1 = catch2 = catch3 = finally1 = finally2 = finally3 = false;
iter = gen();
for (var i in iter) {
if (i == 2)
break;
}
var passed = !catch1 && !catch2 && !catch3 && finally1 && finally2 &&
finally3;
if (!passed) {
print("Failed!");
print("catch1=" + catch1 + " catch2=" + catch2 + " catch3=" +
catch3);
print("finally1=" + finally1 + " finally2=" + finally2 +
" finally3="+finally3);
}
reportCompare(true, passed, 'test GC-invoke close');
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,201 +0,0 @@
/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 380237;
var summary = 'Generator expressions - sudoku';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
if (this.version) version(180);
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Make arrays and strings act more like Python lists by iterating their values, not their keys.
Array.prototype.__iterator__ = String.prototype.__iterator__ = function () {
for (let i = 0; i < this.length; i++)
yield this[i]
}
// Containment testing for arrays and strings that should be coherent with their __iterator__.
Array.prototype.contains = String.prototype.contains = function (e) {
return this.indexOf(e) != -1
}
Array.prototype.repeat = String.prototype.repeat = function (n) {
let s = this.constructor()
for (let i = 0; i < n; i++)
s = s.concat(this)
return s
}
String.prototype.center = function (w) {
let n = this.length
if (w <= n)
return this
let m = Math.floor((w - n) / 2)
return ' '.repeat(m) + this + ' '.repeat(w - n - m)
}
Array.prototype.toString = Array.prototype.toSource
Object.prototype.toString = Object.prototype.toSource
// XXX thought spurred by the next two functions: array extras should default to identity function
function all(seq) {
for (let e in seq)
if (!e)
return false
return true
}
function some(seq) {
for (let e in seq)
if (e)
return e
return false
}
function cross(A, B) {
return [a+b for (a in A) for (b in B)]
}
function dict(A) {
let d = {}
for (let e in A)
d[e[0]] = e[1]
return d
}
function set(A) {
let s = []
for (let e in A)
if (!s.contains(e))
s.push(e)
return s
}
function zip(A, B) {
let z = []
let n = Math.min(A.length, B.length)
for (let i = 0; i < n; i++)
z.push([A[i], B[i]])
return z
}
rows = 'ABCDEFGHI'
cols = '123456789'
digits = '123456789'
squares = cross(rows, cols)
unitlist = [cross(rows, c) for (c in cols)]
.concat([cross(r, cols) for (r in rows)])
.concat([cross(rs, cs) for (rs in ['ABC','DEF','GHI']) for (cs in ['123','456','789'])])
units = dict([s, [u for (u in unitlist) if (u.contains(s))]]
for (s in squares))
peers = dict([s, set([s2 for (u in units[s]) for (s2 in u) if (s2 != s)])]
for (s in squares))
// Given a string of 81 digits (or . or 0 or -), return a dict of {cell:values}.
function parse_grid(grid) {
grid = [c for (c in grid) if ('0.-123456789'.contains(c))]
let values = dict([s, digits] for (s in squares))
for (let [s, d] in zip(squares, grid))
if (digits.contains(d) && !assign(values, s, d))
return false
return values
}
// Eliminate all the other values (except d) from values[s] and propagate.
function assign(values, s, d) {
if (all(eliminate(values, s, d2) for (d2 in values[s]) if (d2 != d)))
return values
return false
}
// Eliminate d from values[s]; propagate when values or places <= 2.
function eliminate(values, s, d) {
if (!values[s].contains(d))
return values // Already eliminated
values[s] = values[s].replace(d, '')
if (values[s].length == 0)
return false // Contradiction: removed last value
if (values[s].length == 1) {
// If there is only one value (d2) left in square, remove it from peers
let d2 = values[s][0]
if (!all(eliminate(values, s2, d2) for (s2 in peers[s])))
return false
}
// Now check the places where d appears in the units of s
for (let u in units[s]) {
let dplaces = [s for (s in u) if (values[s].contains(d))]
if (dplaces.length == 0)
return false
if (dplaces.length == 1)
// d can only be in one place in unit; assign it there
if (!assign(values, dplaces[0], d))
return false
}
return values
}
// Used for debugging.
function print_board(values) {
let width = 1 + Math.max.apply(Math, [values[s].length for (s in squares)])
let line = '\n' + ['-'.repeat(width*3)].repeat(3).join('+')
for (let r in rows)
print([values[r+c].center(width) + ('36'.contains(c) && '|' || '')
for (c in cols)].join('') + ('CF'.contains(r) && line || ''))
print('\n')
}
easy = "..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3.."
print_board(parse_grid(easy))
// Using depth-first search and constraint propagation, try all possible values.
function search(values) {
if (!values)
return false // Failed earlier
if (all(values[s].length == 1 for (s in squares)))
return values // Solved!
// Choose the unfilled square s with the fewest possibilities
// XXX Math.min etc. should work with generator expressions and other iterators
// XXX Math.min etc. should work on arrays (lists or tuples in Python) as well as numbers
let a = [values[s].length + s for (s in squares) if (values[s].length > 1)].sort()
let s = a[0].slice(-2)
return some(search(assign(values.copy(), s, d)) for (d in values[s]))
}
hard = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......'
print_board(search(parse_grid(hard)))
delete Object.prototype.copy;
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,30 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 380237;
var summary = 'Decompilation of generator expressions';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
var f = function() { g = (d for (d in [0])); g.next(); };
expect = 'function() { g = (d for (d in [0])); g.next(); }';
actual = f + '';
compareSource(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,295 +0,0 @@
// |reftest| skip -- obsolete test, need to remove minor failures to reenable.
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 380237;
var summary = 'Generator expressions parenthesization test';
var actual = '';
var expect = '';
/*
Given that parentheization seems so fragile *and* the rules for where
genexps are allowed keep changing, I thought it would be good to have
a way to test that:
1) unparenthesized genexps are allowed in some places and the
decompilation is sane and not over-parenthesized
2) unparenthesized genexps are disallowed in many places and when
there are parens, the decompilation is sane and not over-parenthesized
*/
// |genexp| must have the exact same whitespace the decompiler uses
genexp = "x * x for (x in [])";
genexpParened = "(" + genexp + ")";
genexpParenedTwice = "(" + genexpParened + ")";
// Warning: be careful not to put [] around stuff, because that would
// cause it to be treated as an array comprehension instead of a
// generator expression!
// Statements
doesNotNeedParens(1, "if (xx) { }");
needParens(2, "if (1, xx) { }");
needParens(3, "if (xx, 1) { }");
doesNotNeedParens(4, "do { } while (xx);");
doesNotNeedParens(5, "while (xx) { }");
doesNotNeedParens(6, "switch (xx) { }");
doesNotNeedParens(7, "with (xx) { }");
needParens(8, "switch (x) { case xx: }");
needParens(9, "return xx;");
needParens(10, "yield xx;");
needParens(11, "for (xx;;) { }");
needParens(12, "for (;xx;) { }", "function anonymous() {\n for (;;) {\n }\n}");
needParens(13, "for (;;xx) { }");
needParens(14, "for (i in xx) { }");
needParens(15, "throw xx");
needParens(16, "try { } catch (e if xx) { }");
// Function calls
doesNotNeedParens(19, "f(xx);");
needParens(20, "f(xx, 1);");
needParens(21, "f(1, xx);");
doesNotNeedParens(22, "/x/(xx);");
needParens(23, "/x/(xx, 1);");
needParens(24, "/x/(1, xx);");
// eval is special and often confuses the decompiler.
doesNotNeedParens(25, "eval(xx);");
needParens(26, "eval(xx, 1);");
needParens(27, "eval(1, xx);");
// Expressions
needParens(28, "xx;"); // ???
needParens(29, "var g = xx;"); // ???
needParens(30, "g += xx;");
needParens(31, "xx();");
needParens(32, "xx() = 3;");
needParens(33, "a ? xx : c");
needParens(34, "xx ? b : c");
needParens(35, "a ? b : xx");
needParens(36, "1 ? xx : c");
needParens(37, "0 ? b : xx");
needParens(38, "1 + xx");
needParens(39, "xx + 1");
needParens(40, "1, xx");
doesNotNeedParens(41, "+(xx)");
doesNotNeedParens(42, "!(xx)");
needParens(43, "xx, 1");
needParens(44, "[1, xx]");
needParens(45, "[xx, 1]");
needParens(46, "[xx,3]");
needParens(47, "[xx,null]");
needParens(48, "xx.p");
needParens(49, "xx.@p");
needParens(50, "typeof xx;");
needParens(51, "void xx;");
needParens(52, "({ a: xx })");
needParens(53, "({ a: 1, b: xx })");
needParens(54, "({ a: xx, b: 1 })");
needParens(55, "({ a getter: xx })");
needParens(56, "<x a={xx}/>");
doesNotNeedParens(57, "new (xx);");
doesNotNeedParens(58, "new a(xx);");
// Generator expressions cannot be used as LHS, even though they're syntactic
// sugar for something that looks a lot like an "lvalue return": (f() = 3).
rejectLHS(59, "++ (xx);");
rejectLHS(60, "delete xx;");
rejectLHS(61, "delete (xx);");
rejectLHS(62, "for (xx in []) { }");
rejectLHS(63, "for ((xx) in []) { }");
rejectLHS(64, "try { } catch(xx) { }");
rejectLHS(65, "try { } catch([(xx)]) { }");
rejectLHS(66, "xx += 3;");
rejectLHS(67, "(xx) += 3;");
rejectLHS(68, "xx = 3;");
// Assignment
rejectLHS(69, " (xx) = 3;");
rejectLHS(70, "var (xx) = 3;");
rejectLHS(71, "const (xx) = 3;");
rejectLHS(72, "let (xx) = 3;");
// Destructuring assignment
rejectLHS(73, " [(xx)] = 3;");
rejectLHS(74, "var [(xx)] = 3;");
rejectLHS(75, "const [(xx)] = 3;");
rejectLHS(76, "let [(xx)] = 3;");
// Group assignment (Spidermonkey optimization for certain
// destructuring assignments)
rejectLHS(77, " [(xx)] = [3];");
rejectLHS(78, "var [(xx)] = [3];");
rejectLHS(79, "const [(xx)] = [3];");
rejectLHS(80, "let [(xx)] = [3];");
// Destructuring & group assignment for array comprehensions, just for kicks.
rejectLHS(81, " [xx] = [3];");
rejectLHS(82, "var [xx] = [3];");
rejectLHS(83, "const [xx] = [3];");
rejectLHS(84, "let [xx] = 3;");
rejectLHS(85, " [xx] = 3;");
rejectLHS(86, "var [xx] = 3;");
rejectLHS(87, "const [xx] = 3;");
rejectLHS(88, "let [xx] = 3;");
// This is crazy, ambiguous, and/or buggy.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=380237#c23 et seq.
//doesNotNeedParens("(yield xx);");
print("Done!");
function doesNotNeedParens(section, pat)
{
print("Testing section " + section + " pattern " + pat);
var f, ft;
sanityCheck(section, pat);
expect = 'No Error';
actual = '';
ft = pat.replace(/xx/, genexp);
try {
f = new Function(ft);
actual = 'No Error';
} catch(e) {
print("Unparenthesized genexp SHOULD have been accepted here!");
actual = e + '';
}
reportCompare(expect, actual, summary + ': doesNotNeedParens section ' + section + ' pattern ' + pat);
roundTripTest(section, f);
// Make sure the decompilation is not over-parenthesized.
var uf = "" + f;
if (pat.indexOf("(xx)") != -1)
overParenTest(section, f);
// else
// print("Skipping the over-parenthesization test, because I don't know how to test for over-parenthesization when the pattern doesn't have parens snugly around it.")
}
function needParens(section, pat, exp)
{
print("Testing section " + section + " pattern " + pat);
var f, ft;
sanityCheck(section, pat);
expect = 'SyntaxError';
actual = '';
ft = pat.replace(/xx/, genexp);
try {
f = new Function(ft);
print("Unparenthesized genexp should NOT have been accepted here!");
} catch(e) {
/* expected to throw */
actual = e.name;
}
reportCompare(expect, actual, summary + ': needParens section ' + section + ' pattern ' + pat);
expect = 'No Error';
actual = '';
ft = pat.replace(/xx/, genexpParened);
try {
f = new Function(ft);
actual = 'No Error';
} catch(e) {
print("Yikes!");
actual = e + '';
}
reportCompare(expect, actual, summary + ': needParens section ' + section + ' ft ' + ft);
roundTripTest(section, f, exp);
overParenTest(section, f, exp);
}
function rejectLHS(section, pat)
{
print("Testing section " + section + " pattern " + pat);
// sanityCheck(pat); // because 'z' should be accepted as an LHS or binding
var ft;
expect = 'SyntaxError';
actual = '';
ft = pat.replace(/xx/, genexp)
try {
new Function(ft);
print("That should have been a syntax error!");
actual = 'No Error';
} catch(e) {
actual = e.name;
}
reportCompare(expect, actual, summary + ': rejectLHS section ' + section);
}
function overParenTest(section, f, exp)
{
var uf = "" + f;
if (uf == exp)
return;
reportCompare(false, uf.indexOf(genexpParened) == -1, summary +
': overParenTest genexp snugly in parentheses: section ' + section + ' uf ' + uf);
if (uf.indexOf(genexpParened) != -1) {
reportCompare(true, uf.indexOf(genexpParenedTwice) == -1, summary +
': overParensTest decompilation should not be over-parenthesized: section ' + ' uf ' + uf);
}
}
function sanityCheck(section, pat)
{
expect = '';
actual = '';
if (pat.indexOf("xx") == -1)
{
actual += "No 'xx' in this pattern? ";
}
var f, ft;
ft = pat.replace(/xx/, "z");
try {
f = new Function(ft);
} catch(e) {
actual += "Yowzers! Probably a bogus test!";
}
reportCompare(expect, actual, summary + ': sanityCheck section ' + section + ' pattern ' + pat);
}
function roundTripTest(section, f, exp)
{
// Decompile
var uf = "" + f;
// Recompile
expect = 'No Error';
actual = '';
var euf;
try {
euf = eval("(" + uf + ")");
actual = 'No Error';
reportCompare(expect, actual, summary + ': roundTripTest: section ' + section + ' uf ' + uf);
} catch(e) {
actual = e + '';
reportCompare(expect, actual, summary + ': roundTripTest: section ' + section + ' uf ' + uf);
return;
}
// Decompile again and make sure the decompilations match exactly.
expect = exp || uf;
actual = "" + euf;
reportCompare(expect, actual, summary + ': roundTripTest no round-trip change: section ' + section);
}

Просмотреть файл

@ -1,166 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 634472;
var summary = 'contextual restrictions for yield and arguments';
var actual = '';
var expect = '';
function error(str) {
let base;
try {
// the following line must not be broken up into multiple lines
base = (function(){try{eval('throw new Error()')}catch(e){return e.lineNumber}})(); eval(str);
return null;
} catch (e) {
e.lineNumber = e.lineNumber - base + 1;
return e;
}
}
const JSMSG_GENEXP_YIELD = error("(function(){((yield) for (x in []))})").message;
const JSMSG_TOP_YIELD = error("yield").message;
const JSMSG_YIELD_PAREN = error("(function(){yield, 1})").message;
const JSMSG_YIELD_FOR = error("(function(){yield for})").message;
const JSMSG_BAD_GENERATOR_SYNTAX = error("(1, x for (x in []))").message;
const cases = [
// yield expressions
{ expr: "yield", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield" },
{ expr: "yield 1", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg" },
{ expr: "1, yield", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list" },
{ expr: "1, yield 2", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list" },
{ expr: "yield, 1", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list" },
{ expr: "yield 1, 2", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list" },
{ expr: "(yield)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized" },
{ expr: "(yield 1)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized" },
{ expr: "(1, yield)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list, parenthesized" },
{ expr: "(1, yield 2)", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list, parenthesized" },
{ expr: "(yield, 1)", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list, parenthesized" },
{ expr: "(yield 1, 2)", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list, parenthesized" },
// deeply nested yield expressions
{ expr: "((((yield))))", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield" },
{ expr: "((((yield 1))))", top: JSMSG_TOP_YIELD, fun: null, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield w/ arg" },
// arguments
{ expr: "arguments", top: null, fun: null, gen: null, desc: "arguments in list" },
{ expr: "1, arguments", top: null, fun: null, gen: null, desc: "arguments in list" },
// yield in generator expressions
{ expr: "(yield for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_FOR, gen: JSMSG_YIELD_FOR, desc: "simple yield in genexp" },
{ expr: "(yield 1 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg in genexp" },
{ expr: "(yield, 1 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list in genexp" },
{ expr: "(yield 1, 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list in genexp" },
{ expr: "(1, yield for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_FOR, gen: JSMSG_YIELD_FOR, desc: "simple yield at end of list in genexp" },
{ expr: "(1, yield 2 for (x in []))", top: JSMSG_TOP_YIELD, fun: { simple: JSMSG_GENEXP_YIELD, call: JSMSG_GENEXP_YIELD },
gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list in genexp" },
{ expr: "((yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized in genexp" },
{ expr: "((yield 1) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized in genexp" },
{ expr: "(1, (yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield, parenthesized in list in genexp" },
{ expr: "(1, (yield 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg, parenthesized in list in genexp" },
{ expr: "((1, yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list, parenthesized in genexp" },
{ expr: "((1, yield 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list, parenthesized in genexp" },
{ expr: "(1, (2, yield) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "simple yield at end of list, parenthesized in list in genexp" },
{ expr: "(1, (2, yield 3) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "yield w/ arg at end of list, parenthesized in list in genexp" },
{ expr: "((yield, 1) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list, parenthesized in genexp" },
{ expr: "((yield 1, 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list, parenthesized in genexp" },
{ expr: "(1, (yield, 2) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "simple yield in list, parenthesized in list in genexp" },
{ expr: "(1, (yield 2, 3) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_YIELD_PAREN, gen: JSMSG_YIELD_PAREN, desc: "yield w/ arg in list, parenthesized in list in genexp" },
// deeply nested yield in generator expressions
{ expr: "((((1, yield 2))) for (x in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield in genexp" },
{ expr: "((((1, yield 2)) for (x in [])) for (y in []))", top: JSMSG_TOP_YIELD, fun: JSMSG_GENEXP_YIELD, gen: JSMSG_GENEXP_YIELD, desc: "deeply nested yield in multiple genexps" },
// arguments in generator expressions
{ expr: "(arguments for (x in []))", top: null, fun: null, gen: null, desc: "simple arguments in genexp" },
{ expr: "(1, arguments for (x in []))", top: JSMSG_BAD_GENERATOR_SYNTAX, fun: JSMSG_BAD_GENERATOR_SYNTAX, gen: JSMSG_BAD_GENERATOR_SYNTAX, desc: "arguments in list in genexp" },
{ expr: "((arguments) for (x in []))", top: null, fun: null, gen: null, desc: "arguments, parenthesized in genexp" },
{ expr: "(1, (arguments) for (x in []))", top: JSMSG_BAD_GENERATOR_SYNTAX, fun: JSMSG_BAD_GENERATOR_SYNTAX, gen: JSMSG_BAD_GENERATOR_SYNTAX, desc: "arguments, parenthesized in list in genexp" },
{ expr: "((1, arguments) for (x in []))", top: null, fun: null, gen: null, desc: "arguments in list, parenthesized in genexp" },
{ expr: "(1, (2, arguments) for (x in []))", top: JSMSG_BAD_GENERATOR_SYNTAX, fun: JSMSG_BAD_GENERATOR_SYNTAX, gen: JSMSG_BAD_GENERATOR_SYNTAX, desc: "arguments in list, parenthesized in list in genexp" },
// deeply nested arguments in generator expressions
{ expr: "((((1, arguments))) for (x in []))", top: null, fun: null, gen: null, desc: "deeply nested arguments in genexp" },
{ expr: "((((1, arguments)) for (x in [])) for (y in []))", top: null, fun: null, gen: null, desc: "deeply nested arguments in multiple genexps" },
// legal yield/arguments in nested function
{ expr: "((function() { yield }) for (x in []))", top: null, fun: null, gen: null, desc: "legal yield in nested function" },
{ expr: "((function() { arguments }) for (x in []))", top: null, fun: null, gen: null, desc: "legal arguments in nested function" },
{ expr: "((function() arguments) for (x in []))", top: null, fun: null, gen: null, desc: "legal arguments in nested expression-closure" }
];
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function splitKeyword(str) {
return str.
replace(/yield for/, '\nyield for\n').
replace(/yield ([0-9])/, '\nyield $1\n').
replace(/yield([^ ]|$)/, '\nyield\n$1').
replace(/arguments/, '\narguments\n');
}
function expectError1(err, ctx, msg) {
reportCompare('object', typeof err, 'exn for: ' + msg);
reportCompare(ctx, err.message, 'exn message for: ' + msg);
if (ctx !== JSMSG_BAD_GENERATOR_SYNTAX)
reportCompare(2, err.lineNumber, 'exn token for: ' + msg);
}
function expectError(expr, call, wrapCtx, expect, msg) {
let exps = (typeof expect === "string")
? { simple: expect, call: expect }
: expect;
expectError1(error(wrapCtx(expr)), exps.simple, msg);
if (call)
expectError1(error(wrapCtx(call)), exps.call, 'call argument in ' + msg);
}
function expectSuccess(err, msg) {
reportCompare(null, err, 'parse: ' + msg);
}
function atTop(str) { return str }
function inFun(str) { return '(function(){' + str + '})' }
function inGen(str) { return '(y for (y in ' + str + '))' }
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
for (let i = 0, len = cases.length; i < len; i++) {
let {expr, top, fun, gen, desc} = cases[i];
let call = (expr[0] === "(") ? ("print" + expr) : null;
expr = splitKeyword(expr);
if (call)
call = splitKeyword(call);
if (top)
expectError(expr, call, atTop, top, 'top-level context, ' + desc);
else
expectSuccess(error(expr), 'top-level context, ' + desc);
if (fun)
expectError(expr, call, inFun, fun, 'function context, ' + desc);
else
expectSuccess(error(inFun(expr)), 'function context, ' + desc);
if (gen)
expectError(expr, call, inGen, gen, 'genexp context, ' + desc);
else
expectSuccess(error(inGen(expr)), 'genexp context, ' + desc);
}
exitFunc ('test');
}

Просмотреть файл

@ -1,18 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 665286;
var summary = 'yield in comprehension RHS';
var actual = '';
var expect = '';
function reported() {
[1 for (x in yield)]
}
reportCompare(reported.isGenerator(), true, "reported case: is generator");
reportCompare(typeof reported(), "object", "reported case: calling doesn't crash");

Просмотреть файл

@ -1,41 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 667131;
var summary = 'yield ignored if maybeNoteLegacyGenerator called too late';
var actual = '';
var expect = '';
function testGenerator(f, desc) {
reportCompare(f.isGenerator(), true, desc + ": is generator");
reportCompare(typeof f(), "object", desc + ": calling doesn't crash");
}
function reported1() {
(function(){})([yield[]], (""))
}
function simplified1() {
print([yield], (0))
}
function f1(a) { [x for (x in yield) for (y in (a))] }
function f2(a) { [x for (x in yield) if (y in (a))] }
function f3(a) { ([x for (x in yield) for (y in (a))]) }
function f4(a) { ([x for (x in yield) if (y in (a))]) }
function f7() { print({a:yield},(0)) }
function f8() { ([yield], (0)) }
testGenerator(reported1, "reported function with array literal");
testGenerator(simplified1, "reported function with array literal, simplified");
testGenerator(f1, "top-level array comprehension with paren expr in for-block");
testGenerator(f2, "top-level array comprehension with paren expr in if-block");
testGenerator(f3, "parenthesized array comprehension with paren expr in for-block");
testGenerator(f4, "parenthesized array comprehension with paren expr in if-block");
testGenerator(f7, "object literal");
testGenerator(f8, "array literal in paren exp");

Просмотреть файл

@ -83,21 +83,6 @@ function test()
}
expect("hello", s);
/*
* Generator expressions.
*/
String.prototype.__iterator__ = (function () {
/*
* NOTE:
* Without the "0 + ", the loop over <x/> does not terminate because
* the iterator gets run on a string with an empty length property.
*/
for (let i = 0; i != 0 + this.length; i++)
yield this[i];
});
expect(["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"] + "",
([a + b for (a in 'abc') for (b in '123')]) + "");
print("End of Tests");
/*

Просмотреть файл

@ -1,34 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 463783;
var summary = 'TM: Do not assert: "need a way to EOT now, since this is trace end": 0';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
var a = [0,1,2,3,4,5];
for (let f in a);
[(function(){})() for each (x in a) if (x)];
jit(false);
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,27 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 0;
var summary = 'Test deep bail from non-native call; don\'t crash';
var actual = '';
var expect = '';
printBugNumber(BUGNUMBER);
printStatus (summary);
jit(true);
test();
function test()
{
try {
[1 for each (i in this)];
} catch (ex) {}
}
jit(false);
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,30 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #38 From Jesse Ruderman
[0 for (a in [])];
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,51 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributor: Jason Orendorff
*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #52 From Jason Orendorff
// Crash in NoteLValue, called from BindDestructuringVar.
// NoteLValue assumes pn->pn_lexdef is non-null, but here
// pn is itself the definition of x.
for (var [x] in null) ;
// This one only crashes when executed from a file.
// Assertion failure: pn != dn->dn_uses, at ../jsparse.cpp:1131
for (var f in null)
;
var f = 1;
(f)
// Assertion failure: pnu->pn_cookie == FREE_UPVAR_COOKIE, at ../jsemit.cpp:1815
// In EmitEnterBlock. x has one use, which is pnu here.
// pnu is indeed a name, but pnu->pn_cookie is 0.
try { eval('let (x = 1) { var x; }'); } catch(ex) {}
// Assertion failure: cg->upvars.lookup(atom), at ../jsemit.cpp:1992
// atom="x", upvars is empty.
(1 for each (x in x));
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,69 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// =====
foo = "" + new Function("while(\u3056){let \u3056 = x}");
// =====
function a(){ let c; eval("let c, y"); }
a();
// =====
try
{
{x: 1e+81 ? c : arguments}
}
catch(ex)
{
}
// =====
(function(q){return q;} for each (\u3056 in []))
// =====
function f(){ var c; eval("{var c = NaN, c;}"); }
f();
// =====
try
{
eval(
' x\n' +
' let(x) {\n' +
' var x\n'
);
}
catch(ex)
{
}
// =====
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -44,34 +44,6 @@ function test()
}
g("for (var x = 0; x < 3; ++x)(new (function(){})());");
// =====
try
{
(function(){new (function ({}, x) { yield (x(1e-81) for (x4 in undefined)) })()})();
}
catch(ex)
{
}
// =====
try
{
(function(){[(function ([y]) { })() for each (x in [])];})();
}
catch(ex)
{
}
// =====
try
{
eval('(function(){for(var x2 = [function(id) { return id } for each (x in []) if ([])] in functional) function(){};})();');
}
catch(ex)
{
}
// =====
try
{
@ -104,21 +76,6 @@ function test()
var f = new Function("[] = [( '' )()];");
"" + f;
// =====
try
{
eval(
'for(let x;' +
' ([,,,]' +
' .toExponential(new Function(), (function(){}))); [] = {})' +
' for(var [x, x] = * in this.__defineSetter__("", function(){}));'
);
}
catch(ex)
{
}
// =====
reportCompare(expect, actual, summary);

Просмотреть файл

@ -1,31 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #98 From Gary Kwong [:nth10sd]
uneval(function(){(Number(0) for each (NaN in []) for each (x4 in this))});
// Assertion failure: pos == 0, at ../jsopcode.cpp:2963
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,40 +0,0 @@
// |reftest| skip-if(Android)
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #99 From Gary Kwong [:nth10sd]
if (typeof timeout == 'function')
{
expectExitCode(6);
timeout(3);
while( getter = function() { return y } for (y in y) )( /x/g );
}
// Assertion failure: lexdep->frameLevel() <= funbox->level, at ../jsparse.cpp:1771
// Crash [@ JSCompiler::setFunctionKinds] near null in opt, -j not required.
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,54 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #99 From Gary Kwong [:nth10sd]
try
{
eval("(function x(){x.(this)} )();");
}
catch(ex)
{
}
// Assertion failure: (uint32_t)(index_) < atoms_->length, at ../jsinterp.cpp:327
// Crash [@ js_FullTestPropertyCache] at null in opt, -j not required.
// =====
try
{
(function(){try {x} finally {}; ([x in []] for each (x in x))})();
}
catch(ex)
{
}
// Assertion failure: lexdep->frameLevel() <= funbox->level, at ../jsparse.cpp:1735
// Crash [@ BindNameToSlot] near null in opt, -j not required.
// =====
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -55,24 +55,6 @@ function test()
}
// Assertion failure: regs.sp == StackBase(fp), at ../jsinterp.cpp:2984
// =====
try
{
do {x} while([[] for (x in []) ]);
}
catch(ex)
{
}
// Assertion failure: !(pnu->pn_dflags & PND_BOUND), at ../jsemit.cpp:1818
// =====
try
{
{x} ((x=[] for (x in []))); x;
}
catch(ex)
{
}
// Assertion failure: cg->staticLevel >= level, at ../jsemit.cpp:2014
// Crash [@ BindNameToSlot] in opt without -j

Просмотреть файл

@ -52,27 +52,6 @@ function test()
{
}
// Assertion failure: cg->upvars.lookup(atom), at ../jsemit.cpp:2022
// =====
try
{
(function(){([]) ((function(q) { return q; })for (each in [1,2]))})();
}
catch(ex)
{
}
// Assertion failure: lexdep->frameLevel() <= funbox->level, at ../jsparse.cpp:1782
// Opt crash [@ JSCompiler::setFunctionKinds] near null
// =====
try
{
eval("((x1) > [(x)(function() { x;}) for each (x in x)])()");
}
catch(ex)
{
}
// Assertion failure: pnu->pn_lexdef == dn, at ../jsemit.cpp:1817
// =====
uneval(function(){arguments = ({ get y(){} }); for(var [arguments] in y ) (x);});
@ -87,16 +66,6 @@ function test()
{
}
// Assertion failure: op == JSOP_GETLOCAL, at ../jsemit.cpp:4557
// =====
try
{
(eval("(function(){let x , x = (x for (x in null))});"))();
}
catch(ex)
{
}
// Assertion failure: (fun->u.i.script)->upvarsOffset != 0, at ../jsfun.cpp:1537
// Opt crash [@ js_NewFlatClosure] near null
// =====

Просмотреть файл

@ -1,60 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #119 From Gary Kwong [:nth10sd]
// The following additional testcases also do not require -j.
// =====
function f() {
var x;
eval("for(let y in [false]) var x, x = 0");
}
f();
// Assertion failure: !regs.sp[-2].isPrimitive(), at ../jsinterp.cpp:3243
// Opt crash [@ JS_GetMethodById] near null
// =====
new Function("for(x1 in ((function (){ yield x } )())){var c, x = []} function x(){} ");
// Assertion failure: pn_used, at ../jsparse.h:401
// Opt crash [@ FindFunArgs] at null
// =====
uneval(new Function("[(x = x) for (c in []) if ([{} for (x in [])])]"))
// Assertion failure: (uintN)i < ss->top, at ../jsopcode.cpp:2814
// =====
function f() {
var x;
(function(){})();
eval("if(x|=[]) {var x; }");
}
f();
// Opt crash [@ js_ValueToNumber] at 0xc3510424
// Dbg crash [@ js_ValueToNumber] at 0xdadadad8
// =====
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,43 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #130 From Gary Kwong [:nth10sd]
// Does not require -j:
// =====
((function x()x in []) for (y in []))
// Assertion failure: !(pnu->pn_dflags & PND_BOUND), at ../jsemit.cpp:1818
// =====
// Requires -j:
// =====
for (var x = 0; x < 3; ++x) { new function(){} }
// Assertion failure: cx->bailExit, at ../jstracer.cpp:4672
// Opt crash [@ LeaveTree] near null
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,36 +0,0 @@
// |reftest| skip-if(Android)
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #135 From Gary Kwong [:nth10sd]
if (typeof timeout == 'function')
{
expectExitCode(6);
timeout(3);
eval("do ([]); while(y for each (x in []))");
}
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -32,34 +32,6 @@ function test()
}
}
// Assertion failure: fp2->fun && fp2->script, at ../jsinterp.cpp:5633
// Opt crash [@ js_Interpret]
// ===
try
{
(x for each (c in []))
x
}
catch(ex)
{
}
// Assertion failure: ss->printer->pcstack, at ../jsopcode.cpp:909
// ===
try
{
(function(){for(; (this); ((window for (x in [])) for (y in []))) 0});
}
catch(ex)
{
}
// Assertion failure: level >= tc->staticLevel, at ../jsparse.cpp:5773
// ===
eval(uneval( function(){
((function()y)() for each (x in this))
} ))
// Debug & opt crash [@ BindNameToSlot]
// -j is required:

Просмотреть файл

@ -1,44 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #138 From Gary Kwong [:nth10sd]
// Does not require -j:
// ===
((function x(){ yield (x = undefined) } ) for (y in /x/));
// Assertion failure: lexdep->frameLevel() <= funbox->level, at ../jsparse.cpp:1820
// ===
try
{
for(let x in ( x for (y in x) for each (x in []) )) y;
}
catch(ex)
{
}
// Assertion failure: cg->upvars.lookup(atom), at ../jsemit.cpp:2034
// ===
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,41 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 452498;
var summary = 'TM: upvar2 regression tests';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
// ------- Comment #139 From Gary Kwong [:nth10sd]
// Does not require -j:
// ===
try
{
(function(){var x = x (x() for each (x in []))})();
}
catch(ex)
{
}
// Assertion failure: (fun->u.i.script)->upvarsOffset != 0, at ../jsfun.cpp:1541
// Opt crash near null [@ js_NewFlatClosure]
// ===
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,35 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 507424;
var summary = 'TM: assert with regexp literal inside closure'
var actual = '';
var expect = 'do not crash';
//-----------------------------------------------------------------------------
start_test();
jit(true);
(new Function("'a'.replace(/a/,function(x){return(/x/ for each(y in[x]))})"))();
jit(false);
actual = 'do not crash'
finish_test();
//-----------------------------------------------------------------------------
function start_test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
}
function finish_test()
{
reportCompare(expect, actual, summary);
exitFunc ('test');
}

Просмотреть файл

@ -1,6 +0,0 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var it = (x for (x in [function(){}]));
it.next();
reportCompare("no assertion failure", "no assertion failure", "See bug 515885.");

Просмотреть файл

@ -1,38 +0,0 @@
// |reftest| skip-if(Android)
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
/*
* In strict mode, generator expressions may not locally bind 'eval'
* or 'arguments.'
*/
assertEq(testLenientAndStrict('(1 for (eval in []))',
parsesSuccessfully,
parseRaisesException(SyntaxError)),
true);
assertEq(testLenientAndStrict('(1 for ([eval] in []))',
parsesSuccessfully,
parseRaisesException(SyntaxError)),
true);
assertEq(testLenientAndStrict('(1 for ({x:eval} in []))',
parsesSuccessfully,
parseRaisesException(SyntaxError)),
true);
assertEq(testLenientAndStrict('(1 for (arguments in []))',
parsesSuccessfully,
parseRaisesException(SyntaxError)),
true);
assertEq(testLenientAndStrict('(1 for ([arguments] in []))',
parsesSuccessfully,
parseRaisesException(SyntaxError)),
true);
assertEq(testLenientAndStrict('(1 for ({x:arguments} in []))',
parsesSuccessfully,
parseRaisesException(SyntaxError)),
true);
reportCompare(true, true);

Просмотреть файл

@ -15,7 +15,7 @@ function assertThrows(f) {
}
function byteArray(str) {
return [ c.charCodeAt(0) for (c of str.split('')) ];
return str.split('').map(c => c.charCodeAt(0));
}
// Don't allow forging bogus Date objects.

Просмотреть файл

@ -123,7 +123,7 @@ if (os.getenv("JS_RECORD_RESULTS") !== undefined) {
if (captured[i] instanceof Error) {
print(s + captured[i].toSource() + ";");
} else {
data = [ c.charCodeAt(0) for (c of captured[i].clonebuffer.split('')) ];
data = captured[i].clonebuffer.split('').map(c => c.charCodeAt(0));
print(s + "serialize(0); captured[" + i + "].clonebuffer = String.fromCharCode(" + data.join(", ") + ");");
}
}

Просмотреть файл

@ -1,23 +0,0 @@
// -*- indent-tabs-mode: nil; js-indent-level: 4 -*-
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
var x = 42;
function a() {
var x;
function b() {
x = 43;
// When jsparse.cpp's CompExprTransplanter transplants the
// comprehension expression 'x' into the scope of the 'for' loop,
// it must not bring the placeholder definition node for the
// assignment to x above along with it. If it does, x won't appear
// in b's lexdeps, we'll never find out that the assignment refers
// to a's x, and we'll generate an assignment to the global x.
(x for (x in []));
}
b();
}
a();
assertEq(x, 42);
reportCompare(true, true);

Просмотреть файл

@ -596,7 +596,7 @@ function test()
var numbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ];
function tastring(tarray) {
return [ x for (x of tarray) ].toString();
return [...tarray].toString();
}
function checkCopyWithin(offset, start, end, dest, want) {

Просмотреть файл

@ -39,8 +39,6 @@ assertGlobalExpr("(function() { })", 11, { functionExpression: () => 11 });
assertGlobalExpr("[1,2,3]", 12, { arrayExpression: () => 12 });
assertGlobalExpr("({ x: y })", 13, { objectExpression: () => 13 });
assertGlobalExpr("this", 14, { thisExpression: () => 14 });
assertGlobalExpr("[x for (x in y)]", 17, { comprehensionExpression: () => 17 });
assertGlobalExpr("(x for (x in y))", 18, { generatorExpression: () => 18 });
assertGlobalExpr("(function() { yield 42 })", genFunExpr("legacy", null, [], blockStmt([exprStmt(19)])), { yieldExpression: () => 19 });
assertGlobalStmt("switch (x) { case y: }", switchStmt(ident("x"), [1]), { switchCase: () => 1 });
@ -50,9 +48,6 @@ assertGlobalStmt("try { } catch (e) { }", tryStmt(blockStmt([]), [], 2, null), {
assertGlobalStmt("try { } catch (e if e instanceof A) { } catch (e if e instanceof B) { }",
tryStmt(blockStmt([]), [2, 2], null, null),
{ catchClause: () => 2 });
assertGlobalExpr("[x for (y in z) for (x in y)]",
compExpr(ident("x"), [3, 3], null, "legacy"),
{ comprehensionBlock: () => 3 });
assertGlobalExpr("({ x: y } = z)", aExpr("=", 1, ident("z")), { objectPattern: () => 1 });
assertGlobalExpr("({ x: y } = z)", aExpr("=", objPatt([2]), ident("z")), { propertyPattern: () => 2 });

Просмотреть файл

@ -1,82 +1,34 @@
// |reftest| skip-if(!xulRuntime.shell)
function test() {
// Bug 632029: constant-folding
assertExpr("[x for each (x in y) if (false)]", compExpr(ident("x"), [compEachBlock(ident("x"), ident("y"))], lit(false), "legacy"));
// comprehensions
assertExpr("[ x for (x in foo)]",
compExpr(ident("x"), [compBlock(ident("x"), ident("foo"))], null, "legacy"));
assertExpr("[ [x,y] for (x in foo) for (y in bar)]",
compExpr(arrExpr([ident("x"), ident("y")]), [compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar"))], null, "legacy"));
assertExpr("[ [x,y,z] for (x in foo) for (y in bar) for (z in baz)]",
compExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar")), compBlock(ident("z"), ident("baz"))],
null,
"legacy"));
assertExpr("[ x for (x in foo) if (p)]",
compExpr(ident("x"), [compBlock(ident("x"), ident("foo"))], ident("p"), "legacy"));
assertExpr("[ [x,y] for (x in foo) for (y in bar) if (p)]",
compExpr(arrExpr([ident("x"), ident("y")]), [compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar"))], ident("p"), "legacy"));
assertExpr("[ [x,y,z] for (x in foo) for (y in bar) for (z in baz) if (p) ]",
compExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar")), compBlock(ident("z"), ident("baz"))],
ident("p"),
"legacy"));
assertExpr("[ x for each (x in foo)]",
compExpr(ident("x"), [compEachBlock(ident("x"), ident("foo"))], null, "legacy"));
assertExpr("[ [x,y] for each (x in foo) for each (y in bar)]",
compExpr(arrExpr([ident("x"), ident("y")]), [compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar"))], null, "legacy"));
assertExpr("[ [x,y,z] for each (x in foo) for each (y in bar) for each (z in baz)]",
compExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar")), compEachBlock(ident("z"), ident("baz"))],
null,
"legacy"));
assertExpr("[ x for each (x in foo) if (p)]",
compExpr(ident("x"), [compEachBlock(ident("x"), ident("foo"))], ident("p"), "legacy"));
assertExpr("[ [x,y] for each (x in foo) for each (y in bar) if (p)]",
compExpr(arrExpr([ident("x"), ident("y")]), [compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar"))], ident("p"), "legacy"));
assertExpr("[ [x,y,z] for each (x in foo) for each (y in bar) for each (z in baz) if (p) ]",
compExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar")), compEachBlock(ident("z"), ident("baz"))],
ident("p"),
"legacy"));
// Comprehension expressions using for-of can be written in two different styles.
function assertLegacyAndModernArrayComp(expr, body, blocks, filter) {
assertExpr(expr, compExpr(body, blocks, filter, "legacy"));
// Transform the legacy comprehension to a modern comprehension and test it
// that way too.
// Transform the legacy comprehensions to less legacy comprehensions and test
// them.
function assertFormerlyES6ArrayComp(expr, body, blocks, filter) {
let match = expr.match(/^\[(.*?) for (.*)\]$/);
assertEq(match !== null, true);
let expr2 = "[for " + match[2] + " " + match[1] + "]";
assertExpr(expr2, compExpr(body, blocks, filter, "modern"));
}
assertLegacyAndModernArrayComp("[ x for (x of foo)]",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], null);
assertLegacyAndModernArrayComp("[ [x,y] for (x of foo) for (y of bar)]",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], null);
assertLegacyAndModernArrayComp("[ [x,y,z] for (x of foo) for (y of bar) for (z of baz)]",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
null);
assertFormerlyES6ArrayComp("[ x for (x of foo)]",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], null);
assertFormerlyES6ArrayComp("[ [x,y] for (x of foo) for (y of bar)]",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], null);
assertFormerlyES6ArrayComp("[ [x,y,z] for (x of foo) for (y of bar) for (z of baz)]",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
null);
assertLegacyAndModernArrayComp("[ x for (x of foo) if (p)]",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], ident("p"));
assertLegacyAndModernArrayComp("[ [x,y] for (x of foo) for (y of bar) if (p)]",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], ident("p"));
assertLegacyAndModernArrayComp("[ [x,y,z] for (x of foo) for (y of bar) for (z of baz) if (p) ]",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
ident("p"));
assertFormerlyES6ArrayComp("[ x for (x of foo) if (p)]",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], ident("p"));
assertFormerlyES6ArrayComp("[ [x,y] for (x of foo) for (y of bar) if (p)]",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], ident("p"));
assertFormerlyES6ArrayComp("[ [x,y,z] for (x of foo) for (y of bar) for (z of baz) if (p) ]",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
ident("p"));
// Modern comprehensions with multiple ComprehensionIf.
// FormerlyES6 comprehensions with multiple ComprehensionIf.
assertExpr("[for (x of foo) x]",
compExpr(ident("x"), [compOfBlock(ident("x"), ident("foo"))], null, "modern"));

Просмотреть файл

@ -1,79 +1,33 @@
// |reftest| skip-if(!xulRuntime.shell)
function test() {
// generator expressions
assertExpr("( x for (x in foo))",
genExpr(ident("x"), [compBlock(ident("x"), ident("foo"))], null, "legacy"));
assertExpr("( [x,y] for (x in foo) for (y in bar))",
genExpr(arrExpr([ident("x"), ident("y")]), [compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar"))], null, "legacy"));
assertExpr("( [x,y,z] for (x in foo) for (y in bar) for (z in baz))",
genExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar")), compBlock(ident("z"), ident("baz"))],
null,
"legacy"));
assertExpr("( x for (x in foo) if (p))",
genExpr(ident("x"), [compBlock(ident("x"), ident("foo"))], ident("p"), "legacy"));
assertExpr("( [x,y] for (x in foo) for (y in bar) if (p))",
genExpr(arrExpr([ident("x"), ident("y")]), [compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar"))], ident("p"), "legacy"));
assertExpr("( [x,y,z] for (x in foo) for (y in bar) for (z in baz) if (p) )",
genExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compBlock(ident("x"), ident("foo")), compBlock(ident("y"), ident("bar")), compBlock(ident("z"), ident("baz"))],
ident("p"),
"legacy"));
assertExpr("( x for each (x in foo))",
genExpr(ident("x"), [compEachBlock(ident("x"), ident("foo"))], null, "legacy"));
assertExpr("( [x,y] for each (x in foo) for each (y in bar))",
genExpr(arrExpr([ident("x"), ident("y")]), [compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar"))], null, "legacy"));
assertExpr("( [x,y,z] for each (x in foo) for each (y in bar) for each (z in baz))",
genExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar")), compEachBlock(ident("z"), ident("baz"))],
null,
"legacy"));
assertExpr("( x for each (x in foo) if (p))",
genExpr(ident("x"), [compEachBlock(ident("x"), ident("foo"))], ident("p"), "legacy"));
assertExpr("( [x,y] for each (x in foo) for each (y in bar) if (p))",
genExpr(arrExpr([ident("x"), ident("y")]), [compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar"))], ident("p"), "legacy"));
assertExpr("( [x,y,z] for each (x in foo) for each (y in bar) for each (z in baz) if (p) )",
genExpr(arrExpr([ident("x"), ident("y"), ident("z")]),
[compEachBlock(ident("x"), ident("foo")), compEachBlock(ident("y"), ident("bar")), compEachBlock(ident("z"), ident("baz"))],
ident("p"),
"legacy"));
// Generator expressions using for-of can be written in two different styles.
function assertLegacyAndModernGenExpr(expr, body, blocks, filter) {
assertExpr(expr, genExpr(body, blocks, filter, "legacy"));
// Transform the legacy genexpr to a modern genexpr and test it that way
// too.
// Translate legacy genexprs into less legacy genexprs and test them.
function assertFormerlyES6GenExpr(expr, body, blocks, filter) {
let match = expr.match(/^\((.*?) for (.*)\)$/);
assertEq(match !== null, true);
let expr2 = "(for " + match[2] + " " + match[1] + ")";
assertExpr(expr2, genExpr(body, blocks, filter, "modern"));
}
assertLegacyAndModernGenExpr("( x for (x of foo))",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], null);
assertLegacyAndModernGenExpr("( [x,y] for (x of foo) for (y of bar))",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], null);
assertLegacyAndModernGenExpr("( [x,y,z] for (x of foo) for (y of bar) for (z of baz))",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
null);
assertFormerlyES6GenExpr("( x for (x of foo))",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], null);
assertFormerlyES6GenExpr("( [x,y] for (x of foo) for (y of bar))",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], null);
assertFormerlyES6GenExpr("( [x,y,z] for (x of foo) for (y of bar) for (z of baz))",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
null);
assertLegacyAndModernGenExpr("( x for (x of foo) if (p))",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], ident("p"));
assertLegacyAndModernGenExpr("( [x,y] for (x of foo) for (y of bar) if (p))",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], ident("p"));
assertLegacyAndModernGenExpr("( [x,y,z] for (x of foo) for (y of bar) for (z of baz) if (p) )",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
ident("p"));
assertFormerlyES6GenExpr("( x for (x of foo) if (p))",
ident("x"), [compOfBlock(ident("x"), ident("foo"))], ident("p"));
assertFormerlyES6GenExpr("( [x,y] for (x of foo) for (y of bar) if (p))",
arrExpr([ident("x"), ident("y")]), [compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar"))], ident("p"));
assertFormerlyES6GenExpr("( [x,y,z] for (x of foo) for (y of bar) for (z of baz) if (p) )",
arrExpr([ident("x"), ident("y"), ident("z")]),
[compOfBlock(ident("x"), ident("foo")), compOfBlock(ident("y"), ident("bar")), compOfBlock(ident("z"), ident("baz"))],
ident("p"));
// Modern generator comprehension with multiple ComprehensionIf.
// FormerlyES6 generator comprehension with multiple ComprehensionIf.
assertExpr("(for (x of foo) x)",
genExpr(ident("x"), [compOfBlock(ident("x"), ident("foo"))], null, "modern"));

Просмотреть файл

@ -1,14 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
function range(n)
{
var i = 0;
while (i < n)
yield i++;
}
[0 for (_ in range(Math.pow(2, 20)))];
reportCompare(true, true);

Просмотреть файл

@ -1,14 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributor: Gary Kwong
*/
(function(e) {
eval("\
[(function() {\
x.k = function(){}\
})() \
for (x in [0])]\
")
})();
reportCompare(0, 0, "");

Просмотреть файл

@ -1,23 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributor: Gary Kwong
*/
function f(e) {
eval("\
[((function g(o, bbbbbb) {\
if (aaaaaa = bbbbbb) {\
return window.r = []\
}\
g(aaaaaa, bbbbbb + 1);\
({})\
})([], 0)) \
for (window in this) \
for each(x in [0, 0])\
]\
")
}
t = 1;
f();
reportCompare(0, 0, "");

Просмотреть файл

@ -1,11 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributors: Gary Kwong and Jason Orendorff
*/
function f(e) {
eval("[function () { w.r = 0 }() for (w in [0])]")
}
f(0);
reportCompare(0, 0, "");

Просмотреть файл

@ -1,11 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* Contributors: Gary Kwong and Jason Orendorff
*/
function f(e) {
eval("[function () { w.r = 0 }() for (w in [0,1,2,3,4,5,6,7,8,9])]")
}
f(0);
reportCompare(0, 0, "");

Просмотреть файл

@ -1,19 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
/* Don't crash. */
try {
eval("function f(){}(((f)for(x in function(){}))())");
var threwTypeError = false;
} catch (x) {
var threwTypeError = x instanceof TypeError;
}
assertEq(threwTypeError, true);
/* Properly bind f. */
assertEq(eval("function f() {}; var i = (f for (f in [1])); uneval([n for (n in i)])"),
'["0"]');
reportCompare(true, true);

Просмотреть файл

@ -1,19 +0,0 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
var expect = true;
var actual = expect;
function f() {
'use strict';
for (; false; (0 for each (t in eval("")))) { }
}
fs = "" + f;
try {
eval("(" + fs + ")");
} catch (e) {
actual = false;
}
reportCompare(expect, actual, "ok");