Commit graph

666 commits

Author SHA1 Message Date
Timothy Flynn
0befd52725 LibJS: Begin implementing the relativeTo option of Duration.compare 2024-11-23 14:46:00 +01:00
Timothy Flynn
06593b1894 LibJS: Implement most of GetTemporalRelativeToOption
Now that we have the Temporal.PlainDate object, we can flesh out this AO
for such relative-to objects.
2024-11-23 14:46:00 +01:00
Timothy Flynn
521638642f LibJS: Capture CalendarFields by reference in Calendar*FromFields AOs
These fields are modified by an invocation to CalendarResolveFields. All
callers currently don't care about these modifications, so they move the
CalendarFields struct into the AO. But it turns out that at least one AO
will care (InterpretTemporalDateTimeFields), thus we will need to take
by reference here.
2024-11-23 14:46:00 +01:00
Timothy Flynn
021a5f4ded LibJS: Move ISO-related structures to their own file
Currently, AbstractOperations.h needs to include Time.h for the Time
structure. Soon, Time.h will need to include AbstractOperations.h for
structures defined there. To avoid a circular include, let's put the
ISO types into their own file, so that AO.h does not need to include
any JS type header.
2024-11-23 14:46:00 +01:00
Timothy Flynn
46998e922a LibJS: Implement Temporal.PlainMonthDay/YearMonth.prototype.toPlainDate 2024-11-23 14:46:00 +01:00
Timothy Flynn
06ef32818e LibJS: Implement Temporal.PlainDate.prototype.valueOf 2024-11-23 14:46:00 +01:00
Timothy Flynn
f8b593a7df LibJS: Implement Temporal.PlainDate.prototype.toPlainMonthDay/YearMonth 2024-11-23 14:46:00 +01:00
Timothy Flynn
3aa4cdd314 LibJS: Implement Temporal.PlainDate.prototype.until/since 2024-11-23 14:46:00 +01:00
Timothy Flynn
abc6b679c3 LibJS: Check both the quotient and remainder for rounding negativity
Our BigInt implementation can store the negativity of the division
result in either the quotient or the remainder. This is exposed by an
upcoming prototype, which will reach this division with:

    -432000000000000 / 86400000000000000000000

Which has the BigInt division result:

    quotient = 0
    remainder = -432000000000000

(Our old Temporal implementation also had this bug).
2024-11-23 14:46:00 +01:00
Timothy Flynn
b319d45566 LibJS: Optimize the CalendarDateUntil AO for large year differences
For example, consider the following operation:

    const instance = new Temporal.PlainDate(2000, 5, 2);
    instance.until("-271821-04-19");

The spec would have us enter a loop to compute the difference between
these dates by incrementing an intermediate date one day at a time.
Instead, we can do some math to skip ahead much closer to the desired
date.
2024-11-23 14:46:00 +01:00
Timothy Flynn
f280a96e35 LibJS: Implement Temporal.PlainDate.prototype.with/withCalendar 2024-11-23 14:46:00 +01:00
Timothy Flynn
c2ead84bd9 LibJS: Implement Temporal.PlainDate.prototype.add/subtract/equals 2024-11-23 14:46:00 +01:00
Timothy Flynn
9fbb5a57fa LibJS: Implement stringification Temporal.PlainDate prototypes 2024-11-23 14:46:00 +01:00
Timothy Flynn
a0c55f76e7 LibJS: Implement the Temporal.PlainDate constructor
And the simple Temporal.PlainDate.prototype getters, so that the
constructed Temporal.PlainDate may actually be validated.
2024-11-23 14:46:00 +01:00
Timothy Flynn
b64ccb95ec LibJS: Implement Temporal.PlainYearMonth.prototype.valueOf 2024-11-22 19:55:24 +01:00
Timothy Flynn
35f22dcf79 LibJS: Implement Temporal.PlainYearMonth.prototype.add/subtract 2024-11-22 19:55:24 +01:00
Timothy Flynn
cb5d1b5086 LibJS: Implement Temporal.PlainYearMonth.prototype.until/since 2024-11-22 19:55:24 +01:00
Timothy Flynn
203269fae2 LibJS: Implement Temporal.PlainYearMonth.prototype.with/equals 2024-11-22 19:55:24 +01:00
Timothy Flynn
2da526423f LibJS: Implement stringification Temporal.PlainYearMonth prototypes 2024-11-22 19:55:24 +01:00
Timothy Flynn
b68d67693e LibJS: Implement the Temporal.PlainYearMonth constructor
And the simple Temporal.PlainYearMonth.prototype getters, so that the
constructed Temporal.PlainYearMonth may actually be validated.
2024-11-22 19:55:24 +01:00
Timothy Flynn
c6fccc04e1 LibJS: Use Temporal's ISO8601 parser to parse UTC offset strings
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
We now have the Temporal facilities to implement the Date AOs which
parse UTC offset strings using the ISO8601 parser. This patch updates
those AOs and their callers in accordance with the Temporal spec.
2024-11-21 19:24:25 -05:00
Timothy Flynn
64811ab7b6 LibJS: Implement Temporal.PlainMonthDay.prototype.valueOf 2024-11-21 19:24:25 -05:00
Timothy Flynn
5389acc231 LibJS: Implement Temporal.PlainMonthDay.prototype.with/equals 2024-11-21 19:24:25 -05:00
Timothy Flynn
5bccb36a6f LibJS: Implement stringification Temporal.PlainMonthDay prototypes 2024-11-21 19:24:25 -05:00
Timothy Flynn
1a386e78c3 LibJS: Implement the Temporal.PlainMonthDay constructor
And the simple Temporal.PlainMonthDay.prototype getters, so that the
constructed Temporal.PlainMonthDay may actually be validated.
2024-11-21 19:24:25 -05:00
Timothy Flynn
b3b968bed9 LibJS: Implement several more ISO8601 productions
This started with implementing TemporalMonthDayString. It turns out that
the facilities needed to parse that production includes nearly all the
helpers to parse each of:

    TemporalDateTimeString
    TemporalInstantString
    TemporalMonthDayString
    TemporalTimeString
    TemporalYearMonthString
    TemporalZonedDateTimeString

As most of these invoke the same helpers with different options. So,
all 6 of those productions are implemented here.
2024-11-21 19:24:25 -05:00
Timothy Flynn
f57ff63432 LibJS: Implement Temporal.Duration.prototype.valueOf 2024-11-20 19:04:30 -05:00
Timothy Flynn
c715711f88 LibJS: Implement Temporal.Duration.prototype.total
Until we have re-implemented Temporal.PlainDate/ZonedDateTime, some of
Temporal.Duration.prototype.total (and its invoked AOs) are left
unimplemented.
2024-11-20 19:04:30 -05:00
Timothy Flynn
5689621c2b LibJS: Implement Temporal.Duration.prototype.round
Until we have re-implemented Temporal.PlainDate/ZonedDateTime, some of
Temporal.Duration.prototype.round (and its invoked AOs) are left
unimplemented.
2024-11-20 19:04:30 -05:00
Timothy Flynn
4742775262 LibJS: Implement stringification Temporal.Duration prototypes 2024-11-20 19:04:30 -05:00
Timothy Flynn
a80523be18 LibJS: Implement mathematical Temporal.Duration prototypes
Includes:
Temporal.Duration.prototype.negated
Temporal.Duration.prototype.abs
Temporal.Duration.prototype.add
Temporal.Duration.prototype.subtract
2024-11-20 19:04:30 -05:00
Timothy Flynn
55c81482b0 LibJS: Implement Temporal.Duration.prototype.with 2024-11-20 19:04:30 -05:00
Timothy Flynn
dfaa3bf649 LibJS: Implement Temporal.Duration.prototype.sign/blank 2024-11-20 19:04:30 -05:00
Timothy Flynn
5fe0d3352d LibJS: Implement the Temporal.Duration constructor
This also includes a stubbed Temporal.Duration.prototype.

