From 4766365dc635971b45fb90b961f1cd7f86caedf3 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Mon, 18 Apr 2016 16:01:54 -0400 Subject: [PATCH] Add tests for Annex B.3.3/B.3.4 These tests ensure that the annex B extensions for function declarations are *not* observed in strict mode code. --- .../direct/block-decl-strict-caller.js | 25 ++++++++++++ .../direct/block-decl-strict-source.js | 24 ++++++++++++ .../direct/switch-case-decl-strict-caller.js | 31 +++++++++++++++ .../direct/switch-case-decl-strict-source.js | 31 +++++++++++++++ .../direct/switch-dflt-decl-strict-caller.js | 31 +++++++++++++++ .../direct/switch-dflt-decl-strict-source.js | 31 +++++++++++++++ .../eval-code/indirect/block-decl-strict.js | 24 ++++++++++++ .../indirect/switch-case-decl-strict.js | 31 +++++++++++++++ .../indirect/switch-dflt-decl-strict.js | 31 +++++++++++++++ .../function-code/block-decl-strict.js | 36 ++++++++++++++++++ .../function-code/switch-case-decl-strict.js | 38 +++++++++++++++++++ .../function-code/switch-dflt-decl-strict.js | 38 +++++++++++++++++++ .../language/global-code/block-decl-strict.js | 25 ++++++++++++ .../global-code/switch-case-decl-strict.js | 26 +++++++++++++ .../global-code/switch-dflt-decl-strict.js | 26 +++++++++++++ .../statements/if/if-decl-else-decl-strict.js | 20 ++++++++++ .../statements/if/if-decl-else-stmt-strict.js | 20 ++++++++++ .../statements/if/if-decl-no-else-strict.js | 20 ++++++++++ .../statements/if/if-stmt-else-decl-strict.js | 24 ++++++++++++ 19 files changed, 532 insertions(+) create mode 100644 test/language/eval-code/direct/block-decl-strict-caller.js create mode 100644 test/language/eval-code/direct/block-decl-strict-source.js create mode 100644 test/language/eval-code/direct/switch-case-decl-strict-caller.js create mode 100644 test/language/eval-code/direct/switch-case-decl-strict-source.js create mode 100644 test/language/eval-code/direct/switch-dflt-decl-strict-caller.js create mode 100644 test/language/eval-code/direct/switch-dflt-decl-strict-source.js create mode 100644 test/language/eval-code/indirect/block-decl-strict.js create mode 100644 test/language/eval-code/indirect/switch-case-decl-strict.js create mode 100644 test/language/eval-code/indirect/switch-dflt-decl-strict.js create mode 100644 test/language/function-code/block-decl-strict.js create mode 100644 test/language/function-code/switch-case-decl-strict.js create mode 100644 test/language/function-code/switch-dflt-decl-strict.js create mode 100644 test/language/global-code/block-decl-strict.js create mode 100644 test/language/global-code/switch-case-decl-strict.js create mode 100644 test/language/global-code/switch-dflt-decl-strict.js create mode 100644 test/language/statements/if/if-decl-else-decl-strict.js create mode 100644 test/language/statements/if/if-decl-else-stmt-strict.js create mode 100644 test/language/statements/if/if-decl-no-else-strict.js create mode 100644 test/language/statements/if/if-stmt-else-decl-strict.js diff --git a/test/language/eval-code/direct/block-decl-strict-caller.js b/test/language/eval-code/direct/block-decl-strict-caller.js new file mode 100644 index 0000000000..611364f416 --- /dev/null +++ b/test/language/eval-code/direct/block-decl-strict-caller.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.2 +flags: [onlyStrict] +info: > + Block statement in eval code containing a function declaration + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +eval('{ function f() {} }'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/direct/block-decl-strict-source.js b/test/language/eval-code/direct/block-decl-strict-source.js new file mode 100644 index 0000000000..799a8c8247 --- /dev/null +++ b/test/language/eval-code/direct/block-decl-strict-source.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.2 +info: > + Block statement in eval code containing a function declaration + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +eval('"use strict";{ function f() {} }'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/direct/switch-case-decl-strict-caller.js b/test/language/eval-code/direct/switch-case-decl-strict-caller.js new file mode 100644 index 0000000000..160d554298 --- /dev/null +++ b/test/language/eval-code/direct/switch-case-decl-strict-caller.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +flags: [onlyStrict] +info: > + Function declaration in the `case` clause of a `switch` statement in eval + code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +eval('\ + switch (1) {\ + case 1:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/direct/switch-case-decl-strict-source.js b/test/language/eval-code/direct/switch-case-decl-strict-source.js new file mode 100644 index 0000000000..87c9182514 --- /dev/null +++ b/test/language/eval-code/direct/switch-case-decl-strict-source.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +info: > + Function declaration in the `case` clause of a `switch` statement in eval + code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +eval('\ + "use strict";\ + switch (1) {\ + case 1:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/direct/switch-dflt-decl-strict-caller.js b/test/language/eval-code/direct/switch-dflt-decl-strict-caller.js new file mode 100644 index 0000000000..6134db4e04 --- /dev/null +++ b/test/language/eval-code/direct/switch-dflt-decl-strict-caller.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +flags: [onlyStrict] +info: > + Function declaration in the `default` clause of a `switch` statement in + eval code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +eval('\ + switch (1) {\ + default:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/direct/switch-dflt-decl-strict-source.js b/test/language/eval-code/direct/switch-dflt-decl-strict-source.js new file mode 100644 index 0000000000..d4509e4e48 --- /dev/null +++ b/test/language/eval-code/direct/switch-dflt-decl-strict-source.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +info: > + Function declaration in the `default` clause of a `switch` statement in + eval code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +eval('\ + "use strict";\ + switch (1) {\ + default:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/indirect/block-decl-strict.js b/test/language/eval-code/indirect/block-decl-strict.js new file mode 100644 index 0000000000..98ff47cd74 --- /dev/null +++ b/test/language/eval-code/indirect/block-decl-strict.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.2 +info: > + Block statement in eval code containing a function declaration + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +(0,eval)('"use strict";{ function f() {} }'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/indirect/switch-case-decl-strict.js b/test/language/eval-code/indirect/switch-case-decl-strict.js new file mode 100644 index 0000000000..86d149ddd7 --- /dev/null +++ b/test/language/eval-code/indirect/switch-case-decl-strict.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +info: > + Function declaration in the `case` clause of a `switch` statement in eval + code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +(0,eval)('\ + "use strict";\ + switch (1) {\ + case 1:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/eval-code/indirect/switch-dflt-decl-strict.js b/test/language/eval-code/indirect/switch-dflt-decl-strict.js new file mode 100644 index 0000000000..725c536162 --- /dev/null +++ b/test/language/eval-code/indirect/switch-dflt-decl-strict.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.3 +info: > + Function declaration in the `default` clause of a `switch` statement in + eval code + + B.3.3.3 Changes to EvalDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err; + +(0,eval)('\ + "use strict";\ + switch (1) {\ + default:\ + function f() { }\ + }\ +'); + +try { + f; +} catch (exception) { + err = exception; +} + +assert.sameValue(err.constructor, ReferenceError); diff --git a/test/language/function-code/block-decl-strict.js b/test/language/function-code/block-decl-strict.js new file mode 100644 index 0000000000..0c62079b8f --- /dev/null +++ b/test/language/function-code/block-decl-strict.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.1 +flags: [onlyStrict] +info: > + Block statement in function code containing a function declaration + + B.3.3.1 Changes to FunctionDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err1, err2; + +(function() { + try { + f; + } catch (exception) { + err1 = exception; + } + + { + function f() { } + } + + try { + f; + } catch (exception) { + err2 = exception; + } +}()); + +assert.sameValue(err1.constructor, ReferenceError); +assert.sameValue(err2.constructor, ReferenceError); diff --git a/test/language/function-code/switch-case-decl-strict.js b/test/language/function-code/switch-case-decl-strict.js new file mode 100644 index 0000000000..ea2b52c154 --- /dev/null +++ b/test/language/function-code/switch-case-decl-strict.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.1 +flags: [onlyStrict] +info: > + Function declaration in the `case` clause of a `switch` statement in + function code + + B.3.3.1 Changes to FunctionDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err1, err2; + +(function() { + try { + f; + } catch (exception) { + err1 = exception; + } + + switch (1) { + case 1: + function f() { } + } + + try { + f; + } catch (exception) { + err2 = exception; + } +}()); + +assert.sameValue(err1.constructor, ReferenceError); +assert.sameValue(err2.constructor, ReferenceError); diff --git a/test/language/function-code/switch-dflt-decl-strict.js b/test/language/function-code/switch-dflt-decl-strict.js new file mode 100644 index 0000000000..4569078b36 --- /dev/null +++ b/test/language/function-code/switch-dflt-decl-strict.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode +es6id: B.3.3.1 +flags: [onlyStrict] +info: > + Function declaration in the `default` clause of a `switch` statement in + function code + + B.3.3.1 Changes to FunctionDeclarationInstantiation + + 1. If strict is false, then +---*/ + +var err1, err2; + +(function() { + try { + f; + } catch (exception) { + err1 = exception; + } + + switch (1) { + default: + function f() { } + } + + try { + f; + } catch (exception) { + err2 = exception; + } +}()); + +assert.sameValue(err1.constructor, ReferenceError); +assert.sameValue(err2.constructor, ReferenceError); diff --git a/test/language/global-code/block-decl-strict.js b/test/language/global-code/block-decl-strict.js new file mode 100644 index 0000000000..48c0ef5d94 --- /dev/null +++ b/test/language/global-code/block-decl-strict.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (Block statement in the global scope containing a function declaration) +es6id: B.3.3.2 +flags: [onlyStrict] +info: > + B.3.3.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +assert.throws(ReferenceError, function() { + f; +}); + +{ + function f() { } +} + +assert.throws(ReferenceError, function() { + f; +}); diff --git a/test/language/global-code/switch-case-decl-strict.js b/test/language/global-code/switch-case-decl-strict.js new file mode 100644 index 0000000000..c6a9b46c2d --- /dev/null +++ b/test/language/global-code/switch-case-decl-strict.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (Function declaration in the `case` clause of a `switch` statement in the global scope) +es6id: B.3.3.2 +flags: [onlyStrict] +info: > + B.3.3.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +assert.throws(ReferenceError, function() { + f; +}); + +switch (1) { + case 1: + function f() { } +} + +assert.throws(ReferenceError, function() { + f; +}); diff --git a/test/language/global-code/switch-dflt-decl-strict.js b/test/language/global-code/switch-dflt-decl-strict.js new file mode 100644 index 0000000000..63600a337d --- /dev/null +++ b/test/language/global-code/switch-dflt-decl-strict.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (Funtion declaration in the `default` clause of a `switch` statement in the global scope) +es6id: B.3.3.2 +flags: [onlyStrict] +info: > + B.3.3.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +assert.throws(ReferenceError, function() { + f; +}); + +switch (1) { + default: + function f() { } +} + +assert.throws(ReferenceError, function() { + f; +}); diff --git a/test/language/statements/if/if-decl-else-decl-strict.js b/test/language/statements/if/if-decl-else-decl-strict.js new file mode 100644 index 0000000000..f510ab911e --- /dev/null +++ b/test/language/statements/if/if-decl-else-decl-strict.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (IfStatement with a declaration in both statement positions in the global scope) +es6id: B.3.4 +flags: [onlyStrict] +negative: SyntaxError +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] + + The above rules are only applied when parsing code that is not strict mode code. +---*/ + +if (true) function f() { } else function _f() {} diff --git a/test/language/statements/if/if-decl-else-stmt-strict.js b/test/language/statements/if/if-decl-else-stmt-strict.js new file mode 100644 index 0000000000..3303fdcade --- /dev/null +++ b/test/language/statements/if/if-decl-else-stmt-strict.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (IfStatement with a declaration in the first statement position in the global scope) +es6id: B.3.4 +flags: [onlyStrict] +negative: SyntaxError +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] + + The above rules are only applied when parsing code that is not strict mode code. +---*/ + +if (true) function f() { } else ; diff --git a/test/language/statements/if/if-decl-no-else-strict.js b/test/language/statements/if/if-decl-no-else-strict.js new file mode 100644 index 0000000000..22001387f1 --- /dev/null +++ b/test/language/statements/if/if-decl-no-else-strict.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (IfStatement without an else clause in the global scope) +es6id: B.3.4 +flags: [onlyStrict] +negative: SyntaxError +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] + + The above rules are only applied when parsing code that is not strict mode code. +---*/ + +if (true) function f() { } diff --git a/test/language/statements/if/if-stmt-else-decl-strict.js b/test/language/statements/if/if-stmt-else-decl-strict.js new file mode 100644 index 0000000000..fc7ad50daa --- /dev/null +++ b/test/language/statements/if/if-stmt-else-decl-strict.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (IfStatement with a declaration in the second statement position in the global scope) +es6id: B.3.4 +flags: [onlyStrict] +negative: SyntaxError +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.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +if (false) ; else function f() { }