mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 04:37:22 +00:00
LibJS: Implement the Temporal.Instant constructor
And the simple Temporal.Instant.prototype getters, so that the constructed Temporal.Instant may actually be validated.
This commit is contained in:
parent
1675f40e29
commit
90820873a2
Notes:
github-actions[bot]
2024-11-25 12:34:28 +00:00
Author: https://github.com/trflynn89
Commit: 90820873a2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2557
Reviewed-by: https://github.com/shannonbooth ✅
22 changed files with 710 additions and 14 deletions
30
Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.js
Normal file
30
Libraries/LibJS/Tests/builtins/Temporal/Instant/Instant.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
describe("errors", () => {
|
||||
test("called without new", () => {
|
||||
expect(() => {
|
||||
Temporal.Instant();
|
||||
}).toThrowWithMessage(TypeError, "Temporal.Instant constructor must be called with 'new'");
|
||||
});
|
||||
|
||||
test("argument must be coercible to bigint", () => {
|
||||
expect(() => {
|
||||
new Temporal.Instant(123);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert number to BigInt");
|
||||
expect(() => {
|
||||
new Temporal.Instant("foo");
|
||||
}).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Temporal.Instant).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const instant = new Temporal.Instant(123n);
|
||||
expect(instant.epochNanoseconds).toBe(123n);
|
||||
expect(typeof instant).toBe("object");
|
||||
expect(instant).toBeInstanceOf(Temporal.Instant);
|
||||
expect(Object.getPrototypeOf(instant)).toBe(Temporal.Instant.prototype);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue