diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/language/global-code | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/global-code')
43 files changed, 1563 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/global-code/S10.1.7_A1_T1.js b/js/src/tests/test262/language/global-code/S10.1.7_A1_T1.js new file mode 100644 index 0000000000..787c317c9d --- /dev/null +++ b/js/src/tests/test262/language/global-code/S10.1.7_A1_T1.js @@ -0,0 +1,14 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The this value associated with an executioncontext is immutable +es5id: 10.1.7_A1_T1 +description: Checking if deleting "this" fails +---*/ + +//CHECK#1 +if (delete this !== true) + $ERROR('#1: The this value associated with an executioncontext is immutable. Actual: this was deleted'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/S10.4.1_A1_T1.js b/js/src/tests/test262/language/global-code/S10.4.1_A1_T1.js new file mode 100644 index 0000000000..63ad550d20 --- /dev/null +++ b/js/src/tests/test262/language/global-code/S10.4.1_A1_T1.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Variable instantiation is performed using the global object as + the variable object and using property attributes { DontDelete } +es5id: 10.4.1_A1_T1 +description: > + Checking if deleting variable x, that is defined as var x = 1, + fails +flags: [noStrict] +---*/ + +var x = 1; + +if (this.x !== 1) { + $ERROR("#1: variable x is a property of global object"); +} + +if(delete this.x !== false){ + $ERROR("#2: variable x has property attribute DontDelete"); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/S10.4.1_A1_T2.js b/js/src/tests/test262/language/global-code/S10.4.1_A1_T2.js new file mode 100644 index 0000000000..e64492c8c6 --- /dev/null +++ b/js/src/tests/test262/language/global-code/S10.4.1_A1_T2.js @@ -0,0 +1,23 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Variable instantiation is performed using the global object as + the variable object and using property attributes { DontDelete } +es5id: 10.4.1_A1_T2 +description: Checking if deleting variable x, that is defined as x = 1, fails +flags: [noStrict] +---*/ + +x = 1; + +if (this.x !== 1) { + $ERROR("#1: variable x is a property of global object"); +} + +if(delete this.x !== true){ + $ERROR("#2: variable x has property attribute DontDelete"); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/block-decl-strict-strict.js b/js/src/tests/test262/language/global-code/block-decl-strict-strict.js new file mode 100644 index 0000000000..60bc9f9aa4 --- /dev/null +++ b/js/src/tests/test262/language/global-code/block-decl-strict-strict.js @@ -0,0 +1,28 @@ +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (Block statement in the global scope containing a function declaration) +es6id: B.3.3.2 +flags: [onlyStrict] +info: | + B.3.3.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +assert.throws(ReferenceError, function() { + f; +}); + +{ + function f() { } +} + +assert.throws(ReferenceError, function() { + f; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/browser.js b/js/src/tests/test262/language/global-code/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/global-code/browser.js diff --git a/js/src/tests/test262/language/global-code/decl-func-dup.js b/js/src/tests/test262/language/global-code/decl-func-dup.js new file mode 100644 index 0000000000..501099f58f --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-func-dup.js @@ -0,0 +1,13 @@ +// Copyright (C) 2011 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 13.1 +description: > + redeclaration outermost: + allowed to redeclare function declaration with function declaration +---*/ +function f() { return 1; } function f() { return 2; } + +assert.sameValue(f(), 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/decl-func.js b/js/src/tests/test262/language/global-code/decl-func.js new file mode 100644 index 0000000000..2de1d707ef --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-func.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Declaration of function where permissible +info: | + [...] + 9. Let declaredFunctionNames be a new empty List. + 10. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a + GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn). + 2. If fnDefinable is false, throw a TypeError exception. + 3. Append fn to declaredFunctionNames. + 4. Insert d as the first element of functionsToInitialize. + [...] + 17. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f + with argument env. + c. Perform ? envRec.CreateGlobalFunctionBinding(fn, fo, false). + [...] + + 8.1.1.4.16 CanDeclareGlobalFunction + + 1. Let envRec be the global Environment Record for which the method was + invoked. + 2. Let ObjRec be envRec.[[ObjectRecord]]. + 3. Let globalObject be the binding object for ObjRec. + 4. Let existingProp be ? globalObject.[[GetOwnProperty]](N). + 5. If existingProp is undefined, return ? IsExtensible(globalObject). +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof brandNew, 'function', 'new binding on an extensible global object' +); +verifyEnumerable(this, 'brandNew'); +verifyWritable(this, 'brandNew'); +verifyNotConfigurable(this, 'brandNew'); + +function brandNew() {} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/decl-lex-configurable-global.js b/js/src/tests/test262/language/global-code/decl-lex-configurable-global.js new file mode 100644 index 0000000000..fd457b542b --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-lex-configurable-global.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Lexical declarations "shadow" configurable global properties +info: | + [...] + 5. For each name in lexNames, do + [...] + c. Let hasRestrictedGlobal be ? envRec.HasRestrictedGlobalProperty(name). + d. If hasRestrictedGlobal is true, throw a SyntaxError exception. + [...] + 16. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ? envRec.CreateMutableBinding(dn, false). +---*/ + +let Array; + +assert.sameValue(Array, undefined); +assert.sameValue(typeof this.Array, 'function'); + +// DO NOT USE propertyHelper API! +let descriptor = Object.getOwnPropertyDescriptor(this, 'Array'); +assert.sameValue(descriptor.configurable, true); +assert.sameValue(descriptor.enumerable, false); +assert.sameValue(descriptor.writable, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/decl-lex-deletion.js b/js/src/tests/test262/language/global-code/decl-lex-deletion.js new file mode 100644 index 0000000000..2ddc9530f4 --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-lex-deletion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Globally-declared lexical bindings cannot be deleted +info: | + [...] + 16. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ? envRec.CreateMutableBinding(dn, false). + [...] +flags: [noStrict] +---*/ + +let test262let; + +delete test262let; + +// Binding values are asserted by a dedicated test. IdentifierReferences serve +// to ensure that the entries in the environment record persist. +test262let; + +const test262const = null; + +delete test262const; + +test262const; + +class test262class {} + +delete test262class; + +test262class; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/decl-lex-restricted-global.js b/js/src/tests/test262/language/global-code/decl-lex-restricted-global.js new file mode 100644 index 0000000000..39135a3096 --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-lex-restricted-global.js @@ -0,0 +1,19 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Lexical declaration collides with existing "restricted global" +info: | + [...] + 5. For each name in lexNames, do + [...] + c. Let hasRestrictedGlobal be ? envRec.HasRestrictedGlobalProperty(name). + d. If hasRestrictedGlobal is true, throw a SyntaxError exception. +negative: + phase: runtime + type: SyntaxError +---*/ + +let undefined; diff --git a/js/src/tests/test262/language/global-code/decl-lex.js b/js/src/tests/test262/language/global-code/decl-lex.js new file mode 100644 index 0000000000..7b4cb2590c --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-lex.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Declaration of lexical bindings +info: | + [...] + 16. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ? envRec.CreateMutableBinding(dn, false). + [...] +---*/ + +let test262let = 1; + +test262let = 2; + +assert.sameValue(test262let, 2, '`let` binding is mutable'); +assert.sameValue( + this.hasOwnProperty('test262let'), + false, + 'property not created on the global object (let)' +); + +const test262const = 3; + +assert.throws(TypeError, function() { + test262const = 4; +}, '`const` binding is strictly immutable'); +assert.sameValue(test262const, 3, '`const` binding cannot be modified'); +assert.sameValue( + this.hasOwnProperty('test262const'), + false, + 'property not created on the global object (const)' +); + +class test262class {} + +test262class = 5; + +assert.sameValue(test262class, 5, '`class` binding is mutable'); +assert.sameValue( + this.hasOwnProperty('test262class'), + false, + 'property not created on the global object (class)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/decl-var.js b/js/src/tests/test262/language/global-code/decl-var.js new file mode 100644 index 0000000000..134adc92e1 --- /dev/null +++ b/js/src/tests/test262/language/global-code/decl-var.js @@ -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. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Declaration of variable where permissible +info: | + [...] + 11. Let declaredVarNames be a new empty List. + 12. For each d in varDeclarations, do + a. If d is a VariableDeclaration or a ForBinding, then + i. For each String vn in the BoundNames of d, do + 1. If vn is not an element of declaredFunctionNames, then + a. Let vnDefinable be ? envRec.CanDeclareGlobalVar(vn). + b. If vnDefinable is false, throw a TypeError exception. + c. If vn is not an element of declaredVarNames, then + i. Append vn to declaredVarNames. + [...] + 18. For each String vn in declaredVarNames, in list order do + a. Perform ? envRec.CreateGlobalVarBinding(vn, false). + [...] + + 8.1.1.4.15 CanDeclareGlobalVar + + 1. Let envRec be the global Environment Record for which the method was + invoked. + 2. Let ObjRec be envRec.[[ObjectRecord]]. + 3. Let globalObject be the binding object for ObjRec. + 4. Let hasProperty be ? HasOwnProperty(globalObject, N). + 5. If hasProperty is true, return true. + 6. Return ? IsExtensible(globalObject). +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + this.brandNew, undefined, 'new binding on an extensible global object' +); +verifyEnumerable(this, 'brandNew'); +verifyWritable(this, 'brandNew'); +verifyNotConfigurable(this, 'brandNew'); + +var brandNew; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/export.js b/js/src/tests/test262/language/global-code/export.js new file mode 100644 index 0000000000..311de8f951 --- /dev/null +++ b/js/src/tests/test262/language/global-code/export.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: The `export` declaration may not appear within a ScriptBody +esid: sec-scripts +negative: + phase: parse + type: SyntaxError +info: | + A.5 Scripts and Modules + + Script: + ScriptBodyopt + + ScriptBody: + StatementList +---*/ + +$DONOTEVALUATE(); + +export default null; diff --git a/js/src/tests/test262/language/global-code/import.js b/js/src/tests/test262/language/global-code/import.js new file mode 100644 index 0000000000..9239071e7e --- /dev/null +++ b/js/src/tests/test262/language/global-code/import.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: The `import` declaration may not appear within a ScriptBody +esid: sec-scripts +negative: + phase: parse + type: SyntaxError +info: | + A.5 Scripts and Modules + + Script: + ScriptBodyopt + + ScriptBody: + StatementList +---*/ + +$DONOTEVALUATE(); + +import v from './import.js'; diff --git a/js/src/tests/test262/language/global-code/invalid-private-names-call-expression-bad-reference.js b/js/src/tests/test262/language/global-code/invalid-private-names-call-expression-bad-reference.js new file mode 100644 index 0000000000..d06ab6005d --- /dev/null +++ b/js/src/tests/test262/language/global-code/invalid-private-names-call-expression-bad-reference.js @@ -0,0 +1,41 @@ +// |reftest| shell-option(--enable-private-fields) skip-if(!xulRuntime.shell) error:SyntaxError -- requires shell-options +// This file was procedurally generated from the following sources: +// - src/invalid-private-names/call-expression-bad-reference.case +// - src/invalid-private-names/default/top-level-scriptbody.template +/*--- +description: bad reference in call expression (Invalid private names should throw a SyntaxError, top level of script body) +esid: sec-static-semantics-early-errors +features: [class-fields-private] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + +---*/ + + +$DONOTEVALUATE(); + +(() => {})().#x diff --git a/js/src/tests/test262/language/global-code/invalid-private-names-call-expression-this.js b/js/src/tests/test262/language/global-code/invalid-private-names-call-expression-this.js new file mode 100644 index 0000000000..3bf2a19624 --- /dev/null +++ b/js/src/tests/test262/language/global-code/invalid-private-names-call-expression-this.js @@ -0,0 +1,41 @@ +// |reftest| shell-option(--enable-private-fields) skip-if(!xulRuntime.shell) error:SyntaxError -- requires shell-options +// This file was procedurally generated from the following sources: +// - src/invalid-private-names/call-expression-this.case +// - src/invalid-private-names/default/top-level-scriptbody.template +/*--- +description: this evaluated in call expression (Invalid private names should throw a SyntaxError, top level of script body) +esid: sec-static-semantics-early-errors +features: [class-fields-private] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + +---*/ + + +$DONOTEVALUATE(); + +(() => this)().#x diff --git a/js/src/tests/test262/language/global-code/invalid-private-names-member-expression-bad-reference.js b/js/src/tests/test262/language/global-code/invalid-private-names-member-expression-bad-reference.js new file mode 100644 index 0000000000..e39718462b --- /dev/null +++ b/js/src/tests/test262/language/global-code/invalid-private-names-member-expression-bad-reference.js @@ -0,0 +1,41 @@ +// |reftest| shell-option(--enable-private-fields) skip-if(!xulRuntime.shell) error:SyntaxError -- requires shell-options +// This file was procedurally generated from the following sources: +// - src/invalid-private-names/member-expression-bad-reference.case +// - src/invalid-private-names/default/top-level-scriptbody.template +/*--- +description: bad reference in member expression (Invalid private names should throw a SyntaxError, top level of script body) +esid: sec-static-semantics-early-errors +features: [class-fields-private] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + +---*/ + + +$DONOTEVALUATE(); + +something.#x diff --git a/js/src/tests/test262/language/global-code/invalid-private-names-member-expression-this.js b/js/src/tests/test262/language/global-code/invalid-private-names-member-expression-this.js new file mode 100644 index 0000000000..2bde7d0bfe --- /dev/null +++ b/js/src/tests/test262/language/global-code/invalid-private-names-member-expression-this.js @@ -0,0 +1,41 @@ +// |reftest| shell-option(--enable-private-fields) skip-if(!xulRuntime.shell) error:SyntaxError -- requires shell-options +// This file was procedurally generated from the following sources: +// - src/invalid-private-names/member-expression-this.case +// - src/invalid-private-names/default/top-level-scriptbody.template +/*--- +description: this reference in member expression (Invalid private names should throw a SyntaxError, top level of script body) +esid: sec-static-semantics-early-errors +features: [class-fields-private] +flags: [generated] +negative: + phase: parse + type: SyntaxError +info: | + ScriptBody:StatementList + It is a Syntax Error if AllPrivateNamesValid of StatementList with an empty List + as an argument is false unless the source code is eval code that is being + processed by a direct eval. + + ModuleBody:ModuleItemList + It is a Syntax Error if AllPrivateNamesValid of ModuleItemList with an empty List + as an argument is false. + + + Static Semantics: AllPrivateNamesValid + + MemberExpression : MemberExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + + CallExpression : CallExpression . PrivateName + + 1. If StringValue of PrivateName is in names, return true. + 2. Return false. + +---*/ + + +$DONOTEVALUATE(); + +this.#x diff --git a/js/src/tests/test262/language/global-code/new.target-arrow.js b/js/src/tests/test262/language/global-code/new.target-arrow.js new file mode 100644 index 0000000000..660ed4b950 --- /dev/null +++ b/js/src/tests/test262/language/global-code/new.target-arrow.js @@ -0,0 +1,38 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: An ArrowFunction in global code may not contain `new.target` +info: | + - It is a Syntax Error if StatementList Contains NewTarget unless the source + code containing NewTarget is eval code that is being processed by a direct + eval that is contained in function code that is not the function code of an + ArrowFunction. + + 14.2.3 Static Semantics: Contains + + With parameter symbol. + + ArrowFunction : ArrowParameters => ConciseBody + + 1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super or + this, return false. + 2. If ArrowParameters Contains symbol is true, return true. + 3. Return ConciseBody Contains symbol. + + NOTE Normally, Contains does not look inside most function forms. However, + Contains is used to detect new.target, this, and super usage within an + ArrowFunction. +features: [arrow-function, new.target] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +() => { + new.target; +}; diff --git a/js/src/tests/test262/language/global-code/new.target.js b/js/src/tests/test262/language/global-code/new.target.js new file mode 100644 index 0000000000..2082253971 --- /dev/null +++ b/js/src/tests/test262/language/global-code/new.target.js @@ -0,0 +1,21 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: Global code may not contain `new.target` +info: | + - It is a Syntax Error if StatementList Contains NewTarget unless the source + code containing NewTarget is eval code that is being processed by a direct + eval that is contained in function code that is not the function code of an + ArrowFunction. +negative: + phase: parse + type: SyntaxError +features: [new.target] +---*/ + +$DONOTEVALUATE(); + +new.target; diff --git a/js/src/tests/test262/language/global-code/return.js b/js/src/tests/test262/language/global-code/return.js new file mode 100644 index 0000000000..dabbce59ae --- /dev/null +++ b/js/src/tests/test262/language/global-code/return.js @@ -0,0 +1,23 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts +es6id: 15.1 +description: ReturnStatement may not be used directly within global code +info: | + Syntax + + Script : + ScriptBodyopt + + ScriptBody : + StatementList[~Yield, ~Return] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +return; diff --git a/js/src/tests/test262/language/global-code/script-decl-func-dups.js b/js/src/tests/test262/language/global-code/script-decl-func-dups.js new file mode 100644 index 0000000000..d233337fb6 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-func-dups.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: > + When multiple like-named function declarations exist, the final is assigned + to the new binding. +info: | + [...] + 9. Let declaredFunctionNames be a new empty List. + 10. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a + GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn). + 2. If fnDefinable is false, throw a TypeError exception. + 3. Append fn to declaredFunctionNames. + 4. Insert d as the first element of functionsToInitialize. + [...] +---*/ + +$262.evalScript( + 'function f() { return 1; }' + + 'function f() { return 2; }' + + 'function f() { return 3; }' +); + +assert.sameValue(f(), 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-func-err-non-configurable.js b/js/src/tests/test262/language/global-code/script-decl-func-err-non-configurable.js new file mode 100644 index 0000000000..449c596e7a --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-func-err-non-configurable.js @@ -0,0 +1,107 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: > + Declaration of function when there is a corresponding global property that is + non-configurable but *not* a writable and configurable data property. +info: | + [...] + 9. Let declaredFunctionNames be a new empty List. + 10. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a + GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn). + 2. If fnDefinable is false, throw a TypeError exception. + + 8.1.1.4.16 CanDeclareGlobalFunction + + [...] + 6. If existingProp.[[Configurable]] is true, return true. + 7. If IsDataDescriptor(existingProp) is true and existingProp has attribute + values {[[Writable]]: true, [[Enumerable]]: true}, return true. + 8. Return false. +---*/ + +Object.defineProperty( + this, + 'data1', + { configurable: false, value: 0, writable: true, enumerable: false } +); + +Object.defineProperty( + this, + 'data2', + { configurable: false, value: 0, writable: false, enumerable: true } +); + +Object.defineProperty( + this, + 'data3', + { configurable: false, value: 0, writable: false, enumerable: false } +); + +Object.defineProperty( + this, + 'accessor1', + { + configurable: false, + get: function() {}, + set: function() {}, + enumerable: true + } +); + +Object.defineProperty( + this, + 'accessor2', + { + configurable: false, + get: function() {}, + set: function() {}, + enumerable: true + } +); + +assert.throws(TypeError, function() { + $262.evalScript('var x; function data1() {}'); +}, 'writable, non-enumerable data property'); +assert.throws(ReferenceError, function() { + x; +}, 'bindings not created for writable, non-enumerable data property'); + +assert.throws(TypeError, function() { + $262.evalScript('var x; function data2() {}'); +}, 'non-writable, enumerable data property'); +assert.throws(ReferenceError, function() { + x; +}, 'bindings not created for non-writable, enumerable data property'); + +assert.throws(TypeError, function() { + $262.evalScript('var x; function data3() {}'); +}, 'non-writable, non-enumerable data property'); +assert.throws(ReferenceError, function() { + x; +}, 'bindings not created for non-writable, non-enumerable data property'); + +assert.throws(TypeError, function() { + $262.evalScript('var x; function accessor1() {}'); +}, 'enumerable accessor property'); +assert.throws(ReferenceError, function() { + x; +}, 'bindings not created for enumerableaccessor property'); + +assert.throws(TypeError, function() { + $262.evalScript('var x; function accessor2() {}'); +}, 'non-enumerable accessor property'); +assert.throws(ReferenceError, function() { + x; +}, 'bindings not created for non-enumerableaccessor property'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-func-err-non-extensible.js b/js/src/tests/test262/language/global-code/script-decl-func-err-non-extensible.js new file mode 100644 index 0000000000..b259ddde75 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-func-err-non-extensible.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: > + Declaration of function when there is no corresponding global property and + the global object is non-extensible +info: | + [...] + 9. Let declaredFunctionNames be a new empty List. + 10. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a + GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn). + 2. If fnDefinable is false, throw a TypeError exception. + + 8.1.1.4.16 CanDeclareGlobalFunction + + 1. Let envRec be the global Environment Record for which the method was + invoked. + 2. Let ObjRec be envRec.[[ObjectRecord]]. + 3. Let globalObject be the binding object for ObjRec. + 4. Let existingProp be ? globalObject.[[GetOwnProperty]](N). + 5. If existingProp is undefined, return ? IsExtensible(globalObject). +---*/ + +var executed = false; + +Object.preventExtensions(this); + +assert.throws(TypeError, function() { + $262.evalScript('executed = true; function test262() {}'); +}); + +assert.sameValue(executed, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-func.js b/js/src/tests/test262/language/global-code/script-decl-func.js new file mode 100644 index 0000000000..b6e4808750 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-func.js @@ -0,0 +1,81 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Declaration of function where permissible +info: | + [...] + 9. Let declaredFunctionNames be a new empty List. + 10. For each d in varDeclarations, in reverse list order do + a. If d is neither a VariableDeclaration or a ForBinding, then + i. Assert: d is either a FunctionDeclaration or a + GeneratorDeclaration. + ii. NOTE If there are multiple FunctionDeclarations for the same name, + the last declaration is used. + iii. Let fn be the sole element of the BoundNames of d. + iv. If fn is not an element of declaredFunctionNames, then + 1. Let fnDefinable be ? envRec.CanDeclareGlobalFunction(fn). + 2. If fnDefinable is false, throw a TypeError exception. + 3. Append fn to declaredFunctionNames. + 4. Insert d as the first element of functionsToInitialize. + [...] + 17. For each production f in functionsToInitialize, do + a. Let fn be the sole element of the BoundNames of f. + b. Let fo be the result of performing InstantiateFunctionObject for f + with argument env. + c. Perform ? envRec.CreateGlobalFunctionBinding(fn, fo, false). + [...] + + 8.1.1.4.16 CanDeclareGlobalFunction + + 1. Let envRec be the global Environment Record for which the method was + invoked. + 2. Let ObjRec be envRec.[[ObjectRecord]]. + 3. Let globalObject be the binding object for ObjRec. + 4. Let existingProp be ? globalObject.[[GetOwnProperty]](N). + 5. If existingProp is undefined, return ? IsExtensible(globalObject). +includes: [propertyHelper.js] +---*/ + +$262.evalScript('function brandNew() {}'); + +assert.sameValue( + typeof brandNew, 'function', 'new binding on an extensible global object' +); +verifyEnumerable(this, 'brandNew'); +verifyWritable(this, 'brandNew'); +verifyNotConfigurable(this, 'brandNew'); + +Object.defineProperty(this, 'configurable', { configurable: true, value: 0 }); +Object.defineProperty( + this, + 'nonConfigurable', + { configurable: false, writable: true, enumerable: true, value: 0 } +); + +// Prevent extensions on the global object to ensure that detail is not +// considered by any of the declarations which follow. +Object.preventExtensions(this); + +$262.evalScript('function configurable() {}'); + +assert.sameValue( + typeof configurable, 'function', 'like-named configurable property' +); +verifyEnumerable(this, 'configurable') +verifyWritable(this, 'configurable'); +verifyNotConfigurable(this, 'configurable'); + +$262.evalScript('function nonConfigurable() {}'); + +assert.sameValue( + typeof nonConfigurable, + 'function', + 'like-named non-configurable data property that is writable and enumerable' +); +verifyEnumerable(this, 'nonConfigurable'); +verifyWritable(this, 'nonConfigurable'); +verifyNotConfigurable(this, 'nonConfigurable'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-lex-deletion.js b/js/src/tests/test262/language/global-code/script-decl-lex-deletion.js new file mode 100644 index 0000000000..5588429fc8 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-lex-deletion.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Globally-declared lexical bindings cannot be deleted +info: | + [...] + 16. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ? envRec.CreateMutableBinding(dn, false). + [...] +flags: [noStrict] +---*/ + +$262.evalScript('let test262let;'); + +delete test262let; + +// Binding values are asserted by a dedicated test. IdentifierReferences serve +// to ensure that the entries in the environment record persist. +test262let; + +$262.evalScript('const test262const = null;'); + +delete test262const; + +test262const; + +$262.evalScript('class test262class {}'); + +delete test262class; + +test262class; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-lex-lex.js b/js/src/tests/test262/language/global-code/script-decl-lex-lex.js new file mode 100644 index 0000000000..ec499e97d5 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-lex-lex.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Let binding collision with existing lexical declaration +info: | + [...] + 5. For each name in lexNames, do + a. If envRec.HasVarDeclaration(name) is true, throw a SyntaxError + exception. + b. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + exception. +---*/ + +let test262Let; +const test262Const = null; +class test262Class {} + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; let test262Let;'); +}, '`let` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'No bindings created for script containing `let` redeclaration'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; let test262Const;'); +}, '`const` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'No bindings created for script containing `const` redeclaration'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; let test262Class;'); +}, '`class` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'No bindings created for script containing `class` redeclaration'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-lex-restricted-global.js b/js/src/tests/test262/language/global-code/script-decl-lex-restricted-global.js new file mode 100644 index 0000000000..65b0d49758 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-lex-restricted-global.js @@ -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. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: > + Let binding collision with non-configurable global property (not defined + through a declaration) +info: | + [...] + 5. For each name in lexNames, do + a. If envRec.HasVarDeclaration(name) is true, throw a SyntaxError + exception. + b. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + exception. + c. Let hasRestrictedGlobal be ? envRec.HasRestrictedGlobalProperty(name). + d. If hasRestrictedGlobal is true, throw a SyntaxError exception. +---*/ + +Object.defineProperty(this, 'test262Configurable', { configurable: true }); +Object.defineProperty(this, 'test262NonConfigurable', { configurable: false }); + +$262.evalScript('let test262Configurable;'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; let test262NonConfigurable;'); +}); + +assert.throws(ReferenceError, function() { + x; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-lex-var.js b/js/src/tests/test262/language/global-code/script-decl-lex-var.js new file mode 100644 index 0000000000..41d413068e --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-lex-var.js @@ -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. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Let binding collision with existing var declaration +info: | + [...] + 5. For each name in lexNames, do + a. If envRec.HasVarDeclaration(name) is true, throw a SyntaxError + exception. +---*/ + +var test262Var; +function test262Fn() {} + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; let test262Var;'); +}, 'variable'); + +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script shadowing variable)'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; let test262Fn;'); +}, 'function'); + +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script shadowing function)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-lex.js b/js/src/tests/test262/language/global-code/script-decl-lex.js new file mode 100644 index 0000000000..b61b38afb3 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-lex.js @@ -0,0 +1,58 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Declaration of lexical bindings +info: | + [...] + 16. For each element d in lexDeclarations do + a. NOTE Lexically declared names are only instantiated here but not + initialized. + b. For each element dn of the BoundNames of d do + i. If IsConstantDeclaration of d is true, then + 1. Perform ? envRec.CreateImmutableBinding(dn, true). + ii. Else, + 1. Perform ? envRec.CreateMutableBinding(dn, false). + [...] +---*/ + +// Extensibility of the global object should have no bearing on lexical +// declarations. +Object.preventExtensions(this); + +$262.evalScript('let test262let = 1;'); + +test262let = 2; + +assert.sameValue(test262let, 2, '`let` binding is mutable'); +assert.sameValue( + this.hasOwnProperty('test262let'), + false, + 'property not created on the global object (let)' +); + +$262.evalScript('const test262const = 3;'); + +assert.throws(TypeError, function() { + test262const = 4; +}, '`const` binding is strictly immutable'); +assert.sameValue(test262const, 3, '`const` binding cannot be modified'); +assert.sameValue( + this.hasOwnProperty('test262const'), + false, + 'property not created on the global object (const)' +); + +$262.evalScript('class test262class {}'); + +test262class = 5; + +assert.sameValue(test262class, 5, '`class` binding is mutable'); +assert.sameValue( + this.hasOwnProperty('test262class'), + false, + 'property not created on the global object (class)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-var-collision.js b/js/src/tests/test262/language/global-code/script-decl-var-collision.js new file mode 100644 index 0000000000..dcc247e536 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-var-collision.js @@ -0,0 +1,64 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Var binding collision with existing lexical declaration +info: | + [...] + 6. For each name in varNames, do + a. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError + exception. +---*/ + +var test262Var; +let test262Let; +const test262Const = null; +class test262Class {} + +$262.evalScript('var test262Var;'); +$262.evalScript('function test262Var() {}'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; var test262Let;'); +}, '`var` on `let` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script declaring a `var` on a `let` binding)'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; var test262Const;'); +}, '`var` on `const` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script declaring a `var` on a `const` binding)'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; var test262Class;'); +}, '`var` on `class` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script declaring a `var` on a `class` binding)'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; function test262Let() {}'); +}, 'function on `let` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script declaring a function on a `let` binding)'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; function test262Const() {}'); +}, 'function on `const` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script declaring a function on a `const` binding)'); + +assert.throws(SyntaxError, function() { + $262.evalScript('var x; function test262Class() {}'); +} , 'function on `class` binding'); +assert.throws(ReferenceError, function() { + x; +}, 'no bindings created (script declaring a function on a class binding)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-var-err.js b/js/src/tests/test262/language/global-code/script-decl-var-err.js new file mode 100644 index 0000000000..730309f718 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-var-err.js @@ -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. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: > + Declaration of variable when there is no corresponding global property and + the global object is non-extensible +info: | + [...] + 11. Let declaredVarNames be a new empty List. + 12. For each d in varDeclarations, do + a. If d is a VariableDeclaration or a ForBinding, then + i. For each String vn in the BoundNames of d, do + 1. If vn is not an element of declaredFunctionNames, then + a. Let vnDefinable be ? envRec.CanDeclareGlobalVar(vn). + b. If vnDefinable is false, throw a TypeError exception. + c. If vn is not an element of declaredVarNames, then + i. Append vn to declaredVarNames. + + 8.1.1.4.15 CanDeclareGlobalVar + + 1. Let envRec be the global Environment Record for which the method was + invoked. + 2. Let ObjRec be envRec.[[ObjectRecord]]. + 3. Let globalObject be the binding object for ObjRec. + 4. Let hasProperty be ? HasOwnProperty(globalObject, N). + 5. If hasProperty is true, return true. + 6. Return ? IsExtensible(globalObject). +---*/ + +var executed = false; + +Object.preventExtensions(this); + +assert.throws(TypeError, function() { + $262.evalScript('executed = true; var test262;'); +}); + +assert.sameValue(executed, false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/script-decl-var.js b/js/src/tests/test262/language/global-code/script-decl-var.js new file mode 100644 index 0000000000..7cc30af979 --- /dev/null +++ b/js/src/tests/test262/language/global-code/script-decl-var.js @@ -0,0 +1,73 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-globaldeclarationinstantiation +es6id: 15.1.8 +description: Declaration of variable where permissible +info: | + [...] + 11. Let declaredVarNames be a new empty List. + 12. For each d in varDeclarations, do + a. If d is a VariableDeclaration or a ForBinding, then + i. For each String vn in the BoundNames of d, do + 1. If vn is not an element of declaredFunctionNames, then + a. Let vnDefinable be ? envRec.CanDeclareGlobalVar(vn). + b. If vnDefinable is false, throw a TypeError exception. + c. If vn is not an element of declaredVarNames, then + i. Append vn to declaredVarNames. + [...] + 18. For each String vn in declaredVarNames, in list order do + a. Perform ? envRec.CreateGlobalVarBinding(vn, false). + [...] + + 8.1.1.4.15 CanDeclareGlobalVar + + 1. Let envRec be the global Environment Record for which the method was + invoked. + 2. Let ObjRec be envRec.[[ObjectRecord]]. + 3. Let globalObject be the binding object for ObjRec. + 4. Let hasProperty be ? HasOwnProperty(globalObject, N). + 5. If hasProperty is true, return true. + 6. Return ? IsExtensible(globalObject). +includes: [propertyHelper.js] +---*/ + +$262.evalScript('var brandNew;'); + +assert.sameValue( + this.brandNew, undefined, 'new binding on an extensible global object' +); +verifyEnumerable(this, 'brandNew'); +verifyWritable(this, 'brandNew'); +verifyNotConfigurable(this, 'brandNew'); + +Object.defineProperty( + this, + 'configurable', + { configurable: true, writable: false, enumerable: false, value: 0 } +); +Object.defineProperty( + this, + 'nonConfigurable', + { configurable: false, writable: false, enumerable: false, value: 0 } +); + +// Prevent extensions on the global object to ensure that detail is not +// considered by any of the declarations which follow. +Object.preventExtensions(this); + +$262.evalScript('var configurable;'); + +assert.sameValue(configurable, 0, 'like-named configurable property'); +verifyNotEnumerable(this, 'configurable'); +verifyNotWritable(this, 'configurable'); +verifyConfigurable(this, 'configurable'); + +$262.evalScript('var nonConfigurable;'); + +assert.sameValue(nonConfigurable, 0, 'like-named non-configurable property'); +verifyNotEnumerable(this, 'nonConfigurable'); +verifyNotWritable(this, 'nonConfigurable'); +verifyNotConfigurable(this, 'nonConfigurable'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/shell.js b/js/src/tests/test262/language/global-code/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/global-code/shell.js diff --git a/js/src/tests/test262/language/global-code/super-call-arrow.js b/js/src/tests/test262/language/global-code/super-call-arrow.js new file mode 100644 index 0000000000..a4fdd3f6d4 --- /dev/null +++ b/js/src/tests/test262/language/global-code/super-call-arrow.js @@ -0,0 +1,38 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: An ArrowFunction in global code may not contain SuperCall +info: | + - It is a Syntax Error if StatementList Contains super unless the source code + containing super is eval code that is being processed by a direct eval that + is contained in function code that is not the function code of an + ArrowFunction. + + 14.2.3 Static Semantics: Contains + + With parameter symbol. + + ArrowFunction : ArrowParameters => ConciseBody + + 1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super or + this, return false. + 2. If ArrowParameters Contains symbol is true, return true. + 3. Return ConciseBody Contains symbol. + + NOTE Normally, Contains does not look inside most function forms. However, + Contains is used to detect new.target, this, and super usage within an + ArrowFunction. +features: [super, arrow-function] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +() => { + super(); +}; diff --git a/js/src/tests/test262/language/global-code/super-call.js b/js/src/tests/test262/language/global-code/super-call.js new file mode 100644 index 0000000000..153d46d37b --- /dev/null +++ b/js/src/tests/test262/language/global-code/super-call.js @@ -0,0 +1,21 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: Global code may not contain SuperCall +info: | + - It is a Syntax Error if StatementList Contains super unless the source code + containing super is eval code that is being processed by a direct eval that + is contained in function code that is not the function code of an + ArrowFunction. +negative: + phase: parse + type: SyntaxError +features: [super] +---*/ + +$DONOTEVALUATE(); + +super(); diff --git a/js/src/tests/test262/language/global-code/super-prop-arrow.js b/js/src/tests/test262/language/global-code/super-prop-arrow.js new file mode 100644 index 0000000000..878d91952d --- /dev/null +++ b/js/src/tests/test262/language/global-code/super-prop-arrow.js @@ -0,0 +1,38 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: An ArrowFunction in global code may not contain SuperProperty +info: | + - It is a Syntax Error if StatementList Contains super unless the source code + containing super is eval code that is being processed by a direct eval that + is contained in function code that is not the function code of an + ArrowFunction. + + 14.2.3 Static Semantics: Contains + + With parameter symbol. + + ArrowFunction : ArrowParameters => ConciseBody + + 1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super or + this, return false. + 2. If ArrowParameters Contains symbol is true, return true. + 3. Return ConciseBody Contains symbol. + + NOTE Normally, Contains does not look inside most function forms. However, + Contains is used to detect new.target, this, and super usage within an + ArrowFunction. +features: [super, arrow-function] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +() => { + super.property; +}; diff --git a/js/src/tests/test262/language/global-code/super-prop.js b/js/src/tests/test262/language/global-code/super-prop.js new file mode 100644 index 0000000000..fb69374440 --- /dev/null +++ b/js/src/tests/test262/language/global-code/super-prop.js @@ -0,0 +1,21 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts-static-semantics-early-errors +es6id: 15.1.1 +description: Global code may not contain SuperProperty +info: | + - It is a Syntax Error if StatementList Contains super unless the source code + containing super is eval code that is being processed by a direct eval that + is contained in function code that is not the function code of an + ArrowFunction. +negative: + phase: parse + type: SyntaxError +features: [super] +---*/ + +$DONOTEVALUATE(); + +super.property; diff --git a/js/src/tests/test262/language/global-code/switch-case-decl-strict-strict.js b/js/src/tests/test262/language/global-code/switch-case-decl-strict-strict.js new file mode 100644 index 0000000000..2fb92aedff --- /dev/null +++ b/js/src/tests/test262/language/global-code/switch-case-decl-strict-strict.js @@ -0,0 +1,29 @@ +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (Function declaration in the `case` clause of a `switch` statement in the global scope) +es6id: B.3.3.2 +flags: [onlyStrict] +info: | + B.3.3.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +assert.throws(ReferenceError, function() { + f; +}); + +switch (1) { + case 1: + function f() { } +} + +assert.throws(ReferenceError, function() { + f; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/switch-dflt-decl-strict-strict.js b/js/src/tests/test262/language/global-code/switch-dflt-decl-strict-strict.js new file mode 100644 index 0000000000..402acf21ec --- /dev/null +++ b/js/src/tests/test262/language/global-code/switch-dflt-decl-strict-strict.js @@ -0,0 +1,29 @@ +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: AnnexB extension not honored in strict mode (Funtion declaration in the `default` clause of a `switch` statement in the global scope) +es6id: B.3.3.2 +flags: [onlyStrict] +info: | + B.3.3.2 Changes to GlobalDeclarationInstantiation + + 1. 1. Let strict be IsStrict of script + 2. If strict is *false*, then + [...] +---*/ + +assert.throws(ReferenceError, function() { + f; +}); + +switch (1) { + default: + function f() { } +} + +assert.throws(ReferenceError, function() { + f; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/unscopables-ignored.js b/js/src/tests/test262/language/global-code/unscopables-ignored.js new file mode 100644 index 0000000000..4aaa49909e --- /dev/null +++ b/js/src/tests/test262/language/global-code/unscopables-ignored.js @@ -0,0 +1,47 @@ +// Copyright (c) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-global-environment-records-hasbinding-n +es6id: 8.1.1.4.1 +description: > + Symbol.unscopables is not referenced for the object environment of the global + environment record +info: | + 1. Let envRec be the global Environment Record for which the method was invoked. + 2. Let DclRec be envRec.[[DeclarativeRecord]]. + 3. If DclRec.HasBinding(N) is true, return true. + 4. Let ObjRec be envRec.[[ObjectRecord]]. + 5. Return ? ObjRec.HasBinding(N). + + 8.1.1.2.1 HasBinding + + 1. Let envRec be the object Environment Record for which the method was + invoked. + 2. Let bindings be the binding object for envRec. + 3. Let foundBinding be ? HasProperty(bindings, N). + 4. If foundBinding is false, return false. + 5. If the withEnvironment flag of envRec is false, return true. + 6. Let unscopables be ? Get(bindings, @@unscopables). + 7. If Type(unscopables) is Object, then + a. Let blocked be ToBoolean(? Get(unscopables, N)). + b. If blocked is true, return false. + 8. Return true. +features: [Symbol.unscopables] +---*/ + +var callCount = 0; +Object.defineProperty(this, Symbol.unscopables, { + get: function() { + callCount += 1; + } +}); + +this.test262 = true; + +test262; + +assert.sameValue( + callCount, 0, 'Did not reference @@unscopables property of global object' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/yield-non-strict.js b/js/src/tests/test262/language/global-code/yield-non-strict.js new file mode 100644 index 0000000000..57db0e0ba1 --- /dev/null +++ b/js/src/tests/test262/language/global-code/yield-non-strict.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts +es6id: 15.1 +description: > + The `yield` token is interpreted as an Identifier when it appears in global + code (non-strict mode) +info: | + Syntax + + Script : + ScriptBodyopt + + ScriptBody : + StatementList[~Yield, ~Return] +flags: [noStrict] +---*/ + +// Avoid test failures in cases where the host has defined a `yield` property +// on the global object. +try { + yield = 0; +} catch (_) {} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/global-code/yield-strict-strict.js b/js/src/tests/test262/language/global-code/yield-strict-strict.js new file mode 100644 index 0000000000..33b260bced --- /dev/null +++ b/js/src/tests/test262/language/global-code/yield-strict-strict.js @@ -0,0 +1,27 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-scripts +es6id: 15.1 +description: > + The `yield` token is interpreted as an Identifier when it appears in global + code (strict mode) +info: | + Syntax + + Script : + ScriptBodyopt + + ScriptBody : + StatementList[~Yield, ~Return] +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +yield; |