From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../test262/built-ins/isNaN/S15.1.2.4_A2.6.js | 11 ++++ .../test262/built-ins/isNaN/S15.1.2.4_A2.7.js | 17 +++++ js/src/tests/test262/built-ins/isNaN/browser.js | 0 js/src/tests/test262/built-ins/isNaN/length.js | 17 +++++ js/src/tests/test262/built-ins/isNaN/name.js | 28 ++++++++ .../test262/built-ins/isNaN/not-a-constructor.js | 31 +++++++++ js/src/tests/test262/built-ins/isNaN/prop-desc.js | 15 +++++ .../return-abrupt-from-tonumber-number-symbol.js | 21 ++++++ .../isNaN/return-abrupt-from-tonumber-number.js | 34 ++++++++++ .../isNaN/return-false-not-nan-numbers.js | 29 +++++++++ .../test262/built-ins/isNaN/return-true-nan.js | 20 ++++++ js/src/tests/test262/built-ins/isNaN/shell.js | 48 ++++++++++++++ .../test262/built-ins/isNaN/tonumber-operations.js | 29 +++++++++ .../built-ins/isNaN/toprimitive-call-abrupt.js | 31 +++++++++ .../built-ins/isNaN/toprimitive-get-abrupt.js | 30 +++++++++ .../isNaN/toprimitive-not-callable-throws.js | 54 ++++++++++++++++ .../isNaN/toprimitive-result-is-object-throws.js | 33 ++++++++++ .../isNaN/toprimitive-result-is-symbol-throws.js | 37 +++++++++++ .../built-ins/isNaN/toprimitive-valid-result.js | 74 ++++++++++++++++++++++ 19 files changed, 559 insertions(+) create mode 100644 js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.6.js create mode 100644 js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.7.js create mode 100644 js/src/tests/test262/built-ins/isNaN/browser.js create mode 100644 js/src/tests/test262/built-ins/isNaN/length.js create mode 100644 js/src/tests/test262/built-ins/isNaN/name.js create mode 100644 js/src/tests/test262/built-ins/isNaN/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/isNaN/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number-symbol.js create mode 100644 js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number.js create mode 100644 js/src/tests/test262/built-ins/isNaN/return-false-not-nan-numbers.js create mode 100644 js/src/tests/test262/built-ins/isNaN/return-true-nan.js create mode 100644 js/src/tests/test262/built-ins/isNaN/shell.js create mode 100644 js/src/tests/test262/built-ins/isNaN/tonumber-operations.js create mode 100644 js/src/tests/test262/built-ins/isNaN/toprimitive-call-abrupt.js create mode 100644 js/src/tests/test262/built-ins/isNaN/toprimitive-get-abrupt.js create mode 100644 js/src/tests/test262/built-ins/isNaN/toprimitive-not-callable-throws.js create mode 100644 js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-object-throws.js create mode 100644 js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-symbol-throws.js create mode 100644 js/src/tests/test262/built-ins/isNaN/toprimitive-valid-result.js (limited to 'js/src/tests/test262/built-ins/isNaN') diff --git a/js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.6.js b/js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.6.js new file mode 100644 index 0000000000..acb0f32cbe --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.6.js @@ -0,0 +1,11 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The isNaN property has not prototype property +esid: sec-isnan-number +description: Checking isNaN.prototype +---*/ +assert.sameValue(isNaN.prototype, undefined, 'The value of isNaN.prototype is expected to equal undefined'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.7.js b/js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.7.js new file mode 100644 index 0000000000..d258ef2f54 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/S15.1.2.4_A2.7.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The isNaN property can't be used as constructor +esid: sec-isnan-number +description: > + If property does not implement the internal [[Construct]] method, + throw a TypeError exception +---*/ + +assert.throws(TypeError, () => { + new isNaN(); + throw new Test262Error(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/browser.js b/js/src/tests/test262/built-ins/isNaN/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/isNaN/length.js b/js/src/tests/test262/built-ins/isNaN/length.js new file mode 100644 index 0000000000..01e06d1602 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/length.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-isnan-number +description: > + The length property of isNaN is 1 +includes: [propertyHelper.js] +---*/ + +assert.sameValue(isNaN.length, 1, "The value of `isNaN.length` is `1`"); + +verifyNotEnumerable(isNaN, "length"); +verifyNotWritable(isNaN, "length"); +verifyConfigurable(isNaN, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/name.js b/js/src/tests/test262/built-ins/isNaN/name.js new file mode 100644 index 0000000000..967a74566e --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-isnan-number +description: > + isNaN.name is "isNaN". +info: | + isNaN (number) + + 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] +---*/ + +assert.sameValue(isNaN.name, "isNaN"); + +verifyNotEnumerable(isNaN, "name"); +verifyNotWritable(isNaN, "name"); +verifyConfigurable(isNaN, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/not-a-constructor.js b/js/src/tests/test262/built-ins/isNaN/not-a-constructor.js new file mode 100644 index 0000000000..840489d16b --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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: > + isNaN 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, arrow-function] +---*/ + +assert.sameValue(isConstructor(isNaN), false, 'isConstructor(isNaN) must return false'); + +assert.throws(TypeError, () => { + new isNaN(1); +}, '`new isNaN(1)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/prop-desc.js b/js/src/tests/test262/built-ins/isNaN/prop-desc.js new file mode 100644 index 0000000000..f4b2d6b4cf --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/prop-desc.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-isnan-number +description: > + Property descriptor for isNaN +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, "isNaN"); +verifyWritable(this, "isNaN"); +verifyConfigurable(this, "isNaN"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number-symbol.js b/js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number-symbol.js new file mode 100644 index 0000000000..776aab4cc8 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number-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-isnan-number +description: > + Throws a TypeError if number is a Symbol +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). +features: [Symbol] +---*/ + +var s = Symbol(1); + +assert.throws(TypeError, function() { + isNaN(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number.js b/js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number.js new file mode 100644 index 0000000000..78ae26e8f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/return-abrupt-from-tonumber-number.js @@ -0,0 +1,34 @@ +// 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-isnan-number +description: > + Return abrupt completion from ToNumber(number) +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + isNaN(obj1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + isNaN(obj2); +}, "toString"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/return-false-not-nan-numbers.js b/js/src/tests/test262/built-ins/isNaN/return-false-not-nan-numbers.js new file mode 100644 index 0000000000..0c8edee16f --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/return-false-not-nan-numbers.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-isnan-number +description: > + Return false if number is not NaN +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + 2. If num is NaN, return true. + 3. Otherwise, return false. +---*/ + +assert.sameValue(isNaN(0), false, "0"); +assert.sameValue(isNaN(-0), false, "-0"); +assert.sameValue(isNaN(Math.pow(2, 53)), false, "Math.pow(2, 53)"); +assert.sameValue(isNaN(-Math.pow(2, 53)), false, "-Math.pow(2, 53)"); +assert.sameValue(isNaN(1), false, "1"); +assert.sameValue(isNaN(-1), false, "-1"); +assert.sameValue(isNaN(0.000001), false, "0.000001"); +assert.sameValue(isNaN(-0.000001), false, "-0.000001"); +assert.sameValue(isNaN(1e42), false, "1e42"); +assert.sameValue(isNaN(-1e42), false, "-1e42"); +assert.sameValue(isNaN(Infinity), false, "Infinity"); +assert.sameValue(isNaN(-Infinity), false, "-Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/return-true-nan.js b/js/src/tests/test262/built-ins/isNaN/return-true-nan.js new file mode 100644 index 0000000000..72ffce1274 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/return-true-nan.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-isnan-number +description: > + Return true if number is NaN +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + 2. If num is NaN, return true. +includes: [nans.js] +---*/ + +NaNs.forEach(function(v, i) { + assert.sameValue(isNaN(v), true, "value on position: " + i); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/shell.js b/js/src/tests/test262/built-ins/isNaN/shell.js new file mode 100644 index 0000000000..11ebe418d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/shell.js @@ -0,0 +1,48 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; diff --git a/js/src/tests/test262/built-ins/isNaN/tonumber-operations.js b/js/src/tests/test262/built-ins/isNaN/tonumber-operations.js new file mode 100644 index 0000000000..f2eb404fbe --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/tonumber-operations.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-isnan-number +description: > + number argument is converted by ToNumber +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + 2. If num is NaN, return true. + 3. Otherwise, return false. +---*/ + +assert.sameValue(isNaN("0"), false, "'0'"); +assert.sameValue(isNaN(""), false, "the empty string"); +assert.sameValue(isNaN("Infinity"), false, "'Infinity'"); +assert.sameValue(isNaN("this is not a number"), true, "string"); +assert.sameValue(isNaN(true), false, "true"); +assert.sameValue(isNaN(false), false, "false"); +assert.sameValue(isNaN([1]), false, "Object [1]"); +assert.sameValue(isNaN([Infinity]), false, "Object [Infinity]"); +assert.sameValue(isNaN([NaN]), true, "Object [NaN]"); +assert.sameValue(isNaN(null), false, "null"); +assert.sameValue(isNaN(undefined), true, "undefined"); +assert.sameValue(isNaN(), true, "no arg"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/toprimitive-call-abrupt.js b/js/src/tests/test262/built-ins/isNaN/toprimitive-call-abrupt.js new file mode 100644 index 0000000000..c02b22e5f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/toprimitive-call-abrupt.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-isnan-number +description: > + Return abrupt completion calling number.@@toPrimitive +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + + ToPrimitive ( input [ , PreferredType ] ) + + [...] + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). +features: [Symbol.toPrimitive] +---*/ + +var obj = {}; +obj[Symbol.toPrimitive] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + isNaN(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/toprimitive-get-abrupt.js b/js/src/tests/test262/built-ins/isNaN/toprimitive-get-abrupt.js new file mode 100644 index 0000000000..3b9ebca197 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/toprimitive-get-abrupt.js @@ -0,0 +1,30 @@ +// 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-isnan-number +description: > + Return abrupt completion getting number.@@toPrimitive +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + + ToPrimitive ( input [ , PreferredType ] ) + + [...] + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). +features: [Symbol.toPrimitive] +---*/ + +var obj = Object.defineProperty({}, Symbol.toPrimitive, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + isNaN(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/toprimitive-not-callable-throws.js b/js/src/tests/test262/built-ins/isNaN/toprimitive-not-callable-throws.js new file mode 100644 index 0000000000..fdf011c870 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/toprimitive-not-callable-throws.js @@ -0,0 +1,54 @@ +// 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-isnan-number +description: > + Throws a TypeError if number.@@toPrimitive is not null, undefined, or callable +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + + ToPrimitive ( input [ , PreferredType ] ) + + [...] + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + + GetMethod (V, P) + + [...] + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. + 4. If IsCallable(func) is false, throw a TypeError exception. +features: [Symbol.toPrimitive] +---*/ + +var obj = {}; + +obj[Symbol.toPrimitive] = 42; +assert.throws(TypeError, function() { + isNaN(obj); +}, "number"); + +obj[Symbol.toPrimitive] = ""; +assert.throws(TypeError, function() { + isNaN(obj); +}, "string"); + +obj[Symbol.toPrimitive] = true; +assert.throws(TypeError, function() { + isNaN(obj); +}, "boolean"); + +obj[Symbol.toPrimitive] = Symbol.toPrimitive; +assert.throws(TypeError, function() { + isNaN(obj); +}, "symbol"); + +obj[Symbol.toPrimitive] = {}; +assert.throws(TypeError, function() { + isNaN(obj); +}, "object"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-object-throws.js b/js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-object-throws.js new file mode 100644 index 0000000000..041a64e11f --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-object-throws.js @@ -0,0 +1,33 @@ +// 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-isnan-number +description: > + Throws a TypeError if the result of calling number.@@toPrimitive is an Object +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + + ToPrimitive ( input [ , PreferredType ] ) + + [...] + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. + c. Throw a TypeError exception. +features: [Symbol.toPrimitive] +---*/ + +var obj = {}; +obj[Symbol.toPrimitive] = function() { + return [42]; +}; + +assert.throws(TypeError, function() { + isNaN(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-symbol-throws.js b/js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-symbol-throws.js new file mode 100644 index 0000000000..69cbf6e5f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-symbol-throws.js @@ -0,0 +1,37 @@ +// 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-isnan-number +description: > + Throws a TypeError if the result of calling number.@@toPrimitive is a symbol +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + + ToNumber ( argument ) + + 1. Let primValue be ? ToPrimitive(argument, hint Number). + 2. Return ? ToNumber(primValue). + + ToPrimitive ( input [ , PreferredType ] ) + + [...] + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. +features: [Symbol.toPrimitive] +---*/ + +var obj = {}; +obj[Symbol.toPrimitive] = function() { + return Symbol.toPrimitive; +}; + +assert.throws(TypeError, function() { + isNaN(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/isNaN/toprimitive-valid-result.js b/js/src/tests/test262/built-ins/isNaN/toprimitive-valid-result.js new file mode 100644 index 0000000000..1946134665 --- /dev/null +++ b/js/src/tests/test262/built-ins/isNaN/toprimitive-valid-result.js @@ -0,0 +1,74 @@ +// 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-isnan-number +description: > + Use non-object value returned from @@toPrimitive method +info: | + isNaN (number) + + 1. Let num be ? ToNumber(number). + + ToPrimitive ( input [ , PreferredType ] ) + + [...] + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. +features: [Symbol.toPrimitive] +---*/ + +var called = 0; +var obj = { + valueOf: function() { + called = NaN; + return Infinity; + }, + toString: function() { + called = NaN; + return Infinity; + } +}; + +obj[Symbol.toPrimitive] = function() { + called += 1; + return 42; +}; +assert.sameValue(isNaN(obj), false, "use returned value - non-NaN number"); +assert.sameValue(called, 1, "toPrimitive is called - non-NaN number"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return "this is not a number"; +}; +assert.sameValue(isNaN(obj), true, "use returned value - string to NaN"); +assert.sameValue(called, 1, "toPrimitive is called - string to NaN"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return true; +}; +assert.sameValue(isNaN(obj), false, "use returned value - boolean true"); +assert.sameValue(called, 1, "toPrimitive is called - boolean true"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return false; +}; +assert.sameValue(isNaN(obj), false, "use returned value - boolean false"); +assert.sameValue(called, 1, "toPrimitive is called - boolean false"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return NaN; +}; +assert.sameValue(isNaN(obj), true, "use returned value - NaN"); +assert.sameValue(called, 1, "toPrimitive is called - NaN"); + +reportCompare(0, 0); -- cgit v1.2.3