diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Symbol/prototype | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Symbol/prototype')
45 files changed, 1060 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/browser.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/browser.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/length.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/length.js new file mode 100644 index 0000000000..b2cf331005 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/length.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.4 +description: Symbol.prototype[Symbol.toPrimitive] `length` property +info: | + ES6 section 17: + + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +features: [Symbol.toPrimitive] +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Symbol.prototype[Symbol.toPrimitive].length, 1); + +verifyNotEnumerable(Symbol.prototype[Symbol.toPrimitive], 'length'); +verifyNotWritable(Symbol.prototype[Symbol.toPrimitive], 'length'); +verifyConfigurable(Symbol.prototype[Symbol.toPrimitive], 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/name.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/name.js new file mode 100644 index 0000000000..58579822e7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.4 +description: Symbol.prototype[Symbol.toPrimitive] `name` property +info: | + The value of the name property of this function is "[Symbol.toPrimitive]". + + ES6 Section 17: + + [...] + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +features: [Symbol.toPrimitive] +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Symbol.prototype[Symbol.toPrimitive].name, '[Symbol.toPrimitive]' +); + +verifyNotEnumerable(Symbol.prototype[Symbol.toPrimitive], 'name'); +verifyNotWritable(Symbol.prototype[Symbol.toPrimitive], 'name'); +verifyConfigurable(Symbol.prototype[Symbol.toPrimitive], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/prop-desc.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/prop-desc.js new file mode 100644 index 0000000000..e4dc9ef2c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.4.3.4 +description: Symbol.prototype[Symbol.toPrimitive] property descriptor +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toPrimitive] +---*/ + +verifyNotEnumerable(Symbol.prototype, Symbol.toPrimitive); +verifyNotWritable(Symbol.prototype, Symbol.toPrimitive); +verifyConfigurable(Symbol.prototype, Symbol.toPrimitive); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/redefined-symbol-wrapper-ordinary-toprimitive.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/redefined-symbol-wrapper-ordinary-toprimitive.js new file mode 100644 index 0000000000..365b97f782 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/redefined-symbol-wrapper-ordinary-toprimitive.js @@ -0,0 +1,33 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-symbol.prototype-@@toprimitive +description: > + If redefined to nullish value, Symbol wrapper object is converted to primitive + via OrdinaryToPrimitive. +info: | + ToPrimitive ( input [ , preferredType ] ) + + [...] + 2. If Type(input) is Object, then + a. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + b. If exoticToPrim is not undefined, then + [...] + c. If preferredType is not present, let preferredType be number. + d. Return ? OrdinaryToPrimitive(input, preferredType). +features: [Symbol.toPrimitive] +---*/ + +Object.defineProperty(Symbol.prototype, Symbol.toPrimitive, { value: null }); + +assert.sameValue(Object(Symbol()) == "Symbol()", false, "hint: default"); +assert.throws(TypeError, () => { +Object(Symbol()); }, "hint: number"); +assert.sameValue(`${Object(Symbol())}`, "Symbol()", "hint: string"); + +Object.defineProperty(Symbol.prototype, Symbol.toPrimitive, { value: undefined }); + +assert(Object(Symbol.iterator) == Symbol.iterator, "hint: default"); +assert.throws(TypeError, () => { Object(Symbol()) <= ""; }, "hint: number"); +assert.sameValue({ "Symbol()": 1 }[Object(Symbol())], 1, "hint: string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/removed-symbol-wrapper-ordinary-toprimitive.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/removed-symbol-wrapper-ordinary-toprimitive.js new file mode 100644 index 0000000000..c5b22e3d7d --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/removed-symbol-wrapper-ordinary-toprimitive.js @@ -0,0 +1,85 @@ +// Copyright (C) 2021 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-symbol.prototype-@@toprimitive +description: > + If deleted, Symbol wrapper objects is converted to primitive via OrdinaryToPrimitive. +info: | + ToPrimitive ( input [ , preferredType ] ) + + [...] + 2. If Type(input) is Object, then + a. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + b. If exoticToPrim is not undefined, then + [...] + c. If preferredType is not present, let preferredType be number. + d. Return ? OrdinaryToPrimitive(input, preferredType). +features: [Symbol.toPrimitive] +---*/ + +assert(delete Symbol.prototype[Symbol.toPrimitive]); + +let valueOfGets = 0; +let valueOfCalls = 0; +let valueOfFunction = () => { ++valueOfCalls; return 123; }; +Object.defineProperty(Symbol.prototype, "valueOf", { + get: () => { ++valueOfGets; return valueOfFunction; }, +}); + +assert(Object(Symbol()) == 123, "hint: default"); +assert.sameValue(Object(Symbol()) - 0, 123, "hint: number"); +assert.sameValue("".concat(Object(Symbol())), "Symbol()", "hint: string"); + +assert.sameValue(valueOfGets, 2); +assert.sameValue(valueOfCalls, 2); + +let toStringGets = 0; +let toStringCalls = 0; +let toStringFunction = () => { ++toStringCalls; return "foo"; }; +Object.defineProperty(Symbol.prototype, "toString", { + get: () => { ++toStringGets; return toStringFunction; }, +}); + +assert.sameValue("" + Object(Symbol()), "123", "hint: default"); +assert.sameValue(Object(Symbol()) * 1, 123, "hint: number"); +assert.sameValue({ "123": 1, "Symbol()": 2, "foo": 3 }[Object(Symbol())], 3, "hint: string"); + +assert.sameValue(valueOfGets, 4); +assert.sameValue(valueOfCalls, 4); +assert.sameValue(toStringGets, 1); +assert.sameValue(toStringCalls, 1); + +valueOfFunction = null; + +assert.sameValue(new Date(Object(Symbol())).getTime(), NaN, "hint: default"); +assert.sameValue(+Object(Symbol()), NaN, "hint: number"); +assert.sameValue(`${Object(Symbol())}`, "foo", "hint: string"); + +assert.sameValue(valueOfGets, 6); +assert.sameValue(valueOfCalls, 4); +assert.sameValue(toStringGets, 4); +assert.sameValue(toStringCalls, 4); + +toStringFunction = function() { throw new Test262Error(); }; + +assert.throws(Test262Error, () => { Object(Symbol()) != 123; }, "hint: default"); +assert.throws(Test262Error, () => { Object(Symbol()) / 0; }, "hint: number"); +assert.throws(Test262Error, () => { "".concat(Object(Symbol())); }, "hint: string"); + +assert.sameValue(valueOfGets, 8); +assert.sameValue(valueOfCalls, 4); +assert.sameValue(toStringGets, 7); +assert.sameValue(toStringCalls, 4); + +toStringFunction = undefined; + +assert.throws(TypeError, () => { 1 + Object(Symbol()); }, "hint: default"); +assert.throws(TypeError, () => { Number(Object(Symbol())); }, "hint: number"); +assert.throws(TypeError, () => { String(Object(Symbol())); }, "hint: string"); + +assert.sameValue(valueOfGets, 11); +assert.sameValue(valueOfCalls, 4); +assert.sameValue(toStringGets, 10); +assert.sameValue(toStringCalls, 4); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/shell.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/shell.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-non-obj.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-non-obj.js new file mode 100644 index 0000000000..ac01982c62 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-non-obj.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.4 +description: Behavior when `this` value 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. +features: [Symbol.toPrimitive] +---*/ + +assert.sameValue(typeof Symbol.prototype[Symbol.toPrimitive], 'function'); + +assert.throws(TypeError, function() { + Symbol.prototype[Symbol.toPrimitive].call(undefined); +}); + +assert.throws(TypeError, function() { + Symbol.prototype[Symbol.toPrimitive].call(null); +}); + +assert.throws(TypeError, function() { + Symbol.prototype[Symbol.toPrimitive].call(86); +}); + +assert.throws(TypeError, function() { + Symbol.prototype[Symbol.toPrimitive].call(''); +}); + +assert.throws(TypeError, function() { + Symbol.prototype[Symbol.toPrimitive].call(true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-obj-non-symbol-wrapper.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-obj-non-symbol-wrapper.js new file mode 100644 index 0000000000..81af657246 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-obj-non-symbol-wrapper.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.4 +description: > + Behavior when `this` value is an object without a [[SymbolData]] internal + slot +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. +features: [Symbol.toPrimitive] +---*/ + +assert.throws(TypeError, function() { + Symbol.prototype[Symbol.toPrimitive].call({}); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-obj-symbol-wrapper.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-obj-symbol-wrapper.js new file mode 100644 index 0000000000..cb6c764c08 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-obj-symbol-wrapper.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.4 +description: > + Behavior when `this` value is an object with a [[SymbolData]] internal + slot +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. +features: [Symbol.toPrimitive] +---*/ + +assert.sameValue( + Object(Symbol.toPrimitive)[Symbol.toPrimitive](), Symbol.toPrimitive +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-symbol.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-symbol.js new file mode 100644 index 0000000000..3aec8491ae --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toPrimitive/this-val-symbol.js @@ -0,0 +1,14 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.4 +description: Behavior when `this` value is a Symbol +info: | + 1. Let s be the this value. + 2. If Type(s) is Symbol, return s. +features: [Symbol.toPrimitive] +---*/ + +assert.sameValue(Symbol.toPrimitive[Symbol.toPrimitive](), Symbol.toPrimitive); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..6090ef88bd --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/Symbol.toStringTag.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.5 +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "Symbol". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(Symbol.prototype[Symbol.toStringTag], 'Symbol'); + +verifyNotEnumerable(Symbol.prototype, Symbol.toStringTag); +verifyNotWritable(Symbol.prototype, Symbol.toStringTag); +verifyConfigurable(Symbol.prototype, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/browser.js b/js/src/tests/test262/built-ins/Symbol/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/constructor.js b/js/src/tests/test262/built-ins/Symbol/prototype/constructor.js new file mode 100644 index 0000000000..955fd837f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/constructor.js @@ -0,0 +1,20 @@ +// 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 +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] +features: [Symbol] +---*/ + +assert.sameValue(Symbol.prototype.constructor, Symbol); + +verifyNotEnumerable(Symbol.prototype, 'constructor'); +verifyWritable(Symbol.prototype, 'constructor'); +verifyConfigurable(Symbol.prototype, 'constructor'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/browser.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/browser.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/description-symboldescriptivestring.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/description-symboldescriptivestring.js new file mode 100644 index 0000000000..bd0a8bc867 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/description-symboldescriptivestring.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// Copyright (C) 2018 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-symbol.prototype.description +description: > + SymbolDescriptiveString(sym) via Symbol.prototype.toString() +info: | + SymbolDescriptiveString ( sym ) + + Assert: Type(sym) is Symbol. + Let desc be sym's [[Description]] value. + If desc is undefined, let desc be the empty string. + Assert: Type(desc) is String. + Return the string-concatenation of "Symbol(", desc, and ")". + +features: [Symbol.prototype.description] +---*/ + +const symbol = Symbol('foo'); + +assert.sameValue( + symbol.description, + 'foo', + 'The value of symbol.description is "foo"' +); +assert.sameValue( + symbol.toString(), + `Symbol(${symbol.description})`, + `symbol.toString() returns "Symbol(${symbol.description})"` +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/descriptor.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/descriptor.js new file mode 100644 index 0000000000..2f793f7cf3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/descriptor.js @@ -0,0 +1,41 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-symbol.prototype.description +description: > + Test the descriptor of Symbol.prototype.description. +info: | + `Symbol.prototype.description` is an accessor property whose + set accessor function is undefined. +includes: [propertyHelper.js] +features: [Symbol.prototype.description] +---*/ + + +var desc = Object.getOwnPropertyDescriptor(Symbol.prototype, 'description'); + +assert.sameValue( + desc.set, + undefined, + 'The value of desc.set is `undefined`' +); + +assert.sameValue( + desc.writable, + undefined, + 'The value of desc.writable is `undefined`' +); + +assert.sameValue( + typeof desc.get, + 'function', + 'The value of `typeof desc.get` is "function"' +); + +verifyProperty(Symbol.prototype, 'description', { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/get.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/get.js new file mode 100644 index 0000000000..91f007e2e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/get.js @@ -0,0 +1,43 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-symbol.prototype.description +description: > + Test the get accessor function of Symbol.prototype.description. +info: | + 1. Let s be the this value. + 2. Let sym be ? thisSymbolValue(s). + 3. Return sym.[[Description]]. +features: [Symbol.prototype.description] +---*/ + +const symbol = Symbol('test'); +assert.sameValue( + symbol.description, + 'test', + 'The value of symbol.description is "test"' +); + +const empty = Symbol(); +assert.sameValue( + empty.description, + undefined, + 'The value of empty.description is `undefined`' +); + +const undef = Symbol(undefined); +assert.sameValue( + undef.description, + undefined, + 'The value of undef.description is `undefined`' +); + +const emptyStr = Symbol(''); +assert.sameValue( + emptyStr.description, + '', + 'The value of emptyStr.description is ""' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/is-not-own-property.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/is-not-own-property.js new file mode 100644 index 0000000000..d5bbe141fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/is-not-own-property.js @@ -0,0 +1,16 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-symbol.prototype.description +description: Ensure that 'description' is not an own property of Symbols +features: [Symbol.prototype.description] +---*/ + +assert.sameValue( + Symbol().hasOwnProperty('description'), + false, + 'Symbol().hasOwnProperty("description") returns false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/shell.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/shell.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-non-symbol.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-non-symbol.js new file mode 100644 index 0000000000..8ab9d926f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-non-symbol.js @@ -0,0 +1,48 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-symbol.prototype.description +description: > + Behavior when "this" value is an object without a [[SymbolData]] internal + slot. +info: | + 1. Let s be the this value. + 2. Let sym be ? thisSymbolValue(s). + 3. Return sym.[[Description]]. +features: [Symbol.prototype.description] +---*/ + +const getter = Object.getOwnPropertyDescriptor( + Symbol.prototype, 'description' +).get; + +assert.throws(TypeError, function() { + getter.call(null); +}, 'getter.call(null) throws TypeError'); + +assert.throws(TypeError, function() { + getter.call(123); +}, 'getter.call(123) throws TypeError'); + +assert.throws(TypeError, function() { + getter.call('test'); +}, 'getter.call("test") throws TypeError'); + +assert.throws(TypeError, function() { + getter.call(true); +}, 'getter.call(true) throws TypeError'); + +assert.throws(TypeError, function() { + getter.call(undefined); +}, 'getter.call(undefined) throws TypeError'); + +assert.throws(TypeError, function() { + getter.call(new Proxy({}, {})); +}, 'getter.call(new Proxy({}, {})) throws TypeError'); + +assert.throws(TypeError, function() { + getter.call({}); +}, 'getter.call({}) throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-symbol.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-symbol.js new file mode 100644 index 0000000000..e685f777c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/this-val-symbol.js @@ -0,0 +1,67 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-symbol.prototype.description +description: > + Test that calling the getter on a Symbol or a Symbol wrapper object works. +info: | + 1. Let s be the this value. + 2. Let sym be ? thisSymbolValue(s). + 3. Return sym.[[Description]]. +features: [Symbol.prototype.description] +---*/ + +const getter = Object.getOwnPropertyDescriptor( + Symbol.prototype, 'description' +).get; + +const symbol = Symbol('test'); +assert.sameValue( + getter.call(symbol), + 'test', + 'getter.call(symbol) returns "test"' +); +assert.sameValue( + getter.call(Object(symbol)), + 'test', + 'getter.call(Object(symbol)) returns "test"' +); + +const empty = Symbol(); +assert.sameValue( + getter.call(empty), + undefined, + 'getter.call(empty) returns `undefined`' +); +assert.sameValue( + getter.call(Object(empty)), + undefined, + 'getter.call(Object(empty)) returns `undefined`' +); + +const undef = Symbol(undefined); +assert.sameValue( + getter.call(undef), + undefined, + 'getter.call(undef) returns `undefined`' +); +assert.sameValue( + getter.call(Object(undef)), + undefined, + 'getter.call(Object(undef)) returns `undefined`' +); + +const emptyStr = Symbol(''); +assert.sameValue( + getter.call(emptyStr), + '', + 'getter.call(emptyStr) returns ""' +); +assert.sameValue( + getter.call(Object(emptyStr)), + '', + 'getter.call(Object(emptyStr)) returns ""' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/description/wrapper.js b/js/src/tests/test262/built-ins/Symbol/prototype/description/wrapper.js new file mode 100644 index 0000000000..5c7f06d864 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/description/wrapper.js @@ -0,0 +1,43 @@ +// Copyright 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-symbol.prototype.description +description: > + Test Symbol.prototype.description called on wrapper objects. +info: | + 1. Let s be the this value. + 2. Let sym be ? thisSymbolValue(s). + 3. Return sym.[[Description]]. +features: [Symbol.prototype.description] +---*/ + +const symbol = Object(Symbol('test')); +assert.sameValue( + symbol.description, + 'test', + 'The value of symbol.description is "test"' +); + +const empty = Object(Symbol()); +assert.sameValue( + empty.description, + undefined, + 'The value of empty.description is `undefined`' +); + +const undef = Object(Symbol(undefined)); +assert.sameValue( + undef.description, + undefined, + 'The value of undef.description is `undefined`' +); + +const emptyStr = Object(Symbol('')); +assert.sameValue( + emptyStr.description, + '', + 'The value of emptyStr.description is ""' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/intrinsic.js b/js/src/tests/test262/built-ins/Symbol/prototype/intrinsic.js new file mode 100644 index 0000000000..84da0afeef --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/intrinsic.js @@ -0,0 +1,15 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3 +description: > + Symbol prototype +features: [Symbol] +---*/ +assert.sameValue( + Object.getPrototypeOf(Symbol('66')), + Symbol.prototype, + "`Object.getPrototypeOf(Symbol('66'))` returns `Symbol.prototype`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/shell.js b/js/src/tests/test262/built-ins/Symbol/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/browser.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/browser.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/length.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/length.js new file mode 100644 index 0000000000..84e95cf747 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.4.3.2 +description: > + Symbol.prototype.toString.length is 0. +info: | + Symbol.prototype.toString ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +assert.sameValue(Symbol.prototype.toString.length, 0); + +verifyNotEnumerable(Symbol.prototype.toString, "length"); +verifyNotWritable(Symbol.prototype.toString, "length"); +verifyConfigurable(Symbol.prototype.toString, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/name.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/name.js new file mode 100644 index 0000000000..705eb779f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.4.3.2 +description: > + Symbol.prototype.toString.name is "toString". +info: | + Symbol.prototype.toString ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +assert.sameValue(Symbol.prototype.toString.name, "toString"); + +verifyNotEnumerable(Symbol.prototype.toString, "name"); +verifyNotWritable(Symbol.prototype.toString, "name"); +verifyConfigurable(Symbol.prototype.toString, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/not-a-constructor.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/not-a-constructor.js new file mode 100644 index 0000000000..58914a60d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Symbol.prototype.toString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Symbol, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Symbol.prototype.toString), + false, + 'isConstructor(Symbol.prototype.toString) must return false' +); + +assert.throws(TypeError, () => { + let symbol = Symbol(); new symbol.toString(); +}, '`let symbol = Symbol(); new symbol.toString()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/prop-desc.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/prop-desc.js new file mode 100644 index 0000000000..689b1f3ab8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/prop-desc.js @@ -0,0 +1,20 @@ +// 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 +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] +features: [Symbol] +---*/ + +assert.sameValue(typeof Symbol.prototype.toString, 'function'); + +verifyNotEnumerable(Symbol.prototype, 'toString'); +verifyWritable(Symbol.prototype, 'toString'); +verifyConfigurable(Symbol.prototype, 'toString'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/shell.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/shell.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString-default-attributes-non-strict.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString-default-attributes-non-strict.js new file mode 100644 index 0000000000..f30864f4ad --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString-default-attributes-non-strict.js @@ -0,0 +1,19 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4 +description: > + Symbol property get and set, non-strict +flags: [noStrict] +features: [Symbol] +---*/ + +var sym = Symbol('66'); + +sym.toString = 0; +assert.sameValue(sym.toString(), 'Symbol(66)', "`sym.toString()` returns `'Symbol(66)'`, after executing `sym.toString = 0;`"); + +sym.valueOf = 0; +assert.sameValue(sym, sym.valueOf(), "The value of `sym` is `sym.valueOf()`, after executing `sym.valueOf = 0;`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString-default-attributes-strict-strict.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString-default-attributes-strict-strict.js new file mode 100644 index 0000000000..d33a0c6747 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString-default-attributes-strict-strict.js @@ -0,0 +1,22 @@ +'use strict'; +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4 +description: > + Symbol property get and set, strict +flags: [onlyStrict] +features: [Symbol] +---*/ + +var sym = Symbol("66"); + +assert.throws(TypeError, function() { + sym.toString = 0; +}); + +assert.throws(TypeError, function() { + sym.valueOf = 0; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString.js new file mode 100644 index 0000000000..bc90108708 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/toString.js @@ -0,0 +1,30 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.3.2 +description: > + toString operations on Symbols +features: [Symbol] +---*/ +assert.sameValue( + String(Symbol('66')), + 'Symbol(66)', + "`String(Symbol('66'))` returns `'Symbol(66)'`" +) +assert.sameValue( + Symbol('66').toString(), + 'Symbol(66)', + "`Symbol('66').toString()` returns `'Symbol(66)'`" +); +assert.sameValue( + Object(Symbol('66')).toString(), + 'Symbol(66)', + "`Object(Symbol('66')).toString()` returns `'Symbol(66)'`" +); +assert.sameValue( + Symbol.prototype.toString.call(Symbol('66')), + 'Symbol(66)', + "`Symbol.prototype.toString.call(Symbol('66'))` returns `'Symbol(66)'`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/toString/undefined.js b/js/src/tests/test262/built-ins/Symbol/prototype/toString/undefined.js new file mode 100644 index 0000000000..808657dfa8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/toString/undefined.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-constructor +description: The value "undefined" is reported as the empty string +info: | + 1. If NewTarget is not undefined, throw a TypeError exception. + 2. If description is undefined, let descString be undefined. + 2. Else, let descString be ? ToString(description). + 3. Return a new unique Symbol value whose [[Description]] value is + descString. + + 19.4.3.2.1 Runtime Semantics: SymbolDescriptiveString + + 1. Assert: Type(sym) is Symbol. + 2. Let desc be sym's [[Description]] value. + 3. If desc is undefined, let desc be the empty string. + 4. Assert: Type(desc) is String. + 5. Return the result of concatenating the strings "Symbol(", desc, and ")". +features: [Symbol] +---*/ + +assert.sameValue(Symbol().toString(), 'Symbol()', 'implicit value'); +assert.sameValue(Symbol(undefined).toString(), 'Symbol()', 'explicit value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/browser.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/browser.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/length.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/length.js new file mode 100644 index 0000000000..0134f86d03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.4.3.3 +description: > + Symbol.prototype.valueOf.length is 0. +info: | + Symbol.prototype.valueOf ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +assert.sameValue(Symbol.prototype.valueOf.length, 0); + +verifyNotEnumerable(Symbol.prototype.valueOf, "length"); +verifyNotWritable(Symbol.prototype.valueOf, "length"); +verifyConfigurable(Symbol.prototype.valueOf, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/name.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/name.js new file mode 100644 index 0000000000..a9104cd8a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.4.3.3 +description: > + Symbol.prototype.valueOf.name is "valueOf". +info: | + Symbol.prototype.valueOf ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +assert.sameValue(Symbol.prototype.valueOf.name, "valueOf"); + +verifyNotEnumerable(Symbol.prototype.valueOf, "name"); +verifyNotWritable(Symbol.prototype.valueOf, "name"); +verifyConfigurable(Symbol.prototype.valueOf, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/not-a-constructor.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/not-a-constructor.js new file mode 100644 index 0000000000..e9edf778b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Symbol.prototype.valueOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Symbol, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Symbol.prototype.valueOf), + false, + 'isConstructor(Symbol.prototype.valueOf) must return false' +); + +assert.throws(TypeError, () => { + let symbol = Symbol(); new symbol.valueOf(); +}, '`let symbol = Symbol(); new symbol.valueOf()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/prop-desc.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/prop-desc.js new file mode 100644 index 0000000000..765157b4be --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/prop-desc.js @@ -0,0 +1,20 @@ +// 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 +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] +features: [Symbol] +---*/ + +assert.sameValue(typeof Symbol.prototype.valueOf, 'function'); + +verifyNotEnumerable(Symbol.prototype, 'valueOf'); +verifyWritable(Symbol.prototype, 'valueOf'); +verifyConfigurable(Symbol.prototype, 'valueOf'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/shell.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/shell.js diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js new file mode 100644 index 0000000000..fe5ee15166 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-non-obj.js @@ -0,0 +1,31 @@ +// 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 +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. +features: [Symbol] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js new file mode 100644 index 0000000000..876780fb86 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-obj-non-symbol.js @@ -0,0 +1,28 @@ +// 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 +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. +features: [Symbol] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js new file mode 100644 index 0000000000..1a992371b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-obj-symbol.js @@ -0,0 +1,21 @@ +// 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 +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. +features: [Symbol] +---*/ + +var valueOf = Symbol.prototype.valueOf; +var symbol = Symbol('s'); +var symbolObject = Object(symbol); + +assert.sameValue(valueOf.call(symbolObject), symbol); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-symbol.js b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-symbol.js new file mode 100644 index 0000000000..7bea7e00e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Symbol/prototype/valueOf/this-val-symbol.js @@ -0,0 +1,17 @@ +// 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 +description: Called on a Symbol value +info: | + 1. Let s be the this value. + 2. If Type(s) is Symbol, return s. +features: [Symbol] +---*/ + +var valueOf = Symbol.prototype.valueOf; +var subject = Symbol('s'); + +assert.sameValue(valueOf.call(subject), subject); + +reportCompare(0, 0); |