Merge pull request #587 from bocoup/generation-annexb-fns

Add tests for Annex B "function in block" semantics (procedurally generated)
This commit is contained in:
Leo Balter 2016-05-31 17:45:48 -04:00
commit 1e75730d5f
557 changed files with 19728 additions and 10 deletions

View File

@ -0,0 +1,44 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: A block-scoped binding is created
template: eval-func
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).
---*/
//- setup
var initialBV, currentBV, varBinding;
//- body
initialBV = f; f = 123; currentBV = f; return 'decl';
//- after
varBinding = f;
f();
//- teardown
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(
varBinding(),
'decl',
'Block-scoped binding is independent of outer var-scoped binding'
);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Does not re-initialize binding created by similar forms
template: eval-func
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
//- setup
var init;
//- before
init = f;
{
function f() {}
}
//- teardown
assert.sameValue(init, undefined);

View File

@ -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.
/*---
desc: Variable-scoped binding is updated
template: eval-func
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).
---*/
//- setup
var updated;
//- before
{
function f() {
return 'first declaration';
}
}
//- body
return 'second declaration';
//- after
updated = f;
//- teardown
assert.sameValue(typeof updated, 'function');
assert.sameValue(updated(), 'second declaration');

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Existing variable binding is not modified
template: eval-func
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).
---*/
//- setup
var init;
//- before
init = f;
//- body
return 'inner declaration';
//- after
function f() {
return 'outer declaration';
}
//- teardown
assert.sameValue(init(), 'outer declaration');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: eval-func
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).
---*/
//- setup
var after;
//- body
return 'inner declaration';
//- after
after = f;
function f() {
return 'outer declaration';
}
//- teardown
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'inner declaration');

View File

@ -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.
/*---
desc: Existing variable binding is not modified
template: eval-func
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
//- setup
var init;
//- before
var f = 123;
init = f;
//- teardown
assert.sameValue(init, 123);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: eval-func
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).
---*/
//- setup
var after;
//- body
return 'function declaration';
//- after
after = f;
var f = 123;
//- teardown
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'function declaration');

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding is initialized to `undefined` in outer scope
template: eval-func
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
i. If varEnvRec is a global Environment Record, then
[...]
ii. Else,
i. Let bindingExists be varEnvRec.HasBinding(F).
ii. If bindingExists is false, then
i. Perform ! varEnvRec.CreateMutableBinding(F, true).
ii. Perform ! varEnvRec.InitializeBinding(F, undefined).
[...]
---*/
//- setup
var init, changed;
//- before
init = f;
f = 123;
changed = f;
//- teardown
assert.sameValue(init, undefined, 'binding is initialized to `undefined`');
assert.sameValue(changed, 123, 'binding is mutable');
assert.throws(ReferenceError, function() {
f;
}, 'global binding is not created');

View File

@ -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.
/*---
desc: >
Extension observed when there is a formal parameter with the same name
template: eval-func
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
[...]
---*/
//- setup
var init, after;
//- params
f
//- args
123
//- before
init = f;
//- after
after = f;
//- teardown
assert.sameValue(init, 123, 'binding is not initialized to `undefined`');
assert.sameValue(
typeof after, 'function', 'value is updated following evaluation'
);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Extension not observed when creation of variable binding would produce an
early error
template: eval-func
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
[...]
---*/
//- setup
var init, after;
//- before
let f = 123;
init = f;
//- after
after = f;
//- teardown
assert.sameValue(init, 123, 'binding is not initialized to `undefined`');
assert.sameValue(after, 123, 'value is not updated following evaluation');

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding value is updated following evaluation
template: eval-func
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).
---*/
//- setup
var after;
//- body
return 'declaration';
//- after
after = f;
//- teardown
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'declaration');

View File

@ -0,0 +1,15 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/func-block-decl-
name: Block statement in eval code containing a function declaration
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/{ function f() { /*{ body }*/ } }/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/func-if-decl-else-decl-a-
name: IfStatement with a declaration in both statement positions in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/if (true) function f() { /*{ body }*/ } else function _f() {}/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/func-if-decl-else-decl-b-
name: IfStatement with a declaration in both statement positions in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/if (false) function _f() {} else function f() { /*{ body }*/ }/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/func-if-decl-else-stmt-
name: IfStatement with a declaration in the first statement position in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/if (true) function f() { /*{ body }*/ } else ;/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/func-if-decl-no-else-
name: IfStatement without an else clause in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/if (true) function f() { /*{ body }*/ }/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/func-if-stmt-else-decl-
name: IfStatement with a declaration in the second statement position in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/if (false) ; else function f() { /*{ body }*/ }/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/eval-code/direct/func-switch-case-
name: >
Function declaration in the `case` clause of a `switch` statement in eval code
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/switch (1) {' +
' case 1:' +
' function f() { /*{ body }*/ }' +
'}\
/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/eval-code/direct/func-switch-dflt-
name: >
Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
(function(/*{ params }*/) {
eval(
'/*{ before }*/switch (1) {' +
' default:' +
' function f() { /*{ body }*/ }' +
'}\
/*{ after }*/'
);
}(/*{ args }*/));

View File

@ -0,0 +1,42 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: A block-scoped binding is created
template: eval-global
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).
---*/
//- setup
var initialBV, currentBV;
//- body
initialBV = f; f = 123; currentBV = f; return 'decl';
//- teardown
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'
);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Does not re-initialize binding created by similar forms
template: eval-global
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
//- before
assert.sameValue(f, undefined);
{
function f() {}
}

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated
template: eval-global
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).
---*/
//- setup
{
function f() {
return 'first declaration';
}
}
//- body
return 'second declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'second declaration');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Existing variable binding is not modified
template: eval-global
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
//- before
assert.sameValue(f(), 'outer declaration');
//- body
return 'inner declaration';
//- after
function f() {
return 'outer declaration';
}

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: eval-global
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).
---*/
//- body
return 'inner declaration';
//- after
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'inner declaration');
function f() {
return 'outer declaration';
}

View File

@ -0,0 +1,39 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding is set to `undefined`
template: eval-global
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
i. If varEnvRec is a global Environment Record, then
i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true).
[...]
8.1.1.4.18 CreateGlobalFunctionBinding
[...]
5. If existingProp is undefined or existingProp.[[Configurable]] is true,
then
[...]
6. Else,
a. Let desc be the PropertyDescriptor{[[Value]]: V }.
[...]
includes: [fnGlobalObject.js, propertyHelper.js]
---*/
//- setup
Object.defineProperty(fnGlobalObject(), 'f', {
value: 'x',
enumerable: true,
writable: true,
configurable: false
});
//- before
var global = fnGlobalObject();
assert.sameValue(f, undefined, "binding is initialized to `undefined`");
verifyEnumerable(global, "f");
verifyWritable(global, "f");
verifyNotConfigurable(global, "f");

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: eval-global
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).
includes: [fnGlobalObject.js]
---*/
//- setup
Object.defineProperty(fnGlobalObject(), 'f', {
value: function() { return 'Another function'; },
enumerable: true,
writable: true,
configurable: false
});
//- body
return 'function declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'function declaration');

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Existing variable binding is not modified
template: eval-global
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
//- before
var f = 123;
assert.sameValue(f, 123);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: eval-global
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).
---*/
//- body
return 'function declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'function declaration');
var f = 123;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding is initialized to `undefined` in outer scope
template: eval-global
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
i. If varEnvRec is a global Environment Record, then
i. Perform ? varEnvRec.CreateGlobalFunctionBinding(F, undefined, true).
[...]
includes: [fnGlobalObject.js, propertyHelper.js]
---*/
//- before
var global = fnGlobalObject();
assert.sameValue(f, undefined, "binding is initialized to `undefined`");
verifyEnumerable(global, "f");
verifyWritable(global, "f");
verifyConfigurable(global, "f");

View File

@ -0,0 +1,22 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Extension not observed when creation of variable binding would produce an
early error
template: eval-global
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
[...]
---*/
//- before
let f = 123;
assert.sameValue(f, 123, 'binding is not initialized to `undefined`');
//- after
assert.sameValue(f, 123, 'value is not updated following evaluation');

View File

