Commit graph

1456 commits

Author SHA1 Message Date
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
29c8e7c203 LibJS: Disallow large dates in ToTemporalMonthDay
This is a normative change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/bd5ac12

Note: No test added here because this only affects non-ISO-8601
calendars, which we do not yet support.
2025-03-01 14:49:20 +01:00
Timothy Flynn
080d32c7d0 LibJS: Use Intl.DurationFormat for Temporal.Duration.p.toLocaleString
This is an normative change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/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:
https://github.com/tc39/proposal-temporal/commit/2d97205
2025-03-01 14:49:20 +01:00
Timothy Flynn
f16fe66def LibJS: Migrate IsValidDuration to ECMA-262
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/03770bb

Note: We were actually already using the Temporal definition of this AO
in Intl.DurationFormat, so there's no change needed there.
2025-03-01 14:49:20 +01:00
Timothy Flynn
aa737bb654 LibJS: Migrate ToIntegerIfIntegral to ECMA-262
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/5f76109
2025-03-01 14:49:20 +01:00
Timothy Flynn
a8d6e5c3db LibJS: Migrate Temporal updates to ECMA-262 AOs to the main AO file
These are going to be included in the ECMA-262 AOs once Temporal reaches
stage 4. There's no need to keep them in the Temporal namespace. Some
upcoming Temporal editorial changes will get awkward without this patch.
2025-03-01 14:49:20 +01:00
Timothy Flynn
ea52952774 LibJS: Update Date AOs to use Temporal
Neglected to do this after the Temporal rewrite. This lets us eliminate
the duplicated GetUTCEpochNanoseconds definition in Temporal.
2025-03-01 14:49:20 +01:00
Timothy Flynn
5764eeab05 LibJS: Update spec numbers for the Intl.DurationFormat proposal
This proposal has reached stage 4 and was merged into the ECMA-402 spec.
See: https://github.com/tc39/ecma402/commit/3ff3cc7
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
Timothy Flynn
e591636419 AK+Everywhere: Store JSON object keys as String 2025-02-20 19:27:51 -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
Andreas Kling
dbf52a1b5f LibJS: Allocate RegExp.{lastMatch,leftContext,rightContext} lazily
These properties are always substrings of the RegExp input string,
and so we can store them as views and lazily construct strings if
they're actually accessed (which most of the time they aren't).

This avoids a bunch of unnecessary memory copying, saving roughly
2.1 seconds per iteration of Speedometer.
2025-02-09 00:28:15 +01:00
stasoid
52d0341c5d LibJS: Port to Windows 2025-02-06 15:16:50 -07:00
Timothy Flynn
97f7cb805f LibJS: Remove errant invocation to FormatNumericUnits
This is an editorial change in the Intl.DurationFormat proposal. See:
https://github.com/tc39/proposal-intl-duration-format/commit/cdef892
2025-02-06 10:46:04 -05:00
Timothy Flynn
eef9d07088 LibJS: Add an explicit check for a valid ISO date in ToTemporalYearMonth
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/a1c5d61
2025-02-06 07:59:09 -05:00
Timothy Flynn
97b384db74 LibJS: Move call to CreateISODateRecord lower in ToTemporalYearMonth
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/58fd7de
2025-02-06 07:59:09 -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
Timothy Flynn
b91a0f5403 LibJS: Repurpose MUST_OR_THROW_OOM to propagate general internal errors
There are now no users of the MUST_OR_THROW_OOM macro. Let's rename this
macro to indicate it may be used to propagate any internal error (such
as the call stack limit error) in places that would otherwise crash due
to a MUST/VERIFY invocation.

Note there's no actual functional change here, as we weren't able to
ensure the internal error was an OOM error previously.
2025-02-05 08:05:01 -05:00
Timothy Flynn
4c51602437 LibJS: Remove OOM handling from TypedArrayGetElement 2025-02-05 08:05:01 -05:00
Timothy Flynn
49f1ef52ad LibJS: Remove OOM handling from JS intrinsics initialization 2025-02-05 08:05:01 -05:00
Timothy Flynn
0fe9bbad2e LibJS: Add missing include to Intrinsics.h
This was preventing clangd in my environment from processing the
Intrinsics class.
2025-02-05 08:05:01 -05:00
Shannon Booth
b58ba2e1bd LibJS: Localize popping of execution context in AsyncFunctionDriver
Instead of adding a flag for the two callers that need a pop of the
execution context stack when invoking continue_async_execution inline
the pop of the execution context.

This makes the management of these stacks and surrounding VERIFY calls
much more obvious.
2025-01-30 13:57:29 -07:00
Shannon Booth
d1f9e3be90 LibJS: Only run queued promise jobs if there is no embedder
This has no functional difference as run_queued_promise jobs does
nothing when LibWeb is used as it has a different implementation of
enqueuing and running promise jobs. But this change makes it more
obvious that run_queued_promise jobs does nothing when there is an
embedder, and adjusts the comment to reflect what the code is
actually achieving.
2025-01-30 13:57:29 -07:00
Timothy Flynn
5372d07c5c LibJS: Simplify ParseTemporalCalendarString
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/1b1fd9f
2025-01-28 11:25:42 +00:00
Andreas Kling
d465e2aa2b LibJS: Cache the Intl.Collator in String.prototype.localeCompare()
In the very common case that no special constructor options are provided
for the Intl.Collator when calling localeCompare() on a string, we can
cache and reuse a default-constructed Intl.Collator, saving lots of time
and space.

This shaves a fair bit of load time off of https://wpt.fyi/ where they
use Array.prototype.sort() and localeCompare() to sort a big JSON thing.

Time spent in sort():
- Before: 1656 ms
- After: 135 ms
2025-01-23 21:38:19 +01:00
Andreas Kling
51a91771b8 LibJS+LibGC: Run FinalizationRegistry cleanup host hook *after* GC
Before this change, it was possible for a second GC to get triggered
in the middle of a first GC, due to allocations happening in the
FinalizationRegistry cleanup host hook. To avoid this causing problems,
we add a "post-GC task" mechanism and use that to invoke the host hook
once all other GC activity is finished, and we've unset the "collecting
garbage" flag.

Note that the test included here only fails reliably when running with
the -g flag (collect garbage after each allocation).

Fixes #3051
2025-01-23 12:10:21 +01: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
85b424464a AK+Everywhere: Rename verify_cast to as
Follow-up to fc20e61e72.
2025-01-21 11:34:06 -05:00
Timothy Flynn
b64a355a30 LibJS: Remove support for the "assert" keyword for import attributes
This was removed from the spec some time ago. See:
https://github.com/tc39/proposal-import-attributes/commit/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
Timothy Flynn
2c3077d929 LibJS: Implement InnerModuleLoading as a free function
It is currently implemented as a member of CyclicModule. However, as the
spec indicates, this must be invokable with non-CyclicModule modules. In
several of the call sites, we are blindly casting to a CyclicModule;
this will fail for e.g. JSON modules.
2025-01-21 14:58:32 +01:00
Timothy Flynn
049109452e LibJS: Do not attempt to link modules which have failed to load
Linking a module has assertions about the module's state, namely that
the state is not "new". The state remains "new" if loading the module
has failed. See: https://tc39.es/ecma262/#figure-module-graph-missing

    In any case, this exception causes a loading failure, which results
    in A's [[Status]] remaining new.

So we must propagate that failure, instead of blindly moving on to the
linking steps.
2025-01-21 14:58:32 +01:00
Timothy Flynn
7d420bbd3d LibJS: Update the noted grammar for ImportDeclaration 2025-01-21 14:58:32 +01:00
Timothy Flynn
263fd9b7c6 LibJS: Add missing spec prose to FinishLoadingImportedModule 2025-01-21 14:58:32 +01:00
Timothy Flynn
6a564376fc Meta+LibUnicode+LibJS: Upgrade to ICU 76.1
This updates our local ICU overlay port to use ICU 76.1. This includes
Unicode 16 and CLDR 46.

Upstream vcpkg is not able to supply versions past 74 yet due to various
dependency issues, but we are able to use this version ourselves. The
overlay port now includes a patch to revert ICU's dependence on autoconf
2.72 for now, as this version is not yet available on all systems.

All of the test changes were cross-referenced with Firefox to ensure
correctness.
2025-01-18 17:56:40 -05:00
Timothy Flynn
0763997591 LibJS: Ensure tests using the "ar" locale use the "arab" number system
In ICU 76, the default was changed from "arab" to "latn". See:
c149724509

The whole point of these tests was to use a non-Latin numbering system.
This patch ensures that is the case to make following patches easier to
grok.
2025-01-18 17:56:40 -05:00
Timothy Flynn
26c2484c2f LibJS: Implement the AsyncDisposableStack interface
This is very similar to the DisposableStack interface, except disposal
of resources is promise-based.
2025-01-17 20:46:32 +01:00
Timothy Flynn
5ea0aa5f08 LibJS: Bring the explicit resource management implementation up to date
While we don't yet have a working `using` implementation with our byte
code, we can still keep our DisposableStack implementation up to date.
The changes brought in here are all editorial, and set us up to start
an AsyncDisposableStack implementation.
2025-01-17 20:46:32 +01:00
Timothy Flynn
f82b1c5a2d LibJS: Alphabetically sort the list of well-known symbols 2025-01-17 20:46:32 +01:00
Luke Wilde
a588756105 LibJS: Use correct this value for tagged template literals with members
Required by creepjs, which does Date().split` `[3] to get the current
year.
2025-01-17 17:15:12 +01:00
Luke Wilde
5f33383a7b LibJS: Propagate direct eval presence if the current scope is screwed
Previously it only deoptimized the parent scope if the current scope
contains direct eval, which is incorrect because code ran in direct
eval mode has access to the entire scope chain it was executed in.
The fix is to also propagate direct eval's presence if the current
scope is marked as being screwed by direct eval.

This fixes Google's botguard failing to complete on Google sign in, as
it tried to access local variables outside of a direct parent function
with eval, causing it throw "unhandled" exceptions. Unhandled is in
quotes because their bytecode VM _technically_ caught it, but it was
considered an unhandled exception. This was determined by removing get
optimizations and then adding debug output for every get operation.
Using this, I noticed that for these errors, it would access the
'message' and 'stack' properties. This is because their error handler
function noticed this was not a synthesised error, which is never
expected to happen. That was determined by using Chrome Devtools 'pause
on handled exception' feature, and noticing it never threw a '[var] is
not defined' exception, but only synthesized error objects which
contained a sentinel value to let it know it was synthesized.

I added debug output to eval to print out what was being eval'd because
it makes heavy use of eval. This revealed that the exceptions only came
from eval.

I then dumped every generated executable and noticed the variables it
was trying to access were generated as local variables in the top
scope. This led to checking what makes a variable considered local or
not, which then lead to this block of code in ~ScopePusher that
propagates eval presence only to the immediate parent scope. This
variable directly controls whether to create all variables properly
with variable environments and bindings or allow them to be stored as
local registers tied to that function's executable.

Since this now lets botguard run to completion, it no longer considers
us to be an insecure/potential bot browser when signing in, now
allowing us to be able to sign in to Google.
2025-01-17 14:36:03 +01:00
Timothy Flynn
59162c8155 LibJS: Adjust ad-hoc clamping behavior in RegulateISODate
Instead of clamping to the limits allowed by ISOYearMonthWithinLimits,
clamp to the limits allowed by the type we are converting to (i32). This
allows some callers to then reject years outside that range.
2025-01-17 10:08:06 +01:00
Timothy Flynn
d5b26183f3 LibJS: Convert errant MUST to TRY in Temporal.PlainDateTime.with 2025-01-17 10:08:06 +01:00
Timothy Flynn
c3fc8996bf LibJS: Refer to RFC 9557 instead of ISO 8601 where appropriate
This is an editorial change in the Temporal proposal. See:
https://github.com/tc39/proposal-temporal/commit/9bb84b2
2025-01-17 10:08:06 +01:00