diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-24 23:49:24 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-25 17:51:30 +0200 |
commit | 136451c3aff8785af23be7b000176bde4fd90755 (patch) | |
tree | f0822e937499938e4d12ed4a9319fed7baa24276 /Userland | |
parent | 06726d41ac931af6f8bb8020a303b0d27e4063b6 (diff) | |
download | serenity-136451c3aff8785af23be7b000176bde4fd90755.zip |
LibJS: Move [[HomeObject]] to ECMAScriptFunctionObject
Diffstat (limited to 'Userland')
6 files changed, 14 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 96302be146..baf6728167 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -924,7 +924,7 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob if (interpreter.exception()) return {}; - auto& method_function = method_value.as_function(); + auto& method_function = static_cast<ECMAScriptFunctionObject&>(method_value.as_function()); auto key = method.key().execute(interpreter, global_object); if (interpreter.exception()) @@ -965,7 +965,7 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob if (interpreter.exception()) return {}; - FunctionObject* initializer = nullptr; + ECMAScriptFunctionObject* initializer = nullptr; if (field.initializer()) { auto copy_initializer = field.initializer(); auto body = create_ast_node<ExpressionStatement>(field.initializer()->source_range(), copy_initializer.release_nonnull()); @@ -1923,7 +1923,7 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o return {}; if (value.is_function() && property.is_method()) - value.as_function().set_home_object(object); + static_cast<ECMAScriptFunctionObject&>(value.as_function()).set_home_object(object); String name = get_function_name(global_object, key); if (property.type() == ObjectProperty::Type::Getter) { diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 28deabee52..bebb6436bc 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -99,6 +99,7 @@ void ECMAScriptFunctionObject::visit_edges(Visitor& visitor) Base::visit_edges(visitor); visitor.visit(m_environment); visitor.visit(m_realm); + visitor.visit(m_home_object); } FunctionEnvironment* ECMAScriptFunctionObject::create_environment(FunctionObject& function_being_invoked) @@ -131,7 +132,7 @@ FunctionEnvironment* ECMAScriptFunctionObject::create_environment(FunctionObject } auto* environment = heap().allocate<FunctionEnvironment>(global_object(), m_environment, variables); - environment->set_function_object(function_being_invoked); + environment->set_function_object(static_cast<ECMAScriptFunctionObject&>(function_being_invoked)); if (m_is_arrow_function) { environment->set_this_binding_status(FunctionEnvironment::ThisBindingStatus::Lexical); if (is<FunctionEnvironment>(m_environment)) diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h index eb2abd32c3..5dd9fd5d1f 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h @@ -55,6 +55,9 @@ public: ThisMode this_mode() const { return m_this_mode; } + Object* home_object() const { return m_home_object; } + void set_home_object(Object* home_object) { m_home_object = home_object; } + protected: virtual bool is_strict_mode() const final { return m_strict; } @@ -73,6 +76,7 @@ private: Realm* m_realm { nullptr }; // [[Realm]] ThisMode m_this_mode { ThisMode::Global }; // [[ThisMode]] bool m_strict { false }; // [[Strict]] + Object* m_home_object { nullptr }; // [[HomeObject]] bool m_is_class_constructor { false }; // [[IsClassConstructor]] FlyString m_name; diff --git a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h index 83f63b0173..dbf68df575 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/FunctionEnvironment.h @@ -7,6 +7,7 @@ #pragma once #include <LibJS/Runtime/DeclarativeEnvironment.h> +#include <LibJS/Runtime/ECMAScriptFunctionObject.h> namespace JS { @@ -35,9 +36,9 @@ public: void set_this_binding_status(ThisBindingStatus status) { m_this_binding_status = status; } // [[FunctionObject]] - FunctionObject& function_object() { return *m_function_object; } - FunctionObject const& function_object() const { return *m_function_object; } - void set_function_object(FunctionObject& function) { m_function_object = &function; } + ECMAScriptFunctionObject& function_object() { return *m_function_object; } + ECMAScriptFunctionObject const& function_object() const { return *m_function_object; } + void set_function_object(ECMAScriptFunctionObject& function) { m_function_object = &function; } // [[NewTarget]] Value new_target() const { return m_new_target; } @@ -56,7 +57,7 @@ private: Value m_this_value; ThisBindingStatus m_this_binding_status { ThisBindingStatus::Uninitialized }; - FunctionObject* m_function_object { nullptr }; + ECMAScriptFunctionObject* m_function_object { nullptr }; Value m_new_target; }; diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp index 872542be61..0bc775a0ca 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp @@ -88,7 +88,6 @@ void FunctionObject::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); - visitor.visit(m_home_object); visitor.visit(m_bound_this); for (auto argument : m_bound_arguments) diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.h b/Userland/Libraries/LibJS/Runtime/FunctionObject.h index 5e2cb779e1..fbd3d3932e 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionObject.h +++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.h @@ -29,9 +29,6 @@ public: const Vector<Value>& bound_arguments() const { return m_bound_arguments; } - Object* home_object() const { return m_home_object; } - void set_home_object(Object* home_object) { m_home_object = home_object; } - virtual bool is_strict_mode() const { return false; } // [[Environment]] @@ -68,7 +65,6 @@ private: virtual bool is_function() const override { return true; } Value m_bound_this; Vector<Value> m_bound_arguments; - Object* m_home_object { nullptr }; bool m_has_simple_parameter_list { false }; Vector<InstanceField> m_fields; }; |