diff --git a/test/built-ins/Array/prototype/Symbol.unscopables/prop-desc.js b/test/built-ins/Array/prototype/Symbol.unscopables/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..0e33b462436487c42a47f0d8b88dffb33c1519eb --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.unscopables/prop-desc.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.31 +description: > + Property descriptor for initial value of `Symbol.unscopables` property +info: > + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.unscopables] +---*/ + +verifyNotEnumerable(Array.prototype, Symbol.unscopables); +verifyNotWritable(Array.prototype, Symbol.unscopables); +verifyConfigurable(Array.prototype, Symbol.unscopables); diff --git a/test/built-ins/Array/prototype/Symbol.unscopables/value.js b/test/built-ins/Array/prototype/Symbol.unscopables/value.js new file mode 100644 index 0000000000000000000000000000000000000000..f46879dba793c1c592b1a45da5c0cabf3fa610f0 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.unscopables/value.js @@ -0,0 +1,59 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.31 +description: > + Initial value of `Symbol.unscopables` property +info: > + 1. Let blackList be ObjectCreate(null). + 2. Perform CreateDataProperty(blackList, "copyWithin", true). + 3. Perform CreateDataProperty(blackList, "entries", true). + 4. Perform CreateDataProperty(blackList, "fill", true). + 5. Perform CreateDataProperty(blackList, "find", true). + 6. Perform CreateDataProperty(blackList, "findIndex", true). + 7. Perform CreateDataProperty(blackList, "keys", true). + 8. Perform CreateDataProperty(blackList, "values", true). + 9. Assert: Each of the above calls will return true. + 10. Return blackList. +includes: [propertyHelper.js] +features: [Symbol.unscopables] +---*/ + +var unscopables = Array.prototype[Symbol.unscopables]; + +assert.sameValue(Object.getPrototypeOf(unscopables), null); + +assert.sameValue(unscopables.copyWithin, true, '`copyWithin` property value'); +verifyEnumerable(unscopables, 'copyWithin'); +verifyWritable(unscopables, 'copyWithin'); +verifyConfigurable(unscopables, 'copyWithin'); + +assert.sameValue(unscopables.entries, true, '`entries` property value'); +verifyEnumerable(unscopables, 'entries'); +verifyWritable(unscopables, 'entries'); +verifyConfigurable(unscopables, 'entries'); + +assert.sameValue(unscopables.fill, true, '`fill` property value'); +verifyEnumerable(unscopables, 'fill'); +verifyWritable(unscopables, 'fill'); +verifyConfigurable(unscopables, 'fill'); + +assert.sameValue(unscopables.find, true, '`find` property value'); +verifyEnumerable(unscopables, 'find'); +verifyWritable(unscopables, 'find'); +verifyConfigurable(unscopables, 'find'); + +assert.sameValue(unscopables.findIndex, true, '`findIndex` property value'); +verifyEnumerable(unscopables, 'findIndex'); +verifyWritable(unscopables, 'findIndex'); +verifyConfigurable(unscopables, 'findIndex'); + +assert.sameValue(unscopables.keys, true, '`keys` property value'); +verifyEnumerable(unscopables, 'keys'); +verifyWritable(unscopables, 'keys'); +verifyConfigurable(unscopables, 'keys'); + +assert.sameValue(unscopables.values, true, '`values` property value'); +verifyEnumerable(unscopables, 'values'); +verifyWritable(unscopables, 'values'); +verifyConfigurable(unscopables, 'values'); diff --git a/test/built-ins/Symbol/unscopables/prop-desc.js b/test/built-ins/Symbol/unscopables/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..fdc227a2f6eb41ea26bf31e10261a93d3913ee7e --- /dev/null +++ b/test/built-ins/Symbol/unscopables/prop-desc.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.2.14 +description: > + `Symbol.unscopables` property descriptor +info: > + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [Symbol.unscopables] +---*/ + +assert.sameValue(typeof Symbol.unscopables, 'symbol'); +verifyNotEnumerable(Symbol, 'unscopables'); +verifyNotWritable(Symbol, 'unscopables'); +verifyNotConfigurable(Symbol, 'unscopables'); diff --git a/test/language/identifier-resolution/unscopables.js b/test/language/identifier-resolution/unscopables.js new file mode 100644 index 0000000000000000000000000000000000000000..d9de44ff5e2a455a9321ed64830a5aa1de9750e4 --- /dev/null +++ b/test/language/identifier-resolution/unscopables.js @@ -0,0 +1,23 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.4.1 +includes: [fnGlobalObject.js] +description: > + `Symbol.unscopables` is not referenced when finding bindings in global scope +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). +features: [Symbol.unscopables] +---*/ + +var x = 86; +fnGlobalObject()[Symbol.unscopables] = { + x: true +}; +assert.sameValue(x, 86); diff --git a/test/language/statements/with/binding-blocked-by-unscopables.js b/test/language/statements/with/binding-blocked-by-unscopables.js new file mode 100644 index 0000000000000000000000000000000000000000..e8c431754442812fdd4b2975be99e75308d397e2 --- /dev/null +++ b/test/language/statements/with/binding-blocked-by-unscopables.js @@ -0,0 +1,52 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.2.1 +description: > + True-coercing `Symbol.unscopables` properties block access to object environment record +info: > + [...] + 6. If the withEnvironment flag of envRec is false, return true. + 7. Let unscopables be Get(bindings, @@unscopables). + 8. ReturnIfAbrupt(unscopables). + 9. If Type(unscopables) is Object, then + a. Let blocked be ToBoolean(Get(unscopables, N)). + b. ReturnIfAbrupt(blocked). + c. If blocked is true, return false. + + ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation + [...] + 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + [...] +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var x = 0; +var env = { x: 1 }; +env[Symbol.unscopables] = { x: true }; + +with (env) { + assert.sameValue(x, 0, 'literal `true` value'); +} + +env[Symbol.unscopables].x = 'string'; +with (env) { + assert.sameValue(x, 0, 'non-empty string values'); +} + +env[Symbol.unscopables].x = 86; +with (env) { + assert.sameValue(x, 0, 'non-zero number values'); +} + +env[Symbol.unscopables].x = {}; +with (env) { + assert.sameValue(x, 0, 'object values'); +} + +env[Symbol.unscopables].x = Symbol.unscopables; +with (env) { + assert.sameValue(x, 0, 'Symbol values'); +} diff --git a/test/language/statements/with/binding-not-blocked-by-unscopables-falsey-prop.js b/test/language/statements/with/binding-not-blocked-by-unscopables-falsey-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..313b0d6773812eea50652f5fbe7a7a869cc1ac0b --- /dev/null +++ b/test/language/statements/with/binding-not-blocked-by-unscopables-falsey-prop.js @@ -0,0 +1,58 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.2.1 +description: > + False-coercing `Symbol.unscopables` properties do not block access to object environment record +info: > + [...] + 6. If the withEnvironment flag of envRec is false, return true. + 7. Let unscopables be Get(bindings, @@unscopables). + 8. ReturnIfAbrupt(unscopables). + 9. If Type(unscopables) is Object, then + a. Let blocked be ToBoolean(Get(unscopables, N)). + b. ReturnIfAbrupt(blocked). + c. If blocked is true, return false. + 10. Return true. + + ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation + [...] + 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + [...] +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var x = 0; +var env = { x: 1 }; +env[Symbol.unscopables] = {}; + +with (env) { + assert.sameValue(x, 1, 'undefined (no property defined)'); +} + +env[Symbol.unscopables].x = false; +with (env) { + assert.sameValue(x, 1, 'literal `false` value'); +} + +env[Symbol.unscopables].x = undefined; +with (env) { + assert.sameValue(x, 1, 'literal `undefined` value'); +} + +env[Symbol.unscopables].x = null; +with (env) { + assert.sameValue(x, 1, 'null value'); +} + +env[Symbol.unscopables].x = 0; +with (env) { + assert.sameValue(x, 1, 'literal `0` number value'); +} + +env[Symbol.unscopables].x = ''; +with (env) { + assert.sameValue(x, 1, 'empty string value'); +} diff --git a/test/language/statements/with/binding-not-blocked-by-unscopables-non-obj.js b/test/language/statements/with/binding-not-blocked-by-unscopables-non-obj.js new file mode 100644 index 0000000000000000000000000000000000000000..e838ab949c257121a483570ce7ff5392f0e82f32 --- /dev/null +++ b/test/language/statements/with/binding-not-blocked-by-unscopables-non-obj.js @@ -0,0 +1,32 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.2.1 +description: Non-object values of `Symbol.unscopables` property are ignored +info: > + [...] + 6. If the withEnvironment flag of envRec is false, return true. + 7. Let unscopables be Get(bindings, @@unscopables). + 8. ReturnIfAbrupt(unscopables). + 9. If Type(unscopables) is Object, then + a. Let blocked be ToBoolean(Get(unscopables, N)). + b. ReturnIfAbrupt(blocked). + c. If blocked is true, return false. + 10. Return true. + + ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation + [...] + 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + [...] +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var test262ToString = {}; +var env = { toString: test262ToString }; +env[Symbol.unscopables] = ''; + +with (env) { + assert.sameValue(toString, test262ToString); +} diff --git a/test/language/statements/with/unscopables-get-err.js b/test/language/statements/with/unscopables-get-err.js new file mode 100644 index 0000000000000000000000000000000000000000..be0cbb6a230857291a2e7942f18361342d071bf5 --- /dev/null +++ b/test/language/statements/with/unscopables-get-err.js @@ -0,0 +1,33 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.2.1 +description: > + Behavior when accessing `Symbol.unscopables` property value throws an error +info: > + [...] + 6. If the withEnvironment flag of envRec is false, return true. + 7. Let unscopables be Get(bindings, @@unscopables). + 8. ReturnIfAbrupt(unscopables). + + ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation + [...] + 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + [...] +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var env = { x: 86 }; +Object.defineProperty(env, Symbol.unscopables, { + get: function() { + throw new Test262Error(); + } +}); + +with (env) { + assert.throws(Test262Error, function() { + void x; + }); +} diff --git a/test/language/statements/with/unscopables-not-referenced-for-undef.js b/test/language/statements/with/unscopables-not-referenced-for-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..0b5e3a602b25a091711f67ceef92f888813c4247 --- /dev/null +++ b/test/language/statements/with/unscopables-not-referenced-for-undef.js @@ -0,0 +1,37 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.2.1 +description: > + `Symbol.unscopables` is not referenced when environment record does not have requested property +info: > + 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. ReturnIfAbrupt(foundBinding). + 5. If foundBinding is false, return false. + + ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation + [...] + 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + [...] +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var x = 0; +var env = {}; +var callCount = 0; +Object.defineProperty(env, Symbol.unscopables, { + get: function() { + callCount += 1; + } +}); + +with (env) { + void x; +} + +assert.sameValue(callCount, 0); diff --git a/test/language/statements/with/unscopables-prop-get-err.js b/test/language/statements/with/unscopables-prop-get-err.js new file mode 100644 index 0000000000000000000000000000000000000000..d5d16fe2c728686fcc1289c560a0204527f3a24f --- /dev/null +++ b/test/language/statements/with/unscopables-prop-get-err.js @@ -0,0 +1,38 @@ +// Copyright 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 8.1.1.2.1 +description: > + Behavior when accessing property of `Symbol.unscopables` property throws an error +info: > + [...] + 6. If the withEnvironment flag of envRec is false, return true. + 7. Let unscopables be Get(bindings, @@unscopables). + 8. ReturnIfAbrupt(unscopables). + 9. If Type(unscopables) is Object, then + a. Let blocked be ToBoolean(Get(unscopables, N)). + b. ReturnIfAbrupt(blocked). + + ES6: 13.11.7 (The `with` Statement) Runtime Semantics: Evaluation + [...] + 6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. + [...] +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var env = { x: 86 }; +env[Symbol.unscopables] = {}; + +Object.defineProperty(env[Symbol.unscopables], 'x', { + get: function() { + throw new Test262Error(); + } +}); + +with (env) { + assert.throws(Test262Error, function() { + void x; + }); +}