diff --git a/src/components/script/dom/bindings/callback.rs b/src/components/script/dom/bindings/callback.rs index 96ddae184cc0..8a29c382ca94 100644 --- a/src/components/script/dom/bindings/callback.rs +++ b/src/components/script/dom/bindings/callback.rs @@ -2,13 +2,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::bindings::trace::trace_object; use dom::bindings::utils::Reflectable; use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable}; -use js::jsapi::{JS_GetProperty, JSTracer, JS_CallTracer}; +use js::jsapi::{JS_GetProperty, JSTracer}; use js::jsval::{JSVal, UndefinedValue}; -use js::JSTRACE_OBJECT; -use libc; use std::cast; use std::ptr; @@ -27,45 +26,40 @@ pub enum ExceptionHandling { #[deriving(Clone,Eq)] pub struct CallbackInterface { - pub callback: *JSObject + pub callback: *mut JSObject } impl, E> Encodable for CallbackInterface { fn encode(&self, s: &mut S) -> Result<(), E> { unsafe { let tracer: *mut JSTracer = cast::transmute(s); - "callback".to_c_str().with_ref(|name| { - (*tracer).debugPrinter = ptr::null(); - (*tracer).debugPrintIndex = -1; - (*tracer).debugPrintArg = name as *libc::c_void; - JS_CallTracer(tracer as *JSTracer, self.callback, JSTRACE_OBJECT as u32); - }); - }; + trace_object(tracer, "callback", self.callback); + } Ok(()) } } pub trait CallbackContainer { - fn callback(&self) -> *JSObject; + fn callback(&self) -> *mut JSObject; } impl CallbackContainer for CallbackInterface { - fn callback(&self) -> *JSObject { + fn callback(&self) -> *mut JSObject { self.callback } } impl CallbackInterface { - pub fn new(callback: *JSObject) -> CallbackInterface { + pub fn new(callback: *mut JSObject) -> CallbackInterface { CallbackInterface { callback: callback } } - pub fn GetCallableProperty(&self, cx: *JSContext, name: &str) -> Result { + pub fn GetCallableProperty(&self, cx: *mut JSContext, name: &str) -> Result { let mut callable = UndefinedValue(); unsafe { - if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback, name, &mut callable as *mut JSVal as *JSVal)) == 0 { + if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback, name, &mut callable)) == 0 { return Err(()); } @@ -79,19 +73,19 @@ impl CallbackInterface { } } -pub fn GetJSObjectFromCallback(callback: &T) -> *JSObject { +pub fn GetJSObjectFromCallback(callback: &T) -> *mut JSObject { callback.callback() } -pub fn WrapCallThisObject(cx: *JSContext, - _scope: *JSObject, - p: Box) -> *JSObject { - let obj = GetJSObjectFromCallback(p); +pub fn WrapCallThisObject(cx: *mut JSContext, + _scope: *mut JSObject, + p: Box) -> *mut JSObject { + let mut obj = GetJSObjectFromCallback(p); assert!(obj.is_not_null()); unsafe { - if JS_WrapObject(cx, &obj) == 0 { - return ptr::null(); + if JS_WrapObject(cx, &mut obj) == 0 { + return ptr::mut_null(); } } @@ -99,19 +93,19 @@ pub fn WrapCallThisObject(cx: *JSC } pub struct CallSetup { - pub cx: *JSContext, + pub cx: *mut JSContext, pub handling: ExceptionHandling } impl CallSetup { - pub fn new(cx: *JSContext, handling: ExceptionHandling) -> CallSetup { + pub fn new(cx: *mut JSContext, handling: ExceptionHandling) -> CallSetup { CallSetup { cx: cx, handling: handling } } - pub fn GetContext(&self) -> *JSContext { + pub fn GetContext(&self) -> *mut JSContext { self.cx } } diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 14a3cc1829e7..a749bbce65e1 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -213,7 +213,7 @@ def getPerSignatureCall(signature, argConversionStartsAt=0, signatureIndex=0): # Doesn't matter which of the possible signatures we use, since # they all have the same types up to that point; just use # possibleSignatures[0] - caseBody = [CGGeneric("let argv_start = JS_ARGV(cx, vp as *JSVal);")] + caseBody = [CGGeneric("let argv_start = JS_ARGV(cx, vp);")] caseBody.extend([ CGArgumentConverter(possibleSignatures[0][1][i], i, "argv_start", "argc", descriptor) for i in @@ -960,11 +960,11 @@ def getRetvalDeclarationForType(returnType, descriptorProvider): if returnType.isCallback(): # XXXbz we're going to assume that callback types are always # nullable for now. - return CGGeneric("*JSObject") + return CGGeneric("*mut JSObject") if returnType.isAny(): return CGGeneric("JSVal") if returnType.isObject() or returnType.isSpiderMonkeyInterface(): - return CGGeneric("*JSObject") + return CGGeneric("*mut JSObject") if returnType.isSequence(): raise TypeError("We don't support sequence return values") @@ -1492,14 +1492,7 @@ def define(self): hasInstance: None, construct: None, trace: None, - reserved: (0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 05 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 10 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 15 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 20 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 25 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 30 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 35 - 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void) // 40 + reserved: [0 as *mut libc::c_void, ..40] }; """ % (len(self.descriptor.interface.identifier.name + "Prototype") + 1, str_to_const_array(self.descriptor.interface.identifier.name + "Prototype")) @@ -1726,12 +1719,12 @@ def CreateBindingJSObject(descriptor, parent=None): create += """ let js_info = aScope.deref().page().js_info(); let handler = js_info.get_ref().dom_static.proxy_handlers.deref().get(&(PrototypeList::id::%s as uint)); - let private = PrivateValue(squirrel_away_unique(aObject) as *libc::c_void); + let mut private = PrivateValue(squirrel_away_unique(aObject) as *libc::c_void); let obj = with_compartment(aCx, proto, || { NewProxyObject(aCx, *handler, &private, proto, %s, - ptr::null(), ptr::null()) + ptr::mut_null(), ptr::mut_null()) }); assert!(obj.is_not_null()); @@ -1754,10 +1747,10 @@ class CGWrapMethod(CGAbstractMethod): def __init__(self, descriptor): assert descriptor.interface.hasInterfacePrototypeObject() if not descriptor.createGlobal: - args = [Argument('*JSContext', 'aCx'), Argument('&JSRef', 'aScope'), + args = [Argument('*mut JSContext', 'aCx'), Argument('&JSRef', 'aScope'), Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)] else: - args = [Argument('*JSContext', 'aCx'), + args = [Argument('*mut JSContext', 'aCx'), Argument("Box<%s>" % descriptor.concreteType, 'aObject', mutable=True)] retval = 'JS<%s>' % descriptor.concreteType CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True) @@ -1859,9 +1852,9 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): properties should be a PropertyArrays instance. """ def __init__(self, descriptor, properties): - args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aGlobal'), - Argument('*JSObject', 'aReceiver')] - CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*JSObject', args) + args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'), + Argument('*mut JSObject', 'aReceiver')] + CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', '*mut JSObject', args) self.properties = properties def definition_body(self): protoChain = self.descriptor.prototypeChain @@ -1894,9 +1887,9 @@ def definition_body(self): else: prefCache = None - getParentProto = ("let parentProto: *JSObject = %s;\n" + + getParentProto = ("let parentProto: *mut JSObject = %s;\n" + "if parentProto.is_null() {\n" + - " return ptr::null();\n" + + " return ptr::mut_null();\n" + "}\n") % getParentProto if self.descriptor.interface.ctor(): @@ -1956,10 +1949,10 @@ class CGGetPerInterfaceObject(CGAbstractMethod): constructor object). """ def __init__(self, descriptor, name, idPrefix="", pub=False): - args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aGlobal'), - Argument('*JSObject', 'aReceiver')] + args = [Argument('*mut JSContext', 'aCx'), Argument('*mut JSObject', 'aGlobal'), + Argument('*mut JSObject', 'aReceiver')] CGAbstractMethod.__init__(self, descriptor, name, - '*JSObject', args, pub=pub) + '*mut JSObject', args, pub=pub) self.id = idPrefix + "id::" + self.descriptor.name def definition_body(self): return """ @@ -1973,10 +1966,10 @@ def definition_body(self): assert!(((*JS_GetClass(aGlobal)).flags & JSCLASS_DOM_GLOBAL) != 0); /* Check to see whether the interface objects are already installed */ - let protoOrIfaceArray: *mut *JSObject = GetProtoOrIfaceArray(aGlobal) as *mut *JSObject; - let cachedObject: *JSObject = *protoOrIfaceArray.offset(%s as int); + let protoOrIfaceArray = GetProtoOrIfaceArray(aGlobal); + let cachedObject: *mut JSObject = *protoOrIfaceArray.offset(%s as int); if cachedObject.is_null() { - let tmp: *JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver); + let tmp: *mut JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver); *protoOrIfaceArray.offset(%s as int) = tmp; tmp } else { @@ -2222,7 +2215,7 @@ def __init__(self, returnType, argsPre, arguments, nativeMethodName, static, def getArgv(self): return "argv" if self.argCount > 0 else "" def getArgvDecl(self): - return "\nlet argv = JS_ARGV(cx, vp as *JSVal);\n" + return "\nlet argv = JS_ARGV(cx, vp);\n" def getArgc(self): return "argc" def getArguments(self): @@ -2361,7 +2354,7 @@ def definition_body(self): FakeCastableDescriptor(self.descriptor), "obj", self.unwrapFailureCode)) unwrapThis = CGIndenter( - CGGeneric("let obj: *JSObject = JS_THIS_OBJECT(cx, vp as *mut JSVal);\n" + CGGeneric("let obj: *mut JSObject = JS_THIS_OBJECT(cx, vp as *mut JSVal);\n" "if obj.is_null() {\n" " return false as JSBool;\n" "}\n" @@ -2377,14 +2370,14 @@ class CGGenericMethod(CGAbstractBindingMethod): A class for generating the C++ code for an IDL method.. """ def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('libc::c_uint', 'argc'), + args = [Argument('*mut JSContext', 'cx'), Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] CGAbstractBindingMethod.__init__(self, descriptor, 'genericMethod', args) def generate_code(self): return CGIndenter(CGGeneric( - "let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n" - "return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *libc::c_void, argc, &*vp);")) + "let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n" + "return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *libc::c_void, argc, vp);")) class CGSpecializedMethod(CGAbstractExternMethod): """ @@ -2394,7 +2387,7 @@ class CGSpecializedMethod(CGAbstractExternMethod): def __init__(self, descriptor, method): self.method = method name = method.identifier.name - args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', '_obj'), + args = [Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'), Argument('*mut %s' % descriptor.concreteType, 'this'), Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args) @@ -2411,7 +2404,7 @@ class CGGenericGetter(CGAbstractBindingMethod): A class for generating the C++ code for an IDL attribute getter. """ def __init__(self, descriptor, lenientThis=False): - args = [Argument('*JSContext', 'cx'), Argument('libc::c_uint', 'argc'), + args = [Argument('*mut JSContext', 'cx'), Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] if lenientThis: name = "genericLenientGetter" @@ -2427,8 +2420,8 @@ def __init__(self, descriptor, lenientThis=False): def generate_code(self): return CGIndenter(CGGeneric( - "let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, &*vp));\n" - "return CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, &*vp);\n")) + "let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n" + "return CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, vp);\n")) class CGSpecializedGetter(CGAbstractExternMethod): """ @@ -2438,7 +2431,7 @@ class CGSpecializedGetter(CGAbstractExternMethod): def __init__(self, descriptor, attr): self.attr = attr name = 'get_' + attr.identifier.name - args = [ Argument('*JSContext', 'cx'), + args = [ Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'), Argument('*mut %s' % descriptor.concreteType, 'this'), Argument('*mut JSVal', 'vp') ] @@ -2462,7 +2455,7 @@ class CGGenericSetter(CGAbstractBindingMethod): A class for generating the Rust code for an IDL attribute setter. """ def __init__(self, descriptor, lenientThis=False): - args = [Argument('*JSContext', 'cx'), Argument('libc::c_uint', 'argc'), + args = [Argument('*mut JSContext', 'cx'), Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] if lenientThis: name = "genericLenientSetter" @@ -2477,9 +2470,9 @@ def __init__(self, descriptor, lenientThis=False): def generate_code(self): return CGIndenter(CGGeneric( - "let undef = UndefinedValue();\n" - "let argv: *JSVal = if argc != 0 { JS_ARGV(cx, vp as *JSVal) } else { &undef as *JSVal };\n" - "let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp as *JSVal));\n" + "let mut undef = UndefinedValue();\n" + "let argv: *mut JSVal = if argc != 0 { JS_ARGV(cx, vp) } else { &mut undef as *mut JSVal };\n" + "let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n" "if CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *libc::c_void, argv) == 0 {\n" " return 0;\n" "}\n" @@ -2494,7 +2487,7 @@ class CGSpecializedSetter(CGAbstractExternMethod): def __init__(self, descriptor, attr): self.attr = attr name = 'set_' + attr.identifier.name - args = [ Argument('*JSContext', 'cx'), + args = [ Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'), Argument('*mut %s' % descriptor.concreteType, 'this'), Argument('*mut JSVal', 'argv')] @@ -2604,7 +2597,7 @@ def __init__(self, enum): ]; impl ToJSValConvertible for valuelist { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { strings[*self as uint].to_owned().to_jsval(cx) } } @@ -2819,7 +2812,7 @@ def get_match(name): "Err(())" % ", ".join(names))) method = CGWrapper( CGIndenter(CGList(conversions, "\n\n")), - pre="fn from_jsval(cx: *JSContext, value: JSVal, _option: ()) -> Result<%s, ()> {\n" % self.type, + pre="fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result<%s, ()> {\n" % self.type, post="\n}") return CGWrapper( CGIndenter(method), @@ -2833,7 +2826,7 @@ def try_method(self, t): return CGWrapper( CGIndenter(jsConversion, 4), - pre="fn TryConvertTo%s(cx: *JSContext, value: JSVal) -> %s {\n" % (t.name, returnType), + pre="fn TryConvertTo%s(cx: *mut JSContext, value: JSVal) -> %s {\n" % (t.name, returnType), post="\n}") def define(self): @@ -3394,7 +3387,7 @@ def __init__(self, descriptor): class CGProxyUnwrap(CGAbstractMethod): def __init__(self, descriptor): - args = [Argument('*JSObject', 'obj')] + args = [Argument('*mut JSObject', 'obj')] CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*mut ' + descriptor.concreteType, args, alwaysInline=True) def definition_body(self): @@ -3407,7 +3400,7 @@ def definition_body(self): class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'), + args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), Argument('jsid', 'id'), Argument('JSBool', 'set'), Argument('*mut JSPropertyDescriptor', 'desc')] CGAbstractExternMethod.__init__(self, descriptor, "getOwnPropertyDescriptor", @@ -3482,11 +3475,11 @@ def getBody(self): else: namedGet = "" - return setOrIndexedGet + """let expando: *JSObject = GetExpandoObject(proxy); + return setOrIndexedGet + """let expando: *mut JSObject = GetExpandoObject(proxy); //if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) { if expando.is_not_null() { let flags = if set != 0 { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED; - if JS_GetPropertyDescriptorById(cx, expando, id, flags, desc as *JSPropertyDescriptor) == 0 { + if JS_GetPropertyDescriptorById(cx, expando, id, flags, desc) == 0 { return 0; } if (*desc).obj.is_not_null() { @@ -3496,7 +3489,7 @@ def getBody(self): } } """ + namedGet + """ -(*desc).obj = ptr::null(); +(*desc).obj = ptr::mut_null(); return 1;""" def definition_body(self): @@ -3504,7 +3497,7 @@ def definition_body(self): class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'), + args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), Argument('jsid', 'id'), Argument('*JSPropertyDescriptor', 'desc')] CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args) @@ -3562,7 +3555,7 @@ def definition_body(self): class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'), + args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), Argument('jsid', 'id'), Argument('*mut JSBool', 'bp')] CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "JSBool", args) self.descriptor = descriptor @@ -3597,10 +3590,10 @@ def getBody(self): else: named = "" - return indexed + """let expando: *JSObject = GetExpandoObject(proxy); + return indexed + """let expando: *mut JSObject = GetExpandoObject(proxy); if expando.is_not_null() { - let b: JSBool = 1; - let ok: JSBool = JS_HasPropertyById(cx, expando, id, &b); + let mut b: JSBool = 1; + let ok: JSBool = JS_HasPropertyById(cx, expando, id, &mut b); *bp = !!b; if ok == 0 || *bp != 0 { return ok; @@ -3615,21 +3608,21 @@ def definition_body(self): class CGDOMJSProxyHandler_get(CGAbstractExternMethod): def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'), - Argument('*JSObject', 'receiver'), Argument('jsid', 'id'), + args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), + Argument('*mut JSObject', 'receiver'), Argument('jsid', 'id'), Argument('*mut JSVal', 'vp')] CGAbstractExternMethod.__init__(self, descriptor, "get", "JSBool", args) self.descriptor = descriptor def getBody(self): getFromExpando = """let expando = GetExpandoObject(proxy); if expando.is_not_null() { - let hasProp = 0; - if JS_HasPropertyById(cx, expando, id, &hasProp) == 0 { + let mut hasProp = 0; + if JS_HasPropertyById(cx, expando, id, &mut hasProp) == 0 { return 0; } if hasProp != 0 { - return JS_GetPropertyById(cx, expando, id, vp as *JSVal); + return JS_GetPropertyById(cx, expando, id, vp); } }""" @@ -3671,7 +3664,7 @@ def getBody(self): %s let mut found = false; -if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp as *JSVal) { +if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp) { return 0; } @@ -3687,8 +3680,8 @@ def definition_body(self): class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod): def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy')] - CGAbstractExternMethod.__init__(self, descriptor, "obj_toString", "*JSString", args) + args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy')] + CGAbstractExternMethod.__init__(self, descriptor, "obj_toString", "*mut JSString", args) self.descriptor = descriptor def getBody(self): stringifier = self.descriptor.operations['Stringifier'] @@ -3750,7 +3743,7 @@ class CGClassTraceHook(CGAbstractClassHook): A hook to trace through our native object; used for GC and CC """ def __init__(self, descriptor): - args = [Argument('*mut JSTracer', 'trc'), Argument('*JSObject', 'obj')] + args = [Argument('*mut JSTracer', 'trc'), Argument('*mut JSObject', 'obj')] CGAbstractClassHook.__init__(self, descriptor, TRACE_HOOK_NAME, 'void', args) @@ -3762,7 +3755,7 @@ class CGClassConstructHook(CGAbstractExternMethod): JS-visible constructor for our objects """ def __init__(self, descriptor): - args = [Argument('*JSContext', 'cx'), Argument('u32', 'argc'), Argument('*mut JSVal', 'vp')] + args = [Argument('*mut JSContext', 'cx'), Argument('u32', 'argc'), Argument('*mut JSVal', 'vp')] CGAbstractExternMethod.__init__(self, descriptor, CONSTRUCT_HOOK_NAME, 'JSBool', args) self._ctor = self.descriptor.interface.ctor() @@ -3777,7 +3770,7 @@ def definition_body(self): def generate_code(self): preamble = """ - let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object()).root(); + let global = global_object_for_js_object(JS_CALLEE(cx, vp).to_object()).root(); let obj = global.deref().reflector().get_jsobject(); """ nativeName = MakeNativeName(self._ctor.identifier.name) @@ -3790,7 +3783,7 @@ class CGClassFinalizeHook(CGAbstractClassHook): A hook for finalize, used to release our native object. """ def __init__(self, descriptor): - args = [Argument('*JSFreeOp', 'fop'), Argument('*JSObject', 'obj')] + args = [Argument('*mut JSFreeOp', 'fop'), Argument('*mut JSObject', 'obj')] CGAbstractClassHook.__init__(self, descriptor, FINALIZE_HOOK_NAME, 'void', args) @@ -4018,11 +4011,11 @@ def memberInit(memberInfo): return string.Template( "impl<'a, 'b> ${selfName}<'a, 'b> {\n" " pub fn empty() -> ${selfName} {\n" - " ${selfName}::new(ptr::null(), NullValue()).unwrap()\n" + " ${selfName}::new(ptr::mut_null(), NullValue()).unwrap()\n" " }\n" - " pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n" + " pub fn new(cx: *mut JSContext, val: JSVal) -> Result<${selfName}, ()> {\n" " let object = if val.is_null_or_undefined() {\n" - " ptr::null()\n" + " ptr::mut_null()\n" " } else if val.is_object() {\n" " val.to_object()\n" " } else {\n" @@ -4616,7 +4609,7 @@ def __init__(self, idlObject, descriptorProvider, baseName, methods, def getConstructors(self): return [ClassConstructor( - [Argument("*JSObject", "aCallback")], + [Argument("*mut JSObject", "aCallback")], bodyInHeader=True, visibility="pub", explicit=False, @@ -4629,14 +4622,14 @@ def getMethodImpls(self, method): args = list(method.args) # Strip out the JSContext*/JSObject* args # that got added. - assert args[0].name == "cx" and args[0].argType == "*JSContext" - assert args[1].name == "aThisObj" and args[1].argType == "*JSObject" + assert args[0].name == "cx" and args[0].argType == "*mut JSContext" + assert args[1].name == "aThisObj" and args[1].argType == "*mut JSObject" args = args[2:] # Record the names of all the arguments, so we can use them when we call # the private method. argnames = [arg.name for arg in args] argnamesWithThis = ["s.GetContext()", "thisObjJS"] + argnames - argnamesWithoutThis = ["s.GetContext()", "ptr::null()"] + argnames + argnamesWithoutThis = ["s.GetContext()", "ptr::mut_null()"] + 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. @@ -4662,7 +4655,7 @@ def getMethodImpls(self, method): bodyWithThis = string.Template( setupCall+ - "let thisObjJS = WrapCallThisObject(s.GetContext(), ptr::null() /*XXXjdm proper scope*/, thisObj);\n" + "let thisObjJS = WrapCallThisObject(s.GetContext(), ptr::mut_null() /*XXXjdm proper scope*/, thisObj);\n" "if thisObjJS.is_null() {\n" " return Err(FailureUnknown);\n" "}\n" @@ -4919,8 +4912,8 @@ def getArgs(self, returnType, argList): return args # We want to allow the caller to pass in a "this" object, as # well as a JSContext. - return [Argument("*JSContext", "cx"), - Argument("*JSObject", "aThisObj")] + args + return [Argument("*mut JSContext", "cx"), + Argument("*mut JSObject", "aThisObj")] + args def getCallSetup(self): if self.needThisHandling: @@ -4974,7 +4967,7 @@ def getCall(self): "getCallable": self.getCallableDecl() } if self.argCount > 0: - replacements["argv"] = "argv.as_ptr()" + replacements["argv"] = "argv.as_mut_ptr()" replacements["argc"] = "argc" else: replacements["argv"] = "nullptr" @@ -4982,7 +4975,7 @@ def getCall(self): return string.Template("${getCallable}" "let ok = unsafe {\n" " JS_CallFunctionValue(cx, ${thisObj}, callable,\n" - " ${argc}, ${argv}, &rval)\n" + " ${argc}, ${argv}, &mut rval)\n" "};\n" "if ok == 0 {\n" " return Err(FailureUnknown);\n" diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs index bcbf088ef41e..11e937bd2614 100644 --- a/src/components/script/dom/bindings/conversions.rs +++ b/src/components/script/dom/bindings/conversions.rs @@ -34,24 +34,24 @@ pub trait IDLInterface { } pub trait ToJSValConvertible { - fn to_jsval(&self, cx: *JSContext) -> JSVal; + fn to_jsval(&self, cx: *mut JSContext) -> JSVal; } pub trait FromJSValConvertible { - fn from_jsval(cx: *JSContext, val: JSVal, option: T) -> Result; + fn from_jsval(cx: *mut JSContext, val: JSVal, option: T) -> Result; } impl ToJSValConvertible for () { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { UndefinedValue() } } impl ToJSValConvertible for JSVal { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { let mut value = *self; - if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 { + if unsafe { JS_WrapValue(cx, &mut value) } == 0 { fail!("JS_WrapValue failed."); } value @@ -59,10 +59,10 @@ impl ToJSValConvertible for JSVal { } unsafe fn convert_from_jsval( - cx: *JSContext, value: JSVal, - convert_fn: extern "C" unsafe fn(*JSContext, JSVal, *T) -> JSBool) -> Result { + cx: *mut JSContext, value: JSVal, + convert_fn: extern "C" unsafe fn(*mut JSContext, JSVal, *mut T) -> JSBool) -> Result { let mut ret = Default::default(); - if convert_fn(cx, value, &mut ret as *mut T as *T) == 0 { + if convert_fn(cx, value, &mut ret) == 0 { Err(()) } else { Ok(ret) @@ -71,95 +71,95 @@ unsafe fn convert_from_jsval( impl ToJSValConvertible for bool { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { BooleanValue(*self) } } impl FromJSValConvertible<()> for bool { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { let result = unsafe { convert_from_jsval(cx, val, JS_ValueToBoolean) }; result.map(|b| b != 0) } } impl ToJSValConvertible for i8 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { Int32Value(*self as i32) } } impl FromJSValConvertible<()> for i8 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }; result.map(|v| v as i8) } } impl ToJSValConvertible for u8 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { Int32Value(*self as i32) } } impl FromJSValConvertible<()> for u8 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }; result.map(|v| v as u8) } } impl ToJSValConvertible for i16 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { Int32Value(*self as i32) } } impl FromJSValConvertible<()> for i16 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { let result = unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) }; result.map(|v| v as i16) } } impl ToJSValConvertible for u16 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { Int32Value(*self as i32) } } impl FromJSValConvertible<()> for u16 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { unsafe { convert_from_jsval(cx, val, JS_ValueToUint16) } } } impl ToJSValConvertible for i32 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { Int32Value(*self) } } impl FromJSValConvertible<()> for i32 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { unsafe { convert_from_jsval(cx, val, JS_ValueToECMAInt32) } } } impl ToJSValConvertible for u32 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { UInt32Value(*self) } } impl FromJSValConvertible<()> for u32 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { unsafe { convert_from_jsval(cx, val, JS_ValueToECMAUint32) } } } impl ToJSValConvertible for i64 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { unsafe { RUST_JS_NumberValue(*self as f64) } @@ -167,13 +167,13 @@ impl ToJSValConvertible for i64 { } impl FromJSValConvertible<()> for i64 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { unsafe { convert_from_jsval(cx, val, JS_ValueToInt64) } } } impl ToJSValConvertible for u64 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { unsafe { RUST_JS_NumberValue(*self as f64) } @@ -181,13 +181,13 @@ impl ToJSValConvertible for u64 { } impl FromJSValConvertible<()> for u64 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { unsafe { convert_from_jsval(cx, val, JS_ValueToUint64) } } } impl ToJSValConvertible for f32 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { unsafe { RUST_JS_NumberValue(*self as f64) } @@ -195,14 +195,14 @@ impl ToJSValConvertible for f32 { } impl FromJSValConvertible<()> for f32 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { let result = unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) }; result.map(|f| f as f32) } } impl ToJSValConvertible for f64 { - fn to_jsval(&self, _cx: *JSContext) -> JSVal { + fn to_jsval(&self, _cx: *mut JSContext) -> JSVal { unsafe { RUST_JS_NumberValue(*self) } @@ -210,13 +210,13 @@ impl ToJSValConvertible for f64 { } impl FromJSValConvertible<()> for f64 { - fn from_jsval(cx: *JSContext, val: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, val: JSVal, _option: ()) -> Result { unsafe { convert_from_jsval(cx, val, JS_ValueToNumber) } } } impl ToJSValConvertible for DOMString { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { unsafe { let string_utf16 = self.to_utf16(); let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t); @@ -241,7 +241,7 @@ impl Default for StringificationBehavior { } impl FromJSValConvertible for DOMString { - fn from_jsval(cx: *JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result { + fn from_jsval(cx: *mut JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result { if nullBehavior == Empty && value.is_null() { Ok("".to_owned()) } else { @@ -257,7 +257,7 @@ impl FromJSValConvertible for DOMString { } impl ToJSValConvertible for ByteString { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { unsafe { let slice = self.as_slice(); let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *libc::c_char, @@ -271,7 +271,7 @@ impl ToJSValConvertible for ByteString { } impl FromJSValConvertible<()> for ByteString { - fn from_jsval(cx: *JSContext, value: JSVal, _option: ()) -> Result { + fn from_jsval(cx: *mut JSContext, value: JSVal, _option: ()) -> Result { unsafe { let string = JS_ValueToString(cx, value); if string.is_null() { @@ -280,7 +280,7 @@ impl FromJSValConvertible<()> for ByteString { } let mut length = 0; - let chars = JS_GetStringCharsAndLength(cx, string, &mut length as *mut _ as *_); + let chars = JS_GetStringCharsAndLength(cx, string, &mut length); slice::raw::buf_as_slice(chars, length as uint, |char_vec| { if char_vec.iter().any(|&c| c > 0xFF) { // XXX Throw @@ -294,11 +294,11 @@ impl FromJSValConvertible<()> for ByteString { } impl ToJSValConvertible for Reflector { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { let obj = self.get_jsobject(); assert!(obj.is_not_null()); let mut value = ObjectValue(unsafe { &*obj }); - if unsafe { JS_WrapValue(cx, &mut value as *mut JSVal as *JSVal) } == 0 { + if unsafe { JS_WrapValue(cx, &mut value) } == 0 { fail!("JS_WrapValue failed."); } value @@ -306,7 +306,7 @@ impl ToJSValConvertible for Reflector { } impl FromJSValConvertible<()> for JS { - fn from_jsval(_cx: *JSContext, value: JSVal, _option: ()) -> Result, ()> { + fn from_jsval(_cx: *mut JSContext, value: JSVal, _option: ()) -> Result, ()> { if !value.is_object() { return Err(()); } @@ -317,19 +317,19 @@ impl FromJSValConvertible<()> for JS { } impl<'a, 'b, T: Reflectable> ToJSValConvertible for Root<'a, 'b, T> { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { self.reflector().to_jsval(cx) } } impl<'a, T: Reflectable> ToJSValConvertible for JSRef<'a, T> { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { self.reflector().to_jsval(cx) } } impl ToJSValConvertible for Option { - fn to_jsval(&self, cx: *JSContext) -> JSVal { + fn to_jsval(&self, cx: *mut JSContext) -> JSVal { match self { &Some(ref value) => value.to_jsval(cx), &None => NullValue(), @@ -338,7 +338,7 @@ impl ToJSValConvertible for Option { } impl> FromJSValConvertible<()> for Option { - fn from_jsval(cx: *JSContext, value: JSVal, _: ()) -> Result, ()> { + fn from_jsval(cx: *mut JSContext, value: JSVal, _: ()) -> Result, ()> { if value.is_null_or_undefined() { Ok(None) } else { diff --git a/src/components/script/dom/bindings/error.rs b/src/components/script/dom/bindings/error.rs index 8793a1c1c6e0..f47f28c95b6d 100644 --- a/src/components/script/dom/bindings/error.rs +++ b/src/components/script/dom/bindings/error.rs @@ -4,7 +4,7 @@ use js::jsapi::{JSContext, JSBool}; use js::jsapi::{JS_IsExceptionPending}; -use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, struct_JSErrorFormatString, JSEXN_TYPEERR}; +use js::jsapi::{JS_ReportErrorNumber, JSErrorFormatString, JSEXN_TYPEERR}; use js::glue::{ReportError}; use libc; @@ -29,7 +29,7 @@ pub type Fallible = Result; pub type ErrorResult = Fallible<()>; -pub fn throw_method_failed_with_details(cx: *JSContext, +pub fn throw_method_failed_with_details(cx: *mut JSContext, result: Result, interface: &'static str, member: &'static str) -> JSBool { @@ -42,7 +42,7 @@ pub fn throw_method_failed_with_details(cx: *JSContext, return 0; } -pub fn throw_not_in_union(cx: *JSContext, names: &'static str) -> JSBool { +pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) -> JSBool { assert!(unsafe { JS_IsExceptionPending(cx) } == 0); let message = format!("argument could not be converted to any of: {}", names); message.with_c_str(|string| { @@ -58,7 +58,7 @@ static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [ 0 as libc::c_char, ]; -static ERROR_FORMAT_STRING: JSErrorFormatString = struct_JSErrorFormatString { +static ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { format: &ERROR_FORMAT_STRING_STRING as *libc::c_char, argCount: 1, exnType: JSEXN_TYPEERR as i16, @@ -72,9 +72,9 @@ extern fn get_error_message(_user_ref: *mut libc::c_void, &ERROR_FORMAT_STRING as *JSErrorFormatString } -pub fn throw_type_error(cx: *JSContext, error: &str) { +pub fn throw_type_error(cx: *mut JSContext, error: &str) { let error = error.to_c_str(); error.with_ref(|error| unsafe { - JS_ReportErrorNumber(cx, get_error_message, ptr::null(), 0, error); + JS_ReportErrorNumber(cx, Some(get_error_message), ptr::mut_null(), 0, error); }); } diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 38fafe757a1e..67642c32573e 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -69,17 +69,17 @@ impl Drop for Temporary { fn drop(&mut self) { let cx = cx_for_dom_object(&self.inner); unsafe { - JS_RemoveObjectRoot(cx, self.inner.reflector().rootable()); + JS_RemoveObjectRoot(cx, self.inner.mut_reflector().rootable()); } } } impl Temporary { /// Create a new Temporary value from a JS-owned value. - pub fn new(inner: JS) -> Temporary { + pub fn new(mut inner: JS) -> Temporary { let cx = cx_for_dom_object(&inner); unsafe { - JS_AddObjectRoot(cx, inner.reflector().rootable()); + JS_AddObjectRoot(cx, inner.mut_reflector().rootable()); } Temporary { inner: inner, @@ -351,7 +351,7 @@ impl, U: Reflectable> TemporaryPushable for Vec> { /// An opaque, LIFO rooting mechanism. pub struct RootCollection { - roots: RefCell>, + roots: RefCell>, } impl RootCollection { @@ -396,7 +396,7 @@ pub struct Root<'a, 'b, T> { /// Pointer to underlying Rust data ptr: RefCell<*mut T>, /// On-stack JS pointer to assuage conservative stack scanner - js_ptr: *JSObject, + js_ptr: *mut JSObject, } impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { diff --git a/src/components/script/dom/bindings/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs index 65a54a307695..07b881cf2876 100644 --- a/src/components/script/dom/bindings/proxyhandler.rs +++ b/src/components/script/dom/bindings/proxyhandler.rs @@ -21,7 +21,7 @@ use std::mem::size_of; static JSPROXYSLOT_EXPANDO: u32 = 0; -pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid, +pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, set: libc::c_int, desc: *mut JSPropertyDescriptor) -> libc::c_int { unsafe { let handler = GetProxyHandler(proxy); @@ -35,7 +35,7 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid, //let proto = JS_GetPrototype(proxy); let proto = GetObjectProto(proxy); if proto.is_null() { - (*desc).obj = ptr::null(); + (*desc).obj = ptr::mut_null(); return 1; } @@ -43,7 +43,7 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid, } } -pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid, +pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, desc: *JSPropertyDescriptor) -> JSBool { unsafe { //FIXME: Workaround for https://github.com/mozilla/rust/issues/13385 @@ -68,18 +68,18 @@ pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid, } } -pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid, +pub extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, desc: *JSPropertyDescriptor) -> JSBool { defineProperty_(cx, proxy, id, desc) } -pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString { +pub fn _obj_toString(cx: *mut JSContext, className: *libc::c_char) -> *mut JSString { unsafe { let name = str::raw::from_c_str(className); let nchars = "[object ]".len() + name.len(); let chars: *mut jschar = JS_malloc(cx, (nchars + 1) as libc::size_t * (size_of::() as libc::size_t)) as *mut jschar; if chars.is_null() { - return ptr::null(); + return ptr::mut_null(); } let result = "[object ".to_owned() + name + "]"; @@ -87,35 +87,36 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString { *chars.offset(i as int) = c as jschar; } *chars.offset(nchars as int) = 0; - let jsstr = JS_NewUCString(cx, chars as *jschar, nchars as libc::size_t); + let jsstr = JS_NewUCString(cx, chars, nchars as libc::size_t); if jsstr.is_null() { - JS_free(cx, chars as *libc::c_void); + JS_free(cx, chars as *mut libc::c_void); } jsstr } } -pub fn GetExpandoObject(obj: *JSObject) -> *JSObject { +pub fn GetExpandoObject(obj: *mut JSObject) -> *mut JSObject { unsafe { assert!(is_dom_proxy(obj)); let val = GetProxyExtra(obj, JSPROXYSLOT_EXPANDO); if val.is_undefined() { - ptr::null() + ptr::mut_null() } else { val.to_object() } } } -pub fn EnsureExpandoObject(cx: *JSContext, obj: *JSObject) -> *JSObject { +pub fn EnsureExpandoObject(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject { unsafe { assert!(is_dom_proxy(obj)); let mut expando = GetExpandoObject(obj); if expando.is_null() { - expando = JS_NewObjectWithGivenProto(cx, ptr::null(), ptr::null(), + expando = JS_NewObjectWithGivenProto(cx, ptr::null(), + ptr::mut_null(), GetObjectParent(obj)); if expando.is_null() { - return ptr::null(); + return ptr::mut_null(); } SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, ObjectValue(&*expando)); @@ -124,7 +125,7 @@ pub fn EnsureExpandoObject(cx: *JSContext, obj: *JSObject) -> *JSObject { } } -pub fn FillPropertyDescriptor(desc: &mut JSPropertyDescriptor, obj: *JSObject, readonly: bool) { +pub fn FillPropertyDescriptor(desc: &mut JSPropertyDescriptor, obj: *mut JSObject, readonly: bool) { desc.obj = obj; desc.attrs = if readonly { JSPROP_READONLY } else { 0 } | JSPROP_ENUMERATE; desc.getter = None; diff --git a/src/components/script/dom/bindings/trace.rs b/src/components/script/dom/bindings/trace.rs index 240f280af65f..d18f6a64448d 100644 --- a/src/components/script/dom/bindings/trace.rs +++ b/src/components/script/dom/bindings/trace.rs @@ -11,8 +11,6 @@ use js::jsval::JSVal; use libc; use std::cast; use std::cell::{Cell, RefCell}; -use std::ptr; -use std::ptr::null; use serialize::{Encodable, Encoder}; // IMPORTANT: We rely on the fact that we never attempt to encode DOM objects using @@ -50,11 +48,11 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) { unsafe { description.to_c_str().with_ref(|name| { - (*tracer).debugPrinter = ptr::null(); + (*tracer).debugPrinter = None; (*tracer).debugPrintIndex = -1; (*tracer).debugPrintArg = name as *libc::c_void; debug!("tracing value {:s}", description); - JS_CallTracer(tracer as *JSTracer, val.to_gcthing(), val.trace_kind()); + JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind()); }); } } @@ -63,14 +61,14 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref trace_object(tracer, description, reflector.get_jsobject()) } -pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *JSObject) { +pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject) { unsafe { description.to_c_str().with_ref(|name| { - (*tracer).debugPrinter = ptr::null(); + (*tracer).debugPrinter = None; (*tracer).debugPrintIndex = -1; (*tracer).debugPrintArg = name as *libc::c_void; debug!("tracing {:s}", description); - JS_CallTracer(tracer as *JSTracer, obj, JSTRACE_OBJECT as u32); + JS_CallTracer(tracer, obj as *mut libc::c_void, JSTRACE_OBJECT); }); } } @@ -148,7 +146,7 @@ impl, E, T: Encodable+Copy> Encodable for Traceable, E> Encodable for Traceable<*JSObject> { +impl, E> Encodable for Traceable<*mut JSObject> { fn encode(&self, s: &mut S) -> Result<(), E> { trace_object(get_jstracer(s), "object", **self); Ok(()) diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index b263f8a46d61..f23013e203a5 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -67,14 +67,14 @@ fn is_dom_class(clasp: *JSClass) -> bool { } } -pub fn is_dom_proxy(obj: *JSObject) -> bool { +pub fn is_dom_proxy(obj: *mut JSObject) -> bool { unsafe { (js_IsObjectProxyClass(obj) || js_IsFunctionProxyClass(obj)) && IsProxyHandlerFamily(obj) } } -pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 { +pub unsafe fn dom_object_slot(obj: *mut JSObject) -> u32 { let clasp = JS_GetClass(obj); if is_dom_class(clasp) { DOM_OBJECT_SLOT as u32 @@ -84,13 +84,13 @@ pub unsafe fn dom_object_slot(obj: *JSObject) -> u32 { } } -pub unsafe fn unwrap(obj: *JSObject) -> *mut T { +pub unsafe fn unwrap(obj: *mut JSObject) -> *mut T { let slot = dom_object_slot(obj); let val = JS_GetReservedSlot(obj, slot); val.to_private() as *mut T } -pub unsafe fn get_dom_class(obj: *JSObject) -> Result { +pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result { let clasp = JS_GetClass(obj); if is_dom_class(clasp) { debug!("plain old dom object"); @@ -106,7 +106,7 @@ pub unsafe fn get_dom_class(obj: *JSObject) -> Result { return Err(()); } -pub fn unwrap_jsmanaged(mut obj: *JSObject, +pub fn unwrap_jsmanaged(mut obj: *mut JSObject, proto_id: PrototypeList::id::ID, proto_depth: uint) -> Result, ()> { unsafe { @@ -144,17 +144,17 @@ pub unsafe fn squirrel_away_unique(x: Box) -> *T { cast::transmute(x) } -pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> DOMString { +pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString { unsafe { - let length = 0; - let chars = JS_GetStringCharsAndLength(cx, s, &length); + let mut length = 0; + let chars = JS_GetStringCharsAndLength(cx, s, &mut length); slice::raw::buf_as_slice(chars, length as uint, |char_vec| { str::from_utf16(char_vec).unwrap() }) } } -pub fn jsid_to_str(cx: *JSContext, id: jsid) -> DOMString { +pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString { unsafe { assert!(RUST_JSID_IS_STRING(id) != 0); jsstring_to_str(cx, RUST_JSID_TO_STRING(id)) @@ -206,30 +206,30 @@ pub struct DOMJSClass { pub dom_class: DOMClass } -pub fn GetProtoOrIfaceArray(global: *JSObject) -> **JSObject { +pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> *mut *mut JSObject { unsafe { assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0); - JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as **JSObject + JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as *mut *mut JSObject } } -pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSObject, - protoProto: *JSObject, protoClass: *JSClass, - constructor: Option, +pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject, + protoProto: *mut JSObject, protoClass: *JSClass, + constructor: JSNative, ctorNargs: u32, domClass: *DOMClass, methods: *JSFunctionSpec, properties: *JSPropertySpec, constants: *ConstantSpec, staticMethods: *JSFunctionSpec, - name: &str) -> *JSObject { - let mut proto = ptr::null(); + name: &str) -> *mut JSObject { + let mut proto = ptr::mut_null(); if protoClass.is_not_null() { proto = CreateInterfacePrototypeObject(cx, global, protoProto, protoClass, methods, properties, constants); if proto.is_null() { - return ptr::null(); + return ptr::mut_null(); } unsafe { @@ -238,7 +238,7 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO } } - let mut interface = ptr::null(); + let mut interface = ptr::mut_null(); if constructor.is_some() { interface = name.to_c_str().with_ref(|s| { CreateInterfaceObject(cx, global, receiver, @@ -246,7 +246,7 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO staticMethods, constants, s) }); if interface.is_null() { - return ptr::null(); + return ptr::mut_null(); } } @@ -257,17 +257,17 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO } } -fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject, - constructorNative: Option, - ctorNargs: u32, proto: *JSObject, +fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject, + constructorNative: JSNative, + ctorNargs: u32, proto: *mut JSObject, staticMethods: *JSFunctionSpec, constants: *ConstantSpec, - name: *libc::c_char) -> *JSObject { + name: *libc::c_char) -> *mut JSObject { unsafe { let fun = JS_NewFunction(cx, constructorNative, ctorNargs, JSFUN_CONSTRUCTOR, global, name); if fun.is_null() { - return ptr::null(); + return ptr::mut_null(); } let constructor = JS_GetFunctionObject(fun); @@ -275,34 +275,34 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject, if staticMethods.is_not_null() && !DefineMethods(cx, constructor, staticMethods) { - return ptr::null(); + return ptr::mut_null(); } if constants.is_not_null() && !DefineConstants(cx, constructor, constants) { - return ptr::null(); + return ptr::mut_null(); } if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 { - return ptr::null(); + return ptr::mut_null(); } - let alreadyDefined = 0; - if JS_AlreadyHasOwnProperty(cx, receiver, name, &alreadyDefined) == 0 { - return ptr::null(); + let mut alreadyDefined = 0; + if JS_AlreadyHasOwnProperty(cx, receiver, name, &mut alreadyDefined) == 0 { + return ptr::mut_null(); } if alreadyDefined == 0 && JS_DefineProperty(cx, receiver, name, ObjectValue(&*constructor), None, None, 0) == 0 { - return ptr::null(); + return ptr::mut_null(); } return constructor; } } -fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool { +fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: *ConstantSpec) -> bool { let mut i = 0; loop { unsafe { @@ -330,52 +330,52 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> } } -fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool { +fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: *JSFunctionSpec) -> bool { unsafe { JS_DefineFunctions(cx, obj, methods) != 0 } } -fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool { +fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: *JSPropertySpec) -> bool { unsafe { JS_DefineProperties(cx, obj, properties) != 0 } } -fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject, - parentProto: *JSObject, protoClass: *JSClass, +fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject, + parentProto: *mut JSObject, protoClass: *JSClass, methods: *JSFunctionSpec, properties: *JSPropertySpec, - constants: *ConstantSpec) -> *JSObject { + constants: *ConstantSpec) -> *mut JSObject { unsafe { let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global); if ourProto.is_null() { - return ptr::null(); + return ptr::mut_null(); } if methods.is_not_null() && !DefineMethods(cx, ourProto, methods) { - return ptr::null(); + return ptr::mut_null(); } if properties.is_not_null() && !DefineProperties(cx, ourProto, properties) { - return ptr::null(); + return ptr::mut_null(); } if constants.is_not_null() && !DefineConstants(cx, ourProto, constants) { - return ptr::null(); + return ptr::mut_null(); } return ourProto; } } -pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool { +pub extern fn ThrowingConstructor(_cx: *mut JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool { //XXX should trigger exception here return 0; } -pub fn initialize_global(global: *JSObject) { - let protoArray = box () ([0 as *JSObject, ..PrototypeList::id::IDCount as uint]); +pub fn initialize_global(global: *mut JSObject) { + let protoArray = box () ([0 as *mut JSObject, ..PrototypeList::id::IDCount as uint]); unsafe { let box_ = squirrel_away_unique(protoArray); JS_SetReservedSlot(global, @@ -392,23 +392,23 @@ pub trait Reflectable { pub fn reflect_dom_object (obj: Box, window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, Box) -> JS) + wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef, Box) -> JS) -> Temporary { Temporary::new(wrap_fn(window.deref().get_cx(), window, obj)) } #[deriving(Eq)] pub struct Reflector { - pub object: *JSObject, + pub object: *mut JSObject, } impl Reflector { #[inline] - pub fn get_jsobject(&self) -> *JSObject { + pub fn get_jsobject(&self) -> *mut JSObject { self.object } - pub fn set_jsobject(&mut self, object: *JSObject) { + pub fn set_jsobject(&mut self, object: *mut JSObject) { assert!(self.object.is_null()); assert!(object.is_not_null()); self.object = object; @@ -417,19 +417,19 @@ impl Reflector { /// Return a pointer to the memory location at which the JS reflector object is stored. /// Used by Temporary values to root the reflector, as required by the JSAPI rooting /// APIs. - pub fn rootable<'a>(&'a self) -> &'a *JSObject { - &self.object + pub fn rootable<'a>(&'a mut self) -> &'a mut *mut JSObject { + &mut self.object } pub fn new() -> Reflector { Reflector { - object: ptr::null(), + object: ptr::mut_null(), } } } -pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool, - vp: *JSVal) -> bool { +pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, found: *mut bool, + vp: *mut JSVal) -> bool { unsafe { //let proto = GetObjectProto(proxy); let proto = JS_GetPrototype(proxy); @@ -437,8 +437,8 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *found = false; return true; } - let hasProp = 0; - if JS_HasPropertyById(cx, proto, id, &hasProp) == 0 { + let mut hasProp = 0; + if JS_HasPropertyById(cx, proto, id, &mut hasProp) == 0 { return false; } *found = hasProp != 0; @@ -451,7 +451,7 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: } } -pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option { +pub fn GetArrayIndexFromId(_cx: *mut JSContext, id: jsid) -> Option { unsafe { if RUST_JSID_IS_INT(id) != 0 { return Some(RUST_JSID_TO_INT(id) as u32); @@ -474,7 +474,7 @@ pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option { }*/ } -fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option { +fn InternJSString(cx: *mut JSContext, chars: *libc::c_char) -> Option { unsafe { let s = JS_InternString(cx, chars); if s.is_not_null() { @@ -485,7 +485,7 @@ fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option { } } -pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bool { +pub fn InitIds(cx: *mut JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bool { for (i, spec) in specs.iter().enumerate() { if spec.name.is_null() == true { return true; @@ -500,7 +500,7 @@ pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bo true } -pub fn FindEnumStringIndex(cx: *JSContext, +pub fn FindEnumStringIndex(cx: *mut JSContext, v: JSVal, values: &[&'static str]) -> Result, ()> { unsafe { @@ -509,8 +509,8 @@ pub fn FindEnumStringIndex(cx: *JSContext, return Err(()); } - let length = 0; - let chars = JS_GetStringCharsAndLength(cx, jsstr, &length); + let mut length = 0; + let chars = JS_GetStringCharsAndLength(cx, jsstr, &mut length); if chars.is_null() { return Err(()); } @@ -524,23 +524,23 @@ pub fn FindEnumStringIndex(cx: *JSContext, } } -pub fn get_dictionary_property(cx: *JSContext, - object: *JSObject, +pub fn get_dictionary_property(cx: *mut JSContext, + object: *mut JSObject, property: &str) -> Result, ()> { use std::c_str::CString; - fn has_property(cx: *JSContext, object: *JSObject, property: &CString, + fn has_property(cx: *mut JSContext, object: *mut JSObject, property: &CString, found: &mut JSBool) -> bool { unsafe { property.with_ref(|s| { - JS_HasProperty(cx, object, s, found as *mut _ as *_) != 0 + JS_HasProperty(cx, object, s, found) != 0 }) } } - fn get_property(cx: *JSContext, object: *JSObject, property: &CString, + fn get_property(cx: *mut JSContext, object: *mut JSObject, property: &CString, value: &mut JSVal) -> bool { unsafe { property.with_ref(|s| { - JS_GetProperty(cx, object, s, value as *mut _ as *_) != 0 + JS_GetProperty(cx, object, s, value) != 0 }) } } @@ -567,23 +567,23 @@ pub fn get_dictionary_property(cx: *JSContext, Ok(Some(value)) } -pub fn HasPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid) -> bool { +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::null()) || found; + return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::mut_null()) || found; } -pub fn IsConvertibleToCallbackInterface(cx: *JSContext, obj: *JSObject) -> bool { +pub fn IsConvertibleToCallbackInterface(cx: *mut JSContext, obj: *mut JSObject) -> bool { unsafe { JS_ObjectIsDate(cx, obj) == 0 && JS_ObjectIsRegExp(cx, obj) == 0 } } -pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject { +pub fn CreateDOMGlobal(cx: *mut JSContext, class: *JSClass) -> *mut JSObject { unsafe { - let obj = JS_NewGlobalObject(cx, class, ptr::null()); + let obj = JS_NewGlobalObject(cx, class, ptr::mut_null()); if obj.is_null() { - return ptr::null(); + return ptr::mut_null(); } with_compartment(cx, obj, || { JS_InitStandardClasses(cx, obj); @@ -593,9 +593,9 @@ pub fn CreateDOMGlobal(cx: *JSContext, class: *JSClass) -> *JSObject { } } -pub extern fn wrap_for_same_compartment(cx: *JSContext, obj: *JSObject) -> *JSObject { +pub extern fn wrap_for_same_compartment(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject { unsafe { - JS_ObjectToOuterObject(cx as *mut _, obj as *mut _) as *_ + JS_ObjectToOuterObject(cx, obj) } } @@ -606,10 +606,10 @@ pub extern fn pre_wrap(cx: *mut JSContext, _scope: *mut JSObject, } } -pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject { +pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut JSObject { unsafe { debug!("outerizing"); - let obj = *obj.unnamed; + let obj = *obj.unnamed_field1; let win: Root = unwrap_jsmanaged(obj, IDLInterface::get_prototype_id(None::), @@ -621,17 +621,17 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject } /// Returns the global object of the realm that the given JS object was created in. -pub fn global_object_for_js_object(obj: *JSObject) -> JS { +pub fn global_object_for_js_object(obj: *mut JSObject) -> JS { unsafe { let global = GetGlobalForObjectCrossCompartment(obj); let clasp = JS_GetClass(global); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); - FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ()) + FromJSValConvertible::from_jsval(ptr::mut_null(), ObjectOrNullValue(global), ()) .ok().expect("found DOM global that doesn't unwrap to Window") } } -fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext { +fn cx_for_dom_reflector(obj: *mut JSObject) -> *mut JSContext { let win = global_object_for_js_object(obj).root(); let js_info = win.deref().page().js_info(); match *js_info { @@ -640,7 +640,7 @@ fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext { } } -pub fn cx_for_dom_object(obj: &T) -> *JSContext { +pub fn cx_for_dom_object(obj: &T) -> *mut JSContext { cx_for_dom_reflector(obj.reflector().get_jsobject()) } diff --git a/src/components/script/dom/browsercontext.rs b/src/components/script/dom/browsercontext.rs index f95e84ab02bf..4e8262e7f2ea 100644 --- a/src/components/script/dom/browsercontext.rs +++ b/src/components/script/dom/browsercontext.rs @@ -19,7 +19,7 @@ use std::ptr; pub struct BrowserContext { history: Vec, active_index: uint, - window_proxy: Traceable<*JSObject>, + window_proxy: Traceable<*mut JSObject>, } impl BrowserContext { @@ -27,7 +27,7 @@ impl BrowserContext { let mut context = BrowserContext { history: vec!(SessionHistoryEntry::new(document)), active_index: 0, - window_proxy: Traceable::new(ptr::null()), + window_proxy: Traceable::new(ptr::mut_null()), }; context.window_proxy = Traceable::new(context.create_window_proxy()); context @@ -42,12 +42,12 @@ impl BrowserContext { Temporary::new(doc.deref().window.clone()) } - pub fn window_proxy(&self) -> *JSObject { + pub fn window_proxy(&self) -> *mut JSObject { assert!(self.window_proxy.deref().is_not_null()); *self.window_proxy } - pub fn create_window_proxy(&self) -> *JSObject { + pub fn create_window_proxy(&self) -> *mut JSObject { let win = self.active_window().root(); let page = win.deref().page(); let js_info = page.js_info(); diff --git a/src/components/script/dom/customevent.rs b/src/components/script/dom/customevent.rs index 17b004817f67..1451c3e2a892 100644 --- a/src/components/script/dom/customevent.rs +++ b/src/components/script/dom/customevent.rs @@ -27,8 +27,8 @@ impl CustomEventDerived for Event { } pub trait CustomEventMethods { - fn Detail(&self, _cx: *JSContext) -> JSVal; - fn InitCustomEvent(&mut self, _cx: *JSContext, + fn Detail(&self, _cx: *mut JSContext) -> JSVal; + fn InitCustomEvent(&mut self, _cx: *mut JSContext, type_: DOMString, can_bubble: bool, cancelable: bool, detail: JSVal); } @@ -59,12 +59,12 @@ impl CustomEvent { } impl<'a> CustomEventMethods for JSRef<'a, CustomEvent> { - fn Detail(&self, _cx: *JSContext) -> JSVal { + fn Detail(&self, _cx: *mut JSContext) -> JSVal { self.detail.deref().clone() } fn InitCustomEvent(&mut self, - _cx: *JSContext, + _cx: *mut JSContext, type_: DOMString, can_bubble: bool, cancelable: bool, diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index c554f5c55342..4c39752f9859 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -188,7 +188,7 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> { impl Document { pub fn reflect_document(document: Box, window: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, Box) -> JS) + wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef, Box) -> JS) -> Temporary { assert!(document.reflector().get_jsobject().is_null()); let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(); diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index f1ecec10e150..81f645a0eca7 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -52,8 +52,8 @@ pub trait HTMLElementMethods { fn SetLang(&mut self, _lang: DOMString); fn Dir(&self) -> DOMString; fn SetDir(&mut self, _dir: DOMString) -> ErrorResult; - fn GetItemValue(&self, _cx: *JSContext) -> Fallible; - fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult; + fn GetItemValue(&self, _cx: *mut JSContext) -> Fallible; + fn SetItemValue(&mut self, _cx: *mut JSContext, _val: JSVal) -> ErrorResult; fn Hidden(&self) -> bool; fn SetHidden(&mut self, _hidden: bool) -> ErrorResult; fn Click(&self); @@ -101,11 +101,11 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { Ok(()) } - fn GetItemValue(&self, _cx: *JSContext) -> Fallible { + fn GetItemValue(&self, _cx: *mut JSContext) -> Fallible { Ok(NullValue()) } - fn SetItemValue(&mut self, _cx: *JSContext, _val: JSVal) -> ErrorResult { + fn SetItemValue(&mut self, _cx: *mut JSContext, _val: JSVal) -> ErrorResult { Ok(()) } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index a05dc1e01711..1a9c70f28062 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -637,12 +637,12 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { /// If the given untrusted node address represents a valid DOM node in the given runtime, /// returns it. -pub fn from_untrusted_node_address(runtime: *JSRuntime, candidate: UntrustedNodeAddress) +pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: UntrustedNodeAddress) -> Temporary { unsafe { let candidate: uintptr_t = cast::transmute(candidate); - let object: *JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, - candidate); + let object: *mut JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, + candidate); if object.is_null() { fail!("Attempted to create a `JS` from an invalid pointer!") } @@ -889,7 +889,7 @@ impl Node { pub fn reflect_node (node: Box, document: &JSRef, - wrap_fn: extern "Rust" fn(*JSContext, &JSRef, Box) -> JS) + wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef, Box) -> JS) -> Temporary { assert!(node.reflector().get_jsobject().is_null()); let window = document.deref().window.root(); diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 6bc22be81c17..115fbcadaa53 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -52,8 +52,8 @@ pub trait TestBindingMethods { fn SetEnumAttribute(&self, _: TestEnum) {} fn InterfaceAttribute(&self) -> Temporary; fn SetInterfaceAttribute(&self, _: &JSRef) {} - fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() } - fn SetAnyAttribute(&self, _: *JSContext, _: JSVal) {} + fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() } + fn SetAnyAttribute(&self, _: *mut JSContext, _: JSVal) {} fn GetBooleanAttributeNullable(&self) -> Option { Some(false) } fn SetBooleanAttributeNullable(&self, _: Option) {} @@ -101,7 +101,7 @@ pub trait TestBindingMethods { fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) } fn ReceiveEnum(&self) -> TestEnum { _empty } fn ReceiveInterface(&self) -> Temporary; - fn ReceiveAny(&self, _: *JSContext) -> JSVal { NullValue() } + fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() } fn ReceiveNullableBoolean(&self) -> Option { Some(false) } fn ReceiveNullableByte(&self) -> Option { Some(0) } @@ -118,7 +118,7 @@ pub trait TestBindingMethods { fn ReceiveNullableByteString(&self) -> Option { Some(ByteString::new(vec!())) } fn ReceiveNullableEnum(&self) -> Option { Some(_empty) } fn ReceiveNullableInterface(&self) -> Option>; - fn ReceiveNullableAny(&self, _: *JSContext) -> Option { Some(NullValue()) } + fn ReceiveNullableAny(&self, _: *mut JSContext) -> Option { Some(NullValue()) } fn PassBoolean(&self, _: bool) {} fn PassByte(&self, _: i8) {} @@ -137,7 +137,7 @@ pub trait TestBindingMethods { fn PassInterface(&self, _: &JSRef) {} fn PassUnion(&self, _: HTMLElementOrLong) {} fn PassUnion2(&self, _: StringOrFormData) {} - fn PassAny(&self, _: *JSContext, _: JSVal) {} + fn PassAny(&self, _: *mut JSContext, _: JSVal) {} fn PassNullableBoolean(&self, _: Option) {} fn PassNullableByte(&self, _: Option) {} @@ -156,7 +156,7 @@ pub trait TestBindingMethods { fn PassNullableInterface(&self, _: Option>) {} fn PassNullableUnion(&self, _: Option) {} fn PassNullableUnion2(&self, _: Option) {} - fn PassNullableAny(&self, _: *JSContext, _: Option) {} + fn PassNullableAny(&self, _: *mut JSContext, _: Option) {} fn PassOptionalBoolean(&self, _: Option) {} fn PassOptionalByte(&self, _: Option) {} @@ -175,7 +175,7 @@ pub trait TestBindingMethods { fn PassOptionalInterface(&self, _: Option>) {} fn PassOptionalUnion(&self, _: Option) {} fn PassOptionalUnion2(&self, _: Option) {} - fn PassOptionalAny(&self, _: *JSContext, _: Option) {} + fn PassOptionalAny(&self, _: *mut JSContext, _: Option) {} fn PassOptionalNullableBoolean(&self, _: Option>) {} fn PassOptionalNullableByte(&self, _: Option>) {} @@ -224,7 +224,7 @@ pub trait TestBindingMethods { fn PassOptionalNullableInterfaceWithDefault(&self, _: Option>) {} fn PassOptionalNullableUnionWithDefault(&self, _: Option) {} fn PassOptionalNullableUnion2WithDefault(&self, _: Option) {} - fn PassOptionalAnyWithDefault(&self, _: *JSContext, _: JSVal) {} + fn PassOptionalAnyWithDefault(&self, _: *mut JSContext, _: JSVal) {} fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option) {} fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option) {} diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index e8d4a121dcd1..428040338156 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -82,7 +82,7 @@ pub struct Window { } impl Window { - pub fn get_cx(&self) -> *JSContext { + pub fn get_cx(&self) -> *mut JSContext { let js_info = self.page().js_info(); (**js_info.get_ref().js_context).ptr } @@ -132,10 +132,10 @@ pub trait WindowMethods { fn Confirm(&self, _message: DOMString) -> bool; fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option; fn Print(&self); - fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option) -> JSVal; - fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; + fn ShowModalDialog(&self, _cx: *mut JSContext, _url: DOMString, _argument: Option) -> JSVal; + fn SetTimeout(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32; fn ClearTimeout(&mut self, handle: i32); - fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; + fn SetInterval(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32; fn ClearInterval(&mut self, handle: i32); fn Window(&self) -> Temporary; fn Self(&self) -> Temporary; @@ -227,11 +227,11 @@ impl<'a> WindowMethods for JSRef<'a, Window> { fn Print(&self) { } - fn ShowModalDialog(&self, _cx: *JSContext, _url: DOMString, _argument: Option) -> JSVal { + fn ShowModalDialog(&self, _cx: *mut JSContext, _url: DOMString, _argument: Option) -> JSVal { NullValue() } - fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { + fn SetTimeout(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 { self.set_timeout_or_interval(callback, timeout, false) } @@ -244,7 +244,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { self.active_timers.remove(&TimerId(handle)); } - fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { + fn SetInterval(&mut self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 { self.set_timeout_or_interval(callback, timeout, true) } @@ -394,7 +394,7 @@ impl<'a> PrivateWindowHelpers for JSRef<'a, Window> { } impl Window { - pub fn new(cx: *JSContext, + pub fn new(cx: *mut JSContext, page: Rc, script_chan: ScriptChan, compositor: Box, diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index 3161d4d6ed62..86118550bd5f 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -229,7 +229,7 @@ pub trait XMLHttpRequestMethods<'a> { fn OverrideMimeType(&self, _mime: DOMString); fn ResponseType(&self) -> XMLHttpRequestResponseType; fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType); - fn Response(&self, _cx: *JSContext) -> JSVal; + fn Response(&self, _cx: *mut JSContext) -> JSVal; fn ResponseText(&self) -> DOMString; fn GetResponseXML(&self) -> Option>; } @@ -368,7 +368,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) { self.response_type = response_type } - fn Response(&self, cx: *JSContext) -> JSVal { + fn Response(&self, cx: *mut JSContext) -> JSVal { match self.response_type { _empty | Text => { if self.ready_state == XHRDone || self.ready_state == Loading { @@ -438,14 +438,14 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { unsafe fn to_trusted(&mut self) -> TrustedXHRAddress { assert!(self.pinned == false); self.pinned = true; - JS_AddObjectRoot(self.global.root().get_cx(), self.reflector().rootable()); + JS_AddObjectRoot(self.global.root().get_cx(), self.mut_reflector().rootable()); TrustedXHRAddress(self.deref() as *XMLHttpRequest as *libc::c_void) } fn release(&mut self) { assert!(self.pinned); unsafe { - JS_RemoveObjectRoot(self.global.root().get_cx(), self.reflector().rootable()); + JS_RemoveObjectRoot(self.global.root().get_cx(), self.mut_reflector().rootable()); } self.pinned = false; } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 5846be72fa8c..1b459ca7f052 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -643,7 +643,7 @@ impl ScriptTask { fn new_rt_and_cx() -> (js::rust::rt, Rc) { let js_runtime = js::rust::rt(); assert!({ - let ptr: *JSRuntime = (*js_runtime).ptr; + let ptr: *mut JSRuntime = (*js_runtime).ptr; ptr.is_not_null() }); unsafe { @@ -652,18 +652,18 @@ impl ScriptTask { // to retrieve the default callback is as the result of // JS_SetWrapObjectCallbacks, which is why we call it twice. let callback = JS_SetWrapObjectCallbacks((*js_runtime).ptr, - ptr::null(), - wrap_for_same_compartment, + None, + Some(wrap_for_same_compartment), None); JS_SetWrapObjectCallbacks((*js_runtime).ptr, callback, - wrap_for_same_compartment, + Some(wrap_for_same_compartment), Some(pre_wrap)); } let js_context = js_runtime.cx(); assert!({ - let ptr: *JSContext = (*js_context).ptr; + let ptr: *mut JSContext = (*js_context).ptr; ptr.is_not_null() }); js_context.set_default_options_and_version(); @@ -675,7 +675,7 @@ impl ScriptTask { (js_runtime, js_context) } - pub fn get_cx(&self) -> *JSContext { + pub fn get_cx(&self) -> *mut JSContext { (**self.js_context.borrow().get_ref()).ptr } @@ -835,11 +835,11 @@ impl ScriptTask { // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`. let cx = self.get_cx(); with_compartment(cx, this_value, || { - let rval = NullValue(); + let mut rval = NullValue(); unsafe { JS_CallFunctionValue(cx, this_value, *timer_handle.data.funval, - 0, ptr::null(), &rval); + 0, ptr::mut_null(), &mut rval); } }); @@ -1242,7 +1242,7 @@ impl ScriptTask { } /// Shuts down layout for the given page tree. -fn shut_down_layout(page_tree: &Rc, rt: *JSRuntime) { +fn shut_down_layout(page_tree: &Rc, rt: *mut JSRuntime) { for page in page_tree.iter() { page.join_layout(); diff --git a/src/support/spidermonkey/rust-mozjs b/src/support/spidermonkey/rust-mozjs index c155a3b433c1..d932f5dbb26d 160000 --- a/src/support/spidermonkey/rust-mozjs +++ b/src/support/spidermonkey/rust-mozjs @@ -1 +1 @@ -Subproject commit c155a3b433c1e53b47758aec0d4496df3a312875 +Subproject commit d932f5dbb26dbae9fc67615bd61c86b05f0fb4fe