LibJS: Drop "Record" suffix from all the *Environment record classes

"Records" in the spec are basically C++ classes, so let's drop this
mouthful of a suffix.
This commit is contained in:
Andreas Kling 2021-07-01 12:24:46 +02:00
parent 56d25d7210
commit 44221756ab
Notes: sideshowbarker 2024-07-18 11:10:31 +09:00
40 changed files with 366 additions and 366 deletions

View File

@ -19,12 +19,12 @@
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/BigInt.h> #include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h> #include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/MarkedValueList.h> #include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h> #include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/PrimitiveString.h> #include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Reference.h> #include <LibJS/Runtime/Reference.h>
@ -133,7 +133,7 @@ CallExpression::ThisAndCallee CallExpression::compute_this_and_callee(Interprete
Value this_value; Value this_value;
if (is<SuperExpression>(member_expression.object())) { if (is<SuperExpression>(member_expression.object())) {
auto super_base = interpreter.current_function_environment_record()->get_super_base(); auto super_base = interpreter.current_function_environment()->get_super_base();
if (super_base.is_nullish()) { if (super_base.is_nullish()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, super_base.to_string_without_side_effects()); vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, super_base.to_string_without_side_effects());
return {}; return {};
@ -242,7 +242,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
return {}; return {};
auto& this_er = get_this_environment(interpreter.vm()); auto& this_er = get_this_environment(interpreter.vm());
verify_cast<FunctionEnvironmentRecord>(this_er).bind_this_value(global_object, result); verify_cast<FunctionEnvironment>(this_er).bind_this_value(global_object, result);
} else { } else {
result = vm.call(function, this_value, move(arguments)); result = vm.call(function, this_value, move(arguments));
} }
@ -305,8 +305,8 @@ Value WithStatement::execute(Interpreter& interpreter, GlobalObject& global_obje
VERIFY(object); VERIFY(object);
auto* object_environment_record = new_object_environment(*object, true, interpreter.vm().running_execution_context().lexical_environment); auto* object_environment = new_object_environment(*object, true, interpreter.vm().running_execution_context().lexical_environment);
TemporaryChange<EnvironmentRecord*> scope_change(interpreter.vm().running_execution_context().lexical_environment, object_environment_record); TemporaryChange<Environment*> scope_change(interpreter.vm().running_execution_context().lexical_environment, object_environment);
return interpreter.execute_statement(global_object, m_body).value_or(js_undefined()); return interpreter.execute_statement(global_object, m_body).value_or(js_undefined());
} }
@ -854,7 +854,7 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
interpreter.lexical_environment()->put_into_environment_record(m_class_expression->name(), { class_constructor, DeclarationKind::Let }); interpreter.lexical_environment()->put_into_environment(m_class_expression->name(), { class_constructor, DeclarationKind::Let });
return {}; return {};
} }
@ -2049,8 +2049,8 @@ Value TryStatement::execute(Interpreter& interpreter, GlobalObject& global_objec
HashMap<FlyString, Variable> parameters; HashMap<FlyString, Variable> parameters;
parameters.set(m_handler->parameter(), Variable { exception->value(), DeclarationKind::Var }); parameters.set(m_handler->parameter(), Variable { exception->value(), DeclarationKind::Var });
auto* catch_scope = interpreter.heap().allocate<DeclarativeEnvironmentRecord>(global_object, move(parameters), interpreter.vm().running_execution_context().lexical_environment); auto* catch_scope = interpreter.heap().allocate<DeclarativeEnvironment>(global_object, move(parameters), interpreter.vm().running_execution_context().lexical_environment);
TemporaryChange<EnvironmentRecord*> scope_change(interpreter.vm().running_execution_context().lexical_environment, catch_scope); TemporaryChange<Environment*> scope_change(interpreter.vm().running_execution_context().lexical_environment, catch_scope);
result = interpreter.execute_statement(global_object, m_handler->body()); result = interpreter.execute_statement(global_object, m_handler->body());
} }
} }

View File

@ -14,7 +14,7 @@
#include <LibJS/Bytecode/Op.h> #include <LibJS/Bytecode/Op.h>
#include <LibJS/Bytecode/Register.h> #include <LibJS/Bytecode/Register.h>
#include <LibJS/Bytecode/StringTable.h> #include <LibJS/Bytecode/StringTable.h>
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
namespace JS { namespace JS {
@ -63,7 +63,7 @@ void ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
} }
if (!scope_variables_with_declaration_kind.is_empty()) { if (!scope_variables_with_declaration_kind.is_empty()) {
generator.emit<Bytecode::Op::PushDeclarativeEnvironmentRecord>(move(scope_variables_with_declaration_kind)); generator.emit<Bytecode::Op::PushDeclarativeEnvironment>(move(scope_variables_with_declaration_kind));
} }
for (auto& child : children()) { for (auto& child : children()) {
@ -1214,7 +1214,7 @@ void TryStatement::generate_bytecode(Bytecode::Generator& generator) const
if (!m_finalizer) if (!m_finalizer)
generator.emit<Bytecode::Op::LeaveUnwindContext>(); generator.emit<Bytecode::Op::LeaveUnwindContext>();
if (!m_handler->parameter().is_empty()) { if (!m_handler->parameter().is_empty()) {
// FIXME: We need a separate DeclarativeEnvironmentRecord here // FIXME: We need a separate DeclarativeEnvironment here
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(m_handler->parameter())); generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(m_handler->parameter()));
} }
m_handler->body().generate_bytecode(generator); m_handler->body().generate_bytecode(generator);

View File

@ -64,7 +64,7 @@
O(Increment) \ O(Increment) \
O(Decrement) \ O(Decrement) \
O(Throw) \ O(Throw) \
O(PushDeclarativeEnvironmentRecord) \ O(PushDeclarativeEnvironment) \
O(EnterUnwindContext) \ O(EnterUnwindContext) \
O(LeaveUnwindContext) \ O(LeaveUnwindContext) \
O(ContinuePendingUnwind) \ O(ContinuePendingUnwind) \

View File

@ -10,7 +10,7 @@
#include <LibJS/Bytecode/Instruction.h> #include <LibJS/Bytecode/Instruction.h>
#include <LibJS/Bytecode/Interpreter.h> #include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Bytecode/Op.h> #include <LibJS/Bytecode/Op.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
namespace JS::Bytecode { namespace JS::Bytecode {
@ -49,8 +49,8 @@ Value Interpreter::run(Executable const& executable, BasicBlock const* entry_poi
execution_context.this_value = &global_object(); execution_context.this_value = &global_object();
static FlyString global_execution_context_name = "(*BC* global execution context)"; static FlyString global_execution_context_name = "(*BC* global execution context)";
execution_context.function_name = global_execution_context_name; execution_context.function_name = global_execution_context_name;
execution_context.lexical_environment = &global_object().environment_record(); execution_context.lexical_environment = &global_object().environment();
execution_context.variable_environment = &global_object().environment_record(); execution_context.variable_environment = &global_object().environment();
VERIFY(!vm().exception()); VERIFY(!vm().exception());
// FIXME: How do we know if we're in strict mode? Maybe the Bytecode::Block should know this? // 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 = ???;

View File

@ -12,8 +12,8 @@
#include <LibJS/Bytecode/Op.h> #include <LibJS/Bytecode/Op.h>
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/BigInt.h> #include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h> #include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
@ -381,14 +381,14 @@ void ContinuePendingUnwind::replace_references_impl(BasicBlock const& from, Basi
m_resume_target = Label { to }; m_resume_target = Label { to };
} }
void PushDeclarativeEnvironmentRecord::execute_impl(Bytecode::Interpreter& interpreter) const void PushDeclarativeEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
{ {
HashMap<FlyString, Variable> resolved_variables; HashMap<FlyString, Variable> resolved_variables;
for (auto& it : m_variables) for (auto& it : m_variables)
resolved_variables.set(interpreter.current_executable().get_string(it.key), it.value); 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().lexical_environment()); auto* environment = interpreter.vm().heap().allocate<DeclarativeEnvironment>(interpreter.global_object(), move(resolved_variables), interpreter.vm().lexical_environment());
interpreter.vm().running_execution_context().lexical_environment = environment_record; interpreter.vm().running_execution_context().lexical_environment = environment;
interpreter.vm().running_execution_context().variable_environment = environment_record; interpreter.vm().running_execution_context().variable_environment = environment;
} }
void Yield::execute_impl(Bytecode::Interpreter& interpreter) const void Yield::execute_impl(Bytecode::Interpreter& interpreter) const
@ -635,10 +635,10 @@ String ContinuePendingUnwind::to_string_impl(Bytecode::Executable const&) const
return String::formatted("ContinuePendingUnwind resume:{}", m_resume_target); return String::formatted("ContinuePendingUnwind resume:{}", m_resume_target);
} }
String PushDeclarativeEnvironmentRecord::to_string_impl(const Bytecode::Executable& executable) const String PushDeclarativeEnvironment::to_string_impl(const Bytecode::Executable& executable) const
{ {
StringBuilder builder; StringBuilder builder;
builder.append("PushDeclarativeEnvironmentRecord"); builder.append("PushDeclarativeEnvironment");
if (!m_variables.is_empty()) { if (!m_variables.is_empty()) {
builder.append(" {"); builder.append(" {");
Vector<String> names; Vector<String> names;

View File

@ -14,7 +14,7 @@
#include <LibJS/Bytecode/Register.h> #include <LibJS/Bytecode/Register.h>
#include <LibJS/Bytecode/StringTable.h> #include <LibJS/Bytecode/StringTable.h>
#include <LibJS/Heap/Cell.h> #include <LibJS/Heap/Cell.h>
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
namespace JS::Bytecode::Op { namespace JS::Bytecode::Op {
@ -635,10 +635,10 @@ private:
Optional<Label> m_continuation_label; Optional<Label> m_continuation_label;
}; };
class PushDeclarativeEnvironmentRecord final : public Instruction { class PushDeclarativeEnvironment final : public Instruction {
public: public:
explicit PushDeclarativeEnvironmentRecord(HashMap<u32, Variable> variables) explicit PushDeclarativeEnvironment(HashMap<u32, Variable> variables)
: Instruction(Type::PushDeclarativeEnvironmentRecord) : Instruction(Type::PushDeclarativeEnvironment)
, m_variables(move(variables)) , m_variables(move(variables))
{ {
} }

View File

@ -50,8 +50,8 @@ set(SOURCES
Runtime/DateConstructor.cpp Runtime/DateConstructor.cpp
Runtime/Date.cpp Runtime/Date.cpp
Runtime/DatePrototype.cpp Runtime/DatePrototype.cpp
Runtime/DeclarativeEnvironmentRecord.cpp Runtime/DeclarativeEnvironment.cpp
Runtime/EnvironmentRecord.cpp Runtime/Environment.cpp
Runtime/ErrorConstructor.cpp Runtime/ErrorConstructor.cpp
Runtime/Error.cpp Runtime/Error.cpp
Runtime/ErrorPrototype.cpp Runtime/ErrorPrototype.cpp
@ -61,14 +61,14 @@ set(SOURCES
Runtime/FinalizationRegistryConstructor.cpp Runtime/FinalizationRegistryConstructor.cpp
Runtime/FinalizationRegistryPrototype.cpp Runtime/FinalizationRegistryPrototype.cpp
Runtime/FunctionConstructor.cpp Runtime/FunctionConstructor.cpp
Runtime/FunctionEnvironmentRecord.cpp Runtime/FunctionEnvironment.cpp
Runtime/FunctionObject.cpp Runtime/FunctionObject.cpp
Runtime/FunctionPrototype.cpp Runtime/FunctionPrototype.cpp
Runtime/GeneratorFunctionConstructor.cpp Runtime/GeneratorFunctionConstructor.cpp
Runtime/GeneratorFunctionPrototype.cpp Runtime/GeneratorFunctionPrototype.cpp
Runtime/GeneratorObject.cpp Runtime/GeneratorObject.cpp
Runtime/GeneratorObjectPrototype.cpp Runtime/GeneratorObjectPrototype.cpp
Runtime/GlobalEnvironmentRecord.cpp Runtime/GlobalEnvironment.cpp
Runtime/GlobalObject.cpp Runtime/GlobalObject.cpp
Runtime/IndexedProperties.cpp Runtime/IndexedProperties.cpp
Runtime/IteratorOperations.cpp Runtime/IteratorOperations.cpp
@ -88,7 +88,7 @@ set(SOURCES
Runtime/NumberPrototype.cpp Runtime/NumberPrototype.cpp
Runtime/Object.cpp Runtime/Object.cpp
Runtime/ObjectConstructor.cpp Runtime/ObjectConstructor.cpp
Runtime/ObjectEnvironmentRecord.cpp Runtime/ObjectEnvironment.cpp
Runtime/ObjectPrototype.cpp Runtime/ObjectPrototype.cpp
Runtime/PrimitiveString.cpp Runtime/PrimitiveString.cpp
Runtime/Promise.cpp Runtime/Promise.cpp

View File

@ -120,16 +120,16 @@ class BoundFunction;
class Cell; class Cell;
class CellAllocator; class CellAllocator;
class Console; class Console;
class DeclarativeEnvironmentRecord; class DeclarativeEnvironment;
class DeferGC; class DeferGC;
class EnvironmentRecord; class Environment;
class Error; class Error;
class ErrorType; class ErrorType;
class Exception; class Exception;
class Expression; class Expression;
class FunctionEnvironmentRecord; class FunctionEnvironment;
class FunctionNode; class FunctionNode;
class GlobalEnvironmentRecord; class GlobalEnvironment;
class GlobalObject; class GlobalObject;
class HandleImpl; class HandleImpl;
class Heap; class Heap;
@ -138,7 +138,7 @@ class Interpreter;
class MarkedValueList; class MarkedValueList;
class NativeFunction; class NativeFunction;
class NativeProperty; class NativeProperty;
class ObjectEnvironmentRecord; class ObjectEnvironment;
class PrimitiveString; class PrimitiveString;
class PromiseReaction; class PromiseReaction;
class PromiseReactionJob; class PromiseReactionJob;

View File

@ -50,7 +50,7 @@ public:
virtual ~Visitor() = default; virtual ~Visitor() = default;
}; };
virtual bool is_environment_record() const { return false; } virtual bool is_environment() const { return false; }
virtual void visit_edges(Visitor&) { } virtual void visit_edges(Visitor&) { }
Heap& heap() const; Heap& heap() const;

View File

@ -9,8 +9,8 @@
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibJS/AST.h> #include <LibJS/AST.h>
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h> #include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
@ -51,8 +51,8 @@ void Interpreter::run(GlobalObject& global_object, const Program& program)
execution_context.this_value = &global_object; execution_context.this_value = &global_object;
static FlyString global_execution_context_name = "(global execution context)"; static FlyString global_execution_context_name = "(global execution context)";
execution_context.function_name = global_execution_context_name; execution_context.function_name = global_execution_context_name;
execution_context.lexical_environment = &global_object.environment_record(); execution_context.lexical_environment = &global_object.environment();
execution_context.variable_environment = &global_object.environment_record(); execution_context.variable_environment = &global_object.environment();
VERIFY(!vm.exception()); VERIFY(!vm.exception());
execution_context.is_strict_mode = program.is_strict_mode(); execution_context.is_strict_mode = program.is_strict_mode();
vm.push_execution_context(execution_context, global_object); vm.push_execution_context(execution_context, global_object);
@ -93,7 +93,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
if (scope_type == ScopeType::Function) { if (scope_type == ScopeType::Function) {
push_scope({ scope_type, scope_node, false }); push_scope({ scope_type, scope_node, false });
for (auto& declaration : scope_node.functions()) for (auto& declaration : scope_node.functions())
lexical_environment()->put_into_environment_record(declaration.name(), { js_undefined(), DeclarationKind::Var }); lexical_environment()->put_into_environment(declaration.name(), { js_undefined(), DeclarationKind::Var });
return; return;
} }
@ -130,16 +130,16 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
} }
} }
bool pushed_environment_record = false; bool pushed_environment = false;
if (!scope_variables_with_declaration_kind.is_empty()) { if (!scope_variables_with_declaration_kind.is_empty()) {
auto* environment_record = heap().allocate<DeclarativeEnvironmentRecord>(global_object, move(scope_variables_with_declaration_kind), lexical_environment()); auto* environment = heap().allocate<DeclarativeEnvironment>(global_object, move(scope_variables_with_declaration_kind), lexical_environment());
vm().running_execution_context().lexical_environment = environment_record; vm().running_execution_context().lexical_environment = environment;
vm().running_execution_context().variable_environment = environment_record; vm().running_execution_context().variable_environment = environment;
pushed_environment_record = true; pushed_environment = true;
} }
push_scope({ scope_type, scope_node, pushed_environment_record }); push_scope({ scope_type, scope_node, pushed_environment });
} }
void Interpreter::exit_scope(const ScopeNode& scope_node) void Interpreter::exit_scope(const ScopeNode& scope_node)
@ -198,9 +198,9 @@ Value Interpreter::execute_statement(GlobalObject& global_object, const Statemen
return last_value; return last_value;
} }
FunctionEnvironmentRecord* Interpreter::current_function_environment_record() FunctionEnvironment* Interpreter::current_function_environment()
{ {
return verify_cast<FunctionEnvironmentRecord>(vm().running_execution_context().lexical_environment); return verify_cast<FunctionEnvironment>(vm().running_execution_context().lexical_environment);
} }
} }

View File

@ -15,7 +15,7 @@
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
#include <LibJS/Heap/DeferGC.h> #include <LibJS/Heap/DeferGC.h>
#include <LibJS/Heap/Heap.h> #include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h> #include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/ErrorTypes.h> #include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/Exception.h> #include <LibJS/Runtime/Exception.h>
#include <LibJS/Runtime/MarkedValueList.h> #include <LibJS/Runtime/MarkedValueList.h>
@ -56,9 +56,9 @@ public:
ALWAYS_INLINE Heap& heap() { return vm().heap(); } ALWAYS_INLINE Heap& heap() { return vm().heap(); }
ALWAYS_INLINE Exception* exception() { return vm().exception(); } ALWAYS_INLINE Exception* exception() { return vm().exception(); }
EnvironmentRecord* lexical_environment() { return vm().lexical_environment(); } Environment* lexical_environment() { return vm().lexical_environment(); }
FunctionEnvironmentRecord* current_function_environment_record(); FunctionEnvironment* current_function_environment();
void enter_scope(const ScopeNode&, ScopeType, GlobalObject&); void enter_scope(const ScopeNode&, ScopeType, GlobalObject&);
void exit_scope(const ScopeNode&); void exit_scope(const ScopeNode&);

View File

@ -15,14 +15,14 @@
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayPrototype.h> #include <LibJS/Runtime/ArrayPrototype.h>
#include <LibJS/Runtime/BoundFunction.h> #include <LibJS/Runtime/BoundFunction.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h> #include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/ErrorTypes.h> #include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h> #include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h> #include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/PropertyName.h> #include <LibJS/Runtime/PropertyName.h>
#include <LibJS/Runtime/ProxyObject.h> #include <LibJS/Runtime/ProxyObject.h>
@ -148,21 +148,21 @@ Object* get_prototype_from_constructor(GlobalObject& global_object, FunctionObje
} }
// 9.1.2.2 NewDeclarativeEnvironment ( E ), https://tc39.es/ecma262/#sec-newdeclarativeenvironment // 9.1.2.2 NewDeclarativeEnvironment ( E ), https://tc39.es/ecma262/#sec-newdeclarativeenvironment
DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord& environment_record) DeclarativeEnvironment* new_declarative_environment(Environment& environment)
{ {
auto& global_object = environment_record.global_object(); auto& global_object = environment.global_object();
return global_object.heap().allocate<DeclarativeEnvironmentRecord>(global_object, &environment_record); return global_object.heap().allocate<DeclarativeEnvironment>(global_object, &environment);
} }
// 9.1.2.3 NewObjectEnvironment ( O, W, E ), https://tc39.es/ecma262/#sec-newobjectenvironment // 9.1.2.3 NewObjectEnvironment ( O, W, E ), https://tc39.es/ecma262/#sec-newobjectenvironment
ObjectEnvironmentRecord* new_object_environment(Object& object, bool is_with_environment, EnvironmentRecord* environment_record) ObjectEnvironment* new_object_environment(Object& object, bool is_with_environment, Environment* environment)
{ {
auto& global_object = object.global_object(); auto& global_object = object.global_object();
return global_object.heap().allocate<ObjectEnvironmentRecord>(global_object, object, is_with_environment ? ObjectEnvironmentRecord::IsWithEnvironment::Yes : ObjectEnvironmentRecord::IsWithEnvironment::No, environment_record); return global_object.heap().allocate<ObjectEnvironment>(global_object, object, is_with_environment ? ObjectEnvironment::IsWithEnvironment::Yes : ObjectEnvironment::IsWithEnvironment::No, environment);
} }
// 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment // 9.4.3 GetThisEnvironment ( ), https://tc39.es/ecma262/#sec-getthisenvironment
EnvironmentRecord& get_this_environment(VM& vm) Environment& get_this_environment(VM& vm)
{ {
for (auto* env = vm.lexical_environment(); env; env = env->outer_environment()) { for (auto* env = vm.lexical_environment(); env; env = env->outer_environment()) {
if (env->has_this_binding()) if (env->has_this_binding())
@ -175,7 +175,7 @@ EnvironmentRecord& get_this_environment(VM& vm)
Object* get_super_constructor(VM& vm) Object* get_super_constructor(VM& vm)
{ {
auto& env = get_this_environment(vm); auto& env = get_this_environment(vm);
auto& active_function = verify_cast<FunctionEnvironmentRecord>(env).function_object(); auto& active_function = verify_cast<FunctionEnvironment>(env).function_object();
auto* super_constructor = active_function.prototype(); auto* super_constructor = active_function.prototype();
return super_constructor; return super_constructor;
} }
@ -202,7 +202,7 @@ Value perform_eval(Value x, GlobalObject& caller_realm, CallerMode strict_caller
if (direct == EvalMode::Direct) if (direct == EvalMode::Direct)
return interpreter.execute_statement(caller_realm, program).value_or(js_undefined()); return interpreter.execute_statement(caller_realm, program).value_or(js_undefined());
TemporaryChange scope_change(vm.running_execution_context().lexical_environment, static_cast<EnvironmentRecord*>(&caller_realm.environment_record())); TemporaryChange scope_change(vm.running_execution_context().lexical_environment, static_cast<Environment*>(&caller_realm.environment()));
return interpreter.execute_statement(caller_realm, program).value_or(js_undefined()); return interpreter.execute_statement(caller_realm, program).value_or(js_undefined());
} }
@ -234,7 +234,7 @@ Object* create_unmapped_arguments_object(GlobalObject& global_object, Vector<Val
} }
// 10.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env ), https://tc39.es/ecma262/#sec-createmappedargumentsobject // 10.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env ), https://tc39.es/ecma262/#sec-createmappedargumentsobject
Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObject& function, Vector<FunctionNode::Parameter> const& formals, Vector<Value> const& arguments, EnvironmentRecord&) Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObject& function, Vector<FunctionNode::Parameter> const& formals, Vector<Value> const& arguments, Environment&)
{ {
// FIXME: This implementation is incomplete and doesn't support the actual identifier mappings yet. // FIXME: This implementation is incomplete and doesn't support the actual identifier mappings yet.
(void)formals; (void)formals;

View File

@ -14,9 +14,9 @@
namespace JS { namespace JS {
DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord&); DeclarativeEnvironment* new_declarative_environment(Environment&);
ObjectEnvironmentRecord* new_object_environment(Object&, bool is_with_environment, EnvironmentRecord*); ObjectEnvironment* new_object_environment(Object&, bool is_with_environment, Environment*);
EnvironmentRecord& get_this_environment(VM&); Environment& get_this_environment(VM&);
Object* get_super_constructor(VM&); Object* get_super_constructor(VM&);
Value require_object_coercible(GlobalObject&, Value); Value require_object_coercible(GlobalObject&, Value);
size_t length_of_array_like(GlobalObject&, Object const&); size_t length_of_array_like(GlobalObject&, Object const&);
@ -25,7 +25,7 @@ FunctionObject* species_constructor(GlobalObject&, Object const&, FunctionObject
GlobalObject* get_function_realm(GlobalObject&, FunctionObject const&); GlobalObject* get_function_realm(GlobalObject&, FunctionObject const&);
Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)()); Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)());
Object* create_unmapped_arguments_object(GlobalObject&, Vector<Value> const& arguments); Object* create_unmapped_arguments_object(GlobalObject&, Vector<Value> const& arguments);
Object* create_mapped_arguments_object(GlobalObject&, FunctionObject&, Vector<FunctionNode::Parameter> const&, Vector<Value> const& arguments, EnvironmentRecord&); Object* create_mapped_arguments_object(GlobalObject&, FunctionObject&, Vector<FunctionNode::Parameter> const&, Vector<Value> const& arguments, Environment&);
enum class CallerMode { enum class CallerMode {
Strict, Strict,

View File

@ -44,9 +44,9 @@ Value BoundFunction::construct(FunctionObject& new_target)
return m_target_function->construct(new_target); return m_target_function->construct(new_target);
} }
FunctionEnvironmentRecord* BoundFunction::create_environment_record(FunctionObject& function_being_invoked) FunctionEnvironment* BoundFunction::create_environment(FunctionObject& function_being_invoked)
{ {
return m_target_function->create_environment_record(function_being_invoked); return m_target_function->create_environment(function_being_invoked);
} }
void BoundFunction::visit_edges(Visitor& visitor) void BoundFunction::visit_edges(Visitor& visitor)

View File

@ -22,7 +22,7 @@ public:
virtual Value construct(FunctionObject& new_target) override; virtual Value construct(FunctionObject& new_target) override;
virtual FunctionEnvironmentRecord* create_environment_record(FunctionObject&) override; virtual FunctionEnvironment* create_environment(FunctionObject&) override;
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;

View File

@ -5,7 +5,7 @@
*/ */
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h> #include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
@ -13,27 +13,27 @@
namespace JS { namespace JS {
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord() DeclarativeEnvironment::DeclarativeEnvironment()
: EnvironmentRecord(nullptr) : Environment(nullptr)
{ {
} }
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope) DeclarativeEnvironment::DeclarativeEnvironment(Environment* parent_scope)
: EnvironmentRecord(parent_scope) : Environment(parent_scope)
{ {
} }
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope) DeclarativeEnvironment::DeclarativeEnvironment(HashMap<FlyString, Variable> variables, Environment* parent_scope)
: EnvironmentRecord(parent_scope) : Environment(parent_scope)
, m_variables(move(variables)) , m_variables(move(variables))
{ {
} }
DeclarativeEnvironmentRecord::~DeclarativeEnvironmentRecord() DeclarativeEnvironment::~DeclarativeEnvironment()
{ {
} }
void DeclarativeEnvironmentRecord::visit_edges(Visitor& visitor) void DeclarativeEnvironment::visit_edges(Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
for (auto& it : m_variables) for (auto& it : m_variables)
@ -42,29 +42,29 @@ void DeclarativeEnvironmentRecord::visit_edges(Visitor& visitor)
visitor.visit(it.value.value); visitor.visit(it.value.value);
} }
Optional<Variable> DeclarativeEnvironmentRecord::get_from_environment_record(FlyString const& name) const Optional<Variable> DeclarativeEnvironment::get_from_environment(FlyString const& name) const
{ {
return m_variables.get(name); return m_variables.get(name);
} }
void DeclarativeEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable) void DeclarativeEnvironment::put_into_environment(FlyString const& name, Variable variable)
{ {
m_variables.set(name, variable); m_variables.set(name, variable);
} }
bool DeclarativeEnvironmentRecord::delete_from_environment_record(FlyString const& name) bool DeclarativeEnvironment::delete_from_environment(FlyString const& name)
{ {
return m_variables.remove(name); return m_variables.remove(name);
} }
// 9.1.1.1.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-hasbinding-n // 9.1.1.1.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-hasbinding-n
bool DeclarativeEnvironmentRecord::has_binding(FlyString const& name) const bool DeclarativeEnvironment::has_binding(FlyString const& name) const
{ {
return m_bindings.contains(name); return m_bindings.contains(name);
} }
// 9.1.1.1.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-declarative-environment-records-createmutablebinding-n-d // 9.1.1.1.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-declarative-environment-records-createmutablebinding-n-d
void DeclarativeEnvironmentRecord::create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) void DeclarativeEnvironment::create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted)
{ {
auto result = m_bindings.set(name, auto result = m_bindings.set(name,
Binding { Binding {
@ -78,7 +78,7 @@ void DeclarativeEnvironmentRecord::create_mutable_binding(GlobalObject&, FlyStri
} }
// 9.1.1.1.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-createimmutablebinding-n-s // 9.1.1.1.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-createimmutablebinding-n-s
void DeclarativeEnvironmentRecord::create_immutable_binding(GlobalObject&, FlyString const& name, bool strict) void DeclarativeEnvironment::create_immutable_binding(GlobalObject&, FlyString const& name, bool strict)
{ {
auto result = m_bindings.set(name, auto result = m_bindings.set(name,
Binding { Binding {
@ -92,7 +92,7 @@ void DeclarativeEnvironmentRecord::create_immutable_binding(GlobalObject&, FlySt
} }
// 9.1.1.1.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-declarative-environment-records-initializebinding-n-v // 9.1.1.1.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-declarative-environment-records-initializebinding-n-v
void DeclarativeEnvironmentRecord::initialize_binding(GlobalObject&, FlyString const& name, Value value) void DeclarativeEnvironment::initialize_binding(GlobalObject&, FlyString const& name, Value value)
{ {
auto it = m_bindings.find(name); auto it = m_bindings.find(name);
VERIFY(it != m_bindings.end()); VERIFY(it != m_bindings.end());
@ -102,7 +102,7 @@ void DeclarativeEnvironmentRecord::initialize_binding(GlobalObject&, FlyString c
} }
// 9.1.1.1.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-setmutablebinding-n-v-s // 9.1.1.1.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-setmutablebinding-n-v-s
void DeclarativeEnvironmentRecord::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict) void DeclarativeEnvironment::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict)
{ {
auto it = m_bindings.find(name); auto it = m_bindings.find(name);
if (it == m_bindings.end()) { if (it == m_bindings.end()) {
@ -133,7 +133,7 @@ void DeclarativeEnvironmentRecord::set_mutable_binding(GlobalObject& global_obje
} }
// 9.1.1.1.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-getbindingvalue-n-s // 9.1.1.1.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-getbindingvalue-n-s
Value DeclarativeEnvironmentRecord::get_binding_value(GlobalObject& global_object, FlyString const& name, bool) Value DeclarativeEnvironment::get_binding_value(GlobalObject& global_object, FlyString const& name, bool)
{ {
auto it = m_bindings.find(name); auto it = m_bindings.find(name);
VERIFY(it != m_bindings.end()); VERIFY(it != m_bindings.end());
@ -145,7 +145,7 @@ Value DeclarativeEnvironmentRecord::get_binding_value(GlobalObject& global_objec
} }
// 9.1.1.1.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-deletebinding-n // 9.1.1.1.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-deletebinding-n
bool DeclarativeEnvironmentRecord::delete_binding(GlobalObject&, FlyString const& name) bool DeclarativeEnvironment::delete_binding(GlobalObject&, FlyString const& name)
{ {
auto it = m_bindings.find(name); auto it = m_bindings.find(name);
VERIFY(it != m_bindings.end()); VERIFY(it != m_bindings.end());

View File

@ -8,7 +8,7 @@
#include <AK/FlyString.h> #include <AK/FlyString.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
namespace JS { namespace JS {
@ -21,19 +21,19 @@ struct Binding {
bool initialized { false }; bool initialized { false };
}; };
class DeclarativeEnvironmentRecord : public EnvironmentRecord { class DeclarativeEnvironment : public Environment {
JS_ENVIRONMENT_RECORD(DeclarativeEnvironmentRecord, EnvironmentRecord); JS_ENVIRONMENT(DeclarativeEnvironment, Environment);
public: public:
DeclarativeEnvironmentRecord(); DeclarativeEnvironment();
explicit DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope); explicit DeclarativeEnvironment(Environment* parent_scope);
DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope); DeclarativeEnvironment(HashMap<FlyString, Variable> variables, Environment* parent_scope);
virtual ~DeclarativeEnvironmentRecord() override; virtual ~DeclarativeEnvironment() override;
// ^EnvironmentRecord // ^Environment
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override; virtual Optional<Variable> get_from_environment(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override; virtual void put_into_environment(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override; virtual bool delete_from_environment(FlyString const&) override;
HashMap<FlyString, Variable> const& variables() const { return m_variables; } HashMap<FlyString, Variable> const& variables() const { return m_variables; }
@ -49,13 +49,13 @@ protected:
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
private: private:
virtual bool is_declarative_environment_record() const override { return true; } virtual bool is_declarative_environment() const override { return true; }
HashMap<FlyString, Variable> m_variables; HashMap<FlyString, Variable> m_variables;
HashMap<FlyString, Binding> m_bindings; HashMap<FlyString, Binding> m_bindings;
}; };
template<> template<>
inline bool EnvironmentRecord::fast_is<DeclarativeEnvironmentRecord>() const { return is_declarative_environment_record(); } inline bool Environment::fast_is<DeclarativeEnvironment>() const { return is_declarative_environment(); }
} }

View File

@ -4,23 +4,23 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/VM.h> #include <LibJS/Runtime/VM.h>
namespace JS { namespace JS {
EnvironmentRecord::EnvironmentRecord(EnvironmentRecord* outer_environment) Environment::Environment(Environment* outer_environment)
: m_outer_environment(outer_environment) : m_outer_environment(outer_environment)
{ {
} }
void EnvironmentRecord::initialize(GlobalObject& global_object) void Environment::initialize(GlobalObject& global_object)
{ {
m_global_object = &global_object; m_global_object = &global_object;
Cell::initialize(global_object); Cell::initialize(global_object);
} }
void EnvironmentRecord::visit_edges(Visitor& visitor) void Environment::visit_edges(Visitor& visitor)
{ {
Cell::visit_edges(visitor); Cell::visit_edges(visitor);
visitor.visit(m_outer_environment); visitor.visit(m_outer_environment);

View File

@ -15,21 +15,21 @@ struct Variable {
DeclarationKind declaration_kind; DeclarationKind declaration_kind;
}; };
#define JS_ENVIRONMENT_RECORD(class_, base_class) \ #define JS_ENVIRONMENT(class_, base_class) \
public: \ public: \
using Base = base_class; \ using Base = base_class; \
virtual char const* class_name() const override { return #class_; } virtual char const* class_name() const override { return #class_; }
class EnvironmentRecord : public Cell { class Environment : public Cell {
public: public:
GlobalObject& global_object() { return *m_global_object; } GlobalObject& global_object() { return *m_global_object; }
GlobalObject const& global_object() const { return *m_global_object; } GlobalObject const& global_object() const { return *m_global_object; }
virtual void initialize(GlobalObject&) override; virtual void initialize(GlobalObject&) override;
virtual Optional<Variable> get_from_environment_record(FlyString const&) const = 0; virtual Optional<Variable> get_from_environment(FlyString const&) const = 0;
virtual void put_into_environment_record(FlyString const&, Variable) = 0; virtual void put_into_environment(FlyString const&, Variable) = 0;
virtual bool delete_from_environment_record(FlyString const&) = 0; virtual bool delete_from_environment(FlyString const&) = 0;
virtual bool has_this_binding() const { return false; } virtual bool has_this_binding() const { return false; }
virtual Value get_this_binding(GlobalObject&) const { return {}; } virtual Value get_this_binding(GlobalObject&) const { return {}; }
@ -45,28 +45,28 @@ public:
virtual bool delete_binding(GlobalObject&, [[maybe_unused]] FlyString const& name) { return false; } virtual bool delete_binding(GlobalObject&, [[maybe_unused]] FlyString const& name) { return false; }
// [[OuterEnv]] // [[OuterEnv]]
EnvironmentRecord* outer_environment() { return m_outer_environment; } Environment* outer_environment() { return m_outer_environment; }
EnvironmentRecord const* outer_environment() const { return m_outer_environment; } Environment const* outer_environment() const { return m_outer_environment; }
virtual bool is_global_environment_record() const { return false; } virtual bool is_global_environment() const { return false; }
virtual bool is_declarative_environment_record() const { return false; } virtual bool is_declarative_environment() const { return false; }
virtual bool is_function_environment_record() const { return false; } virtual bool is_function_environment() const { return false; }
template<typename T> template<typename T>
bool fast_is() const = delete; bool fast_is() const = delete;
virtual char const* class_name() const override { return "EnvironmentRecord"; } virtual char const* class_name() const override { return "Environment"; }
protected: protected:
explicit EnvironmentRecord(EnvironmentRecord* parent); explicit Environment(Environment* parent);
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
private: private:
virtual bool is_environment_record() const final { return true; } virtual bool is_environment() const final { return true; }
GlobalObject* m_global_object { nullptr }; GlobalObject* m_global_object { nullptr };
EnvironmentRecord* m_outer_environment { nullptr }; Environment* m_outer_environment { nullptr };
}; };
} }

View File

@ -5,22 +5,22 @@
*/ */
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h> #include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
namespace JS { namespace JS {
FunctionEnvironmentRecord::FunctionEnvironmentRecord(EnvironmentRecord* parent_scope, HashMap<FlyString, Variable> variables) FunctionEnvironment::FunctionEnvironment(Environment* parent_scope, HashMap<FlyString, Variable> variables)
: DeclarativeEnvironmentRecord(variables, parent_scope) : DeclarativeEnvironment(variables, parent_scope)
{ {
} }
FunctionEnvironmentRecord::~FunctionEnvironmentRecord() FunctionEnvironment::~FunctionEnvironment()
{ {
} }
void FunctionEnvironmentRecord::visit_edges(Visitor& visitor) void FunctionEnvironment::visit_edges(Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_this_value); visitor.visit(m_this_value);
@ -29,7 +29,7 @@ void FunctionEnvironmentRecord::visit_edges(Visitor& visitor)
} }
// 9.1.1.3.5 GetSuperBase ( ), https://tc39.es/ecma262/#sec-getsuperbase // 9.1.1.3.5 GetSuperBase ( ), https://tc39.es/ecma262/#sec-getsuperbase
Value FunctionEnvironmentRecord::get_super_base() const Value FunctionEnvironment::get_super_base() const
{ {
VERIFY(m_function_object); VERIFY(m_function_object);
auto home_object = m_function_object->home_object(); auto home_object = m_function_object->home_object();
@ -39,7 +39,7 @@ Value FunctionEnvironmentRecord::get_super_base() const
} }
// 9.1.1.3.2 HasThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding // 9.1.1.3.2 HasThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hasthisbinding
bool FunctionEnvironmentRecord::has_this_binding() const bool FunctionEnvironment::has_this_binding() const
{ {
if (this_binding_status() == ThisBindingStatus::Lexical) if (this_binding_status() == ThisBindingStatus::Lexical)
return false; return false;
@ -47,7 +47,7 @@ bool FunctionEnvironmentRecord::has_this_binding() const
} }
// 9.1.1.3.3 HasSuperBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hassuperbinding // 9.1.1.3.3 HasSuperBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-hassuperbinding
bool FunctionEnvironmentRecord::has_super_binding() const bool FunctionEnvironment::has_super_binding() const
{ {
if (this_binding_status() == ThisBindingStatus::Lexical) if (this_binding_status() == ThisBindingStatus::Lexical)
return false; return false;
@ -57,7 +57,7 @@ bool FunctionEnvironmentRecord::has_super_binding() const
} }
// 9.1.1.3.4 GetThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding // 9.1.1.3.4 GetThisBinding ( ), https://tc39.es/ecma262/#sec-function-environment-records-getthisbinding
Value FunctionEnvironmentRecord::get_this_binding(GlobalObject& global_object) const Value FunctionEnvironment::get_this_binding(GlobalObject& global_object) const
{ {
VERIFY(has_this_binding()); VERIFY(has_this_binding());
if (this_binding_status() == ThisBindingStatus::Uninitialized) { if (this_binding_status() == ThisBindingStatus::Uninitialized) {
@ -68,7 +68,7 @@ Value FunctionEnvironmentRecord::get_this_binding(GlobalObject& global_object) c
} }
// 9.1.1.3.1 BindThisValue ( V ), https://tc39.es/ecma262/#sec-bindthisvalue // 9.1.1.3.1 BindThisValue ( V ), https://tc39.es/ecma262/#sec-bindthisvalue
Value FunctionEnvironmentRecord::bind_this_value(GlobalObject& global_object, Value this_value) Value FunctionEnvironment::bind_this_value(GlobalObject& global_object, Value this_value)
{ {
VERIFY(this_binding_status() != ThisBindingStatus::Lexical); VERIFY(this_binding_status() != ThisBindingStatus::Lexical);
if (this_binding_status() == ThisBindingStatus::Initialized) { if (this_binding_status() == ThisBindingStatus::Initialized) {

View File

@ -6,12 +6,12 @@
#pragma once #pragma once
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h> #include <LibJS/Runtime/DeclarativeEnvironment.h>
namespace JS { namespace JS {
class FunctionEnvironmentRecord final : public DeclarativeEnvironmentRecord { class FunctionEnvironment final : public DeclarativeEnvironment {
JS_ENVIRONMENT_RECORD(FunctionEnvironmentRecord, DeclarativeEnvironmentRecord); JS_ENVIRONMENT(FunctionEnvironment, DeclarativeEnvironment);
public: public:
enum class ThisBindingStatus : u8 { enum class ThisBindingStatus : u8 {
@ -20,8 +20,8 @@ public:
Uninitialized, Uninitialized,
}; };
FunctionEnvironmentRecord(EnvironmentRecord* parent_scope, HashMap<FlyString, Variable> variables); FunctionEnvironment(Environment* parent_scope, HashMap<FlyString, Variable> variables);
virtual ~FunctionEnvironmentRecord() override; virtual ~FunctionEnvironment() override;
// [[ThisValue]] // [[ThisValue]]
Value this_value() const { return m_this_value; } Value this_value() const { return m_this_value; }
@ -51,7 +51,7 @@ public:
Value bind_this_value(GlobalObject&, Value); Value bind_this_value(GlobalObject&, Value);
private: private:
virtual bool is_function_environment_record() const override { return true; } virtual bool is_function_environment() const override { return true; }
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
Value m_this_value; Value m_this_value;
@ -61,6 +61,6 @@ private:
}; };
template<> template<>
inline bool EnvironmentRecord::fast_is<FunctionEnvironmentRecord>() const { return is_function_environment_record(); } inline bool Environment::fast_is<FunctionEnvironment>() const { return is_function_environment(); }
} }

View File

@ -26,7 +26,7 @@ public:
virtual Value call() = 0; virtual Value call() = 0;
virtual Value construct(FunctionObject& new_target) = 0; virtual Value construct(FunctionObject& new_target) = 0;
virtual const FlyString& name() const = 0; virtual const FlyString& name() const = 0;
virtual FunctionEnvironmentRecord* create_environment_record(FunctionObject&) = 0; virtual FunctionEnvironment* create_environment(FunctionObject&) = 0;
BoundFunction* bind(Value bound_this_value, Vector<Value> arguments); BoundFunction* bind(Value bound_this_value, Vector<Value> arguments);
@ -45,7 +45,7 @@ public:
// [[Environment]] // [[Environment]]
// The Environment Record that the function was closed over. // The Environment Record that the function was closed over.
// Used as the outer environment when evaluating the code of the function. // Used as the outer environment when evaluating the code of the function.
virtual EnvironmentRecord* environment() { return nullptr; } virtual Environment* environment() { return nullptr; }
// [[Realm]] // [[Realm]]
virtual GlobalObject* realm() const { return nullptr; } virtual GlobalObject* realm() const { return nullptr; }

View File

@ -13,7 +13,7 @@
namespace JS { namespace JS {
GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value initial_value, OrdinaryFunctionObject* generating_function, EnvironmentRecord* generating_scope, Bytecode::RegisterWindow frame) GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value initial_value, OrdinaryFunctionObject* generating_function, Environment* generating_scope, Bytecode::RegisterWindow frame)
{ {
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) // This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
auto generating_function_proto_property = generating_function->get(global_object.vm().names.prototype).to_object(global_object); auto generating_function_proto_property = generating_function->get(global_object.vm().names.prototype).to_object(global_object);
@ -22,7 +22,7 @@ GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value init
auto object = global_object.heap().allocate<GeneratorObject>(global_object, global_object, *generating_function_proto_property); auto object = global_object.heap().allocate<GeneratorObject>(global_object, global_object, *generating_function_proto_property);
object->m_generating_function = generating_function; object->m_generating_function = generating_function;
object->m_environment_record = generating_scope; object->m_environment = generating_scope;
object->m_frame = move(frame); object->m_frame = move(frame);
object->m_previous_value = initial_value; object->m_previous_value = initial_value;
return object; return object;
@ -44,7 +44,7 @@ GeneratorObject::~GeneratorObject()
void GeneratorObject::visit_edges(Cell::Visitor& visitor) void GeneratorObject::visit_edges(Cell::Visitor& visitor)
{ {
Object::visit_edges(visitor); Object::visit_edges(visitor);
visitor.visit(m_environment_record); visitor.visit(m_environment);
visitor.visit(m_generating_function); visitor.visit(m_generating_function);
if (m_previous_value.is_object()) if (m_previous_value.is_object())
visitor.visit(&m_previous_value.as_object()); visitor.visit(&m_previous_value.as_object());
@ -107,7 +107,7 @@ Value GeneratorObject::next_impl(VM& vm, GlobalObject& global_object, Optional<V
} }
// Temporarily switch to the captured environment record // Temporarily switch to the captured environment record
TemporaryChange change { vm.running_execution_context().lexical_environment, m_environment_record }; TemporaryChange change { vm.running_execution_context().lexical_environment, m_environment };
m_previous_value = bytecode_interpreter->run(*m_generating_function->bytecode_executable(), next_block); m_previous_value = bytecode_interpreter->run(*m_generating_function->bytecode_executable(), next_block);

View File

@ -15,7 +15,7 @@ class GeneratorObject final : public Object {
JS_OBJECT(GeneratorObject, Object); JS_OBJECT(GeneratorObject, Object);
public: public:
static GeneratorObject* create(GlobalObject&, Value, OrdinaryFunctionObject*, EnvironmentRecord*, Bytecode::RegisterWindow); static GeneratorObject* create(GlobalObject&, Value, OrdinaryFunctionObject*, Environment*, Bytecode::RegisterWindow);
GeneratorObject(GlobalObject&, Object& prototype); GeneratorObject(GlobalObject&, Object& prototype);
virtual void initialize(GlobalObject&) override; virtual void initialize(GlobalObject&) override;
virtual ~GeneratorObject() override; virtual ~GeneratorObject() override;
@ -25,7 +25,7 @@ public:
void set_done() { m_done = true; } void set_done() { m_done = true; }
private: private:
EnvironmentRecord* m_environment_record { nullptr }; Environment* m_environment { nullptr };
OrdinaryFunctionObject* m_generating_function { nullptr }; OrdinaryFunctionObject* m_generating_function { nullptr };
Value m_previous_value; Value m_previous_value;
Bytecode::RegisterWindow m_frame; Bytecode::RegisterWindow m_frame;

View File

@ -5,57 +5,57 @@
*/ */
#include <LibJS/AST.h> #include <LibJS/AST.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h> #include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h> #include <LibJS/Runtime/ObjectEnvironment.h>
namespace JS { namespace JS {
GlobalEnvironmentRecord::GlobalEnvironmentRecord(GlobalObject& global_object) GlobalEnvironment::GlobalEnvironment(GlobalObject& global_object)
: EnvironmentRecord(nullptr) : Environment(nullptr)
{ {
m_object_record = global_object.heap().allocate<ObjectEnvironmentRecord>(global_object, global_object, ObjectEnvironmentRecord::IsWithEnvironment::No, nullptr); m_object_record = global_object.heap().allocate<ObjectEnvironment>(global_object, global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr);
m_declarative_record = global_object.heap().allocate<DeclarativeEnvironmentRecord>(global_object); m_declarative_record = global_object.heap().allocate<DeclarativeEnvironment>(global_object);
} }
void GlobalEnvironmentRecord::visit_edges(Cell::Visitor& visitor) void GlobalEnvironment::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_object_record); visitor.visit(m_object_record);
visitor.visit(m_declarative_record); visitor.visit(m_declarative_record);
} }
Optional<Variable> GlobalEnvironmentRecord::get_from_environment_record(FlyString const& name) const Optional<Variable> GlobalEnvironment::get_from_environment(FlyString const& name) const
{ {
// FIXME: This should be a "composite" of the object record and the declarative record. // FIXME: This should be a "composite" of the object record and the declarative record.
return m_object_record->get_from_environment_record(name); return m_object_record->get_from_environment(name);
} }
void GlobalEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable) void GlobalEnvironment::put_into_environment(FlyString const& name, Variable variable)
{ {
// FIXME: This should be a "composite" of the object record and the declarative record. // FIXME: This should be a "composite" of the object record and the declarative record.
m_object_record->put_into_environment_record(name, variable); m_object_record->put_into_environment(name, variable);
} }
bool GlobalEnvironmentRecord::delete_from_environment_record(FlyString const& name) bool GlobalEnvironment::delete_from_environment(FlyString const& name)
{ {
// FIXME: This should be a "composite" of the object record and the declarative record. // FIXME: This should be a "composite" of the object record and the declarative record.
return object_record().delete_from_environment_record(name); return object_record().delete_from_environment(name);
} }
Value GlobalEnvironmentRecord::get_this_binding(GlobalObject&) const Value GlobalEnvironment::get_this_binding(GlobalObject&) const
{ {
return &global_object(); return &global_object();
} }
Value GlobalEnvironmentRecord::global_this_value() const Value GlobalEnvironment::global_this_value() const
{ {
return &global_object(); return &global_object();
} }
// 9.1.1.4.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-hasbinding-n // 9.1.1.4.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-hasbinding-n
bool GlobalEnvironmentRecord::has_binding(FlyString const& name) const bool GlobalEnvironment::has_binding(FlyString const& name) const
{ {
if (m_declarative_record->has_binding(name)) if (m_declarative_record->has_binding(name))
return true; return true;
@ -63,7 +63,7 @@ bool GlobalEnvironmentRecord::has_binding(FlyString const& name) const
} }
// 9.1.1.4.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-global-environment-records-createmutablebinding-n-d // 9.1.1.4.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-global-environment-records-createmutablebinding-n-d
void GlobalEnvironmentRecord::create_mutable_binding(GlobalObject& global_object, FlyString const& name, bool can_be_deleted) void GlobalEnvironment::create_mutable_binding(GlobalObject& global_object, FlyString const& name, bool can_be_deleted)
{ {
if (m_declarative_record->has_binding(name)) { if (m_declarative_record->has_binding(name)) {
global_object.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorString); global_object.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
@ -73,7 +73,7 @@ void GlobalEnvironmentRecord::create_mutable_binding(GlobalObject& global_object
} }
// 9.1.1.4.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-createimmutablebinding-n-s // 9.1.1.4.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-createimmutablebinding-n-s
void GlobalEnvironmentRecord::create_immutable_binding(GlobalObject& global_object, FlyString const& name, bool strict) void GlobalEnvironment::create_immutable_binding(GlobalObject& global_object, FlyString const& name, bool strict)
{ {
if (m_declarative_record->has_binding(name)) { if (m_declarative_record->has_binding(name)) {
global_object.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorString); global_object.vm().throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
@ -83,7 +83,7 @@ void GlobalEnvironmentRecord::create_immutable_binding(GlobalObject& global_obje
} }
// 9.1.1.4.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-global-environment-records-initializebinding-n-v // 9.1.1.4.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-global-environment-records-initializebinding-n-v
void GlobalEnvironmentRecord::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value) void GlobalEnvironment::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value)
{ {
if (m_declarative_record->has_binding(name)) { if (m_declarative_record->has_binding(name)) {
m_declarative_record->initialize_binding(global_object, name, value); m_declarative_record->initialize_binding(global_object, name, value);
@ -93,7 +93,7 @@ void GlobalEnvironmentRecord::initialize_binding(GlobalObject& global_object, Fl
} }
// 9.1.1.4.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-global-environment-records-setmutablebinding-n-v-s // 9.1.1.4.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-global-environment-records-setmutablebinding-n-v-s
void GlobalEnvironmentRecord::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict) void GlobalEnvironment::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict)
{ {
if (m_declarative_record->has_binding(name)) { if (m_declarative_record->has_binding(name)) {
m_declarative_record->set_mutable_binding(global_object, name, value, strict); m_declarative_record->set_mutable_binding(global_object, name, value, strict);
@ -104,7 +104,7 @@ void GlobalEnvironmentRecord::set_mutable_binding(GlobalObject& global_object, F
} }
// 9.1.1.4.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-getbindingvalue-n-s // 9.1.1.4.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-getbindingvalue-n-s
Value GlobalEnvironmentRecord::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict) Value GlobalEnvironment::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict)
{ {
if (m_declarative_record->has_binding(name)) if (m_declarative_record->has_binding(name))
return m_declarative_record->get_binding_value(global_object, name, strict); return m_declarative_record->get_binding_value(global_object, name, strict);
@ -112,7 +112,7 @@ Value GlobalEnvironmentRecord::get_binding_value(GlobalObject& global_object, Fl
} }
// 9.1.1.4.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-deletebinding-n // 9.1.1.4.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-deletebinding-n
bool GlobalEnvironmentRecord::delete_binding(GlobalObject& global_object, FlyString const& name) bool GlobalEnvironment::delete_binding(GlobalObject& global_object, FlyString const& name)
{ {
if (m_declarative_record->has_binding(name)) if (m_declarative_record->has_binding(name))
return m_declarative_record->delete_binding(global_object, name); return m_declarative_record->delete_binding(global_object, name);
@ -129,19 +129,19 @@ bool GlobalEnvironmentRecord::delete_binding(GlobalObject& global_object, FlyStr
} }
// 9.1.1.4.12 HasVarDeclaration ( N ), https://tc39.es/ecma262/#sec-hasvardeclaration // 9.1.1.4.12 HasVarDeclaration ( N ), https://tc39.es/ecma262/#sec-hasvardeclaration
bool GlobalEnvironmentRecord::has_var_declaration(FlyString const& name) const bool GlobalEnvironment::has_var_declaration(FlyString const& name) const
{ {
return m_var_names.contains_slow(name); return m_var_names.contains_slow(name);
} }
// 9.1.1.4.13 HasLexicalDeclaration ( N ), https://tc39.es/ecma262/#sec-haslexicaldeclaration // 9.1.1.4.13 HasLexicalDeclaration ( N ), https://tc39.es/ecma262/#sec-haslexicaldeclaration
bool GlobalEnvironmentRecord::has_lexical_declaration(FlyString const& name) const bool GlobalEnvironment::has_lexical_declaration(FlyString const& name) const
{ {
return m_declarative_record->has_binding(name); return m_declarative_record->has_binding(name);
} }
// 9.1.1.4.14 HasRestrictedGlobalProperty ( N ), https://tc39.es/ecma262/#sec-hasrestrictedglobalproperty // 9.1.1.4.14 HasRestrictedGlobalProperty ( N ), https://tc39.es/ecma262/#sec-hasrestrictedglobalproperty
bool GlobalEnvironmentRecord::has_restricted_global_property(FlyString const& name) const bool GlobalEnvironment::has_restricted_global_property(FlyString const& name) const
{ {
auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name); auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name);
if (!existing_prop.has_value() || existing_prop.value().value.is_undefined()) if (!existing_prop.has_value() || existing_prop.value().value.is_undefined())
@ -152,7 +152,7 @@ bool GlobalEnvironmentRecord::has_restricted_global_property(FlyString const& na
} }
// 9.1.1.4.15 CanDeclareGlobalVar ( N ), https://tc39.es/ecma262/#sec-candeclareglobalvar // 9.1.1.4.15 CanDeclareGlobalVar ( N ), https://tc39.es/ecma262/#sec-candeclareglobalvar
bool GlobalEnvironmentRecord::can_declare_global_var(FlyString const& name) const bool GlobalEnvironment::can_declare_global_var(FlyString const& name) const
{ {
bool has_property = m_object_record->binding_object().has_own_property(name); bool has_property = m_object_record->binding_object().has_own_property(name);
if (has_property) if (has_property)
@ -161,7 +161,7 @@ bool GlobalEnvironmentRecord::can_declare_global_var(FlyString const& name) cons
} }
// 9.1.1.4.16 CanDeclareGlobalFunction ( N ), https://tc39.es/ecma262/#sec-candeclareglobalfunction // 9.1.1.4.16 CanDeclareGlobalFunction ( N ), https://tc39.es/ecma262/#sec-candeclareglobalfunction
bool GlobalEnvironmentRecord::can_declare_global_function(FlyString const& name) const bool GlobalEnvironment::can_declare_global_function(FlyString const& name) const
{ {
auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name); auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name);
if (!existing_prop.has_value() || existing_prop.value().value.is_undefined()) if (!existing_prop.has_value() || existing_prop.value().value.is_undefined())
@ -174,7 +174,7 @@ bool GlobalEnvironmentRecord::can_declare_global_function(FlyString const& name)
} }
// 9.1.1.4.17 CreateGlobalVarBinding ( N, D ), https://tc39.es/ecma262/#sec-createglobalvarbinding // 9.1.1.4.17 CreateGlobalVarBinding ( N, D ), https://tc39.es/ecma262/#sec-createglobalvarbinding
void GlobalEnvironmentRecord::create_global_var_binding(FlyString const& name, bool can_be_deleted) void GlobalEnvironment::create_global_var_binding(FlyString const& name, bool can_be_deleted)
{ {
bool has_property = m_object_record->binding_object().has_own_property(name); bool has_property = m_object_record->binding_object().has_own_property(name);
bool extensible = m_object_record->binding_object().is_extensible(); bool extensible = m_object_record->binding_object().is_extensible();
@ -187,7 +187,7 @@ void GlobalEnvironmentRecord::create_global_var_binding(FlyString const& name, b
} }
// 9.1.1.4.18 CreateGlobalFunctionBinding ( N, V, D ), https://tc39.es/ecma262/#sec-createglobalfunctionbinding // 9.1.1.4.18 CreateGlobalFunctionBinding ( N, V, D ), https://tc39.es/ecma262/#sec-createglobalfunctionbinding
void GlobalEnvironmentRecord::create_global_function_binding(FlyString const& name, Value value, bool can_be_deleted) void GlobalEnvironment::create_global_function_binding(FlyString const& name, Value value, bool can_be_deleted)
{ {
auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name); auto existing_prop = m_object_record->binding_object().get_own_property_descriptor(name);
PropertyDescriptor desc; PropertyDescriptor desc;

View File

@ -6,19 +6,19 @@
#pragma once #pragma once
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
namespace JS { namespace JS {
class GlobalEnvironmentRecord final : public EnvironmentRecord { class GlobalEnvironment final : public Environment {
JS_ENVIRONMENT_RECORD(GlobalEnvironmentRecord, EnvironmentRecord); JS_ENVIRONMENT(GlobalEnvironment, Environment);
public: public:
explicit GlobalEnvironmentRecord(GlobalObject&); explicit GlobalEnvironment(GlobalObject&);
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override; virtual Optional<Variable> get_from_environment(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override; virtual void put_into_environment(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override; virtual bool delete_from_environment(FlyString const&) override;
virtual bool has_this_binding() const final { return true; } virtual bool has_this_binding() const final { return true; }
virtual Value get_this_binding(GlobalObject&) const final; virtual Value get_this_binding(GlobalObject&) const final;
@ -33,10 +33,10 @@ public:
Value global_this_value() const; Value global_this_value() const;
// [[ObjectRecord]] // [[ObjectRecord]]
ObjectEnvironmentRecord& object_record() { return *m_object_record; } ObjectEnvironment& object_record() { return *m_object_record; }
// [[DeclarativeRecord]] // [[DeclarativeRecord]]
DeclarativeEnvironmentRecord& declarative_record() { return *m_declarative_record; } DeclarativeEnvironment& declarative_record() { return *m_declarative_record; }
bool has_var_declaration(FlyString const& name) const; bool has_var_declaration(FlyString const& name) const;
bool has_lexical_declaration(FlyString const& name) const; bool has_lexical_declaration(FlyString const& name) const;
@ -47,15 +47,15 @@ public:
void create_global_function_binding(FlyString const& name, Value, bool can_be_deleted); void create_global_function_binding(FlyString const& name, Value, bool can_be_deleted);
private: private:
virtual bool is_global_environment_record() const override { return true; } virtual bool is_global_environment() const override { return true; }
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
ObjectEnvironmentRecord* m_object_record { nullptr }; ObjectEnvironment* m_object_record { nullptr };
DeclarativeEnvironmentRecord* m_declarative_record { nullptr }; DeclarativeEnvironment* m_declarative_record { nullptr };
Vector<FlyString> m_var_names; Vector<FlyString> m_var_names;
}; };
template<> template<>
inline bool EnvironmentRecord::fast_is<GlobalEnvironmentRecord>() const { return is_global_environment_record(); } inline bool Environment::fast_is<GlobalEnvironment>() const { return is_global_environment(); }
} }

View File

@ -40,7 +40,7 @@
#include <LibJS/Runtime/GeneratorFunctionConstructor.h> #include <LibJS/Runtime/GeneratorFunctionConstructor.h>
#include <LibJS/Runtime/GeneratorFunctionPrototype.h> #include <LibJS/Runtime/GeneratorFunctionPrototype.h>
#include <LibJS/Runtime/GeneratorObjectPrototype.h> #include <LibJS/Runtime/GeneratorObjectPrototype.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorPrototype.h> #include <LibJS/Runtime/IteratorPrototype.h>
#include <LibJS/Runtime/JSONObject.h> #include <LibJS/Runtime/JSONObject.h>
@ -99,7 +99,7 @@ void GlobalObject::initialize_global_object()
m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(*this); m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(*this);
m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(*this); m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(*this);
m_environment_record = heap().allocate<GlobalEnvironmentRecord>(*this, *this); m_environment = heap().allocate<GlobalEnvironment>(*this, *this);
m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(*this); m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(*this);
m_new_object_shape->set_prototype_without_transition(m_object_prototype); m_new_object_shape->set_prototype_without_transition(m_object_prototype);
@ -225,7 +225,7 @@ void GlobalObject::visit_edges(Visitor& visitor)
visitor.visit(m_new_ordinary_function_prototype_object_shape); visitor.visit(m_new_ordinary_function_prototype_object_shape);
visitor.visit(m_proxy_constructor); visitor.visit(m_proxy_constructor);
visitor.visit(m_generator_object_prototype); visitor.visit(m_generator_object_prototype);
visitor.visit(m_environment_record); visitor.visit(m_environment);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
visitor.visit(m_##snake_name##_constructor); \ visitor.visit(m_##snake_name##_constructor); \

View File

@ -7,7 +7,7 @@
#pragma once #pragma once
#include <LibJS/Heap/Heap.h> #include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/VM.h> #include <LibJS/Runtime/VM.h>
namespace JS { namespace JS {
@ -21,7 +21,7 @@ public:
virtual ~GlobalObject() override; virtual ~GlobalObject() override;
GlobalEnvironmentRecord& environment_record() { return *m_environment_record; } GlobalEnvironment& environment() { return *m_environment; }
Console& console() { return *m_console; } Console& console() { return *m_console; }
@ -87,7 +87,7 @@ private:
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
GeneratorObjectPrototype* m_generator_object_prototype { nullptr }; GeneratorObjectPrototype* m_generator_object_prototype { nullptr };
GlobalEnvironmentRecord* m_environment_record { nullptr }; GlobalEnvironment* m_environment { nullptr };
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
ConstructorName* m_##snake_name##_constructor { nullptr }; \ ConstructorName* m_##snake_name##_constructor { nullptr }; \

View File

@ -47,7 +47,7 @@ Value NativeFunction::construct(FunctionObject&)
return {}; return {};
} }
FunctionEnvironmentRecord* NativeFunction::create_environment_record(FunctionObject&) FunctionEnvironment* NativeFunction::create_environment(FunctionObject&)
{ {
return nullptr; return nullptr;
} }

View File

@ -36,7 +36,7 @@ protected:
explicit NativeFunction(Object& prototype); explicit NativeFunction(Object& prototype);
private: private:
virtual FunctionEnvironmentRecord* create_environment_record(FunctionObject&) override final; virtual FunctionEnvironment* create_environment(FunctionObject&) override final;
virtual bool is_native_function() const final { return true; } virtual bool is_native_function() const final { return true; }
FlyString m_name; FlyString m_name;

View File

@ -6,24 +6,24 @@
#include <LibJS/AST.h> #include <LibJS/AST.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h> #include <LibJS/Runtime/ObjectEnvironment.h>
namespace JS { namespace JS {
ObjectEnvironmentRecord::ObjectEnvironmentRecord(Object& binding_object, IsWithEnvironment is_with_environment, EnvironmentRecord* outer_environment) ObjectEnvironment::ObjectEnvironment(Object& binding_object, IsWithEnvironment is_with_environment, Environment* outer_environment)
: EnvironmentRecord(outer_environment) : Environment(outer_environment)
, m_binding_object(binding_object) , m_binding_object(binding_object)
, m_with_environment(is_with_environment == IsWithEnvironment::Yes) , m_with_environment(is_with_environment == IsWithEnvironment::Yes)
{ {
} }
void ObjectEnvironmentRecord::visit_edges(Cell::Visitor& visitor) void ObjectEnvironment::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(&m_binding_object); visitor.visit(&m_binding_object);
} }
Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyString const& name) const Optional<Variable> ObjectEnvironment::get_from_environment(FlyString const& name) const
{ {
auto value = m_binding_object.get(name); auto value = m_binding_object.get(name);
if (value.is_empty()) if (value.is_empty())
@ -31,18 +31,18 @@ Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyStrin
return Variable { value, DeclarationKind::Var }; return Variable { value, DeclarationKind::Var };
} }
void ObjectEnvironmentRecord::put_into_environment_record(FlyString const& name, Variable variable) void ObjectEnvironment::put_into_environment(FlyString const& name, Variable variable)
{ {
m_binding_object.put(name, variable.value); m_binding_object.put(name, variable.value);
} }
bool ObjectEnvironmentRecord::delete_from_environment_record(FlyString const& name) bool ObjectEnvironment::delete_from_environment(FlyString const& name)
{ {
return m_binding_object.delete_property(name); return m_binding_object.delete_property(name);
} }
// 9.1.1.2.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-hasbinding-n // 9.1.1.2.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-hasbinding-n
bool ObjectEnvironmentRecord::has_binding(FlyString const& name) const bool ObjectEnvironment::has_binding(FlyString const& name) const
{ {
bool found_binding = m_binding_object.has_property(name); bool found_binding = m_binding_object.has_property(name);
if (!found_binding) if (!found_binding)
@ -54,7 +54,7 @@ bool ObjectEnvironmentRecord::has_binding(FlyString const& name) const
} }
// 9.1.1.2.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-object-environment-records-createmutablebinding-n-d // 9.1.1.2.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-object-environment-records-createmutablebinding-n-d
void ObjectEnvironmentRecord::create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) void ObjectEnvironment::create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted)
{ {
PropertyAttributes attributes; PropertyAttributes attributes;
attributes.set_enumerable(); attributes.set_enumerable();
@ -68,20 +68,20 @@ void ObjectEnvironmentRecord::create_mutable_binding(GlobalObject&, FlyString co
} }
// 9.1.1.2.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-createimmutablebinding-n-s // 9.1.1.2.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-createimmutablebinding-n-s
void ObjectEnvironmentRecord::create_immutable_binding(GlobalObject&, FlyString const&, bool) void ObjectEnvironment::create_immutable_binding(GlobalObject&, FlyString const&, bool)
{ {
// "The CreateImmutableBinding concrete method of an object Environment Record is never used within this specification." // "The CreateImmutableBinding concrete method of an object Environment Record is never used within this specification."
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
// 9.1.1.2.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-object-environment-records-initializebinding-n-v // 9.1.1.2.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-object-environment-records-initializebinding-n-v
void ObjectEnvironmentRecord::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value) void ObjectEnvironment::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value)
{ {
set_mutable_binding(global_object, name, value, false); set_mutable_binding(global_object, name, value, false);
} }
// 9.1.1.2.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-object-environment-records-setmutablebinding-n-v-s // 9.1.1.2.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-object-environment-records-setmutablebinding-n-v-s
void ObjectEnvironmentRecord::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict) void ObjectEnvironment::set_mutable_binding(GlobalObject& global_object, FlyString const& name, Value value, bool strict)
{ {
bool still_exists = m_binding_object.has_property(name); bool still_exists = m_binding_object.has_property(name);
if (!still_exists && strict) { if (!still_exists && strict) {
@ -94,7 +94,7 @@ void ObjectEnvironmentRecord::set_mutable_binding(GlobalObject& global_object, F
} }
// 9.1.1.2.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-getbindingvalue-n-s // 9.1.1.2.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-getbindingvalue-n-s
Value ObjectEnvironmentRecord::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict) Value ObjectEnvironment::get_binding_value(GlobalObject& global_object, FlyString const& name, bool strict)
{ {
if (!m_binding_object.has_property(name)) { if (!m_binding_object.has_property(name)) {
if (!strict) if (!strict)
@ -108,7 +108,7 @@ Value ObjectEnvironmentRecord::get_binding_value(GlobalObject& global_object, Fl
} }
// 9.1.1.2.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-deletebinding-n // 9.1.1.2.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-deletebinding-n
bool ObjectEnvironmentRecord::delete_binding(GlobalObject&, FlyString const& name) bool ObjectEnvironment::delete_binding(GlobalObject&, FlyString const& name)
{ {
return m_binding_object.delete_property(name); return m_binding_object.delete_property(name);
} }

View File

@ -6,23 +6,23 @@
#pragma once #pragma once
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
namespace JS { namespace JS {
class ObjectEnvironmentRecord : public EnvironmentRecord { class ObjectEnvironment : public Environment {
JS_ENVIRONMENT_RECORD(ObjectEnvironmentRecord, EnvironmentRecord); JS_ENVIRONMENT(ObjectEnvironment, Environment);
public: public:
enum class IsWithEnvironment { enum class IsWithEnvironment {
No, No,
Yes, Yes,
}; };
ObjectEnvironmentRecord(Object& binding_object, IsWithEnvironment, EnvironmentRecord* outer_environment); ObjectEnvironment(Object& binding_object, IsWithEnvironment, Environment* outer_environment);
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override; virtual Optional<Variable> get_from_environment(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override; virtual void put_into_environment(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override; virtual bool delete_from_environment(FlyString const&) override;
virtual bool has_binding(FlyString const& name) const override; virtual bool has_binding(FlyString const& name) const override;
virtual void create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) override; virtual void create_mutable_binding(GlobalObject&, FlyString const& name, bool can_be_deleted) override;

View File

@ -14,7 +14,7 @@
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h> #include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GeneratorObject.h> #include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/GeneratorObjectPrototype.h> #include <LibJS/Runtime/GeneratorObjectPrototype.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
@ -36,7 +36,7 @@ static OrdinaryFunctionObject* typed_this(VM& vm, GlobalObject& global_object)
return static_cast<OrdinaryFunctionObject*>(this_object); return static_cast<OrdinaryFunctionObject*>(this_object);
} }
OrdinaryFunctionObject* OrdinaryFunctionObject::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, FunctionKind kind, bool is_strict, bool is_arrow_function) OrdinaryFunctionObject* OrdinaryFunctionObject::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, FunctionKind kind, bool is_strict, bool is_arrow_function)
{ {
Object* prototype = nullptr; Object* prototype = nullptr;
switch (kind) { switch (kind) {
@ -50,7 +50,7 @@ OrdinaryFunctionObject* OrdinaryFunctionObject::create(GlobalObject& global_obje
return global_object.heap().allocate<OrdinaryFunctionObject>(global_object, global_object, name, body, move(parameters), m_function_length, parent_scope, *prototype, kind, is_strict, is_arrow_function); return global_object.heap().allocate<OrdinaryFunctionObject>(global_object, global_object, name, body, move(parameters), m_function_length, parent_scope, *prototype, kind, is_strict, is_arrow_function);
} }
OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 function_length, EnvironmentRecord* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function) OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 function_length, Environment* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function)
: FunctionObject(is_arrow_function ? vm().this_value(global_object) : Value(), {}, prototype) : FunctionObject(is_arrow_function ? vm().this_value(global_object) : Value(), {}, prototype)
, m_name(name) , m_name(name)
, m_body(body) , m_body(body)
@ -113,7 +113,7 @@ void OrdinaryFunctionObject::visit_edges(Visitor& visitor)
visitor.visit(m_environment); visitor.visit(m_environment);
} }
FunctionEnvironmentRecord* OrdinaryFunctionObject::create_environment_record(FunctionObject& function_being_invoked) FunctionEnvironment* OrdinaryFunctionObject::create_environment(FunctionObject& function_being_invoked)
{ {
HashMap<FlyString, Variable> variables; HashMap<FlyString, Variable> variables;
for (auto& parameter : m_parameters) { for (auto& parameter : m_parameters) {
@ -142,11 +142,11 @@ FunctionEnvironmentRecord* OrdinaryFunctionObject::create_environment_record(Fun
} }
} }
auto* environment = heap().allocate<FunctionEnvironmentRecord>(global_object(), m_environment, variables); auto* environment = heap().allocate<FunctionEnvironment>(global_object(), m_environment, variables);
environment->set_function_object(function_being_invoked); environment->set_function_object(function_being_invoked);
if (m_is_arrow_function) { if (m_is_arrow_function) {
if (is<FunctionEnvironmentRecord>(m_environment)) if (is<FunctionEnvironment>(m_environment))
environment->set_new_target(static_cast<FunctionEnvironmentRecord*>(m_environment)->new_target()); environment->set_new_target(static_cast<FunctionEnvironment*>(m_environment)->new_target());
} }
return environment; return environment;
} }

View File

@ -16,9 +16,9 @@ class OrdinaryFunctionObject final : public FunctionObject {
JS_OBJECT(OrdinaryFunctionObject, FunctionObject); JS_OBJECT(OrdinaryFunctionObject, FunctionObject);
public: public:
static OrdinaryFunctionObject* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, FunctionKind, bool is_strict, bool is_arrow_function = false); static OrdinaryFunctionObject* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, FunctionKind, bool is_strict, bool is_arrow_function = false);
OrdinaryFunctionObject(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, Object& prototype, FunctionKind, bool is_strict, bool is_arrow_function = false); OrdinaryFunctionObject(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, Object& prototype, FunctionKind, bool is_strict, bool is_arrow_function = false);
virtual void initialize(GlobalObject&) override; virtual void initialize(GlobalObject&) override;
virtual ~OrdinaryFunctionObject(); virtual ~OrdinaryFunctionObject();
@ -35,7 +35,7 @@ public:
auto& bytecode_executable() const { return m_bytecode_executable; } auto& bytecode_executable() const { return m_bytecode_executable; }
virtual EnvironmentRecord* environment() override { return m_environment; } virtual Environment* environment() override { return m_environment; }
GlobalObject* realm() const override { return m_realm; } GlobalObject* realm() const override { return m_realm; }
@ -44,7 +44,7 @@ protected:
private: private:
virtual bool is_ordinary_function_object() const override { return true; } virtual bool is_ordinary_function_object() const override { return true; }
virtual FunctionEnvironmentRecord* create_environment_record(FunctionObject&) override; virtual FunctionEnvironment* create_environment(FunctionObject&) override;
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
Value execute_function_body(); Value execute_function_body();
@ -56,7 +56,7 @@ private:
NonnullRefPtr<Statement> m_body; NonnullRefPtr<Statement> m_body;
const Vector<FunctionNode::Parameter> m_parameters; const Vector<FunctionNode::Parameter> m_parameters;
Optional<Bytecode::Executable> m_bytecode_executable; Optional<Bytecode::Executable> m_bytecode_executable;
EnvironmentRecord* m_environment { nullptr }; Environment* m_environment { nullptr };
GlobalObject* m_realm { nullptr }; GlobalObject* m_realm { nullptr };
i32 m_function_length { 0 }; i32 m_function_length { 0 };
FunctionKind m_kind { FunctionKind::Regular }; FunctionKind m_kind { FunctionKind::Regular };

View File

@ -478,10 +478,10 @@ const FlyString& ProxyObject::name() const
return static_cast<FunctionObject&>(m_target).name(); return static_cast<FunctionObject&>(m_target).name();
} }
FunctionEnvironmentRecord* ProxyObject::create_environment_record(FunctionObject& function_being_invoked) FunctionEnvironment* ProxyObject::create_environment(FunctionObject& function_being_invoked)
{ {
VERIFY(is_function()); VERIFY(is_function());
return static_cast<FunctionObject&>(m_target).create_environment_record(function_being_invoked); return static_cast<FunctionObject&>(m_target).create_environment(function_being_invoked);
} }
} }

View File

@ -22,7 +22,7 @@ public:
virtual Value call() override; virtual Value call() override;
virtual Value construct(FunctionObject& new_target) override; virtual Value construct(FunctionObject& new_target) override;
virtual const FlyString& name() const override; virtual const FlyString& name() const override;
virtual FunctionEnvironmentRecord* create_environment_record(FunctionObject&) override; virtual FunctionEnvironment* create_environment(FunctionObject&) override;
const Object& target() const { return m_target; } const Object& target() const { return m_target; }
const Object& handler() const { return m_handler; } const Object& handler() const { return m_handler; }

View File

@ -47,8 +47,8 @@ void Reference::put_value(GlobalObject& global_object, Value value)
return; return;
} }
VERIFY(m_base_type == BaseType::EnvironmentRecord); VERIFY(m_base_type == BaseType::Environment);
auto existing_variable = m_base_environment_record->get_from_environment_record(m_name.as_string()); auto existing_variable = m_base_environment->get_from_environment(m_name.as_string());
Variable variable { Variable variable {
.value = value, .value = value,
.declaration_kind = existing_variable.has_value() ? existing_variable->declaration_kind : DeclarationKind::Var .declaration_kind = existing_variable.has_value() ? existing_variable->declaration_kind : DeclarationKind::Var
@ -60,7 +60,7 @@ void Reference::put_value(GlobalObject& global_object, Value value)
return; return;
} }
m_base_environment_record->put_into_environment_record(m_name.as_string(), variable); m_base_environment->put_into_environment(m_name.as_string(), variable);
} }
void Reference::throw_reference_error(GlobalObject& global_object) void Reference::throw_reference_error(GlobalObject& global_object)
@ -87,8 +87,8 @@ Value Reference::get_value(GlobalObject& global_object, bool throw_if_undefined)
return base_obj->get(m_name).value_or(js_undefined()); return base_obj->get(m_name).value_or(js_undefined());
} }
VERIFY(m_base_type == BaseType::EnvironmentRecord); VERIFY(m_base_type == BaseType::Environment);
auto value = m_base_environment_record->get_from_environment_record(m_name.as_string()); auto value = m_base_environment->get_from_environment(m_name.as_string());
if (!value.has_value()) { if (!value.has_value()) {
if (!throw_if_undefined) { if (!throw_if_undefined) {
// FIXME: This is an ad-hoc hack for the `typeof` operator until we support proper variable bindings. // FIXME: This is an ad-hoc hack for the `typeof` operator until we support proper variable bindings.
@ -121,8 +121,8 @@ bool Reference::delete_(GlobalObject& global_object)
return succeeded; return succeeded;
} }
VERIFY(m_base_type == BaseType::EnvironmentRecord); VERIFY(m_base_type == BaseType::Environment);
return m_base_environment_record->delete_from_environment_record(m_name.as_string()); return m_base_environment->delete_from_environment(m_name.as_string());
} }
String Reference::to_string() const String Reference::to_string() const
@ -133,7 +133,7 @@ String Reference::to_string() const
case BaseType::Unresolvable: case BaseType::Unresolvable:
builder.append("Unresolvable"); builder.append("Unresolvable");
break; break;
case BaseType::EnvironmentRecord: case BaseType::Environment:
builder.appendff("{}", base_environment().class_name()); builder.appendff("{}", base_environment().class_name());
break; break;
case BaseType::Value: case BaseType::Value:

View File

@ -7,7 +7,7 @@
#pragma once #pragma once
#include <AK/String.h> #include <AK/String.h>
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/PropertyName.h> #include <LibJS/Runtime/PropertyName.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
@ -18,7 +18,7 @@ public:
enum class BaseType : u8 { enum class BaseType : u8 {
Unresolvable, Unresolvable,
Value, Value,
EnvironmentRecord, Environment,
}; };
Reference() { } Reference() { }
@ -44,9 +44,9 @@ public:
} }
} }
Reference(EnvironmentRecord& base, FlyString const& referenced_name, bool strict = false) Reference(Environment& base, FlyString const& referenced_name, bool strict = false)
: m_base_type(BaseType::EnvironmentRecord) : m_base_type(BaseType::Environment)
, m_base_environment_record(&base) , m_base_environment(&base)
, m_name(referenced_name) , m_name(referenced_name)
, m_strict(strict) , m_strict(strict)
{ {
@ -58,10 +58,10 @@ public:
return m_base_value; return m_base_value;
} }
EnvironmentRecord& base_environment() const Environment& base_environment() const
{ {
VERIFY(m_base_type == BaseType::EnvironmentRecord); VERIFY(m_base_type == BaseType::Environment);
return *m_base_environment_record; return *m_base_environment;
} }
PropertyName const& name() const { return m_name; } PropertyName const& name() const { return m_name; }
@ -75,7 +75,7 @@ public:
{ {
if (is_unresolvable()) if (is_unresolvable())
return false; return false;
if (m_base_type == BaseType::EnvironmentRecord) if (m_base_type == BaseType::Environment)
return false; return false;
if (m_base_value.is_boolean() || m_base_value.is_string() || m_base_value.is_symbol() || m_base_value.is_bigint() || m_base_value.is_number() || m_base_value.is_object()) if (m_base_value.is_boolean() || m_base_value.is_string() || m_base_value.is_symbol() || m_base_value.is_bigint() || m_base_value.is_number() || m_base_value.is_object())
return true; return true;
@ -109,7 +109,7 @@ private:
BaseType m_base_type { BaseType::Unresolvable }; BaseType m_base_type { BaseType::Unresolvable };
union { union {
Value m_base_value {}; Value m_base_value {};
EnvironmentRecord* m_base_environment_record; Environment* m_base_environment;
}; };
PropertyName m_name; PropertyName m_name;
Value m_this_value; Value m_this_value;

View File

@ -13,8 +13,8 @@
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FinalizationRegistry.h> #include <LibJS/Runtime/FinalizationRegistry.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h> #include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
@ -132,14 +132,14 @@ Symbol* VM::get_global_symbol(const String& description)
return new_global_symbol; return new_global_symbol;
} }
void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_object, bool first_assignment, EnvironmentRecord* specific_scope) void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_object, bool first_assignment, Environment* specific_scope)
{ {
Optional<Variable> possible_match; Optional<Variable> possible_match;
if (!specific_scope && m_execution_context_stack.size()) { if (!specific_scope && m_execution_context_stack.size()) {
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) { for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
possible_match = environment_record->get_from_environment_record(name); possible_match = environment->get_from_environment(name);
if (possible_match.has_value()) { if (possible_match.has_value()) {
specific_scope = environment_record; specific_scope = environment;
break; break;
} }
} }
@ -151,12 +151,12 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
return; return;
} }
specific_scope->put_into_environment_record(name, { value, possible_match.value().declaration_kind }); specific_scope->put_into_environment(name, { value, possible_match.value().declaration_kind });
return; return;
} }
if (specific_scope) { if (specific_scope) {
specific_scope->put_into_environment_record(name, { value, DeclarationKind::Var }); specific_scope->put_into_environment(name, { value, DeclarationKind::Var });
return; return;
} }
@ -165,13 +165,13 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
bool VM::delete_variable(FlyString const& name) bool VM::delete_variable(FlyString const& name)
{ {
EnvironmentRecord* specific_scope = nullptr; Environment* specific_scope = nullptr;
Optional<Variable> possible_match; Optional<Variable> possible_match;
if (!m_execution_context_stack.is_empty()) { if (!m_execution_context_stack.is_empty()) {
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) { for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
possible_match = environment_record->get_from_environment_record(name); possible_match = environment->get_from_environment(name);
if (possible_match.has_value()) { if (possible_match.has_value()) {
specific_scope = environment_record; specific_scope = environment;
break; break;
} }
} }
@ -183,15 +183,15 @@ bool VM::delete_variable(FlyString const& name)
return false; return false;
VERIFY(specific_scope); VERIFY(specific_scope);
return specific_scope->delete_from_environment_record(name); return specific_scope->delete_from_environment(name);
} }
void VM::assign(const FlyString& target, Value value, GlobalObject& global_object, bool first_assignment, EnvironmentRecord* specific_scope) void VM::assign(const FlyString& target, Value value, GlobalObject& global_object, bool first_assignment, Environment* specific_scope)
{ {
set_variable(target, move(value), global_object, first_assignment, specific_scope); set_variable(target, move(value), global_object, first_assignment, specific_scope);
} }
void VM::assign(const Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>>& target, Value value, GlobalObject& global_object, bool first_assignment, EnvironmentRecord* specific_scope) void VM::assign(const Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>>& target, Value value, GlobalObject& global_object, bool first_assignment, Environment* specific_scope)
{ {
if (auto id_ptr = target.get_pointer<NonnullRefPtr<Identifier>>()) if (auto id_ptr = target.get_pointer<NonnullRefPtr<Identifier>>())
return assign((*id_ptr)->string(), move(value), global_object, first_assignment, specific_scope); return assign((*id_ptr)->string(), move(value), global_object, first_assignment, specific_scope);
@ -199,7 +199,7 @@ void VM::assign(const Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPa
assign(target.get<NonnullRefPtr<BindingPattern>>(), move(value), global_object, first_assignment, specific_scope); assign(target.get<NonnullRefPtr<BindingPattern>>(), move(value), global_object, first_assignment, specific_scope);
} }
void VM::assign(const NonnullRefPtr<BindingPattern>& target, Value value, GlobalObject& global_object, bool first_assignment, EnvironmentRecord* specific_scope) void VM::assign(const NonnullRefPtr<BindingPattern>& target, Value value, GlobalObject& global_object, bool first_assignment, Environment* specific_scope)
{ {
auto& binding = *target; auto& binding = *target;
@ -365,7 +365,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
// a function parameter, or by a local var declaration, we use that. // a function parameter, or by a local var declaration, we use that.
// Otherwise, we return a lazily constructed Array with all the argument values. // Otherwise, we return a lazily constructed Array with all the argument values.
// FIXME: Do something much more spec-compliant. // FIXME: Do something much more spec-compliant.
auto possible_match = lexical_environment()->get_from_environment_record(name); auto possible_match = lexical_environment()->get_from_environment(name);
if (possible_match.has_value()) if (possible_match.has_value())
return possible_match.value().value; return possible_match.value().value;
if (!context.arguments_object) { if (!context.arguments_object) {
@ -378,8 +378,8 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
return context.arguments_object; return context.arguments_object;
} }
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) { for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
auto possible_match = environment_record->get_from_environment_record(name); auto possible_match = environment->get_from_environment(name);
if (exception()) if (exception())
return {}; return {};
if (possible_match.has_value()) if (possible_match.has_value())
@ -393,16 +393,16 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
} }
// 9.4.2 ResolveBinding ( name [ , env ] ), https://tc39.es/ecma262/#sec-resolvebinding // 9.4.2 ResolveBinding ( name [ , env ] ), https://tc39.es/ecma262/#sec-resolvebinding
Reference VM::resolve_binding(GlobalObject& global_object, FlyString const& name, EnvironmentRecord*) Reference VM::resolve_binding(GlobalObject& global_object, FlyString const& name, Environment*)
{ {
// FIXME: This implementation of ResolveBinding is non-conforming. // FIXME: This implementation of ResolveBinding is non-conforming.
for (auto* environment_record = lexical_environment(); environment_record && environment_record->outer_environment(); environment_record = environment_record->outer_environment()) { for (auto* environment = lexical_environment(); environment && environment->outer_environment(); environment = environment->outer_environment()) {
auto possible_match = environment_record->get_from_environment_record(name); auto possible_match = environment->get_from_environment(name);
if (possible_match.has_value()) if (possible_match.has_value())
return Reference { *environment_record, name }; return Reference { *environment, name };
} }
return Reference { global_object.environment_record(), name }; return Reference { global_object.environment(), name };
} }
Value VM::construct(FunctionObject& function, FunctionObject& new_target, Optional<MarkedValueList> arguments) Value VM::construct(FunctionObject& function, FunctionObject& new_target, Optional<MarkedValueList> arguments)
@ -433,7 +433,7 @@ Value VM::construct(FunctionObject& function, FunctionObject& new_target, Option
callee_context.arguments = function.bound_arguments(); callee_context.arguments = function.bound_arguments();
if (arguments.has_value()) if (arguments.has_value())
callee_context.arguments.extend(arguments.value().values()); callee_context.arguments.extend(arguments.value().values());
auto* environment = function.create_environment_record(function); auto* environment = function.create_environment(function);
callee_context.lexical_environment = environment; callee_context.lexical_environment = environment;
callee_context.variable_environment = environment; callee_context.variable_environment = environment;
if (environment) { if (environment) {
@ -459,7 +459,7 @@ Value VM::construct(FunctionObject& function, FunctionObject& new_target, Option
// set the prototype on objects created by constructors that return an object (i.e. NativeFunction subclasses). // set the prototype on objects created by constructors that return an object (i.e. NativeFunction subclasses).
if (function.constructor_kind() == FunctionObject::ConstructorKind::Base && new_target.constructor_kind() == FunctionObject::ConstructorKind::Derived && result.is_object()) { if (function.constructor_kind() == FunctionObject::ConstructorKind::Base && new_target.constructor_kind() == FunctionObject::ConstructorKind::Derived && result.is_object()) {
if (environment) { if (environment) {
verify_cast<FunctionEnvironmentRecord>(lexical_environment())->replace_this_binding(result); verify_cast<FunctionEnvironment>(lexical_environment())->replace_this_binding(result);
} }
auto prototype = new_target.get(names.prototype); auto prototype = new_target.get(names.prototype);
if (exception()) if (exception())
@ -508,7 +508,7 @@ String VM::join_arguments(size_t start_index) const
Value VM::get_new_target() Value VM::get_new_target()
{ {
auto& env = get_this_environment(*this); auto& env = get_this_environment(*this);
return verify_cast<FunctionEnvironmentRecord>(env).new_target(); return verify_cast<FunctionEnvironment>(env).new_target();
} }
Value VM::call_internal(FunctionObject& function, Value this_value, Optional<MarkedValueList> arguments) Value VM::call_internal(FunctionObject& function, Value this_value, Optional<MarkedValueList> arguments)
@ -526,12 +526,12 @@ Value VM::call_internal(FunctionObject& function, Value this_value, Optional<Mar
callee_context.arguments = function.bound_arguments(); callee_context.arguments = function.bound_arguments();
if (arguments.has_value()) if (arguments.has_value())
callee_context.arguments.extend(arguments.value().values()); callee_context.arguments.extend(arguments.value().values());
auto* environment = function.create_environment_record(function); auto* environment = function.create_environment(function);
callee_context.lexical_environment = environment; callee_context.lexical_environment = environment;
callee_context.variable_environment = environment; callee_context.variable_environment = environment;
if (environment) { if (environment) {
VERIFY(environment->this_binding_status() == FunctionEnvironmentRecord::ThisBindingStatus::Uninitialized); VERIFY(environment->this_binding_status() == FunctionEnvironment::ThisBindingStatus::Uninitialized);
environment->bind_this_value(function.global_object(), callee_context.this_value); environment->bind_this_value(function.global_object(), callee_context.this_value);
} }
@ -613,13 +613,13 @@ void VM::dump_backtrace() const
dbgln("-> {}", m_execution_context_stack[i]->function_name); dbgln("-> {}", m_execution_context_stack[i]->function_name);
} }
void VM::dump_environment_record_chain() const void VM::dump_environment_chain() const
{ {
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) { for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
dbgln("+> {} ({:p})", environment_record->class_name(), environment_record); dbgln("+> {} ({:p})", environment->class_name(), environment);
if (is<DeclarativeEnvironmentRecord>(*environment_record)) { if (is<DeclarativeEnvironment>(*environment)) {
auto& declarative_environment_record = static_cast<DeclarativeEnvironmentRecord const&>(*environment_record); auto& declarative_environment = static_cast<DeclarativeEnvironment const&>(*environment);
for (auto& variable : declarative_environment_record.variables()) { for (auto& variable : declarative_environment.variables()) {
dbgln(" {}", variable.key); dbgln(" {}", variable.key);
} }
} }

View File

@ -49,8 +49,8 @@ struct ExecutionContext {
Value this_value; Value this_value;
Vector<Value> arguments; Vector<Value> arguments;
Object* arguments_object { nullptr }; Object* arguments_object { nullptr };
EnvironmentRecord* lexical_environment { nullptr }; Environment* lexical_environment { nullptr };
EnvironmentRecord* variable_environment { nullptr }; Environment* variable_environment { nullptr };
bool is_strict_mode { false }; bool is_strict_mode { false };
}; };
@ -73,7 +73,7 @@ public:
void clear_exception() { m_exception = nullptr; } void clear_exception() { m_exception = nullptr; }
void dump_backtrace() const; void dump_backtrace() const;
void dump_environment_record_chain() const; void dump_environment_chain() const;
class InterpreterExecutionScope { class InterpreterExecutionScope {
public: public:
@ -123,11 +123,11 @@ public:
Vector<ExecutionContext*> const& execution_context_stack() const { return m_execution_context_stack; } Vector<ExecutionContext*> const& execution_context_stack() const { return m_execution_context_stack; }
Vector<ExecutionContext*>& execution_context_stack() { return m_execution_context_stack; } Vector<ExecutionContext*>& execution_context_stack() { return m_execution_context_stack; }
EnvironmentRecord const* lexical_environment() const { return running_execution_context().lexical_environment; } Environment const* lexical_environment() const { return running_execution_context().lexical_environment; }
EnvironmentRecord* lexical_environment() { return running_execution_context().lexical_environment; } Environment* lexical_environment() { return running_execution_context().lexical_environment; }
EnvironmentRecord const* variable_environment() const { return running_execution_context().variable_environment; } Environment const* variable_environment() const { return running_execution_context().variable_environment; }
EnvironmentRecord* variable_environment() { return running_execution_context().variable_environment; } Environment* variable_environment() { return running_execution_context().variable_environment; }
bool in_strict_mode() const; bool in_strict_mode() const;
@ -198,13 +198,13 @@ public:
FlyString unwind_until_label() const { return m_unwind_until_label; } FlyString unwind_until_label() const { return m_unwind_until_label; }
Value get_variable(const FlyString& name, GlobalObject&); Value get_variable(const FlyString& name, GlobalObject&);
void set_variable(const FlyString& name, Value, GlobalObject&, bool first_assignment = false, EnvironmentRecord* specific_scope = nullptr); void set_variable(const FlyString& name, Value, GlobalObject&, bool first_assignment = false, Environment* specific_scope = nullptr);
bool delete_variable(FlyString const& name); bool delete_variable(FlyString const& name);
void assign(const Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>>& target, Value, GlobalObject&, bool first_assignment = false, EnvironmentRecord* specific_scope = nullptr); void assign(const Variant<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>>& target, Value, GlobalObject&, bool first_assignment = false, Environment* specific_scope = nullptr);
void assign(const FlyString& target, Value, GlobalObject&, bool first_assignment = false, EnvironmentRecord* specific_scope = nullptr); void assign(const FlyString& target, Value, GlobalObject&, bool first_assignment = false, Environment* specific_scope = nullptr);
void assign(const NonnullRefPtr<BindingPattern>& target, Value, GlobalObject&, bool first_assignment = false, EnvironmentRecord* specific_scope = nullptr); void assign(const NonnullRefPtr<BindingPattern>& target, Value, GlobalObject&, bool first_assignment = false, Environment* specific_scope = nullptr);
Reference resolve_binding(GlobalObject&, FlyString const&, EnvironmentRecord* = nullptr); Reference resolve_binding(GlobalObject&, FlyString const&, Environment* = nullptr);
template<typename T, typename... Args> template<typename T, typename... Args>
void throw_exception(GlobalObject& global_object, Args&&... args) void throw_exception(GlobalObject& global_object, Args&&... args)