diff options
Diffstat (limited to 'src/components/script/dom')
25 files changed, 234 insertions, 258 deletions
diff --git a/src/components/script/dom/bindings/callback.rs b/src/components/script/dom/bindings/callback.rs index 3d8ba107fa2..fb1dd9750dd 100644 --- a/src/components/script/dom/bindings/callback.rs +++ b/src/components/script/dom/bindings/callback.rs @@ -97,7 +97,8 @@ impl CallbackInterface { pub fn GetCallableProperty(&self, cx: *mut JSContext, name: &str) -> Result<JSVal, ()> { let mut callable = UndefinedValue(); unsafe { - if name.to_c_str().with_ref(|name| JS_GetProperty(cx, self.callback(), name, &mut callable)) == 0 { + let name = name.to_c_str(); + if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 { return Err(()); } diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index a9a77fb34ff..42175de35e4 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -374,7 +374,7 @@ class CGMethodCall(CGThing): class FakeCastableDescriptor(): def __init__(self, descriptor): - self.nativeType = "*%s" % descriptor.concreteType + self.nativeType = "*const %s" % descriptor.concreteType self.name = descriptor.name class FakeInterface: def inheritanceDepth(self): @@ -1161,7 +1161,7 @@ class MethodDefiner(PropertyDefiner): jitinfo = ("&%s_methodinfo" % m["name"]) accessor = "genericMethod" else: - jitinfo = "0 as *JSJitInfo" + jitinfo = "0 as *const JSJitInfo" accessor = m.get("nativeName", m["name"]) return (m["name"], accessor, jitinfo, m["length"], m["flags"]) @@ -1172,8 +1172,8 @@ class MethodDefiner(PropertyDefiner): decls = ''.join([stringDecl(m) for m in array]) return decls + self.generatePrefableArray( array, name, - ' JSFunctionSpec {name: &%s_name as *u8 as *libc::c_char, call: JSNativeWrapper {op: Some(%s), info: %s}, nargs: %s, flags: %s as u16, selfHostedName: 0 as *libc::c_char }', - ' JSFunctionSpec {name: 0 as *libc::c_char, call: JSNativeWrapper {op: None, info: 0 as *JSJitInfo}, nargs: 0, flags: 0, selfHostedName: 0 as *libc::c_char }', + ' JSFunctionSpec {name: &%s_name as *const u8 as *const libc::c_char, call: JSNativeWrapper {op: Some(%s), info: %s}, nargs: %s, flags: %s as u16, selfHostedName: 0 as *const libc::c_char }', + ' JSFunctionSpec {name: 0 as *const libc::c_char, call: JSNativeWrapper {op: None, info: 0 as *const JSJitInfo}, nargs: 0, flags: 0, selfHostedName: 0 as *const libc::c_char }', 'JSFunctionSpec', specData) @@ -1206,13 +1206,13 @@ class AttrDefiner(PropertyDefiner): accessor = "genericGetter" jitinfo = "&%s_getterinfo" % attr.identifier.name - return ("JSPropertyOpWrapper {op: Some(%(native)s), info: %(info)s as *JSJitInfo}" + return ("JSPropertyOpWrapper {op: Some(%(native)s), info: %(info)s as *const JSJitInfo}" % {"info" : jitinfo, "native" : accessor}) def setter(attr): if attr.readonly: - return "JSStrictPropertyOpWrapper {op: None, info: 0 as *JSJitInfo}" + return "JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}" if self.static: accessor = 'set_' + attr.identifier.name @@ -1224,7 +1224,7 @@ class AttrDefiner(PropertyDefiner): accessor = "genericSetter" jitinfo = "&%s_setterinfo" % attr.identifier.name - return ("JSStrictPropertyOpWrapper {op: Some(%(native)s), info: %(info)s as *JSJitInfo}" + return ("JSStrictPropertyOpWrapper {op: Some(%(native)s), info: %(info)s as *const JSJitInfo}" % {"info" : jitinfo, "native" : accessor}) @@ -1241,8 +1241,8 @@ class AttrDefiner(PropertyDefiner): return decls + self.generatePrefableArray( array, name, - ' JSPropertySpec { name: &%s_name as *u8 as *libc::c_char, tinyid: 0, flags: ((%s) & 0xFF) as u8, getter: %s, setter: %s }', - ' JSPropertySpec { name: 0 as *libc::c_char, tinyid: 0, flags: 0, getter: JSPropertyOpWrapper {op: None, info: 0 as *JSJitInfo}, setter: JSStrictPropertyOpWrapper {op: None, info: 0 as *JSJitInfo} }', + ' JSPropertySpec { name: &%s_name as *const u8 as *const libc::c_char, tinyid: 0, flags: ((%s) & 0xFF) as u8, getter: %s, setter: %s }', + ' JSPropertySpec { name: 0 as *const libc::c_char, tinyid: 0, flags: 0, getter: JSPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}, setter: JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo} }', 'JSPropertySpec', specData) @@ -1413,8 +1413,8 @@ class CGDOMJSClass(CGThing): static Class_name: [u8, ..%i] = %s; static Class: DOMJSClass = DOMJSClass { base: js::Class { - name: &Class_name as *u8 as *libc::c_char, - flags: JSCLASS_IS_DOMJSCLASS | %s | (((%s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), //JSCLASS_HAS_RESERVED_SLOTS(%s), + name: &Class_name as *const u8 as *const libc::c_char, + flags: JSCLASS_IS_DOMJSCLASS | %s | (((%s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT as uint), //JSCLASS_HAS_RESERVED_SLOTS(%s), addProperty: Some(JS_PropertyStub), delProperty: Some(JS_PropertyStub), getProperty: Some(JS_PropertyStub), @@ -1430,48 +1430,48 @@ static Class: DOMJSClass = DOMJSClass { trace: %s, ext: js::ClassExtension { - equality: 0 as *u8, + equality: 0 as *const u8, outerObject: %s, innerObject: None, - iteratorObject: 0 as *u8, - unused: 0 as *u8, - isWrappedNative: 0 as *u8, + iteratorObject: 0 as *const u8, + unused: 0 as *const u8, + isWrappedNative: 0 as *const u8, }, ops: js::ObjectOps { - lookupGeneric: 0 as *u8, - lookupProperty: 0 as *u8, - lookupElement: 0 as *u8, - lookupSpecial: 0 as *u8, - defineGeneric: 0 as *u8, - defineProperty: 0 as *u8, - defineElement: 0 as *u8, - defineSpecial: 0 as *u8, - getGeneric: 0 as *u8, - getProperty: 0 as *u8, - getElement: 0 as *u8, - getElementIfPresent: 0 as *u8, - getSpecial: 0 as *u8, - setGeneric: 0 as *u8, - setProperty: 0 as *u8, - setElement: 0 as *u8, - setSpecial: 0 as *u8, - getGenericAttributes: 0 as *u8, - getPropertyAttributes: 0 as *u8, - getElementAttributes: 0 as *u8, - getSpecialAttributes: 0 as *u8, - setGenericAttributes: 0 as *u8, - setPropertyAttributes: 0 as *u8, - setElementAttributes: 0 as *u8, - setSpecialAttributes: 0 as *u8, - deleteProperty: 0 as *u8, - deleteElement: 0 as *u8, - deleteSpecial: 0 as *u8, - - enumerate: 0 as *u8, - typeOf: 0 as *u8, + lookupGeneric: 0 as *const u8, + lookupProperty: 0 as *const u8, + lookupElement: 0 as *const u8, + lookupSpecial: 0 as *const u8, + defineGeneric: 0 as *const u8, + defineProperty: 0 as *const u8, + defineElement: 0 as *const u8, + defineSpecial: 0 as *const u8, + getGeneric: 0 as *const u8, + getProperty: 0 as *const u8, + getElement: 0 as *const u8, + getElementIfPresent: 0 as *const u8, + getSpecial: 0 as *const u8, + setGeneric: 0 as *const u8, + setProperty: 0 as *const u8, + setElement: 0 as *const u8, + setSpecial: 0 as *const u8, + getGenericAttributes: 0 as *const u8, + getPropertyAttributes: 0 as *const u8, + getElementAttributes: 0 as *const u8, + getSpecialAttributes: 0 as *const u8, + setGenericAttributes: 0 as *const u8, + setPropertyAttributes: 0 as *const u8, + setElementAttributes: 0 as *const u8, + setSpecialAttributes: 0 as *const u8, + deleteProperty: 0 as *const u8, + deleteElement: 0 as *const u8, + deleteSpecial: 0 as *const u8, + + enumerate: 0 as *const u8, + typeOf: 0 as *const u8, thisObject: %s, - clear: 0 as *u8, + clear: 0 as *const u8, }, }, dom_class: %s @@ -1496,8 +1496,8 @@ class CGPrototypeJSClass(CGThing): return """ static PrototypeClassName__: [u8, ..%s] = %s; static PrototypeClass: JSClass = JSClass { - name: &PrototypeClassName__ as *u8 as *libc::c_char, - flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT, //JSCLASS_HAS_RESERVED_SLOTS(1) + name: &PrototypeClassName__ as *const u8 as *const libc::c_char, + flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT as uint, //JSCLASS_HAS_RESERVED_SLOTS(1) addProperty: Some(JS_PropertyStub), delProperty: Some(JS_PropertyStub), getProperty: Some(JS_PropertyStub), @@ -1524,7 +1524,7 @@ class CGInterfaceObjectJSClass(CGThing): def define(self): if True: return "" - ctorname = "0 as *u8" if not self.descriptor.interface.ctor() else CONSTRUCT_HOOK_NAME + ctorname = "0 as *const u8" if not self.descriptor.interface.ctor() else CONSTRUCT_HOOK_NAME hasinstance = HASINSTANCE_HOOK_NAME return """ static InterfaceObjectClass: JSClass = { @@ -1536,12 +1536,12 @@ static InterfaceObjectClass: JSClass = { JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, - 0 as *u8, - 0 as *u8, + 0 as *const u8, + 0 as *const u8, %s, %s, %s, - 0 as *u8, + 0 as *const u8, JSCLASS_NO_INTERNAL_MEMBERS }; """ % (str_to_const_array("Function"), ctorname, hasinstance, ctorname) @@ -1766,7 +1766,7 @@ def CreateBindingJSObject(descriptor, parent=None): assert not descriptor.createGlobal create += """ let handler = RegisterBindings::proxy_handlers[PrototypeList::proxies::%s as uint]; -let mut private = PrivateValue(squirrel_away_unique(aObject) as *libc::c_void); +let mut private = PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void); let obj = with_compartment(aCx, proto, || { NewProxyObject(aCx, handler, &private, @@ -1778,15 +1778,15 @@ assert!(obj.is_not_null()); """ % (descriptor.name, parent) else: if descriptor.createGlobal: - create += "let obj = CreateDOMGlobal(aCx, &Class.base as *js::Class as *JSClass);\n" + create += "let obj = CreateDOMGlobal(aCx, &Class.base as *const js::Class as *const JSClass);\n" else: create += ("let obj = with_compartment(aCx, proto, || {\n" - " JS_NewObject(aCx, &Class.base as *js::Class as *JSClass, proto, %s)\n" + " JS_NewObject(aCx, &Class.base as *const js::Class as *const JSClass, &*proto, &*%s)\n" "});\n" % parent) create += """assert!(obj.is_not_null()); JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32, - PrivateValue(squirrel_away_unique(aObject) as *libc::c_void)); + PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void)); """ return create @@ -2049,7 +2049,7 @@ class CGDefineProxyHandler(CGAbstractMethod): """ def __init__(self, descriptor): assert descriptor.proxy - CGAbstractMethod.__init__(self, descriptor, 'DefineProxyHandler', '*libc::c_void', [], pub=True) + CGAbstractMethod.__init__(self, descriptor, 'DefineProxyHandler', '*const libc::c_void', [], pub=True) def define(self): return CGAbstractMethod.define(self) @@ -2088,7 +2088,7 @@ let traps = ProxyTraps { trace: Some(%s) }; -CreateProxyHandler(&traps, &Class as *_ as *_) +CreateProxyHandler(&traps, &Class as *const _ as *const _) """ % (FINALIZE_HOOK_NAME, TRACE_HOOK_NAME) return CGGeneric(body) @@ -2440,8 +2440,8 @@ class CGGenericMethod(CGAbstractBindingMethod): def generate_code(self): return 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: *const JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n" + "return CallJitMethodOp(_info, cx, obj, this.unsafe_get() as *mut libc::c_void, argc, vp);") class CGSpecializedMethod(CGAbstractExternMethod): """ @@ -2452,7 +2452,7 @@ class CGSpecializedMethod(CGAbstractExternMethod): self.method = method name = method.identifier.name args = [Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'), - Argument('*%s' % descriptor.concreteType, 'this'), + Argument('*const %s' % descriptor.concreteType, 'this'), Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args) @@ -2504,8 +2504,8 @@ class CGGenericGetter(CGAbstractBindingMethod): def generate_code(self): return 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: *const JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n" + "return CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *mut libc::c_void, vp);\n") class CGSpecializedGetter(CGAbstractExternMethod): """ @@ -2517,7 +2517,7 @@ class CGSpecializedGetter(CGAbstractExternMethod): name = 'get_' + attr.identifier.name args = [ Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'), - Argument('*%s' % descriptor.concreteType, 'this'), + Argument('*const %s' % descriptor.concreteType, 'this'), Argument('*mut JSVal', 'vp') ] CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) @@ -2579,8 +2579,8 @@ class CGGenericSetter(CGAbstractBindingMethod): return CGGeneric( "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" + "let info: *const JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n" + "if CallJitPropertyOp(info, cx, obj, this.unsafe_get() as *mut libc::c_void, argv) == 0 {\n" " return 0;\n" "}\n" "*vp = UndefinedValue();\n" @@ -2596,7 +2596,7 @@ class CGSpecializedSetter(CGAbstractExternMethod): name = 'set_' + attr.identifier.name args = [ Argument('*mut JSContext', 'cx'), Argument('JSHandleObject', '_obj'), - Argument('*%s' % descriptor.concreteType, 'this'), + Argument('*const %s' % descriptor.concreteType, 'this'), Argument('*mut JSVal', 'argv')] CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) @@ -2651,7 +2651,7 @@ class CGMemberJITInfo(CGThing): failstr = "true" if infallible else "false" return ("\n" "static %s: JSJitInfo = JSJitInfo {\n" - " op: %s as *u8,\n" + " op: %s as *const u8,\n" " protoID: %s,\n" " depth: %s,\n" " isInfallible: %s, /* False in setters. */\n" @@ -3535,14 +3535,14 @@ class CGProxyNamedSetter(CGProxySpecialOperation): class CGProxyUnwrap(CGAbstractMethod): def __init__(self, descriptor): args = [Argument('*mut JSObject', 'obj')] - CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*' + descriptor.concreteType, args, alwaysInline=True) + CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*const ' + descriptor.concreteType, args, alwaysInline=True) def definition_body(self): return CGGeneric("""/*if (xpc::WrapperFactory::IsXrayWrapper(obj)) { obj = js::UnwrapObject(obj); }*/ //MOZ_ASSERT(IsProxy(obj)); -let box_ = GetProxyPrivate(obj).to_private() as *%s; +let box_ = GetProxyPrivate(obj).to_private() as *const %s; return box_;""" % self.descriptor.concreteType) class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): @@ -3646,7 +3646,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): def __init__(self, descriptor): args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), Argument('jsid', 'id'), - Argument('*JSPropertyDescriptor', 'desc')] + Argument('*const JSPropertyDescriptor', 'desc')] CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args) self.descriptor = descriptor def getBody(self): @@ -3850,9 +3850,8 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod): JSString* jsresult; return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;""" - return """"%s".to_c_str().with_ref(|s| { - _obj_toString(cx, s) -})""" % self.descriptor.name + return """let s = "%s".to_c_str(); + _obj_toString(cx, s.as_ptr())""" % self.descriptor.name def definition_body(self): return CGGeneric(self.getBody()) @@ -3868,7 +3867,7 @@ class CGAbstractClassHook(CGAbstractExternMethod): def definition_body_prologue(self): return CGGeneric("""\ -let this: *%s = unwrap::<%s>(obj); +let this: *const %s = unwrap::<%s>(obj); """ % (self.descriptor.concreteType, self.descriptor.concreteType)) def definition_body(self): @@ -4400,7 +4399,7 @@ class CGRegisterProxyHandlers(CGThing): descriptors = config.getDescriptors(proxy=True) length = len(descriptors) self.root = CGList([ - CGGeneric("pub static mut proxy_handlers: [*libc::c_void, ..%d] = [0 as *libc::c_void, ..%d];" % (length, length)), + CGGeneric("pub static mut proxy_handlers: [*const libc::c_void, ..%d] = [0 as *const libc::c_void, ..%d];" % (length, length)), CGRegisterProxyHandlersMethod(descriptors), ], "\n") diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs index 60d8d2a2b98..8ce5b55e9d3 100644 --- a/src/components/script/dom/bindings/conversions.rs +++ b/src/components/script/dom/bindings/conversions.rs @@ -227,7 +227,7 @@ impl FromJSValConvertible<()> for f64 { impl ToJSValConvertible for DOMString { fn to_jsval(&self, cx: *mut JSContext) -> JSVal { unsafe { - let string_utf16 = self.to_utf16(); + let string_utf16: Vec<u16> = self.as_slice().utf16_units().collect(); let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr(), string_utf16.len() as libc::size_t); if jsstr.is_null() { fail!("JS_NewUCStringCopyN failed"); @@ -272,7 +272,7 @@ impl ToJSValConvertible for ByteString { 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, + let jsstr = JS_NewStringCopyN(cx, slice.as_ptr() as *const libc::c_char, slice.len() as libc::size_t); if jsstr.is_null() { fail!("JS_NewStringCopyN failed"); diff --git a/src/components/script/dom/bindings/error.rs b/src/components/script/dom/bindings/error.rs index aa0642179a3..cb39e4f0755 100644 --- a/src/components/script/dom/bindings/error.rs +++ b/src/components/script/dom/bindings/error.rs @@ -91,24 +91,24 @@ static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [ /// Format string struct used to throw `TypeError`s. static ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { - format: &ERROR_FORMAT_STRING_STRING as *libc::c_char, + format: &ERROR_FORMAT_STRING_STRING as *const libc::c_char, argCount: 1, exnType: JSEXN_TYPEERR as i16, }; /// Callback used to throw `TypeError`s. extern fn get_error_message(_user_ref: *mut libc::c_void, - _locale: *libc::c_char, - error_number: libc::c_uint) -> *JSErrorFormatString + _locale: *const libc::c_char, + error_number: libc::c_uint) -> *const JSErrorFormatString { assert_eq!(error_number, 0); - &ERROR_FORMAT_STRING as *JSErrorFormatString + &ERROR_FORMAT_STRING as *const JSErrorFormatString } /// Throw a `TypeError` with the given message. pub fn throw_type_error(cx: *mut JSContext, error: &str) { let error = error.to_c_str(); - error.with_ref(|error| unsafe { - JS_ReportErrorNumber(cx, Some(get_error_message), ptr::mut_null(), 0, error); - }); + unsafe { + JS_ReportErrorNumber(cx, Some(get_error_message), ptr::mut_null(), 0, error.as_ptr()); + } } diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 73cb19c5072..6a57b45449f 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -106,7 +106,7 @@ impl<T: Reflectable> Temporary<T> { /// A rooted, JS-owned value. Must only be used as a field in other JS-owned types. pub struct JS<T> { - ptr: *T + ptr: *const T } impl<T> PartialEq for JS<T> { @@ -129,7 +129,7 @@ impl JS<Node> { pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> { let TrustedNodeAddress(addr) = inner; JS { - ptr: addr as *Node + ptr: addr as *const Node } } } @@ -138,14 +138,14 @@ impl JS<XMLHttpRequest> { pub unsafe fn from_trusted_xhr_address(inner: TrustedXHRAddress) -> JS<XMLHttpRequest> { let TrustedXHRAddress(addr) = inner; JS { - ptr: addr as *XMLHttpRequest + ptr: addr as *const XMLHttpRequest } } } impl<T: Reflectable> JS<T> { /// Create a new JS-owned value wrapped from a raw Rust pointer. - pub unsafe fn from_raw(raw: *T) -> JS<T> { + pub unsafe fn from_raw(raw: *const T) -> JS<T> { JS { ptr: raw } @@ -442,7 +442,7 @@ impl<'a, T: Reflectable> Deref<T> for JSRef<'a, T> { /// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable. pub struct JSRef<'a, T> { - ptr: *T, + ptr: *const T, chain: ContravariantLifetime<'a>, } diff --git a/src/components/script/dom/bindings/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs index 1a035a26eb2..8b5f130af1c 100644 --- a/src/components/script/dom/bindings/proxyhandler.rs +++ b/src/components/script/dom/bindings/proxyhandler.rs @@ -49,13 +49,13 @@ pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, id } pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - desc: *JSPropertyDescriptor) -> JSBool { + desc: *mut JSPropertyDescriptor) -> JSBool { static JSMSG_GETTER_ONLY: libc::c_uint = 160; unsafe { //FIXME: Workaround for https://github.com/mozilla/rust/issues/13385 - let setter: *libc::c_void = mem::transmute((*desc).setter); - let setter_stub: *libc::c_void = mem::transmute(JS_StrictPropertyStub); + 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 | @@ -75,7 +75,7 @@ pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, } pub extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - desc: *JSPropertyDescriptor) -> JSBool { + desc: *mut JSPropertyDescriptor) -> JSBool { defineProperty_(cx, proxy, id, desc) } @@ -97,7 +97,7 @@ pub extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, } } -pub fn _obj_toString(cx: *mut JSContext, className: *libc::c_char) -> *mut JSString { +pub fn _obj_toString(cx: *mut JSContext, className: *const libc::c_char) -> *mut JSString { unsafe { let name = str::raw::from_c_str(className); let nchars = "[object ]".len() + name.len(); @@ -137,7 +137,7 @@ 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::null(), + expando = JS_NewObjectWithGivenProto(cx, ptr::mut_null(), ptr::mut_null(), GetObjectParent(obj)); if expando.is_null() { diff --git a/src/components/script/dom/bindings/trace.rs b/src/components/script/dom/bindings/trace.rs index b9865eeec91..f26af087796 100644 --- a/src/components/script/dom/bindings/trace.rs +++ b/src/components/script/dom/bindings/trace.rs @@ -73,13 +73,12 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) { } unsafe { - description.to_c_str().with_ref(|name| { - (*tracer).debugPrinter = None; - (*tracer).debugPrintIndex = -1; - (*tracer).debugPrintArg = name as *libc::c_void; - debug!("tracing value {:s}", description); - JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind()); - }); + let name = description.to_c_str(); + (*tracer).debugPrinter = None; + (*tracer).debugPrintIndex = -1; + (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; + debug!("tracing value {:s}", description); + JS_CallTracer(tracer, val.to_gcthing(), val.trace_kind()); } } @@ -91,13 +90,12 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref /// Trace a `JSObject`. pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject) { unsafe { - description.to_c_str().with_ref(|name| { - (*tracer).debugPrinter = None; - (*tracer).debugPrintIndex = -1; - (*tracer).debugPrintArg = name as *libc::c_void; - debug!("tracing {:s}", description); - JS_CallTracer(tracer, obj as *mut libc::c_void, JSTRACE_OBJECT); - }); + let name = description.to_c_str(); + (*tracer).debugPrinter = None; + (*tracer).debugPrintIndex = -1; + (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; + debug!("tracing {:s}", description); + JS_CallTracer(tracer, obj as *mut libc::c_void, JSTRACE_OBJECT); } } @@ -185,23 +183,3 @@ impl<S: Encoder<E>, E> Encodable<S, E> for Traceable<JSVal> { Ok(()) } } - -/// for a field which contains DOMType -impl<T: Reflectable+Encodable<S, E>, S: Encoder<E>, E> Encodable<S, E> for Cell<JS<T>> { - fn encode(&self, s: &mut S) -> Result<(), E> { - self.get().encode(s) - } -} - -impl<T: Reflectable+Encodable<S, E>, S: Encoder<E>, E> Encodable<S, E> for Cell<Option<JS<T>>> { - fn encode(&self, s: &mut S) -> Result<(), E> { - self.get().encode(s) - } -} - -/// for a field which contains non-POD type contains DOMType -impl<T: Reflectable+Encodable<S, E>, S: Encoder<E>, E> Encodable<S, E> for RefCell<Vec<JS<T>>> { - fn encode(&self, s: &mut S) -> Result<(), E> { - self.borrow().encode(s) - } -} diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index f104f880563..4aa5c60601e 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -20,9 +20,7 @@ use std::cell::Cell; use std::mem; use std::cmp::PartialEq; use std::ptr; -use std::ptr::null; use std::slice; -use std::str; use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily}; use js::glue::{GetGlobalForObjectCrossCompartment, UnwrapObject, GetProxyHandlerExtra}; use js::glue::{IsWrapper, RUST_JSID_TO_STRING, RUST_JSID_IS_INT}; @@ -54,7 +52,7 @@ use js; #[allow(raw_pointer_deriving)] #[deriving(Encodable)] pub struct GlobalStaticData { - pub windowproxy_handler: Untraceable<*libc::c_void>, + pub windowproxy_handler: Untraceable<*const libc::c_void>, } pub fn GlobalStaticData() -> GlobalStaticData { @@ -64,7 +62,7 @@ pub fn GlobalStaticData() -> GlobalStaticData { } /// Returns whether the given `clasp` is one for a DOM object. -fn is_dom_class(clasp: *JSClass) -> bool { +fn is_dom_class(clasp: *const JSClass) -> bool { unsafe { ((*clasp).flags & js::JSCLASS_IS_DOMJSCLASS) != 0 } @@ -84,7 +82,7 @@ pub fn is_dom_proxy(obj: *mut JSObject) -> bool { /// Fails if `obj` is not a DOM object. pub unsafe fn dom_object_slot(obj: *mut JSObject) -> u32 { let clasp = JS_GetClass(obj); - if is_dom_class(clasp) { + if is_dom_class(&*clasp) { DOM_OBJECT_SLOT as u32 } else { assert!(is_dom_proxy(obj)); @@ -93,23 +91,23 @@ pub unsafe fn dom_object_slot(obj: *mut JSObject) -> u32 { } /// Get the DOM object from the given reflector. -pub unsafe fn unwrap<T>(obj: *mut JSObject) -> *T { +pub unsafe fn unwrap<T>(obj: *mut JSObject) -> *const T { let slot = dom_object_slot(obj); let val = JS_GetReservedSlot(obj, slot); - val.to_private() as *T + val.to_private() as *const T } /// Get the `DOMClass` from `obj`, or `Err(())` if `obj` is not a DOM object. pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<DOMClass, ()> { let clasp = JS_GetClass(obj); - if is_dom_class(clasp) { + if is_dom_class(&*clasp) { debug!("plain old dom object"); - let domjsclass: *DOMJSClass = clasp as *DOMJSClass; + let domjsclass: *const DOMJSClass = clasp as *const DOMJSClass; return Ok((*domjsclass).dom_class); } if is_dom_proxy(obj) { debug!("proxy dom object"); - let dom_class: *DOMClass = GetProxyHandlerExtra(obj) as *DOMClass; + let dom_class: *const DOMClass = GetProxyHandlerExtra(obj) as *const DOMClass; return Ok(*dom_class); } debug!("not a dom object"); @@ -129,7 +127,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::null()); + obj = UnwrapObject(obj, /* stopAtOuter = */ 0, ptr::mut_null()); if obj.is_null() { debug!("unwrapping security wrapper failed"); Err(()) @@ -157,7 +155,7 @@ pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject, } /// Leak the given pointer. -pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *T { +pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *const T { mem::transmute(x) } @@ -168,7 +166,7 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString { 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() + String::from_utf16(char_vec).unwrap() }) } } @@ -265,23 +263,22 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv protoProto: *mut JSObject, protoClass: &'static JSClass, constructor: Option<(NonNullJSNative, &'static str, u32)>, - domClass: *DOMClass, + domClass: *const DOMClass, members: &'static NativeProperties) -> *mut JSObject { let proto = CreateInterfacePrototypeObject(cx, global, protoProto, protoClass, members); unsafe { JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT, - PrivateValue(domClass as *libc::c_void)); + PrivateValue(domClass as *const libc::c_void)); } match constructor { Some((native, name, nargs)) => { - name.to_c_str().with_ref(|s| { - CreateInterfaceObject(cx, global, receiver, - native, nargs, proto, - members, s) - }) + let s = name.to_c_str(); + CreateInterfaceObject(cx, global, receiver, + native, nargs, proto, + members, s.as_ptr()) }, None => (), } @@ -295,7 +292,7 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m constructorNative: NonNullJSNative, ctorNargs: u32, proto: *mut JSObject, members: &'static NativeProperties, - name: *libc::c_char) { + name: *const libc::c_char) { unsafe { let fun = JS_NewFunction(cx, Some(constructorNative), ctorNargs, JSFUN_CONSTRUCTOR, global, name); @@ -347,7 +344,7 @@ fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ VoidVal => UndefinedValue(), }; unsafe { - assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *libc::c_char, + assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *const libc::c_char, jsval, None, None, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) != 0); @@ -380,7 +377,7 @@ fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject, protoClass: &'static JSClass, members: &'static NativeProperties) -> *mut JSObject { unsafe { - let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global); + let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, &*parentProto, &*global); assert!(ourProto.is_not_null()); match members.methods { @@ -418,7 +415,7 @@ pub fn initialize_global(global: *mut JSObject) { let box_ = squirrel_away_unique(protoArray); JS_SetReservedSlot(global, DOM_PROTOTYPE_SLOT, - PrivateValue(box_ as *libc::c_void)); + PrivateValue(box_ as *const libc::c_void)); } } @@ -462,7 +459,7 @@ impl Reflector { /// Used by Temporary values to root the reflector, as required by the JSAPI rooting /// APIs. pub fn rootable(&self) -> *mut *mut JSObject { - &self.object as *Cell<*mut JSObject> + &self.object as *const Cell<*mut JSObject> as *mut Cell<*mut JSObject> as *mut *mut JSObject } @@ -544,7 +541,7 @@ pub fn FindEnumStringIndex(cx: *mut JSContext, Ok(values.iter().position(|value| { value.len() == length as uint && range(0, length as uint).all(|j| { - value[j] as u16 == *chars.offset(j as int) + value.as_bytes()[j] as u16 == *chars.offset(j as int) }) })) } @@ -560,17 +557,13 @@ pub fn get_dictionary_property(cx: *mut JSContext, 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) != 0 - }) + JS_HasProperty(cx, object, property.as_ptr(), found) != 0 } } 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) != 0 - }) + JS_GetProperty(cx, object, property.as_ptr(), value) != 0 } } @@ -610,7 +603,7 @@ 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: *JSClass) -> *mut JSObject { +pub fn CreateDOMGlobal(cx: *mut JSContext, class: *const JSClass) -> *mut JSObject { unsafe { let obj = JS_NewGlobalObject(cx, class, ptr::mut_null()); if obj.is_null() { diff --git a/src/components/script/dom/browsercontext.rs b/src/components/script/dom/browsercontext.rs index ce67b882c66..1a16d30290d 100644 --- a/src/components/script/dom/browsercontext.rs +++ b/src/components/script/dom/browsercontext.rs @@ -85,20 +85,20 @@ static proxy_handler: ProxyTraps = ProxyTraps { getPropertyDescriptor: None, getOwnPropertyDescriptor: None, defineProperty: None, - getOwnPropertyNames: 0 as *u8, + getOwnPropertyNames: 0 as *const u8, delete_: None, - enumerate: 0 as *u8, + enumerate: 0 as *const u8, has: None, hasOwn: None, get: None, set: None, - keys: 0 as *u8, + keys: 0 as *const u8, iterate: None, call: None, construct: None, - nativeCall: 0 as *u8, + nativeCall: 0 as *const u8, hasInstance: None, typeOf: None, objectClassIs: None, @@ -113,7 +113,7 @@ static proxy_handler: ProxyTraps = ProxyTraps { trace: None }; -pub fn new_window_proxy_handler() -> *c_void { +pub fn new_window_proxy_handler() -> *const c_void { unsafe { CreateWrapperProxyHandler(&proxy_handler) } diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs index 2336c95e9a8..7d1ba33ffb8 100644 --- a/src/components/script/dom/domexception.rs +++ b/src/components/script/dom/domexception.rs @@ -15,26 +15,26 @@ use servo_util::str::DOMString; #[repr(uint)] #[deriving(Show, Encodable)] pub enum DOMErrorName { - IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR, - HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR, - WrongDocumentError = DOMExceptionConstants::WRONG_DOCUMENT_ERR, - InvalidCharacterError = DOMExceptionConstants::INVALID_CHARACTER_ERR, - NoModificationAllowedError = DOMExceptionConstants::NO_MODIFICATION_ALLOWED_ERR, - NotFoundError = DOMExceptionConstants::NOT_FOUND_ERR, - NotSupportedError = DOMExceptionConstants::NOT_SUPPORTED_ERR, - InvalidStateError = DOMExceptionConstants::INVALID_STATE_ERR, - SyntaxError = DOMExceptionConstants::SYNTAX_ERR, - InvalidModificationError = DOMExceptionConstants::INVALID_MODIFICATION_ERR, - NamespaceError = DOMExceptionConstants::NAMESPACE_ERR, - InvalidAccessError = DOMExceptionConstants::INVALID_ACCESS_ERR, - SecurityError = DOMExceptionConstants::SECURITY_ERR, - NetworkError = DOMExceptionConstants::NETWORK_ERR, - AbortError = DOMExceptionConstants::ABORT_ERR, - URLMismatchError = DOMExceptionConstants::URL_MISMATCH_ERR, - QuotaExceededError = DOMExceptionConstants::QUOTA_EXCEEDED_ERR, - TimeoutError = DOMExceptionConstants::TIMEOUT_ERR, - InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR, - DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR, + IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR as uint, + HierarchyRequestError = DOMExceptionConstants::HIERARCHY_REQUEST_ERR as uint, + WrongDocumentError = DOMExceptionConstants::WRONG_DOCUMENT_ERR as uint, + InvalidCharacterError = DOMExceptionConstants::INVALID_CHARACTER_ERR as uint, + NoModificationAllowedError = DOMExceptionConstants::NO_MODIFICATION_ALLOWED_ERR as uint, + NotFoundError = DOMExceptionConstants::NOT_FOUND_ERR as uint, + NotSupportedError = DOMExceptionConstants::NOT_SUPPORTED_ERR as uint, + InvalidStateError = DOMExceptionConstants::INVALID_STATE_ERR as uint, + SyntaxError = DOMExceptionConstants::SYNTAX_ERR as uint, + InvalidModificationError = DOMExceptionConstants::INVALID_MODIFICATION_ERR as uint, + NamespaceError = DOMExceptionConstants::NAMESPACE_ERR as uint, + InvalidAccessError = DOMExceptionConstants::INVALID_ACCESS_ERR as uint, + SecurityError = DOMExceptionConstants::SECURITY_ERR as uint, + NetworkError = DOMExceptionConstants::NETWORK_ERR as uint, + AbortError = DOMExceptionConstants::ABORT_ERR as uint, + URLMismatchError = DOMExceptionConstants::URL_MISMATCH_ERR as uint, + QuotaExceededError = DOMExceptionConstants::QUOTA_EXCEEDED_ERR as uint, + TimeoutError = DOMExceptionConstants::TIMEOUT_ERR as uint, + InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR as uint, + DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR as uint, EncodingError } @@ -100,7 +100,7 @@ impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> { // http://dom.spec.whatwg.org/#error-names-0 fn Name(&self) -> DOMString { - self.code.to_str() + self.code.to_string() } // http://dom.spec.whatwg.org/#error-names-0 diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index afc176b8a26..04d9603bdb6 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -176,7 +176,7 @@ impl RawLayoutElementHelpers for Element { unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) -> Option<&'static str> { // cast to point to T in RefCell<T> directly - let attrs: *Vec<JS<Attr>> = mem::transmute(&self.attrs); + let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); (*attrs).iter().find(|attr: & &JS<Attr>| { let attr = attr.unsafe_get(); name == (*attr).local_name.as_slice() && (*attr).namespace == *namespace @@ -190,7 +190,7 @@ impl RawLayoutElementHelpers for Element { unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) -> Option<Atom> { // cast to point to T in RefCell<T> directly - let attrs: *Vec<JS<Attr>> = mem::transmute(&self.attrs); + let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); (*attrs).iter().find(|attr: & &JS<Attr>| { let attr = attr.unsafe_get(); name == (*attr).local_name.as_slice() && (*attr).namespace == *namespace @@ -427,7 +427,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn set_uint_attribute(&self, name: &str, value: u32) { assert!(name == name.to_ascii_lower().as_slice()); - self.set_attribute(name, UIntAttrValue(value.to_str(), value)); + self.set_attribute(name, UIntAttrValue(value.to_string(), value)); } } @@ -791,9 +791,9 @@ pub fn get_attribute_parts<'a>(name: &'a str) -> (Option<&'a str>, &'a str) { } impl<'a> VirtualMethods for JSRef<'a, Element> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let node: &JSRef<Node> = NodeCast::from_ref(self); - Some(node as &VirtualMethods+) + Some(node as &VirtualMethods) } fn after_set_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index b84eff12607..115f9a4024b 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -29,10 +29,10 @@ pub enum Event_ { #[deriving(Encodable)] pub enum EventPhase { - PhaseNone = EventConstants::NONE, - PhaseCapturing = EventConstants::CAPTURING_PHASE, - PhaseAtTarget = EventConstants::AT_TARGET, - PhaseBubbling = EventConstants::BUBBLING_PHASE, + PhaseNone = EventConstants::NONE as int, + PhaseCapturing = EventConstants::CAPTURING_PHASE as int, + PhaseAtTarget = EventConstants::AT_TARGET as int, + PhaseBubbling = EventConstants::BUBBLING_PHASE as int, } #[deriving(PartialEq, Encodable)] diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index e1a74b17aeb..4f2cba18def 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -179,18 +179,20 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { let nargs = 1; //XXXjdm not true for onerror static arg_name: [c_char, ..6] = ['e' as c_char, 'v' as c_char, 'e' as c_char, 'n' as c_char, 't' as c_char, 0]; - static arg_names: [*c_char, ..1] = [&arg_name as *c_char]; + static arg_names: [*const c_char, ..1] = [&arg_name as *const c_char]; - let source = source.to_utf16(); - let handler = name.with_ref(|name| { - url.with_ref(|url| { - unsafe { - JS_CompileUCFunction(cx, ptr::mut_null(), name, - nargs, &arg_names as **i8 as *mut *i8, - source.as_ptr(), source.len() as size_t, url, lineno) - } - }) - }); + let source: Vec<u16> = source.as_slice().utf16_units().collect(); + let handler = unsafe { + JS_CompileUCFunction(cx, + ptr::mut_null(), + name.as_ptr(), + nargs, + &arg_names as *const *const i8 as *mut *const i8, + source.as_ptr(), + source.len() as size_t, + url.as_ptr(), + lineno) + }; if handler.is_null() { report_pending_exception(cx, self.reflector().get_jsobject()); return; @@ -279,7 +281,7 @@ impl Reflectable for EventTarget { } impl<'a> VirtualMethods for JSRef<'a, EventTarget> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { None } } diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index 34b8591c4f5..5b905b1bd44 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -67,9 +67,9 @@ impl<'a> PrivateHTMLAnchorElementHelpers for JSRef<'a, HTMLAnchorElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLAnchorElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(htmlelement as &VirtualMethods+) + Some(htmlelement as &VirtualMethods) } fn handle_event(&self, event: &JSRef<Event>) { diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index a6ab3b047a8..64abfc39eac 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -55,9 +55,9 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let element: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(element as &VirtualMethods+) + Some(element as &VirtualMethods) } fn after_set_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmlcanvaselement.rs b/src/components/script/dom/htmlcanvaselement.rs index bf5208be532..509d246848e 100644 --- a/src/components/script/dom/htmlcanvaselement.rs +++ b/src/components/script/dom/htmlcanvaselement.rs @@ -93,9 +93,9 @@ impl<'a> HTMLCanvasElementMethods for JSRef<'a, HTMLCanvasElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLCanvasElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let element: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(element as &VirtualMethods+) + Some(element as &VirtualMethods) } fn before_remove_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs index 22a4527f5c9..6633e54d065 100644 --- a/src/components/script/dom/htmlelement.rs +++ b/src/components/script/dom/htmlelement.rs @@ -87,9 +87,9 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let element: &JSRef<Element> = ElementCast::from_ref(self); - Some(element as &VirtualMethods+) + Some(element as &VirtualMethods) } fn after_set_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index b4908d24cc3..5be30eceb2e 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -158,9 +158,9 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(htmlelement as &VirtualMethods+) + Some(htmlelement as &VirtualMethods) } fn after_set_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 7cffec11099..21c109195a3 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -129,7 +129,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { fn SetIsMap(&self, is_map: bool) { let element: &JSRef<Element> = ElementCast::from_ref(self); - element.set_string_attribute("isMap", is_map.to_str()) + element.set_string_attribute("isMap", is_map.to_string()) } fn Width(&self) -> u32 { @@ -216,9 +216,9 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(htmlelement as &VirtualMethods+) + Some(htmlelement as &VirtualMethods) } fn after_set_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index 407e4234fca..3dd88ff49f4 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -86,9 +86,9 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(htmlelement as &VirtualMethods+) + Some(htmlelement as &VirtualMethods) } fn after_set_attr(&self, name: DOMString, value: DOMString) { diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index eb4b29e1c97..d32219ea8f9 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -61,9 +61,9 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { } impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self); - Some(htmlelement as &VirtualMethods+) + Some(htmlelement as &VirtualMethods) } fn child_inserted(&self, child: &JSRef<Node>) { diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 325df6a29d0..a73c4d7e879 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -164,7 +164,7 @@ pub struct SharedLayoutData { pub struct LayoutData { chan: Option<LayoutChan>, _shared_data: SharedLayoutData, - _data: *(), + _data: *const (), } pub struct LayoutDataRef { @@ -197,7 +197,7 @@ impl LayoutDataRef { /// happen if you try to mutate the layout data while this is held. This is the only thread- /// safe layout data accessor. #[inline] - pub unsafe fn borrow_unchecked(&self) -> *Option<LayoutData> { + pub unsafe fn borrow_unchecked(&self) -> *const Option<LayoutData> { mem::transmute(&self.data_cell) } @@ -538,7 +538,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } fn to_trusted_node_address(&self) -> TrustedNodeAddress { - TrustedNodeAddress(self.deref() as *Node as *libc::c_void) + TrustedNodeAddress(self.deref() as *const Node as *const libc::c_void) } fn get_bounding_content_box(&self) -> Rect<Au> { @@ -665,7 +665,7 @@ pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: Untrusted if object.is_null() { fail!("Attempted to create a `JS<Node>` from an invalid pointer!") } - let boxed_node: *Node = utils::unwrap(object); + let boxed_node: *const Node = utils::unwrap(object); Temporary::new(JS::from_raw(boxed_node)) } } @@ -905,7 +905,7 @@ pub enum CloneChildrenFlag { DoNotCloneChildren } -fn as_uintptr<T>(t: &T) -> uintptr_t { t as *T as uintptr_t } +fn as_uintptr<T>(t: &T) -> uintptr_t { t as *const T as uintptr_t } impl Node { pub fn reflect_node<N: Reflectable+NodeBase> @@ -1918,9 +1918,9 @@ pub fn window_from_node<T: NodeBase>(derived: &JSRef<T>) -> Temporary<Window> { } impl<'a> VirtualMethods for JSRef<'a, Node> { - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+> { + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(self); - Some(eventtarget as &VirtualMethods+) + Some(eventtarget as &VirtualMethods) } } diff --git a/src/components/script/dom/urlsearchparams.rs b/src/components/script/dom/urlsearchparams.rs index 52e48628911..8c76e03a0b7 100644 --- a/src/components/script/dom/urlsearchparams.rs +++ b/src/components/script/dom/urlsearchparams.rs @@ -18,7 +18,7 @@ use encoding::types::{Encoding, EncodeReplace}; use std::cell::RefCell; use std::collections::hashmap::HashMap; -use std::num::ToStrRadix; +use std::fmt::radix; use std::ascii::OwnedStrAsciiExt; #[deriving(Encodable)] @@ -115,7 +115,9 @@ impl URLSearchParamsHelpers for URLSearchParams { a => { // http://url.spec.whatwg.org/#percent-encode let mut encoded = vec!(0x25); // % - encoded.push_all(a.to_str_radix(16).into_ascii_upper().as_bytes()); + let s = format!("{}", radix(a, 16)).into_ascii_upper(); + let bytes = s.as_bytes(); + encoded.push_all(bytes); encoded } }; diff --git a/src/components/script/dom/virtualmethods.rs b/src/components/script/dom/virtualmethods.rs index 04b750003c9..042420d7479 100644 --- a/src/components/script/dom/virtualmethods.rs +++ b/src/components/script/dom/virtualmethods.rs @@ -35,7 +35,7 @@ use servo_util::str::DOMString; pub trait VirtualMethods { /// Returns self as the superclass of the implementation for this trait, /// if any. - fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods+>; + fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods>; /// Called when changing or adding attributes, after the attribute's value /// has been updated. @@ -105,46 +105,46 @@ pub trait VirtualMethods { /// method call on the trait object will invoke the corresponding method on the /// concrete type, propagating up the parent hierarchy unless otherwise /// interrupted. -pub fn vtable_for<'a>(node: &'a JSRef<Node>) -> &'a VirtualMethods+ { +pub fn vtable_for<'a>(node: &'a JSRef<Node>) -> &'a VirtualMethods { match node.type_id() { ElementNodeTypeId(HTMLAnchorElementTypeId) => { let element: &JSRef<HTMLAnchorElement> = HTMLAnchorElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(HTMLBodyElementTypeId) => { let element: &JSRef<HTMLBodyElement> = HTMLBodyElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(HTMLCanvasElementTypeId) => { let element: &JSRef<HTMLCanvasElement> = HTMLCanvasElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(HTMLImageElementTypeId) => { let element: &JSRef<HTMLImageElement> = HTMLImageElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(HTMLIFrameElementTypeId) => { let element: &JSRef<HTMLIFrameElement> = HTMLIFrameElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(HTMLObjectElementTypeId) => { let element: &JSRef<HTMLObjectElement> = HTMLObjectElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(HTMLStyleElementTypeId) => { let element: &JSRef<HTMLStyleElement> = HTMLStyleElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(ElementTypeId) => { let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } ElementNodeTypeId(_) => { let element: &JSRef<HTMLElement> = HTMLElementCast::to_ref(node).unwrap(); - element as &VirtualMethods+ + element as &VirtualMethods } _ => { - node as &VirtualMethods+ + node as &VirtualMethods } } } diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index a3a21046bd6..b2bfd64eb4e 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -71,11 +71,11 @@ pub enum XMLHttpRequestId { #[deriving(PartialEq, Encodable)] enum XMLHttpRequestState { - Unsent = 0u16, - Opened = 1u16, - HeadersReceived = 2u16, - Loading = 3u16, - XHRDone = 4u16, // So as not to conflict with the ProgressMsg `Done` + Unsent = 0, + Opened = 1, + HeadersReceived = 2, + Loading = 3, + XHRDone = 4, // So as not to conflict with the ProgressMsg `Done` } pub enum XHRProgress { @@ -632,7 +632,8 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { }, _ if self.ready_state.deref().get() != XHRDone => NullValue(), Json => { - let decoded = UTF_8.decode(self.response.deref().borrow().as_slice(), DecodeReplace).unwrap().to_string().to_utf16(); + let decoded = UTF_8.decode(self.response.deref().borrow().as_slice(), DecodeReplace).unwrap().to_string(); + let decoded: Vec<u16> = decoded.as_slice().utf16_units().collect(); let mut vp = UndefinedValue(); unsafe { if JS_ParseJSON(cx, decoded.as_ptr(), decoded.len() as u32, &mut vp) == 0 { @@ -679,7 +680,7 @@ impl XMLHttpRequestDerived for EventTarget { } } -pub struct TrustedXHRAddress(pub *c_void); +pub struct TrustedXHRAddress(pub *const c_void); impl TrustedXHRAddress { pub fn release_once(self) { @@ -713,7 +714,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { } let pinned_count = self.pinned_count.deref().get(); self.pinned_count.deref().set(pinned_count + 1); - TrustedXHRAddress(self.deref() as *XMLHttpRequest as *libc::c_void) + TrustedXHRAddress(self.deref() as *const XMLHttpRequest as *const libc::c_void) } fn release_once(&self) { |