Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for proposed Annex B semantics #969

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/annex-b-fns/eval-global-existing-global-init.case
@@ -1,25 +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: Variable binding is set to `undefined`
desc: Variable binding is left in place by legacy function hoisting
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).
i. Perform ? varEnvRec.CreateGlobalVarBinding(F, 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]
---*/

Expand All @@ -32,8 +23,15 @@ Object.defineProperty(fnGlobalObject(), 'f', {
});
//- before
var global = fnGlobalObject();
assert.sameValue(f, undefined, "binding is initialized to `undefined`");
assert.sameValue(f, 'x', "binding is not reinitialized");

verifyProperty(global, "f", {
enumerable: true,
writable: true,
configurable: false
}, { restore: true });
//- teardown
assert.sameValue(typeof f, "function");
verifyProperty(global, "f", {
enumerable: true,
writable: true,
Expand Down
@@ -0,0 +1,42 @@
// Copyright (C) 2017 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Variable binding is left in place by legacy function hoisting.
CreateGlobalVariableBinding leaves the binding as non-enumerable even
if it has the chance to change it to be enumerable.
template: eval-global
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation

[...]
i. If varEnvRec is a global Environment Record, then
i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

includes: [fnGlobalObject.js, propertyHelper.js]
---*/

//- setup
Object.defineProperty(fnGlobalObject(), 'f', {
value: 'x',
enumerable: false,
writable: true,
configurable: true
});
//- before
var global = fnGlobalObject();
assert.sameValue(f, 'x', "binding is not reinitialized");

verifyProperty(global, 'f', {
enumerable: false,
writable: true,
configurable: true
}, { restore: true });
//- teardown
assert.sameValue(typeof f, "function");
verifyProperty(global, 'f', {
enumerable: false,
writable: true,
configurable: true
});
49 changes: 49 additions & 0 deletions src/annex-b-fns/global-existing-global-init.case
@@ -0,0 +1,49 @@
// Copyright (C) 2017 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Variable binding is left in place by legacy function hoisting.
CreateGlobalVariableBinding leaves the binding as non-enumerable even
if it has the chance to change it to be enumerable.
template: global
info: |
B.3.3.3 Changes to GlobalDeclarationInstantiation

[...]
Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

includes: [fnGlobalObject.js, propertyHelper.js]
---*/

//- setup
var global = fnGlobalObject();
Object.defineProperty(global, 'f', {
value: 'x',
enumerable: true,
writable: true,
configurable: false
});

$262.evalScript(`
assert.sameValue(f, 'x');
verifyProperty(global, 'f', {
enumerable: true,
writable: true,
configurable: false
}, { restore: true });
`);

$262.evalScript(`
//- body
return 'inner declaration';
//- teardown
`);

$262.evalScript(`
verifyProperty(global, 'f', {
enumerable: true,
writable: true,
configurable: false
});
`);
50 changes: 50 additions & 0 deletions src/annex-b-fns/global-existing-non-enumerable-global-init.case
@@ -0,0 +1,50 @@
// Copyright (C) 2017 Igalia, S. L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: >
Variable binding is left in place by legacy function hoisting.
CreateGlobalVariableBinding leaves the binding as non-enumerable even
if it has the chance to change it to be enumerable.
template: global
info: |
B.3.3.3 Changes to GlobalDeclarationInstantiation

[...]
Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

includes: [fnGlobalObject.js, propertyHelper.js]
---*/

//- setup
var global = fnGlobalObject();
Object.defineProperty(global, 'f', {
value: 'x',
enumerable: false,
writable: true,
configurable: true
});

$262.evalScript(`
assert.sameValue(f, 'x');
verifyProperty(global, 'f', {
enumerable: false,
writable: true,
configurable: true
}, { restore: true });
`);

$262.evalScript(`
//- body
return 'inner declaration';
//- teardown
`);

$262.evalScript(`
assert.sameValue(f(), 'inner declaration');
verifyProperty(global, 'f', {
enumerable: false,
writable: true,
configurable: true
});
`);
Expand Up @@ -2,7 +2,7 @@
// - src/annex-b-fns/eval-global-existing-global-init.case
// - src/annex-b-fns/eval-global/direct-block.template
/*---
description: Variable binding is set to `undefined` (Block statement in eval code containing a function declaration)
description: Variable binding is left in place by legacy function hoisting (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [generated, noStrict]
Expand All @@ -12,17 +12,7 @@ info: |

[...]
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 }.
i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

---*/
Expand All @@ -35,11 +25,18 @@ Object.defineProperty(fnGlobalObject(), 'f', {

eval(
'var global = fnGlobalObject();\
assert.sameValue(f, undefined, "binding is initialized to `undefined`");\
assert.sameValue(f, "x", "binding is not reinitialized");\
\
verifyProperty(global, "f", {\
enumerable: true,\
writable: true,\
configurable: false\
});{ function f() { } }'
}, { restore: true });{ function f() { } }'
);

assert.sameValue(typeof f, "function");
verifyProperty(global, "f", {
enumerable: true,
writable: true,
configurable: false
});
@@ -0,0 +1,42 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case
// - src/annex-b-fns/eval-global/direct-block.template
/*---
description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (Block statement in eval code containing a function declaration)
esid: sec-web-compat-evaldeclarationinstantiation
es6id: B.3.3.3
flags: [generated, noStrict]
includes: [fnGlobalObject.js, propertyHelper.js]
info: |
B.3.3.3 Changes to EvalDeclarationInstantiation

[...]
i. If varEnvRec is a global Environment Record, then
i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

---*/
Object.defineProperty(fnGlobalObject(), 'f', {
value: 'x',
enumerable: false,
writable: true,
configurable: true
});

eval(
'var global = fnGlobalObject();\
assert.sameValue(f, "x", "binding is not reinitialized");\
\
verifyProperty(global, "f", {\
enumerable: false,\
writable: true,\
configurable: true\
}, { restore: true });{ function f() { } }'
);

assert.sameValue(typeof f, "function");
verifyProperty(global, 'f', {
enumerable: false,
writable: true,
configurable: true
});
Expand Up @@ -2,7 +2,7 @@
// - src/annex-b-fns/eval-global-existing-global-init.case
// - src/annex-b-fns/eval-global/direct-if-decl-else-decl-a.template
/*---
description: Variable binding is set to `undefined` (IfStatement with a declaration in both statement positions in eval code)
description: Variable binding is left in place by legacy function hoisting (IfStatement with a declaration in both statement positions in eval code)
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.3
flags: [generated, noStrict]
Expand All @@ -21,17 +21,7 @@ info: |

[...]
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 }.
i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

---*/
Expand All @@ -44,11 +34,18 @@ Object.defineProperty(fnGlobalObject(), 'f', {

eval(
'var global = fnGlobalObject();\
assert.sameValue(f, undefined, "binding is initialized to `undefined`");\
assert.sameValue(f, "x", "binding is not reinitialized");\
\
verifyProperty(global, "f", {\
enumerable: true,\
writable: true,\
configurable: false\
});if (true) function f() { } else function _f() {}'
}, { restore: true });if (true) function f() { } else function _f() {}'
);

assert.sameValue(typeof f, "function");
verifyProperty(global, "f", {
enumerable: true,
writable: true,
configurable: false
});
@@ -0,0 +1,51 @@
// This file was procedurally generated from the following sources:
// - src/annex-b-fns/eval-global-existing-non-enumerable-global-init.case
// - src/annex-b-fns/eval-global/direct-if-decl-else-decl-a.template
/*---
description: Variable binding is left in place by legacy function hoisting. CreateGlobalVariableBinding leaves the binding as non-enumerable even if it has the chance to change it to be enumerable. (IfStatement with a declaration in both statement positions in eval code)
esid: sec-functiondeclarations-in-ifstatement-statement-clauses
es6id: B.3.3
flags: [generated, noStrict]
includes: [fnGlobalObject.js, propertyHelper.js]
info: |
The following rules for IfStatement augment those in 13.6:

IfStatement[Yield, Return]:
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]


B.3.3.3 Changes to EvalDeclarationInstantiation

[...]
i. If varEnvRec is a global Environment Record, then
i. Perform ? varEnvRec.CreateGlobalVarBinding(F, true).
[...]

---*/
Object.defineProperty(fnGlobalObject(), 'f', {
value: 'x',
enumerable: false,
writable: true,
configurable: true
});

eval(
'var global = fnGlobalObject();\
assert.sameValue(f, "x", "binding is not reinitialized");\
\
verifyProperty(global, "f", {\
enumerable: false,\
writable: true,\
configurable: true\
}, { restore: true });if (true) function f() { } else function _f() {}'
);

assert.sameValue(typeof f, "function");
verifyProperty(global, 'f', {
enumerable: false,
writable: true,
configurable: true
});