mirror of https://github.com/tc39/test262.git
Add test coverage for Date.prototype.toTemporalInstant
This commit is contained in:
parent
437f9a7631
commit
26a396da14
|
@ -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,
|
||||
});
|
|
@ -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
|
||||
});
|
|
@ -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();
|
||||
});
|
||||
|
|
@ -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,
|
||||
});
|
|
@ -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();
|
||||
});
|
|
@ -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");
|
|
@ -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");
|
|
@ -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"
|
||||
);
|
Loading…
Reference in New Issue