Until we have re-implemented Temporal.PlainDate/ZonedDateTime, some of
Temporal.Duration.compare (and its invoked AOs) are left unimplemented.
2024-11-20 19:04:30 -05:00
Timothy Flynn
eca378a7a3 LibJS: Restore some Temporal numeric constants
And add few ad-hoc constants for convenience.
2024-11-20 19:04:30 -05:00
Timothy Flynn
e4e05837e1 LibJS: Return a GC::Ref from Temporal::get_options_object
The Object returned here is always non-null.
2024-11-20 19:04:30 -05:00
Timothy Flynn
c8d2404230 LibJS: Update spec steps for the few remaining Temporal AOs 2024-11-20 19:04:30 -05:00
Timothy Flynn
d368fcadac LibJS: Update spec link for Temporal [ %Symbol.toStringTag% ] 2024-11-20 19:04:30 -05:00
Timothy Flynn
f7517c5b8d LibJS: Remove our existing Temporal implementation
Our Temporal implementation is woefully out of date. The spec has been
so vastly rewritten that it is unfortunately not practical to update our
implementation in-place. Even just removing Temporal objects that were
removed from the spec, or updating any of the simpler remaining objects,
has proven to be a mess in previous attempts.

So, this removes our Temporal implementation. AOs used by other specs
are left intact.
2024-11-20 19:04:30 -05:00
rmg-x
74b27d620d LibJS: Parse dates like "Wed Nov 20 2024" 2024-11-20 09:20:48 +00:00
Timothy Flynn
dd6acfecd4 LibJS: Don't use Temporal to parse UTC offset strings
The production for these strings has been removed from Temporal. This
implements a separate parser in accordance with the Date spec.
2024-11-18 17:46:41 -05:00
Timothy Flynn
f88826691c LibJS: Remove usage of obsolete Duration record from Intl.DurationFormat
The Duration record no longer exists in Temporal. Implement it according
to the DurationFormat spec to prepare for its removal from our Temporal
implementation.

We also implement the DurationSign AO here as well, as the Temporal
implementation will now require a Temporal.Duration JS object.
2024-11-18 17:46:41 -05:00
Timothy Flynn
59e0b7ccb7 LibJS: Remove unused Temporal inclusion from Intl 2024-11-18 17:46:41 -05:00
Shannon Booth
fd0c63b338 LibJS: Align spec comments for ShadowRealm for HostInitializeShadowRealm
The proposed changes have been merged into the proposal with:

https://github.com/tc39/proposal-shadowrealm/commit/f20d02
2024-11-17 22:15:22 +01:00
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Shannon Booth
c2988a7dd5 LibJS: Don't directly teach the heap about the javascript VM or Realm
Instead, smuggle it in as a `void*` private data and let Javascript
aware code cast out that pointer to a VM&.

In order to make this split, rename JS::Cell to JS::CellImpl. Once we
have a LibGC, this will become GC::Cell. CellImpl then has no specific
knowledge of the VM& and Realm&. That knowledge is instead put into
JS::Cell, which inherits from CellImpl. JS::Cell is responsible for
JavaScript's realm initialization, as well as converting of the void*
private data to what it knows should be the VM&.
2024-11-14 15:38:45 +01:00
Shannon Booth
ae6d105f41 LibJS: Use a Function to indirectly let Heap visit VM's GC roots
This allows the heap to mark cells that it needs to mark as roots
without needing to directly reference the VM.
2024-11-14 15:38:45 +01:00
Shannon Booth
0bf2a8362a LibJS: Make Value inherit from a NanBoxedValue
NanBoxedValue is intended to be a GC-allocatable type which is not
specific to javascript, towards the effort of factoring out the GC
implementation from LibJS.
2024-11-14 15:38:45 +01:00
Shannon Booth
1e54003cb1 LibJS+LibWeb: Rename Heap::allocate_without_realm to Heap::allocate
Now that the heap has no knowledge about a JavaScript realm and is
purely for managing the memory of the heap, it does not make sense
to name this function to say that it is a non-realm variant.
2024-11-13 16:51:44 -05:00
Shannon Booth
9b79a686eb LibJS+LibWeb: Use realm.create<T> instead of heap.allocate<T>
The main motivation behind this is to remove JS specifics of the Realm
from the implementation of the Heap.

As a side effect of this change, this is a bit nicer to read than the
previous approach, and in my opinion, also makes it a little more clear
that this method is specific to a JavaScript Realm.
2024-11-13 16:51:44 -05:00