diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/Symbol/toPrimitive.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/Symbol/toPrimitive.js')
-rw-r--r-- | js/src/tests/ecma_6/Symbol/toPrimitive.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Symbol/toPrimitive.js b/js/src/tests/ecma_6/Symbol/toPrimitive.js new file mode 100644 index 000000000..06262f99c --- /dev/null +++ b/js/src/tests/ecma_6/Symbol/toPrimitive.js @@ -0,0 +1,39 @@ +// ES6 19.4.3.4 Symbol.prototype[@@toPrimitive](hint) + +// This method gets the primitive symbol from a Symbol wrapper object. +var sym = Symbol.for("truth") +var obj = Object(sym); +assertEq(obj[Symbol.toPrimitive]("default"), sym); + +// The hint argument is ignored. +assertEq(obj[Symbol.toPrimitive]("number"), sym); +assertEq(obj[Symbol.toPrimitive]("string"), sym); +assertEq(obj[Symbol.toPrimitive](), sym); +assertEq(obj[Symbol.toPrimitive](Math.atan2), sym); + +// The this value can also be a primitive symbol. +assertEq(sym[Symbol.toPrimitive](), sym); + +// Or a wrapper to a Symbol object in another compartment. +var obj2 = newGlobal().Object(sym); +assertEq(obj2[Symbol.toPrimitive]("default"), sym); + +// Otherwise a TypeError is thrown. +var symbolToPrimitive = Symbol.prototype[Symbol.toPrimitive]; +var nonSymbols = [ + undefined, null, true, 13, NaN, "justice", {}, [sym], + symbolToPrimitive, + new Proxy(obj, {}) +]; +for (var value of nonSymbols) { + assertThrowsInstanceOf(() => symbolToPrimitive.call(value, "string"), TypeError); +} + +// Surface features: +assertEq(symbolToPrimitive.name, "[Symbol.toPrimitive]"); +var desc = Object.getOwnPropertyDescriptor(Symbol.prototype, Symbol.toPrimitive); +assertEq(desc.configurable, true); +assertEq(desc.enumerable, false); +assertEq(desc.writable, false); + +reportCompare(0, 0); |