diff options
Diffstat (limited to 'components/script/dom/bindings/proxyhandler.rs')
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 97 |
1 files changed, 56 insertions, 41 deletions
diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index 2a512b02df3..86b7d81667c 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -30,12 +30,12 @@ use js::rust::wrappers::JS_AlreadyHasOwnPropertyById; use js::rust::wrappers::JS_NewObjectWithGivenProto; use std::ptr; - /// Determine if this id shadows any existing properties for this proxy. -pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext, - object: RawHandleObject, - id: RawHandleId) - -> DOMProxyShadowsResult { +pub unsafe extern "C" fn shadow_check_callback( + cx: *mut JSContext, + object: RawHandleObject, + id: RawHandleId, +) -> DOMProxyShadowsResult { // TODO: support OverrideBuiltins when #12978 is fixed. rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>()); @@ -59,19 +59,19 @@ pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext, /// Initialize the infrastructure for DOM proxy objects. pub unsafe fn init() { - SetDOMProxyInformation(GetProxyHandlerFamily(), - Some(shadow_check_callback)); + SetDOMProxyInformation(GetProxyHandlerFamily(), Some(shadow_check_callback)); } /// Invoke the [[GetOwnProperty]] trap (`getOwnPropertyDescriptor`) on `proxy`, /// with argument `id` and return the result, if it is not `undefined`. /// Otherwise, walk along the prototype chain to find a property with that /// name. -pub unsafe extern "C" fn get_property_descriptor(cx: *mut JSContext, - proxy: RawHandleObject, - id: RawHandleId, - desc: RawMutableHandle<PropertyDescriptor>) - -> bool { +pub unsafe extern "C" fn get_property_descriptor( + cx: *mut JSContext, + proxy: RawHandleObject, + id: RawHandleId, + desc: RawMutableHandle<PropertyDescriptor>, +) -> bool { let handler = GetProxyHandler(proxy.get()); if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) { return false; @@ -91,23 +91,25 @@ pub unsafe extern "C" fn get_property_descriptor(cx: *mut JSContext, } /// Defines an expando on the given `proxy`. -pub unsafe extern "C" fn define_property(cx: *mut JSContext, - proxy: RawHandleObject, - id: RawHandleId, - desc: RawHandle<PropertyDescriptor>, - result: *mut ObjectOpResult) - -> bool { +pub unsafe extern "C" fn define_property( + cx: *mut JSContext, + proxy: RawHandleObject, + id: RawHandleId, + desc: RawHandle<PropertyDescriptor>, + result: *mut ObjectOpResult, +) -> bool { rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>()); ensure_expando_object(cx, proxy, expando.handle_mut()); JS_DefinePropertyById(cx, expando.handle().into(), id, desc, result) } /// Deletes an expando off the given `proxy`. -pub unsafe extern "C" fn delete(cx: *mut JSContext, - proxy: RawHandleObject, - id: RawHandleId, - bp: *mut ObjectOpResult) - -> bool { +pub unsafe extern "C" fn delete( + cx: *mut JSContext, + proxy: RawHandleObject, + id: RawHandleId, + bp: *mut ObjectOpResult, +) -> bool { rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>()); get_expando_object(proxy, expando.handle_mut()); if expando.is_null() { @@ -119,19 +121,21 @@ pub unsafe extern "C" fn delete(cx: *mut JSContext, } /// Controls whether the Extensible bit can be changed -pub unsafe extern "C" fn prevent_extensions(_cx: *mut JSContext, - _proxy: RawHandleObject, - result: *mut ObjectOpResult) - -> bool { +pub unsafe extern "C" fn prevent_extensions( + _cx: *mut JSContext, + _proxy: RawHandleObject, + result: *mut ObjectOpResult, +) -> bool { (*result).code_ = JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS as ::libc::uintptr_t; true } /// Reports whether the object is Extensible -pub unsafe extern "C" fn is_extensible(_cx: *mut JSContext, - _proxy: RawHandleObject, - succeeded: *mut bool) - -> bool { +pub unsafe extern "C" fn is_extensible( + _cx: *mut JSContext, + _proxy: RawHandleObject, + succeeded: *mut bool, +) -> bool { *succeeded = true; true } @@ -145,11 +149,12 @@ pub unsafe extern "C" fn is_extensible(_cx: *mut JSContext, /// This implementation always handles the case of the ordinary /// `[[GetPrototypeOf]]` behavior. An alternative implementation will be /// necessary for the Location object. -pub unsafe extern "C" fn get_prototype_if_ordinary(_: *mut JSContext, - proxy: RawHandleObject, - is_ordinary: *mut bool, - proto: RawMutableHandleObject) - -> bool { +pub unsafe extern "C" fn get_prototype_if_ordinary( + _: *mut JSContext, + proxy: RawHandleObject, + is_ordinary: *mut bool, + proto: RawMutableHandleObject, +) -> bool { *is_ordinary = true; proto.set(GetStaticPrototype(proxy.get())); true @@ -169,11 +174,19 @@ pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandl /// Get the expando object, or create it if it doesn't exist yet. /// Fails on JSAPI failure. -pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: RawHandleObject, mut expando: MutableHandleObject) { +pub unsafe fn ensure_expando_object( + cx: *mut JSContext, + obj: RawHandleObject, + mut expando: MutableHandleObject, +) { assert!(is_dom_proxy(obj.get())); get_expando_object(obj, expando); if expando.is_null() { - expando.set(JS_NewObjectWithGivenProto(cx, ptr::null_mut(), HandleObject::null())); + expando.set(JS_NewObjectWithGivenProto( + cx, + ptr::null_mut(), + HandleObject::null(), + )); assert!(!expando.is_null()); SetProxyPrivate(obj.get(), &ObjectValue(expando.get())); @@ -182,9 +195,11 @@ pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: RawHandleObject, mu /// 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, - attrs: u32) { +pub fn fill_property_descriptor( + mut desc: MutableHandle<PropertyDescriptor>, + obj: *mut JSObject, + attrs: u32, +) { desc.obj = obj; desc.attrs = attrs; desc.getter = None; |