diff --git a/Userland/Libraries/LibJS/Bytecode/Executable.h b/Userland/Libraries/LibJS/Bytecode/Executable.h index 6f1c3f99390..4abe68ab058 100644 --- a/Userland/Libraries/LibJS/Bytecode/Executable.h +++ b/Userland/Libraries/LibJS/Bytecode/Executable.h @@ -20,6 +20,7 @@ struct Executable { NonnullOwnPtr string_table; NonnullOwnPtr identifier_table; size_t number_of_registers { 0 }; + bool is_strict_mode { false }; String const& get_string(StringTableIndex index) const { return string_table->get(index); } FlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); } diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.cpp b/Userland/Libraries/LibJS/Bytecode/Generator.cpp index 3dc17991040..76ca4ebd755 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Generator.cpp @@ -41,12 +41,24 @@ CodeGenerationErrorOr> Generator::generate(ASTNode con generator.emit(nullptr); } } + + bool is_strict_mode = false; + if (is(node)) + is_strict_mode = static_cast(node).is_strict_mode(); + else if (is(node)) + is_strict_mode = static_cast(node).in_strict_mode(); + else if (is(node)) + is_strict_mode = static_cast(node).is_strict_mode(); + else if (is(node)) + is_strict_mode = static_cast(node).is_strict_mode(); + return adopt_own(*new Executable { .name = {}, .basic_blocks = move(generator.m_root_basic_blocks), .string_table = move(generator.m_string_table), .identifier_table = move(generator.m_identifier_table), - .number_of_registers = generator.m_next_register }); + .number_of_registers = generator.m_next_register, + .is_strict_mode = is_strict_mode }); } void Generator::grow(size_t additional_size) diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 561a086b61a..dceec8c5d33 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -57,8 +57,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e execution_context.lexical_environment = &m_realm.global_environment(); execution_context.variable_environment = &m_realm.global_environment(); execution_context.realm = &m_realm; - // FIXME: How do we know if we're in strict mode? Maybe the Bytecode::Block should know this? - // execution_context.is_strict_mode = ???; + execution_context.is_strict_mode = executable.is_strict_mode; vm().push_execution_context(execution_context); pushed_execution_context = true; }