mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibJS/Bytecode: Determine strict mode on an executable basis
An executable is generated for the top-level script and for each function. Strict mode can only be changed with the first statement of the top-level script and each function, which corresponds directly to Executable.
This commit is contained in:
parent
37ab7cc694
commit
8568d18d7d
3 changed files with 15 additions and 3 deletions
|
@ -20,6 +20,7 @@ struct Executable {
|
|||
NonnullOwnPtr<StringTable> string_table;
|
||||
NonnullOwnPtr<IdentifierTable> 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); }
|
||||
|
|
|
@ -41,12 +41,24 @@ CodeGenerationErrorOr<NonnullOwnPtr<Executable>> Generator::generate(ASTNode con
|
|||
generator.emit<Bytecode::Op::Yield>(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
bool is_strict_mode = false;
|
||||
if (is<Program>(node))
|
||||
is_strict_mode = static_cast<Program const&>(node).is_strict_mode();
|
||||
else if (is<FunctionBody>(node))
|
||||
is_strict_mode = static_cast<FunctionBody const&>(node).in_strict_mode();
|
||||
else if (is<FunctionDeclaration>(node))
|
||||
is_strict_mode = static_cast<FunctionDeclaration const&>(node).is_strict_mode();
|
||||
else if (is<FunctionExpression>(node))
|
||||
is_strict_mode = static_cast<FunctionExpression const&>(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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue