From 42634c8788b83fcbd8a3cefffaca2fdf58ae0e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 5 Nov 2024 14:23:29 +0100 Subject: [PATCH] Add test coverage for Date.prototype.toTemporalInstant --- .../prototype/toTemporalInstant/length.js | 30 ++++++++++++ .../Date/prototype/toTemporalInstant/name.js | 28 +++++++++++ .../toTemporalInstant/not-a-constructor.js | 29 +++++++++++ .../prototype/toTemporalInstant/prop-desc.js | 23 +++++++++ .../this-value-invalid-date.js | 22 +++++++++ .../toTemporalInstant/this-value-non-date.js | 43 +++++++++++++++++ .../this-value-non-object.js | 48 +++++++++++++++++++ .../this-value-valid-date.js | 46 ++++++++++++++++++ 8 files changed, 269 insertions(+) create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/length.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/name.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/not-a-constructor.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/prop-desc.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/this-value-invalid-date.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/this-value-non-date.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/this-value-non-object.js create mode 100644 test/built-ins/Date/prototype/toTemporalInstant/this-value-valid-date.js diff --git a/test/built-ins/Date/prototype/toTemporalInstant/length.js b/test/built-ins/Date/prototype/toTemporalInstant/length.js new file mode 100644 index 00000000000..27afed87430 --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Date.prototype.toTemporalInstant.length is 0. +info: | + Date.prototype.toTemporalInstant ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in function object, including constructors, has a "length" + property whose value is a non-negative integral Number. Unless otherwise + specified, this value is the number of required parameters shown in the + subclause heading for the function description. Optional parameters and rest + parameters are not included in the parameter 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] +features: [Temporal] +---*/ + +verifyProperty(Date.prototype.toTemporalInstant, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/Date/prototype/toTemporalInstant/name.js b/test/built-ins/Date/prototype/toTemporalInstant/name.js new file mode 100644 index 00000000000..7ac9c2ef60d --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Date.prototype.toTemporalInstant.name is "toTemporalInstant". +info: | + Date.prototype.toTemporalInstant ( ) + + 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] +features: [Temporal] +---*/ + +verifyProperty(Date.prototype.toTemporalInstant, "name", { + value: "toTemporalInstant", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/Date/prototype/toTemporalInstant/not-a-constructor.js b/test/built-ins/Date/prototype/toTemporalInstant/not-a-constructor.js new file mode 100644 index 00000000000..3a52a5f2bb0 --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/not-a-constructor.js @@ -0,0 +1,29 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Date.prototype.toTemporalInstant does not implement [[Construct]] +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. +includes: [isConstructor.js] +features: [Temporal, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(Date.prototype.toTemporalInstant), + false, + 'isConstructor(Date.prototype.toTemporalInstant) must return false' +); + +var date = new Date(0); + +assert.throws(TypeError, function() { + new date.toTemporalInstant(); +}); + diff --git a/test/built-ins/Date/prototype/toTemporalInstant/prop-desc.js b/test/built-ins/Date/prototype/toTemporalInstant/prop-desc.js new file mode 100644 index 00000000000..cde795274c3 --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/prop-desc.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Property descriptor for Date.prototype.toTemporalInstant. +info: | + Date.prototype.toTemporalInstant ( ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 19 through 28 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Temporal] +---*/ + +verifyProperty(Date.prototype, "toTemporalInstant", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/Date/prototype/toTemporalInstant/this-value-invalid-date.js b/test/built-ins/Date/prototype/toTemporalInstant/this-value-invalid-date.js new file mode 100644 index 00000000000..fe930c14c4e --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/this-value-invalid-date.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Throws RangeError for invalid dates. +info: | + Date.prototype.toTemporalInstant ( ) + + ... + 3. Let t be dateObject.[[DateValue]]. + 4. Let ns be ? NumberToBigInt(t) × ℤ(10**6). + ... +features: [Temporal] +---*/ + +var date = new Date(NaN); + +assert.throws(RangeError, function() { + date.toTemporalInstant(); +}); diff --git a/test/built-ins/Date/prototype/toTemporalInstant/this-value-non-date.js b/test/built-ins/Date/prototype/toTemporalInstant/this-value-non-date.js new file mode 100644 index 00000000000..80270b44761 --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/this-value-non-date.js @@ -0,0 +1,43 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Behaviour when "this" value is an Object without a [[DateValue]] internal slot +info: | + Date.prototype.toTemporalInstant ( ) + + 1. Let dateObject be the this value. + 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]). + ... +features: [Temporal] +---*/ + +var toTemporalInstant = Date.prototype.toTemporalInstant; + +var args = (function() { + return arguments; +}()); + +assert.sameValue(typeof toTemporalInstant, "function"); + +assert.throws(TypeError, function() { + toTemporalInstant.call({}); +}, "ordinary object"); + +assert.throws(TypeError, function() { + toTemporalInstant.call([]); +}, "array exotic object"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(args); +}, "arguments exotic object"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(function(){}); +}, "function object"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(Date.prototype); +}, "Date.prototype"); diff --git a/test/built-ins/Date/prototype/toTemporalInstant/this-value-non-object.js b/test/built-ins/Date/prototype/toTemporalInstant/this-value-non-object.js new file mode 100644 index 00000000000..816dd2e7015 --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/this-value-non-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Behaviour when "this" value is not an Object +info: | + Date.prototype.toTemporalInstant ( ) + + 1. Let dateObject be the this value. + 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]). + ... +features: [Temporal, Symbol, BigInt] +---*/ + +var toTemporalInstant = Date.prototype.toTemporalInstant; +var symbol = Symbol(); + +assert.sameValue(typeof toTemporalInstant, "function"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(0); +}, "number"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(true); +}, "boolean"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(null); +}, "null"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(""); +}, "string"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(symbol); +}, "symbol"); + +assert.throws(TypeError, function() { + toTemporalInstant.call(0n); +}, "bigint"); diff --git a/test/built-ins/Date/prototype/toTemporalInstant/this-value-valid-date.js b/test/built-ins/Date/prototype/toTemporalInstant/this-value-valid-date.js new file mode 100644 index 00000000000..f7b0167a5b0 --- /dev/null +++ b/test/built-ins/Date/prototype/toTemporalInstant/this-value-valid-date.js @@ -0,0 +1,46 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-date.prototype.totemporalinstant +description: > + Return value for valid dates. +info: | + Date.prototype.toTemporalInstant ( ) + + ... + 3. Let t be dateObject.[[DateValue]]. + 4. Let ns be ? NumberToBigInt(t) × ℤ(10**6). + 5. Return ! CreateTemporalInstant(ns). +features: [Temporal, BigInt] +---*/ + +assert.sameValue( + new Date(0).toTemporalInstant().epochNanoseconds, + 0n, + "the (Unix) epoch" +); + +assert.sameValue( + new Date(123_456_789).toTemporalInstant().epochNanoseconds, + 123_456_789_000_000n, + "date after the (Unix) epoch" +); + +assert.sameValue( + new Date(-123_456_789).toTemporalInstant().epochNanoseconds, + -123_456_789_000_000n, + "date before the (Unix) epoch" +); + +assert.sameValue( + new Date(-8.64e15).toTemporalInstant().epochNanoseconds, + -8640_000_000_000_000_000_000n, + "start of time" +); + +assert.sameValue( + new Date(8.64e15).toTemporalInstant().epochNanoseconds, + 8640_000_000_000_000_000_000n, + "end of time" +);