Commit Graph

5396 Commits

Author SHA1 Message Date
Andreas Kling
5cd1016714 LibJS: Add RawNonnullGCPtr<T>
This is really just a type alias for NonnullGCPtr<T>, but it provides
a way to have non-owning non-visited NonnullGCPtr<T> without getting
yelled at by the Clang plugin for catching GC errors.

(cherry picked from commit 6a6618f5eab6e6a2c7c3fc03f8063cc6b497a0ec)
2024-11-11 17:22:05 -05:00
Andreas Kling
3d36c75eee LibJS: Use correct cell address for HeapFunction captures in GC dumps
We were previously dumping the address of the cell pointer instead of
the address of the cell itself. This was causing mysterious orphans
in GC dumps, and it took me way too long to figure this out.

(cherry picked from commit e240084437ea0bfe03d83dc3533d4ee6214b7206)
2024-11-11 17:22:05 -05:00
Luke Wilde
c7f707afa6 LibJS: Allow division after IdentifierNames in optional chain
The following syntax is valid:
```js
e?.example / 1.2
```

Previously, the `/` would be treated as a unterminated regex literal,
because it was calling the regular `consume` instead of
`consume_and_allow_division`.

This is what is done when parsing IdentifierNames in
parse_secondary_expression when a period is encountered.

Allows us to parse clients-main-[hash].js on https://ubereats.com/

(cherry picked from commit bd4c29322c945647c52ff4d8045c7529f8152b08)
2024-11-11 17:22:05 -05:00
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
Christoffer Sandberg
e40ddaff92 LibJS: Count code-points instead of bytes for syntax highlight
This fixes issue #1847, a crash on view-source
for https://chalmers.se

(cherry picked from commit 84c881fc66975bdbfc8fa6d139bc38f6ec37005b)
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
samu698
980de1b160 LibJS: Don't generate useless jumps for if statement
If statements without an else clause generated jumps to the next
instruction, this commit fixes the if statement generation so that it
dosen't produce them anymore.

This is an example of JS code that generates the useless jumps
(a => if(a){}) ();

(cherry picked from commit 7865fbfe6d04a79a253a38eaec5c21c2bde110b5)
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
16473663ea LibJS: Don't infinite loop on unknown console.log formatting specifiers
(cherry picked from commit ef9208047dc8770f6263b483d7a442df703bc42b)
2024-11-10 10:46:01 -05:00
Sam Atkins
d727545a1f LibJS: Update wording from Console spec
https://github.com/whatwg/console/pull/240 is an editorial change to use
the term "implementation-defined" more consistently. This seems to be
the only instance in the spec text which we quote verbatim.

(cherry picked from commit 51f82c1d939dd28a3e719d7fa495cf9f30d0921c)
2024-11-10 10:46:01 -05:00
Aliaksandr Kalenik
6f7297446a LibJS: Reset in_formal_parameter_context after entering a new function
Fixes a bug when "'Await' expression is not allowed in formal parameters
of an async function" is thrown for "await" encountered in a function
definition assigned to a default function parameter.

Fixes loading of https://excalidraw.com/

(cherry picked from commit 10064d0e1a89a4f48dc1e896de35a65f2ab946f4)
2024-11-09 16:08:01 -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
Andreas Kling
c4a11363dc LibJS: Fix mix-up when re-exporting an imported symbol with a new name
This makes https://cling.com/ load, and more of the animated elements
on https://shopify.com/ start appearing.

(cherry picked from commit 0f9444fa06031e7d8e3c1ad36e701090e0b17ec1)
2024-11-09 07:29:52 -05:00
Andreas Kling
0e13e00d6a LibJS: Use the system native page size as the HeapBlock::block_size
Before this change, we were hard-coding 4 KiB. This meant that systems
with a 16 KiB native page size were wasting 12 KiB per HeapBlock on
nothing, leading to worse locality and more mmap/madvise churn.

We now query the system page size on startup and use that as the
HeapBlock size.

The only downside here is that some of the pointer math for finding the
base of a HeapBlock now has to use a runtime computed value instead of a
compile time constant. But that's a small price to pay for what we get.

(cherry picked from commit a6bf253602702c052453d5ccb45a40d8fbb368ba)
2024-11-09 07:29:52 -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
7c6bb5bd77 LibJS: Update spec link to the hashbang comment syntax
The proposal reached stage 4 and was merged into the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/2006dea

(cherry picked from commit 9f1517492cc85c5f12cb52436dc72ec21e594b7a)
2024-11-08 07:44:45 -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
Gasim Gasimzada
186c66bab9 LibJS: Treat passing undefined as no argument for console labels
- Affects time, timeLog, timeEnd, count, and countReset functions

(cherry picked from commit 8545756d17799aaf3dec9b3b46caa3b9b74c0d9f)
2024-11-07 21:52:13 -05:00
Daniel La Rocque
7af4d382da LibJS: Improve deep equals algorithm in tests
The `deepEquals` algorithm used for testing was naive, and incorrectly
evaluated equality of objects in some cases. The new algorithm considers
that the second object could have more keys than the first, and compares
the prototypes of the objects.

(cherry picked from commit cb629e18bbcb8f5a6c6fd535e290a34da7a5cfb6)
2024-11-07 20:29:07 -05:00
Andrew Kaster
5182adab7e LibJS+ClangPlugins: Add escape hatch for GCPtr checks
(cherry picked from commit f314f58fca04ac8246fcdacd47f4a3829d3c6e01)
2024-11-01 18:41:49 -04:00
Andreas Kling
ebc4aed930 LibJS: Remember arrow function parsing failures by offset
We don't need to remember these by (line, column, offset). Just the
offset should be enough.

(cherry picked from commit 2e06d26ddb0c13b8c90933e619876281ce8eeab2)
2024-11-01 13:26:26 -04:00
Andreas Kling
bb0a56c0be LibJS: Remove unused field Token::m_filename
(cherry picked from commit d5a0bb91590a6f76be6ad859a1e905d79cd5eeb8)
2024-11-01 13:26:26 -04:00
Andreas Kling
5e031f91bc LibJS: Make JS lexer handle 2 and 3 character tokens faster
By checking the lengths and then looking directly at the bytes, the
generated code becomes a lot nicer.

This gives a 1.23x speedup when parsing the JS from x.com

(cherry picked from commit 93a4d7395f60e25f5eba2103fa562d0278a91a9a)
2024-11-01 13:26:26 -04:00
Sam Atkins
934fe3c32c LibJS: Update console spec's use of "Type()" -> "is a"
Corresponds to the change in this PR:
https://github.com/whatwg/console/pull/241

(cherry picked from commit 99c66f49fb35b8415e13d3bef638487fb8c7238f)
2024-11-01 05:10:51 -04: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
Bastian Neumann
ee440daa58 LibJS: Do not print large arrays
Printing the whole array causes wpt
console/console-log-large-array.any.html to crash.
This limits logged arrays to 100 elements and
truncates the rest with ...

(cherry picked from commit 9650cf8b15a941aaf71c8a4d7db6ee899e367cbd)
2024-10-26 10:47:30 -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