diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-11 22:05:43 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-09-12 11:10:20 +0100 |
commit | 80e58dab9ac4e1abcc5fe609b6ddbda76fbaff99 (patch) | |
tree | 8368f05e4c92e6ea0d1179b092b300fc2acea05d /Userland/Libraries/LibJS | |
parent | 06e89311fa0d09ac0b0a6bf4ea9b75773ac5d2df (diff) | |
download | serenity-80e58dab9ac4e1abcc5fe609b6ddbda76fbaff99.zip |
LibJS: Make get_function_realm() actually return a Realm
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/AbstractOperations.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp | 6 |
3 files changed, 9 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 640325a1d2..1bf920174a 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -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(); } diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index b1797f6867..fb9d24bdd3 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -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)()); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 3eb7c3a5a4..774d500550 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -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(); } } |