From 81f22800fa237b5af2e451d82d01614e75bcd751 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Thu, 30 Jun 2016 12:57:00 -0300 Subject: [PATCH] Update and expand tests for isFinite --- test/built-ins/isFinite/S15.1.2.5_A1_T1.js | 70 ---------------- test/built-ins/isFinite/S15.1.2.5_A1_T2.js | 40 --------- test/built-ins/isFinite/S15.1.2.5_A2.1.js | 25 ------ test/built-ins/isFinite/S15.1.2.5_A2.2.js | 25 ------ test/built-ins/isFinite/S15.1.2.5_A2.3.js | 16 ---- test/built-ins/isFinite/S15.1.2.5_A2.4.js | 13 --- test/built-ins/isFinite/S15.1.2.5_A2.5.js | 25 ------ test/built-ins/isFinite/S15.1.2.5_A2.6.js | 2 +- test/built-ins/isFinite/length.js | 16 ++++ test/built-ins/isFinite/prop-desc.js | 14 ++++ ...turn-abrupt-from-tonumber-number-symbol.js | 20 +++++ .../return-abrupt-from-tonumber-number.js | 33 ++++++++ .../return-false-on-nan-or-infinities.js | 18 +++++ .../return-true-for-valid-finite-numbers.js | 26 ++++++ .../built-ins/isFinite/tonumber-operations.js | 28 +++++++ .../isFinite/toprimitive-call-abrupt.js | 30 +++++++ .../isFinite/toprimitive-get-abrupt.js | 29 +++++++ .../toprimitive-not-callable-throws.js | 53 ++++++++++++ .../toprimitive-result-is-object-throws.js | 32 ++++++++ .../toprimitive-result-is-symbol-throws.js | 36 +++++++++ .../isFinite/toprimitive-valid-result.js | 81 +++++++++++++++++++ 21 files changed, 417 insertions(+), 215 deletions(-) delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A1_T1.js delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A1_T2.js delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A2.1.js delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A2.2.js delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A2.3.js delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A2.4.js delete mode 100644 test/built-ins/isFinite/S15.1.2.5_A2.5.js create mode 100644 test/built-ins/isFinite/length.js create mode 100644 test/built-ins/isFinite/prop-desc.js create mode 100644 test/built-ins/isFinite/return-abrupt-from-tonumber-number-symbol.js create mode 100644 test/built-ins/isFinite/return-abrupt-from-tonumber-number.js create mode 100644 test/built-ins/isFinite/return-false-on-nan-or-infinities.js create mode 100644 test/built-ins/isFinite/return-true-for-valid-finite-numbers.js create mode 100644 test/built-ins/isFinite/tonumber-operations.js create mode 100644 test/built-ins/isFinite/toprimitive-call-abrupt.js create mode 100644 test/built-ins/isFinite/toprimitive-get-abrupt.js create mode 100644 test/built-ins/isFinite/toprimitive-not-callable-throws.js create mode 100644 test/built-ins/isFinite/toprimitive-result-is-object-throws.js create mode 100644 test/built-ins/isFinite/toprimitive-result-is-symbol-throws.js create mode 100644 test/built-ins/isFinite/toprimitive-valid-result.js diff --git a/test/built-ins/isFinite/S15.1.2.5_A1_T1.js b/test/built-ins/isFinite/S15.1.2.5_A1_T1.js deleted file mode 100644 index c818bd1546..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A1_T1.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: > - isFinite applies ToNumber to its argument, then return false if the - result is NaN, +Infinity, -Infinity, and otherwise return true -es5id: 15.1.2.5_A1_T1 -description: Checking all primitive ----*/ - -// CHECK#1 -if (!(isFinite(NaN) === false)) { - $ERROR('#1: NaN === Not-a-Finite. Actual: ' + (NaN)); -} - -// CHECK#2 -if (!(isFinite(Number.NaN) === false)) { - $ERROR('#2: Number.NaN === Not-a-Finite. Actual: ' + (Number.NaN)); -} - -// CHECK#3 -if (!(isFinite(Number(void 0)) === false)) { - $ERROR('#3: Number(void 0) === Not-a-Finite. Actual: ' + (Number(void 0))); -} - -// CHECK#4 -if (!(isFinite(void 0) === false)) { - $ERROR('#4: void 0 === Not-a-Finite. Actual: ' + (void 0)); -} - -// CHECK#5 -if (!(isFinite("string") === false)) { - $ERROR('#5: "string" === Not-a-Finite. Actual: ' + ("string")); -} - -// CHECK#6 -if (isFinite(Number.POSITIVE_INFINITY) !== false) { - $ERROR('#6: Number.POSITIVE_INFINITY === Not-a-Finite. Actual: ' + (Number.POSITIVE_INFINITY)); -} - -// CHECK#7 -if (isFinite(Number.NEGATIVE_INFINITY) !== false) { - $ERROR('#7: Number.NEGATIVE_INFINITY === Not-a-Finite. Actual: ' + (Number.NEGATIVE_INFINITY)); -} - -// CHECK#8 -if (isFinite(Number.MAX_VALUE) === false) { - $ERROR('#8: Number.MAX_VALUE !== Not-a-Finite'); -} - -// CHECK#9 -if (isFinite(Number.MIN_VALUE) === false) { - $ERROR('#9: Number.MIN_VALUE !== Not-a-Finite'); -} - -// CHECK#10 -if (isFinite(-0) === false) { - $ERROR('#10: -0 !== Not-a-Finite'); -} - -// CHECK#11 -if (isFinite(false) === false) { - $ERROR('#11: false !== Not-a-Finite'); -} - -// CHECK#12 -if (isFinite("1") === false) { - $ERROR('#12: "1" !== Not-a-Finite'); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A1_T2.js b/test/built-ins/isFinite/S15.1.2.5_A1_T2.js deleted file mode 100644 index 607ad89aae..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A1_T2.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: > - isFinite applies ToNumber to its argument, then return false if the - result is NaN, +Infinity, -Infinity, and otherwise return true -es5id: 15.1.2.5_A1_T2 -description: Checking all object ----*/ - -// CHECK#1 -if (!(isFinite({}) === false)) { - $ERROR('#1: {} === Not-a-Finite. Actual: ' + ({})); -} - -// CHECK#2 -if (!(isFinite(new String("string")) === false)) { - $ERROR('#2: new String("string") === Not-a-Finite. Actual: ' + (new String("string"))); -} - -// CHECK#3 -if (isFinite(new String("1")) === false) { - $ERROR('#3: new String("1") === Not-a-Finite. Actual: ' + (new String("1"))); -} - -// CHECK#4 -if (isFinite(new Number(1)) === false) { - $ERROR('#4: new Number(1) !== Not-a-Finite'); -} - -// CHECK#5 -if (!(isFinite(new Number(NaN)) === false)) { - $ERROR('#5: new Number(NaN) === Not-a-Finite. Actual: ' + (new Number(NaN))); -} - -// CHECK#6 -if (isFinite(new Boolean(true)) === false) { - $ERROR('#6: new Boolean(true) !== Not-a-Finite'); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A2.1.js b/test/built-ins/isFinite/S15.1.2.5_A2.1.js deleted file mode 100644 index a409f4ebb5..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A2.1.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: The length property of isFinite has the attribute DontEnum -es5id: 15.1.2.5_A2.1 -description: Checking use propertyIsEnumerable, for-in ----*/ - -//CHECK#1 -if (isFinite.propertyIsEnumerable('length') !== false) { - $ERROR('#1: isFinite.propertyIsEnumerable(\'length\') === false. Actual: ' + (isFinite.propertyIsEnumerable('length'))); -} - -//CHECK#2 -var result = true; -for (var p in isFinite){ - if (p === "length") { - result = false; - } -} - -if (result !== true) { - $ERROR('#2: result = true; for (p in isFinite) { if (p === "length") result = false; } result === true;'); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A2.2.js b/test/built-ins/isFinite/S15.1.2.5_A2.2.js deleted file mode 100644 index b133621897..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A2.2.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: The length property of isFinite does not have the attribute DontDelete -es5id: 15.1.2.5_A2.2 -description: Checking use hasOwnProperty, delete ----*/ - -//CHECK#1 -if (isFinite.hasOwnProperty('length') !== true) { - $ERROR('#1: isFinite.hasOwnProperty(\'length\') === true. Actual: ' + (isFinite.hasOwnProperty('length'))); -} - -delete isFinite.length; - -//CHECK#2 -if (isFinite.hasOwnProperty('length') !== false) { - $ERROR('#2: delete isFinite.length; isFinite.hasOwnProperty(\'length\') === false. Actual: ' + (isFinite.hasOwnProperty('length'))); -} - -//CHECK#3 -if (isFinite.length === undefined) { - $ERROR('#3: delete isFinite.length; isFinite.length !== undefined'); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A2.3.js b/test/built-ins/isFinite/S15.1.2.5_A2.3.js deleted file mode 100644 index ea89d94a38..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A2.3.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: The length property of isFinite has the attribute ReadOnly -es5id: 15.1.2.5_A2.3 -description: Checking if varying the length property fails -includes: [propertyHelper.js] ----*/ - -//CHECK#1 -var x = isFinite.length; -verifyNotWritable(isFinite, "length", null, Infinity); -if (isFinite.length !== x) { - $ERROR('#1: x = isFinite.length; isFinite.length = Infinity; isFinite.length === x. Actual: ' + (isFinite.length)); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A2.4.js b/test/built-ins/isFinite/S15.1.2.5_A2.4.js deleted file mode 100644 index 6af10f2a1f..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A2.4.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: The length property of isFinite is 1 -es5id: 15.1.2.5_A2.4 -description: isFinite.length === 1 ----*/ - -//CHECK#1 -if (isFinite.length !== 1) { - $ERROR('#1: isFinite.length === 1. Actual: ' + (isFinite.length)); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A2.5.js b/test/built-ins/isFinite/S15.1.2.5_A2.5.js deleted file mode 100644 index 42057474c9..0000000000 --- a/test/built-ins/isFinite/S15.1.2.5_A2.5.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: The isFinite property has the attribute DontEnum -es5id: 15.1.2.5_A2.5 -description: Checking use propertyIsEnumerable, for-in ----*/ - -//CHECK#1 -if (this.propertyIsEnumerable('isFinite') !== false) { - $ERROR('#1: this.propertyIsEnumerable(\'isFinite\') === false. Actual: ' + (this.propertyIsEnumerable('isFinite'))); -} - -//CHECK#2 -var result = true; -for (var p in this){ - if (p === "isFinite") { - result = false; - } -} - -if (result !== true) { - $ERROR('#2: result = true; for (p in this) { if (p === "isFinite") result = false; } result === true;'); -} diff --git a/test/built-ins/isFinite/S15.1.2.5_A2.6.js b/test/built-ins/isFinite/S15.1.2.5_A2.6.js index 71011f1dfe..5a0e9406d9 100644 --- a/test/built-ins/isFinite/S15.1.2.5_A2.6.js +++ b/test/built-ins/isFinite/S15.1.2.5_A2.6.js @@ -4,7 +4,7 @@ /*--- info: The isFinite property has not prototype property es5id: 15.1.2.5_A2.6 -description: Checking isFinit.prototype +description: Checking isFinite.prototype ---*/ //CHECK#1 diff --git a/test/built-ins/isFinite/length.js b/test/built-ins/isFinite/length.js new file mode 100644 index 0000000000..136fdb19f9 --- /dev/null +++ b/test/built-ins/isFinite/length.js @@ -0,0 +1,16 @@ +// 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-isfinite-number +es6id: 18.2.2 +description: > + The length property of isFinite is 1 +includes: [propertyHelper.js] +---*/ + +assert.sameValue(isFinite.length, 1, "The value of `isFinite.length` is `1`"); + +verifyNotEnumerable(isFinite, "length"); +verifyNotWritable(isFinite, "length"); +verifyConfigurable(isFinite, "length"); diff --git a/test/built-ins/isFinite/prop-desc.js b/test/built-ins/isFinite/prop-desc.js new file mode 100644 index 0000000000..0147bcddc4 --- /dev/null +++ b/test/built-ins/isFinite/prop-desc.js @@ -0,0 +1,14 @@ +// 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-isfinite-number +es6id: 18.2.2 +description: > + Property descriptor for isFinite +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(this, "isFinite"); +verifyWritable(this, "isFinite"); +verifyConfigurable(this, "isFinite"); diff --git a/test/built-ins/isFinite/return-abrupt-from-tonumber-number-symbol.js b/test/built-ins/isFinite/return-abrupt-from-tonumber-number-symbol.js new file mode 100644 index 0000000000..1dd19b2bb1 --- /dev/null +++ b/test/built-ins/isFinite/return-abrupt-from-tonumber-number-symbol.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-isfinite-number +es6id: 18.2.2 +description: > + Throws a TypeError if number is a Symbol +info: | + isFinite (number) + + 1. Let num be ? ToNumber(number). +features: [Symbol] +---*/ + +var s = Symbol(1); + +assert.throws(TypeError, function() { + isFinite(s); +}); diff --git a/test/built-ins/isFinite/return-abrupt-from-tonumber-number.js b/test/built-ins/isFinite/return-abrupt-from-tonumber-number.js new file mode 100644 index 0000000000..afeba7d311 --- /dev/null +++ b/test/built-ins/isFinite/return-abrupt-from-tonumber-number.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-isfinite-number +es6id: 18.2.2 +description: > + Return abrupt completion from ToNumber(number) +info: | + isFinite (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() { + isFinite(obj1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + isFinite(obj2); +}, "toString"); diff --git a/test/built-ins/isFinite/return-false-on-nan-or-infinities.js b/test/built-ins/isFinite/return-false-on-nan-or-infinities.js new file mode 100644 index 0000000000..c07cf19dff --- /dev/null +++ b/test/built-ins/isFinite/return-false-on-nan-or-infinities.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-isfinite-number +es6id: 18.2.2 +description: > + Return false if number is NaN, Infinity or -Infinity +info: | + isFinite (number) + + 1. Let num be ? ToNumber(number). + 2. If num is NaN, +∞, or -∞, return false. +---*/ + +assert.sameValue(isFinite(NaN), false, "NaN"); +assert.sameValue(isFinite(Infinity), false, "Infinity"); +assert.sameValue(isFinite(-Infinity), false, "-Infinity"); diff --git a/test/built-ins/isFinite/return-true-for-valid-finite-numbers.js b/test/built-ins/isFinite/return-true-for-valid-finite-numbers.js new file mode 100644 index 0000000000..9e7eb8165c --- /dev/null +++ b/test/built-ins/isFinite/return-true-for-valid-finite-numbers.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-isfinite-number +es6id: 18.2.2 +description: > + Return true if number is not NaN, Infinity or -Infinity +info: | + isFinite (number) + + 1. Let num be ? ToNumber(number). + 2. If num is NaN, +∞, or -∞, return false. + 3. Otherwise, return true. +---*/ + +assert.sameValue(isFinite(0), true, "0"); +assert.sameValue(isFinite(-0), true, "-0"); +assert.sameValue(isFinite(Math.pow(2, 53)), true, "Math.pow(2, 53)"); +assert.sameValue(isFinite(-Math.pow(2, 53)), true, "-Math.pow(2, 53)"); +assert.sameValue(isFinite(1), true, "1"); +assert.sameValue(isFinite(-1), true, "-1"); +assert.sameValue(isFinite(0.000001), true, "0.000001"); +assert.sameValue(isFinite(-0.000001), true, "-0.000001"); +assert.sameValue(isFinite(1e42), true, "1e42"); +assert.sameValue(isFinite(-1e42), true, "-1e42"); diff --git a/test/built-ins/isFinite/tonumber-operations.js b/test/built-ins/isFinite/tonumber-operations.js new file mode 100644 index 0000000000..0048b65e7e --- /dev/null +++ b/test/built-ins/isFinite/tonumber-operations.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-isfinite-number +es6id: 18.2.2 +description: > + number argument is converted by ToNumber +info: | + isFinite (number) + + 1. Let num be ? ToNumber(number). + 2. If num is NaN, +∞, or -∞, return false. + 3. Otherwise, return true. +---*/ + +assert.sameValue(isFinite("0"), true, "'0'"); +assert.sameValue(isFinite(""), true, "the empty string"); +assert.sameValue(isFinite("Infinity"), false, "'Infinity'"); +assert.sameValue(isFinite("this is not a number"), false, "string"); +assert.sameValue(isFinite(true), true, "true"); +assert.sameValue(isFinite(false), true, "false"); +assert.sameValue(isFinite([1]), true, "Object [1]"); +assert.sameValue(isFinite([Infinity]), false, "Object [Infinity]"); +assert.sameValue(isFinite([NaN]), false, "Object [NaN]"); +assert.sameValue(isFinite(null), true, "null"); +assert.sameValue(isFinite(undefined), false, "undefined"); +assert.sameValue(isFinite(), false, "no arg"); diff --git a/test/built-ins/isFinite/toprimitive-call-abrupt.js b/test/built-ins/isFinite/toprimitive-call-abrupt.js new file mode 100644 index 0000000000..9a4242c343 --- /dev/null +++ b/test/built-ins/isFinite/toprimitive-call-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-isfinite-number +es6id: 18.2.2 +description: > + Return abrupt completion calling number.@@toPrimitive +info: | + isFinite (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() { + isFinite(obj); +}); diff --git a/test/built-ins/isFinite/toprimitive-get-abrupt.js b/test/built-ins/isFinite/toprimitive-get-abrupt.js new file mode 100644 index 0000000000..bc6d05700f --- /dev/null +++ b/test/built-ins/isFinite/toprimitive-get-abrupt.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-isfinite-number +es6id: 18.2.2 +description: > + Return abrupt completion getting number.@@toPrimitive +info: | + isFinite (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() { + isFinite(obj); +}); diff --git a/test/built-ins/isFinite/toprimitive-not-callable-throws.js b/test/built-ins/isFinite/toprimitive-not-callable-throws.js new file mode 100644 index 0000000000..8ce8703ce8 --- /dev/null +++ b/test/built-ins/isFinite/toprimitive-not-callable-throws.js @@ -0,0 +1,53 @@ +// 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-isfinite-number +es6id: 18.2.2 +description: > + Throws a TypeError if number.@@toPrimitive is not null, undefined, or callable +info: | + isFinite (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() { + isFinite(obj); +}, "number"); + +obj[Symbol.toPrimitive] = ""; +assert.throws(TypeError, function() { + isFinite(obj); +}, "string"); + +obj[Symbol.toPrimitive] = true; +assert.throws(TypeError, function() { + isFinite(obj); +}, "boolean"); + +obj[Symbol.toPrimitive] = Symbol.toPrimitive; +assert.throws(TypeError, function() { + isFinite(obj); +}, "symbol"); + +obj[Symbol.toPrimitive] = {}; +assert.throws(TypeError, function() { + isFinite(obj); +}, "object"); diff --git a/test/built-ins/isFinite/toprimitive-result-is-object-throws.js b/test/built-ins/isFinite/toprimitive-result-is-object-throws.js new file mode 100644 index 0000000000..017089d9e4 --- /dev/null +++ b/test/built-ins/isFinite/toprimitive-result-is-object-throws.js @@ -0,0 +1,32 @@ +// 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-isfinite-number +es6id: 18.2.2 +description: > + Throws a TypeError if the result of calling number.@@toPrimitive is an Object +info: | + isFinite (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() { + isFinite(obj); +}); diff --git a/test/built-ins/isFinite/toprimitive-result-is-symbol-throws.js b/test/built-ins/isFinite/toprimitive-result-is-symbol-throws.js new file mode 100644 index 0000000000..0dfa8275df --- /dev/null +++ b/test/built-ins/isFinite/toprimitive-result-is-symbol-throws.js @@ -0,0 +1,36 @@ +// 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-isfinite-number +es6id: 18.2.2 +description: > + Throws a TypeError if the result of calling number.@@toPrimitive is a symbol +info: | + isFinite (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() { + isFinite(obj); +}); diff --git a/test/built-ins/isFinite/toprimitive-valid-result.js b/test/built-ins/isFinite/toprimitive-valid-result.js new file mode 100644 index 0000000000..6af51b5701 --- /dev/null +++ b/test/built-ins/isFinite/toprimitive-valid-result.js @@ -0,0 +1,81 @@ +// 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-isfinite-number +es6id: 18.2.2 +description: > + Use non-object value returned from @@toPrimitive method +info: | + isFinite (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(isFinite(obj), true, "use returned value - number"); +assert.sameValue(called, 1, "toPrimitive is called - number"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return "42"; +}; +assert.sameValue(isFinite(obj), true, "use returned value - string"); +assert.sameValue(called, 1, "toPrimitive is called - string"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return true; +}; +assert.sameValue(isFinite(obj), true, "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(isFinite(obj), true, "use returned value - boolean false"); +assert.sameValue(called, 1, "toPrimitive is called - boolean false"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return Infinity; +}; +assert.sameValue(isFinite(obj), false, "use returned value - Infinity"); +assert.sameValue(called, 1, "toPrimitive is called - Infinity"); + +called = 0; +obj[Symbol.toPrimitive] = function() { + called += 1; + return -Infinity; +}; +assert.sameValue(isFinite(obj), false, "use returned value - -Infinity"); +assert.sameValue(called, 1, "toPrimitive is called - -Infinity");