diff options
author | yvt <i@yvt.jp> | 2021-07-26 01:07:29 +0900 |
---|---|---|
committer | yvt <i@yvt.jp> | 2021-07-26 01:07:29 +0900 |
commit | c28e98ec40e0950e77c60b32af023c6eb7da7366 (patch) | |
tree | 6fcc0af229cba18114dd347e19ee5687c0f9ea21 /components/script/dom/bindings/proxyhandler.rs | |
parent | 66a4ea0727cf1e1cec8c6d49bcea495ff8b0650e (diff) | |
download | servo-c28e98ec40e0950e77c60b32af023c6eb7da7366.tar.gz servo-c28e98ec40e0950e77c60b32af023c6eb7da7366.zip |
refactor(script): squash `CGDOMJSProxyHandler_set`
The implementation in `crate::dom::bindings::proxyhandler::
maybe_cross_origin_set_rawcx` is now directly assigned to `ProxyTraps::
set`.
Diffstat (limited to 'components/script/dom/bindings/proxyhandler.rs')
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index fb05f17611e..4a00a71fa04 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -310,6 +310,50 @@ pub unsafe fn cross_origin_own_property_keys( true } +/// Implementation of `[[Set]]` for [`Location`]. +/// +/// [`Location`]: https://html.spec.whatwg.org/multipage/#location-set +pub unsafe extern "C" fn maybe_cross_origin_set_rawcx( + cx: *mut JSContext, + proxy: RawHandleObject, + id: RawHandleId, + v: RawHandleValue, + receiver: RawHandleValue, + result: *mut ObjectOpResult, +) -> bool { + let cx = SafeJSContext::from_ptr(cx); + + if !is_platform_object_same_origin(cx, proxy) { + return cross_origin_set(cx, proxy, id, v, receiver, result); + } + + // Safe to enter the Realm of proxy now. + let _ac = JSAutoRealm::new(*cx, proxy.get()); + + // OrdinarySet + // <https://tc39.es/ecma262/#sec-ordinaryset> + rooted!(in(*cx) let mut own_desc = PropertyDescriptor::default()); + if !InvokeGetOwnPropertyDescriptor( + GetProxyHandler(*proxy), + *cx, + proxy, + id, + own_desc.handle_mut().into(), + ) { + return false; + } + + js::jsapi::SetPropertyIgnoringNamedGetter( + *cx, + proxy, + id, + v, + receiver, + own_desc.handle().into(), + result, + ) +} + pub unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_rawcx( _: *mut JSContext, _proxy: RawHandleObject, |