diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-eval.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-eval.js new file mode 100644 index 000000000..380ebba83 --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-eval.js @@ -0,0 +1,38 @@ +var log = ""; + +function f() { + log += g(); + function g() { return "outer-g"; } + + var o = { g: function () { return "with-g"; } }; + with (o) { + // Annex B.3.3.3 says g should be set on the nearest VariableEnvironment, + // and so should not change o.g. + eval(`{ + function g() { return "eval-g"; } + }`); + } + + log += g(); + log += o.g(); +} + +f(); + +function h() { + eval(` + // Should return true, as var bindings introduced by eval are configurable. + log += (delete q); + { + function q() { log += "q"; } + // Should return false, as lexical bindings introduced by eval are not + // configurable. + log += (delete q); + } + `); + return q; +} + +h()(); + +reportCompare(log, "outer-geval-gwith-gtruefalseq"); diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-if.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-if.js new file mode 100644 index 000000000..ce63aeeea --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-if.js @@ -0,0 +1,42 @@ +var log = ""; + +function f(x) { + if (x) + function g() { return "g0"; } + else + function g() { return "g1"; } + + log += g(); + + if (x) + function g() { return "g2"; } + else { + } + + log += g(); + + if (x) { + } else + function g() { return "g3"; } + + log += g(); + + if (x) + function g() { return "g4"; } + + log += g(); +} + +f(true); +f(false); + +try { + eval(` + if (1) + l: function foo() {} + `); +} catch (e) { + log += "e"; +} + +reportCompare(log, "g0g2g2g4g1g1g3g3e"); diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-label.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-label.js new file mode 100644 index 000000000..0fe9f45fc --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-label.js @@ -0,0 +1,43 @@ +function expectSyntaxError(str) { + var threwSyntaxError; + try { + eval(str); + } catch (e) { + threwSyntaxError = e instanceof SyntaxError; + } + assertEq(threwSyntaxError, true); + + try { + eval('"use strict";' + str); + } catch (e) { + threwSyntaxError = e instanceof SyntaxError; + } + assertEq(threwSyntaxError, true); +} + +function expectSloppyPass(str) { + eval(str); + + try { + eval('"use strict";' + str); + } catch (e) { + threwSyntaxError = e instanceof SyntaxError; + } + assertEq(threwSyntaxError, true); +} + +expectSloppyPass(`l: function f1() {}`); +expectSloppyPass(`l0: l: function f1() {}`); +expectSloppyPass(`{ f1(); l: function f1() {} }`); +expectSloppyPass(`{ f1(); l0: l: function f1() {} }`); +expectSloppyPass(`{ f1(); l: function f1() { return 42; } } assertEq(f1(), 42);`); +expectSloppyPass(`eval("fe(); l: function fe() {}")`); +expectSyntaxError(`if (1) l: function f2() {}`); +expectSyntaxError(`if (1) {} else l: function f3() {}`); +expectSyntaxError(`do l: function f4() {} while (0)`); +expectSyntaxError(`while (0) l: function f5() {}`); +expectSyntaxError(`for (;;) l: function f6() {}`); +expectSloppyPass(`switch (1) { case 1: l: function f7() {} }`); +expectSloppyPass(`switch (1) { case 1: assertEq(f8(), 'f8'); case 2: l: function f8() { return 'f8'; } } assertEq(f8(), 'f8');`); + +reportCompare(0, 0); diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-property.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-property.js new file mode 100644 index 000000000..a295de508 --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-property.js @@ -0,0 +1,18 @@ +// |reftest| skip-if(!xulRuntime.shell) + +// Define a global getter without a setter. +Object.defineProperty(this, "x", { + get: function () { return "get-x"; }, + configurable: true +}); + +// Simulate loading a 2nd script with evaluate, else we would DEFVAR the x and +// the above defineProperty would fail in trying to redefine a non-configurable +// property on the global. +evaluate(`{ + function x() { return "fun-x"; } +}`); + +// Annex B is supposed to be like an assignment. Should not blow away the +// existing setter-less getter. +reportCompare(x, "get-x"); diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-same-name.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-same-name.js new file mode 100644 index 000000000..b89f91c59 --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-same-name.js @@ -0,0 +1,7 @@ +{ + function f() { return "inner"; } +} + +function f() { return "outer"; } + +reportCompare(f(), "inner"); diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-with.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-with.js new file mode 100644 index 000000000..d9bdd98dc --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b-with.js @@ -0,0 +1,18 @@ +var o = { f: "string-f" }; +with (o) { + var desc = Object.getOwnPropertyDescriptor(this, "f"); + assertEq(desc.value, undefined); + assertEq(desc.writable, true); + assertEq(desc.enumerable, true); + assertEq(desc.configurable, false); + function f() { + return "fun-f"; + } +} + +// Annex B explicitly assigns to the nearest VariableEnvironment, so the +// with-object "o" should have its property unchanged. +assertEq(o.f, "string-f"); +assertEq(f(), "fun-f"); + +reportCompare(true, true) diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b.js new file mode 100644 index 000000000..16c40774c --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-annex-b.js @@ -0,0 +1,31 @@ +var log = ""; + +log += typeof f; + +{ + log += f(); + + function f() { + return "f1"; + } +} + +log += f(); + +function g() { + log += typeof h; + + { + log += h(); + + function h() { + return "h1"; + } + } + + log += h(); +} + +g(); + +reportCompare(log, "undefinedf1f1undefinedh1h1"); diff --git a/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-strict.js b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-strict.js new file mode 100644 index 000000000..2b780d7dd --- /dev/null +++ b/js/src/tests/ecma_6/LexicalEnvironment/block-scoped-functions-strict.js @@ -0,0 +1,45 @@ +"use strict" + +var log = ""; + +function f() { + return "f0"; +} + +log += f(); + +{ + log += f(); + + function f() { + return "f1"; + } + + log += f(); +} + +log += f(); + +function g() { + function h() { + return "h0"; + } + + log += h(); + + { + log += h(); + + function h() { + return "h1"; + } + + log += h(); + } + + log += h(); +} + +g(); + +reportCompare(log, "f0f1f1f0h0h1h1h0");