Commit graph

1219 commits

Author SHA1 Message Date
Timothy Flynn
ca0d926036 LibJS: Use decimal compact patterns for currency style sub-patterns
When formatting a currency style pattern with compact notation, we were
(trying to) doubly insert the currency symbol into the formatted string.
We would first look up the currency pattern in GetNumberFormatPattern
(for the en locale, this is "¤#,##0.00", which our generator transforms
to "{currency}{number}").

When we hit the "{number}" field, NumberFormat will do a second lookup
for the compact pattern to use for the number being formatted. By using
the currency compact patterns, we receive a second pattern that also has
the currency symbol (for the en locale, if formatting the number 1000,
this is "¤0K", which our generator transforms to
"{currency}{number}{compactIdentifier:0}". This second lookup is not
supposed to have currency symbols (or any other symbols), thus we hit a
VERIFY_NOT_REACHED().

Instead, we are meant to use the decimal compact pattern, and allow the
currency symbol to be handled by only the outer currency pattern.
2023-09-04 18:22:28 +02:00
Andreas Kling
1c06111cbd LibJS: Add file & line number to bytecode VM stack traces :^)
This works by adding source start/end offset to every bytecode
instruction. In the future we can make this more efficient by keeping
a map of bytecode ranges to source ranges in the Executable instead,
but let's just get traces working first.

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2023-09-02 15:37:53 +02:00
Luke Wilde
2aaae6fc70 LibJS: Avoid ToPropertyKey for spreading in PutByValue(WithThis)
This is not we're supposed to do according to https://tc39.es/ecma262/#sec-runtime-semantics-propertydefinitionevaluation
Furthermore, this was observable by ToPrimitive looking up toString and
valueOf and potentially calling them if they exist. The big ticket
issue however is that for objects without toString and valueOf, such as
null-proto objects, this would unexpectedly throw.
2023-08-29 21:38:54 -04:00
Luke Wilde
3ceedbd16a LibJS: Allow assignment expression in spreading property definition
See: https://tc39.es/ecma262/#sec-runtime-semantics-propertydefinitionevaluation
PropertyDefinition : ... AssignmentExpression
Also add a test for this in array spreading, which already had this in
place.
2023-08-29 18:46:01 -04:00
Andreas Kling
9d6f00d918 LibJS: Behave like major engines when substituting missing capture group
When a substitution refers to a 2-digit capture group that doesn't exist
we need to check if the first digit refers to an existing capture group.
In other words, '$10' should be treated as capture group #1, followed by
the literal '0' if 1 is a valid capture group but 10 is not.

This makes the Dromaeo "dom-query" subtest run to completion.
2023-08-29 10:33:48 +02:00
Shannon Booth
9b884a9605 LibJS: Avoid double construction in Array.fromAsync
This is a normative change in the array from async proposal, see:

https://github.com/tc39/proposal-array-from-async/commit/49cfde2

It fixes a double construction when Array.fromAsync is given an array
like object.
2023-08-28 20:45:11 -04:00
Timothy Flynn
b7676cc436 LibJS: Disable Temporal custom time zone test
This test has been flaky for quite some time. Disable it for now, and
revisit once we've caught up with the Temporal spec.
2023-08-27 15:26:40 -04: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
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
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
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
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
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
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
Timothy Flynn
31e555aaa5 LibJS: Disallow negative set record sizes
This is a normative change in the Set Methods proposal. See:
https://github.com/tc39/proposal-set-methods/commit/4155e6e
2023-07-18 12:31:10 +01:00
Shannon Booth
016b31fae2 LibJS/Tests: Add a test for an async function which returns a thenable
This test passes when running in the AST interpreter, but fails when
running for bytecode.
2023-07-17 12:33:01 +01:00
Timothy Flynn
0e63d04a35 LibJS: Implement %IteratorHelperPrototype%.return 2023-07-16 23:56:55 +01:00
Florian Stellbrink
d4d7550588 LibJS/Tests: Test splice at non zero index 2023-07-16 17:13:44 +01:00
Shannon Booth
ba758e9f4d LibJS/Tests: Add some basic tests for Array.fromAsync 2023-07-16 14:56:10 +01:00
Luke Wilde
e86d7cab06 LibJS: Don't crash on broken promises in AsyncGenerator#return
See: https://github.com/tc39/ecma262/pull/2683
2023-07-15 01:08:52 +02:00
Luke Wilde
d1cb78c411 LibJS/Bytecode: Implement async generators 2023-07-15 01:08:52 +02:00
Timothy Flynn
36d156428b LibJS: Implement the Promise.withResolvers proposal
https://github.com/tc39/proposal-promise-with-resolvers
2023-07-13 00:02:19 +02:00
Timothy Flynn
705e96568c LibJS: Change error message for non-objects in GetIteratorFlattenable
Matches other usages in e.g. Temporal now.
2023-07-12 23:57:41 +02:00
Timothy Flynn
ff4e0d2943 LibJS: Avoid creating String object wrappers in iterator helpers
This is a normative change in the Iterator Helpers spec. See:
https://github.com/tc39/proposal-iterator-helpers/commit/3e275cf
2023-07-12 23:26:51 +02:00
Linus Groh
419e710c1c LibJS: Re-implement the Array Grouping proposal as static methods
Closes #19495.
2023-07-12 00:03:54 +02:00
Andreas Kling
cf6792ec40 LibJS/Bytecode: Invalidate inline caches on unique shape mutation
Since we can't rely on shape identity (i.e its pointer address) for
unique shapes, give them a serial number that increments whenever a
mutation occurs.

