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
Notes: sideshowbarker 2024-07-18 04:11:02 +09:00
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
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();
@ -118,7 +118,7 @@ GlobalObject* get_function_realm(GlobalObject& global_object, FunctionObject con
// 2. If obj has a [[Realm]] internal slot, then
if (function.realm()) {
// a. Return obj.[[Realm]].
return &function.global_object();
return function.realm();
}
// 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.
return &global_object;
return vm.current_realm();
}
// 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);
if (vm.exception())
return nullptr;
prototype = (realm->*intrinsic_default_prototype)();
prototype = (realm->global_object().*intrinsic_default_prototype)();
}
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&);
MarkedValueList create_list_from_array_like(GlobalObject&, Value, Function<void(Value)> = {});
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 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)());

View file

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