From d7c4f2ba93a93c328153586df0586d8b7f6c5ce7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 18 Jun 2014 11:53:07 +0200 Subject: [PATCH] Stop pretending that CreateInterfaceObjects2 can return the interface object. We do not currently support the case of a non-callback interface that doesn't have an interface prototype object. (This case is not allowed by the WebIDL specification; it was added to Gecko to allow feature-detecting the URL interface. See .) It follows that, if we call CreateInterfaceObjects2 at all, we will call it with a protoClass argument, so there is no reason to use a nullable pointer type for that argument. Moreover, if we had actually supported that case, the returned interface object would have been stored in the interface prototype object cache, to ill effect. --- .../dom/bindings/codegen/CodegenRust.py | 3 +- src/components/script/dom/bindings/utils.rs | 30 +++++++------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 075f1096769..6962a154574 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1902,14 +1902,13 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): return "Some(%s.as_slice())" % val call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto, - %s, %s, %d, + &PrototypeClass, %s, %d, %s, %s, %s, %s, %s, %s);""" % ( - "&PrototypeClass" if needInterfacePrototypeObject else "ptr::null()", "Some(%s)" % constructHook if needInterfaceObject else "None", constructArgs, domClass, diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 6b57c6be382..1e278b8ef48 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -216,7 +216,8 @@ pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> *mut *mut JSObject { } pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject, - protoProto: *mut JSObject, protoClass: *JSClass, + protoProto: *mut JSObject, + protoClass: &'static JSClass, constructor: JSNative, ctorNargs: u32, domClass: *DOMClass, @@ -225,32 +226,24 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv constants: Option<&'static [ConstantSpec]>, staticMethods: Option<&'static [JSFunctionSpec]>, name: &str) -> *mut JSObject { - let mut proto = ptr::mut_null(); - if protoClass.is_not_null() { - proto = CreateInterfacePrototypeObject(cx, global, protoProto, + let proto = CreateInterfacePrototypeObject(cx, global, protoProto, protoClass, methods, properties, constants); - unsafe { - JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT, - PrivateValue(domClass as *libc::c_void)); - } + unsafe { + JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT, + PrivateValue(domClass as *libc::c_void)); } - let mut interface = ptr::mut_null(); if constructor.is_some() { - interface = name.to_c_str().with_ref(|s| { + name.to_c_str().with_ref(|s| { CreateInterfaceObject(cx, global, receiver, constructor, ctorNargs, proto, staticMethods, constants, s) }); } - if protoClass.is_not_null() { - proto - } else { - interface - } + proto } fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject, @@ -258,7 +251,7 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m ctorNargs: u32, proto: *mut JSObject, staticMethods: Option<&'static [JSFunctionSpec]>, constants: Option<&'static [ConstantSpec]>, - name: *libc::c_char) -> *mut JSObject { + name: *libc::c_char) { unsafe { let fun = JS_NewFunction(cx, constructorNative, ctorNargs, JSFUN_CONSTRUCTOR, global, name); @@ -289,8 +282,6 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m ObjectValue(&*constructor), None, None, 0) != 0); } - - return constructor; } } @@ -326,7 +317,8 @@ fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: &'static } fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject, - parentProto: *mut JSObject, protoClass: *JSClass, + parentProto: *mut JSObject, + protoClass: &'static JSClass, methods: Option<&'static [JSFunctionSpec]>, properties: Option<&'static [JSPropertySpec]>, constants: Option<&'static [ConstantSpec]>) -> *mut JSObject {