Commit Graph

3918 Commits

Author SHA1 Message Date
Jonne Ransijn
201d36665b LibJS: Remember the position into the cached indices
There is no need to do a full linear search from start to end when
we can just remember the position and continue where we left off.

(cherry picked from commit f4e24762846cfb7a98054f700319d940173086bb)
2024-11-11 10:11:22 -05:00
Andreas Kling
e9f9716ef6 LibJS: Parse dates like "Tuesday, October 29, 2024, 18:00 UTC"
This format is used on https://jetbrains.com/

(cherry picked from commit 3180df3337cc319cdc30b33b70a19b3aafa5642b)
2024-11-11 10:11:22 -05:00
Andreas Kling
37c9b1ce7b LibJS: Store RegExp flags as a bitmask
This avoids having to do O(n) contains() in the various flag accessors.

Yields a ~20% speed-up on the following microbenchmark:

    const re = /foo/dgimsvy;
    for (let i = 0; i < 1_000_000; ++i)
        re.flags;

(cherry picked from commit 257ebea3645ab709be4a984100cc6478b289d0e6)
2024-11-11 10:11:22 -05:00
Jonne Ransijn
c1acf77d6b LibJS: Add HashMap for finding Bindings by name
`find_binding_and_index` was doing a linear search, and while most
environments are small, websites using JavaScript bundlers can have
functions with very large environments, like youtube.com, which has
environments with over 13K bindings, causing environment lookups to
take a noticeable amount of time, showing up high while profiling.

Adding a HashMap significantly increases performance on such websites.

(cherry picked from commit 78ecde9923e954e8ae9bb8d7a8ceefc08a8130ae)
2024-11-11 10:11:22 -05:00
Timothy Flynn
68940f0d37 LibJS: Update spec numbers for the Iterator Helpers proposal
This proposal has reached stage 4 and was merged into the ECMA-262 spec.
See: https://github.com/tc39/ecma262/commit/961f269

(cherry picked from commit 84ad36de0692b8890a2aa7ab66ed4d679cf630c8;
amended to replace one ASSERT() with VERIFY())
2024-11-11 10:11:22 -05:00
Timothy Flynn
391797ca52 LibJS: Close iterator records inside the Iterator{Next,Step} AOs
This is an editorial change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/c4c55b6

(cherry picked from commit 896c2e2f0f08d20770e63055225b627cd4969241)
2024-11-11 10:11:22 -05:00
Timothy Flynn
c2d206a9e0 LibJS: Update spec numbers for the Promise.try proposal
This proposal has reached stage 4 and was merged into the ECMA-262 spec.
See: https://github.com/tc39/ecma262/commit/d72630f

(cherry picked from commit 3aca12d2fadca1628a4dd2f800050b4e54194d65)
2024-11-11 10:11:22 -05:00
Shannon Booth
7816e173fa LibJS: Update comments for WrappedFunction [[Call]] implementation
(cherry picked from commit 01c2ecf355868f7c8d3d757488e7d20b039fcc61)
2024-11-11 09:14:29 -05:00
Shannon Booth
4696edae82 LibJS: Return void from SetDefaultGlobalBindings
Aligning with spec change:

https://github.com/tc39/ecma262/commit/052def
(cherry picked from commit b5536db915623908f2f7488ab32793ba8f4e2b31)
2024-11-11 09:14:29 -05:00
Shannon Booth
70bc70acb0 LibJS: Inline somes AO's into InitializeHostDefinedRealm
Aligning with the editorial change in the spec of:

https://github.com/tc39/ecma262/commit/977a6c
(cherry picked from commit 0a1c9e4038dddbe0078e7c0ef82d8374b928bde1)
2024-11-11 09:14:29 -05:00
Shannon Booth
ab6418f5a0 LibJS: Allow host to create ShadowRealm global object
This implements the proposed update to the ShadowRealm proposal for
integrating the ShadowRealm specification into the web platform.

(cherry picked from commit d1fc76bffdafe5a057c0da5855d9d643608bd726)
2024-11-11 09:14:29 -05:00
Shannon Booth
108ffa8eee LibJS: Initialize ShadowRealm internal slots through setters
This allows us to align our implementation in the same order as the
specification.

No functional change with the current implementation of this AO.

However, this change is required in order to correctly implement a
proposed update of the shadow realm proposal for integration with
the HTML spec host bindings in order to give the ShadowRealm
object the correct 'intrinsic' realm.

This is due to that proposed change adding a step which manipulates the
currently executing Javascript execution context, making the ordering
important.

(cherry picked from commit 0ec8af5b70702e9ee2edc7269c103fa49e6987c1)
2024-11-11 09:14:29 -05:00
Andreas Kling
3590a94fc4 LibJS: Don't leak class field initializers
We were storing these in Handle (strong GC roots) hanging off of
ECMAScriptFunctionObject which effectively turned into world leaks.

(cherry picked from commit 5aa1d7837fe37dd203763178df3325ff8b24abbd)
2024-11-10 19:39:05 -05:00
Shannon Booth
23ff912009 LibJS: Allow unpaired surrogates in String.prototype.replace
This was resulting in a crash for the WPT test case:

https://wpt.live/xhr/send-data-string-invalid-unicode.any.html
(cherry picked from commit e02ca0480f7d39ff79fde59df024df9b53fe945e)
2024-11-10 19:39:05 -05:00
Shannon Booth
fdeeac157c LibJS: Implement Error.isError
Implementing the stage 2.7 proposal:

https://github.com/tc39/proposal-is-error
(cherry picked from commit e4891af9709c7f604a5118c341f99bc9f19d72a9)
2024-11-10 19:39:05 -05:00
Gasim Gasimzada
696021e252 LibJS: Set configurable toStringTag property for console
(cherry picked from commit c5b8e75204cb1603e2470e6cfeee3f2161a49b91)
2024-11-10 18:24:10 -05:00
Andreas Kling
33bfcc467b LibJS: Don't copy current program counter into new execution contexts
This didn't make any sense, and was already handled by pushing a new
execution context anyway.

By simply removing these bogus lines of code, we fix a bug where
throwing inside a function whose bytecode was shorter than the calling
function would crash trying to generate an Error stack trace (because
the bytecode offset we were trying to symbolicate was actually from
the longer caller function, and not valid in the callee function.)

This makes --log-all-js-exceptions less crash prone and more helpful.

(cherry picked from commit b3f77e47690cfd07058d824ea6f0b652489778bf)
2024-11-09 16:08:01 -05:00
Timothy Flynn
4afa0a1973 LibJS: Use the IteratorStepValue AO in Iterator prototypes
This is an editorial change in the Iterator Helpers proposal. See:
https://github.com/tc39/proposal-iterator-helpers/commit/b4ccc31

(cherry picked from commit e782947a03d00f08fcfb16d4164c9edcd9155caf)
2024-11-09 16:08:01 -05:00
Timothy Flynn
464a0b9756 LibJS: Change generator state enum casing in IteratorHelperPrototype
This is an editorial change in the Iterator Helpers proposal. See:
https://github.com/tc39/proposal-iterator-helpers/commit/f1427ec

(cherry picked from commit 48bef246a0720ae4610b6f9c5dcd42eb8c5b448d)
2024-11-09 16:08:01 -05:00
Shannon Booth
bdb21f3279 LibJS: Use HeapFunction for IteratorHelper
(cherry picked from commit 87d964b2f5e3bb10e05fc7b12d13e153d0ba8b1e)
2024-11-09 07:30:40 -05:00
Gasim Gasimzada
cb77f29de1 LibJS+WebContent: Implement console.table
- Expose table from console object
- Add new Table log level
- Create a JS object that represents table rows and columns
- Print table as HTML using WebContentConsoleClient

(cherry picked from commit 785180dd45ef6dcce4d847e564eca52ed0ad955b)
2024-11-08 22:32:11 -05:00
Timothy Flynn
74186d8135 LibJS: Mark a call to DetachArrayBuffer as infallible
Noticed while looking at the merged ArrayBuffer transfer proposal.

(cherry picked from commit caf1606c9f1b76a9e3a67f381e4d364d0ae14a74)
2024-11-08 07:44:45 -05:00
Timothy Flynn
259a321d66 LibJS: Update spec steps/links for the ArrayBuffer transfer proposal
The proposal reached stage 4 and was merged into the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/44bb0e0

(cherry picked from commit bf3e7d3ac43a16a8183b03c299b88702f493af82)
2024-11-08 07:44:45 -05:00
Gasim Gasimzada
7d4fd29673 LibJS: Set empty prototype for console object
(cherry picked from commit 4a42c97f4d369e24c1cba9b554fdb243b6c8692b)
2024-11-07 23:07:20 -05:00
Shannon Booth
9052e09061 LibJS: Early return from Date string parsing on empty string
Loading Ladybird on Github results in 37 debug logs about being unable
to parse an empty Date string. This log is intended to catch Date
formats we do not support to detect web compatability problems, which
makes this case not particuarly useful to log.

Instead of trying to parse all of the different date formats and
logging that the string is not valid, let's just return NAN immediately.

(cherry picked from commit ee35e93eb23996923db12f39ba17ece61da4e39b)
2024-10-26 14:55:24 -04:00
Andreas Kling
3544236559 LibJS: Cache UTF-16 strings on the VM
We were already caching UTF-8 and byte strings, so let's add a cache
for UTF-16 strings as well. This is particularly profitable whenever we
run regular expressions, since the output of regex execution is a set of
UTF-16 strings.

Note that this is a weak cache like the other JS string caches, meaning
that strings are removed from the cache as they are garbage collected.

This avoids billions of PrimitiveString allocations across a run of WPT,
significantly reducing GC activity.

(cherry picked from commit 206479b2b5fc2641a619eb0d05c1185d869ef844)
2024-10-26 11:39:26 -04:00
stelar7
a14791537c LibJS: Extend supported date string formats
(cherry picked from commit d16414b61e01cdf94fa94cad0fffc3cbe2784e08)
2024-10-26 11:39:14 -04:00
Andreas Kling
7f1a0c027b LibJS: Allow GetById to cache getters
1.25x speed-up on this microbenchmark:

    let o = { get x() { return 1; } };
    for (let i = 0; i < 10_000_000; ++i)
        o.x;

I looked into this because I noticed getter invocation when profiling
long-running WPT tests. We already had the mechanism for non-getter
properties, and the change to support getters turned out to be trivial.

(cherry picked from commit 3c5819a6d27883907237bf8137fd4dc24ed04e72)
2024-10-26 10:47:09 -04:00
Shannon Booth
f02836e8b2 LibJS: Add Value::to_well_formed_string
(cherry picked from commit 2e884ff1404dca582985abfb372817e5276e9c1c)
2024-10-17 20:28:06 -04:00
Timothy Flynn
401dadb685 LibJS: Support date strings of the form "Wed Apr 17 2019 23:08:53""
Seen on https://www.skaping.com/valloire/galibier.

(cherry picked from commit c0102aa818b98d4d608e195837aefdb698540427)
2024-10-15 10:27:27 -04:00
rmg-x
88a240c8d7 LibJS: Add extra date format "d B Y"
This allows date strings like "01 February 2013" to be parsed.
auth0.com also loads now because of this :^)

Add test for date parsing

(cherry picked from commit 179641a297ab0b4bafcce3a6361be2c4ed0c51ea)
2024-10-15 09:30:43 -04:00
Kevin Perdlich
c9fbc6a380 LibJS: Extend supported date string formats
(cherry picked from commit a3472aef2401d6b550207475d60f1d5b336254dd)
2024-10-15 09:00:31 -04:00
Arhcout
2446f7e11a LibJS: Allow date format "YYYY-M-DD"
(cherry picked from commit b4d996680a24e6ecb8d0dc755e1208838ee88601)
2024-10-15 07:49:32 -04:00
Timothy Flynn
6f402210d7 LibJS+LibWeb: Add a custom host hook to log unparsed date strings
This lets us log when our Date.parse implementation was unable to handle
a string found on the web.

(cherry picked from commit 8d6f36f8d6c0aea0253df8c84746f8c99bf79b4d)
2024-10-14 22:33:37 -04:00
Timothy Flynn
04e94ffea7 LibJS: Add "month day, year" support to Date.parse
Used on https://rauchg.com.

(cherry picked from commit 921a9cef621537f3dc1c442828bf26ee0800422d)
2024-10-14 22:33:37 -04:00
kleines Filmröllchen
a3077203fe AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
2024-09-14 13:30:27 +02:00
Andreas Kling
0a42c97866 LibJS: Rename Value::typeof() to Value::typeof_()
This to avoid clashing with the GCC typeof extension, which apparently
confuses clang-format.

(cherry picked from commit 14beda00c9e823dd34da74e7d8fdf46aa57e845c)
2024-07-23 08:53:02 -04:00
Andreas Kling
4a4ee92402 LibJS: Make typeof a lot faster by caching all possible results
The typeof operator has a very small set of possible resulting strings,
so let's make it much faster by caching those strings on the VM.

~8x speed-up on this microbenchmark:

    for (let i = 0; i < 10_000_000; ++i) {
        typeof i;
    }

(cherry picked from commit d0b11af3876a64e6b254b5fc3f474d9bbe552024)
2024-07-23 08:53:02 -04:00
Timothy Flynn
582305fdc3 LibJS: Implement Iterator.prototype.constructor according to spec
The spec allows setting a constructor on non built-in Iterator objects.

This is a normative change in the Iterator Helpers proposal. See:
https://github.com/tc39/proposal-iterator-helpers/commit/30b3501

(cherry picked from commit fb228a3d850eb5e4b06550823755719a377b41e6)
2024-07-21 14:54:16 -04:00
Timothy Flynn
978d3331fa LibJS: Implement Iterator.prototype [ @@toStringTag ] according to spec
The spec allows setting the prototype on non built-in Iterator objects.

This is a normative change in the Iterator Helpers proposal. See:
https://github.com/tc39/proposal-iterator-helpers/commit/30b3501

(cherry picked from commit 734e37442db4419b58228e25702bfe176e52f5e3)
2024-07-21 14:54:16 -04:00
Timothy Flynn
258e9335ef LibJS: Create exception messages as Strings
The JS::Error types all store their exception messages as a String. So
by using ByteString, we hit the StringView constructor, and end up
allocating the same string twice.

(cherry picked from commit c3f8202d0ca7761caaabf0af5f413dc25337801f)
2024-07-21 13:11:01 -04:00
Timothy Flynn
3f8b94b131 LibJS: Update specification steps for the Set Methods proposal
It is now Stage 4 and has been merged into the main ECMA-262 spec:
https://github.com/tc39/ecma262/commit/a78d504

(cherry picked from commit 2dbd71d54ba20b3700d3f98001a1cf0ec4adbe25)
2024-07-14 16:45:08 -04:00
Timothy Flynn
0bbf42bca7 LibJS: Introduce the CanonicalizeKeyedCollectionKey AO
This is an editorial change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/30257dd

(cherry picked from commit 55b4ef79157f299e68163824d8d03dfab31dd3d6)
2024-07-14 16:45:08 -04:00
Daniel Bertalan
85b7ce8c2f LibJS: Add missing ValueInlines.h include for Value::to_numeric
When compiling with `-O2 -g1` optimizations (as done in the main
Serenity build), no out-of-line definitions end up emitted for
`Value::to_numeric`, causing files that reference the function but don't
include the definition from `ValueInlines.h` to add an undefined
reference in LibJS.so.
2024-07-07 11:11:02 +02:00
Tim Ledbetter
c98bcd0a10 LibJS: Add the [[Unimplemented]] attribute
Properties marked with the [[Unimplemented]] attribute behave as normal
but invoke the `VM::on_unimplemented_property_access callback` when
they are accessed.

(cherry picked from commit 88d425f32b3b49d5dfa8d86e6e4e2c263cd450d4)
2024-06-26 16:34:37 +02:00
Daniel Bertalan
8d2a8dbb8b Everywhere: Write dtors for types with incomplete members out-of-line
These are rejected by Clang (19) trunk as a result of
https://github.com/llvm/llvm-project/pull/77753.

(cherry picked from commit bf1f631f257e90e91b0b45a6454d731b4b98914c)
2024-06-25 17:42:49 +02:00
Ali Mohammad Pur
1c31dbd110 LibJS: Make emsdk's clang happy 2024-06-19 15:45:02 +02:00
Andreas Kling
a48fc971c6 LibJS: Rearrange ExecutionContext members to shrink the class
Just a minor tweak to make the class 8 bytes smaller.
2024-05-31 16:31:33 +02:00
Andreas Kling
a3782782fa LibJS: Remove two unused members from ExecutionContext 2024-05-31 16:31:33 +02:00
Matthew Olsson
9ea6ab0ad4 LibJS+LibWeb: Fix a ton of JS_CELL-like macro issues 2024-05-30 09:29:20 -06:00