diff options
Diffstat (limited to 'js/src/tests/js1_7/lexical')
-rw-r--r-- | js/src/tests/js1_7/lexical/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/js1_7/lexical/regress-336376-01.js | 323 | ||||
-rw-r--r-- | js/src/tests/js1_7/lexical/regress-346642-03.js | 124 | ||||
-rw-r--r-- | js/src/tests/js1_7/lexical/regress-346642-04.js | 36 | ||||
-rw-r--r-- | js/src/tests/js1_7/lexical/regress-351515.js | 97 | ||||
-rw-r--r-- | js/src/tests/js1_7/lexical/shell.js | 0 |
6 files changed, 580 insertions, 0 deletions
diff --git a/js/src/tests/js1_7/lexical/browser.js b/js/src/tests/js1_7/lexical/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_7/lexical/browser.js diff --git a/js/src/tests/js1_7/lexical/regress-336376-01.js b/js/src/tests/js1_7/lexical/regress-336376-01.js new file mode 100644 index 000000000..959593e04 --- /dev/null +++ b/js/src/tests/js1_7/lexical/regress-336376-01.js @@ -0,0 +1,323 @@ +/* -*- 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 = "336376"; +var summary = "Tests reserved words in contexts in which they are not reserved"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * TEST SETUP * + **************/ + +// +// New tests go in Tester.prototype._tests. A test is called with a single +// argument, the keyword to test in the syntax tested by that test. Tests +// should not return anything, and they should signal failure by throwing an +// explanatory exception and success by not throwing one. +// +// If you define a new test, make sure to name it using an informative string +// for ease of use if any keywords ever manually define the array of tests they +// should pass, and add it as a string to ALL_TESTS. +// + +// all tests +const ALL_TESTS = + [ + "CONTEXT_OBJECT_LITERAL_PROPERTY", + "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE", + "CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION", + "CONTEXT_OBJECT_PROPERTY_DOT_GET", + "CONTEXT_OBJECT_PROPERTY_DOT_SET", + ]; + +function r(keyword, tests) +{ + /** + * @param keyword + * the keyword as a string + * @param tests + * array of test numbers against it, or leave undefined to run all tests + * against it + */ + function Reserved(keyword, tests) + { + this.keyword = keyword; + if (tests) + this.tests = tests; + else + this.tests = ALL_TESTS; + } + Reserved.prototype = + { + toString: + function() + { + return "'" + this.keyword + "' being run against tests " + + this.tests; + } + }; + return new Reserved(keyword, tests); +} + +// ECMA-262, 3rd. ed. keywords -- see 7.5.2 +const ECMA_262_3_KEYWORD = + [ + r("break"), + r("case"), + r("catch"), + r("continue"), + r("default"), + r("delete"), + r("do"), + r("else"), + r("finally"), + r("for"), + r("function"), + r("if"), + r("in"), + r("instanceof"), + r("new"), + r("return"), + r("switch"), + r("this"), + r("throw"), + r("try"), + r("typeof"), + r("var"), + r("void"), + r("while"), + r("with"), + ]; + +// ECMA-262, 3rd. ed. future reserved keywords -- see 7.5.3 +const ECMA_262_3_FUTURERESERVEDKEYWORD = + [ + r("abstract"), + r("boolean"), + r("byte"), + r("char"), + r("class"), + r("const"), + r("debugger"), + r("double"), + r("enum"), + r("export"), + r("extends"), + r("final"), + r("float"), + r("goto"), + r("implements"), + r("import"), + r("int"), + r("interface"), + r("long"), + r("native"), + r("package"), + r("private"), + r("protected"), + r("public"), + r("short"), + r("static"), + r("super"), + r("synchronized"), + r("throws"), + r("transient"), + r("volatile"), + ]; + +// like reserved words, but not quite reserved words +const PSEUDO_RESERVED = + [ + r("true"), + r("false"), + r("null"), + r("each"), // |for each| + ]; + +// new-in-ES4 reserved words -- fill this as each is implemented +const ECMA_262_4_RESERVED_WORDS = + [ + r("let") + ]; + + + +/** + * @param keyword + * string containing the tested keyword + * @param test + * the number of the failing test + * @param error + * the exception thrown when running the test + */ +function Failure(keyword, test, error) +{ + this.keyword = keyword; + this.test = test; + this.error = error; +} +Failure.prototype = +{ + toString: + function() + { + return "*** FAILURE on '" + this.keyword + "'!\n" + + "* test: " + this.test + "\n" + + "* error: " + this.error + "\n"; + } +}; + +function Tester() +{ + this._failedTests = []; +} +Tester.prototype = +{ + testReservedWords: + function(reservedArray) + { + var rv; + for (var i = 0, sz = reservedArray.length; i < sz; i++) + { + var res = reservedArray[i]; + if (!res) + continue; + + var tests = res.tests; + for (var j = 0, sz2 = tests.length; j < sz2; j++) + { + var test = tests[j]; + if (!test) + continue; + + try + { + this._tests[test](res.keyword); + } + catch (e) + { + this._failedTests.push(new Failure(res.keyword, test, e)); + } + } + } + }, + flushErrors: + function () + { + if (this._failedTests.length > 0) { + var except = "*************************\n" + + "* FAILURES ENCOUNTERED! *\n" + + "*************************\n"; + for (var i = 0, sz = this._failedTests.length; i < sz; i++) + except += this._failedTests[i]; + throw except; + } + }, + _tests: + { + CONTEXT_OBJECT_LITERAL_PROPERTY: + function(keyword) + { + try + { + eval("var o = { " + keyword + ": 17 };\n" + + "if (o['" + keyword + "'] != 17)\n" + + "throw \"o['" + keyword + "'] == 17\";"); + } + catch (e) + { + throw e; + } + }, + CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE: + function(keyword) + { + try + { + eval("var o = { \"" + keyword + "\": 17, baz: null };\n" + + "if (o." + keyword + " != 17)\n" + + "throw \"o." + keyword + " == 17\";"); + } + catch (e) + { + throw e; + } + }, + CONTEXT_OBJECT_PROPERTY_DOT_REFERENCE_IS_FUNCTION: + function(keyword) + { + try + { + eval("var o = { '" + keyword + "': function() { return 17; }, baz: null };\n" + + "if (o." + keyword + "() != 17)\n" + + "throw \"o." + keyword + " == 17\";"); + } + catch (e) + { + throw e; + } + }, + CONTEXT_OBJECT_PROPERTY_DOT_GET: + function(keyword) + { + try + { + var o = {}; + eval("o['" + keyword + "'] = 17;\n" + + "if (o." + keyword + " != 17)\n" + + "throw \"'o." + keyword + " != 17' failed!\";"); + } + catch (e) + { + throw e; + } + }, + CONTEXT_OBJECT_PROPERTY_DOT_SET: + function(keyword) + { + try + { + var o = {}; + eval("o." + keyword + " = 17;\n" + + "if (o['" + keyword + "'] != 17)\n" + + "throw \"'o." + keyword + " = 17' failed!\";"); + } + catch (e) + { + throw e; + } + }, + } +}; + + +/*************** + * BEGIN TESTS * + ***************/ + +var failed = false; + +try +{ + var tester = new Tester(); + tester.testReservedWords(ECMA_262_3_KEYWORD); + tester.testReservedWords(ECMA_262_3_FUTURERESERVEDKEYWORD); + tester.testReservedWords(PSEUDO_RESERVED); + tester.testReservedWords(ECMA_262_4_RESERVED_WORDS); + tester.flushErrors(); +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/lexical/regress-346642-03.js b/js/src/tests/js1_7/lexical/regress-346642-03.js new file mode 100644 index 000000000..14f36648b --- /dev/null +++ b/js/src/tests/js1_7/lexical/regress-346642-03.js @@ -0,0 +1,124 @@ +// |reftest| skip -- obsolete test +/* -*- 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 = 346642; +var summary = 'decompilation of destructuring assignment'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 'TypeError: NaN is not a constructor'; + actual = 'No Crash'; + try + { + try { throw 1; } catch(e1 if 0) { } catch(e2 if (new NaN)) { } + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 1'); + + expect = /TypeError: x.t (has no properties|is undefined)/; + actual = 'No Crash'; + try + { + z = [1]; + let (x = (undefined ? 3 : z)) { x.t.g } + } + catch(ex) + { + actual = ex + ''; + } + reportMatch(expect, actual, summary + ': 2'); + + expect = /TypeError: x.t (has no properties|is undefined)/; + actual = 'No Crash'; + try + { + z = [1]; + new Function("let (x = (undefined ? 3 : z)) { x.t.g }")() + } + catch(ex) + { + actual = ex + ''; + } + reportMatch(expect, actual, summary + ': 3'); + + expect = 'TypeError: b is not a constructor'; + actual = 'No Crash'; + try + { + with({x: (new (b = 1))}) (2).x + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 4'); + + expect = /TypeError: this.zzz (has no properties|is undefined)/; + actual = 'No Crash'; + try + { + (function(){try { } catch(f) { return; } finally { this.zzz.zzz }})(); + } + catch(ex) + { + actual = ex + ''; + } + reportMatch(expect, actual, summary + ': 5'); + + expect = 'TypeError: p.z = <x><y/></x> ? 3 : 4 is not a function'; + actual = 'No Crash'; + try + { + (new Function("if(\n({y:5, p: (print).r})) { p={}; (p.z = <x\n><y/></x> ? 3 : 4)(5) }"))(); + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 6'); + + expect = 'TypeError: xx is not a function'; + actual = 'No Crash'; + try + { + switch(xx) { case 3: case (new ([3].map)): } const xx; + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 7'); + + expect = 'ReferenceError: x.y is not defined'; + actual = 'No Crash'; + try + { + x = {}; + import x.y; + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 9'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/lexical/regress-346642-04.js b/js/src/tests/js1_7/lexical/regress-346642-04.js new file mode 100644 index 000000000..77fe059ce --- /dev/null +++ b/js/src/tests/js1_7/lexical/regress-346642-04.js @@ -0,0 +1,36 @@ +/* -*- 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 = 346642; +var summary = 'decompilation of destructuring assignment'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 'No Crash'; + actual = 'No Crash'; + try + { + (function() { for (var [a, b] in []) for ([c, d] in []) { } }); + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/lexical/regress-351515.js b/js/src/tests/js1_7/lexical/regress-351515.js new file mode 100644 index 000000000..e68e3da50 --- /dev/null +++ b/js/src/tests/js1_7/lexical/regress-351515.js @@ -0,0 +1,97 @@ +/* -*- 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 = 351515; +var summary = 'Invalid uses of yield, let keywords in js17'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +try +{ + expect = "SyntaxError"; + eval('yield = 1;'); + actual = 'No Error'; +} +catch(ex) +{ + actual = ex.name; +} +reportCompare(expect, actual, summary + ': global: yield = 1'); + +try +{ + expect = "SyntaxError"; + eval('(function(){yield = 1;})'); + actual = 'No Error'; +} +catch(ex) +{ + actual = ex.name; +} +reportCompare(expect, actual, summary + ': local: yield = 1'); + +try +{ + expect = "No Error"; + eval('let = 1;'); + actual = 'No Error'; +} +catch(ex) +{ + actual = ex.name; +} +reportCompare(expect, actual, summary + ': global: let = 1'); + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + try + { + expect = "SyntaxError"; + eval('function f(yield, let) { return yield+let; }'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex.name; + } + reportCompare(expect, actual, summary + + ': function f(yield, let) { return yield+let; }'); + + try + { + expect = "SyntaxError"; + eval('var yield = 1;'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex.name; + } + reportCompare(expect, actual, summary + ': function () {var yield;}'); + + try + { + expect = "No Error"; + eval('var let = 1;'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex.name; + } + reportCompare(expect, actual, summary + ': function () { var let;}'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/lexical/shell.js b/js/src/tests/js1_7/lexical/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_7/lexical/shell.js |