mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 02:18:12 +00:00
LibJS+LibWeb: Replace GlobalObject with Realm in create() functions
This is a continuation of the previous two commits. As allocating a JS cell already primarily involves a realm instead of a global object, and we'll need to pass one to the allocate() function itself eventually (it's bridged via the global object right now), the create() functions need to receive a realm as well. The plan is for this to be the highest-level function that actually receives a realm and passes it around, AOs on an even higher level will use the "current realm" concept via VM::current_realm() as that's what the spec assumes; passing around realms (or global objects, for that matter) on higher AO levels is pointless and unlike for allocating individual objects, which may happen outside of regular JS execution, we don't need control over the specific realm that is being used there.
This commit is contained in:
parent
5dd5896588
commit
b99cc7d050
178 changed files with 883 additions and 609 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <LibWeb/Bindings/CrossOriginAbstractOperations.h>
|
||||
#include <LibWeb/Bindings/DOMExceptionWrapper.h>
|
||||
#include <LibWeb/Bindings/LocationObject.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/DOM/DOMException.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
|
@ -93,6 +94,7 @@ bool is_platform_object_same_origin(JS::Object const& object)
|
|||
// 7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P ), https://html.spec.whatwg.org/multipage/browsers.html#crossorigingetownpropertyhelper-(-o,-p-)
|
||||
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const& object, JS::PropertyKey const& property_key)
|
||||
{
|
||||
auto& realm = *main_thread_vm().current_realm();
|
||||
auto const* object_ptr = object.visit([](auto* o) { return static_cast<JS::Object const*>(o); });
|
||||
auto const object_const_variant = object.visit([](auto* o) { return Variant<LocationObject const*, WindowObject const*> { o }; });
|
||||
|
||||
|
@ -126,7 +128,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
|||
// 2. If IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.
|
||||
if (value->is_function()) {
|
||||
value = JS::NativeFunction::create(
|
||||
HTML::current_global_object(), [function = JS::make_handle(*value)](auto&, auto& global_object) {
|
||||
realm, [function = JS::make_handle(*value)](auto&, auto& global_object) {
|
||||
return JS::call(global_object, function.value(), JS::js_undefined());
|
||||
},
|
||||
0, "");
|
||||
|
@ -143,7 +145,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
|||
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
|
||||
if (*entry.needs_get) {
|
||||
cross_origin_get = JS::NativeFunction::create(
|
||||
HTML::current_global_object(), [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto&, auto& global_object) {
|
||||
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto&, auto& global_object) {
|
||||
return JS::call(global_object, getter.cell(), object_ptr);
|
||||
},
|
||||
0, "");
|
||||
|
@ -155,7 +157,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
|||
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
|
||||
if (*entry.needs_set) {
|
||||
cross_origin_set = JS::NativeFunction::create(
|
||||
HTML::current_global_object(), [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto&, auto& global_object) {
|
||||
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto&, auto& global_object) {
|
||||
return JS::call(global_object, setter.cell(), object_ptr);
|
||||
},
|
||||
0, "");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue