summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_2017/Statements
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/ecma_2017/Statements')
-rw-r--r--js/src/tests/ecma_2017/Statements/browser.js0
-rw-r--r--js/src/tests/ecma_2017/Statements/for-in-with-assignment-semantics.js46
-rw-r--r--js/src/tests/ecma_2017/Statements/for-in-with-assignment-syntax.js68
-rw-r--r--js/src/tests/ecma_2017/Statements/for-in-with-assignments.js82
-rw-r--r--js/src/tests/ecma_2017/Statements/shell.js1
-rw-r--r--js/src/tests/ecma_2017/Statements/trailing_comma_parameters.js92
6 files changed, 289 insertions, 0 deletions
diff --git a/js/src/tests/ecma_2017/Statements/browser.js b/js/src/tests/ecma_2017/Statements/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/ecma_2017/Statements/browser.js
diff --git a/js/src/tests/ecma_2017/Statements/for-in-with-assignment-semantics.js b/js/src/tests/ecma_2017/Statements/for-in-with-assignment-semantics.js
new file mode 100644
index 000000000..f1dbb3438
--- /dev/null
+++ b/js/src/tests/ecma_2017/Statements/for-in-with-assignment-semantics.js
@@ -0,0 +1,46 @@
+/* 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/. */
+
+const unreachable = () => { throw "unreachable"; };
+
+// var-initializer expression is executed before for-in expression.
+var log = "";
+for (var x = (log += "head") in (log += "|expr", null)) unreachable();
+assertEq(log, "head|expr");
+
+log = "";
+for (var x = (log += "head") in (log += "|expr", {})) unreachable();
+assertEq(log, "head|expr");
+
+
+// for-in expression isn't executed when var-initializer throws exception.
+function ExpectedError() {}
+assertThrowsInstanceOf(() => {
+ var throwErr = () => { throw new ExpectedError(); };
+ for (var x = throwErr() in unreachable()) unreachable();
+}, ExpectedError);
+
+
+// Ensure environment operations are performed correctly.
+var scope = new Proxy({x: 0}, new Proxy({}, {
+ get(t, pk, r) {
+ log += pk + "|";
+ }
+}));
+
+log = "";
+with (scope) {
+ for (var x = 0 in {}) ;
+}
+assertEq(log, "has|get|set|getOwnPropertyDescriptor|defineProperty|");
+
+log = "";
+with (scope) {
+ for (var x = 0 in {p: 0}) ;
+}
+assertEq(log, "has|get|set|getOwnPropertyDescriptor|defineProperty|".repeat(2));
+
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/ecma_2017/Statements/for-in-with-assignment-syntax.js b/js/src/tests/ecma_2017/Statements/for-in-with-assignment-syntax.js
new file mode 100644
index 000000000..4ac711e21
--- /dev/null
+++ b/js/src/tests/ecma_2017/Statements/for-in-with-assignment-syntax.js
@@ -0,0 +1,68 @@
+/* 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/. */
+
+const validSyntax = [
+ "var x",
+];
+
+const destructuring = [
+ "[]",
+ "[,]",
+ "[a]",
+ "[a = 0]",
+ "[...a]",
+ "[...[]]",
+ "[...[a]]",
+ "{}",
+ "{p: x}",
+ "{p: x = 0}",
+ "{x}",
+ "{x = 0}",
+];
+
+const invalidSyntax = [
+ ...destructuring.map(binding => `var ${binding}`),
+ "let x",
+ ...destructuring.map(binding => `let ${binding}`),
+ "const x",
+ ...destructuring.map(binding => `const ${binding}`),
+ "x",
+ ...destructuring.map(binding => `${binding}`),
+ "o.p",
+ "o[0]",
+ "f()",
+];
+
+for (let valid of validSyntax) {
+ eval(`for (${valid} = 0 in {});`);
+ assertThrowsInstanceOf(() => eval(`"use strict"; for (${valid} = 0 in {});`),
+ SyntaxError);
+}
+
+for (let invalid of invalidSyntax) {
+ assertThrowsInstanceOf(() => eval(`for (${invalid} = 0 in {});`), SyntaxError);
+}
+
+// Invalid syntax, needs method context to parse.
+assertThrowsInstanceOf(() => eval(`({ m() { for (super.p = 0 in {}); } })`), SyntaxError);
+assertThrowsInstanceOf(() => eval(`({ m() { for (super[0] = 0 in {}); } })`), SyntaxError);
+
+// Throws ReferenceError instead of SyntaxError, because we intermingle parsing
+// and early error checking.
+assertThrowsInstanceOf(() => eval(`for (0 = 0 in {});`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`for (i++ = 0 in {});`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`for (new F() = 0 in {});`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`function f() { for (new.target = 0 in {}); }`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`class C extends D { constructor() { for (super() = 0 in {}); } }`), ReferenceError);
+
+// Same as above, only this time don't make it look like we actually parse a for-in statement.
+assertThrowsInstanceOf(() => eval(`for (0 = 0 #####`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`for (i++ = 0 #####`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`for (new F() = 0 #####`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`function f() { for (new.target = 0 #####`), ReferenceError);
+assertThrowsInstanceOf(() => eval(`class C extends D { constructor() { for (super() = 0 #####`), ReferenceError);
+
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
diff --git a/js/src/tests/ecma_2017/Statements/for-in-with-assignments.js b/js/src/tests/ecma_2017/Statements/for-in-with-assignments.js
new file mode 100644
index 000000000..9a9782ee4
--- /dev/null
+++ b/js/src/tests/ecma_2017/Statements/for-in-with-assignments.js
@@ -0,0 +1,82 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+
+var gTestfile = "for-in-with-assignments.js";
+var BUGNUMBER = 1164741;
+var summary = "Parse |for (var ... = ... in ...)|."
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+// This is a total grab-bag of junk originally in tests changed when this
+// syntax was removed. Leaving it all in one file will make it easier to
+// eventually remove. Avert your eyes!
+// TC39 has revived this syntax for ES2017 - "What is dead may never die."
+
+if (typeof Reflect !== "undefined" && Reflect.parse)
+ Reflect.parse("for (var x = 3 in []) { }");
+
+/******************************************************************************/
+
+function testQ() {
+ try {
+ for (var i = 0 in this) throw p;
+ } catch (e) {
+ if (i !== 94)
+ return "what";
+ }
+}
+testQ();
+
+/******************************************************************************/
+
+function f3(i,o){for(var x=i in o)parseInt(o[x]); return x}
+function f4(i,o){with(this)for(var x=i in o)parseInt(o[x]); return x}
+
+assertEq(f3(42, []), 42);
+assertEq(f3(42, ['first']), "0");
+assertEq(f4(42, []), 42);
+assertEq(f4(42, ['first']), "0");
+
+/******************************************************************************/
+
+function SetLangHead(l){
+ with(p){
+ for(var i=0 in x)
+ if(getElementById("TxtH"+i)!=undefined)
+ parseInt('huh');
+ }
+}
+x=[0,1,2,3];
+p={getElementById: function (id){parseInt(uneval(this), id); return undefined;}};
+SetLangHead(1);
+
+/******************************************************************************/
+
+(function(){for(var x = arguments in []){} function x(){}})();
+
+/******************************************************************************/
+
+with (0)
+ for (var b = 0 in 0); // don't assert in parser
+
+/******************************************************************************/
+
+function* g1() {
+ for (var x = yield in {}) ;
+}
+var it = g1();
+assertEq(it.next().done, false);
+assertEq(it.next().done, true);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");
diff --git a/js/src/tests/ecma_2017/Statements/shell.js b/js/src/tests/ecma_2017/Statements/shell.js
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/js/src/tests/ecma_2017/Statements/shell.js
@@ -0,0 +1 @@
+
diff --git a/js/src/tests/ecma_2017/Statements/trailing_comma_parameters.js b/js/src/tests/ecma_2017/Statements/trailing_comma_parameters.js
new file mode 100644
index 000000000..8612f7b1b
--- /dev/null
+++ b/js/src/tests/ecma_2017/Statements/trailing_comma_parameters.js
@@ -0,0 +1,92 @@
+/* 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/. */
+
+// Trailing comma in functions and generators.
+
+// 14.1 Function Definitions
+// FunctionDeclaration[Yield, Default]:
+// function BindingIdentifier[?Yield] ( FormalParameters[~Yield] ) { FunctionBody[~Yield] }
+
+// 14.4 Generator Function Definitions
+// GeneratorDeclaration[Yield, Default]:
+// function * BindingIdentifier[?Yield] ( FormalParameters[+Yield] ) { GeneratorBody }
+
+
+function functionDeclaration(argList, parameters = "", returnExpr = "") {
+ return eval(`
+ function f(${argList}) {
+ var fun = f;
+ return ${returnExpr};
+ }
+ f(${parameters});
+ `);
+}
+
+function generatorDeclaration(argList, parameters = "", returnExpr = "") {
+ return eval(`
+ function* f(${argList}) {
+ var fun = f;
+ return ${returnExpr};
+ }
+ f(${parameters}).next().value;
+ `);
+}
+
+const tests = [
+ functionDeclaration,
+ generatorDeclaration,
+];
+
+// Ensure parameters are passed correctly.
+for (let test of tests) {
+ assertEq(test("a, ", "10", "a"), 10);
+ assertEq(test("a, b, ", "10, 20", "a + b"), 30);
+ assertEq(test("a = 30, ", "", "a"), 30);
+ assertEq(test("a = 30, b = 40, ", "", "a + b"), 70);
+
+ assertEq(test("[a], ", "[10]", "a"), 10);
+ assertEq(test("[a], [b], ", "[10], [20]", "a + b"), 30);
+ assertEq(test("[a] = [30], ", "", "a"), 30);
+ assertEq(test("[a] = [30], [b] = [40], ", "", "a + b"), 70);
+
+ assertEq(test("{a}, ", "{a: 10}", "a"), 10);
+ assertEq(test("{a}, {b}, ", "{a: 10}, {b: 20}", "a + b"), 30);
+ assertEq(test("{a} = {a: 30}, ", "", "a"), 30);
+ assertEq(test("{a} = {a: 30}, {b} = {b: 40}, ", "", "a + b"), 70);
+}
+
+// Ensure function length doesn't change.
+for (let test of tests) {
+ assertEq(test("a, ", "", "fun.length"), 1);
+ assertEq(test("a, b, ", "", "fun.length"), 2);
+
+ assertEq(test("[a], ", "[]", "fun.length"), 1);
+ assertEq(test("[a], [b], ", "[], []", "fun.length"), 2);
+
+ assertEq(test("{a}, ", "{}", "fun.length"), 1);
+ assertEq(test("{a}, {b}, ", "{}, {}", "fun.length"), 2);
+}
+
+for (let test of tests) {
+ // Trailing comma in empty parameters list.
+ assertThrowsInstanceOf(() => test(","), SyntaxError);
+
+ // Leading comma.
+ assertThrowsInstanceOf(() => test(", a"), SyntaxError);
+ assertThrowsInstanceOf(() => test(", ...a"), SyntaxError);
+
+ // Multiple trailing comma.
+ assertThrowsInstanceOf(() => test("a, , "), SyntaxError);
+ assertThrowsInstanceOf(() => test("a..., , "), SyntaxError);
+
+ // Trailing comma after rest parameter.
+ assertThrowsInstanceOf(() => test("...a, "), SyntaxError);
+ assertThrowsInstanceOf(() => test("a, ...b, "), SyntaxError);
+
+ // Elision.
+ assertThrowsInstanceOf(() => test("a, , b"), SyntaxError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);