1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 22:14:58 +00:00
Commit graph

3776 commits

Author SHA1 Message Date
Timothy Flynn
4bdcf9a4b7 LibJS: Revert the free stack limit back to 32 KiB 2024-02-20 16:24:09 -05:00
Timothy Flynn
3ac4b02604 LibJS: Further increase the free stack limit to 256 KiB
128 KiB seems to not be enough for CI.
2024-02-20 12:29:27 -05:00
Shannon Booth
0b457f90e0 LibJS: Fix copy paste errors in Temporal's Calendar Methods Record
This adapts our implementation to the editorial change in the temporal
proposal: 737baf2d

The changes to CalendarMethodsRecordLookup had already been implemented,
but we had followed the typo in the spec for CalendarMethodsRecordCall.
The issue in CalendarMethodsRecordCall hasn't surfaced yet, as the AOs
using Calendar Methods Record are currently not passing through a String
to represent a Calendar builtin.

No change to test-262.
2024-02-20 06:54:32 -05:00
Andreas Kling
fb4c632309 LibJS: Throw "call stack size exceeded" exception a bit earlier
This number is pure guesswork but it appears to fix GCC builds with
both ASAN and UBSAN hitting a native stack overflow before we have
a chance to catch it on our Azure CI.
2024-02-20 10:54:52 +01:00
Andreas Kling
e46b217e42 LibJS/Bytecode: Move to a new bytecode format
This patch moves us away from the accumulator-based bytecode format to
one with explicit source and destination registers.

The new format has multiple benefits:

- ~25% faster on the Kraken and Octane benchmarks :^)
- Fewer instructions to accomplish the same thing
- Much easier for humans to read(!)

Because this change requires a fundamental shift in how bytecode is
generated, it is quite comprehensive.

Main implementation mechanism: generate_bytecode() virtual function now
takes an optional "preferred dst" operand, which allows callers to
communicate when they have an operand that would be optimal for the
result to go into. It also returns an optional "actual dst" operand,
which is where the completion value (if any) of the AST node is stored
after the node has "executed".

One thing of note that's new: because instructions can now take locals
as operands, this means we got rid of the GetLocal instruction.
A side-effect of that is we have to think about the temporal deadzone
(TDZ) a bit differently for locals (GetLocal would previously check
for empty values and interpret that as a TDZ access and throw).
We now insert special ThrowIfTDZ instructions in places where a local
access may be in the TDZ, to maintain the correct behavior.

There are a number of progressions and regressions from this test:

A number of async generator tests have been accidentally fixed while
converting the implementation to the new bytecode format. It didn't
seem useful to preserve bugs in the original code when converting it.

Some "does eval() return the correct completion value" tests have
regressed, in particular ones related to propagating the appropriate
completion after control flow statements like continue and break.
These are all fairly obscure issues, and I believe we can continue
working on them separately.

The net test262 result is a progression though. :^)
2024-02-19 21:45:27 +01:00
Andreas Kling
1d29f9081f LibJS: Remove JIT compiler
The JIT compiler was an interesting experiment, but ultimately the
security & complexity cost of doing arbitrary code generation at runtime
is far too high.

In subsequent commits, the bytecode format will change drastically, and
instead of rewriting the JIT to fit the new bytecode, this patch simply
removes the JIT instead.

Other engines, JavaScriptCore in particular, have already proven that
it's possible to handle the vast majority of contemporary web content
with an interpreter. They are currently ~5x faster than us on benchmarks
when running without a JIT. We need to catch up to them before
considering performance techniques with a heavy security cost.
2024-02-19 21:45:27 +01:00
Shannon Booth
4348b484c6 LibJS: Verify valid Duraton is made in DifferenceTemporalPlainDate
It shouldn't be possible to create an invalid duration here, so follow
the spec and verify that this succeeds.
2024-02-16 12:27:23 -05:00
Shannon Booth
bb8dad5bb0 LibJS: Begin using CalendarMethodsRecord for AOs
This begins the process of aligning our implementation with the spec
with regard to using CalendarMethodsRecord. The main intent here is to
make it much easier to make normative changes to AOs which have been
updated to CalendarMethodsRecord.

While this does resolve various FIXMEs, many others above need to be
added in order to be able to pass through a CalendarMethodsRecord. The
use here aligns with what I can gather from the spec of what the
arguments to CreateCalendarMethodsRecord should be, but various AOs have
been updated so much with other changes it's not completely obvious.
Other AOs do not even exist in the latest version of the spec, but we
still rely on them.

As part of these updates, this commit coincidentally also fixes two
PlainDate roundingmode issues seen in test262 - a test of which is also
added in test-js. This issue boiled down to what appears to be an
observable optimization in the spec, where it can avoid calling
dateUntil in certain situations (roundingGranularityIsNoop).

However, the main goal here is to make it much easier to fix many more
issues in the future :^)

since/calendar-dateuntil-called-with-singular-largestunit.js  -> 
until/calendar-dateuntil-called-with-singular-largestunit.js  -> 
2024-02-16 12:27:23 -05:00
Shannon Booth
6d4eda0028 LibJS: Make CreateTemporalDuration return a NonnullGCPtr
Since it can't return null.

This also results in a bunch of fallout from callers who were
expecting a raw pointer.
2024-02-16 12:27:23 -05:00
Shannon Booth
fdfe06bb44 LibJS: Begin implementing Temporal's CalendarMethodsRecord
This is part of a large refactor made as part of the temporal spec.
Most AOs using the calendar now pass through this record. There will
need to be a long process of going through updating AOs to use this
record.
2024-02-16 12:27:23 -05:00
Matthew Olsson
3c9c134d71 LibWeb: Implement KeyframeEffect::{get,set}_keyframes 2024-02-13 19:44:44 +01:00
Nico Weber
4409b33145 AK: Make IndexSequence use size_t
This makes it possible to use MakeIndexSequqnce in functions like:

    template<typename T, size_t N>
    constexpr auto foo(T (&a)[N])

This means AK/StdLibExtraDetails.h must now include AK/Types.h
for size_t, which means AK/Types.h can no longer include
AK/StdLibExtras.h (which arguably it shouldn't do anyways),
which requires rejiggering some things.

(IMHO Types.h shouldn't use AK::Details metaprogramming at all.
FlatPtr doesn't necessarily have to use Conditional<> and ssize_t could
maybe be in its own header or something. But since it's tangential to
this PR, going with the tried and true "lift things that cause the
cycle up to the top" approach.)
2024-02-11 18:53:00 +01:00
Shannon Booth
0ed352e44e LibJS: Update DifferenceInstant and its callers to latest spec
This is a bit tangled in that updating these functions involves a slew
of other spec changes.

However those spec updates fix a bunch of rounding issues, fixing 32
test cases.

Diff Tests:
    +32     -32 
2024-02-06 08:45:34 +01:00
Shannon Booth
c4f37c1bfa LibJS: Implement Temporal AO BalanceDuration 2024-02-06 08:45:34 +01:00
Shannon Booth
276930185a LibJS: Implement temporal AO BalancePossiblyInfiniteTimeDuration
This has the guts of the old temporal AO BalanceDuration with some
differences such as an extra precision of one unit. This appears to be
important for different rounding modes to act as a tiebreaker.

It also does not have any logic regarding a zoned date time 'relative
to' - the spec seems to have this factored in a way where callers are
expected to perform this logic if neccessary.
2024-02-06 08:45:34 +01:00
Shannon Booth
750ecc3f43 LibJS: Add a FIXME to remove use of old Temporal AO BalanceDuration
This is a bit too big of a yak to take on right now - leave a FIXME to
remove this as it seems easier to update callers of this function
piecemeal.
2024-02-06 08:45:34 +01:00
Shannon Booth
af586dde64 LibJS: Add a remainder() function to represent remainder(x, y)
This is just the same as calling x % y - or fmod, and is implemented
for symmetry with the 'modulo' function.
2024-02-06 08:45:34 +01:00
Timothy Flynn
0d3072bdac LibJS: Use IteratorStepValue in ECMA-402
This is an editorial change in the ECMA-402 spec. See:
e295500
2024-02-03 14:07:26 -05:00
Timothy Flynn
18847fca50 LibJS: Use IteratorStepValue in ECMA-262
This is an editorial change in the ECMA-262 spec. See:
12d3687

Note they have not yet updated all potential consumers to use this new
AO.
2024-02-03 14:07:26 -05:00
Timothy Flynn
2b96e732dd LibJS: Implement the IteratorStepValue AO
This is an editorial change in the ECMA-262 spec. See:
12d3687

This AO is meant to replace usages of IteratorNext followed by
IteratorValue with a single operation.
2024-02-03 14:07:26 -05:00
Timothy Flynn
3ca86cd044 LibJS: Allow creating the specialized Optional<Value> from OptionalNone
This allows, for example:

    ThrowCompletionOr<Optional<Value>> foo()
    {
        return OptionalNone {};
    }

The constructors and constraints here are lifted verbatim from
AK::Optional.
2024-02-03 14:07:26 -05:00
Kyle Lanmon
f757a7cfa8 LibJS: Support more weird date formats found on the web 2024-02-03 09:29:40 +01:00
Linus Groh
d667721b24 LibJS: Skip object creation for BigInt and Symbol values in GetValue
I'm not sure why these were omitted initially - works fine for other
engines, e.g.:

- d5aed64eff/src/types/language/value.zig (L1279-L1292)
- 5792a94c10/Source/JavaScriptCore/runtime/JSCJSValue.cpp (L180-L206)
2024-01-27 13:11:18 -05:00
Dan Klishch
b5f1a48a7c AK+Everywhere: Remove JsonValue APIs with implicit default values 2024-01-21 15:47:53 -07:00
Dan Klishch
77f36a9e46 LibJS: Remove redundant use of JsonValue::{is,as}_i32()
Value::Value(double) already converts double to int when it is safe, no
need to check for this here explicitly. While this technically removes
an optimization, I doubt that it will regress performance in any
measurable way.
2024-01-21 15:47:53 -07:00
Andreas Kling
1a07205c33 LibJS: Don't reserve space in function environment for parameter locals
3% speed-up on Octane/typescript.js (but basically improves performance
on most JS.)
2024-01-21 21:03:59 +01:00
Andreas Kling
bed78eb3cc LibJS: Don't add uncaptured parameter bindings to environment
For parameters that exist strictly as "locals", we can save time and
space by not adding them to the function environment.

This is a speed-up across the board on basically every test.
For example, ~11% on Octane/typescript.js :^)
2024-01-21 21:03:59 +01:00
Andrew Kaster
aef5932235 LibJS: Add method to VM to clear the execution context stack
This is needed for the spin the event loop AO in LibWeb
2024-01-19 11:47:59 +01:00
Shannon Booth
a7316d3641 LibJS: Update Temporal RoundDuration AO to some spec changes
This commit effectively just does a bulk update of this function to the
spec. Since there have been so many spec changes, no specific change was
made in mind, and many FIXMEs have been left for where we are still out
of date.

These changes also appear to include a normative change to the temporal
spec which was previously resulting in timeouts for some tests, and is
now resulting in a timeout.

Furthermore, this also resolves some crashes by protecting against
division by zero, instead throwing a RangeError. This can only happen
when a custom calender is provided which returns funky values. See:

https://github.com/tc39/proposal-temporal/commit/ed85e9

Diff Tests:
    +8     -4 💀    -4 💥
2024-01-14 16:08:52 -07:00
Shannon Booth
83b84cf0bd LibJS: Implement Temporal AO DifferenceDate 2024-01-14 16:08:52 -07:00
Shannon Booth
a372a16b2c LibJS: Improve const-correctness of CalendarDateUntil 2024-01-14 16:08:52 -07:00
Shannon Booth
23c5a7a0a3 LibJS: Expose const prototype getter in Object
This is used in the temporal proposal in an assertion.
2024-01-14 16:08:52 -07:00
Shannon Booth
9f7e27564c LibJS: Catch up DifferenceTemporalPlainYearMonth somewhat to the spec
The spec has moved along quite a bit since this was originally
implemented. Catch up on at least some of these changes, and leave
FIXMEs for what is missing.

No change to test262.
2024-01-14 16:08:52 -07:00
Shannon Booth
d2710ad73f LibJS: Implement temporal AO SnapshotOwnProperties 2024-01-14 16:08:52 -07:00
Shannon Booth
107fa1fdb8 LibJS: Implement excluded values in CopyDataProperties
This is a change to this AO as part of the Temporal proposal.
2024-01-14 16:08:52 -07:00
Tim Ledbetter
48a3a02238 LibCrypto: Make constructing a BigInteger from string fallible
Previously, constructing a `UnsignedBigInteger::from_base()` could
produce an incorrect result if the input string contained a valid
Base36 digit that was out of range of the given base. The same method
would also crash if the input string contained an invalid Base36 digit.
An error is now returned in both these cases.

Constructing a BigFraction from string is now also fallible, so that we
can handle the case where we are given an input string with invalid
digits.
2024-01-13 19:01:35 -07:00
Dan Klishch
ccd701809f Everywhere: Add deprecated_ prefix to JsonValue::to_byte_string
`JsonValue::to_byte_string` has peculiar type-erasure semantics which is
not usually intended. Unfortunately, it also has a very stereotypical
name which does not warn about unexpected behavior. So let's prefix it
with `deprecated_` to make new code use `as_string` if it just wants to
get string value or `serialized<StringBuilder>` if it needs to do proper
serialization.
2024-01-12 17:41:34 -07:00
Timothy Flynn
75262a92e1 LibJS: Update spec notes for a resizable ArrayBuffer workaround
This is a normative change in the ECMA-262 spec. See:
22de374

The issue noted here has been fixed in the same way that we previously
worked around it. Update the spec notes to match.
2024-01-12 07:09:54 -05:00
Andrew Kaster
6047f1adcb LibJS: Ensure JS::Date has a key function and its vtable is in LibJS
Without a key function, the vtable for this class can be emitted into
every shared object or executable that needs it. This can cause bugs and
bad behavior when trying to access the vtable or RTTI for the class.

This is most easily seen when trying to call ``is<JS::Date>``, which
currently will do a dynamic_cast. Based on compiler, linker and loader
choices about ordering, it's possible that the code checking the RTTI
and the code that created the object could have a different vtable and
type_info in mind, causing false negatives for the ``is`` check.
2024-01-12 09:11:18 +01:00
Timothy Flynn
6d1c10ed10 LibJS: Implement the GetSubstitution AO according to the spec
There was recently a normative change to this AO in ECMA-262. See:
5eaee2f

It turns out we already implemented this to align with web-reality
before it was codified in the spec. This was a bit difficult to reason
without spec text and with a somewhat ad-hoc implementation. So this
patch aligns our implementation with the spec. There should not be any
behavior change.
2024-01-04 12:43:10 +01:00
Timothy Flynn
8de1db7b78 LibJS: Avoid needless allocation in the StringToNumber AO 2024-01-04 12:43:10 +01:00
Timothy Flynn
a984067567 LibJS: Make the StringIndexOf AO public
It will be used outside of String.prototype.
2024-01-04 12:43:10 +01:00
Shannon Booth
f589bedb0d LibJS: Improve JS::modulo precision for large floating values
JS::modulo was yielding a result of '0' for the input:
```
modulo(1., 18446744073709551616.)
```

Instead of the expected '1'.

As far as I can tell the reason for this is that the repeated calls to
fmod is losing precision in the calculation, leading to the wrong
result. Fix this by only calling fmod once, and preserving the negative
value behaviour by an 'if' check.

Without this, the LibWeb text test:
`/Streams/ReadableByteStream-enqueue-respond.html`

Would hang forever after using this function in the IDL conversion of a
u64 in ConvertToInt.

This should also be more efficient :^)
2024-01-02 10:01:26 +01:00
Shannon Booth
986abe7047 LibJS: Rename IntlNumberIsNaNOrInfinity to NumberIsNaNOrInfinity
While only currently used in Intl in LibJS, this is a pretty generic
error and is useful elsewhere. Rename it to something more generic.
2024-01-02 10:01:26 +01:00
Shannon Booth
56ec36a9dc LibJS: Export MAX_ARRAY_LIKE_INDEX & NEGATIVE_ZERO_BITS in JS namespace 2024-01-02 10:01:26 +01:00
Andreas Kling
0ad4be3d78 LibJS: Skip redundant UTF-8 validation in rope string resolution
When resolving a rope, we've already taken care to resolve it to
a UTF-8 byte stream. There's no need to do a separate pass just for
validating the data again.

This was noticeable in some profiles. I made a simple microbenchmark
that gets a 30% speed-up:

    ("x" + "y".repeat(100_000_000)).trimStart()
2023-12-30 13:49:50 +01:00
Andreas Kling
a285e36041 LibJS+AK: Make String.prototype.repeat() way faster
Instead of using a StringBuilder, add a String::repeated(String, N)
overload that takes advantage of knowing it's already all UTF-8.

This makes the following microbenchmark go 4x faster:

    "foo".repeat(100_000_000)

And for single character strings, we can even go 10x faster:

    "x".repeat(100_000_000)
2023-12-30 13:49:50 +01:00
Timothy Flynn
3f3686cf7b LibJS: Implement missing steps from the ArrayBuffer transfer proposal
We can now implement steps related to resizable ArrayBuffer objects. We
can also implement a couple of missing SharedArrayBuffer checks.

The original implementation of this proposal did not have any tests, so
tests are added here for the whole implementation.
2023-12-29 09:25:41 +01:00
Timothy Flynn
526a74f2f1 LibJS: Implement missing checks for SharedArrayBuffer values 2023-12-29 09:25:41 +01:00
Timothy Flynn
299c86db20 LibJS: Change error message for values that can't be a SharedArrayBuffer
This error will be used in contexts that apply to more than than the
|this| object.
2023-12-29 09:25:41 +01:00