diff --git a/test/built-ins/Symbol/for/create-value.js b/test/built-ins/Symbol/for/create-value.js new file mode 100644 index 0000000000000000000000000000000000000000..b5ceaeacb9c1d196d948807d2f78fa366040d08a --- /dev/null +++ b/test/built-ins/Symbol/for/create-value.js @@ -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')); diff --git a/test/built-ins/Symbol/for/prop-desc.js b/test/built-ins/Symbol/for/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..3d61eef4d73ec5583f05791c0a7cb09f96441de7 --- /dev/null +++ b/test/built-ins/Symbol/for/prop-desc.js @@ -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'); diff --git a/test/built-ins/Symbol/for/retrieve-value.js b/test/built-ins/Symbol/for/retrieve-value.js new file mode 100644 index 0000000000000000000000000000000000000000..0bb28ca9f91b36bc8bd5a497f258255a6a9341a6 --- /dev/null +++ b/test/built-ins/Symbol/for/retrieve-value.js @@ -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')); diff --git a/test/built-ins/Symbol/for/to-string-err.js b/test/built-ins/Symbol/for/to-string-err.js new file mode 100644 index 0000000000000000000000000000000000000000..77348fbd4505fdf3d9510cdd6bd0f285bd040355 --- /dev/null +++ b/test/built-ins/Symbol/for/to-string-err.js @@ -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); +}); diff --git a/test/built-ins/Symbol/keyFor/arg-non-symbol.js b/test/built-ins/Symbol/keyFor/arg-non-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..2042cfa6f165edd7217e65f20ebbd386d1a6dc05 --- /dev/null +++ b/test/built-ins/Symbol/keyFor/arg-non-symbol.js @@ -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'); diff --git a/test/built-ins/Symbol/keyFor/arg-symbol-registry-hit.js b/test/built-ins/Symbol/keyFor/arg-symbol-registry-hit.js new file mode 100644 index 0000000000000000000000000000000000000000..cd20e0a3684b1ccfde1a6aa44611a2a15f6e100e --- /dev/null +++ b/test/built-ins/Symbol/keyFor/arg-symbol-registry-hit.js @@ -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'); diff --git a/test/built-ins/Symbol/keyFor/arg-symbol-registry-miss.js b/test/built-ins/Symbol/keyFor/arg-symbol-registry-miss.js new file mode 100644 index 0000000000000000000000000000000000000000..86bf657a8fd29fb6515786767d705b5152e3f769 --- /dev/null +++ b/test/built-ins/Symbol/keyFor/arg-symbol-registry-miss.js @@ -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' +); diff --git a/test/built-ins/Symbol/keyFor/prop-desc.js b/test/built-ins/Symbol/keyFor/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..c6b01bcc39ae5d8b347b538f34f9dbb3070123c8 --- /dev/null +++ b/test/built-ins/Symbol/keyFor/prop-desc.js @@ -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'); diff --git a/test/built-ins/Symbol/prototype/constructor.js b/test/built-ins/Symbol/prototype/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7b8b7f3e4a4c5d6c4c2fb982591b694d9f7988b1 --- /dev/null +++ b/test/built-ins/Symbol/prototype/constructor.js @@ -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'); diff --git a/test/built-ins/Symbol/prototype/toString/prop-desc.js b/test/built-ins/Symbol/prototype/toString/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..ad50fc0eb1f474e063f301d4cc6fce8f901cb100 --- /dev/null +++ b/test/built-ins/Symbol/prototype/toString/prop-desc.js @@ -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'); diff --git a/test/built-ins/Symbol/prototype/valueOf/prop-desc.js b/test/built-ins/Symbol/prototype/valueOf/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..32ba32fbf76bbb1aead724a3b714b872659dc902 --- /dev/null +++ b/test/built-ins/Symbol/prototype/valueOf/prop-desc.js @@ -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'); diff --git a/test/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js b/test/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js new file mode 100644 index 0000000000000000000000000000000000000000..39a053aed8fc676c1564c1b7db26acf6c1097f99 --- /dev/null +++ b/test/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js @@ -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'); diff --git a/test/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js b/test/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..e8ffe3bdfda9c967731261ce84ae3b3fc60f8c3b --- /dev/null +++ b/test/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.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-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'); diff --git a/test/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js b/test/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c34b6bbdd3db592c2050f33691582b3173f27a45 --- /dev/null +++ b/test/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js @@ -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); diff --git a/test/built-ins/Symbol/prototype/valueOf/this-val-symbol.js b/test/built-ins/Symbol/prototype/valueOf/this-val-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..395ba5b48cf29782f42912e043797e3347db2bc2 --- /dev/null +++ b/test/built-ins/Symbol/prototype/valueOf/this-val-symbol.js @@ -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);