diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Number/prototype/valueOf | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Number/prototype/valueOf')
13 files changed, 350 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T01.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T01.js new file mode 100644 index 0000000000..22f0607f0d --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T01.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Number.prototype.valueOf() returns this number value +es5id: 15.7.4.4_A1_T01 +description: Call without argument +---*/ +assert.sameValue(Number.prototype.valueOf(), 0, 'Number.prototype.valueOf() must return 0'); +assert.sameValue((new Number()).valueOf(), 0, '(new Number()).valueOf() must return 0'); +assert.sameValue((new Number(0)).valueOf(), 0, '(new Number(0)).valueOf() must return 0'); +assert.sameValue((new Number(-1)).valueOf(), -1, '(new Number(-1)).valueOf() must return -1'); +assert.sameValue((new Number(1)).valueOf(), 1, '(new Number(1)).valueOf() must return 1'); + +assert.sameValue( + new Number(NaN).valueOf(), + NaN, + 'new Number(NaN).valueOf() returns NaN' +); + +assert.sameValue( + (new Number(Number.POSITIVE_INFINITY)).valueOf(), + Number.POSITIVE_INFINITY, + '(new Number(Number.POSITIVE_INFINITY)).valueOf() returns Number.POSITIVE_INFINITY' +); + +assert.sameValue( + (new Number(Number.NEGATIVE_INFINITY)).valueOf(), + Number.NEGATIVE_INFINITY, + '(new Number(Number.NEGATIVE_INFINITY)).valueOf() returns Number.NEGATIVE_INFINITY' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T02.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T02.js new file mode 100644 index 0000000000..0b5df3987c --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A1_T02.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Number.prototype.valueOf() returns this number value +es5id: 15.7.4.4_A1_T02 +description: calling with argument +---*/ +assert.sameValue(Number.prototype.valueOf("argument"), 0, 'Number.prototype.valueOf("argument") must return 0'); +assert.sameValue((new Number()).valueOf("argument"), 0, '(new Number()).valueOf("argument") must return 0'); +assert.sameValue((new Number(0)).valueOf("argument"), 0, '(new Number(0)).valueOf("argument") must return 0'); +assert.sameValue((new Number(-1)).valueOf("argument"), -1, '(new Number(-1)).valueOf("argument") must return -1'); +assert.sameValue((new Number(1)).valueOf("argument"), 1, '(new Number(1)).valueOf("argument") must return 1'); + +assert.sameValue( + new Number(NaN).valueOf("argument"), + NaN, + 'new Number(NaN).valueOf("argument") returns NaN' +); + +assert.sameValue( + (new Number(Number.POSITIVE_INFINITY)).valueOf("argument"), + Number.POSITIVE_INFINITY, + '(new Number(Number.POSITIVE_INFINITY)).valueOf("argument") returns Number.POSITIVE_INFINITY' +); + +assert.sameValue( + (new Number(Number.NEGATIVE_INFINITY)).valueOf("argument"), + Number.NEGATIVE_INFINITY, + '(new Number(Number.NEGATIVE_INFINITY)).valueOf("argument") returns Number.NEGATIVE_INFINITY' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T01.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T01.js new file mode 100644 index 0000000000..15d7fa57b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T01.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The valueOf function is not generic, it cannot be transferred + to other kinds of objects for use as a method and there is should be + a TypeError exception if its this value is not a Number object +es5id: 15.7.4.4_A2_T01 +description: transferring to the String objects +---*/ + +try { + var s1 = new String(); + s1.valueOf = Number.prototype.valueOf; + var v1 = s1.valueOf(); + throw new Test262Error('#1: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +try { + var s2 = new String(); + s2.myValueOf = Number.prototype.valueOf; + var v2 = s2.myValueOf(); + throw new Test262Error('#2: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T02.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T02.js new file mode 100644 index 0000000000..94c443f74d --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T02.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The valueOf function is not generic, it cannot be transferred + to other kinds of objects for use as a method and there is should be + a TypeError exception if its this value is not a Number object +es5id: 15.7.4.4_A2_T02 +description: transferring to the Boolean objects +---*/ + +try { + var s1 = new Boolean(); + s1.valueOf = Number.prototype.valueOf; + var v1 = s1.valueOf(); + throw new Test262Error('#1: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +try { + var s2 = new Boolean(); + s2.myValueOf = Number.prototype.valueOf; + var v2 = s2.myValueOf(); + throw new Test262Error('#2: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T03.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T03.js new file mode 100644 index 0000000000..3363f17cd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T03.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The valueOf function is not generic, it cannot be transferred + to other kinds of objects for use as a method and there is should be + a TypeError exception if its this value is not a Number object +es5id: 15.7.4.4_A2_T03 +description: transferring to the Date objects +---*/ + +try { + var s1 = new Date(); + s1.valueOf = Number.prototype.valueOf; + var v1 = s1.valueOf(); + throw new Test262Error('#1: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +try { + var s2 = new Date(); + s2.myValueOf = Number.prototype.valueOf; + var v2 = s2.myValueOf(); + throw new Test262Error('#2: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T04.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T04.js new file mode 100644 index 0000000000..3eee5d784b --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T04.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The valueOf function is not generic, it cannot be transferred + to other kinds of objects for use as a method and there is should be + a TypeError exception if its this value is not a Number object +es5id: 15.7.4.4_A2_T04 +description: transferring to the Object objects +---*/ + +try { + var s1 = new Object(); + s1.valueOf = Number.prototype.valueOf; + var v1 = s1.valueOf(); + throw new Test262Error('#1: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +try { + var s2 = new Object(); + s2.myValueOf = Number.prototype.valueOf; + var v2 = s2.myValueOf(); + throw new Test262Error('#2: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T05.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T05.js new file mode 100644 index 0000000000..504b834cb7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/S15.7.4.4_A2_T05.js @@ -0,0 +1,37 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The valueOf function is not generic, it cannot be transferred + to other kinds of objects for use as a method and there is should be + a TypeError exception if its this value is not a Number object +es5id: 15.7.4.4_A2_T05 +description: transferring to the other objects +---*/ + +try { + var s1 = { + x: 1 + }; + s1.valueOf = Number.prototype.valueOf; + var v1 = s1.valueOf(); + throw new Test262Error('#1: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +try { + var s2 = { + x: 1 + }; + s2.myValueOf = Number.prototype.valueOf; + var v2 = s2.myValueOf(); + throw new Test262Error('#2: Number.prototype.valueOf on not a Number object should throw TypeError'); +} +catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/browser.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/browser.js diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/length.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/length.js new file mode 100644 index 0000000000..65a31127ff --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 20.1.3.7 +description: > + Number.prototype.valueOf.length is 0. +info: | + Number.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] +---*/ + +assert.sameValue(Number.prototype.valueOf.length, 0); + +verifyNotEnumerable(Number.prototype.valueOf, "length"); +verifyNotWritable(Number.prototype.valueOf, "length"); +verifyConfigurable(Number.prototype.valueOf, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/name.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/name.js new file mode 100644 index 0000000000..8c1830f5fd --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/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. + +/*--- +es6id: 20.1.3.7 +description: > + Number.prototype.valueOf.name is "valueOf". +info: | + Number.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] +---*/ + +assert.sameValue(Number.prototype.valueOf.name, "valueOf"); + +verifyNotEnumerable(Number.prototype.valueOf, "name"); +verifyNotWritable(Number.prototype.valueOf, "name"); +verifyConfigurable(Number.prototype.valueOf, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/not-a-constructor.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/not-a-constructor.js new file mode 100644 index 0000000000..5037924ce3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/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: > + Number.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, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Number.prototype.valueOf), + false, + 'isConstructor(Number.prototype.valueOf) must return false' +); + +assert.throws(TypeError, () => { + new Number.prototype.valueOf(); +}, '`new Number.prototype.valueOf()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/prop-desc.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/prop-desc.js new file mode 100644 index 0000000000..9b7bcbe491 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/prop-desc.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-number.prototype.valueof +description: > + "valueOf" property of Number.prototype +info: | + 17 ECMAScript Standard Built-in Objects: + + 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] +---*/ + +verifyNotEnumerable(Number.prototype, "valueOf"); +verifyWritable(Number.prototype, "valueOf"); +verifyConfigurable(Number.prototype, "valueOf"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Number/prototype/valueOf/shell.js b/js/src/tests/test262/built-ins/Number/prototype/valueOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Number/prototype/valueOf/shell.js |