mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
auto merge of #1811 : Ms2ger/servo/Wrap_, r=jdm
This commit is contained in:
commit
da6a571f9e
28 changed files with 65 additions and 72 deletions
|
@ -85,6 +85,11 @@ DOMInterfaces = {
|
|||
'ValidityState': {},
|
||||
'Window': {
|
||||
'createGlobal': True,
|
||||
'needsAbstract': [
|
||||
'console',
|
||||
'location',
|
||||
'navigator',
|
||||
],
|
||||
},
|
||||
|
||||
'WindowProxy': {},
|
||||
|
|
|
@ -2569,8 +2569,7 @@ def CreateBindingJSObject(descriptor, parent=None):
|
|||
if descriptor.proxy:
|
||||
assert not descriptor.createGlobal
|
||||
handler = """
|
||||
let page = page_from_context(aCx);
|
||||
let mut js_info = (*page).js_info();
|
||||
let js_info = aScope.get().page().js_info();
|
||||
let handler = js_info.get().get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
|
||||
""" % descriptor.name
|
||||
create += handler + """ let obj = NewProxyObject(aCx, *handler,
|
||||
|
@ -2596,21 +2595,26 @@ def CreateBindingJSObject(descriptor, parent=None):
|
|||
"""
|
||||
return create
|
||||
|
||||
class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||
class CGWrapMethod(CGAbstractMethod):
|
||||
def __init__(self, descriptor):
|
||||
assert descriptor.interface.hasInterfacePrototypeObject()
|
||||
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aScope'),
|
||||
Argument(DOMObjectPointerArg(descriptor), 'aObject', mutable=True)]
|
||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap_', '*JSObject', args)
|
||||
if not descriptor.createGlobal:
|
||||
args = [Argument('*JSContext', 'aCx'), Argument('&JS<Window>', 'aScope'),
|
||||
Argument(DOMObjectPointerArg(descriptor), 'aObject', mutable=True)]
|
||||
else:
|
||||
args = [Argument('*JSContext', 'aCx'),
|
||||
Argument(DOMObjectPointerArg(descriptor), 'aObject', mutable=True)]
|
||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', '*JSObject', args, pub=True)
|
||||
|
||||
def definition_body(self):
|
||||
if not self.descriptor.createGlobal:
|
||||
return """
|
||||
assert!(aScope.is_not_null());
|
||||
assert!(((*JS_GetClass(aScope)).flags & JSCLASS_IS_GLOBAL) != 0);
|
||||
let scope = aScope.reflector().get_jsobject();
|
||||
assert!(scope.is_not_null());
|
||||
assert!(((*JS_GetClass(scope)).flags & JSCLASS_IS_GLOBAL) != 0);
|
||||
|
||||
//JSAutoCompartment ac(aCx, aScope);
|
||||
let proto = GetProtoObject(aCx, aScope, aScope);
|
||||
//JSAutoCompartment ac(aCx, scope);
|
||||
let proto = GetProtoObject(aCx, scope, scope);
|
||||
if proto.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
@ -2619,28 +2623,15 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
|||
|
||||
(*raw).mut_reflector().set_jsobject(obj);
|
||||
|
||||
return obj;""" % CreateBindingJSObject(self.descriptor, "aScope")
|
||||
return obj;""" % CreateBindingJSObject(self.descriptor, "scope")
|
||||
else:
|
||||
return """
|
||||
assert!(aScope.is_null());
|
||||
|
||||
%s
|
||||
let proto = GetProtoObject(aCx, obj, obj);
|
||||
JS_SetPrototype(aCx, obj, proto);
|
||||
(*raw).mut_reflector().set_jsobject(obj);
|
||||
return obj;""" % CreateBindingJSObject(self.descriptor)
|
||||
|
||||
class CGWrapMethod(CGAbstractMethod):
|
||||
def __init__(self, descriptor):
|
||||
# XXX can we wrap if we don't have an interface prototype object?
|
||||
assert descriptor.interface.hasInterfacePrototypeObject()
|
||||
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aScope'),
|
||||
Argument(DOMObjectPointerArg(descriptor), 'aObject', mutable=True)]
|
||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap', '*JSObject', args, inline=True, pub=True)
|
||||
|
||||
def definition_body(self):
|
||||
return "return Wrap_(aCx, aScope, aObject);"
|
||||
|
||||
class CGAbstractExternMethod(CGAbstractMethod):
|
||||
"""
|
||||
Abstract base class for codegen of implementation-only (no
|
||||
|
@ -4929,7 +4920,6 @@ class CGDescriptor(CGThing):
|
|||
cgThings.append(CGDOMJSClass(descriptor))
|
||||
pass
|
||||
|
||||
cgThings.append(CGWrapWithCacheMethod(descriptor))
|
||||
cgThings.append(CGWrapMethod(descriptor))
|
||||
|
||||
cgThings = CGList((CGIndenter(t, declareOnly=True) for t in cgThings), "\n")
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::utils::{Reflector, Reflectable};
|
||||
use dom::window;
|
||||
use dom::window::Window;
|
||||
use js::jsapi::{JSContext, JSObject};
|
||||
use layout_interface::TrustedNodeAddress;
|
||||
|
||||
|
@ -31,12 +31,11 @@ impl <T> Clone for JS<T> {
|
|||
|
||||
impl<T: Reflectable> JS<T> {
|
||||
pub fn new(mut obj: ~T,
|
||||
window: &window::Window,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, *JSObject, ~T) -> *JSObject) -> JS<T> {
|
||||
let cx = window.get_cx();
|
||||
let scope = window.reflector().get_jsobject();
|
||||
window: &JS<Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JS<Window>, ~T) -> *JSObject) -> JS<T> {
|
||||
let cx = window.get().get_cx();
|
||||
let raw: *mut T = &mut *obj;
|
||||
if wrap_fn(cx, scope, obj).is_null() {
|
||||
if wrap_fn(cx, window, obj).is_null() {
|
||||
fail!("Could not eagerly wrap object");
|
||||
}
|
||||
JS {
|
||||
|
|
|
@ -491,8 +491,8 @@ pub trait Reflectable {
|
|||
|
||||
pub fn reflect_dom_object<T: Reflectable>
|
||||
(obj: ~T,
|
||||
window: &window::Window,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, *JSObject, ~T) -> *JSObject)
|
||||
window: &JS<window::Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JS<window::Window>, ~T) -> *JSObject)
|
||||
-> JS<T> {
|
||||
JS::new(obj, window, wrap_fn)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue