1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:17:34 +00:00

LibJS: Make get_function_realm() actually return a Realm

This commit is contained in:
Linus Groh 2021-09-11 22:05:43 +01:00
parent 06e89311fa
commit 80e58dab9a
3 changed files with 9 additions and 7 deletions

View file

@ -109,7 +109,7 @@ FunctionObject* species_constructor(GlobalObject& global_object, Object const& o
} }
// 7.3.24 GetFunctionRealm ( obj ), https://tc39.es/ecma262/#sec-getfunctionrealm // 7.3.24 GetFunctionRealm ( obj ), https://tc39.es/ecma262/#sec-getfunctionrealm
GlobalObject* get_function_realm(GlobalObject& global_object, FunctionObject const& function) Realm* get_function_realm(GlobalObject& global_object, FunctionObject const& function)
{ {
auto& vm = global_object.vm(); auto& vm = global_object.vm();
@ -118,7 +118,7 @@ GlobalObject* get_function_realm(GlobalObject& global_object, FunctionObject con
// 2. If obj has a [[Realm]] internal slot, then // 2. If obj has a [[Realm]] internal slot, then
if (function.realm()) { if (function.realm()) {
// a. Return obj.[[Realm]]. // a. Return obj.[[Realm]].
return &function.global_object(); return function.realm();
} }
// 3. If obj is a bound function exotic object, then // 3. If obj is a bound function exotic object, then
@ -151,7 +151,7 @@ GlobalObject* get_function_realm(GlobalObject& global_object, FunctionObject con
} }
// 5. Return the current Realm Record. // 5. Return the current Realm Record.
return &global_object; return vm.current_realm();
} }
// 10.1.6.2 IsCompatiblePropertyDescriptor ( Extensible, Desc, Current ), https://tc39.es/ecma262/#sec-iscompatiblepropertydescriptor // 10.1.6.2 IsCompatiblePropertyDescriptor ( Extensible, Desc, Current ), https://tc39.es/ecma262/#sec-iscompatiblepropertydescriptor
@ -320,7 +320,7 @@ Object* get_prototype_from_constructor(GlobalObject& global_object, FunctionObje
auto* realm = get_function_realm(global_object, constructor); auto* realm = get_function_realm(global_object, constructor);
if (vm.exception()) if (vm.exception())
return nullptr; return nullptr;
prototype = (realm->*intrinsic_default_prototype)(); prototype = (realm->global_object().*intrinsic_default_prototype)();
} }
return &prototype.as_object(); return &prototype.as_object();
} }

View file

@ -23,7 +23,7 @@ Value require_object_coercible(GlobalObject&, Value);
size_t length_of_array_like(GlobalObject&, Object const&); size_t length_of_array_like(GlobalObject&, Object const&);
MarkedValueList create_list_from_array_like(GlobalObject&, Value, Function<void(Value)> = {}); MarkedValueList create_list_from_array_like(GlobalObject&, Value, Function<void(Value)> = {});
FunctionObject* species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor); FunctionObject* species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor);
GlobalObject* get_function_realm(GlobalObject&, FunctionObject const&); Realm* get_function_realm(GlobalObject&, FunctionObject const&);
bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current); bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
bool validate_and_apply_property_descriptor(Object*, PropertyName const&, bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current); bool validate_and_apply_property_descriptor(Object*, PropertyName const&, bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)()); Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)());

View file

@ -20,6 +20,7 @@
#include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ObjectPrototype.h> #include <LibJS/Runtime/ObjectPrototype.h>
#include <LibJS/Runtime/Realm.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
namespace JS { namespace JS {
@ -122,11 +123,12 @@ static Object* array_species_create(GlobalObject& global_object, Object& origina
return {}; return {};
if (constructor.is_constructor()) { if (constructor.is_constructor()) {
auto& constructor_function = constructor.as_function(); auto& constructor_function = constructor.as_function();
auto* this_realm = vm.current_realm();
auto* constructor_realm = get_function_realm(global_object, constructor_function); auto* constructor_realm = get_function_realm(global_object, constructor_function);
if (vm.exception()) if (vm.exception())
return {}; return {};
if (constructor_realm != &global_object) { if (constructor_realm != this_realm) {
if (&constructor_function == constructor_realm->array_constructor()) if (&constructor_function == constructor_realm->global_object().array_constructor())
constructor = js_undefined(); constructor = js_undefined();
} }
} }