Commit graph

4556 commits

Author SHA1 Message Date
Aliaksandr Kalenik
d978c762bc LibJS: Remove usage of bytecode_interpreter_if_exists()
There is no need to check if bytecode interpreter exists after we
switched away from AST interpreter.
2023-08-12 08:46:35 +02:00
Andreas Kling
a0bceeb704 LibJS: Remove unused VM::destructuring_assignment_evaluation() 2023-08-10 16:36:18 +02:00
Andreas Kling
0ff9992ea1 LibJS: Remove now-unused mutable caches from AST nodes
The Identifier and TaggedTemplateLiteral AST nodes had caches that were
only used by the AST interpreter.
2023-08-10 16:36:18 +02:00
Andreas Kling
f49c5ca553 LibJS: Fix most clang-tidy warnings in AST.h
Mostly adding a bunch of move() to avoid ref-count churn.
2023-08-10 16:36:18 +02:00
Luke Wilde
ae7a0c43a9 LibJS: Implement await properly for async functions
Fixes #20275

```
Summary:
    Diff Tests:
        +4     -4    

Diff Tests:
    test/built-ins/Array/fromAsync/non-iterable-input-with-thenable
    -async-mapped-awaits-callback-result-once.js  -> 
    test/language/expressions/await/async-await-interleaved.js  -> 
    test/language/expressions/await/await-awaits-thenables-that-
    throw.js  -> 
    test/language/expressions/await/await-awaits-thenables.js  -> 
```
2023-08-10 05:12:07 +02:00
Timothy Flynn
375a6f5dd9 LibJS: Remove bytecode condition from tests expected to fail 2023-08-09 20:47:44 +01:00
Timothy Flynn
854330ec73 LibJS: Mark a test-js test as always passing
This passes in bytecode mode, which is now the only mode.
2023-08-09 20:47:44 +01:00
flofriday
a2abc5b824 LibJS: Improve garbage collection trigger condition
This patch triggers the collector when allocated memory doubles instead
of every 100k allocations. Which can almost half (reduce by ~48%) the
time spent on collection when loading google-maps.

This dynamic approach is inspired by some other GCs like Golang's and
Lua's and improves performance in memory heavy applications because
marking must visit old objects which will dominate the marking phase if
the GC is invoked too often.

This commit also improves the Octane Splay benchmark and almost
doubles it :^)
2023-08-09 18:32:19 +02:00
Andreas Kling
97ebfd9f0f LibJS: Make Value::to_string_without_side_effects() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
b8f78c0adc LibJS: Make JS::number_to_string() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
09547ec975 LibJS: Make PrimitiveString::deprecated_string() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
c084269e5f LibJS: Make PrimitiveString::utf8_string() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
7849950383 LibJS: Make Utf16String & related APIs infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
9708b86d65 LibJS: Make PrimitiveString::resolve_rope_if_needed() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Andreas Kling
1a27c525d5 LibJS: Make PrimitiveString::create() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Daniel Bertalan
fb305b66c2 LibJS: Enable await test that used to crash in AST mode
Now that the AST interpreter has been removed, this can be a simple
XFAIL.
2023-08-08 15:09:53 +02:00
Daniel Bertalan
7ac6af1998 LibJS: Uncomment passing tests 2023-08-08 15:09:53 +02:00
Sam Kravitz
c97eec030c LibJS: Test function toBeCloseTo takes an optional precision argument
Modeled after the equivalent Jest function.
https://jestjs.io/docs/expect#tobeclosetonumber-numdigits
2023-08-08 13:29:56 +02:00
Sam Kravitz
73c8650ea0 LibJS: Expect this.target to have typeof number in toBeCloseTo
The previous expectation of typeof value was inconsistent with the
expect message.
2023-08-08 13:29:56 +02:00
Andreas Kling
2eaa528a0e LibJS: Rip out the AST interpreter :^)
This has been superseded by the bytecode VM, which is both faster
and more capable.
2023-08-08 13:07:13 +02:00
Andreas Kling
e2c8d5859e LibJS: Remove ability to disable bytecode VM 2023-08-08 13:07:13 +02:00
Andreas Kling
9df7bf79cc LibJS: Add create_simple_execution_context<GlobalObjectType>() helper
This makes it easy to set up a realm, global object and root execution
context with a single call to LibJS. It will be useful to basically
everyone except LibWeb.
2023-08-08 13:07:13 +02:00
Andreas Kling
d1d24569f8 LibJS/Bytecode: Remove unused AST interpreter hacks from bytecode VM 2023-08-08 13:07:13 +02:00
Sam Kravitz
073eb46824 LibJS: Apply the correct precedence for unary + and - operators
When determining the precedence of the + and - operators, the parser
always returned the precedence using these operators in a binary
expression (lower than division!). The context of whether the operator
is used in a unary or binary expression must be taken into account.
2023-08-08 07:41:07 +02:00
Andreas Kling
18c54d8d40 LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs.

Work towards #20405
2023-08-08 07:39:11 +02:00
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Daniel Bertalan
66645cdc94 LibJS+LibWeb: Mark NonnullGCPtr::ptr() as returns_nonnull
This invariant is enforced by the fact that `NonnullGCPtr` can only be
constructed from references.

This commit fixes an instance where we compared a pointer to null after
we have already dereferenced it.
2023-08-07 22:20:03 -04:00
Daniel Bertalan
9feb1ce39f LibJS+LibWeb: Apply the Rule of Zero to {Nonnull,}GCPtr<T>
The compiler-generated copy constructor and copy assignment operator
already do the right thing (which is to simply copy the underlying
pointer).

The [Itanium C++ ABI][1] treats any class with non-trivial copy/move
constructors and destructors as non-trivial for the purposes of calls --
even if they are functionally identical to the compiler-generated ones.
If a class is non-trivial, it cannot be passed or returned in registers,
only via an invisible reference, which is worse for codegen. This commit
makes `{Nonnull,}GCPtr` trivial.

As the compiler can be sure that capturing a `GCPtr` by value has no
side effects, a few `-Wunused-lambda-capture` warnings had to be
addressed in LibWeb.

GCC seems to have a bug that prevents `ExceptionOr<Variant<GCPtr<T>>>`
from being implicitly constructed from `GCPtr<T>` after this change. A
non-invasive workaround is to explicitly construct the inner Variant
type.

[1]: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial
2023-08-07 22:20:03 -04:00
Andreas Kling
34344120f2 AK: Make "foo"_string infallible
Stop worrying about tiny OOMs.

Work towards #20405.
2023-08-07 16:03:27 +02:00
Hediadyoin1
50bf303edd LibJS: Capture UnrealizedSourceRanges in ExecutionContext, not ASTNodes
This loosens the connection to the AST interpreter and will allow us to
generate SourceRanges for the Bytecode interpreter in the future as well

Moves UnrealizedSourceRanges from TracebackFrame to the JS namespace for
this
2023-08-05 06:39:06 +02:00
Andreas Kling
e91bdedc93 LibJS: Use correct this value when callee is a with binding
If we're inside of a `with` statement scope, we have to take care to
extract the correct `this` value for use in calls when calling a method
on the binding object via an Identifier instead of a MemberExpression.

This makes Vue.js work way better in the bytecode VM. :^)

Also, 1 new pass on test262.
2023-08-01 16:08:21 +02:00
Shannon Booth
378595e8b1 LibJS: Add three more await thenable tests
The first test crashes in AST, and fails in bytecode, so the best thing
which we can do here without complicated test setup logic is to just
skip this test for now. Interestinglny, this crashing test is very
similar to the existing thenable test case, and only differs in the way
that the thenable is given to the async function.

The next two tests are effectively the same as the above two mentioned
tests, with the only different being that the thenable calls the fulfill
function. For the test case that crashes in AST mode, doing that appears
to fix the test case for AST mode (but both still fail in bytecode).
2023-07-30 09:31:16 +02:00
Aliaksandr Kalenik
2bdc69c42c LibJS: Add caching of this value in ResolveThisBinding instruction
Because "this" value cannot be changed during function execution it is
safe to compute it once and then use for future access.

This optimization makes ai-astar.js run 8% faster.
2023-07-29 04:23:49 +02:00
Shannon Booth
d766014787 LibJS/Tests: Set failing bytecode tests as xfail when in bytecode mode
This should allow us to enable running test-js in bytecode mode in CI.
2023-07-23 07:36:13 +02:00
Shannon Booth
9b66e87bd8 LibJS/Tests: Run 'delete always evaluates the lhs' in bytecode mode
As this test passes for bytecode, but fails in AST.
2023-07-23 07:36:13 +02:00
Shannon Booth
2401c0ff7e LibJS/Tests: Add support for expected failure (xfail) tests
To allow us to add tests that are failing now, but can be enabled as
soon as a change is made to make it pass (without any opportunity to
forget about enabling it).

Additionally, support is added for `xfailIf`, for tests that are
expected to fail given a certain condition, but are expected to pass
otherwise. This is intended to be used for tests that fail in bytecode
mode, but pass in AST (and vice versa).
2023-07-23 07:36:13 +02:00
Timothy Flynn
8b23bbf58e LibJS: Read properties from the Intl.DateTimeFormat options object once
This is a normative change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/02bd03a

This is observable just due to reading the properties one less time. It
would have been possible for e.g. the property values to change between
those invocations.
2023-07-22 10:18:55 +02:00
Timothy Flynn
3a4cdf77ba LibJS: Move Intl.DateTimeFormat creation to CreateDateTimeFormat AO
This is an editorial change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/b6ed64b
https://github.com/tc39/ecma402/commit/6e3b70d

This moves Intl.DateTimeFormat creation to InitializeDateTimeFormat and
renames that AO to CreateDateTimeFormat.
2023-07-22 10:18:55 +02:00
Timothy Flynn
ea774111e8 LibJS: Raise the upper minimum/maximum fraction digit limit to 100
This is a normative change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/f6d2945
2023-07-22 10:18:55 +02:00
Andreas Kling
1768d70823 Revert "LibJS: Remove "uprooting" mechanism from garbage collector"
This reverts commit 6232ad3a0d.

Unfortunately this introduced some flakiness on CI, so it wasn't
quite this simple.
2023-07-22 06:53:26 +02:00
Andreas Kling
9f06e130a2 LibJS/Bytecode: Keep saved return value in call frame register
This fixes an issue where returning inside a `try` block and then
calling a function inside `finally` would clobber the saved return
value from the `try` block.

Note that we didn't need to change the base of register allocation,
since it was already 1 too high.

With this fixed, https://microsoft.com/edge loads in bytecode mode. :^)

Thanks to Luke for reducing the issue!
2023-07-21 19:15:33 +02:00
Timothy Flynn
77d7f715e3 LibJS+CI: Remove bytecode optimization passes for now
These passes have not been shown to actually optimize any JS, and tests
have become very flaky with optimizations enabled. Until some measurable
benefit is shown, remove the optimization passes to reduce overhead of
maintaining bytecode operations and to reduce CI churn. The framework
for optimizations will live on in git history, and can be restored once
proven useful.
2023-07-21 19:47:36 +03:30
Andreas Kling
6232ad3a0d LibJS: Remove "uprooting" mechanism from garbage collector
The Heap::uproot_cell() API was used to implement markAsGarbage() which
was used in 3 tests to forcibly destroy a value, even if it had
references on the stack or elsewhere.

This patch rewrites the 3 tests that used this mechanism to be
structured in a way that allows garbage collection to collect the values
as intended without hacks. And now that the uprooting mechanism is no
longer needed, it's uprooted as well.

This fixes 3 test-js tests in bytecode mode. :^)
2023-07-21 14:14:00 +02:00
Andreas Kling
9054b1bc14 LibJS: Always taint parsing environment on call to eval()
We had an edge case where calls to eval() left the environment untainted
*if* `eval` had also been declared as a local variable in the same
parsing context.

This broke the expected direct eval behavior when the variable `eval`
was still pointing at the global `eval` function.

This patch fixes the issue by simply always tainting the environment
when a call to something named `eval` is encountered. It doesn't seem
worth worrying about optimizing the case where someone is calling their
own function named `eval`..

Fixes 1 test-js test in bytecode mode. :^)
2023-07-21 14:14:00 +02:00
Andreas Kling
c90bf22d29 LibJS/Bytecode: Use primitive this for strict mode GetByValue
GetByValue now shares code with GetById to elide the synthetic wrapper
objects for primitive values in strict mode.

Fixes 2 test-js tests in bytecode mode. :^)
2023-07-21 14:14:00 +02:00
Andreas Kling
7253d021fc LibJS/Bytecode: Factor out determining the base object from GetById
This will allow us to use the same logic in GetByValue (in a subsequent
commit.)
2023-07-21 14:14:00 +02:00
Andreas Kling
6de22ec789 LibJS/Bytecode: Rename RegisterWindow to CallFrame
This is a better name for what it actually represents.
2023-07-21 14:14:00 +02:00
MacDue
17a5af04e3 LibJS: Actually generate the bytecode CFG
This is just something I spotted looking around the code, previously
the PassPipelineExecutable was passed by value to
generate_cfg_for_block, which generated the CFG then just dropped it on
the floor. Making this a reference results in the CFG actually getting
generated.
2023-07-21 06:59:51 +02:00
Aliaksandr Kalenik
fb94415f03 LibJS: Delete Declaration::for_each_var_declared_name
1. Replaces for_each_var_declared_name usage with more generic
for_each_var_declared_identifier.
2. Deletes for_each_var_declared_name.
2023-07-20 20:19:15 +02:00
Aliaksandr Kalenik
0fa47405df LibJS: Delete Declaration::for_each_lexically_declared_name
1. Replaces for_each_lexically_declared_name usage with more generic
for_each_lexically_declared_identifier.
2. Deletes for_each_lexically_declared_name.
2023-07-20 20:19:15 +02:00