1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-21 07:45:08 +00:00
serenity/Userland/Libraries/LibJS
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
..
Bytecode LibJS: Fix a bunch of unwind related errors in GenerateCFG 2023-03-17 09:57:51 +00:00
Contrib/Test262 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Heap LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Runtime LibJS: Add fast path to Value::to_u32() if Value is a positive i32 2023-03-30 19:13:35 +01:00
Tests LibJS: Parse secondary expressions with the original forbidden token set 2023-04-02 06:45:37 +02:00
AST.cpp LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
AST.h LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
CMakeLists.txt Everywhere: Use LibFileSystem where trivial 2023-03-21 19:03:21 +00:00
Console.cpp Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Console.h LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
CyclicModule.cpp LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
CyclicModule.h LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Forward.h LibJS: Add DisposableStack{, Prototype, Constructor} 2023-01-23 09:56:50 +00:00
Interpreter.cpp WebContent+LibWeb+LibJS: Simplify injection of JS console globals 2022-12-09 18:51:03 +00:00
Interpreter.h AK+Everywhere: Rename FlyString to DeprecatedFlyString 2023-01-09 23:00:24 +00:00
Lexer.cpp Everywhere: Use _{short_,}string to create Strings from literals 2023-02-25 20:51:49 +01:00
Lexer.h LibJS: Remove some usage of DeprecatedString usage from Lexer 2023-01-26 20:25:25 +00:00
MarkupGenerator.cpp LibJS: Convert remaining usages of Value::TDSWOSE to Value::TSWOSE 2023-02-16 14:32:22 +01:00
MarkupGenerator.h LibJS: Convert MarkupGenerator to the new String 2022-12-07 09:58:38 +00:00
Module.cpp LibJS+Everywhere: Propagate Cell::initialize errors from Heap::allocate 2023-01-29 00:02:45 +00:00
Module.h LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Parser.cpp LibJS: Parse secondary expressions with the original forbidden token set 2023-04-02 06:45:37 +02:00
Parser.h LibJS: Make RefPtr and NonnullRefPtr usage const-correct 2023-02-21 00:54:04 +01:00
ParserError.cpp LibJS: Add to_string definitions to CodeGenerationError and ParserError 2023-02-17 09:14:23 -05:00
ParserError.h LibJS: Add to_string definitions to CodeGenerationError and ParserError 2023-02-17 09:14:23 -05:00
Print.cpp LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Print.h Everywhere: Remove the AK:: qualifier from Stream usages 2023-02-13 00:50:07 +00:00
SafeFunction.h LibJS: Fix compilation of operator= for JS::SafeFunction 2023-03-07 11:51:12 +00:00
Script.cpp LibJS: Convert Heap::allocate{,_without_realm}() to NonnullGCPtr 2022-12-15 06:56:37 -05:00
Script.h AK+Everywhere: Rename String to DeprecatedString 2022-12-06 08:54:33 +01:00
SourceCode.cpp LibJS: Make RefPtr and NonnullRefPtr usage const-correct 2023-02-21 00:54:04 +01:00
SourceCode.h LibJS: Make RefPtr and NonnullRefPtr usage const-correct 2023-02-21 00:54:04 +01:00
SourceRange.h LibJS+LibWeb: Add a bunch of missing includes 2023-03-06 13:05:43 +00:00
SourceTextModule.cpp LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
SourceTextModule.h LibJS: Make RefPtr and NonnullRefPtr usage const-correct 2023-02-21 00:54:04 +01:00
SyntaxHighlighter.cpp LibSyntax+Libraries: Replace TextStyle with Gfx::TextAttributes 2023-03-15 14:55:49 +01:00
SyntaxHighlighter.h LibSyntax: Teach each highlighter about it's comment syntax 2022-11-27 18:28:43 -07:00
SyntheticModule.cpp LibJS+LibWeb: Convert string view PrimitiveString instances to String 2023-02-09 17:13:33 +00:00
SyntheticModule.h AK+Everywhere: Rename FlyString to DeprecatedFlyString 2023-01-09 23:00:24 +00:00
Token.cpp AK: Remove StringBuilder::build() in favor of to_deprecated_string() 2023-01-27 20:38:49 +00:00
Token.h LibJS: Remove DeprecatedString usage from Token 2023-01-26 20:25:25 +00:00