Commit graph

1155 commits

Author SHA1 Message Date
Linus Groh
3709d11212 LibJS: Parse secondary expressions with the original forbidden token set
Instead of passing the continuously merged initial forbidden token set
(with the new additional forbidden tokens from each parsed secondary
expression) to the next call of parse_secondary_expression(), keep a
copy of the original set and use it as the base for parsing the next
secondary expression.

This bug prevented us from properly parsing the following expression:

```js
0 ?? 0 ? 0 : 0 || 0
```

...due to LogicalExpression with LogicalOp::NullishCoalescing returning
both DoubleAmpersand and DoublePipe in its forbidden token set.

The following correct AST is now generated:

Program
  (Children)
    ExpressionStatement
      ConditionalExpression
        (Test)
          LogicalExpression
            NumericLiteral 0
            ??
            NumericLiteral 0
        (Consequent)
          NumericLiteral 0
        (Alternate)
          LogicalExpression
            NumericLiteral 0
            ||
            NumericLiteral 0

An alternate solution I explored was only merging the original forbidden
token set with the one of the last parsed secondary expression which is
then passed to match_secondary_expression(); however that led to an
incorrect AST (note the alternate expression):

Program
  (Children)
    ExpressionStatement
      LogicalExpression
        ConditionalExpression
          (Test)
            LogicalExpression
              NumericLiteral 0
              ??
              NumericLiteral 0
          (Consequent)
            NumericLiteral 0
          (Alternate)
            NumericLiteral 0
        ||
        NumericLiteral 0

Truth be told, I don't know enough about the inner workings of the
parser to fully explain the difference. AFAICT this patch has no
unintended side effects in its current form though.

Fixes #18087.
2023-04-02 06:45:37 +02:00
Hendiadyoin1
b76d3f287f LibJS: Make yy{/,-}mm{/,-}dd hh:mm test timezone independent
Otherwise this will fail in non UTC timezones.
2023-03-23 13:33:03 -04:00
Luke Wilde
f0d0459c3e LibJS: Support the yy{/,-}mm{/,-}dd hh:mm format for Date
Required by a UK news website for loading a Piano configuration.
This is presumably configuration for piano.io Analytics.
2023-03-23 13:38:08 +01:00
Timothy Flynn
24459a44b0 LibJS: Ensure Date tests can pass in any time zone by testing UTC values
When we create a Date object from a timestamp, or set its value by way
of Date.prototype.setTime, the timestamp is interpreted as UTC. Change
test expecatations against such instances to use UTC as well.
2023-03-21 18:05:22 +00:00
Luke Wilde
ddc7bedca6 LibJS: Make int_part a double in StringPrototype::to_string
u64 is not big enough to hold extremely large numbers, such as
4.192938423e+54. This would cause an integer underflow on the radix
index when performing something like `toString(36)` and thus cause an
OOB Array read.
2023-03-01 10:53:31 +01:00
Ali Mohammad Pur
bcfbe0fbf7 LibJS: Manually loop over escaped regex pattern instead of ::replace()
This makes it ever-so-slightly faster, but more importantly, it fixes
the bug where a `/\//` regex's `source` property would return `\\/`
("\\\\/") instead of `\/` due to the existing '/' -> '\/' replace()
call.
2023-02-16 21:03:19 +01:00
Timothy Flynn
5cbf054651 LibUnicode: Fix typos causing text segmentation on mid-word punctuation
For example the words "can't" and "32.3" should not have boundaries
detected on the "'" and "." code points, respectively.

The String test cases fixed here are because "b'ar" is now considered
one word.
2023-02-15 12:36:47 +01:00
Luke Wilde
588dae8aa6 LibJS/Temporal: Allow annotations after YYYY-MM and MM-DD
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/160e836
2023-02-11 18:42:32 +00:00
Timothy Flynn
bb4fda3b97 LibJS: Format the era of ISO year 0 as BC
This is a normative change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/2034315
2023-02-02 12:12:26 +00:00
Timothy Flynn
e74e8381d5 LibJS: Allow "approximately" results to differ in plural form
This is a normative change in the Intl.NumberFormat V3 spec. See:
https://github.com/tc39/proposal-intl-numberformat-v3/commit/08f599b

Note that this didn't seem to actually affect our implementation. The
Unicode spec states:

https://www.unicode.org/reports/tr35/tr35-53/tr35-numbers.html#Plural_Ranges
"If there is no value for a <start,end> pair, the default result is end"

Therefore, our implementation did not have the behavior noted by the
issue this normative change addressed:

    const pr = new Intl.PluralRules("en-US");
    pr.selectRange(1, 1); // Is "other", should be "one"

Our implementation already returned "one" here because there is no such
<start=one, end=one> value in the CLDR for en-US. Thus, we already
returned the end value of "one".
2023-01-30 14:10:07 -05:00
Timothy Flynn
5b3b14be0a LibJS: Move resolution of some Intl.NumberFormat options to a common AO
This is a normative change in the Intl.NumberFormat V3 spec. See:
https://github.com/tc39/proposal-intl-numberformat-v3/commit/29acfc6

This is to allow Intl.PluralRules to use these options, as they were in-
effect required by later AOs anyways.
2023-01-30 12:19:14 -05:00
davidot
6255ca4a42 LibJS: Add DisposableStack{, Prototype, Constructor}
Since the async parts of the spec are not stage 3 at this point we don't
add AsyncDisposableStack.
2023-01-23 09:56:50 +00:00
davidot
bff038411a LibJS: Add using declaration support in for and for of loops
The using declarations have kind of special behavior in for loops so
this is seperated.
2023-01-23 09:56:50 +00:00
davidot
541637e15a LibJS: Add using declaration support, RAII like operation in js
In this patch only top level and not the more complicated for loop using
statements are supported. Also, as noted in the latest meeting of tc39
async parts of the spec are not stage 3 thus not included.
2023-01-23 09:56:50 +00:00
davidot
2c87ff2218 LibJS: Add Symbol.dispose 2023-01-23 09:56:50 +00:00
davidot
3353cf68f1 LibJS: Add SuppressedError{, Prototype, Constructor} 2023-01-23 09:56:50 +00:00
davidot
0d8bab82f0 LibJS: Add custom details to toBe{True, False} shown on failure
Any test with multiple expect(...).toBe{True, False} checks is very hard
to debug.
2023-01-23 09:56:50 +00:00
davidot
fa030d7b9c LibJS: Clarify more errors in test-common
Without a message these just show 'ExpectationError' even if the check
has multiple steps.
2023-01-23 09:56:50 +00:00
Timothy Flynn
d1881da2be LibJS: Set approximate number range format result's "source" to "shared"
This is a normative change in the Intl.NumberFormat v3 spec. See:
https://github.com/tc39/proposal-intl-numberformat-v3/commit/7510e7f
2023-01-14 19:12:48 +00:00
Andreas Kling
7826cb2556 LibJS: Use a work queue instead of the C++ stack for the GC mark phase
This fixes an issue where we'd run out of C++ stack while traversing
large GC heap graphs.
2023-01-10 15:30:07 -05:00
Luke Wilde
fa1416987a LibJS: Add yearOfWeek calendar methods and properties
This is a normative change in the Temporal spec.

See:
- https://github.com/tc39/proposal-temporal/commit/7fa4d18
- https://github.com/tc39/proposal-temporal/commit/caa941d
2022-12-26 09:30:36 +01:00
Timothy Flynn
a2cf026b30 LibJS: Throw a RangeError when when formatting strings in DurationFormat
This is a normative change in the Intl.DurationFormat proposal. See:
https://github.com/tc39/proposal-intl-duration-format/commit/2546080
2022-12-15 09:40:09 +00:00
davidot
2bbea62176 LibJS: Don't update names of resulting functions in object expression
The only cases where the name should be set is if the function comes
from a direct anonymous function expression.
2022-12-14 15:27:08 +00:00
Luke Wilde
ce39c907fd LibJS: Support MM/DD/YYYY HH:MM <timezone-offset> format for Date
Required by Discord to determine if it should show Christmas themed
loading tips on the loading screen.
Fixes #16473.
2022-12-13 21:42:28 +00:00
Linus Groh
5ee1758f46 LibJS: Use ToPropertyKey AO for computed member expression value
This ensures the value goes through the regular ToPrimitive mechanism,
which PropertyKey::from_value() bypasses. This is relevant for objects
with a @@toPrimitive method, for example.
Also enables one skipped test in delete-basic.js, which now passes.
2022-12-10 01:08:34 +00:00
Timothy Flynn
d37d6b3479 LibJS: Protect CanonicalIndex against double-to-integer overflow
Explicitly disallow constructing a CanonicalIndex from a floating point
type without going through a factory method that will throw when the
provided index cannot fit in a u32.
2022-12-07 16:43:19 +00:00
davidot
cf0d30add6 LibJS: Add a function to ensure calls are made within the same second
Before these tests could be flaky if they happened to be called around
the edge of a second. Now we try up to 5 times to execute the tests
while staying within the same second.
2022-12-03 23:04:08 +00:00
Idan Horowitz
2e806dab07 LibJS: Implement Set.prototype.isDisjointFrom 2022-12-02 13:09:15 +01:00
Idan Horowitz
3470f33a0f LibJS: Implement Set.prototype.isSupersetOf 2022-12-02 13:09:15 +01:00
Idan Horowitz
e29be4eaa8 LibJS: Implement Set.prototype.isSubsetOf 2022-12-02 13:09:15 +01:00
Idan Horowitz
e359eeabe8 LibJS: Implement Set.prototype.symmetricDifference 2022-12-02 13:09:15 +01:00
Idan Horowitz
be8329d5f6 LibJS: Implement Set.prototype.difference 2022-12-02 13:09:15 +01:00
Idan Horowitz
9e693304ff LibJS: Implement Set.prototype.intersection 2022-12-02 13:09:15 +01:00
Idan Horowitz
fee65f6453 LibJS: Implement Set.prototype.union 2022-12-02 13:09:15 +01:00
Linus Groh
b0e7d59b8b LibJS: Throw on conversion from TimeZone to Calendar and vice versa
This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2084e77
2022-12-02 02:04:13 +01:00
Timothy Flynn
3ee5217adc LibJS: Implement String.prototype.toWellFormed 2022-12-01 17:03:55 +01:00
Timothy Flynn
0bb46235a7 LibJS: Implement String.prototype.isWellFormed 2022-12-01 17:03:55 +01:00
Timothy Flynn
34e328e580 LibJS: Allow TypedArrays to become detached while sorting
This is a normative change in the Change Array by Copy proposal. See:
https://github.com/tc39/proposal-change-array-by-copy/commit/17d8b54
2022-11-30 23:27:51 +01:00
davidot
d218a68296 LibJS: Allow CallExpressions as lhs of assignments in most cases
Although not quite like the spec says the web reality is that a lhs
target of CallExpression should not give a SyntaxError but only a
ReferenceError once executed.
2022-11-30 08:05:37 +01:00
davidot
8319d7ac06 LibJS: Fix that constant declaration in for loop was mutable in body 2022-11-30 08:05:37 +01:00
Timothy Flynn
675e5bfdce LibJS: Allow specifying only roundingIncrement in NumberFormat options
This is a normative change in the Intl.NumberFormat v3 spec. See:
https://github.com/tc39/proposal-intl-numberformat-v3/commit/a260aa3
2022-11-29 10:24:44 +01:00
davidot
ab19d7c99d LibJS: Enable commented out tests in Math.asin 2022-11-28 13:10:21 +01:00
davidot
bf1b2d63c6 LibJS: Add spec comments and check for edge cases in Math.tanh 2022-11-28 13:10:21 +01:00
davidot
8de8742b7c LibJS: Add spec comments and check for edge cases in Math.sinh 2022-11-28 13:10:21 +01:00
davidot
4306462a95 LibJS: Add spec comments and check for edge cases in Math.log10 2022-11-28 13:10:21 +01:00
davidot
eda90b54d4 LibJS: Add spec comments and check for edge cases in Math.log2 2022-11-28 13:10:21 +01:00
davidot
4813385c9a LibJS: Add spec comments and check for edge cases in Math.log 2022-11-28 13:10:21 +01:00
davidot
d4e5644df8 LibJS: Add spec comments and check for edge cases in Math.atanh 2022-11-28 13:10:21 +01:00
davidot
c565cbd30c LibJS: Add spec comments and check for edge cases in Math.atanh 2022-11-28 13:10:21 +01:00
davidot
68aeeea5d2 LibJS: Add spec comments and check for edge cases in Math.asinh 2022-11-28 13:10:21 +01:00