@ -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.
/*---
desc: Variable binding value is updated following evaluation
template: eval-global
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).
---*/
//- body
return 'declaration';
//- after
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'declaration');

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-block-decl-
name: Block statement in eval code containing a function declaration
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
eval(
'/*{ before }*/{ function f() { /*{ body }*/ } }/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-if-decl-else-decl-a-
name: IfStatement with a declaration in both statement positions in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.3
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]
flags: [noStrict]
---*/
eval(
'/*{ before }*/if (true) function f() { /*{ body }*/ } else function _f() {}/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-if-decl-else-decl-b-
name: IfStatement with a declaration in both statement positions in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
eval(
'/*{ before }*/if (false) function _f() {} else function f() { /*{ body }*/ }/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-if-decl-else-stmt-
name: IfStatement with a declaration in the first statement position in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
eval(
'/*{ before }*/if (true) function f() { /*{ body }*/ } else ;/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-if-decl-no-else-
name: IfStatement without an else clause in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
eval(
'/*{ before }*/if (true) function f() { /*{ body }*/ }/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-if-stmt-else-decl-
name: IfStatement with a declaration in the second statement position in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
eval(
'/*{ before }*/if (false) ; else function f() { /*{ body }*/ }/*{ after }*/'
);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-switch-case-
name: >
Function declaration in the `case` clause of a `switch` statement in eval code
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
eval(
'/*{ before }*/switch (1) {' +
' case 1:' +
' function f() { /*{ body }*/ }' +
'}\
/*{ after }*/'
);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/direct/global-switch-dflt-
name: >
Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
eval(
'/*{ before }*/switch (1) {' +
' default:' +
' function f() { /*{ body }*/ }' +
'}\
/*{ after }*/'
);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-block-decl-
name: Block statement in eval code containing a function declaration
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/{ function f() { /*{ body }*/ } }/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-if-decl-else-decl-a-
name: IfStatement with a declaration in both statement positions in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.3
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]
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/if (true) function f() { /*{ body }*/ } else function _f() {}/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-if-decl-else-decl-b-
name: IfStatement with a declaration in both statement positions in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/if (false) function _f() {} else function f() { /*{ body }*/ }/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-if-decl-else-stmt-
name: IfStatement with a declaration in the first statement position in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/if (true) function f() { /*{ body }*/ } else ;/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-if-decl-no-else-
name: IfStatement without an else clause in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/if (true) function f() { /*{ body }*/ }/*{ after }*/'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-if-stmt-else-decl-
name: IfStatement with a declaration in the second statement position in eval code
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/if (false) ; else function f() { /*{ body }*/ }/*{ after }*/'
);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-switch-case-
name: >
Function declaration in the `case` clause of a `switch` statement in eval code
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/switch (1) {' +
' case 1:' +
' function f() { /*{ body }*/ }' +
'}\
/*{ after }*/'
);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/eval-code/indirect/global-switch-dflt-
name: >
Funtion declaration in the `default` clause of a `switch` statement in eval code in the global scope
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [noStrict]
---*/
(0,eval)(
'/*{ before }*/switch (1) {' +
' default:' +
' function f() { /*{ body }*/ }' +
'}\
/*{ after }*/'
);

View File

@ -0,0 +1,44 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: A block-scoped binding is created
template: func
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).
---*/
//- setup
var initialBV, currentBV, varBinding;
//- body
initialBV = f; f = 123; currentBV = f; return 'decl';
//- after
varBinding = f;
f();
//- teardown
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(
varBinding(),
'decl',
'Block-scoped binding is independent of outer var-scoped binding'
);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Does not re-initialize binding created by similar forms
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
2. If instantiatedVarNames does not contain F, then
[...]
---*/
//- setup
var init;
//- before
init = f;
{
function f() {}
}
//- teardown
assert.sameValue(init, undefined);

View File

@ -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.
/*---
desc: Variable-scoped binding is updated
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
3. When the FunctionDeclaration f is evaluated, perform the following steps
in place of the FunctionDeclaration Evaluation algorithm provided in
14.1.21:
a. Let fenv be the running execution context's VariableEnvironment.
b. Let fenvRec be fenv's EnvironmentRecord.
c. Let benv be the running execution context's LexicalEnvironment.
d. Let benvRec be benv's EnvironmentRecord.
e. Let fobj be ! benvRec.GetBindingValue(F, false).
f. Perform ! fenvRec.SetMutableBinding(F, fobj, false).
g. Return NormalCompletion(empty).
---*/
//- setup
var updated;
//- before
{
function f() {
return 'first declaration';
}
}
//- body
return 'second declaration';
//- after
updated = f;
//- teardown
assert.sameValue(typeof updated, 'function');
assert.sameValue(updated(), 'second declaration');

View File

@ -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.
/*---
desc: Existing variable binding is not modified
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
2. If instantiatedVarNames does not contain F, then
[...]
---*/
//- setup
var init;
//- before
init = f;
//- body
return 'inner declaration';
//- after
function f() {
return 'outer declaration';
}
//- teardown
assert.sameValue(init(), 'outer declaration');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
3. When the FunctionDeclaration f is evaluated, perform the following steps
in place of the FunctionDeclaration Evaluation algorithm provided in
14.1.21:
a. Let fenv be the running execution context's VariableEnvironment.
b. Let fenvRec be fenv's EnvironmentRecord.
c. Let benv be the running execution context's LexicalEnvironment.
d. Let benvRec be benv's EnvironmentRecord.
e. Let fobj be ! benvRec.GetBindingValue(F, false).
f. Perform ! fenvRec.SetMutableBinding(F, fobj, false).
g. Return NormalCompletion(empty).
---*/
//- setup
var after;
//- body
return 'inner declaration';
//- after
after = f;
function f() {
return 'outer declaration';
}
//- teardown
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'inner declaration');

