Generate bindings for HTMLDivElement, and pass abstract type to methods that need access to the opaque wrappers.

This commit is contained in:
Josh Matthews 2013-08-06 16:08:38 -04:00
parent 08ed6d318e
commit 65a33f60e5
10 changed files with 161 additions and 131 deletions

View file

@ -169,7 +169,8 @@ DOMInterfaces = {
'Element': {
'nativeType': 'AbstractNode<ScriptView>',
'pointerType': ''
'pointerType': '',
'needsAbstract': ['getClientRects', 'getBoundingClientRect']
},
'Event': {
@ -545,6 +546,7 @@ def addHTMLElement(element):
}
addHTMLElement('HTMLAnchorElement')
addHTMLElement('HTMLDivElement')
addHTMLElement('HTMLElement')
addHTMLElement('HTMLHeadElement')
addHTMLElement('HTMLHtmlElement')

View file

@ -3177,7 +3177,7 @@ class CGGenericMethod(CGAbstractBindingMethod):
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, ptr::to_unsafe_ptr(&(*this).payload) as *libc::c_void, argc, vp);"))
"return CallJitMethodOp(_info, cx, obj, this as *libc::c_void, argc, vp);"))
class CGAbstractStaticMethod(CGAbstractMethod):
"""
@ -3200,16 +3200,24 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.method = method
name = method.identifier.name
args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'),
Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('*mut rust_box<%s>' % descriptor.concreteType, 'this'),
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
def definition_body(self):
name = self.method.identifier.name
nativeName = MakeNativeName(self.descriptor.binaryNames.get(name, name))
return CGWrapper(CGMethodCall([], nativeName, self.method.isStatic(),
extraPre = ''
argsPre = []
if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = ' let abstract_this = %s::from_box(this);\n' % abstractName
argsPre = ['abstract_this']
return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(),
self.descriptor, self.method),
pre=" let obj = (*obj.unnamed);\n").define()
pre=extraPre +
" let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).payload;\n").define()
class CGGenericGetter(CGAbstractBindingMethod):
"""
@ -3233,7 +3241,7 @@ class CGGenericGetter(CGAbstractBindingMethod):
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, ptr::to_unsafe_ptr(&(*this).payload) as *libc::c_void, vp);"))
"return CallJitPropertyOp(info, cx, obj, this as *libc::c_void, vp);"))
class CGSpecializedGetter(CGAbstractExternMethod):
"""
@ -3245,7 +3253,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
name = 'get_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'),
Argument('*%s' % descriptor.concreteType, 'this'),
Argument('*mut rust_box<%s>' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'vp') ]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@ -3263,7 +3271,8 @@ class CGSpecializedGetter(CGAbstractExternMethod):
nativeName = "Get" + nativeName
return CGWrapper(CGIndenter(CGGetterCall(self.attr.type, nativeName,
self.descriptor, self.attr)),
pre=" let obj = (*obj.unnamed);\n").define()
pre=" let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).payload;\n").define()
class CGGenericSetter(CGAbstractBindingMethod):
"""
@ -3288,7 +3297,7 @@ class CGGenericSetter(CGAbstractBindingMethod):
"let undef = JSVAL_VOID;\n"
"let argv: *JSVal = if argc != 0 { JS_ARGV(cx, cast::transmute(vp)) } else { &undef as *JSVal };\n"
"let info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, cast::transmute(vp)));\n"
"if CallJitPropertyOp(info, cx, obj, ptr::to_unsafe_ptr(&(*this).payload) as *libc::c_void, argv) == 0 {"
"if CallJitPropertyOp(info, cx, obj, this as *libc::c_void, argv) == 0 {"
" return 0;\n"
"}\n"
"*vp = JSVAL_VOID;\n"
@ -3304,7 +3313,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
name = 'set_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'),
Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('*mut rust_box<%s>' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'argv')]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@ -3313,7 +3322,8 @@ class CGSpecializedSetter(CGAbstractExternMethod):
nativeName = "Set" + MakeNativeName(self.descriptor.binaryNames.get(name, name))
return CGWrapper(CGIndenter(CGSetterCall(self.attr.type, nativeName,
self.descriptor, self.attr)),
pre=" let obj = (*obj.unnamed);\n").define()
pre=" let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).payload;\n").define()
def infallibleForMember(member, type, descriptorProvider):
"""
@ -4606,6 +4616,7 @@ class CGBindingRoot(CGThing):
'dom::node::{AbstractNode, Node, Text}', #XXXjdm
'dom::document::{Document, AbstractDocument}', #XXXjdm
'dom::element::{Element, HTMLHeadElement, HTMLHtmlElement}', #XXXjdm
'dom::element::{HTMLDivElement}', #XXXjdm
'dom::htmlanchorelement::HTMLAnchorElement', #XXXjdm
'dom::htmlelement::HTMLElement', #XXXjdm
'dom::htmldocument::HTMLDocument', #XXXjdm

View file

@ -141,6 +141,7 @@ class Descriptor(DescriptorProvider):
self.nativeType = desc.get('nativeType', nativeTypeDefault)
self.pointerType = desc.get('pointerType', '@mut ')
self.concreteType = desc.get('concreteType', ifaceName)
self.needsAbstract = desc.get('needsAbstract', [])
self.hasInstanceInterface = desc.get('hasInstanceInterface', None)
# Do something sane for JSObject

View file

@ -0,0 +1,19 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*
* The origin of this IDL file is
* http://www.whatwg.org/specs/web-apps/current-work/
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
* Opera Software ASA. You are granted a license to use, reproduce
* and create derivative works of this document.
*/
interface HTMLDivElement : HTMLElement {};
partial interface HTMLDivElement {
[SetterThrows]
attribute DOMString align;
};