Inline caches can then compare this serial number against what they
have seen before.
2023-07-11 00:14:50 +02:00
Aliaksandr Kalenik
2f85faef0f LibJS: Fix scope detection for ids in default function params
This change fixes an issue where identifiers used in default function
parameters were being "registered" in the function's parent scope
instead of its own scope. This bug resulted in incorrectly detected
local variables. (Variables used in the default function parameter
expression should be considered 'captured by nested function'.)

To resolve this issue, the function scope is now created before parsing
function parameters. Since function parameters can no longer be passed
in the constructor, a setter function has been introduced to set them
later, when they are ready.
2023-07-08 14:03:12 +02:00
Timothy Flynn
2b19d1b5ab LibJS: Do not coerce nullish references to unresolvable references
These are not strictly unresolvable references. Treating them as such
fails an assertion in the `delete UnaryExpression` semantic (which is
Reference::delete_ in our implementation) - we enter the unresolvable,
branch, which then asserts that the [[Strict]] slot of the reference is
false.
2023-07-06 21:36:13 +01:00
Daniel Bertalan
d165590809 LibJS/Bytecode: Do not coerce the receiver to Object for internal_set
This makes the behavior of `Symbol` correct in strict mode, wherein if
the receiver is a symbol primitive, assigning new properties should
throw a TypeError.
2023-07-02 22:08:48 +01:00
Daniel Bertalan
0cd85ab0fc AK+LibJS: Make Number.MIN_VALUE a denormal
ECMA-262 implies that `MIN_VALUE` should be a denormalized value if
denormal arithmetic is supported. This is the case on x86-64 and AArch64
using standard GCC/Clang compilation settings.

test262 checks whether `Number.MIN_VALUE / 2.0` is equal to 0, which
only holds if `MIN_VALUE` is the smallest denormalized value.

This commit renames the existing `NumericLimits<FloatingPoint>::min()`
to `min_normal()` and adds a `min_denormal()` method to force users to
explicitly think about which one is appropriate for their use case. We
shouldn't follow the STL's confusingly designed interface in this
regard.
2023-07-02 21:19:09 +01:00
Shannon Booth
3781948f0c LibJS: Add initial implementation for SharedArrayBuffer
None of the actual sharing is implemented yet, but this is enough for
most basic functionality.

Diff Tests:
    +260     -262    +2 💀
2023-07-01 16:55:17 +01:00
Daniel Bertalan
96b197ef46 LibJS/Temporal: Perform floating point arithmetic in RoundTime
The valid range for temporal values (`nsMinInstant`/`nsMaxInstant`)
means performing nanosecond-valued integers could lead to an overflow.

NB: Only the `roundingMode: "day"` case was affected, as all others were
already performing the division on floating-point `fractional_second`
values. I'm adding `.0` suffixes everywhere to make this fact clearer.

This adds a few local tests as well, as those are tested with sanitizers
enabled by default, unlike test262.
2023-07-01 06:51:25 +02:00
Shannon Booth
be280ff3e4 LibJS/Tests: Enable some now passing Array length tests
Now that serenity is 64 bit only these tests no longer need to be
skipped :^)
2023-06-28 10:48:15 +02:00
Timothy Flynn
6fb670c1c2 LibJS: Implement Iterator.prototype.find 2023-06-26 10:39:07 +02:00
Timothy Flynn
1f05b0638f LibJS: Implement Iterator.prototype.every 2023-06-26 10:39:07 +02:00
Timothy Flynn
6ac1d5afae LibJS: Implement Iterator.prototype.some 2023-06-26 10:39:07 +02:00
Timothy Flynn
134bb44ca0 LibJS: Implement Iterator.prototype.forEach 2023-06-26 10:39:07 +02:00
Timothy Flynn
35380b2aef LibJS: Implement Iterator.prototype.toArray 2023-06-26 10:39:07 +02:00
Timothy Flynn
acc05480e8 LibJS: Implement Iterator.prototype.reduce 2023-06-26 10:39:07 +02:00
Timothy Flynn
ad42b4ea67 LibJS: Implement Iterator.prototype.flatMap
This prototype is a bit tricky in that we need to maintain the iteration
state of the mapped iterator's inner iterator as we return values to the
caller. To do this, we create a FlatMapIterator helper to perform the
steps that apply to the current iteration state.
2023-06-26 10:39:07 +02:00
Timothy Flynn
67028ee3a3 LibJS: Implement Iterator.prototype.drop 2023-06-26 10:39:07 +02:00