summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Parser.h
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-04-10 00:55:45 +0100
committerLinus Groh <mail@linusgroh.de>2022-04-11 21:23:36 +0100
commit34f902fb524808b308efe4568ff5a026d2cb4884 (patch)
treee83d706c51a5d67564d300fb92575b2a701b7e29 /Userland/Libraries/LibJS/Parser.h
parentf4f850aaf2ca300b55e14ffbf303a4b0e4f53cb7 (diff)
downloadserenity-34f902fb524808b308efe4568ff5a026d2cb4884.zip
LibJS: Add missing steps and spec comments to PerformEval
While adding spec comments to PerformEval, I noticed we were missing multiple steps. Namely, these were: - Checking if the host will allow us to compile the string (allowing LibWeb to perform CSP for eval) - The parser's initial state depending on the environment around us on direct eval: - Allowing new.target via eval in functions - Allowing super calls and super properties via eval in classes - Disallowing the use of the arguments object in class field initializers at eval's parse time - Setting ScriptOrModule of eval's execution context The spec allows us to apply the additional parsing steps in any order. The method I have gone with is passing in a struct to the parser's constructor, which overrides the parser's initial state to (dis)allow the things stated above from the get-go.
Diffstat (limited to 'Userland/Libraries/LibJS/Parser.h')
-rw-r--r--Userland/Libraries/LibJS/Parser.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h
index 10d708c1ed..1f017bfbdd 100644
--- a/Userland/Libraries/LibJS/Parser.h
+++ b/Userland/Libraries/LibJS/Parser.h
@@ -43,7 +43,14 @@ class ScopePusher;
class Parser {
public:
- explicit Parser(Lexer lexer, Program::Type program_type = Program::Type::Script);
+ struct EvalInitialState {
+ bool in_eval_function_context { false };
+ bool allow_super_property_lookup { false };
+ bool allow_super_constructor_call { false };
+ bool in_class_field_initializer { false };
+ };
+
+ explicit Parser(Lexer lexer, Program::Type program_type = Program::Type::Script, Optional<EvalInitialState> initial_state_for_eval = {});
NonnullRefPtr<Program> parse_program(bool starts_in_strict_mode = false);
@@ -300,6 +307,7 @@ private:
bool allow_super_property_lookup { false };
bool allow_super_constructor_call { false };
bool in_function_context { false };
+ bool in_eval_function_context { false }; // This controls if we allow new.target or not. Note that eval("return") is not allowed, so we have to have a separate state variable for eval.
bool in_formal_parameter_context { false };
bool in_generator_function_context { false };
bool await_expression_is_valid { false };