1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00
serenity/Userland/Libraries/LibJS
davidot 830ea0414c LibJS: Make scoping follow the spec
Before this we used an ad-hoc combination of references and 'variables'
stored in a hashmap. This worked in most cases but is not spec like.
Additionally hoisting, dynamically naming functions and scope analysis
was not done properly.

This patch fixes all of that by:
  - Implement BindingInitialization for destructuring assignment.
  - Implementing a new ScopePusher which tracks the lexical and var
    scoped declarations. This hoists functions to the top level if no
    lexical declaration name overlaps. Furthermore we do checking of
    redeclarations in the ScopePusher now requiring less checks all over
    the place.
  - Add methods for parsing the directives and statement lists instead
    of having that code duplicated in multiple places. This allows
    declarations to pushed to the appropriate scope more easily.
  - Remove the non spec way of storing 'variables' in
    DeclarativeEnvironment and make Reference follow the spec instead of
    checking both the bindings and 'variables'.
  - Remove all scoping related things from the Interpreter. And instead
    use environments as specified by the spec. This also includes fixing
    that NativeFunctions did not produce a valid FunctionEnvironment
    which could cause issues with callbacks and eval. All
    FunctionObjects now have a valid NewFunctionEnvironment
    implementation.
  - Remove execute_statements from Interpreter and instead use
    ASTNode::execute everywhere this simplifies AST.cpp as you no longer
    need to worry about which method to call.
  - Make ScopeNodes setup their own environment. This uses four
    different methods specified by the spec
    {Block, Function, Eval, Global}DeclarationInstantiation with the
    annexB extensions.
  - Implement and use NamedEvaluation where specified.

Additionally there are fixes to things exposed by these changes to eval,
{for, for-in, for-of} loops and assignment.

Finally it also fixes some tests in test-js which where passing before
but not now that we have correct behavior :^).
2021-09-30 08:16:32 +01:00
..
Bytecode LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
Heap LibJS: Increase time between garbage collections 2021-09-17 15:23:18 +02:00
Runtime LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
Tests LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
AST.cpp LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
AST.h LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
CMakeLists.txt LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObject 2021-09-25 17:51:30 +02:00
Console.cpp LibJS: Rename CallFrame => ExecutionContext 2021-06-24 19:28:00 +02:00
Console.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Forward.h LibJS: Add ECMAScriptFunctionObject forward declaration 2021-09-25 17:51:30 +02:00
Interpreter.cpp LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
Interpreter.h LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
Lexer.cpp LibJS: Always inline two hot (and trivial) functions in JS::Lexer 2021-09-18 19:54:24 +02:00
Lexer.h LibJS: Make Lexer::s_keywords store keywords as FlyString 2021-09-18 19:54:24 +02:00
MarkupGenerator.cpp LibJS: Remove unused includes out of Cell.h, move to the users 2021-08-01 08:10:16 +02:00
MarkupGenerator.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Module.cpp LibJS: Add a barebones Module class 2021-09-14 21:41:51 +02:00
Module.h LibJS: Add a barebones Module class 2021-09-14 21:41:51 +02:00
Parser.cpp LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
Parser.h LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00
Script.cpp LibJS+LibWeb: Move script parse time logging from JS::Script to LibWeb 2021-09-14 21:41:51 +02:00
Script.h LibJS+LibWeb: Let JS::Script::parse() return a list of errors (on error) 2021-09-14 21:41:51 +02:00
SourceRange.h LibJS: Implement parsing and evaluation for AssignmentPatterns 2021-07-11 21:41:54 +01:00
SourceTextModule.cpp LibJS: Add a barebones SourceTextModule class 2021-09-14 21:41:51 +02:00
SourceTextModule.h LibJS: Add a barebones SourceTextModule class 2021-09-14 21:41:51 +02:00
SyntaxHighlighter.cpp LibJS: Remove unused header includes 2021-08-01 08:10:16 +02:00
SyntaxHighlighter.h LibWeb+LibSyntax: Implement nested syntax highlighters 2021-06-07 14:45:49 +04:30
Token.cpp AK: Replace the mutable String::replace API with an immutable version 2021-09-11 20:36:43 +03:00
Token.h Libraries: Use AK::Variant default initialization where appropriate 2021-09-21 04:22:52 +04:30