summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Interpreter.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-04 13:54:44 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-04 17:03:33 +0200
commita007b3c379bd28795eebd93877eced138b51f739 (patch)
treeac1b55824b701e88e8997b577cc7793d32a5690a /Libraries/LibJS/Interpreter.cpp
parentf41b5a453525a185cf80ab65204d23ec27071f64 (diff)
downloadserenity-a007b3c379bd28795eebd93877eced138b51f739.zip
LibJS: Move "strict mode" state to the call stack
Each call frame now knows whether it's executing in strict mode. It's no longer necessary to access the scope stack to find this mode.
Diffstat (limited to 'Libraries/LibJS/Interpreter.cpp')
-rw-r--r--Libraries/LibJS/Interpreter.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp
index a1351e7c64..51e5cf0a3c 100644
--- a/Libraries/LibJS/Interpreter.cpp
+++ b/Libraries/LibJS/Interpreter.cpp
@@ -72,6 +72,7 @@ Value Interpreter::run(GlobalObject& global_object, const Program& program)
global_call_frame.function_name = "(global execution context)";
global_call_frame.environment = heap().allocate<LexicalEnvironment>(global_object, LexicalEnvironment::EnvironmentRecordType::Global);
global_call_frame.environment->bind_this_value(global_object, &global_object);
+ global_call_frame.is_strict_mode = program.is_strict_mode();
if (vm().exception())
return {};
vm().call_stack().append(move(global_call_frame));
@@ -91,15 +92,15 @@ const GlobalObject& Interpreter::global_object() const
return static_cast<const GlobalObject&>(*m_global_object.cell());
}
-void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector arguments, ScopeType scope_type, GlobalObject& global_object, bool is_strict)
+void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector arguments, ScopeType scope_type, GlobalObject& global_object)
{
for (auto& declaration : scope_node.functions()) {
- auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), current_environment(), is_strict);
+ auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), current_environment(), declaration.is_strict_mode());
vm().set_variable(declaration.name(), function, global_object);
}
if (scope_type == ScopeType::Function) {
- push_scope({ scope_type, scope_node, false, is_strict });
+ push_scope({ scope_type, scope_node, false });
return;
}
@@ -130,7 +131,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector argume
pushed_lexical_environment = true;
}
- push_scope({ scope_type, scope_node, pushed_lexical_environment, is_strict });
+ push_scope({ scope_type, scope_node, pushed_lexical_environment });
}
void Interpreter::exit_scope(const ScopeNode& scope_node)
@@ -150,18 +151,16 @@ void Interpreter::exit_scope(const ScopeNode& scope_node)
void Interpreter::push_scope(ScopeFrame frame)
{
- if (in_strict_mode())
- frame.is_strict_mode = true;
m_scope_stack.append(move(frame));
}
-Value Interpreter::execute_statement(GlobalObject& global_object, const Statement& statement, ArgumentVector arguments, ScopeType scope_type, bool is_strict)
+Value Interpreter::execute_statement(GlobalObject& global_object, const Statement& statement, ArgumentVector arguments, ScopeType scope_type)
{
if (!statement.is_scope_node())
return statement.execute(*this, global_object);
auto& block = static_cast<const ScopeNode&>(statement);
- enter_scope(block, move(arguments), scope_type, global_object, is_strict);
+ enter_scope(block, move(arguments), scope_type, global_object);
if (block.children().is_empty())
vm().set_last_value({}, js_undefined());