1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
Commit graph

1596 commits

Author SHA1 Message Date
R-Goc
9ec26058d1 LibTest/Tests: Build and run test-js on windows
This commit allows test-js to build and run, also in CI.

Co-authored-by: Andrew Kaster <andrew@ladybird.org>
2025-06-05 22:00:55 -06:00
Aliaksandr Kalenik
3b68fd0b8e LibJS: Make array_like_size() non-virtual in IndexedPropertyStorage 2025-06-05 03:43:43 +02:00
Aliaksandr Kalenik
1d4f63e4cd LibJS: Add simple storage fast path in internal_define_own_property()
...of Array. If array has simple storage, which implies that attributes
of all indexed properties are default, and newly added property also
has default attribute, we can do a fast path and skip lots of checks
that happen in `Object::internal_define_own_property()`.
2025-06-05 03:43:43 +02:00
Aliaksandr Kalenik
20655b8ebf LibJS: Add simple storage fast path in internal_get_own_property()
...of Array. This allows us to avoid lots of unnecessary for simple
arrays checks that happen in `Object::internal_get_own_property()`.
2025-06-05 03:43:43 +02:00
Timothy Flynn
128675770c LibJS: Implement Intl.Locale.prototype.variants
This is a normative change in the ECMA-402 spec. See:
e8c995a
2025-06-04 17:11:35 -04:00
Timothy Flynn
324bd0f163 LibJS: Update the Intl.Locale prototype to the latest editorial spec
This has been refactored a bit recently.
2025-06-04 17:11:35 -04:00
Timothy Flynn
208a5e6763 LibJS: Update the Intl.Locale constructor to the latest editorial spec
This has been refactored a bit recently. There are upcoming normative
changes that do not apply cleanly without this update.
2025-06-04 17:11:35 -04:00
Aliaksandr Kalenik
93cd17db74 LibJS: Add fast path internal_has_property() for Array
If array has packed index property storage without holes, we could check
if indexed property is present simple by checking if it's less than
array's length.

Makes the following program go 1.1x faster:
```js
function f() {
    let array = [];
    for (let i = 0; i < 3_000; i++) {
        array.push(i);
    }

    for (let i = 0; i < 10_000; i++) {
        array.map(x => x * 2);
    }
}

f();
```
2025-06-03 23:18:41 +02:00
Aliaksandr Kalenik
22e0b732db LibJS: Add missing update for holes count in IndexedPropertyStorage
This one is required to cover the case when new empty elements are
introduced by assigning to element with index > length, like:
```js
var x = [];
x[0] = 1;
x[2] = 2;
```
2025-06-03 23:18:41 +02:00
Aliaksandr Kalenik
1274f4e2f7 LibJS: Optimize Function.prototype.apply()
...by avoiding `CreateListFromArrayLike` in cases when we could directly
use elements of underlying object's indexed properties storage.

Makes this program go 2.1x faster:
```js
function target(a, b, c) {
    return a + b + c;
}

const args = [1, 2, 3];
let result = 0;

(function() {
    for (let i = 0; i < 10_000_000; i++) {
        result += target.apply(null, args);
    }
})();
```
2025-06-03 17:16:01 +02:00
Aliaksandr Kalenik
3f7c4dd5f6 LibJS: Maintain number of empty elements in SimpleIndexedPropertyStorage
This will be used in upcoming changes to do a fast path when array does
not have any holes.
2025-06-03 17:16:01 +02:00
Timothy Flynn
8145572180 LibJS+LibUnicode: Support ambiguous time zone transitions
For example, time zone transitions can result in repeated or skipped
wall times. Temporal wants us to handle these transitions.
2025-06-03 09:09:21 +12:00
Timothy Flynn
c8b4dc4847 LibJS: Require strict matching with a precise ZonedDateTime offset
This is a normative change in the Temporal proposal. See:
1117eaf
2025-06-03 09:09:21 +12:00
Timothy Flynn
f091047159 LibJS+LibUnicode: Implement retrieval of collator keyword values
Completely missed this when implementing Intl.Collator!
2025-06-03 09:03:33 +12:00
Aliaksandr Kalenik
285bc005cb LibJS: Do more comprehensive check if next() fast path is possible
Before this change each built-in iterator object has a boolean
`m_next_method_was_redefined`. If user code later changed the iterator’s
prototype (e.g. `Object.setPrototypeOf()`), we still believed the
built-in fast-path was safe and skipped the user supplied override,
producing wrong results.

With this change
`BuiltinIterator::as_builtin_iterator_if_next_is_not_redefined()` looks
up the current `next` property and verifies that it is still the
built-in native function.
2025-06-02 00:15:36 +02:00
Julien Le Bras
3ba6d129df LibJS: Cache string constants in Generator::add_constant
This mirrors the existing caching logic for int32 constants.
Avoids duplication of string constants in m_constants which could
result in stack overflows for large scripts with a lot of similar
strings.
2025-06-01 18:25:59 +02:00
Richard Gibson
9bf836e6c4 js: Don't escape printed strings with --disable-string-quotes 2025-06-01 09:51:09 -04:00
Timothy Flynn
5e40db5a17 AK: Remove some now-unnecessary workarounds for simdutf base64 usage 2025-06-01 08:03:00 -04:00
Lucien Fiorini
81e84c8273 js: Add option to disable quotes around strings 2025-05-29 17:33:26 -06:00
R-Goc
96c197faf1 LibJS: Add minimum changes to build on Windows and run js.exe
This commit adds the minimal export macros needed to run js.exe on
windows. A followup commit is planned to move to explicit export
entirely.

A static_assert for the size of a struct is also ifdef'ed out as the
semantics around object layout and inheritance are different on MSVC abi
and the struct IteratorRecord ends up being 40 bytes not 32.
2025-05-29 03:26:23 -06:00
Timothy Flynn
8e5cc74eb1 LibJS: Add notation to Intl.PluralRules
This is a normative change in the ECMA-402 spec. See:
a7ff535
2025-05-27 10:39:25 -04:00
Aliaksandr Kalenik
1647d7b34c LibJS: Use CallBuiltin for Math.tan() 2025-05-26 21:52:43 +02:00
Aliaksandr Kalenik
878cc16d7a LibJS: Use CallBuiltin for Math.cos() 2025-05-26 21:52:43 +02:00
Aliaksandr Kalenik
c02535e9f9 LibJS: Use CallBuiltin for Math.sin()
Improves performance on https://pierre.co/
2025-05-26 21:52:43 +02:00
Manuel Zahariev
addff9e35d LibJS: Unit tests for non-standard date formats 2025-05-26 18:48:09 +02:00
Manuel Zahariev
973110c046 LibJS: Convert date_parse_string to use DateParser 2025-05-26 18:48:09 +02:00
Manuel Zahariev
8263e7fa51 LibJS: DateParser for simplified ISO8601 and non-standard date strings 2025-05-26 18:48:09 +02:00
Aliaksandr Kalenik
dcfc515cd0 LibJS: Fix arrow function parsing bug
In the following example:
```js
const f = (i) => ({
    obj: { a: { x: i }, b: { x: i } },
    g: () => {},
});
```

The body of function `f` is initially parsed as an arrow function. As a
result, what is actually an object expression is interpreted as a formal
parameter with a binding pattern. Since duplicate identifiers are not
allowed in this context (`i` in the example), the parser generates an
error, causing the entire script to fail parsing.

This change ignores the "Duplicate parameter names in bindings" error
during arrow function parameter parsing, allowing the parser to continue
and recognize the object expression of the outer arrow function with an
implicit return.

Fixes error on https://chat.openai.com/
2025-05-26 12:44:21 +03:00
Aliaksandr Kalenik
bd6750aaa5 LibJS: Skip prototype chain lookup in internal_set() for arrays
...when Array.prototype and Object.prototype are intact.

If `internal_set()` is called on an array exotic object with a numeric
PropertyKey, and:
- the prototype chain has not been modified (i.e., there are no getters
  or setters for indexed properties), and
- the array is not the target of a Proxy object,

then we can directly store the value in the receiver's indexed
properties, without checking whether it already exists somewhere in the
prototype chain.

1.7x improvement on the following program:
```js
function f() {
    let a = [];
    let i = 0;
    while (i < 10_000_000) {
        a.push(i);
        i++;
    }
}

f();
```
2025-05-23 14:51:32 +02:00
Aliaksandr Kalenik
6404f6db57 LibJS: Delete unused Shape::create_for_prototype() 2025-05-23 14:51:32 +02:00
devgianlu
4b3715ccba LibCrypto: Replace {Unsigned,Signed}BigInteger impl with LibTomMath
Replace the implementation of maths in `UnsignedBigInteger`
and `SignedBigInteger` with LibTomMath. This gives benefits in terms of
less code to maintain, correctness and speed.

These changes also remove now-unsued methods and improve the error
propagation for functions allocating lots of memory. Additionally, the
new implementation is always trimmed and won't have dangling zeros when
exporting it.
2025-05-23 11:57:21 +02:00
devgianlu
5a4cfd05d0 LibCrypto+LibJS: Move Power to method of {Unsigned,Signed}BigInteger
Having it as a method instead of a free function is necessary for the
next commits and generally allows for optimizations that require deeper
access into the `UnsignedBigInteger` / `SignedBigInteger`.

Also restrict the exponent to 32 bits to avoid huge memory allocations.
2025-05-23 11:57:21 +02:00
Shannon Booth
3bf7f94150 LibJS: Use caller_context to determine strict mode
This is functionaly the same since caller_context is the topmost
execution context on the stack, but makes it more clear that
we are directly inheriting the strict mode from the caller context
when pushing the next context on to the stack.
2025-05-23 03:25:55 +02:00
Shannon Booth
7d44640c0f LibJS: Assume is_strict_mode called with running execution context
This should always be invoked when there is an execution context
on the stack.
2025-05-23 03:25:55 +02:00
Shannon Booth
f2fb86abea LibJS: Always emit value in emit_named_evaluation_if_anonymous_function
There does not appear to be any case that we need to return an
OptionalNone{}.
2025-05-23 03:25:55 +02:00
Shannon Booth
20dba8f1ab LibJS: Make Op::Return value required
It turns out we do not have any scenario where this is not provided.
2025-05-23 03:25:55 +02:00
Aliaksandr Kalenik
95e1ec4abc LibJS: Skip caching get_by_id() if object's shape is changed by a getter
Fixes a bug that reproduces with the following steps:
1. Create an object with a getter for property "a" in its prototype,
   where the getter adds an "a" property to the object itself.
