mirror of
https://github.com/tc39/test262.git
synced 2025-07-19 20:14:56 +02:00
Improve test coverage for Symbol (#645)
This commit is contained in:
parent
a12e271269
commit
30d4c04182
24
test/built-ins/Symbol/for/create-value.js
Normal file
24
test/built-ins/Symbol/for/create-value.js
Normal file
@ -0,0 +1,24 @@
|
||||
// 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-symbol.for
|
||||
es6id: 19.4.2.1
|
||||
description: Creation of a unique Symbol value
|
||||
info: >
|
||||
1. Let stringKey be ? ToString(key).
|
||||
2. For each element e of the GlobalSymbolRegistry List,
|
||||
a. If SameValue(e.[[Key]], stringKey) is true, return e.[[Symbol]].
|
||||
3. Assert: GlobalSymbolRegistry does not currently contain an entry for
|
||||
stringKey.
|
||||
4. Let newSymbol be a new unique Symbol value whose [[Description]] value
|
||||
is stringKey.
|
||||
5. Append the Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the
|
||||
GlobalSymbolRegistry List.
|
||||
6. Return newSymbol.
|
||||
---*/
|
||||
|
||||
var canonical = Symbol.for('s');
|
||||
|
||||
assert.sameValue(typeof canonical, 'symbol');
|
||||
assert.notSameValue(canonical, Symbol('s'));
|
||||
assert.notSameValue(canonical, Symbol.for('y'));
|
18
test/built-ins/Symbol/for/prop-desc.js
Normal file
18
test/built-ins/Symbol/for/prop-desc.js
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.for
|
||||
es6id: 19.4.2.1
|
||||
description: Property descriptor
|
||||
info: >
|
||||
Every other data property described in clauses 18 through 26 and in Annex
|
||||
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.for, 'function');
|
||||
|
||||
verifyNotEnumerable(Symbol, 'for');
|
||||
verifyWritable(Symbol, 'for');
|
||||
verifyConfigurable(Symbol, 'for');
|
23
test/built-ins/Symbol/for/retrieve-value.js
Normal file
23
test/built-ins/Symbol/for/retrieve-value.js
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.for
|
||||
es6id: 19.4.2.1
|
||||
description: Retrieval of previously-created value
|
||||
info: >
|
||||
1. Let stringKey be ? ToString(key).
|
||||
2. For each element e of the GlobalSymbolRegistry List,
|
||||
a. If SameValue(e.[[Key]], stringKey) is true, return e.[[Symbol]].
|
||||
3. Assert: GlobalSymbolRegistry does not currently contain an entry for
|
||||
stringKey.
|
||||
4. Let newSymbol be a new unique Symbol value whose [[Description]] value
|
||||
is stringKey.
|
||||
5. Append the Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the
|
||||
GlobalSymbolRegistry List.
|
||||
6. Return newSymbol.
|
||||
---*/
|
||||
|
||||
var canonical = Symbol.for('s');
|
||||
|
||||
assert.sameValue(typeof canonical, 'symbol');
|
||||
assert.sameValue(canonical, Symbol.for('s'));
|
25
test/built-ins/Symbol/for/to-string-err.js
Normal file
25
test/built-ins/Symbol/for/to-string-err.js
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.for
|
||||
es6id: 19.4.2.1
|
||||
description: Error resulting from string coercion of first argument
|
||||
info: >
|
||||
1. Let stringKey be ? ToString(key).
|
||||
---*/
|
||||
|
||||
var subject = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Symbol.for(subject);
|
||||
});
|
||||
|
||||
subject = Symbol('s');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.for(subject);
|
||||
});
|
45
test/built-ins/Symbol/keyFor/arg-non-symbol.js
Normal file
45
test/built-ins/Symbol/keyFor/arg-non-symbol.js
Normal file
@ -0,0 +1,45 @@
|
||||
// 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-symbol.keyfor
|
||||
es6id: 19.4.2.5
|
||||
description: Called with a non-symbol argument
|
||||
info: >
|
||||
1. If Type(sym) is not Symbol, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.keyFor, 'function');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor('1');
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor('');
|
||||
}, 'string');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor({});
|
||||
}, 'ordinary object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor([]);
|
||||
}, 'array exotic object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor(arguments);
|
||||
}, 'arguments exotic object');
|
||||
|
||||
var subject = Object(Symbol('s'));
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Symbol.keyFor(subject);
|
||||
}, 'symbol object');
|
15
test/built-ins/Symbol/keyFor/arg-symbol-registry-hit.js
Normal file
15
test/built-ins/Symbol/keyFor/arg-symbol-registry-hit.js
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.keyfor
|
||||
es6id: 19.4.2.5
|
||||
description: Called with Symbol value that exists in the global symbol registry
|
||||
info: >
|
||||
1. If Type(sym) is not Symbol, throw a TypeError exception.
|
||||
2. For each element e of the GlobalSymbolRegistry List (see 19.4.2.1),
|
||||
a. If SameValue(e.[[Symbol]], sym) is true, return e.[[Key]].
|
||||
---*/
|
||||
|
||||
var canonical = Symbol.for('s');
|
||||
|
||||
assert.sameValue(Symbol.keyFor(canonical), 's');
|
22
test/built-ins/Symbol/keyFor/arg-symbol-registry-miss.js
Normal file
22
test/built-ins/Symbol/keyFor/arg-symbol-registry-miss.js
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.keyfor
|
||||
es6id: 19.4.2.5
|
||||
description: >
|
||||
Called with Symbol value that does not exist in the global symbol registry
|
||||
info: >
|
||||
1. If Type(sym) is not Symbol, throw a TypeError exception.
|
||||
2. For each element e of the GlobalSymbolRegistry List (see 19.4.2.1),
|
||||
a. If SameValue(e.[[Symbol]], sym) is true, return e.[[Key]].
|
||||
3. Assert: GlobalSymbolRegistry does not currently contain an entry for
|
||||
sym.
|
||||
4. Return undefined.
|
||||
---*/
|
||||
|
||||
var constructed = Symbol('Symbol.iterator');
|
||||
assert.sameValue(Symbol.keyFor(constructed), undefined, 'constructed symbol');
|
||||
|
||||
assert.sameValue(
|
||||
Symbol.keyFor(Symbol.iterator), undefined, 'well-known symbol'
|
||||
);
|
18
test/built-ins/Symbol/keyFor/prop-desc.js
Normal file
18
test/built-ins/Symbol/keyFor/prop-desc.js
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.keyfor
|
||||
es6id: 19.4.2.5
|
||||
description: Property descriptor
|
||||
info: >
|
||||
Every other data property described in clauses 18 through 26 and in Annex
|
||||
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.keyFor, 'function');
|
||||
|
||||
verifyNotEnumerable(Symbol, 'keyFor');
|
||||
verifyWritable(Symbol, 'keyFor');
|
||||
verifyConfigurable(Symbol, 'keyFor');
|
18
test/built-ins/Symbol/prototype/constructor.js
vendored
Normal file
18
test/built-ins/Symbol/prototype/constructor.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.constructor
|
||||
es6id: 19.4.3.1
|
||||
description: Property descriptor
|
||||
info: >
|
||||
Every other data property described in clauses 18 through 26 and in Annex
|
||||
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(Symbol.prototype.constructor, Symbol);
|
||||
|
||||
verifyNotEnumerable(Symbol.prototype, 'constructor');
|
||||
verifyWritable(Symbol.prototype, 'constructor');
|
||||
verifyConfigurable(Symbol.prototype, 'constructor');
|
18
test/built-ins/Symbol/prototype/toString/prop-desc.js
vendored
Normal file
18
test/built-ins/Symbol/prototype/toString/prop-desc.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.tostring
|
||||
es6id: 19.4.3.2
|
||||
description: Property descriptor
|
||||
info: >
|
||||
Every other data property described in clauses 18 through 26 and in Annex
|
||||
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.prototype.toString, 'function');
|
||||
|
||||
verifyNotEnumerable(Symbol.prototype, 'toString');
|
||||
verifyWritable(Symbol.prototype, 'toString');
|
||||
verifyConfigurable(Symbol.prototype, 'toString');
|
18
test/built-ins/Symbol/prototype/valueOf/prop-desc.js
vendored
Normal file
18
test/built-ins/Symbol/prototype/valueOf/prop-desc.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.valueof
|
||||
es6id: 19.4.3.3
|
||||
description: Property descriptor
|
||||
info: >
|
||||
Every other data property described in clauses 18 through 26 and in Annex
|
||||
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.prototype.valueOf, 'function');
|
||||
|
||||
verifyNotEnumerable(Symbol.prototype, 'valueOf');
|
||||
verifyWritable(Symbol.prototype, 'valueOf');
|
||||
verifyConfigurable(Symbol.prototype, 'valueOf');
|
29
test/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js
vendored
Normal file
29
test/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.valueof
|
||||
es6id: 19.4.3.3
|
||||
description: Called on a value that is neither a Symbol nor an Object
|
||||
info: |
|
||||
1. Let s be the this value.
|
||||
2. If Type(s) is Symbol, return s.
|
||||
3. If Type(s) is not Object, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var valueOf = Symbol.prototype.valueOf;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call(0);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call('');
|
||||
}, 'string');
|
26
test/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js
vendored
Normal file
26
test/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.valueof
|
||||
es6id: 19.4.3.3
|
||||
description: Called on an Object value that is not a Symbol object
|
||||
info: |
|
||||
1. Let s be the this value.
|
||||
2. If Type(s) is Symbol, return s.
|
||||
3. If Type(s) is not Object, throw a TypeError exception.
|
||||
4. If s does not have a [[SymbolData]] internal slot, throw a TypeError exception.
|
||||
---*/
|
||||
|
||||
var valueOf = Symbol.prototype.valueOf;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call({});
|
||||
}, 'ordinary object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call([]);
|
||||
}, 'array exotic object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
valueOf.call(arguments);
|
||||
}, 'arguments exotic object');
|
19
test/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js
vendored
Normal file
19
test/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.valueof
|
||||
es6id: 19.4.3.3
|
||||
description: Called on a Symbol Object value
|
||||
info: |
|
||||
1. Let s be the this value.
|
||||
2. If Type(s) is Symbol, return s.
|
||||
3. If Type(s) is not Object, throw a TypeError exception.
|
||||
4. If s does not have a [[SymbolData]] internal slot, throw a TypeError exception.
|
||||
5. Return the value of s's [[SymbolData]] internal slot.
|
||||
---*/
|
||||
|
||||
var valueOf = Symbol.prototype.valueOf;
|
||||
var symbol = Symbol('s');
|
||||
var symbolObject = Object(symbol);
|
||||
|
||||
assert.sameValue(valueOf.call(symbolObject), symbol);
|
15
test/built-ins/Symbol/prototype/valueOf/this-val-symbol.js
vendored
Normal file
15
test/built-ins/Symbol/prototype/valueOf/this-val-symbol.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-symbol.prototype.valueof
|
||||
es6id: 19.4.3.3
|
||||
description: Called on a Symbol value
|
||||
info: |
|
||||
1. Let s be the this value.
|
||||
2. If Type(s) is Symbol, return s.
|
||||
---*/
|
||||
|
||||
var valueOf = Symbol.prototype.valueOf;
|
||||
var subject = Symbol('s');
|
||||
|
||||
assert.sameValue(valueOf.call(subject), subject);
|
Loading…
x
Reference in New Issue
Block a user