diff options
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 16 | ||||
-rw-r--r-- | components/script/dom/bindings/error.rs | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/js.rs | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/proxyhandler.rs | 80 | ||||
-rw-r--r-- | components/script/dom/bindings/utils.rs | 30 |
6 files changed, 62 insertions, 72 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index b4394647bbd..5c1f4c771cb 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -121,7 +121,7 @@ pub fn WrapCallThisObject<T: Reflectable>(cx: *mut JSContext, unsafe { if JS_WrapObject(cx, &mut obj) == 0 { - return ptr::mut_null(); + return ptr::null_mut(); } } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 8ec5f24ccdd..383595248c3 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1757,6 +1757,7 @@ class CGAbstractMethod(CGThing): decorators.append('#[inline(always)]') if self.extern: + decorators.append('unsafe') decorators.append('extern') if self.pub: @@ -1797,7 +1798,7 @@ let obj = with_compartment(aCx, proto, || { NewProxyObject(aCx, handler, &private, proto, %s, - ptr::mut_null(), ptr::mut_null()) + ptr::null_mut(), ptr::null_mut()) }); assert!(obj.is_not_null()); @@ -3665,7 +3666,7 @@ if expando.is_not_null() { } } """ + namedGet + """ -(*desc).obj = ptr::mut_null(); +(*desc).obj = ptr::null_mut(); return true;""" def definition_body(self): @@ -4302,11 +4303,11 @@ class CGDictionary(CGThing): return string.Template( "impl<'a, 'b> ${selfName}<'a, 'b> {\n" " pub fn empty() -> ${selfName}<'a, 'b> {\n" - " ${selfName}::new(ptr::mut_null(), NullValue()).unwrap()\n" + " ${selfName}::new(ptr::null_mut(), NullValue()).unwrap()\n" " }\n" " pub fn new(cx: *mut JSContext, val: JSVal) -> Result<${selfName}<'a, 'b>, ()> {\n" " let object = if val.is_null_or_undefined() {\n" - " ptr::mut_null()\n" + " ptr::null_mut()\n" " } else if val.is_object() {\n" " val.to_object()\n" " } else {\n" @@ -4538,7 +4539,6 @@ class CGBindingRoot(CGThing): 'dom::bindings::conversions::{Default, Empty}', 'dom::bindings::codegen::*', 'dom::bindings::codegen::Bindings::*', - 'dom::bindings::codegen::RegisterBindings', 'dom::bindings::codegen::UnionTypes::*', 'dom::bindings::error::{FailureUnknown, Fallible, Error, ErrorResult}', 'dom::bindings::error::throw_dom_exception', @@ -4914,7 +4914,7 @@ class CGCallback(CGClass): # the private method. argnames = [arg.name for arg in args] argnamesWithThis = ["s.GetContext()", "thisObjJS"] + argnames - argnamesWithoutThis = ["s.GetContext()", "ptr::mut_null()"] + argnames + argnamesWithoutThis = ["s.GetContext()", "ptr::null_mut()"] + argnames # Now that we've recorded the argnames for our call to our private # method, insert our optional argument for deciding whether the # CallSetup should re-throw exceptions on aRv. @@ -5477,12 +5477,12 @@ class GlobalGenRoots(): } #[inline(always)] - fn from_ref<'a, T: ${fromBound}>(derived: JSRef<'a, T>) -> JSRef<'a, Self> { + fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, Self> { unsafe { derived.transmute() } } #[inline(always)] - fn from_borrowed_ref<'a, 'b, T: ${fromBound}>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, Self> { + fn from_borrowed_ref<'a, 'b, T: ${fromBound}+Reflectable>(derived: &'a JSRef<'b, T>) -> &'a JSRef<'b, Self> { unsafe { derived.transmute_borrowed() } } diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index cb39e4f0755..e2e06d8205a 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -97,7 +97,7 @@ static ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { }; /// Callback used to throw `TypeError`s. -extern fn get_error_message(_user_ref: *mut libc::c_void, +unsafe extern fn get_error_message(_user_ref: *mut libc::c_void, _locale: *const libc::c_char, error_number: libc::c_uint) -> *const JSErrorFormatString { @@ -109,6 +109,6 @@ extern fn get_error_message(_user_ref: *mut libc::c_void, pub fn throw_type_error(cx: *mut JSContext, error: &str) { let error = error.to_c_str(); unsafe { - JS_ReportErrorNumber(cx, Some(get_error_message), ptr::mut_null(), 0, error.as_ptr()); + JS_ReportErrorNumber(cx, Some(get_error_message), ptr::null_mut(), 0, error.as_ptr()); } } diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 5395db760fd..3fff9445c3c 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -255,7 +255,7 @@ impl<T> Assignable<T> for JS<T> { } } -impl<'a, T> Assignable<T> for JSRef<'a, T> { +impl<'a, T: Reflectable> Assignable<T> for JSRef<'a, T> { unsafe fn get_js(&self) -> JS<T> { self.unrooted() } diff --git a/components/script/dom/bindings/proxyhandler.rs b/components/script/dom/bindings/proxyhandler.rs index f2c1486280d..3c26206c373 100644 --- a/components/script/dom/bindings/proxyhandler.rs +++ b/components/script/dom/bindings/proxyhandler.rs @@ -26,11 +26,10 @@ use std::mem::size_of; static JSPROXYSLOT_EXPANDO: u32 = 0; -pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, - id: jsid, set: bool, - desc: *mut JSPropertyDescriptor) - -> bool { - unsafe { +pub unsafe extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, + id: jsid, set: bool, + desc: *mut JSPropertyDescriptor) + -> bool { let handler = GetProxyHandler(proxy); if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, set, desc) { return false; @@ -42,55 +41,50 @@ pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, //let proto = JS_GetPrototype(proxy); let proto = GetObjectProto(proxy); if proto.is_null() { - (*desc).obj = ptr::mut_null(); + (*desc).obj = ptr::null_mut(); return true; } JS_GetPropertyDescriptorById(cx, proto, id, JSRESOLVE_QUALIFIED, desc) != 0 - } } -pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - desc: *mut JSPropertyDescriptor) -> bool { +pub unsafe fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, + desc: *mut JSPropertyDescriptor) -> bool { static JSMSG_GETTER_ONLY: libc::c_uint = 160; - unsafe { - //FIXME: Workaround for https://github.com/mozilla/rust/issues/13385 - let setter: *const libc::c_void = mem::transmute((*desc).setter); - let setter_stub: *const libc::c_void = mem::transmute(JS_StrictPropertyStub); - if ((*desc).attrs & JSPROP_GETTER) != 0 && setter == setter_stub { - return JS_ReportErrorFlagsAndNumber(cx, - JSREPORT_WARNING | JSREPORT_STRICT | - JSREPORT_STRICT_MODE_ERROR, - Some(RUST_js_GetErrorMessage), ptr::mut_null(), - JSMSG_GETTER_ONLY) != 0; - } - - let expando = EnsureExpandoObject(cx, proxy); - if expando.is_null() { - return false; - } + //FIXME: Workaround for https://github.com/mozilla/rust/issues/13385 + let setter: *const libc::c_void = mem::transmute((*desc).setter); + let setter_stub: *const libc::c_void = mem::transmute(JS_StrictPropertyStub); + if ((*desc).attrs & JSPROP_GETTER) != 0 && setter == setter_stub { + return JS_ReportErrorFlagsAndNumber(cx, + JSREPORT_WARNING | JSREPORT_STRICT | + JSREPORT_STRICT_MODE_ERROR, + Some(RUST_js_GetErrorMessage), ptr::null_mut(), + JSMSG_GETTER_ONLY) != 0; + } - return JS_DefinePropertyById(cx, expando, id, (*desc).value, (*desc).getter, - (*desc).setter, (*desc).attrs) != 0; + let expando = EnsureExpandoObject(cx, proxy); + if expando.is_null() { + return false; } + + return JS_DefinePropertyById(cx, expando, id, (*desc).value, (*desc).getter, + (*desc).setter, (*desc).attrs) != 0; } -pub extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - desc: *mut JSPropertyDescriptor) -> bool { +pub unsafe extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, + desc: *mut JSPropertyDescriptor) -> bool { defineProperty_(cx, proxy, id, desc) } -pub extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - bp: *mut bool) -> bool { - unsafe { - let expando = EnsureExpandoObject(cx, proxy); - if expando.is_null() { - return false; - } - - return delete_property_by_id(cx, expando, id, &mut *bp); +pub unsafe extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, + bp: *mut bool) -> bool { + let expando = EnsureExpandoObject(cx, proxy); + if expando.is_null() { + return false; } + + return delete_property_by_id(cx, expando, id, &mut *bp); } pub fn _obj_toString(cx: *mut JSContext, className: *const libc::c_char) -> *mut JSString { @@ -99,7 +93,7 @@ pub fn _obj_toString(cx: *mut JSContext, className: *const libc::c_char) -> *mut let nchars = "[object ]".len() + name.len(); let chars: *mut jschar = JS_malloc(cx, (nchars + 1) as libc::size_t * (size_of::<jschar>() as libc::size_t)) as *mut jschar; if chars.is_null() { - return ptr::mut_null(); + return ptr::null_mut(); } let result = format!("[object {}]", name); @@ -121,7 +115,7 @@ pub fn GetExpandoObject(obj: *mut JSObject) -> *mut JSObject { assert!(is_dom_proxy(obj)); let val = GetProxyExtra(obj, JSPROXYSLOT_EXPANDO); if val.is_undefined() { - ptr::mut_null() + ptr::null_mut() } else { val.to_object() } @@ -133,11 +127,11 @@ pub fn EnsureExpandoObject(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObj assert!(is_dom_proxy(obj)); let mut expando = GetExpandoObject(obj); if expando.is_null() { - expando = JS_NewObjectWithGivenProto(cx, ptr::mut_null(), - ptr::mut_null(), + expando = JS_NewObjectWithGivenProto(cx, ptr::null_mut(), + ptr::null_mut(), GetObjectParent(obj)); if expando.is_null() { - return ptr::mut_null(); + return ptr::null_mut(); } SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(&*expando)); diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 0f6ab2098fe..a923371ae8e 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -129,7 +129,7 @@ pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject, let dom_class = get_dom_class(obj).or_else(|_| { if IsWrapper(obj) == 1 { debug!("found wrapper"); - obj = UnwrapObject(obj, /* stopAtOuter = */ 0, ptr::mut_null()); + obj = UnwrapObject(obj, /* stopAtOuter = */ 0, ptr::null_mut()); if obj.is_null() { debug!("unwrapping security wrapper failed"); Err(()) @@ -421,7 +421,7 @@ fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject, /// A throwing constructor, for those interfaces that have neither /// `NoInterfaceObject` nor `Constructor`. -pub extern fn ThrowingConstructor(cx: *mut JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool { +pub unsafe extern fn ThrowingConstructor(cx: *mut JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool { throw_type_error(cx, "Illegal constructor."); return 0; } @@ -488,7 +488,7 @@ impl Reflector { /// Create an uninitialized `Reflector`. pub fn new() -> Reflector { Reflector { - object: Cell::new(ptr::mut_null()), + object: Cell::new(ptr::null_mut()), } } } @@ -613,7 +613,7 @@ pub fn get_dictionary_property(cx: *mut JSContext, pub fn HasPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> bool { // MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler); let mut found = false; - return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::mut_null()) || found; + return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::null_mut()) || found; } /// Returns whether `obj` can be converted to a callback interface per IDL. @@ -626,9 +626,9 @@ pub fn IsConvertibleToCallbackInterface(cx: *mut JSContext, obj: *mut JSObject) /// Create a DOM global object with the given class. pub fn CreateDOMGlobal(cx: *mut JSContext, class: *const JSClass) -> *mut JSObject { unsafe { - let obj = JS_NewGlobalObject(cx, class, ptr::mut_null()); + let obj = JS_NewGlobalObject(cx, class, ptr::null_mut()); if obj.is_null() { - return ptr::mut_null(); + return ptr::null_mut(); } with_compartment(cx, obj, || { JS_InitStandardClasses(cx, obj); @@ -639,18 +639,14 @@ pub fn CreateDOMGlobal(cx: *mut JSContext, class: *const JSClass) -> *mut JSObje } /// Callback to outerize windows when wrapping. -pub extern fn wrap_for_same_compartment(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject { - unsafe { - JS_ObjectToOuterObject(cx, obj) - } +pub unsafe extern fn wrap_for_same_compartment(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject { + JS_ObjectToOuterObject(cx, obj) } /// Callback to outerize windows before wrapping. -pub extern fn pre_wrap(cx: *mut JSContext, _scope: *mut JSObject, +pub unsafe extern fn pre_wrap(cx: *mut JSContext, _scope: *mut JSObject, obj: *mut JSObject, _flags: c_uint) -> *mut JSObject { - unsafe { - JS_ObjectToOuterObject(cx, obj) - } + JS_ObjectToOuterObject(cx, obj) } /// Callback to outerize windows. @@ -664,7 +660,7 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut IDLInterface::get_prototype_depth(None::<window::Window>)) .unwrap() .root(); - win.deref().browser_context.deref().borrow().get_ref().window_proxy() + win.deref().browser_context.deref().borrow().as_ref().unwrap().window_proxy() } } @@ -675,12 +671,12 @@ pub fn global_object_for_js_object(obj: *mut JSObject) -> GlobalField { let global = GetGlobalForObjectCrossCompartment(obj); let clasp = JS_GetClass(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); - match FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) { + match FromJSValConvertible::from_jsval(ptr::null_mut(), ObjectOrNullValue(global), ()) { Ok(window) => return WindowField(window), Err(_) => (), } - match FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) { + match FromJSValConvertible::from_jsval(ptr::null_mut(), ObjectOrNullValue(global), ()) { Ok(worker) => return WorkerField(worker), Err(_) => (), } |