2. Call the "a" getter in a loop for the first time. This triggers
   caching of metadata indicating that the "a" property is located in
   the prototype chain.
3. Call the "a" getter in a loop for the second time. Oops, the cache
   says the getter is in the prototype chain, but the object now
   also has its own "a" property that was added by the first getter
   call.
2025-05-20 19:10:56 -04:00
Aliaksandr Kalenik
b559965448 LibJS+LibWeb: Replace StringOrSymbol usage with PropertyKey
- Avoids unnecessary conversions between StringOrSymbol and PropertyKey
  on the hot path of property access.
- Simplifies the code by removing StringOrSymbol and using PropertyKey
  directly. There was no reason to have a separate StringOrSymbol type
  representing the same data as PropertyKey, just with the index key
  stored as a string.

PropertyKey has been updated to use a tagged pointer instead of a
Variant, so it still occupies 8 bytes, same as StringOrSymbol.

12% improvement on JetStream/gcc-loops.cpp.js
12% improvement on MicroBench/object-assign.js
7% improvement on MicroBench/object-keys.js
2025-05-17 10:08:37 -04:00
Shannon Booth
5495531118 LibJS: Implement 'less than' for a String over code units
...Instead of code points.
2025-05-17 08:00:59 -04:00
Tim Ledbetter
2903defcfc Revert "LibJS+LibWeb: Return Vector<PropertyKey> from…
internal_own_property_keys"

This reverts commit 5ee810f772.
2025-05-16 06:33:09 +01:00
Tim Ledbetter
8cd9275416 Revert "LibJS: Ensure keys vector capacity in…
Object::internal_own_property_keys"

This reverts commit 27ba216e3f.
2025-05-16 06:33:09 +01:00
Aliaksandr Kalenik
27ba216e3f LibJS: Ensure keys vector capacity in Object::internal_own_property_keys
12% improvement on MicroBench/object-keys.js
2025-05-15 14:12:18 -04:00
Aliaksandr Kalenik
5ee810f772 LibJS+LibWeb: Return Vector<PropertyKey> from internal_own_property_keys
By doing that we avoid lots of `PropertyKey` -> `Value` -> `PropertyKey`
transforms, which are quite expensive because of underlying
`FlyString` -> `PrimitiveString` -> `FlyString` conversions.

10% improvement on MicroBench/object-keys.js
2025-05-15 14:12:18 -04:00
R-Goc
d60543c2cb LibJS/LibCrypto: Cleanup JS Math random() RNG
This commit adds a convenience method to secure random for initializing
single types. It changes the random number generator in JS math random()
to use newer constants by the author as well as initializes it with a
higher quality seed.
2025-05-15 07:41:02 -06:00
R-Goc
34c14d4e6d LibJS: Add fast path for float to int put
This commit adds a fast path for putting values into a TypedArray of an
integer type, when the value being put in is a double. This leads to a
6% speedup on JetStream/gcc-loops.js.
2025-05-14 12:33:35 +02:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
Aliaksandr Kalenik
155e60a5ff LibJS: Use iteration_step() in IteratorNextUnpack instruction
Allows us to avoid code duplication for builtin iterators fast path.
2025-05-13 15:14:25 +03:00
Aliaksandr Kalenik
bb53485dea LibJS+LibWeb: Add fast path for builtin iterators in iterator_step()
We already have fast path for built-in iterators that skips `next()`
lookup and iteration result object allocation applied for `for..of` and
`for..in` loops. This change extends it to `iterator_step()` to cover
`Array.from()`, `[...arr]` and many other cases.

Makes following function go 2.35x faster on my computer:
```js
(function f() {
  let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  for (let i = 0; i < 1000000; i++) {
    let [a, ...rest] = arr;
  }
})();
```
2025-05-13 15:14:25 +03:00
Daniel Bertalan
456d750539 LibJS: Make generate_labelled_evaluation non-virtual if possible
We don't override anything with definitions of this function in
`SwitchStatement` and `LabelledStatement`. Also, we can make the
`IterationStatement` abstract, there is no need to add a fallback
error-generating stub implementation of this method.
2025-05-12 11:40:45 -06:00
Aliaksandr Kalenik
f405d71657 LibJS: Disable optimization in IteratorNextUnpack if next() is redefined
81b6a11 regressed correctness by always bypassing the `next()` method
resolution for built-in iterators, causing incorrect behavior when
`next()` was redefined on built-in prototypes. This change fixes the
issue by storing a flag on built-in prototypes indicating whether
`next()` has ever been redefined.
2025-05-12 07:41:29 -04:00