diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/annexB/language/eval-code/indirect | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/annexB/language/eval-code/indirect')
162 files changed, 6802 insertions, 0 deletions
diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/browser.js b/js/src/tests/test262/annexB/language/eval-code/indirect/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/browser.js diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-block-scoping.js new file mode 100644 index 0000000000..dee07e058a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-block-scoping.js @@ -0,0 +1,46 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: A block-scoped binding is created (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + '{ function f() { initialBV = f; f = 123; currentBV = f; return "decl"; } }' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..af9d45557c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,24 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Does not re-initialize binding created by similar forms (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }{ function f() { } }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..750dcbc80a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-block-fn-update.js @@ -0,0 +1,36 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable-scoped binding is updated (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + '{ function f() { return "second declaration"; } }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..5b9b87599d --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-fn-no-init.js @@ -0,0 +1,22 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Existing variable binding is not modified (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");{ function f() { return "inner declaration"; } }function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..a4a3b1e39c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-fn-update.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable-scoped binding is updated following evaluation (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + '{ function f() { return "inner declaration"; } }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-global-init.js new file mode 100644 index 0000000000..0ffa7a899e --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-global-init.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable binding is left in place by legacy function hoisting (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });{ function f() { } }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-global-update.js new file mode 100644 index 0000000000..1f53ce9d32 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-global-update.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable-scoped binding is updated following evaluation (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + '{ function f() { return "function declaration"; } }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..37bbbfb131 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });{ function f() { } }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..2144c040a2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-var-no-init.js @@ -0,0 +1,21 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Existing variable binding is not modified (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);{ function f() { } }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-var-update.js new file mode 100644 index 0000000000..6b6d13d6cf --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-existing-var-update.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable-scoped binding is updated following evaluation (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + '{ function f() { return "function declaration"; } }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-init.js new file mode 100644 index 0000000000..502fa612fe --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-init.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });{ function f() { } }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-no-skip-try.js new file mode 100644 index 0000000000..ab65c646ae --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-no-skip-try.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {{ function f() { return 123; } }}\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..42b6330b97 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-block.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;{ function f() { } }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..b24bbb3f9b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for-in.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {{ function f() { } }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..0ca9f52538 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for-of.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {{ function f() { } }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..05bb08ccb2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-for.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {{ function f() { } }break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..885b6be204 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-switch.js @@ -0,0 +1,41 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;{ function f() { } }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..23251e6323 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err-try.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {{ function f() { } }}\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err.js new file mode 100644 index 0000000000..2a05b83d93 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-skip-early-err.js @@ -0,0 +1,23 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");{ function f() { } }assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-update.js new file mode 100644 index 0000000000..a8ea533e4c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-block-decl-eval-global-update.js @@ -0,0 +1,29 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-block.template +/*--- +description: Variable binding value is updated following evaluation (Block statement in eval code containing a function declaration) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + '{ function f() { return "declaration"; } }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-block-scoping.js new file mode 100644 index 0000000000..2bd1ad9a4b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-block-scoping.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: A block-scoped binding is created (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'if (true) function f() { initialBV = f; f = 123; currentBV = f; return "decl"; } else function _f() {}' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..410903ce55 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Does not re-initialize binding created by similar forms (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }if (true) function f() { } else function _f() {}' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..9157174c6b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-block-fn-update.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable-scoped binding is updated (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'if (true) function f() { return "second declaration"; } else function _f() {}' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..cc67626ccb --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-fn-no-init.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");if (true) function f() { return "inner declaration"; } else function _f() {}function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..f63d933e4b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-fn-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "inner declaration"; } else function _f() {}assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-global-init.js new file mode 100644 index 0000000000..0f6e39cbcd --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable binding is left in place by legacy function hoisting (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });if (true) function f() { } else function _f() {}' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-global-update.js new file mode 100644 index 0000000000..6899ce3b0d --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-global-update.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'if (true) function f() { return "function declaration"; } else function _f() {}' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..79d79148e1 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });if (true) function f() { } else function _f() {}' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..f20019e58a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-var-no-init.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);if (true) function f() { } else function _f() {}' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-var-update.js new file mode 100644 index 0000000000..2521f2693a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-existing-var-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "function declaration"; } else function _f() {}' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-init.js new file mode 100644 index 0000000000..eb88aedf98 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });if (true) function f() { } else function _f() {}' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-no-skip-try.js new file mode 100644 index 0000000000..7c3e4152e0 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-no-skip-try.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {if (true) function f() { return 123; } else function _f() {}}\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..7c7c5544ae --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-block.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;if (true) function f() { } else function _f() {}}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..489c55e0e1 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for-in.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {if (true) function f() { } else function _f() {}}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..75c6882953 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for-of.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {if (true) function f() { } else function _f() {}}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..0fa2fbac21 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-for.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {if (true) function f() { } else function _f() {}break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..a4a9497966 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-switch.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;if (true) function f() { } else function _f() {}}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..afae753fb0 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err-try.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {if (true) function f() { } else function _f() {}}\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err.js new file mode 100644 index 0000000000..48b4d66397 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-skip-early-err.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");if (true) function f() { } else function _f() {}assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-update.js new file mode 100644 index 0000000000..418be65581 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-update.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template +/*--- +description: Variable binding value is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "declaration"; } else function _f() {}assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-block-scoping.js new file mode 100644 index 0000000000..f9dd218ded --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-block-scoping.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: A block-scoped binding is created (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'if (false) function _f() {} else function f() { initialBV = f; f = 123; currentBV = f; return "decl"; }' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..8fc96c150c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Does not re-initialize binding created by similar forms (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }if (false) function _f() {} else function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..873b7fdcec --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-block-fn-update.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable-scoped binding is updated (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'if (false) function _f() {} else function f() { return "second declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..9b98e79b16 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-fn-no-init.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");if (false) function _f() {} else function f() { return "inner declaration"; }function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..c796f2885d --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-fn-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (false) function _f() {} else function f() { return "inner declaration"; }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-global-init.js new file mode 100644 index 0000000000..f70c8a72de --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable binding is left in place by legacy function hoisting (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });if (false) function _f() {} else function f() { }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-global-update.js new file mode 100644 index 0000000000..a43f415cd2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-global-update.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'if (false) function _f() {} else function f() { return "function declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..771682c51a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });if (false) function _f() {} else function f() { }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..5fa68bd4ec --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-var-no-init.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);if (false) function _f() {} else function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-var-update.js new file mode 100644 index 0000000000..0ba642d928 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-existing-var-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (false) function _f() {} else function f() { return "function declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-init.js new file mode 100644 index 0000000000..b9764fb934 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });if (false) function _f() {} else function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-no-skip-try.js new file mode 100644 index 0000000000..0dc4019426 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-no-skip-try.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {if (false) function _f() {} else function f() { return 123; }}\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..673a3b14c4 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-block.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;if (false) function _f() {} else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..d32e4846a7 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for-in.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {if (false) function _f() {} else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..8906db6b0e --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for-of.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {if (false) function _f() {} else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..9f871505a2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-for.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {if (false) function _f() {} else function f() { }break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..e9b0a9a32a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-switch.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;if (false) function _f() {} else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..07d3c36894 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err-try.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {if (false) function _f() {} else function f() { }}\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err.js new file mode 100644 index 0000000000..a324b1b1e3 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-skip-early-err.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");if (false) function _f() {} else function f() { }assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-update.js new file mode 100644 index 0000000000..3c5e3643cf --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-decl-b-eval-global-update.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-b.template +/*--- +description: Variable binding value is updated following evaluation (IfStatement with a declaration in both statement positions in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (false) function _f() {} else function f() { return "declaration"; }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-block-scoping.js new file mode 100644 index 0000000000..42be9b1467 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-block-scoping.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: A block-scoped binding is created (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'if (true) function f() { initialBV = f; f = 123; currentBV = f; return "decl"; } else ;' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..8f547b4aba --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Does not re-initialize binding created by similar forms (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }if (true) function f() { } else ;' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..4e4c6f7549 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-block-fn-update.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable-scoped binding is updated (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'if (true) function f() { return "second declaration"; } else ;' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..0dce1c9149 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-fn-no-init.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");if (true) function f() { return "inner declaration"; } else ;function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..e150620612 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-fn-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "inner declaration"; } else ;assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-global-init.js new file mode 100644 index 0000000000..eb57ab56ab --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable binding is left in place by legacy function hoisting (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });if (true) function f() { } else ;' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-global-update.js new file mode 100644 index 0000000000..db469b6aa4 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-global-update.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'if (true) function f() { return "function declaration"; } else ;' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..33658df992 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });if (true) function f() { } else ;' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..cc63ca1f1a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-var-no-init.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);if (true) function f() { } else ;' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-var-update.js new file mode 100644 index 0000000000..d2b1f06fc0 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-existing-var-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "function declaration"; } else ;' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-init.js new file mode 100644 index 0000000000..f060b0924b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });if (true) function f() { } else ;' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-no-skip-try.js new file mode 100644 index 0000000000..3f0cf3f2d2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-no-skip-try.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {if (true) function f() { return 123; } else ;}\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..1b2e82de18 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-block.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;if (true) function f() { } else ;}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..6e748fde84 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for-in.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {if (true) function f() { } else ;}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..f3e8a8c965 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for-of.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {if (true) function f() { } else ;}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..5b3d8b0dda --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-for.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {if (true) function f() { } else ;break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..ff2e160658 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-switch.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;if (true) function f() { } else ;}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..0612d7f5af --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err-try.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {if (true) function f() { } else ;}\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err.js new file mode 100644 index 0000000000..d79c826ff2 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-skip-early-err.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");if (true) function f() { } else ;assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-update.js new file mode 100644 index 0000000000..452aaceff3 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-else-stmt-eval-global-update.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-else-stmt.template +/*--- +description: Variable binding value is updated following evaluation (IfStatement with a declaration in the first statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "declaration"; } else ;assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-block-scoping.js new file mode 100644 index 0000000000..66ba3a21b6 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-block-scoping.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: A block-scoped binding is created (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'if (true) function f() { initialBV = f; f = 123; currentBV = f; return "decl"; }' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..7d6a39a424 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Does not re-initialize binding created by similar forms (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }if (true) function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..b30c10ed7f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-block-fn-update.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable-scoped binding is updated (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'if (true) function f() { return "second declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..185b33268b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-fn-no-init.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Existing variable binding is not modified (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");if (true) function f() { return "inner declaration"; }function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..8bf0e03a7f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-fn-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "inner declaration"; }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-global-init.js new file mode 100644 index 0000000000..1d4b99ce6b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable binding is left in place by legacy function hoisting (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });if (true) function f() { }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-global-update.js new file mode 100644 index 0000000000..8cec9721a6 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-global-update.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'if (true) function f() { return "function declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..f88664333c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });if (true) function f() { }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..b0cd617454 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-var-no-init.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Existing variable binding is not modified (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);if (true) function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-var-update.js new file mode 100644 index 0000000000..96d860be07 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-existing-var-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "function declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-init.js new file mode 100644 index 0000000000..5306f61dcc --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });if (true) function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-no-skip-try.js new file mode 100644 index 0000000000..270e6b0b33 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-no-skip-try.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {if (true) function f() { return 123; }}\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..59392a8c3f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-block.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;if (true) function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..26a27767e3 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for-in.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {if (true) function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..468bfcb30b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for-of.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {if (true) function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..557dcc13ac --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-for.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {if (true) function f() { }break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..c710a3a748 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-switch.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;if (true) function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..93311c721e --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err-try.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {if (true) function f() { }}\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err.js new file mode 100644 index 0000000000..432a0cec8d --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-skip-early-err.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");if (true) function f() { }assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-update.js new file mode 100644 index 0000000000..7128f2eaab --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-decl-no-else-eval-global-update.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-decl-no-else.template +/*--- +description: Variable binding value is updated following evaluation (IfStatement without an else clause in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (true) function f() { return "declaration"; }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-block-scoping.js new file mode 100644 index 0000000000..281ec9a2ef --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-block-scoping.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: A block-scoped binding is created (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'if (false) ; else function f() { initialBV = f; f = 123; currentBV = f; return "decl"; }' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..0eb87a5311 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Does not re-initialize binding created by similar forms (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }if (false) ; else function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..4e22fc5ad4 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-block-fn-update.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable-scoped binding is updated (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'if (false) ; else function f() { return "second declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..1798f83625 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-fn-no-init.js @@ -0,0 +1,31 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");if (false) ; else function f() { return "inner declaration"; }function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..755d56c0d9 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-fn-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (false) ; else function f() { return "inner declaration"; }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-global-init.js new file mode 100644 index 0000000000..a16c613523 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable binding is left in place by legacy function hoisting (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });if (false) ; else function f() { }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-global-update.js new file mode 100644 index 0000000000..bf0750d6b4 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-global-update.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'if (false) ; else function f() { return "function declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..e59344134d --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });if (false) ; else function f() { }' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..249fab4e6b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-var-no-init.js @@ -0,0 +1,30 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Existing variable binding is not modified (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);if (false) ; else function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-var-update.js new file mode 100644 index 0000000000..2eebbf0d0f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-existing-var-update.js @@ -0,0 +1,42 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (false) ; else function f() { return "function declaration"; }' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-init.js new file mode 100644 index 0000000000..bb35c760b3 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-init.js @@ -0,0 +1,39 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });if (false) ; else function f() { }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-no-skip-try.js new file mode 100644 index 0000000000..c53c08d910 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-no-skip-try.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {if (false) ; else function f() { return 123; }}\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..bbf00049aa --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-block.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;if (false) ; else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..d7fedb42e6 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for-in.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {if (false) ; else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..ed49e8a4b1 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for-of.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {if (false) ; else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..b8f9a70732 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-for.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {if (false) ; else function f() { }break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..5469f6c82c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-switch.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;if (false) ; else function f() { }}' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..fdffbd867a --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err-try.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {if (false) ; else function f() { }}\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err.js new file mode 100644 index 0000000000..0002212e06 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-skip-early-err.js @@ -0,0 +1,32 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");if (false) ; else function f() { }assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-update.js new file mode 100644 index 0000000000..6ffd11526b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-if-stmt-else-decl-eval-global-update.js @@ -0,0 +1,38 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-if-stmt-else-decl.template +/*--- +description: Variable binding value is updated following evaluation (IfStatement with a declaration in the second statement position in eval code) +esid: sec-functiondeclarations-in-ifstatement-statement-clauses +flags: [generated, noStrict] +info: | + The following rules for IfStatement augment those in 13.6: + + IfStatement[Yield, Return]: + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] + if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] + if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] + + + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'if (false) ; else function f() { return "declaration"; }assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-block-scoping.js new file mode 100644 index 0000000000..12fd087b47 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-block-scoping.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: A block-scoped binding is created (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'switch (1) {' + + ' case 1:' + + ' function f() { initialBV = f; f = 123; currentBV = f; return "decl"; }' + + '}\ + ' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..411271208f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,28 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Does not re-initialize binding created by similar forms (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + ' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..a30594f3cd --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-block-fn-update.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable-scoped binding is updated (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'switch (1) {' + + ' case 1:' + + ' function f() { return "second declaration"; }' + + '}\ + ' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..8a442f14d1 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-fn-no-init.js @@ -0,0 +1,26 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Existing variable binding is not modified (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");switch (1) {' + + ' case 1:' + + ' function f() { return "inner declaration"; }' + + '}\ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..b4602a7b92 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-fn-update.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable-scoped binding is updated following evaluation (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'switch (1) {' + + ' case 1:' + + ' function f() { return "inner declaration"; }' + + '}\ + assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-global-init.js new file mode 100644 index 0000000000..e19cebf7eb --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-global-init.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable binding is left in place by legacy function hoisting (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + ' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-global-update.js new file mode 100644 index 0000000000..857cabdc91 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-global-update.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable-scoped binding is updated following evaluation (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'switch (1) {' + + ' case 1:' + + ' function f() { return "function declaration"; }' + + '}\ + ' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..0e55e7e1ff --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + ' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..130db94796 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-var-no-init.js @@ -0,0 +1,25 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Existing variable binding is not modified (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + ' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-var-update.js new file mode 100644 index 0000000000..c12fc70170 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-existing-var-update.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable-scoped binding is updated following evaluation (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'switch (1) {' + + ' case 1:' + + ' function f() { return "function declaration"; }' + + '}\ + ' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-init.js new file mode 100644 index 0000000000..2629a27034 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-init.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + ' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-no-skip-try.js new file mode 100644 index 0000000000..6d0e7b9b5c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-no-skip-try.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {switch (1) {' + + ' case 1:' + + ' function f() { return 123; }' + + '}\ + }\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..4c48bd812e --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-block.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..c832db3e5f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for-in.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..1ea7359ea1 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for-of.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..9d3a6fbfec --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-for.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..a9b929ae94 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-switch.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..d58c513efa --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err-try.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + }\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err.js new file mode 100644 index 0000000000..7827b54806 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-skip-early-err.js @@ -0,0 +1,27 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");switch (1) {' + + ' case 1:' + + ' function f() { }' + + '}\ + assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-update.js new file mode 100644 index 0000000000..6bdf8da365 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-case-eval-global-update.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-switch-case.template +/*--- +description: Variable binding value is updated following evaluation (Function declaration in the `case` clause of a `switch` statement in eval code) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'switch (1) {' + + ' case 1:' + + ' function f() { return "declaration"; }' + + '}\ + assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-block-scoping.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-block-scoping.js new file mode 100644 index 0000000000..e844088498 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-block-scoping.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-block-scoping.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: A block-scoped binding is created (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + 13.2.14 Runtime Semantics: BlockDeclarationInstantiation + + [...] + 4. For each element d in declarations do + a. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + [...] + ii. Else, + 2. Perform ! envRec.CreateMutableBinding(dn, false). + + b. If d is a GeneratorDeclaration production or a FunctionDeclaration + production, then + i. Let fn be the sole element of the BoundNames of d. + ii. Let fo be the result of performing InstantiateFunctionObject for + d with argument env. + iii. Perform envRec.InitializeBinding(fn, fo). +---*/ +var initialBV, currentBV; + +(0,eval)( + 'switch (1) {' + + ' default:' + + ' function f() { initialBV = f; f = 123; currentBV = f; return "decl"; }' + + '}\ + ' +); + +f(); + +assert.sameValue( + initialBV(), + 'decl', + 'Block-scoped binding value is function object at execution time' +); +assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable'); +assert.sameValue( + f(), + 'decl', + 'Block-scoped binding is independent of outer var-scoped binding' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-block-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-block-fn-no-init.js new file mode 100644 index 0000000000..084d141e84 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-block-fn-no-init.js @@ -0,0 +1,28 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Does not re-initialize binding created by similar forms (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f, undefined);\ + \ + {\ + function f() {}\ + }switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + ' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-block-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-block-fn-update.js new file mode 100644 index 0000000000..6a2bebe5cb --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-block-fn-update.js @@ -0,0 +1,40 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-block-fn-update.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable-scoped binding is updated (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ +{ + function f() { + return 'first declaration'; + } +} + +(0,eval)( + 'switch (1) {' + + ' default:' + + ' function f() { return "second declaration"; }' + + '}\ + ' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'second declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-fn-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-fn-no-init.js new file mode 100644 index 0000000000..0ce42cabab --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-fn-no-init.js @@ -0,0 +1,26 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-no-init.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Existing variable binding is not modified (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'assert.sameValue(f(), "outer declaration");switch (1) {' + + ' default:' + + ' function f() { return "inner declaration"; }' + + '}\ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-fn-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-fn-update.js new file mode 100644 index 0000000000..5229335927 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-fn-update.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-fn-update.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable-scoped binding is updated following evaluation (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'switch (1) {' + + ' default:' + + ' function f() { return "inner declaration"; }' + + '}\ + assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "inner declaration");\ + \ + function f() {\ + return "outer declaration";\ + }' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-global-init.js new file mode 100644 index 0000000000..d6f470f684 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-global-init.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-init.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable binding is left in place by legacy function hoisting (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: false\ + }, { restore: true });switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + ' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, "f", { + enumerable: true, + writable: true, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-global-update.js new file mode 100644 index 0000000000..90813461da --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-global-update.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-global-update.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable-scoped binding is updated following evaluation (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: function() { return 'Another function'; }, + enumerable: true, + writable: true, + configurable: false +}); + +(0,eval)( + 'switch (1) {' + + ' default:' + + ' function f() { return "function declaration"; }' + + '}\ + ' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-non-enumerable-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-non-enumerable-global-init.js new file mode 100644 index 0000000000..f1efedc74d --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-non-enumerable-global-init.js @@ -0,0 +1,47 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true). + [...] + +---*/ +Object.defineProperty(fnGlobalObject(), 'f', { + value: 'x', + enumerable: false, + writable: true, + configurable: true +}); + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, "x", "binding is not reinitialized");\ + \ + verifyProperty(global, "f", {\ + enumerable: false,\ + writable: true,\ + configurable: true\ + }, { restore: true });switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + ' +); + +assert.sameValue(typeof f, "function"); +verifyProperty(global, 'f', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-var-no-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-var-no-init.js new file mode 100644 index 0000000000..af7dde5d00 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-var-no-init.js @@ -0,0 +1,25 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-no-init.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Existing variable binding is not modified (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + a. If declaredFunctionOrVarNames does not contain F, then + [...] +---*/ + +(0,eval)( + 'var f = 123;\ + assert.sameValue(f, 123);switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + ' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-var-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-var-update.js new file mode 100644 index 0000000000..9bcc7f911f --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-existing-var-update.js @@ -0,0 +1,37 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-existing-var-update.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable-scoped binding is updated following evaluation (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'switch (1) {' + + ' default:' + + ' function f() { return "function declaration"; }' + + '}\ + ' +); + +assert.sameValue(typeof f, 'function'); +assert.sameValue(f(), 'function declaration'); + +var f = 123; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-init.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-init.js new file mode 100644 index 0000000000..944f136303 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-init.js @@ -0,0 +1,34 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-init.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable binding is initialized to `undefined` in outer scope (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +includes: [fnGlobalObject.js, propertyHelper.js] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + i. If varEnvRec is a global Environment Record, then + i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true). + [...] + +---*/ + +(0,eval)( + 'var global = fnGlobalObject();\ + assert.sameValue(f, undefined, "binding is initialized to `undefined`");\ + \ + verifyProperty(global, "f", {\ + enumerable: true,\ + writable: true,\ + configurable: true\ + });switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + ' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-no-skip-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-no-skip-try.js new file mode 100644 index 0000000000..169b929df1 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-no-skip-try.js @@ -0,0 +1,48 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-no-skip-try.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension is observed when creation of variable binding would not produce an early error (try statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.sameValue(\ + f, undefined, "Initialized binding created prior to evaluation"\ + );\ + \ + try {\ + throw null;\ + } catch (f) {switch (1) {' + + ' default:' + + ' function f() { return 123; }' + + '}\ + }\ + \ + assert.sameValue(\ + typeof f,\ + "function",\ + "binding value is updated following evaluation"\ + );\ + assert.sameValue(f(), 123);' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-block.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-block.js new file mode 100644 index 0000000000..6eb580a334 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-block.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-block.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Block statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + '{\ + let f = 123;switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for-in.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for-in.js new file mode 100644 index 0000000000..cd97de3069 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for-in.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-in.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f in { key: 0 }) {switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for-of.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for-of.js new file mode 100644 index 0000000000..954727e550 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for-of.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for-of.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for-of statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f of [0]) {switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for.js new file mode 100644 index 0000000000..504b53166b --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-for.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-for.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (for statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'for (let f; ; ) {switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + break;\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-switch.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-switch.js new file mode 100644 index 0000000000..76eb99d49c --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-switch.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-switch.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (switch statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created prior to evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created prior to evaluation' +); + +(0,eval)( + 'switch (0) {\ + default:\ + let f;switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + }' +); + +assert.throws(ReferenceError, function() { + f; +}, 'An initialized binding is not created following evaluation'); +assert.sameValue( + typeof f, + 'undefined', + 'An uninitialized binding is not created following evaluation' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-try.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-try.js new file mode 100644 index 0000000000..6082a67782 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err-try.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err-try.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension is not observed when creation of variable binding would produce an early error (try statement) (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] + + B.3.5 VariableStatements in Catch Blocks + + [...] + - It is a Syntax Error if any element of the BoundNames of CatchParameter + also occurs in the VarDeclaredNames of Block unless CatchParameter is + CatchParameter:BindingIdentifier and that element is only bound by a + VariableStatement, the VariableDeclarationList of a for statement, or the + ForBinding of a for-in statement. +---*/ + +(0,eval)( + 'assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created prior to evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created prior to evaluation"\ + );\ + \ + try {\ + throw {};\ + } catch ({ f }) {switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + }\ + \ + assert.throws(ReferenceError, function() {\ + f;\ + }, "An initialized binding is not created following evaluation");\ + assert.sameValue(\ + typeof f,\ + "undefined",\ + "An uninitialized binding is not created following evaluation"\ + );' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err.js new file mode 100644 index 0000000000..83737f47a6 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-skip-early-err.js @@ -0,0 +1,27 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-skip-early-err.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Extension not observed when creation of variable binding would produce an early error (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + ii. If replacing the FunctionDeclaration f with a VariableStatement that + has F as a BindingIdentifier would not produce any Early Errors for + body, then + [...] +---*/ + +(0,eval)( + 'let f = 123;\ + assert.sameValue(f, 123, "binding is not initialized to `undefined`");switch (1) {' + + ' default:' + + ' function f() { }' + + '}\ + assert.sameValue(f, 123, "value is not updated following evaluation");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-update.js b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-update.js new file mode 100644 index 0000000000..052721cb11 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/global-switch-dflt-eval-global-update.js @@ -0,0 +1,33 @@ +// This file was procedurally generated from the following sources: +// - src/annex-b-fns/eval-global-update.case +// - src/annex-b-fns/eval-global/indirect-switch-dflt.template +/*--- +description: Variable binding value is updated following evaluation (Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope) +esid: sec-web-compat-evaldeclarationinstantiation +flags: [generated, noStrict] +info: | + B.3.3.3 Changes to EvalDeclarationInstantiation + + [...] + b. When the FunctionDeclaration f is evaluated, perform the following steps + in place of the FunctionDeclaration Evaluation algorithm provided in + 14.1.21: + i. Let genv be the running execution context's VariableEnvironment. + ii. Let genvRec be genv's EnvironmentRecord. + iii. Let benv be the running execution context's LexicalEnvironment. + iv. Let benvRec be benv's EnvironmentRecord. + v. Let fobj be ! benvRec.GetBindingValue(F, false). + vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). + vii. Return NormalCompletion(empty). +---*/ + +(0,eval)( + 'switch (1) {' + + ' default:' + + ' function f() { return "declaration"; }' + + '}\ + assert.sameValue(typeof f, "function");\ + assert.sameValue(f(), "declaration");' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/annexB/language/eval-code/indirect/shell.js b/js/src/tests/test262/annexB/language/eval-code/indirect/shell.js new file mode 100644 index 0000000000..d8963d9d60 --- /dev/null +++ b/js/src/tests/test262/annexB/language/eval-code/indirect/shell.js @@ -0,0 +1,14 @@ +// GENERATED, DO NOT EDIT +// file: fnGlobalObject.js +// Copyright (C) 2017 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Produce a reliable global object +defines: [fnGlobalObject] +---*/ + +var __globalObject = Function("return this;")(); +function fnGlobalObject() { + return __globalObject; +} |