mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Merge pull request #2683 from Ms2ger/nointerfaceobject
Fix the implementation of NoInterfaceObject.
This commit is contained in:
commit
5067ebac2a
3 changed files with 49 additions and 49 deletions
|
@ -1880,13 +1880,6 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
getParentProto = ("let parentProto: *mut JSObject = %s;\n"
|
getParentProto = ("let parentProto: *mut JSObject = %s;\n"
|
||||||
"assert!(parentProto.is_not_null());\n") % getParentProto
|
"assert!(parentProto.is_not_null());\n") % getParentProto
|
||||||
|
|
||||||
if self.descriptor.interface.ctor():
|
|
||||||
constructHook = CONSTRUCT_HOOK_NAME
|
|
||||||
constructArgs = methodLength(self.descriptor.interface.ctor())
|
|
||||||
else:
|
|
||||||
constructHook = "ThrowingConstructor"
|
|
||||||
constructArgs = 0
|
|
||||||
|
|
||||||
if self.descriptor.concrete:
|
if self.descriptor.concrete:
|
||||||
if self.descriptor.proxy:
|
if self.descriptor.proxy:
|
||||||
domClass = "&Class"
|
domClass = "&Class"
|
||||||
|
@ -1901,20 +1894,31 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
return "None"
|
return "None"
|
||||||
return "Some(%s.as_slice())" % val
|
return "Some(%s.as_slice())" % val
|
||||||
|
|
||||||
|
if needInterfaceObject:
|
||||||
|
if self.descriptor.interface.ctor():
|
||||||
|
constructHook = CONSTRUCT_HOOK_NAME
|
||||||
|
constructArgs = methodLength(self.descriptor.interface.ctor())
|
||||||
|
else:
|
||||||
|
constructHook = "ThrowingConstructor"
|
||||||
|
constructArgs = 0
|
||||||
|
|
||||||
|
constructor = 'Some((%s, "%s", %d))' % (
|
||||||
|
constructHook, self.descriptor.interface.identifier.name,
|
||||||
|
constructArgs)
|
||||||
|
else:
|
||||||
|
constructor = 'None'
|
||||||
|
|
||||||
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
||||||
&PrototypeClass, %s, %d,
|
&PrototypeClass, %s,
|
||||||
%s,
|
|
||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s);""" % (
|
%s);""" % (
|
||||||
"Some(%s)" % constructHook if needInterfaceObject else "None",
|
constructor,
|
||||||
constructArgs,
|
|
||||||
domClass,
|
domClass,
|
||||||
arrayPtr("methods"), arrayPtr("attrs"),
|
arrayPtr("methods"), arrayPtr("attrs"),
|
||||||
arrayPtr("consts"), arrayPtr("staticMethods"),
|
arrayPtr("consts"), arrayPtr("staticMethods"))
|
||||||
'"' + self.descriptor.interface.identifier.name + '"' if needInterfaceObject else "ptr::null()")
|
|
||||||
|
|
||||||
functionBody = CGList(
|
functionBody = CGList(
|
||||||
[CGGeneric(getParentProto),
|
[CGGeneric(getParentProto),
|
||||||
|
@ -1997,13 +2001,6 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
||||||
return CGAbstractMethod.define(self)
|
return CGAbstractMethod.define(self)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
if self.descriptor.interface.hasInterfacePrototypeObject():
|
|
||||||
# We depend on GetProtoObject defining an interface constructor
|
|
||||||
# object as needed.
|
|
||||||
getter = "GetProtoObject"
|
|
||||||
else:
|
|
||||||
getter = "GetConstructorObject"
|
|
||||||
|
|
||||||
body = ""
|
body = ""
|
||||||
#XXXjdm This self.descriptor.concrete check shouldn't be necessary
|
#XXXjdm This self.descriptor.concrete check shouldn't be necessary
|
||||||
if not self.descriptor.concrete or self.descriptor.proxy:
|
if not self.descriptor.concrete or self.descriptor.proxy:
|
||||||
|
@ -2045,10 +2042,13 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
||||||
TRACE_HOOK_NAME,
|
TRACE_HOOK_NAME,
|
||||||
self.descriptor.name)
|
self.descriptor.name)
|
||||||
|
|
||||||
return (body + """ let cx = (**js_info.js_context).ptr;
|
if self.descriptor.interface.hasInterfaceObject():
|
||||||
|
body += """ let cx = (**js_info.js_context).ptr;
|
||||||
let global = window.reflector().get_jsobject();
|
let global = window.reflector().get_jsobject();
|
||||||
assert!(global.is_not_null());
|
assert!(global.is_not_null());
|
||||||
assert!(%s(cx, global, global).is_not_null());""" % (getter))
|
assert!(GetProtoObject(cx, global, global).is_not_null());"""
|
||||||
|
|
||||||
|
return body
|
||||||
|
|
||||||
def needCx(returnType, arguments, extendedAttributes, considerTypes):
|
def needCx(returnType, arguments, extendedAttributes, considerTypes):
|
||||||
return (considerTypes and
|
return (considerTypes and
|
||||||
|
@ -3807,8 +3807,10 @@ class CGDescriptor(CGThing):
|
||||||
cgThings = []
|
cgThings = []
|
||||||
if descriptor.interface.hasInterfacePrototypeObject():
|
if descriptor.interface.hasInterfacePrototypeObject():
|
||||||
cgThings.append(CGGetProtoObjectMethod(descriptor))
|
cgThings.append(CGGetProtoObjectMethod(descriptor))
|
||||||
else:
|
if descriptor.interface.hasInterfaceObject():
|
||||||
cgThings.append(CGGetConstructorObjectMethod(descriptor))
|
# https://github.com/mozilla/servo/issues/2665
|
||||||
|
# cgThings.append(CGGetConstructorObjectMethod(descriptor))
|
||||||
|
pass
|
||||||
|
|
||||||
if descriptor.interface.hasInterfacePrototypeObject():
|
if descriptor.interface.hasInterfacePrototypeObject():
|
||||||
(hasMethod, hasGetter, hasLenientGetter,
|
(hasMethod, hasGetter, hasLenientGetter,
|
||||||
|
@ -3861,8 +3863,7 @@ class CGDescriptor(CGThing):
|
||||||
CGConstant(m for m in descriptor.interface.members if m.isConst()),
|
CGConstant(m for m in descriptor.interface.members if m.isConst()),
|
||||||
public=True))
|
public=True))
|
||||||
|
|
||||||
if descriptor.interface.hasInterfaceObject():
|
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
|
||||||
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
|
|
||||||
|
|
||||||
if descriptor.concrete:
|
if descriptor.concrete:
|
||||||
if descriptor.proxy:
|
if descriptor.proxy:
|
||||||
|
@ -4108,7 +4109,7 @@ class CGRegisterProtos(CGAbstractMethod):
|
||||||
|
|
||||||
def _registerProtos(self):
|
def _registerProtos(self):
|
||||||
lines = [" codegen::Bindings::%sBinding::DefineDOMInterface(window, js_info);" % desc.name
|
lines = [" codegen::Bindings::%sBinding::DefineDOMInterface(window, js_info);" % desc.name
|
||||||
for desc in self.config.getDescriptors(hasInterfaceObject=True,
|
for desc in self.config.getDescriptors(isCallback=False,
|
||||||
register=True)]
|
register=True)]
|
||||||
return '\n'.join(lines) + '\n'
|
return '\n'.join(lines) + '\n'
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
|
@ -5126,13 +5127,7 @@ class GlobalGenRoots():
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def InterfaceTypes(config):
|
def InterfaceTypes(config):
|
||||||
|
descriptors = [d.name for d in config.getDescriptors(register=True, isCallback=False)]
|
||||||
def pathToType(descriptor):
|
|
||||||
if descriptor.interface.isCallback():
|
|
||||||
return "dom::bindings::codegen::Bindings::%sBinding" % descriptor.name
|
|
||||||
return "dom::%s" % descriptor.name.lower()
|
|
||||||
|
|
||||||
descriptors = [d.name for d in config.getDescriptors(register=True, hasInterfaceObject=True)]
|
|
||||||
curr = CGList([CGGeneric("pub use dom::%s::%s;\n" % (name.lower(), name)) for name in descriptors])
|
curr = CGList([CGGeneric("pub use dom::%s::%s;\n" % (name.lower(), name)) for name in descriptors])
|
||||||
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
|
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
|
||||||
return curr
|
return curr
|
||||||
|
@ -5149,7 +5144,7 @@ class GlobalGenRoots():
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def InheritTypes(config):
|
def InheritTypes(config):
|
||||||
|
|
||||||
descriptors = config.getDescriptors(register=True, hasInterfaceObject=True)
|
descriptors = config.getDescriptors(register=True, isCallback=False)
|
||||||
allprotos = [CGGeneric("#![allow(unused_imports)]\n"),
|
allprotos = [CGGeneric("#![allow(unused_imports)]\n"),
|
||||||
CGGeneric("use dom::types::*;\n"),
|
CGGeneric("use dom::types::*;\n"),
|
||||||
CGGeneric("use dom::bindings::js::{JS, JSRef, Temporary};\n"),
|
CGGeneric("use dom::bindings::js::{JS, JSRef, Temporary};\n"),
|
||||||
|
|
|
@ -34,7 +34,7 @@ use js::jsapi::{JS_HasPropertyById, JS_GetPrototype};
|
||||||
use js::jsapi::{JS_GetProperty, JS_HasProperty};
|
use js::jsapi::{JS_GetProperty, JS_HasProperty};
|
||||||
use js::jsapi::{JS_DefineFunctions, JS_DefineProperty};
|
use js::jsapi::{JS_DefineFunctions, JS_DefineProperty};
|
||||||
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
||||||
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative};
|
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass};
|
||||||
use js::jsapi::{JSFunctionSpec, JSPropertySpec};
|
use js::jsapi::{JSFunctionSpec, JSPropertySpec};
|
||||||
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
||||||
use js::jsapi::{JSString};
|
use js::jsapi::{JSString};
|
||||||
|
@ -215,17 +215,18 @@ pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> *mut *mut JSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type NonNullJSNative =
|
||||||
|
unsafe extern "C" fn (arg1: *mut JSContext, arg2: c_uint, arg3: *mut JSVal) -> JSBool;
|
||||||
|
|
||||||
pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
||||||
protoProto: *mut JSObject,
|
protoProto: *mut JSObject,
|
||||||
protoClass: &'static JSClass,
|
protoClass: &'static JSClass,
|
||||||
constructor: JSNative,
|
constructor: Option<(NonNullJSNative, &'static str, u32)>,
|
||||||
ctorNargs: u32,
|
|
||||||
domClass: *DOMClass,
|
domClass: *DOMClass,
|
||||||
methods: Option<&'static [JSFunctionSpec]>,
|
methods: Option<&'static [JSFunctionSpec]>,
|
||||||
properties: Option<&'static [JSPropertySpec]>,
|
properties: Option<&'static [JSPropertySpec]>,
|
||||||
constants: Option<&'static [ConstantSpec]>,
|
constants: Option<&'static [ConstantSpec]>,
|
||||||
staticMethods: Option<&'static [JSFunctionSpec]>,
|
staticMethods: Option<&'static [JSFunctionSpec]>) -> *mut JSObject {
|
||||||
name: &str) -> *mut JSObject {
|
|
||||||
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
||||||
protoClass, methods,
|
protoClass, methods,
|
||||||
properties, constants);
|
properties, constants);
|
||||||
|
@ -235,25 +236,28 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
PrivateValue(domClass as *libc::c_void));
|
PrivateValue(domClass as *libc::c_void));
|
||||||
}
|
}
|
||||||
|
|
||||||
if constructor.is_some() {
|
match constructor {
|
||||||
name.to_c_str().with_ref(|s| {
|
Some((native, name, nargs)) => {
|
||||||
CreateInterfaceObject(cx, global, receiver,
|
name.to_c_str().with_ref(|s| {
|
||||||
constructor, ctorNargs, proto,
|
CreateInterfaceObject(cx, global, receiver,
|
||||||
staticMethods, constants, s)
|
native, nargs, proto,
|
||||||
});
|
staticMethods, constants, s)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
None => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
proto
|
proto
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
||||||
constructorNative: JSNative,
|
constructorNative: NonNullJSNative,
|
||||||
ctorNargs: u32, proto: *mut JSObject,
|
ctorNargs: u32, proto: *mut JSObject,
|
||||||
staticMethods: Option<&'static [JSFunctionSpec]>,
|
staticMethods: Option<&'static [JSFunctionSpec]>,
|
||||||
constants: Option<&'static [ConstantSpec]>,
|
constants: Option<&'static [ConstantSpec]>,
|
||||||
name: *libc::c_char) {
|
name: *libc::c_char) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
let fun = JS_NewFunction(cx, Some(constructorNative), ctorNargs,
|
||||||
JSFUN_CONSTRUCTOR, global, name);
|
JSFUN_CONSTRUCTOR, global, name);
|
||||||
assert!(fun.is_not_null());
|
assert!(fun.is_not_null());
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
[NoInterfaceObject]
|
||||||
interface AttrList {
|
interface AttrList {
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
getter Attr? item(unsigned long index);
|
getter Attr? item(unsigned long index);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue