davidot
a8b25d6c36
LibJS: Handle '++' and '--' more correctly within expression
2021-08-16 23:20:04 +01:00
davidot
5f344f7ca3
LibJS: Check that 'let' is followed by declaration before matching it
...
Since 'let' is a valid variable name (in non-strict mode) let may not be
the start of a declaration but just an identifier.
2021-08-16 23:20:04 +01:00
davidot
179c48e1a4
LibJS: Add optional extra strict checks in parse_binding_pattern
2021-08-16 23:20:04 +01:00
davidot
f1f338edcd
LibJS: Tighten default values in formal parameter parsing
...
Disallow default parameter for rest parameters.
Disallow yield expressions as default values.
2021-08-16 23:20:04 +01:00
davidot
4989e79c45
LibJS: Allow yielding a class
2021-08-16 23:20:04 +01:00
davidot
19582ccad8
LibJS: Treat yield as an identifier in more non-generator contexts
...
And disallow some cases where we are in a generator context.
2021-08-16 23:20:04 +01:00
davidot
26177b1826
LibJS: Add more duplicated declarations detection
...
This is a small step in the right direction although the amount of
different checks is becoming unsustainable. In the future we probably
want to have the current_scope handle all declarations.
2021-08-16 23:20:04 +01:00
davidot
085c7df895
LibJS: Be more strict about the lhs of a for in/of loop
...
This is not entirely correct as really Object- and ArrayExpressions are
not allowed but that requires a bigger refactoring of for statement
parsing.
2021-08-16 23:20:04 +01:00
davidot
106f9e30d7
LibJS: Force the lexer to parse a regex when expecting a statement
2021-08-16 23:20:04 +01:00
davidot
05444103e3
LibJS: Treat arrow expression as function and stop parsing after
2021-08-16 23:20:04 +01:00
davidot
e31b715808
LibJS: Make functions reset break and continue context
2021-08-16 23:20:04 +01:00
davidot
be3b4a68d2
LibJS: Allow class methods named "get", "set" or "static"
2021-08-16 23:20:04 +01:00
davidot
b16c02d6b4
LibJS: Allow labelled functions in certain contexts
...
Also disallow duplicated labels.
2021-08-16 23:20:04 +01:00
davidot
020bfc9d93
LibJS: Parse and partially execute import and export statements
...
We produce the import and export entries as per the spec. However we do
not yet verify that named things that are exported are declared
somewhere.
2021-08-15 23:51:47 +01:00
davidot
7613c22b06
LibJS: Add a mode to parse JS as a module
...
In a module strict mode should be enabled at the start of parsing and we
allow import and export statements.
2021-08-15 23:51:47 +01:00
Lenny Maiorani
a0d7640e03
Userland: Make use of container version of any_of
...
Problem:
- New `any_of` implementation takes the entire container so the user
does not need to pass explicit begin/end iterators. This is unused
except is in tests.
Solution:
- Make use of the new and more user-friendly version where possible.
2021-08-02 00:37:18 +02:00
Timothy Flynn
f1dd770a8a
LibJS: Parse RegExp literals at AST creation time, not execution time
...
The spec requires that invalid RegExp literals must cause a Syntax Error
before the JavaScript is executed. See:
https://tc39.es/ecma262/#sec-patterns-static-semantics-early-errors
This is explicitly tested in the RegExp/property-escapes test262 tests.
For example, see unsupported-property-Line_Break.js:
$DONOTEVALUATE();
/\p{Line_Break}/u;
That RegExp literal is invalid because Line_Break is not a supported
Unicode property. $DONOTEVALUATE() just throws an exception when it is
executed. The test expects that this file will fail to be parsed.
Note that RegExp patterns can still be parsed at execution time by way
of "new RegExp(...)".
2021-07-30 21:26:31 +01:00
davidot
a6263150be
LibJS: Disallow unqualified deletes in strict mode
2021-07-20 23:45:28 +02:00
davidot
697882a7ad
LibJS: Disallow multiple __proto__ keys in object expression
2021-07-20 23:45:28 +02:00
davidot
93b57e6d8c
LibJS: Disallow static methods named prototype in classes
2021-07-20 23:45:28 +02:00
davidot
40b8689f9b
LibJS: Disallow duplicated variable declarations
2021-07-20 23:45:28 +02:00
davidot
5cc518f07a
LibJS: Handle strict mode for functions more correctly
...
If a function is strict (has 'use strict' directive) it cannot have
bindings, cannot have duplicated parameter names and cannot have some
reserved keywords and identifiers as parameter names.
The logic partly applies depending on whether we are already in strict
mode or the function contains 'use strict';
2021-07-20 23:45:28 +02:00
davidot
4485df1405
LibJS: Be more strict about reserved and special identifiers
2021-07-20 23:45:28 +02:00
davidot
2a61b90fef
LibJS: Be less strict about 'use strict'
...
It is allowed to have (bogus) directives e.g.
'does nothing'; 'same'; 'use strict';
Should still trigger strict mode.
2021-07-20 23:45:28 +02:00
Linus Groh
08a303172d
LibJS: Extend class 'extends' RHS expression parsing
...
Instead of only parsing a primary expression, we should also allow
member expressions, call expressions, and tagged template literals (and
optional chains, which we don't have yet).
In the spec, all of this is covered by `LeftHandSideExpression`
(https://tc39.es/ecma262/#prod-LeftHandSideExpression ).
2021-07-18 00:17:57 +01:00
Ali Mohammad Pur
dfb7e716f7
LibJS: Use expected() instead of syntax_error("Expected ...")
2021-07-11 21:41:54 +01:00
Ali Mohammad Pur
049e210cfa
LibJS: Rework Identifier parsing to match the spec more closely
2021-07-11 21:41:54 +01:00
Ali Mohammad Pur
77a5144264
LibJS: Add support for binding patterns in catch clauses
...
`try { ... } catch({a=foo}) {}` is valid, and now we parse and evaluate
it correctly :^)
2021-07-11 21:41:54 +01:00
Ali Mohammad Pur
1a9518ebe3
LibJS: Implement parsing and evaluation for AssignmentPatterns
...
e.g. `[...foo] = bar` can now be evaluated :^)
2021-07-11 21:41:54 +01:00
Ali Mohammad Pur
7fc6cd6b20
LibJS: Allow 'name = value' in object literals as the spec does
...
Currently, these are _always_ a syntax error, future commits will make
it valid in certain contexts.
2021-07-11 21:41:54 +01:00
Ali Mohammad Pur
7dae25eceb
LibJS: Fix computed property ending token in binding pattern parsing
...
The syntax is supposed to be '[expression]', not '[expression['.
2021-07-11 21:41:54 +01:00
Ali Mohammad Pur
b5b84029ab
LibJS: Treat default parameter values as being in function context
...
e.g. `new.target` should be permitted in
`function foo(x = new.target) {}`.
2021-07-11 21:41:54 +01:00
Timothy Flynn
d1e06b00e3
LibJS: Parse the RegExp.prototype.hasIndices flag
2021-07-10 16:49:35 +01:00
Hendi
37c4fbb6ca
LibJS: Don't hoist functions under certain circumstances
...
When a lexical declaration with the same name as a function exists,
the function is not hoisted (annex B).
2021-07-06 22:55:16 +01:00
Linus Groh
3faeabf1dc
Revert "LibJS: Don't hoist functions under certain circumstances"
...
This reverts commit 3411d50737
.
It was causing LeakSanitizer on CI to fail, possibly due to a circular
reference.
2021-07-06 13:25:37 +01:00
Hendi
3411d50737
LibJS: Don't hoist functions under certain circumstances
...
When a lexical declaration with the same name as a function exists,
the function is not hoisted (annex B).
2021-07-06 00:15:37 +01:00
Hendi
c194afd17c
LibJS: Fix runaway let scope when parsing for-in/of statements
...
This requires variables that should be exported to the script host
or to other scripts to be declared as var (such as in test-common.js),
since lexically-scoped variables won't be visible.
2021-07-06 00:15:37 +01:00
Hendi
38fd980b0c
LibJS: Improve function hoisting across blocks
...
The parser now keeps track of a scope chain so that it can hoist
function declarations to the closest function scope.
2021-07-06 00:15:37 +01:00
Hendi
72f8d90dc5
LibJS: Remove variables from FunctionNode
...
They weren't consumed anywhere outside the AST and went
against the usual concept of having declaration in ScopeNode.
2021-07-06 00:15:37 +01:00
Andreas Kling
71fc7ac7ac
LibJS: Make SuperCall a proper AST node and clean up evaluation
2021-07-02 19:39:09 +02:00
Ali Mohammad Pur
ccbc54358d
LibJS: Allow patterns in parenthesized arrow function parameters
2021-07-02 14:59:03 +02:00
Ali Mohammad Pur
2e00731ddb
LibJS: Allow 'yield' and 'await' as function expression names
...
The spec says so, and test262 checks for this too.
2021-07-02 14:59:03 +02:00
Ali Mohammad Pur
a6fe27423a
LibJS: Allow binding patterns as for in/of targets
2021-07-02 14:59:03 +02:00
Ali Mohammad Pur
bd9f28bba6
LibJS: Allow 'yield' as a variable name outside of generator functions
2021-07-02 14:59:03 +02:00
Ali Mohammad Pur
46ef333e9c
LibJS: Parse generator functions in class expressions too
2021-07-02 14:59:03 +02:00
Andreas Kling
beb43f673e
AK: Undo bogus Variant::downcast() rename
...
I accidentally renamed these to verify_cast() when doing the global
AK::downcast() rename.
2021-06-26 21:27:58 +02:00
Andreas Kling
527c639c1f
LibJS: Fix spelling mistake in one of the syntax error descriptions
2021-06-26 16:25:11 +02:00
Andreas Kling
ee3a73ddbb
AK: Rename downcast<T> => verify_cast<T>
...
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
Anonymous
2822da8c8f
LibJS: Correct behaviour of direct vs. indirect eval
...
eval only has direct access to the local scope when accessed through
the name eval. This includes locals named eval, because of course it
does.
2021-06-23 09:38:33 +01:00
Andreas Kling
8a3c9d9851
LibJS: Remove direct argument loading since it was buggy
...
The parser doesn't always track lexical scopes correctly, so let's not
rely on that for direct argument loading.
This reverts the LoadArguments bytecode instruction as well. We can
bring these things back when the parser can reliably tell us that
a given Identifier is indeed a function argument.
2021-06-22 22:20:17 +02:00