summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Parser.h
AgeCommit message (Collapse)Author
2021-09-14LibJS: Implement parsing and execution of optional chainsAli Mohammad Pur
2021-09-11AK: Replace the mutable String::replace API with an immutable versionIdan Horowitz
This removes the awkward String::replace API which was the only String API which mutated the String and replaces it with a new immutable version that returns a new String with the replacements applied. This also fixes a couple of UAFs that were caused by the use of this API. As an optimization an equivalent StringView::replace API was also added to remove an unnecessary String allocations in the format of: `String { view }.replace(...);`
2021-09-03Everywhere: Prevent risky implicit casts of (Nonnull)RefPtrDaniel Bertalan
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
2021-09-01LibJS: Add support for public fields in classesdavidot
2021-09-01LibJS: Fix small issues in parserdavidot
- Fix some places where escaped keywords are (not) allowed. - Be more strict about parameters for functions with 'use strict'. - Fix that expressions statements allowed functions and classes. - Fix that class expressions were not allowed. - Added a new next_token() method for checking the look ahead. - Fix that continue labels could jump to non iterating targets. - Fix that generator functions cannot be declared in if statements.
2021-08-24LibJS: Disallow yield expression correctly in formal parametersdavidot
And add ZERO WIDTH NO BREAK SPACE to valid whitespace.
2021-08-16LibJS: Correctly handle Unicode characters in JS source textdavidot
Also recognize additional white space characters.
2021-08-16LibJS: Check that 'let' is followed by declaration before matching itdavidot
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-16LibJS: Add optional extra strict checks in parse_binding_patterndavidot
2021-08-16LibJS: Allow labelled functions in certain contextsdavidot
Also disallow duplicated labels.
2021-08-15LibJS: Parse and partially execute import and export statementsdavidot
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-15LibJS: Add a mode to parse JS as a moduledavidot
In a module strict mode should be enabled at the start of parsing and we allow import and export statements.
2021-07-20LibJS: Handle strict mode for functions more correctlydavidot
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-20LibJS: Be more strict about reserved and special identifiersdavidot
2021-07-20LibJS: Partially revert e3fa32bLinus Groh
This was causing some syntactically wrong inputs to crash and subsequently broke CI (test262 parser tests).
2021-07-20LibJS: Optimize source_location_hint and add flag in print_errorsAlexander
This optimizes the algorithm used in source_location_hint and adds a flag to not print hints in print_errors.
2021-07-11LibJS: Rework Identifier parsing to match the spec more closelyAli Mohammad Pur
2021-07-06LibJS: Don't hoist functions under certain circumstancesHendi
When a lexical declaration with the same name as a function exists, the function is not hoisted (annex B).
2021-07-06Revert "LibJS: Don't hoist functions under certain circumstances"Linus Groh
This reverts commit 3411d50737725b382ae526e91a8bbd60656c3323. It was causing LeakSanitizer on CI to fail, possibly due to a circular reference.
2021-07-06LibJS: Don't hoist functions under certain circumstancesHendi
When a lexical declaration with the same name as a function exists, the function is not hoisted (annex B).
2021-07-06LibJS: Improve function hoisting across blocksHendi
The parser now keeps track of a scope chain so that it can hoist function declarations to the closest function scope.
2021-06-23LibJS: Correct behaviour of direct vs. indirect evalAnonymous
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-21LibJS: Rename Parser::m_parser_state => m_stateAndreas Kling
Also remove the "m_" prefix from all the public data members.
2021-06-19LibJS: Restructure and fully implement BindingPatternsMatthew Olsson
2021-06-14LibJS: Correctly parse yield-from expressionsAli Mohammad Pur
This commit implements parsing for `yield *expr`, and the multiple ways something can or can't be parsed like that. Also makes yield-from a TODO in the bytecode generator. Behold, the glory of javascript syntax: ```js // 'yield' = expression in generators. function* foo() { yield *bar; // <- Syntax error here, expression can't start with * } // 'yield' = identifier anywhere else. function foo() { yield *bar; // Perfectly fine, this is just `yield * bar` } ```
2021-06-14LibJS: Parse generator functions in object literalsAli Mohammad Pur
Also add some parser tests
2021-06-14LibJS: Track which Identifier nodes refer to function argumentsAndreas Kling
This patch adds an "argument index" field to Identifier AST nodes. If the Identifier refers to a function parameter in the currently open function scope, we stash the index of the parameter here. This will allow us to implement much faster direct access to function argument variables.
2021-06-11LibJS: Implement generator functions (only in bytecode mode)Ali Mohammad Pur
2021-05-29LibJS: Implement destructuring assignments and function parametersAli Mohammad Pur
2021-05-29Everywhere: Use s.unverwerth@serenityos.org :^)Stephan Unverwerth
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-12LibJS: Memoize failed calls of try_parse_arrow_function_expression()Stephan Unverwerth
2021-03-01LibJS: Keep track of file names, lines and columns inside the ASTJean-Baptiste Boric
2021-02-24LibJS: Use const references to avoid some copies in the parserLinus Groh
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-01-12Libraries: Move to Userland/Libraries/Andreas Kling