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

604 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
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
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
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
Timothy Flynn
5e40db5a17 AK: Remove some now-unnecessary workarounds for simdutf base64 usage 2025-06-01 08:03:00 -04: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
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
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
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
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
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
Andreas Kling
74f133293d LibJS: Avoid redundant ExecutionContext allocation for bound functions
Instead of creating a second ExecutionContext in BoundFunction.[[Call]],
we now implement BoundFunction::get_stack_frame_size() and combine
information from the target + the bound arguments list.

This allows BoundFunction.[[Call]] to reuse the already-established
ExecutionContext for the callee.

1.20x speedup on MicroBench/bound-call-04-args.js
2025-05-07 13:20:41 +02:00
Timothy Flynn
8a80ff7b3b AK+LibJS: Use simdutf for all base64 operations
We were previously unable to use simdutf for base64 decoding operations
other than "loose". Upstream has added support for the "strict" and
"stop-before-partial" operations, so let's make use of them!
2025-05-03 11:21:10 -04:00
Timothy Flynn
4d70f6ce1c LibJS: Ensure iterator parameter validation closes underlying iterator
This is a normative change in the ECMA-262 spec. See:
9552f29
f2bad00
2025-04-29 07:33:08 -04:00
Timothy Flynn
568524f8ba LibJS: Close sync iterator when async wrapper yields rejection
This is a normative change in the ECMA-262 spec. See:
ff129b1
2025-04-29 07:33:08 -04:00
Timothy Flynn
15faaeb2bb LibJS: Remove [[VarNames]] from GlobalEnvironment
This is a normative change in the ECMA-262 spec. See:
ed75310
2025-04-29 07:33:08 -04:00
aplefull
223c9c91e6 LibJS: Implement rawJSON and isRawJSON functions 2025-04-24 09:33:49 -04:00
Luke Wilde
25e343464d LibJS: Cache length identifier for GetLengthWithThis
We cached the length identifier for GetLength, but not
GetLengthWithThis. This caused an `has_value()` verification failure
when accessing super.length. Found by Fuzzilli.
2025-04-07 14:40:48 +02:00
devgianlu
08cfd5ff1b LibJS: Set empty function parameters on ClassStaticInit scope
This prevents the variables declared inside a class static initializer
to escape to the nearest containing function causing all sorts of memory
corruptions.
2025-04-05 18:20:36 +01:00
Andreas Kling
fe1962d7fa LibJS: Make SetCompletionType bytecode instruction actually set type
This recovers 38 tests in test262 that regressed in a0bb31f7a0.
2025-04-05 15:00:05 +02:00
Jess
83e46b3728 LibRegex: Fix crash when parse result exceeds max cache size
Before, If the cache was empty we would try and evict non-existant
entries and crash. So the fix is to make sure that we don't saturate
the cache with a single parse result.
2025-04-04 16:10:25 +02:00
Lucien Fiorini
6b6e13e28c LibJS: Avoid emptying the return value register in try/finally
This works because at the end of the finally chunk, a
ContinuePendingUnwind is generated which copies the saved return value
register into the return value register. In cases where
ContinuePendingUnwind is not generated such as when there is a break
statement in the finally block, the fonction will return undefined which
is consistent with V8 and SpiderMonkey.
2025-03-27 12:18:30 +00:00
Jess
f3a937ee76 LibJS: Fix integer overflow in target_offset of TypedArray.set() 2025-03-25 07:45:42 +00:00
Tim Ledbetter
ed62aa6224 Revert "LibJS: Reduce number of proxy traps called during for..in…
…iteration"

This reverts commit 357eeba49c.
2025-03-21 11:44:21 -05:00
Andreas Kling
357eeba49c LibJS: Reduce number of proxy traps called during for..in iteration
Before this change, we would enumerate all the keys with
[[OwnPropertyKeys]], and then do [[GetOwnPropertyDescriptor]] twice for
each key as we went through them.

We now only do one [[GetOwnPropertyDescriptor]] per key, which
drastically reduces the number of proxy traps when those are involved.
The new trap sequence matches what you get with V8, so I don't think
anyone will be unpleasantly surprised here.
2025-03-20 17:50:02 -05:00
Andreas Kling
660d533b50 LibJS: Don't assume [[GetOwnPropertyDescriptor]] always succeeds
It can fail if we're talking to a badly-behaved proxy when enumerating
object properties for iteration.
2025-03-20 12:51:21 -05:00
Jess
12cbefbee7 LibJS+LibCrypto: Use a bitwise approach for BigInt's as*IntN methods
This speeds up expressions such as `BigInt.asIntN(0x4000000000000, 1n)`
(#3615). And those involving very large bigints.
2025-03-20 09:44:12 +01:00
Jess
f5a6704219 LibJS: Fix UAF in ECMAScriptFunctionObject::internal_construct
Currently, we create `this_argument` with
`ordinary_create_from_constructor`, then we use `arguments_list` to
build the callee_context.

The issue is we don't properly model the side-effects of
`ordinary_create_from_constructor`, if `new_target` is a proxy object
then when we `get` the prototype, arbitrary javascript can run.

This javascript could perform a function call with enough arguments to
reallocate the interpreters m_argument_values_buffer vector. This is
dangerous and leads to a use-after-free, as our stack frame maintains a
pointer to m_argument_values_buffer (`arguments_list`).
2025-03-19 10:31:00 +01:00
Timothy Flynn
00d00b84d3 LibJS: Ensure relevant extension keys are included in ICU locale data
This is a normative change in the ECMA-402 spec. See:
7508197

In our implementation, we don't have the affected AOs directly, as we
delegate to ICU. So instead, we must ensure we provide ICU a locale with
the relevant extension keys present.
2025-03-18 11:47:23 -04:00
Timothy Flynn
37b8ba96f1 LibJS: Use currency digits for NumberFormat only for standard notation
This is a normative change in the ECMA-402 spec. See:
9140da2
2025-03-18 11:47:23 -04:00
aplefull
80b2c11c81 LibJS: Implement Math.sumPrecise 2025-03-03 21:46:22 +01:00
aplefull
53cdb04ee8 LibJS: Fix parseFloat(-0) returning -0 instead of +0
The optimization that skips the string conversion for number values was
causing -0 to be returned as-is. This patch adds a check for this case.
2025-03-02 11:30:34 -05:00
Timothy Flynn
080d32c7d0 LibJS: Use Intl.DurationFormat for Temporal.Duration.p.toLocaleString
This is an normative change in the Temporal proposal. See:
ffb4fb5
2025-03-01 14:49:20 +01:00
Timothy Flynn
8f51d1dd04 LibJS: Integrate Temporal.Duration into Intl.DurationFormat
This is a normative change in the Temporal proposal. See:
2d97205
2025-03-01 14:49:20 +01:00
Ali Mohammad Pur
ea3b7efd91 LibRegex: Treat the UnicodeSets flag as Unicode
Fixes /.../v not being interpreted as a unicode pattern.
2025-02-28 14:31:45 -05:00
Jess
8ed7dee0f0 LibJS: Propogate allocation errors in BigInt constructor functions 2025-02-19 09:00:59 -05:00
Luke Wilde
105096e75a LibJS: Stop executing successful regex if it's past the end of the input
If the regex always matches the input, even if it's past the end, then
we need to stop execution of the regex when it's past the end. This
corresponds to step 13.a and prevents it from infinitely looping.

Reduced from: d98672060f/packages/react-i18n/src/utilities/money.ts (L10-L14)
2025-02-16 09:22:37 +01:00
Jess
356728b1e0 LibJS: Fix bytecode generation for super property stores and loads
The new test case crashes during bytecode generation due to
`emit_super_reference` not correctly generating the reference record
for the property access.
2025-02-15 06:59:59 -05:00
Psychpsyo
f92d037752 LibJS: Parse dates like "Jan 15, 2025" 2025-02-14 06:27:37 -05:00
jg99
51434c2ed0 LibJS: Parse dates like "1 Jan 2001 00:00:00 GMT" 2025-02-05 15:06:54 -07:00
Timothy Flynn
911b915763 LibJS: Handle call stack limit exceptions in NewPromiseReactionJob
The promise job's fulfillment / rejection handlers may push an execution
context onto the VM, which will throw an internal error if our ad-hoc
call stack size limit has been reached. Thus, we cannot blindly VERIFY
that the result of invoking these handlers is non-abrupt.

This patch will propagate any internal error forward, and retains the
condition that any other error type is not thrown.
2025-02-05 08:05:01 -05:00
Luke Wilde
30507681f7 LibJS: Parse dates like "2021-04-21T15:00:00+0000"
This is used on figma.com
2025-01-21 21:36:05 +01:00
Luke Wilde
3ab4efb7ef LibJS: Parse dates like "2025-01-13 00:00:00.000"
This is used on figma.com.
2025-01-21 21:36:05 +01:00
Timothy Flynn
b64a355a30 LibJS: Remove support for the "assert" keyword for import attributes
This was removed from the spec some time ago. See:
14286bb
2025-01-21 14:58:32 +01:00
Timothy Flynn
47ba231a9b LibJS: Do not consume "with" tokens in import statements as identifiers
The "with" statement is its own token (TokenType::With), and thus would
fail to parse as an identifier. We've already asserted that the token
we are parsing is "with" or "assert", so just consume it.
2025-01-21 14:58:32 +01:00