View File

@ -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.
/*---
desc: Existing variable binding is not modified
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
2. If instantiatedVarNames does not contain F, then
[...]
---*/
//- setup
var init;
//- before
var f = 123;
init = f;
//- teardown
assert.sameValue(init, 123);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
3. When the FunctionDeclaration f is evaluated, perform the following steps
in place of the FunctionDeclaration Evaluation algorithm provided in
14.1.21:
a. Let fenv be the running execution context's VariableEnvironment.
b. Let fenvRec be fenv's EnvironmentRecord.
c. Let benv be the running execution context's LexicalEnvironment.
d. Let benvRec be benv's EnvironmentRecord.
e. Let fobj be ! benvRec.GetBindingValue(F, false).
f. Perform ! fenvRec.SetMutableBinding(F, fobj, false).
g. Return NormalCompletion(empty).
---*/
//- setup
var after;
//- body
return 'function declaration';
//- after
after = f;
var f = 123;
//- teardown
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'function declaration');

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding is initialized to `undefined` in outer scope
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
2. If instantiatedVarNames does not contain F, then
a. Perform ! varEnvRec.CreateMutableBinding(F, false).
b. Perform varEnvRec.InitializeBinding(F, undefined).
c. Append F to instantiatedVarNames.
[...]
---*/
//- setup
var init, changed;
//- before
init = f;
f = 123;
changed = f;
//- teardown
assert.sameValue(init, undefined, 'binding is initialized to `undefined`');
assert.sameValue(changed, 123, 'binding is mutable');
assert.throws(ReferenceError, function() {
f;
}, 'global binding is not created');

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Extension not observed when creation of variable binding would produce an
early error
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
ii. If replacing the FunctionDeclaration f with a VariableStatement that
has F as a BindingIdentifier would not produce any Early Errors for
func and F is not an element of BoundNames of argumentsList, then
[...]
---*/
//- setup
var init, after;
//- before
let f = 123;
init = f;
//- after
after = f;
//- teardown
assert.sameValue(init, 123, 'binding is not initialized to `undefined`');
assert.sameValue(after, 123, 'value is not updated following evaluation');

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Extension not observed when there is a formal parameter with the same name
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
ii. If replacing the FunctionDeclaration f with a VariableStatement that
has F as a BindingIdentifier would not produce any Early Errors for
func and F is not an element of BoundNames of argumentsList, then
[...]
---*/
//- setup
var init, after;
//- params
f
//- args
123
//- before
init = f;
//- after
after = f;
//- teardown
assert.sameValue(init, 123, 'binding is not initialized to `undefined`');
assert.sameValue(after, 123, 'value is not updated following evaluation');

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding value is updated following evaluation
template: func
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
[...]
3. When the FunctionDeclaration f is evaluated, perform the following steps
in place of the FunctionDeclaration Evaluation algorithm provided in
14.1.21:
a. Let fenv be the running execution context's VariableEnvironment.
b. Let fenvRec be fenv's EnvironmentRecord.
c. Let benv be the running execution context's LexicalEnvironment.
d. Let benvRec be benv's EnvironmentRecord.
e. Let fobj be ! benvRec.GetBindingValue(F, false).
f. Perform ! fenvRec.SetMutableBinding(F, fobj, false).
g. Return NormalCompletion(empty).
---*/
//- setup
var after;
//- body
return 'declaration';
//- after
after = f;
//- teardown
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'declaration');

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/function-code/block-decl-
name: Block statement in function scope containing a function declaration
esid: sec-web-compat-functiondeclarationinstantiation
es6id: B.3.3.1
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
{
function f() { /*{ body }*/ }
}
/*{ after }*/
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/function-code/if-decl-else-decl-a-
name: IfStatement with a declaration in both statement positions in function scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
if (true) function f() { /*{ body }*/ } else function _f() {}
/*{ after }*/
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/function-code/if-decl-else-decl-b-
name: IfStatement with a declaration in both statement positions in function scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
if (false) function _f() {} else function f() { /*{ body }*/ }
/*{ after }*/
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/function-code/if-decl-else-stmt-
name: IfStatement with a declaration in the first statement position in function scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
if (true) function f() { /*{ body }*/ } else ;
/*{ after }*/
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/function-code/if-decl-no-else-
name: IfStatement without an else clause in function scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
if (true) function f() { /*{ body }*/ }
/*{ after }*/
}(/*{ args }*/));

View File

@ -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.
/*---
path: annexB/language/function-code/if-stmt-else-decl-
name: IfStatement with a declaration in the second statement position in function scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
if (false) ; else function f() { /*{ body }*/ }
/*{ after }*/
}(/*{ args }*/));

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/function-code/switch-case-
name: >
Function declaration in the `case` clause of a `switch` statement in function scope
esid: sec-web-compat-functiondeclarationinstantiation
es6id: B.3.3.1
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
switch (1) {
case 1:
function f() { /*{ body }*/ }
}
/*{ after }*/
}(/*{ args }*/));

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/function-code/switch-dflt-
name: >
Funtion declaration in the `default` clause of a `switch` statement in function scope
esid: sec-web-compat-functiondeclarationinstantiation
es6id: B.3.3.1
flags: [noStrict]
---*/
(function(/*{ params }*/) {
/*{ before }*/
switch (1) {
default:
function f() { /*{ body }*/ }
}
/*{ after }*/
}(/*{ args }*/));

View File

@ -0,0 +1,42 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: A block-scoped binding is created
template: global
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).
---*/
//- setup
var initialBV, currentBV;
//- body
initialBV = f; f = 123; currentBV = f; return 'decl';
//- teardown
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'
);

View File

@ -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.
/*---
desc: Does not re-initialize binding created by similar forms
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
b. If declaredFunctionOrVarNames does not contain F, then
i. Perform ? envRec.CreateGlobalFunctionBinding(F, undefined, false).
ii. Append F to declaredFunctionOrVarNames.
---*/
//- setup
assert.sameValue(f, undefined);
{
function f() {}
}

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
c. 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.
ii. 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).
---*/
//- setup
{
function f() {
return 'first declaration';
}
}
//- body
return 'second declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'second declaration');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Existing variable binding is not modified
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(F).
2. If fnDefinable is true, then
---*/
//- setup
assert.sameValue(f(), 'outer declaration');
//- body
return 'inner declaration';
//- teardown
function f() {
return 'outer declaration';
}

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
c. 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.
ii. 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).
---*/
//- body
return 'inner declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'inner declaration');
function f() {
return 'outer declaration';
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Existing variable binding is not modified
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
b. If declaredFunctionOrVarNames does not contain F, then
i. Perform ? envRec.CreateGlobalFunctionBinding(F, undefined, false).
ii. Append F to declaredFunctionOrVarNames.
[...]
---*/
//- setup
var f = 123;
assert.sameValue(f, 123);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable-scoped binding is updated following evaluation
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
c. 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.
ii. 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).
---*/
//- body
return 'function declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'function declaration');
var f = 123;

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Variable binding is initialized to `undefined` in outer scope
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
b. If declaredFunctionOrVarNames does not contain F, then
i. Perform ? envRec.CreateGlobalFunctionBinding(F, undefined, false).
ii. Append F to declaredFunctionOrVarNames.
[...]
includes: [fnGlobalObject.js, propertyHelper.js]
---*/
//- setup
var global = fnGlobalObject();
assert.sameValue(f, undefined, 'binding is initialized to `undefined`');
verifyEnumerable(global, 'f');
verifyWritable(global, 'f');
verifyNotConfigurable(global, 'f');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Extension not observed when creation of variable binding would produce an
early error
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
b. If replacing the FunctionDeclaration f with a VariableStatement that has
F as a BindingIdentifier would not produce any Early Errors for script,
then
[...]
---*/
//- setup
let f = 123;
assert.sameValue(f, 123, 'binding is not initialized to `undefined`');
//- teardown
assert.sameValue(f, 123, 'value is not updated following evaluation');

View File

@ -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.
/*---
desc: Variable binding value is updated following evaluation
template: global
info: |
B.3.3.2 Changes to GlobalDeclarationInstantiation
[...]
e. 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).
---*/
//- body
return 'declaration';
//- teardown
assert.sameValue(typeof f, 'function');
assert.sameValue(f(), 'declaration');

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/block-decl-
name: Block statement in the global scope containing a function declaration
esid: sec-web-compat-globaldeclarationinstantiation
es6id: B.3.3.2
flags: [noStrict]
---*/
{
function f() { /*{ body }*/ }
}

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/if-decl-else-decl-a-
name: IfStatement with a declaration in both statement positions in the global scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
if (true) function f() { /*{ body }*/ } else function _f() {}

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/if-decl-else-decl-b-
name: IfStatement with a declaration in both statement positions in the global scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
if (false) function _f() {} else function f() { /*{ body }*/ }

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/if-decl-else-stmt-
name: IfStatement with a declaration in the first statement position in the global scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
if (true) function f() { /*{ body }*/ } else ;

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/if-decl-no-else-
name: IfStatement without an else clause in the global scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
if (true) function f() { /*{ body }*/ }

View File

@ -0,0 +1,19 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/if-stmt-else-decl-
name: IfStatement with a declaration in the second statement position in the global scope
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.4
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]
flags: [noStrict]
---*/
if (false) ; else function f() { /*{ body }*/ }

View File

@ -0,0 +1,15 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/switch-case-
name: >
Function declaration in the `case` clause of a `switch` statement in the global scope
esid: sec-web-compat-globaldeclarationinstantiation
es6id: B.3.3.2
flags: [noStrict]
---*/
switch (1) {
case 1:
function f() { /*{ body }*/ }
}

View File

@ -0,0 +1,15 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: annexB/language/global-code/switch-dflt-
name: >
Funtion declaration in the `default` clause of a `switch` statement in the global scope
esid: sec-web-compat-globaldeclarationinstantiation
es6id: B.3.3.2
flags: [noStrict]
---*/
switch (1) {
default:
function f() { /*{ body }*/ }
}

View File

@ -0,0 +1,47 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-block-scoping.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: A block-scoped binding is created (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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, varBinding;
(function() {
eval(
'{ function f() { initialBV = f; f = 123; currentBV = f; return "decl"; } }varBinding = 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(
varBinding(),
'decl',
'Block-scoped binding is independent of outer var-scoped binding'
);

View File

@ -0,0 +1,28 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-block-fn-no-init.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.3.3
flags: [generated, noStrict]
info: >
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
var init;
(function() {
eval(
'init = f;\
\
{\
function f() {}\
}{ function f() { } }'
);
}());
assert.sameValue(init, undefined);

View File

@ -0,0 +1,37 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-block-fn-update.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Variable-scoped binding is updated (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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).
---*/
var updated;
(function() {
eval(
'{\
function f() {\
return "first declaration";\
}\
}{ function f() { return "second declaration"; } }updated = f;'
);
}());
assert.sameValue(typeof updated, 'function');
assert.sameValue(updated(), 'second declaration');

View File

@ -0,0 +1,34 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-fn-no-init.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Existing variable binding is not modified (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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).
---*/
var init;
(function() {
eval(
'init = f;{ function f() { return "inner declaration"; } }function f() {\
return "outer declaration";\
}'
);
}());
assert.sameValue(init(), 'outer declaration');

View File

@ -0,0 +1,37 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-fn-update.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Variable-scoped binding is updated following evaluation (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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).
---*/
var after;
(function() {
eval(
'{ function f() { return "inner declaration"; } }after = f;\
\
function f() {\
return "outer declaration";\
}'
);
}());
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'inner declaration');

View File

@ -0,0 +1,25 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-var-no-init.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Existing variable binding is not modified (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [generated, noStrict]
info: >
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
[...]
---*/
var init;
(function() {
eval(
'var f = 123;\
init = f;{ function f() { } }'
);
}());
assert.sameValue(init, 123);

View File

@ -0,0 +1,36 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-var-update.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Variable-scoped binding is updated following evaluation (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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).
---*/
var after;
(function() {
eval(
'{ function f() { return "function declaration"; } }after = f;\
\
var f = 123;'
);
}());
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'function declaration');

View File

@ -0,0 +1,37 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-init.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.3.3
flags: [generated, noStrict]
info: >
B.3.3.3 Changes to EvalDeclarationInstantiation
[...]
a. If declaredFunctionOrVarNames does not contain F, then
i. If varEnvRec is a global Environment Record, then
[...]
ii. Else,
i. Let bindingExists be varEnvRec.HasBinding(F).
ii. If bindingExists is false, then
i. Perform ! varEnvRec.CreateMutableBinding(F, true).
ii. Perform ! varEnvRec.InitializeBinding(F, undefined).
[...]
---*/
var init, changed;
(function() {
eval(
'init = f;\
f = 123;\
changed = f;{ function f() { } }'
);
}());
assert.sameValue(init, undefined, 'binding is initialized to `undefined`');
assert.sameValue(changed, 123, 'binding is mutable');
assert.throws(ReferenceError, function() {
f;
}, 'global binding is not created');

View File

@ -0,0 +1,29 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-no-skip-param.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Extension observed when there is a formal parameter with the same name (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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
[...]
---*/
var init, after;
(function(f) {
eval(
'init = f;{ function f() { } }after = f;'
);
}(123));
assert.sameValue(init, 123, 'binding is not initialized to `undefined`');
assert.sameValue(
typeof after, 'function', 'value is updated following evaluation'
);

View File

@ -0,0 +1,28 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-skip-early-err.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.3.3
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
[...]
---*/
var init, after;
(function() {
eval(
'let f = 123;\
init = f;{ function f() { } }after = f;'
);
}());
assert.sameValue(init, 123, 'binding is not initialized to `undefined`');
assert.sameValue(after, 123, 'value is not updated following evaluation');

View File

@ -0,0 +1,33 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-update.case
// - src/annex-b-fns/eval-func/direct-block.template
/*---
description: Variable binding value is updated following evaluation (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
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).
---*/
var after;
(function() {
eval(
'{ function f() { return "declaration"; } }after = f;'
);
}());
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'declaration');

View File

@ -0,0 +1,56 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-block-scoping.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.4
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, varBinding;
(function() {
eval(
'if (true) function f() { initialBV = f; f = 123; currentBV = f; return "decl"; } else function _f() {}varBinding = 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(
varBinding(),
'decl',
'Block-scoped binding is independent of outer var-scoped binding'
);

View File

@ -0,0 +1,37 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-block-fn-no-init.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.4
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
[...]
---*/
var init;
(function() {
eval(
'init = f;\
\
{\
function f() {}\
}if (true) function f() { } else function _f() {}'
);
}());
assert.sameValue(init, undefined);

View File

@ -0,0 +1,46 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-block-fn-update.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.4
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).
---*/
var updated;
(function() {
eval(
'{\
function f() {\
return "first declaration";\
}\
}if (true) function f() { return "second declaration"; } else function _f() {}updated = f;'
);
}());
assert.sameValue(typeof updated, 'function');
assert.sameValue(updated(), 'second declaration');

View File

@ -0,0 +1,43 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-fn-no-init.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.4
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).
---*/
var init;
(function() {
eval(
'init = f;if (true) function f() { return "inner declaration"; } else function _f() {}function f() {\
return "outer declaration";\
}'
);
}());
assert.sameValue(init(), 'outer declaration');

View File

@ -0,0 +1,46 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-func-exsting-fn-update.case
// - src/annex-b-fns/eval-func/direct-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
es6id: B.3.4
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).
---*/
var after;
(function() {
eval(
'if (true) function f() { return "inner declaration"; } else function _f() {}after = f;\
\
function f() {\
return "outer declaration";\
}'
);
}());
assert.sameValue(typeof after, 'function');
assert.sameValue(after(), 'inner declaration');

Some files were not shown because too many files have changed in this diff Show More