mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:57:36 +00:00
LibJS: Add a [[Realm]] getter to FunctionObject and use it where needed
Defined by https://tc39.es/ecma262/#sec-ordinaryfunctioncreate step #17 and by https://tc39.es/ecma262/#sec-createbuiltinfunction step #6.
This commit is contained in:
parent
38b8fa8f3e
commit
5606332ed7
5 changed files with 11 additions and 3 deletions
|
@ -110,9 +110,8 @@ GlobalObject* get_function_realm(GlobalObject& global_object, FunctionObject con
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// FIXME: not sure how to do this currently.
|
if (function.realm())
|
||||||
// 2. If obj has a [[Realm]] internal slot, then
|
return function.realm();
|
||||||
// a. Return obj.[[Realm]].
|
|
||||||
if (is<BoundFunction>(function)) {
|
if (is<BoundFunction>(function)) {
|
||||||
auto& bound_function = static_cast<BoundFunction const&>(function);
|
auto& bound_function = static_cast<BoundFunction const&>(function);
|
||||||
auto& target = bound_function.target_function();
|
auto& target = bound_function.target_function();
|
||||||
|
|
|
@ -47,6 +47,9 @@ public:
|
||||||
// Used as the outer environment when evaluating the code of the function.
|
// Used as the outer environment when evaluating the code of the function.
|
||||||
virtual EnvironmentRecord* environment() { return nullptr; }
|
virtual EnvironmentRecord* environment() { return nullptr; }
|
||||||
|
|
||||||
|
// [[Realm]]
|
||||||
|
virtual GlobalObject* realm() const { return nullptr; }
|
||||||
|
|
||||||
enum class ThisMode : u8 {
|
enum class ThisMode : u8 {
|
||||||
Lexical,
|
Lexical,
|
||||||
Strict,
|
Strict,
|
||||||
|
|
|
@ -29,6 +29,8 @@ public:
|
||||||
|
|
||||||
virtual bool is_strict_mode() const override;
|
virtual bool is_strict_mode() const override;
|
||||||
|
|
||||||
|
GlobalObject* realm() const override { return &global_object(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NativeFunction(FlyString name, Object& prototype);
|
NativeFunction(FlyString name, Object& prototype);
|
||||||
explicit NativeFunction(Object& prototype);
|
explicit NativeFunction(Object& prototype);
|
||||||
|
|
|
@ -56,6 +56,7 @@ OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, cons
|
||||||
, m_body(body)
|
, m_body(body)
|
||||||
, m_parameters(move(parameters))
|
, m_parameters(move(parameters))
|
||||||
, m_environment(parent_scope)
|
, m_environment(parent_scope)
|
||||||
|
, m_realm(&global_object)
|
||||||
, m_function_length(function_length)
|
, m_function_length(function_length)
|
||||||
, m_kind(kind)
|
, m_kind(kind)
|
||||||
, m_is_strict(is_strict)
|
, m_is_strict(is_strict)
|
||||||
|
|
|
@ -37,6 +37,8 @@ public:
|
||||||
|
|
||||||
virtual EnvironmentRecord* environment() override { return m_environment; }
|
virtual EnvironmentRecord* environment() override { return m_environment; }
|
||||||
|
|
||||||
|
GlobalObject* realm() const override { return m_realm; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool is_strict_mode() const final { return m_is_strict; }
|
virtual bool is_strict_mode() const final { return m_is_strict; }
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ private:
|
||||||
const Vector<FunctionNode::Parameter> m_parameters;
|
const Vector<FunctionNode::Parameter> m_parameters;
|
||||||
Optional<Bytecode::Executable> m_bytecode_executable;
|
Optional<Bytecode::Executable> m_bytecode_executable;
|
||||||
EnvironmentRecord* m_environment { nullptr };
|
EnvironmentRecord* m_environment { nullptr };
|
||||||
|
GlobalObject* m_realm { nullptr };
|
||||||
i32 m_function_length { 0 };
|
i32 m_function_length { 0 };
|
||||||
FunctionKind m_kind { FunctionKind::Regular };
|
FunctionKind m_kind { FunctionKind::Regular };
|
||||||
bool m_is_strict { false };
|
bool m_is_strict { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue