mirror of https://github.com/tc39/test262.git
Merge pull request #434 from jugglinmike/symbol-unscopables
Add tests for well-known Symbol: @@unscopables
This commit is contained in:
commit
ea222fb7d0
|
@ -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);
|
|
@ -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');
|
|
@ -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');
|
|
@ -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);
|
|
@ -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');
|
||||||
|
}
|
|
@ -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');
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
});
|
||||||
|
}
|
|
@ -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);
|
|
@ -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;
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue