mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibJS: Rename VM::current_scope() => current_environment_record()
And rename some related functions that wrapped this as well.
This commit is contained in:
parent
d407f247b7
commit
08510a0c80
8 changed files with 28 additions and 27 deletions
|
@ -100,7 +100,7 @@ Value FunctionDeclaration::execute(Interpreter& interpreter, GlobalObject&) cons
|
|||
Value FunctionExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const
|
||||
{
|
||||
InterpreterNodeScope node_scope { interpreter, *this };
|
||||
return ScriptFunction::create(global_object, name(), body(), parameters(), function_length(), interpreter.current_scope(), kind(), is_strict_mode() || interpreter.vm().in_strict_mode(), is_arrow_function());
|
||||
return ScriptFunction::create(global_object, name(), body(), parameters(), function_length(), interpreter.current_environment_record(), kind(), is_strict_mode() || interpreter.vm().in_strict_mode(), is_arrow_function());
|
||||
}
|
||||
|
||||
Value ExpressionStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const
|
||||
|
@ -131,7 +131,7 @@ CallExpression::ThisAndCallee CallExpression::compute_this_and_callee(Interprete
|
|||
Object* this_value = nullptr;
|
||||
|
||||
if (is<SuperExpression>(member_expression.object())) {
|
||||
auto super_base = interpreter.current_environment()->get_super_base();
|
||||
auto super_base = interpreter.current_declarative_environment_record()->get_super_base();
|
||||
if (super_base.is_nullish()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, super_base.to_string_without_side_effects());
|
||||
return {};
|
||||
|
@ -229,7 +229,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
|
|||
// FIXME: This is merely a band-aid to make super() inside catch {} work (which constructs
|
||||
// a new DeclarativeEnvironmentRecord without current function). Implement GetSuperConstructor()
|
||||
// and subsequently GetThisEnvironment() instead.
|
||||
auto* function_environment = interpreter.current_environment();
|
||||
auto* function_environment = interpreter.current_declarative_environment_record();
|
||||
if (!function_environment->current_function())
|
||||
function_environment = static_cast<DeclarativeEnvironmentRecord*>(function_environment->outer_environment());
|
||||
|
||||
|
@ -853,7 +853,7 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o
|
|||
if (interpreter.exception())
|
||||
return {};
|
||||
|
||||
interpreter.current_scope()->put_into_environment_record(m_class_expression->name(), { class_constructor, DeclarationKind::Let });
|
||||
interpreter.current_environment_record()->put_into_environment_record(m_class_expression->name(), { class_constructor, DeclarationKind::Let });
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ void Call::execute_impl(Bytecode::Interpreter& interpreter) const
|
|||
void NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_scope(), m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.is_arrow_function());
|
||||
interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_environment_record(), m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.is_arrow_function());
|
||||
}
|
||||
|
||||
void Return::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||
|
@ -386,7 +386,7 @@ void PushDeclarativeEnvironmentRecord::execute_impl(Bytecode::Interpreter& inter
|
|||
HashMap<FlyString, Variable> resolved_variables;
|
||||
for (auto& it : m_variables)
|
||||
resolved_variables.set(interpreter.current_executable().get_string(it.key), it.value);
|
||||
auto* environment_record = interpreter.vm().heap().allocate<DeclarativeEnvironmentRecord>(interpreter.global_object(), move(resolved_variables), interpreter.vm().current_scope());
|
||||
auto* environment_record = interpreter.vm().heap().allocate<DeclarativeEnvironmentRecord>(interpreter.global_object(), move(resolved_variables), interpreter.vm().current_environment_record());
|
||||
interpreter.vm().call_frame().environment_record = environment_record;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
|
|||
{
|
||||
ScopeGuard guard([&] {
|
||||
for (auto& declaration : scope_node.functions()) {
|
||||
auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), current_scope(), declaration.kind(), declaration.is_strict_mode());
|
||||
auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), current_environment_record(), declaration.kind(), declaration.is_strict_mode());
|
||||
vm().set_variable(declaration.name(), function, global_object);
|
||||
}
|
||||
});
|
||||
|
@ -91,7 +91,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
|
|||
if (scope_type == ScopeType::Function) {
|
||||
push_scope({ scope_type, scope_node, false });
|
||||
for (auto& declaration : scope_node.functions())
|
||||
current_scope()->put_into_environment_record(declaration.name(), { js_undefined(), DeclarationKind::Var });
|
||||
current_environment_record()->put_into_environment_record(declaration.name(), { js_undefined(), DeclarationKind::Var });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
|
|||
bool pushed_environment_record = false;
|
||||
|
||||
if (!scope_variables_with_declaration_kind.is_empty()) {
|
||||
auto* environment_record = heap().allocate<DeclarativeEnvironmentRecord>(global_object, move(scope_variables_with_declaration_kind), current_scope());
|
||||
auto* environment_record = heap().allocate<DeclarativeEnvironmentRecord>(global_object, move(scope_variables_with_declaration_kind), current_environment_record());
|
||||
vm().call_frame().environment_record = environment_record;
|
||||
pushed_environment_record = true;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ Value Interpreter::execute_statement(GlobalObject& global_object, const Statemen
|
|||
return last_value;
|
||||
}
|
||||
|
||||
DeclarativeEnvironmentRecord* Interpreter::current_environment()
|
||||
DeclarativeEnvironmentRecord* Interpreter::current_declarative_environment_record()
|
||||
{
|
||||
VERIFY(is<DeclarativeEnvironmentRecord>(vm().call_frame().environment_record));
|
||||
return static_cast<DeclarativeEnvironmentRecord*>(vm().call_frame().environment_record);
|
||||
|
|
|
@ -56,8 +56,9 @@ public:
|
|||
ALWAYS_INLINE Heap& heap() { return vm().heap(); }
|
||||
ALWAYS_INLINE Exception* exception() { return vm().exception(); }
|
||||
|
||||
EnvironmentRecord* current_scope() { return vm().current_scope(); }
|
||||
DeclarativeEnvironmentRecord* current_environment();
|
||||
EnvironmentRecord* current_environment_record() { return vm().current_environment_record(); }
|
||||
|
||||
DeclarativeEnvironmentRecord* current_declarative_environment_record();
|
||||
|
||||
void enter_scope(const ScopeNode&, ScopeType, GlobalObject&);
|
||||
void exit_scope(const ScopeNode&);
|
||||
|
|
|
@ -62,7 +62,7 @@ Value GeneratorFunctionConstructor::construct(Function& new_target)
|
|||
block.dump(executable);
|
||||
}
|
||||
|
||||
return ScriptFunction::create(global_object(), function->name(), function->body(), function->parameters(), function->function_length(), vm().current_scope(), FunctionKind::Generator, function->is_strict_mode(), false);
|
||||
return ScriptFunction::create(global_object(), function->name(), function->body(), function->parameters(), function->function_length(), vm().current_environment_record(), FunctionKind::Generator, function->is_strict_mode(), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ Value ScriptFunction::execute_function_body()
|
|||
if (i >= call_frame_args.size())
|
||||
call_frame_args.resize(i + 1);
|
||||
call_frame_args[i] = argument_value;
|
||||
vm.assign(param, argument_value, global_object(), true, vm.current_scope());
|
||||
vm.assign(param, argument_value, global_object(), true, vm.current_environment_record());
|
||||
});
|
||||
|
||||
if (vm.exception())
|
||||
|
|
|
@ -135,7 +135,7 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
|
|||
{
|
||||
Optional<Variable> possible_match;
|
||||
if (!specific_scope && m_call_stack.size()) {
|
||||
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
for (auto* environment_record = current_environment_record(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
possible_match = environment_record->get_from_environment_record(name);
|
||||
if (possible_match.has_value()) {
|
||||
specific_scope = environment_record;
|
||||
|
@ -167,7 +167,7 @@ bool VM::delete_variable(FlyString const& name)
|
|||
EnvironmentRecord* specific_scope = nullptr;
|
||||
Optional<Variable> possible_match;
|
||||
if (!m_call_stack.is_empty()) {
|
||||
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
for (auto* environment_record = current_environment_record(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
possible_match = environment_record->get_from_environment_record(name);
|
||||
if (possible_match.has_value()) {
|
||||
specific_scope = environment_record;
|
||||
|
@ -363,7 +363,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
|
|||
// a function parameter, or by a local var declaration, we use that.
|
||||
// Otherwise, we return a lazily constructed Array with all the argument values.
|
||||
// FIXME: Do something much more spec-compliant.
|
||||
auto possible_match = current_scope()->get_from_environment_record(name);
|
||||
auto possible_match = current_environment_record()->get_from_environment_record(name);
|
||||
if (possible_match.has_value())
|
||||
return possible_match.value().value;
|
||||
if (!call_frame().arguments_object) {
|
||||
|
@ -376,7 +376,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
|
|||
return call_frame().arguments_object;
|
||||
}
|
||||
|
||||
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
for (auto* environment_record = current_environment_record(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
auto possible_match = environment_record->get_from_environment_record(name);
|
||||
if (exception())
|
||||
return {};
|
||||
|
@ -393,7 +393,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
|
|||
Reference VM::get_reference(const FlyString& name)
|
||||
{
|
||||
if (m_call_stack.size()) {
|
||||
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
for (auto* environment_record = current_environment_record(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
if (is<GlobalObject>(environment_record))
|
||||
break;
|
||||
auto possible_match = environment_record->get_from_environment_record(name);
|
||||
|
@ -460,8 +460,8 @@ Value VM::construct(Function& function, Function& new_target, Optional<MarkedVal
|
|||
// set the prototype on objects created by constructors that return an object (i.e. NativeFunction subclasses).
|
||||
if (function.constructor_kind() == Function::ConstructorKind::Base && new_target.constructor_kind() == Function::ConstructorKind::Derived && result.is_object()) {
|
||||
if (environment) {
|
||||
VERIFY(is<DeclarativeEnvironmentRecord>(current_scope()));
|
||||
static_cast<DeclarativeEnvironmentRecord*>(current_scope())->replace_this_binding(result);
|
||||
VERIFY(is<DeclarativeEnvironmentRecord>(current_environment_record()));
|
||||
static_cast<DeclarativeEnvironmentRecord*>(current_environment_record())->replace_this_binding(result);
|
||||
}
|
||||
auto prototype = new_target.get(names.prototype);
|
||||
if (exception())
|
||||
|
@ -508,7 +508,7 @@ Value VM::resolve_this_binding(GlobalObject& global_object) const
|
|||
const EnvironmentRecord* VM::find_this_scope() const
|
||||
{
|
||||
// We will always return because the Global environment will always be reached, which has a |this| binding.
|
||||
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
for (auto* environment_record = current_environment_record(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
if (environment_record->has_this_binding())
|
||||
return environment_record;
|
||||
}
|
||||
|
@ -622,9 +622,9 @@ void VM::dump_backtrace() const
|
|||
dbgln("-> {}", m_call_stack[i]->function_name);
|
||||
}
|
||||
|
||||
void VM::dump_scope_chain() const
|
||||
void VM::dump_environment_record_chain() const
|
||||
{
|
||||
for (auto* environment_record = current_scope(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
for (auto* environment_record = current_environment_record(); environment_record; environment_record = environment_record->outer_environment()) {
|
||||
dbgln("+> {} ({:p})", environment_record->class_name(), environment_record);
|
||||
if (is<DeclarativeEnvironmentRecord>(*environment_record)) {
|
||||
auto& declarative_environment_record = static_cast<DeclarativeEnvironmentRecord const&>(*environment_record);
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
void clear_exception() { m_exception = nullptr; }
|
||||
|
||||
void dump_backtrace() const;
|
||||
void dump_scope_chain() const;
|
||||
void dump_environment_record_chain() const;
|
||||
|
||||
class InterpreterExecutionScope {
|
||||
public:
|
||||
|
@ -122,8 +122,8 @@ public:
|
|||
const Vector<CallFrame*>& call_stack() const { return m_call_stack; }
|
||||
Vector<CallFrame*>& call_stack() { return m_call_stack; }
|
||||
|
||||
const EnvironmentRecord* current_scope() const { return call_frame().environment_record; }
|
||||
EnvironmentRecord* current_scope() { return call_frame().environment_record; }
|
||||
EnvironmentRecord const* current_environment_record() const { return call_frame().environment_record; }
|
||||
EnvironmentRecord* current_environment_record() { return call_frame().environment_record; }
|
||||
|
||||
bool in_strict_mode() const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue