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/Date/prototype/toJSON | |
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 '')
15 files changed, 477 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/browser.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/browser.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/builtin.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/builtin.js new file mode 100644 index 0000000000..cccb5c7e2e --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/builtin.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + Tests that Date.prototype.toJSON meets the requirements + for built-in objects defined by the introduction of chapter 17 of + the ECMAScript Language Specification. +features: [Reflect.construct] +---*/ + +assert(Object.isExtensible(Date.prototype.toJSON), 'Object.isExtensible(Date.prototype.toJSON) must return true'); +assert.sameValue(typeof Date.prototype.toJSON, 'function', 'The value of `typeof Date.prototype.toJSON` is "function"'); +assert.sameValue( + Object.prototype.toString.call(Date.prototype.toJSON), + '[object Function]', + 'Object.prototype.toString.call(Date.prototype.toJSON) must return "[object Function]"' +); +assert.sameValue( + Object.getPrototypeOf(Date.prototype.toJSON), + Function.prototype, + 'Object.getPrototypeOf(Date.prototype.toJSON) must return the value of Function.prototype' +); +assert.sameValue(Date.prototype.toJSON.hasOwnProperty('prototype'), false, 'Date.prototype.toJSON.hasOwnProperty("prototype") must return false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/called-as-function.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/called-as-function.js new file mode 100644 index 0000000000..06e9775c6c --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/called-as-function.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.tojson +description: > + `this` value is resolved using strict mode semantics, + throwing TypeError if called as top-level function. +info: | + Date.prototype.toJSON ( key ) + + 1. Let O be ? ToObject(this value). + + ToObject ( argument ) + + Argument Type: Undefined + Result: Throw a TypeError exception. +features: [Symbol, Symbol.toPrimitive] +---*/ + +[Symbol.toPrimitive, "toString", "valueOf", "toISOString"].forEach(function(key) { + Object.defineProperty(this, key, { + get: function() { + throw new Test262Error(String(key) + " lookup should not be performed"); + }, + }); +}, this); + +var toJSON = Date.prototype.toJSON; +assert.throws(TypeError, function() { + toJSON(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-abrupt.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-abrupt.js new file mode 100644 index 0000000000..0fba650fa8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-abrupt.js @@ -0,0 +1,40 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + Abrupt completion from GetV or Call. +info: | + Date.prototype.toJSON ( key ) + + [...] + 4. Return ? Invoke(O, "toISOString"). + + Invoke ( V, P [ , argumentsList ] ) + + [...] + 3. Let func be ? GetV(V, P). + 4. Return ? Call(func, V, argumentsList). +---*/ + +var abruptGet = { + get toISOString() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + Date.prototype.toJSON.call(abruptGet); +}); + +var abruptCall = { + toISOString() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + Date.prototype.toJSON.call(abruptCall); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-arguments.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-arguments.js new file mode 100644 index 0000000000..59638976cc --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-arguments.js @@ -0,0 +1,44 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + toISOString is called with correct context and without arguments. +info: | + Date.prototype.toJSON ( key ) + + [...] + 4. Return ? Invoke(O, "toISOString"). + + Invoke ( V, P [ , argumentsList ] ) + + [...] + 3. Let func be ? GetV(V, P). + 4. Return ? Call(func, V, argumentsList). +---*/ + +var getCount = 0, getContext; +var callCount = 0, callContext, callArguments; +var obj = { + get toISOString() { + getCount += 1; + getContext = this; + + return function() { + callCount += 1; + callContext = this; + callArguments = arguments; + }; + }, +}; + +Date.prototype.toJSON.call(obj); + +assert.sameValue(getCount, 1); +assert.sameValue(getContext, obj); + +assert.sameValue(callCount, 1); +assert.sameValue(callContext, obj); +assert.sameValue(callArguments.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-result.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-result.js new file mode 100644 index 0000000000..2f98510e64 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/invoke-result.js @@ -0,0 +1,31 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + Result of toISOString call is returned. +info: | + Date.prototype.toJSON ( key ) + + [...] + 4. Return ? Invoke(O, "toISOString"). + + Invoke ( V, P [ , argumentsList ] ) + + [...] + 3. Let func be ? GetV(V, P). + 4. Return ? Call(func, V, argumentsList). +---*/ + +var date = new Date(); +assert.sameValue(date.toJSON(), date.toISOString()); + +var result = {}; +assert.sameValue( + Date.prototype.toJSON.call({ + toISOString: function() { return result; }, + }), + result +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/length.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/length.js new file mode 100644 index 0000000000..a4186d87dc --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/length.js @@ -0,0 +1,25 @@ +// Copyright (C) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + Date.prototype.toJSON.length is 1. +info: | + Date.prototype.toJSON ( key ) + + ECMAScript Standard Built-in Objects + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(Date.prototype.toJSON, 'length', { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/name.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/name.js new file mode 100644 index 0000000000..ca4abc27f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/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. + +/*--- +esid: sec-date.prototype.tojson +description: > + Date.prototype.toJSON.name is "toJSON". +info: | + Date.prototype.toJSON ( key ) + + 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] +---*/ + +verifyProperty(Date.prototype.toJSON, 'name', { + value: 'toJSON', + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/non-finite.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/non-finite.js new file mode 100644 index 0000000000..f3f6753a04 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/non-finite.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + If this value coerces to non-finite number, null is returned. +info: | + Date.prototype.toJSON ( key ) + + [...] + 2. Let tv be ? ToPrimitive(O, hint Number). + 3. If Type(tv) is Number and tv is not finite, return null. +---*/ + +var toJSON = Date.prototype.toJSON; + +assert.sameValue( + toJSON.call({ + get toISOString() { throw new Test262Error(); }, + valueOf: function() { return NaN; }, + }), + null +); + +var num = new Number(-Infinity); +num.toISOString = function() { throw new Test262Error(); }; +assert.sameValue(toJSON.call(num), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/not-a-constructor.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/not-a-constructor.js new file mode 100644 index 0000000000..df5faff002 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/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: > + Date.prototype.toJSON 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(Date.prototype.toJSON), + false, + 'isConstructor(Date.prototype.toJSON) must return false' +); + +assert.throws(TypeError, () => { + let date = new Date(Date.now()); new date.toJSON(); +}, '`let date = new Date(Date.now()); new date.toJSON()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/shell.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/shell.js diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-object.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-object.js new file mode 100644 index 0000000000..579cc102a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-object.js @@ -0,0 +1,31 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + This value is coerced to an object. +info: | + Date.prototype.toJSON ( key ) + + 1. Let O be ? ToObject(this value). +features: [Symbol] +---*/ + +var toJSON = Date.prototype.toJSON; +this.toISOString = function() { return 'global'; }; + +assert.throws(TypeError, function() { + toJSON.call(undefined); +}); + +assert.throws(TypeError, function() { + toJSON.call(null); +}); + +Number.prototype.toISOString = function() { return 'str'; }; +assert.sameValue(toJSON.call(10), 'str'); + +Symbol.prototype.toISOString = function() { return 10; }; +assert.sameValue(toJSON.call(Symbol()), 10); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-abrupt.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-abrupt.js new file mode 100644 index 0000000000..767d8b8240 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-abrupt.js @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + Abrupt completion from ToPrimitive. +info: | + Date.prototype.toJSON ( key ) + + [...] + 2. Let tv be ? ToPrimitive(O, hint Number). + + ToPrimitive ( input [ , PreferredType ] ) + + 1. Assert: input is an ECMAScript language value. + 2. If Type(input) is Object, then + [...] + g. Return ? OrdinaryToPrimitive(input, hint). + + OrdinaryToPrimitive ( O, hint ) + + [...] + 5. For each name in methodNames in List order, do + a. Let method be ? Get(O, name). + b. If IsCallable(method) is true, then + i. Let result be ? Call(method, O). + ii. If Type(result) is not Object, return result. + 6. Throw a TypeError exception. +---*/ + +var toJSON = Date.prototype.toJSON; +var getAbrupt = { + get valueOf() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + toJSON.call(getAbrupt); +}); + +var callAbrupt = { + toString: function() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + toJSON.call(callAbrupt); +}); + +var notCoercible = Object.create(null); + +assert.throws(TypeError, function() { + toJSON.call(notCoercible); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-symbol.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-symbol.js new file mode 100644 index 0000000000..7cf18d9060 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-symbol.js @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + This value is coerced to primitive with Number hint (exotic @@toPrimitive). +info: | + Date.prototype.toJSON ( key ) + + [...] + 2. Let tv be ? ToPrimitive(O, hint Number). + + ToPrimitive ( input [ , PreferredType ] ) + + 1. Assert: input is an ECMAScript language value. + 2. If Type(input) is Object, then + [...] + d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + e. If exoticToPrim is not undefined, then + i. Let result be ? Call(exoticToPrim, input, « hint »). + ii. If Type(result) is not Object, return result. +features: [Symbol, Symbol.toPrimitive] +---*/ + +var callCount = 0, _this, _arguments; +var result = new Boolean(false); + +var obj = { + toISOString: function() { return result; }, + toString: function() { throw new Test262Error('should not be called'); }, + valueOf: function() { throw new Test262Error('should not be called'); }, +}; + +obj[Symbol.toPrimitive] = function() { + callCount += 1; + _this = this; + _arguments = arguments; + return 3.14; +}; + +assert.sameValue(Date.prototype.toJSON.call(obj), result); +assert.sameValue(callCount, 1); +assert.sameValue(_this, obj); +assert.sameValue(_arguments[0], 'number'); +assert.sameValue(_arguments.length, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-value-of.js b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-value-of.js new file mode 100644 index 0000000000..f8cf0c5f19 --- /dev/null +++ b/js/src/tests/test262/built-ins/Date/prototype/toJSON/to-primitive-value-of.js @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-date.prototype.tojson +description: > + This value is coerced to primitive with Number hint (OrdinaryToPrimitive). +info: | + Date.prototype.toJSON ( key ) + + [...] + 2. Let tv be ? ToPrimitive(O, hint Number). + + ToPrimitive ( input [ , PreferredType ] ) + + 1. Assert: input is an ECMAScript language value. + 2. If Type(input) is Object, then + [...] + g. Return ? OrdinaryToPrimitive(input, hint). + + OrdinaryToPrimitive ( O, hint ) + + [...] + 5. For each name in methodNames in List order, do + a. Let method be ? Get(O, name). + b. If IsCallable(method) is true, then + i. Let result be ? Call(method, O). + ii. If Type(result) is not Object, return result. +---*/ + +var callCount = 0, _this, _arguments; +var result = []; +var obj = { + toISOString: function() { return result; }, + toString: function() { throw new Test262Error('should not be called'); }, + valueOf: function() { + callCount += 1; + _this = this; + _arguments = arguments; + return 'NaN'; + }, +}; + +assert.sameValue(Date.prototype.toJSON.call(obj), result); +assert.sameValue(callCount, 1); +assert.sameValue(_this, obj); +assert.sameValue(_arguments.length, 0); + +reportCompare(0, 0); |