Selaa lähdekoodia

LibJS: Use GlobalObject::associated_realm() for function object realms

As outlined in the previous commit, this should be more reliable than
Interpreter::realm(), as we don't always have access to an Interpreter.
Linus Groh 3 vuotta sitten
vanhempi
commit
0241071ca2

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp

@@ -43,7 +43,7 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(FlyString name, Statement con
     , m_environment(parent_scope)
     , m_environment(parent_scope)
     , m_formal_parameters(move(formal_parameters))
     , m_formal_parameters(move(formal_parameters))
     , m_ecmascript_code(ecmascript_code)
     , m_ecmascript_code(ecmascript_code)
-    , m_realm(vm().interpreter_if_exists() ? &vm().interpreter().realm() : nullptr)
+    , m_realm(global_object().associated_realm())
     , m_strict(strict)
     , m_strict(strict)
     , m_name(move(name))
     , m_name(move(name))
     , m_function_length(function_length)
     , m_function_length(function_length)

+ 3 - 3
Userland/Libraries/LibJS/Runtime/NativeFunction.cpp

@@ -24,7 +24,7 @@ NativeFunction* NativeFunction::create(GlobalObject& global_object, const FlyStr
 
 
 NativeFunction::NativeFunction(Object& prototype)
 NativeFunction::NativeFunction(Object& prototype)
     : FunctionObject(prototype)
     : FunctionObject(prototype)
-    , m_realm(vm().interpreter_if_exists() ? &vm().interpreter().realm() : nullptr)
+    , m_realm(global_object().associated_realm())
 {
 {
 }
 }
 
 
@@ -32,14 +32,14 @@ NativeFunction::NativeFunction(FlyString name, Function<Value(VM&, GlobalObject&
     : FunctionObject(prototype)
     : FunctionObject(prototype)
     , m_name(move(name))
     , m_name(move(name))
     , m_native_function(move(native_function))
     , m_native_function(move(native_function))
-    , m_realm(vm().interpreter_if_exists() ? &vm().interpreter().realm() : nullptr)
+    , m_realm(global_object().associated_realm())
 {
 {
 }
 }
 
 
 NativeFunction::NativeFunction(FlyString name, Object& prototype)
 NativeFunction::NativeFunction(FlyString name, Object& prototype)
     : FunctionObject(prototype)
     : FunctionObject(prototype)
     , m_name(move(name))
     , m_name(move(name))
-    , m_realm(vm().interpreter_if_exists() ? &vm().interpreter().realm() : nullptr)
+    , m_realm(global_object().associated_realm())
 {
 {
 }
 }