mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibWeb: Replace GlobalObject with VM in CrossOrigin AOs [Part 2/4]
This commit is contained in:
parent
5f1fe4b012
commit
f8fb985b05
4 changed files with 18 additions and 26 deletions
|
@ -67,10 +67,8 @@ bool is_cross_origin_accessible_window_property_name(JS::PropertyKey const& prop
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.3.2 CrossOriginPropertyFallback ( P ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertyfallback-(-p-)
|
// 7.2.3.2 CrossOriginPropertyFallback ( P ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertyfallback-(-p-)
|
||||||
JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::GlobalObject& global_object, JS::PropertyKey const& property_key)
|
JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::VM& vm, JS::PropertyKey const& property_key)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. If P is "then", @@toStringTag, @@hasInstance, or @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]: undefined, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
// 1. If P is "then", @@toStringTag, @@hasInstance, or @@isConcatSpreadable, then return PropertyDescriptor{ [[Value]]: undefined, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||||
auto property_key_is_then = property_key.is_string() && property_key.as_string() == vm.names.then.as_string();
|
auto property_key_is_then = property_key.is_string() && property_key.as_string() == vm.names.then.as_string();
|
||||||
auto property_key_is_allowed_symbol = property_key.is_symbol()
|
auto property_key_is_allowed_symbol = property_key.is_symbol()
|
||||||
|
@ -179,10 +177,8 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.3.5 CrossOriginGet ( O, P, Receiver ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginget-(-o,-p,-receiver-)
|
// 7.2.3.5 CrossOriginGet ( O, P, Receiver ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginget-(-o,-p,-receiver-)
|
||||||
JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject& global_object, JS::Object const& object, JS::PropertyKey const& property_key, JS::Value receiver)
|
JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::VM& vm, JS::Object const& object, JS::PropertyKey const& property_key, JS::Value receiver)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. Let desc be ? O.[[GetOwnProperty]](P).
|
// 1. Let desc be ? O.[[GetOwnProperty]](P).
|
||||||
auto descriptor = TRY(object.internal_get_own_property(property_key));
|
auto descriptor = TRY(object.internal_get_own_property(property_key));
|
||||||
|
|
||||||
|
@ -208,10 +204,8 @@ JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject& global_objec
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.3.6 CrossOriginSet ( O, P, V, Receiver ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginset-(-o,-p,-v,-receiver-)
|
// 7.2.3.6 CrossOriginSet ( O, P, V, Receiver ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginset-(-o,-p,-v,-receiver-)
|
||||||
JS::ThrowCompletionOr<bool> cross_origin_set(JS::GlobalObject& global_object, JS::Object& object, JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
|
JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM& vm, JS::Object& object, JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. Let desc be ? O.[[GetOwnProperty]](P).
|
// 1. Let desc be ? O.[[GetOwnProperty]](P).
|
||||||
auto descriptor = TRY(object.internal_get_own_property(property_key));
|
auto descriptor = TRY(object.internal_get_own_property(property_key));
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ using CrossOriginPropertyDescriptorMap = HashMap<CrossOriginKey, JS::PropertyDes
|
||||||
|
|
||||||
Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, WindowObject const*> const&);
|
Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, WindowObject const*> const&);
|
||||||
bool is_cross_origin_accessible_window_property_name(JS::PropertyKey const&);
|
bool is_cross_origin_accessible_window_property_name(JS::PropertyKey const&);
|
||||||
JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::GlobalObject&, JS::PropertyKey const&);
|
JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::VM&, JS::PropertyKey const&);
|
||||||
bool is_platform_object_same_origin(JS::Object const&);
|
bool is_platform_object_same_origin(JS::Object const&);
|
||||||
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const&, JS::PropertyKey const&);
|
Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const&, JS::PropertyKey const&);
|
||||||
JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject&, JS::Object const&, JS::PropertyKey const&, JS::Value receiver);
|
JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::VM&, JS::Object const&, JS::PropertyKey const&, JS::Value receiver);
|
||||||
JS::ThrowCompletionOr<bool> cross_origin_set(JS::GlobalObject&, JS::Object&, JS::PropertyKey const&, JS::Value, JS::Value receiver);
|
JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM&, JS::Object&, JS::PropertyKey const&, JS::Value, JS::Value receiver);
|
||||||
JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, WindowObject const*> const&);
|
JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, WindowObject const*> const&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,8 +268,7 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_prevent_extensions()
|
||||||
// 7.10.5.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-getownproperty
|
// 7.10.5.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-getownproperty
|
||||||
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LocationObject::internal_get_own_property(JS::PropertyKey const& property_key) const
|
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LocationObject::internal_get_own_property(JS::PropertyKey const& property_key) const
|
||||||
{
|
{
|
||||||
auto& global_object = HTML::current_global_object();
|
auto& vm = this->vm();
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. If IsPlatformObjectSameOrigin(this) is true, then:
|
// 1. If IsPlatformObjectSameOrigin(this) is true, then:
|
||||||
if (is_platform_object_same_origin(*this)) {
|
if (is_platform_object_same_origin(*this)) {
|
||||||
|
@ -295,7 +294,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> LocationObject::internal
|
||||||
return property;
|
return property;
|
||||||
|
|
||||||
// 4. Return ? CrossOriginPropertyFallback(P).
|
// 4. Return ? CrossOriginPropertyFallback(P).
|
||||||
return TRY(cross_origin_property_fallback(global_object, property_key));
|
return TRY(cross_origin_property_fallback(vm, property_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/history.html#location-defineownproperty
|
// 7.10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/history.html#location-defineownproperty
|
||||||
|
@ -318,27 +317,27 @@ JS::ThrowCompletionOr<bool> LocationObject::internal_define_own_property(JS::Pro
|
||||||
// 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get
|
// 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get
|
||||||
JS::ThrowCompletionOr<JS::Value> LocationObject::internal_get(JS::PropertyKey const& property_key, JS::Value receiver) const
|
JS::ThrowCompletionOr<JS::Value> LocationObject::internal_get(JS::PropertyKey const& property_key, JS::Value receiver) const
|
||||||
{
|
{
|
||||||
auto& global_object = HTML::current_global_object();
|
auto& vm = this->vm();
|
||||||
|
|
||||||
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryGet(this, P, Receiver).
|
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryGet(this, P, Receiver).
|
||||||
if (is_platform_object_same_origin(*this))
|
if (is_platform_object_same_origin(*this))
|
||||||
return JS::Object::internal_get(property_key, receiver);
|
return JS::Object::internal_get(property_key, receiver);
|
||||||
|
|
||||||
// 2. Return ? CrossOriginGet(this, P, Receiver).
|
// 2. Return ? CrossOriginGet(this, P, Receiver).
|
||||||
return cross_origin_get(global_object, static_cast<JS::Object const&>(*this), property_key, receiver);
|
return cross_origin_get(vm, static_cast<JS::Object const&>(*this), property_key, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.10.5.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-set
|
// 7.10.5.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-set
|
||||||
JS::ThrowCompletionOr<bool> LocationObject::internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
|
JS::ThrowCompletionOr<bool> LocationObject::internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
|
||||||
{
|
{
|
||||||
auto& global_object = HTML::current_global_object();
|
auto& vm = this->vm();
|
||||||
|
|
||||||
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinarySet(this, P, V, Receiver).
|
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinarySet(this, P, V, Receiver).
|
||||||
if (is_platform_object_same_origin(*this))
|
if (is_platform_object_same_origin(*this))
|
||||||
return JS::Object::internal_set(property_key, value, receiver);
|
return JS::Object::internal_set(property_key, value, receiver);
|
||||||
|
|
||||||
// 2. Return ? CrossOriginSet(this, P, V, Receiver).
|
// 2. Return ? CrossOriginSet(this, P, V, Receiver).
|
||||||
return cross_origin_set(global_object, static_cast<JS::Object&>(*this), property_key, value, receiver);
|
return cross_origin_set(vm, static_cast<JS::Object&>(*this), property_key, value, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.10.5.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-delete
|
// 7.10.5.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-delete
|
||||||
|
|
|
@ -65,8 +65,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_prevent_extensions()
|
||||||
// 7.4.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-getownproperty
|
// 7.4.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-getownproperty
|
||||||
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_get_own_property(JS::PropertyKey const& property_key) const
|
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_get_own_property(JS::PropertyKey const& property_key) const
|
||||||
{
|
{
|
||||||
auto& global_object = HTML::current_global_object();
|
auto& vm = this->vm();
|
||||||
auto& vm = global_object.vm();
|
|
||||||
|
|
||||||
// 1. Let W be the value of the [[Window]] internal slot of this.
|
// 1. Let W be the value of the [[Window]] internal slot of this.
|
||||||
|
|
||||||
|
@ -123,7 +122,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Return ? CrossOriginPropertyFallback(P).
|
// 7. Return ? CrossOriginPropertyFallback(P).
|
||||||
return TRY(cross_origin_property_fallback(global_object, property_key));
|
return TRY(cross_origin_property_fallback(vm, property_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.4.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-defineownproperty
|
// 7.4.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-defineownproperty
|
||||||
|
@ -152,7 +151,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_define_own_property(JS::Proper
|
||||||
// 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get
|
// 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get
|
||||||
JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const& property_key, JS::Value receiver) const
|
JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const& property_key, JS::Value receiver) const
|
||||||
{
|
{
|
||||||
auto& global_object = HTML::current_global_object();
|
auto& vm = this->vm();
|
||||||
|
|
||||||
// 1. Let W be the value of the [[Window]] internal slot of this.
|
// 1. Let W be the value of the [[Window]] internal slot of this.
|
||||||
|
|
||||||
|
@ -166,13 +165,13 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
|
||||||
|
|
||||||
// 4. Return ? CrossOriginGet(this, P, Receiver).
|
// 4. Return ? CrossOriginGet(this, P, Receiver).
|
||||||
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
|
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
|
||||||
return cross_origin_get(global_object, *this, property_key, receiver);
|
return cross_origin_get(vm, *this, property_key, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.4.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-set
|
// 7.4.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-set
|
||||||
JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
|
JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& property_key, JS::Value value, JS::Value receiver)
|
||||||
{
|
{
|
||||||
auto& global_object = HTML::current_global_object();
|
auto& vm = this->vm();
|
||||||
|
|
||||||
// 1. Let W be the value of the [[Window]] internal slot of this.
|
// 1. Let W be the value of the [[Window]] internal slot of this.
|
||||||
|
|
||||||
|
@ -191,7 +190,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro
|
||||||
|
|
||||||
// 4. Return ? CrossOriginSet(this, P, V, Receiver).
|
// 4. Return ? CrossOriginSet(this, P, V, Receiver).
|
||||||
// NOTE: this is passed rather than W as CrossOriginSet will invoke the [[GetOwnProperty]] internal method.
|
// NOTE: this is passed rather than W as CrossOriginSet will invoke the [[GetOwnProperty]] internal method.
|
||||||
return cross_origin_set(global_object, *this, property_key, value, receiver);
|
return cross_origin_set(vm, *this, property_key, value, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.4.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-delete
|
// 7.4.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-delete
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue