diff options
author | Josh Matthews <josh@joshmatthews.net> | 2022-11-20 00:34:37 -0500 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2022-11-23 10:04:50 -0500 |
commit | bd77a4043c559c40bbd2edd4a5391096f5b8da45 (patch) | |
tree | 074f35996417a7ebe8c19b6af6f2acc8c1121043 /components/script/dom/bindings/proxyhandler.rs | |
parent | f1bb3dcad088073de5cfa11f2e992441b5d4467d (diff) | |
download | servo-bd77a4043c559c40bbd2edd4a5391096f5b8da45.tar.gz servo-bd77a4043c559c40bbd2edd4a5391096f5b8da45.zip |
Changes for spidermomkey upgrade.
Diffstat (limited to 'components/script/dom/bindings/proxyhandler.rs')
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 85 |
1 files changed, 39 insertions, 46 deletions
diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index 3650df6186b..1d9e8155104 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -44,8 +44,8 @@ use js::jsval::ObjectValue; use js::jsval::UndefinedValue; use js::rust::wrappers::JS_AlreadyHasOwnPropertyById; use js::rust::wrappers::JS_NewObjectWithGivenProto; -use js::rust::wrappers::{AppendToIdVector, RUST_INTERNED_STRING_TO_JSID}; -use js::rust::{get_context_realm, Handle, HandleObject, MutableHandle, MutableHandleObject}; +use js::rust::wrappers::{AppendToIdVector, RUST_INTERNED_STRING_TO_JSID, SetDataPropertyDescriptor}; +use js::rust::{get_context_realm, Handle, HandleObject, HandleValue, MutableHandle, MutableHandleObject}; use std::{ffi::CStr, os::raw::c_char, ptr}; /// Determine if this id shadows any existing properties for this proxy. @@ -189,15 +189,16 @@ pub unsafe fn ensure_expando_object( /// Set the property descriptor's object to `obj` and set it to enumerable, /// and writable if `readonly` is true. -pub fn fill_property_descriptor( - mut desc: MutableHandle<PropertyDescriptor>, - obj: *mut JSObject, +pub fn set_property_descriptor( + desc: MutableHandle<PropertyDescriptor>, + value: HandleValue, attrs: u32, + is_none: &mut bool, ) { - desc.obj = obj; - desc.attrs = attrs; - desc.getter = None; - desc.setter = None; + unsafe { + SetDataPropertyDescriptor(desc, value, attrs); + } + *is_none = false; } /// <https://html.spec.whatwg.org/multipage/#isplatformobjectsameorigin-(-o-)> @@ -333,12 +334,14 @@ pub unsafe extern "C" fn maybe_cross_origin_set_rawcx( // OrdinarySet // <https://tc39.es/ecma262/#sec-ordinaryset> rooted!(in(*cx) let mut own_desc = PropertyDescriptor::default()); + let mut is_none = false; if !InvokeGetOwnPropertyDescriptor( GetProxyHandler(*proxy), *cx, proxy, id, own_desc.handle_mut().into(), + &mut is_none, ) { return false; } @@ -439,26 +442,28 @@ pub unsafe fn cross_origin_get( ) -> bool { // > 1. Let `desc` be `? O.[[GetOwnProperty]](P)`. rooted!(in(*cx) let mut descriptor = PropertyDescriptor::default()); + let mut is_none = false; if !InvokeGetOwnPropertyDescriptor( GetProxyHandler(*proxy), *cx, proxy, id, descriptor.handle_mut().into(), + &mut is_none, ) { return false; } // > 2. Assert: `desc` is not undefined. assert!( - !descriptor.obj.is_null(), + !is_none, "Callees should throw in all cases when they are not finding \ a property decriptor" ); // > 3. If `! IsDataDescriptor(desc)` is true, then return `desc.[[Value]]`. if is_data_descriptor(&descriptor) { - vp.set(descriptor.value); + vp.set(descriptor.value_); return true; } @@ -504,19 +509,21 @@ pub unsafe fn cross_origin_set( ) -> bool { // > 1. Let desc be ? O.[[GetOwnProperty]](P). rooted!(in(*cx) let mut descriptor = PropertyDescriptor::default()); + let mut is_none = false; if !InvokeGetOwnPropertyDescriptor( GetProxyHandler(*proxy), *cx, proxy, id, descriptor.handle_mut().into(), + &mut is_none, ) { return false; } // > 2. Assert: desc is not undefined. assert!( - !descriptor.obj.is_null(), + !is_none, "Callees should throw in all cases when they are not finding \ a property decriptor" ); @@ -557,32 +564,25 @@ pub unsafe fn cross_origin_set( } unsafe fn get_getter_object(d: &PropertyDescriptor, out: RawMutableHandleObject) { - if (d.attrs & jsapi::JSPROP_GETTER as u32) != 0 { - out.set(std::mem::transmute(d.getter)); + if d.hasGetter_() { + out.set(std::mem::transmute(d.getter_)); } } unsafe fn get_setter_object(d: &PropertyDescriptor, out: RawMutableHandleObject) { - if (d.attrs & jsapi::JSPROP_SETTER as u32) != 0 { - out.set(std::mem::transmute(d.setter)); + if d.hasSetter_() { + out.set(std::mem::transmute(d.setter_)); } } /// <https://tc39.es/ecma262/#sec-isaccessordescriptor> fn is_accessor_descriptor(d: &PropertyDescriptor) -> bool { - d.attrs & (jsapi::JSPROP_GETTER as u32 | jsapi::JSPROP_SETTER as u32) != 0 + d.hasSetter_() || d.hasGetter_() } /// <https://tc39.es/ecma262/#sec-isdatadescriptor> fn is_data_descriptor(d: &PropertyDescriptor) -> bool { - let is_accessor = is_accessor_descriptor(d); - let is_generic = d.attrs & - (jsapi::JSPROP_GETTER as u32 | - jsapi::JSPROP_SETTER as u32 | - jsapi::JSPROP_IGNORE_READONLY | - jsapi::JSPROP_IGNORE_VALUE) == - jsapi::JSPROP_IGNORE_READONLY | jsapi::JSPROP_IGNORE_VALUE; - !is_accessor && !is_generic + d.hasWritable_() || d.hasValue_() } /// Evaluate `CrossOriginGetOwnPropertyHelper(proxy, id) != null`. @@ -621,7 +621,8 @@ pub unsafe fn cross_origin_get_own_property_helper( proxy: RawHandleObject, cross_origin_properties: &'static CrossOriginProperties, id: RawHandleId, - mut desc: RawMutableHandle<PropertyDescriptor>, + desc: RawMutableHandle<PropertyDescriptor>, + is_none: &mut bool, ) -> bool { rooted!(in(*cx) let mut holder = ptr::null_mut::<JSObject>()); @@ -632,15 +633,7 @@ pub unsafe fn cross_origin_get_own_property_helper( holder.handle_mut().into(), ); - if !JS_GetOwnPropertyDescriptorById(*cx, holder.handle().into(), id, desc) { - return false; - } - - if !desc.obj.is_null() { - desc.obj = proxy.get(); - } - - true + return JS_GetOwnPropertyDescriptorById(*cx, holder.handle().into(), id, desc, is_none); } /// Implementation of [`CrossOriginPropertyFallback`]. @@ -651,24 +644,24 @@ pub unsafe fn cross_origin_get_own_property_helper( /// [`CrossOriginPropertyFallback`]: https://html.spec.whatwg.org/multipage/#crossoriginpropertyfallback-(-p-) pub unsafe fn cross_origin_property_fallback( cx: SafeJSContext, - proxy: RawHandleObject, + _proxy: RawHandleObject, id: RawHandleId, - mut desc: RawMutableHandle<PropertyDescriptor>, + desc: RawMutableHandle<PropertyDescriptor>, + is_none: &mut bool, ) -> bool { - assert!(desc.obj.is_null(), "why are we being called?"); + assert!(*is_none, "why are we being called?"); // > 1. If P is `then`, `@@toStringTag`, `@@hasInstance`, or // > `@@isConcatSpreadable`, then return `PropertyDescriptor{ [[Value]]: // > undefined, [[Writable]]: false, [[Enumerable]]: false, // > [[Configurable]]: true }`. if is_cross_origin_allowlisted_prop(cx, id) { - *desc = PropertyDescriptor { - getter: None, - setter: None, - value: UndefinedValue(), - attrs: jsapi::JSPROP_READONLY as u32, - obj: proxy.get(), - }; + set_property_descriptor( + MutableHandle::from_raw(desc), + HandleValue::undefined(), + jsapi::JSPROP_READONLY as u32, + is_none, + ); return true; } @@ -695,7 +688,7 @@ unsafe fn is_cross_origin_allowlisted_prop(cx: SafeJSContext, id: RawHandleId) - ); // `jsid`s containing `JS::Symbol *` can be compared by // referential equality - allowed_id.get().asBits == id.asBits + allowed_id.get().asBits_ == id.asBits_ }) } |