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/BigInt.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Reference.h>
@ -133,7 +133,7 @@ CallExpression::ThisAndCallee CallExpression::compute_this_and_callee(Interprete
Value this_value;
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()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, super_base.to_string_without_side_effects());
return {};
@ -242,7 +242,7 @@ Value CallExpression::execute(Interpreter& interpreter, GlobalObject& global_obj
return {};
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 {
result = vm.call(function, this_value, move(arguments));
}
@ -305,8 +305,8 @@ Value WithStatement::execute(Interpreter& interpreter, GlobalObject& global_obje
VERIFY(object);
auto* object_environment_record = 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);
auto* object_environment = new_object_environment(*object, true, interpreter.vm().running_execution_context().lexical_environment);
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());
}
@ -854,7 +854,7 @@ Value ClassDeclaration::execute(Interpreter& interpreter, GlobalObject& global_o
if (interpreter.exception())
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 {};
}
@ -2049,8 +2049,8 @@ Value TryStatement::execute(Interpreter& interpreter, GlobalObject& global_objec
HashMap<FlyString, Variable> parameters;
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);
TemporaryChange<EnvironmentRecord*> scope_change(interpreter.vm().running_execution_context().lexical_environment, catch_scope);
auto* catch_scope = interpreter.heap().allocate<DeclarativeEnvironment>(global_object, move(parameters), interpreter.vm().running_execution_context().lexical_environment);
TemporaryChange<Environment*> scope_change(interpreter.vm().running_execution_context().lexical_environment, catch_scope);
result = interpreter.execute_statement(global_object, m_handler->body());
}
}

View File

@ -14,7 +14,7 @@
#include <LibJS/Bytecode/Op.h>
#include <LibJS/Bytecode/Register.h>
#include <LibJS/Bytecode/StringTable.h>
#include <LibJS/Runtime/EnvironmentRecord.h>
#include <LibJS/Runtime/Environment.h>
namespace JS {
@ -63,7 +63,7 @@ void ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
}
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()) {
@ -1214,7 +1214,7 @@ void TryStatement::generate_bytecode(Bytecode::Generator& generator) const
if (!m_finalizer)
generator.emit<Bytecode::Op::LeaveUnwindContext>();
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()));
}
m_handler->body().generate_bytecode(generator);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,8 @@
#include <AK/StringBuilder.h>
#include <LibJS/AST.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.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;
static FlyString global_execution_context_name = "(global execution context)";
execution_context.function_name = global_execution_context_name;
execution_context.lexical_environment = &global_object.environment_record();
execution_context.variable_environment = &global_object.environment_record();
execution_context.lexical_environment = &global_object.environment();
execution_context.variable_environment = &global_object.environment();
VERIFY(!vm.exception());
execution_context.is_strict_mode = program.is_strict_mode();
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) {
push_scope({ scope_type, scope_node, false });
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;
}
@ -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()) {
auto* environment_record = heap().allocate<DeclarativeEnvironmentRecord>(global_object, move(scope_variables_with_declaration_kind), lexical_environment());
vm().running_execution_context().lexical_environment = environment_record;
vm().running_execution_context().variable_environment = environment_record;
pushed_environment_record = true;
auto* environment = heap().allocate<DeclarativeEnvironment>(global_object, move(scope_variables_with_declaration_kind), lexical_environment());
vm().running_execution_context().lexical_environment = environment;
vm().running_execution_context().variable_environment = environment;
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)
@ -198,9 +198,9 @@ Value Interpreter::execute_statement(GlobalObject& global_object, const Statemen
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/Heap/DeferGC.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/Exception.h>
#include <LibJS/Runtime/MarkedValueList.h>
@ -56,9 +56,9 @@ public:
ALWAYS_INLINE Heap& heap() { return vm().heap(); }
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 exit_scope(const ScopeNode&);

View File

@ -15,14 +15,14 @@
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayPrototype.h>
#include <LibJS/Runtime/BoundFunction.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/ErrorTypes.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
#include <LibJS/Runtime/PropertyName.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
DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord& environment_record)
DeclarativeEnvironment* new_declarative_environment(Environment& environment)
{
auto& global_object = environment_record.global_object();
return global_object.heap().allocate<DeclarativeEnvironmentRecord>(global_object, &environment_record);
auto& global_object = environment.global_object();
return global_object.heap().allocate<DeclarativeEnvironment>(global_object, &environment);
}
// 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();
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
EnvironmentRecord& get_this_environment(VM& vm)
Environment& get_this_environment(VM& vm)
{
for (auto* env = vm.lexical_environment(); env; env = env->outer_environment()) {
if (env->has_this_binding())
@ -175,7 +175,7 @@ EnvironmentRecord& get_this_environment(VM& vm)
Object* get_super_constructor(VM& 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();
return super_constructor;
}
@ -202,7 +202,7 @@ Value perform_eval(Value x, GlobalObject& caller_realm, CallerMode strict_caller
if (direct == EvalMode::Direct)
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());
}
@ -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
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.
(void)formals;

View File

@ -14,9 +14,9 @@
namespace JS {
DeclarativeEnvironmentRecord* new_declarative_environment(EnvironmentRecord&);
ObjectEnvironmentRecord* new_object_environment(Object&, bool is_with_environment, EnvironmentRecord*);
EnvironmentRecord& get_this_environment(VM&);
DeclarativeEnvironment* new_declarative_environment(Environment&);
ObjectEnvironment* new_object_environment(Object&, bool is_with_environment, Environment*);
Environment& get_this_environment(VM&);
Object* get_super_constructor(VM&);
Value require_object_coercible(GlobalObject&, Value);
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&);
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_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 {
Strict,

View File

@ -44,9 +44,9 @@ Value BoundFunction::construct(FunctionObject& 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)

View File

@ -22,7 +22,7 @@ public:
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;

View File

@ -5,7 +5,7 @@
*/
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
@ -13,27 +13,27 @@
namespace JS {
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord()
: EnvironmentRecord(nullptr)
DeclarativeEnvironment::DeclarativeEnvironment()
: Environment(nullptr)
{
}
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope)
: EnvironmentRecord(parent_scope)
DeclarativeEnvironment::DeclarativeEnvironment(Environment* parent_scope)
: Environment(parent_scope)
{
}
DeclarativeEnvironmentRecord::DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope)
: EnvironmentRecord(parent_scope)
DeclarativeEnvironment::DeclarativeEnvironment(HashMap<FlyString, Variable> variables, Environment* parent_scope)
: Environment(parent_scope)
, m_variables(move(variables))
{
}
DeclarativeEnvironmentRecord::~DeclarativeEnvironmentRecord()
DeclarativeEnvironment::~DeclarativeEnvironment()
{
}
void DeclarativeEnvironmentRecord::visit_edges(Visitor& visitor)
void DeclarativeEnvironment::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
for (auto& it : m_variables)
@ -42,29 +42,29 @@ void DeclarativeEnvironmentRecord::visit_edges(Visitor& visitor)
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);
}
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);
}
bool DeclarativeEnvironmentRecord::delete_from_environment_record(FlyString const& name)
bool DeclarativeEnvironment::delete_from_environment(FlyString const& name)
{
return m_variables.remove(name);
}
// 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);
}
// 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,
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
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,
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
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);
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
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);
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
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);
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
bool DeclarativeEnvironmentRecord::delete_binding(GlobalObject&, FlyString const& name)
bool DeclarativeEnvironment::delete_binding(GlobalObject&, FlyString const& name)
{
auto it = m_bindings.find(name);
VERIFY(it != m_bindings.end());

View File

@ -8,7 +8,7 @@
#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <LibJS/Runtime/EnvironmentRecord.h>
#include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/Value.h>
namespace JS {
@ -21,19 +21,19 @@ struct Binding {
bool initialized { false };
};
class DeclarativeEnvironmentRecord : public EnvironmentRecord {
JS_ENVIRONMENT_RECORD(DeclarativeEnvironmentRecord, EnvironmentRecord);
class DeclarativeEnvironment : public Environment {
JS_ENVIRONMENT(DeclarativeEnvironment, Environment);
public:
DeclarativeEnvironmentRecord();
explicit DeclarativeEnvironmentRecord(EnvironmentRecord* parent_scope);
DeclarativeEnvironmentRecord(HashMap<FlyString, Variable> variables, EnvironmentRecord* parent_scope);
virtual ~DeclarativeEnvironmentRecord() override;
DeclarativeEnvironment();
explicit DeclarativeEnvironment(Environment* parent_scope);
DeclarativeEnvironment(HashMap<FlyString, Variable> variables, Environment* parent_scope);
virtual ~DeclarativeEnvironment() override;
// ^EnvironmentRecord
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override;
// ^Environment
virtual Optional<Variable> get_from_environment(FlyString const&) const override;
virtual void put_into_environment(FlyString const&, Variable) override;
virtual bool delete_from_environment(FlyString const&) override;
HashMap<FlyString, Variable> const& variables() const { return m_variables; }
@ -49,13 +49,13 @@ protected:
virtual void visit_edges(Visitor&) override;
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, Binding> m_bindings;
};
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
*/
#include <LibJS/Runtime/EnvironmentRecord.h>
#include <LibJS/Runtime/Environment.h>
#include <LibJS/Runtime/VM.h>
namespace JS {
EnvironmentRecord::EnvironmentRecord(EnvironmentRecord* outer_environment)
Environment::Environment(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;
Cell::initialize(global_object);
}
void EnvironmentRecord::visit_edges(Visitor& visitor)
void Environment::visit_edges(Visitor& visitor)
{
Cell::visit_edges(visitor);
visitor.visit(m_outer_environment);

View File

@ -15,21 +15,21 @@ struct Variable {
DeclarationKind declaration_kind;
};
#define JS_ENVIRONMENT_RECORD(class_, base_class) \
#define JS_ENVIRONMENT(class_, base_class) \
public: \
using Base = base_class; \
virtual char const* class_name() const override { return #class_; }
class EnvironmentRecord : public Cell {
class Environment : public Cell {
public:
GlobalObject& global_object() { return *m_global_object; }
GlobalObject const& global_object() const { return *m_global_object; }
virtual void initialize(GlobalObject&) override;
virtual Optional<Variable> get_from_environment_record(FlyString const&) const = 0;
virtual void put_into_environment_record(FlyString const&, Variable) = 0;
virtual bool delete_from_environment_record(FlyString const&) = 0;
virtual Optional<Variable> get_from_environment(FlyString const&) const = 0;
virtual void put_into_environment(FlyString const&, Variable) = 0;
virtual bool delete_from_environment(FlyString const&) = 0;
virtual bool has_this_binding() const { return false; }
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; }
// [[OuterEnv]]
EnvironmentRecord* outer_environment() { return m_outer_environment; }
EnvironmentRecord const* outer_environment() const { return m_outer_environment; }
Environment* outer_environment() { 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_declarative_environment_record() const { return false; }
virtual bool is_function_environment_record() const { return false; }
virtual bool is_global_environment() const { return false; }
virtual bool is_declarative_environment() const { return false; }
virtual bool is_function_environment() const { return false; }
template<typename T>
bool fast_is() const = delete;
virtual char const* class_name() const override { return "EnvironmentRecord"; }
virtual char const* class_name() const override { return "Environment"; }
protected:
explicit EnvironmentRecord(EnvironmentRecord* parent);
explicit Environment(Environment* parent);
virtual void visit_edges(Visitor&) override;
private:
virtual bool is_environment_record() const final { return true; }
virtual bool is_environment() const final { return true; }
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/Runtime/FunctionEnvironmentRecord.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS {
FunctionEnvironmentRecord::FunctionEnvironmentRecord(EnvironmentRecord* parent_scope, HashMap<FlyString, Variable> variables)
: DeclarativeEnvironmentRecord(variables, parent_scope)
FunctionEnvironment::FunctionEnvironment(Environment* parent_scope, HashMap<FlyString, Variable> variables)
: DeclarativeEnvironment(variables, parent_scope)
{
}
FunctionEnvironmentRecord::~FunctionEnvironmentRecord()
FunctionEnvironment::~FunctionEnvironment()
{
}
void FunctionEnvironmentRecord::visit_edges(Visitor& visitor)
void FunctionEnvironment::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
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
Value FunctionEnvironmentRecord::get_super_base() const
Value FunctionEnvironment::get_super_base() const
{
VERIFY(m_function_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
bool FunctionEnvironmentRecord::has_this_binding() const
bool FunctionEnvironment::has_this_binding() const
{
if (this_binding_status() == ThisBindingStatus::Lexical)
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
bool FunctionEnvironmentRecord::has_super_binding() const
bool FunctionEnvironment::has_super_binding() const
{
if (this_binding_status() == ThisBindingStatus::Lexical)
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
Value FunctionEnvironmentRecord::get_this_binding(GlobalObject& global_object) const
Value FunctionEnvironment::get_this_binding(GlobalObject& global_object) const
{
VERIFY(has_this_binding());
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
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);
if (this_binding_status() == ThisBindingStatus::Initialized) {

View File

@ -6,12 +6,12 @@
#pragma once
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/DeclarativeEnvironment.h>
namespace JS {
class FunctionEnvironmentRecord final : public DeclarativeEnvironmentRecord {
JS_ENVIRONMENT_RECORD(FunctionEnvironmentRecord, DeclarativeEnvironmentRecord);
class FunctionEnvironment final : public DeclarativeEnvironment {
JS_ENVIRONMENT(FunctionEnvironment, DeclarativeEnvironment);
public:
enum class ThisBindingStatus : u8 {
@ -20,8 +20,8 @@ public:
Uninitialized,
};
FunctionEnvironmentRecord(EnvironmentRecord* parent_scope, HashMap<FlyString, Variable> variables);
virtual ~FunctionEnvironmentRecord() override;
FunctionEnvironment(Environment* parent_scope, HashMap<FlyString, Variable> variables);
virtual ~FunctionEnvironment() override;
// [[ThisValue]]
Value this_value() const { return m_this_value; }
@ -51,7 +51,7 @@ public:
Value bind_this_value(GlobalObject&, Value);
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;
Value m_this_value;
@ -61,6 +61,6 @@ private:
};
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 construct(FunctionObject& new_target) = 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);
@ -45,7 +45,7 @@ public:
// [[Environment]]
// The Environment Record that the function was closed over.
// Used as the outer environment when evaluating the code of the function.
virtual EnvironmentRecord* environment() { return nullptr; }
virtual Environment* environment() { return nullptr; }
// [[Realm]]
virtual GlobalObject* realm() const { return nullptr; }

View File

@ -13,7 +13,7 @@
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)
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);
object->m_generating_function = generating_function;
object->m_environment_record = generating_scope;
object->m_environment = generating_scope;
object->m_frame = move(frame);
object->m_previous_value = initial_value;
return object;
@ -44,7 +44,7 @@ GeneratorObject::~GeneratorObject()
void GeneratorObject::visit_edges(Cell::Visitor& visitor)
{
Object::visit_edges(visitor);
visitor.visit(m_environment_record);
visitor.visit(m_environment);
visitor.visit(m_generating_function);
if (m_previous_value.is_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
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);

View File

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

View File

@ -5,57 +5,57 @@
*/
#include <LibJS/AST.h>
#include <LibJS/Runtime/DeclarativeEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
namespace JS {
GlobalEnvironmentRecord::GlobalEnvironmentRecord(GlobalObject& global_object)
: EnvironmentRecord(nullptr)
GlobalEnvironment::GlobalEnvironment(GlobalObject& global_object)
: Environment(nullptr)
{
m_object_record = global_object.heap().allocate<ObjectEnvironmentRecord>(global_object, global_object, ObjectEnvironmentRecord::IsWithEnvironment::No, nullptr);
m_declarative_record = global_object.heap().allocate<DeclarativeEnvironmentRecord>(global_object);
m_object_record = global_object.heap().allocate<ObjectEnvironment>(global_object, global_object, ObjectEnvironment::IsWithEnvironment::No, nullptr);
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);
visitor.visit(m_object_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.
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.
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.
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();
}
Value GlobalEnvironmentRecord::global_this_value() const
Value GlobalEnvironment::global_this_value() const
{
return &global_object();
}
// 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))
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
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)) {
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
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)) {
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
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)) {
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
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)) {
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
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))
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
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))
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
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);
}
// 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);
}
// 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);
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
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);
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
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);
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
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 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
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);
PropertyDescriptor desc;

View File

@ -6,19 +6,19 @@
#pragma once
#include <LibJS/Runtime/EnvironmentRecord.h>
#include <LibJS/Runtime/Environment.h>
namespace JS {
class GlobalEnvironmentRecord final : public EnvironmentRecord {
JS_ENVIRONMENT_RECORD(GlobalEnvironmentRecord, EnvironmentRecord);
class GlobalEnvironment final : public Environment {
JS_ENVIRONMENT(GlobalEnvironment, Environment);
public:
explicit GlobalEnvironmentRecord(GlobalObject&);
explicit GlobalEnvironment(GlobalObject&);
virtual Optional<Variable> get_from_environment_record(FlyString const&) const override;
virtual void put_into_environment_record(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override;
virtual Optional<Variable> get_from_environment(FlyString const&) const override;
virtual void put_into_environment(FlyString const&, Variable) override;
virtual bool delete_from_environment(FlyString const&) override;
virtual bool has_this_binding() const final { return true; }
virtual Value get_this_binding(GlobalObject&) const final;
@ -33,10 +33,10 @@ public:
Value global_this_value() const;
// [[ObjectRecord]]
ObjectEnvironmentRecord& object_record() { return *m_object_record; }
ObjectEnvironment& object_record() { return *m_object_record; }
// [[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_lexical_declaration(FlyString const& name) const;
@ -47,15 +47,15 @@ public:
void create_global_function_binding(FlyString const& name, Value, bool can_be_deleted);
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;
ObjectEnvironmentRecord* m_object_record { nullptr };
DeclarativeEnvironmentRecord* m_declarative_record { nullptr };
ObjectEnvironment* m_object_record { nullptr };
DeclarativeEnvironment* m_declarative_record { nullptr };
Vector<FlyString> m_var_names;
};
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/GeneratorFunctionPrototype.h>
#include <LibJS/Runtime/GeneratorObjectPrototype.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorPrototype.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_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->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_proxy_constructor);
visitor.visit(m_generator_object_prototype);
visitor.visit(m_environment_record);
visitor.visit(m_environment);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
visitor.visit(m_##snake_name##_constructor); \

View File

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

View File

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

View File

@ -36,7 +36,7 @@ protected:
explicit NativeFunction(Object& prototype);
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; }
FlyString m_name;

View File

@ -6,24 +6,24 @@
#include <LibJS/AST.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h>
#include <LibJS/Runtime/ObjectEnvironment.h>
namespace JS {
ObjectEnvironmentRecord::ObjectEnvironmentRecord(Object& binding_object, IsWithEnvironment is_with_environment, EnvironmentRecord* outer_environment)
: EnvironmentRecord(outer_environment)
ObjectEnvironment::ObjectEnvironment(Object& binding_object, IsWithEnvironment is_with_environment, Environment* outer_environment)
: Environment(outer_environment)
, m_binding_object(binding_object)
, 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);
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);
if (value.is_empty())
@ -31,18 +31,18 @@ Optional<Variable> ObjectEnvironmentRecord::get_from_environment_record(FlyStrin
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);
}
bool ObjectEnvironmentRecord::delete_from_environment_record(FlyString const& name)
bool ObjectEnvironment::delete_from_environment(FlyString const& 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
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);
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
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;
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
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."
VERIFY_NOT_REACHED();
}
// 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);
}
// 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);
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
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 (!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
bool ObjectEnvironmentRecord::delete_binding(GlobalObject&, FlyString const& name)
bool ObjectEnvironment::delete_binding(GlobalObject&, FlyString const& name)
{
return m_binding_object.delete_property(name);
}

View File

@ -6,23 +6,23 @@
#pragma once
#include <LibJS/Runtime/EnvironmentRecord.h>
#include <LibJS/Runtime/Environment.h>
namespace JS {
class ObjectEnvironmentRecord : public EnvironmentRecord {
JS_ENVIRONMENT_RECORD(ObjectEnvironmentRecord, EnvironmentRecord);
class ObjectEnvironment : public Environment {
JS_ENVIRONMENT(ObjectEnvironment, Environment);
public:
enum class IsWithEnvironment {
No,
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 void put_into_environment_record(FlyString const&, Variable) override;
virtual bool delete_from_environment_record(FlyString const&) override;
virtual Optional<Variable> get_from_environment(FlyString const&) const override;
virtual void put_into_environment(FlyString const&, Variable) override;
virtual bool delete_from_environment(FlyString 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;

View File

@ -14,7 +14,7 @@
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/GeneratorObjectPrototype.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);
}
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;
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);
}
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)
, m_name(name)
, m_body(body)
@ -113,7 +113,7 @@ void OrdinaryFunctionObject::visit_edges(Visitor& visitor)
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;
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);
if (m_is_arrow_function) {
if (is<FunctionEnvironmentRecord>(m_environment))
environment->set_new_target(static_cast<FunctionEnvironmentRecord*>(m_environment)->new_target());
if (is<FunctionEnvironment>(m_environment))
environment->set_new_target(static_cast<FunctionEnvironment*>(m_environment)->new_target());
}
return environment;
}

View File

@ -16,9 +16,9 @@ class OrdinaryFunctionObject final : public FunctionObject {
JS_OBJECT(OrdinaryFunctionObject, FunctionObject);
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 ~OrdinaryFunctionObject();
@ -35,7 +35,7 @@ public:
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; }
@ -44,7 +44,7 @@ protected:
private:
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;
Value execute_function_body();
@ -56,7 +56,7 @@ private:
NonnullRefPtr<Statement> m_body;
const Vector<FunctionNode::Parameter> m_parameters;
Optional<Bytecode::Executable> m_bytecode_executable;
EnvironmentRecord* m_environment { nullptr };
Environment* m_environment { nullptr };
GlobalObject* m_realm { nullptr };
i32 m_function_length { 0 };
FunctionKind m_kind { FunctionKind::Regular };

View File

@ -478,10 +478,10 @@ const FlyString& ProxyObject::name() const
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());
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 construct(FunctionObject& new_target) 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& handler() const { return m_handler; }

View File

@ -47,8 +47,8 @@ void Reference::put_value(GlobalObject& global_object, Value value)
return;
}
VERIFY(m_base_type == BaseType::EnvironmentRecord);
auto existing_variable = m_base_environment_record->get_from_environment_record(m_name.as_string());
VERIFY(m_base_type == BaseType::Environment);
auto existing_variable = m_base_environment->get_from_environment(m_name.as_string());
Variable variable {
.value = value,
.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;
}
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)
@ -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());
}
VERIFY(m_base_type == BaseType::EnvironmentRecord);
auto value = m_base_environment_record->get_from_environment_record(m_name.as_string());
VERIFY(m_base_type == BaseType::Environment);
auto value = m_base_environment->get_from_environment(m_name.as_string());
if (!value.has_value()) {
if (!throw_if_undefined) {
// 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;
}
VERIFY(m_base_type == BaseType::EnvironmentRecord);
return m_base_environment_record->delete_from_environment_record(m_name.as_string());
VERIFY(m_base_type == BaseType::Environment);
return m_base_environment->delete_from_environment(m_name.as_string());
}
String Reference::to_string() const
@ -133,7 +133,7 @@ String Reference::to_string() const
case BaseType::Unresolvable:
builder.append("Unresolvable");
break;
case BaseType::EnvironmentRecord:
case BaseType::Environment:
builder.appendff("{}", base_environment().class_name());
break;
case BaseType::Value:

View File

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

View File

@ -13,8 +13,8 @@
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FinalizationRegistry.h>
#include <LibJS/Runtime/FunctionEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/FunctionEnvironment.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/NativeFunction.h>
@ -132,14 +132,14 @@ Symbol* VM::get_global_symbol(const String& description)
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;
if (!specific_scope && m_execution_context_stack.size()) {
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) {
possible_match = environment_record->get_from_environment_record(name);
for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
possible_match = environment->get_from_environment(name);
if (possible_match.has_value()) {
specific_scope = environment_record;
specific_scope = environment;
break;
}
}
@ -151,12 +151,12 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
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;
}
if (specific_scope) {
specific_scope->put_into_environment_record(name, { value, DeclarationKind::Var });
specific_scope->put_into_environment(name, { value, DeclarationKind::Var });
return;
}
@ -165,13 +165,13 @@ void VM::set_variable(const FlyString& name, Value value, GlobalObject& global_o
bool VM::delete_variable(FlyString const& name)
{
EnvironmentRecord* specific_scope = nullptr;
Environment* specific_scope = nullptr;
Optional<Variable> possible_match;
if (!m_execution_context_stack.is_empty()) {
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) {
possible_match = environment_record->get_from_environment_record(name);
for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
possible_match = environment->get_from_environment(name);
if (possible_match.has_value()) {
specific_scope = environment_record;
specific_scope = environment;
break;
}
}
@ -183,15 +183,15 @@ bool VM::delete_variable(FlyString const& name)
return false;
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);
}
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>>())
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);
}
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;
@ -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.
// Otherwise, we return a lazily constructed Array with all the argument values.
// 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())
return possible_match.value().value;
if (!context.arguments_object) {
@ -378,8 +378,8 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object)
return context.arguments_object;
}
for (auto* environment_record = lexical_environment(); environment_record; environment_record = environment_record->outer_environment()) {
auto possible_match = environment_record->get_from_environment_record(name);
for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
auto possible_match = environment->get_from_environment(name);
if (exception())
return {};
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
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.
for (auto* environment_record = lexical_environment(); environment_record && environment_record->outer_environment(); environment_record = environment_record->outer_environment()) {
auto possible_match = environment_record->get_from_environment_record(name);
for (auto* environment = lexical_environment(); environment && environment->outer_environment(); environment = environment->outer_environment()) {
auto possible_match = environment->get_from_environment(name);
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)
@ -433,7 +433,7 @@ Value VM::construct(FunctionObject& function, FunctionObject& new_target, Option
callee_context.arguments = function.bound_arguments();
if (arguments.has_value())
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.variable_environment = 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).
if (function.constructor_kind() == FunctionObject::ConstructorKind::Base && new_target.constructor_kind() == FunctionObject::ConstructorKind::Derived && result.is_object()) {
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);
if (exception())
@ -508,7 +508,7 @@ String VM::join_arguments(size_t start_index) const
Value VM::get_new_target()
{
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)
@ -526,12 +526,12 @@ Value VM::call_internal(FunctionObject& function, Value this_value, Optional<Mar
callee_context.arguments = function.bound_arguments();
if (arguments.has_value())
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.variable_environment = 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);
}
@ -613,13 +613,13 @@ void VM::dump_backtrace() const
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()) {
dbgln("+> {} ({:p})", environment_record->class_name(), environment_record);
if (is<DeclarativeEnvironmentRecord>(*environment_record)) {
auto& declarative_environment_record = static_cast<DeclarativeEnvironmentRecord const&>(*environment_record);
for (auto& variable : declarative_environment_record.variables()) {
for (auto* environment = lexical_environment(); environment; environment = environment->outer_environment()) {
dbgln("+> {} ({:p})", environment->class_name(), environment);
if (is<DeclarativeEnvironment>(*environment)) {
auto& declarative_environment = static_cast<DeclarativeEnvironment const&>(*environment);
for (auto& variable : declarative_environment.variables()) {
dbgln(" {}", variable.key);
}
}

View File

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