From 6e6516a55893dce6895a4cf35989dbeaf94c9bba Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 11 Sep 2020 15:06:37 -0400 Subject: [PATCH] Switch: lexical declarations inner scope. Fixes gh-422 --- .../switch/scope-lex-async-function.js | 22 +++++++++++++++++++ .../switch/scope-lex-async-generator.js | 22 +++++++++++++++++++ .../statements/switch/scope-lex-class.js | 22 +++++++++++++++++++ .../statements/switch/scope-lex-const.js | 22 +++++++++++++++++++ .../statements/switch/scope-lex-generator.js | 22 +++++++++++++++++++ .../statements/switch/scope-lex-let.js | 22 +++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 test/language/statements/switch/scope-lex-async-function.js create mode 100644 test/language/statements/switch/scope-lex-async-generator.js create mode 100644 test/language/statements/switch/scope-lex-class.js create mode 100644 test/language/statements/switch/scope-lex-const.js create mode 100644 test/language/statements/switch/scope-lex-generator.js create mode 100644 test/language/statements/switch/scope-lex-let.js diff --git a/test/language/statements/switch/scope-lex-async-function.js b/test/language/statements/switch/scope-lex-async-function.js new file mode 100644 index 0000000000..2dab4d44ba --- /dev/null +++ b/test/language/statements/switch/scope-lex-async-function.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-switch-statement-runtime-semantics-evaluation +description: Creation of new lexical environment (into `default` clause) +info: | + 1. Let exprRef be the result of evaluating Expression. + 2. Let switchValue be ? GetValue(exprRef). + 3. Let oldEnv be the running execution context's LexicalEnvironment. + 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). + 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). + 6. Set the running execution context's LexicalEnvironment to blockEnv. + 7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + [...] +negative: + phase: runtime + type: ReferenceError +---*/ + +switch (0) { default: async function x() {} } +x; diff --git a/test/language/statements/switch/scope-lex-async-generator.js b/test/language/statements/switch/scope-lex-async-generator.js new file mode 100644 index 0000000000..e5c21e668a --- /dev/null +++ b/test/language/statements/switch/scope-lex-async-generator.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-switch-statement-runtime-semantics-evaluation +description: Creation of new lexical environment (into `default` clause) +info: | + 1. Let exprRef be the result of evaluating Expression. + 2. Let switchValue be ? GetValue(exprRef). + 3. Let oldEnv be the running execution context's LexicalEnvironment. + 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). + 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). + 6. Set the running execution context's LexicalEnvironment to blockEnv. + 7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + [...] +negative: + phase: runtime + type: ReferenceError +---*/ + +switch (0) { default: async function * x() {} } +x; diff --git a/test/language/statements/switch/scope-lex-class.js b/test/language/statements/switch/scope-lex-class.js new file mode 100644 index 0000000000..9be8cdce75 --- /dev/null +++ b/test/language/statements/switch/scope-lex-class.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-switch-statement-runtime-semantics-evaluation +description: Creation of new lexical environment (into `default` clause) +info: | + 1. Let exprRef be the result of evaluating Expression. + 2. Let switchValue be ? GetValue(exprRef). + 3. Let oldEnv be the running execution context's LexicalEnvironment. + 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). + 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). + 6. Set the running execution context's LexicalEnvironment to blockEnv. + 7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + [...] +negative: + phase: runtime + type: ReferenceError +---*/ + +switch (0) { default: class x {} } +x; diff --git a/test/language/statements/switch/scope-lex-const.js b/test/language/statements/switch/scope-lex-const.js new file mode 100644 index 0000000000..c0746f0adc --- /dev/null +++ b/test/language/statements/switch/scope-lex-const.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-switch-statement-runtime-semantics-evaluation +description: Creation of new lexical environment (into `default` clause) +info: | + 1. Let exprRef be the result of evaluating Expression. + 2. Let switchValue be ? GetValue(exprRef). + 3. Let oldEnv be the running execution context's LexicalEnvironment. + 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). + 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). + 6. Set the running execution context's LexicalEnvironment to blockEnv. + 7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + [...] +negative: + phase: runtime + type: ReferenceError +---*/ + +switch (0) { default: const x = 1; } +x; diff --git a/test/language/statements/switch/scope-lex-generator.js b/test/language/statements/switch/scope-lex-generator.js new file mode 100644 index 0000000000..007ca9f349 --- /dev/null +++ b/test/language/statements/switch/scope-lex-generator.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-switch-statement-runtime-semantics-evaluation +description: Creation of new lexical environment (into `default` clause) +info: | + 1. Let exprRef be the result of evaluating Expression. + 2. Let switchValue be ? GetValue(exprRef). + 3. Let oldEnv be the running execution context's LexicalEnvironment. + 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). + 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). + 6. Set the running execution context's LexicalEnvironment to blockEnv. + 7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + [...] +negative: + phase: runtime + type: ReferenceError +---*/ + +switch (0) { default: function * x() {} } +x; diff --git a/test/language/statements/switch/scope-lex-let.js b/test/language/statements/switch/scope-lex-let.js new file mode 100644 index 0000000000..ac466d7b09 --- /dev/null +++ b/test/language/statements/switch/scope-lex-let.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-switch-statement-runtime-semantics-evaluation +description: Creation of new lexical environment (into `default` clause) +info: | + 1. Let exprRef be the result of evaluating Expression. + 2. Let switchValue be ? GetValue(exprRef). + 3. Let oldEnv be the running execution context's LexicalEnvironment. + 4. Let blockEnv be NewDeclarativeEnvironment(oldEnv). + 5. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv). + 6. Set the running execution context's LexicalEnvironment to blockEnv. + 7. Let R be the result of performing CaseBlockEvaluation of CaseBlock with + argument switchValue. + [...] +negative: + phase: runtime + type: ReferenceError +---*/ + +switch (0) { default: /*{ body }*/ } +f;