mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +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
|
@ -43,18 +43,18 @@ impl Attr {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window, local_name: DOMString, value: DOMString) -> JS<Attr> {
|
||||
pub fn new(window: &JS<Window>, local_name: DOMString, value: DOMString) -> JS<Attr> {
|
||||
let name = local_name.clone();
|
||||
Attr::new_helper(window, local_name, value, name, Null, None)
|
||||
}
|
||||
|
||||
pub fn new_ns(window: &Window, local_name: DOMString, value: DOMString,
|
||||
pub fn new_ns(window: &JS<Window>, local_name: DOMString, value: DOMString,
|
||||
name: DOMString, namespace: Namespace,
|
||||
prefix: Option<DOMString>) -> JS<Attr> {
|
||||
Attr::new_helper(window, local_name, value, name, namespace, prefix)
|
||||
}
|
||||
|
||||
fn new_helper(window: &Window, local_name: DOMString, value: DOMString,
|
||||
fn new_helper(window: &JS<Window>, local_name: DOMString, value: DOMString,
|
||||
name: DOMString, namespace: Namespace,
|
||||
prefix: Option<DOMString>) -> JS<Attr> {
|
||||
let attr = Attr::new_inherited(local_name, value, name, namespace, prefix);
|
||||
|
|
|
@ -27,7 +27,7 @@ impl AttrList {
|
|||
|
||||
pub fn new(window: &JS<Window>, elem: &JS<Element>) -> JS<AttrList> {
|
||||
reflect_dom_object(~AttrList::new_inherited(window.clone(), elem.clone()),
|
||||
window.get(), AttrListBinding::Wrap)
|
||||
window, AttrListBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
|
|
|
@ -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'),
|
||||
if not descriptor.createGlobal:
|
||||
args = [Argument('*JSContext', 'aCx'), Argument('&JS<Window>', 'aScope'),
|
||||
Argument(DOMObjectPointerArg(descriptor), 'aObject', mutable=True)]
|
||||
CGAbstractMethod.__init__(self, descriptor, 'Wrap_', '*JSObject', args)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Blob {
|
|||
|
||||
pub fn new(window: &JS<Window>) -> JS<Blob> {
|
||||
reflect_dom_object(~Blob::new_inherited(window.clone()),
|
||||
window.get(),
|
||||
window,
|
||||
BlobBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl ClientRect {
|
|||
top: Au, bottom: Au,
|
||||
left: Au, right: Au) -> JS<ClientRect> {
|
||||
let rect = ClientRect::new_inherited(window.clone(), top, bottom, left, right);
|
||||
reflect_dom_object(~rect, window.get(), ClientRectBinding::Wrap)
|
||||
reflect_dom_object(~rect, window, ClientRectBinding::Wrap)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ impl ClientRectList {
|
|||
pub fn new(window: &JS<Window>,
|
||||
rects: ~[JS<ClientRect>]) -> JS<ClientRectList> {
|
||||
reflect_dom_object(~ClientRectList::new_inherited(window.clone(), rects),
|
||||
window.get(), ClientRectListBinding::Wrap)
|
||||
window, ClientRectListBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
|
|
|
@ -20,7 +20,7 @@ impl Console {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window) -> JS<Console> {
|
||||
pub fn new(window: &JS<Window>) -> JS<Console> {
|
||||
reflect_dom_object(~Console::new_inherited(), window, ConsoleBinding::Wrap)
|
||||
}
|
||||
|
||||
|
|
|
@ -87,10 +87,10 @@ impl Document {
|
|||
pub fn reflect_document<D: Reflectable+DocumentBase>
|
||||
(document: ~D,
|
||||
window: &JS<Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, *JSObject, ~D) -> *JSObject)
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JS<Window>, ~D) -> *JSObject)
|
||||
-> JS<D> {
|
||||
assert!(document.reflector().get_jsobject().is_null());
|
||||
let raw_doc = reflect_dom_object(document, window.get(), wrap_fn);
|
||||
let raw_doc = reflect_dom_object(document, window, wrap_fn);
|
||||
assert!(raw_doc.reflector().get_jsobject().is_not_null());
|
||||
|
||||
let document = DocumentCast::from(&raw_doc);
|
||||
|
|
|
@ -48,7 +48,7 @@ impl DOMException {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window, code: DOMErrorName) -> JS<DOMException> {
|
||||
pub fn new(window: &JS<Window>, code: DOMErrorName) -> JS<DOMException> {
|
||||
reflect_dom_object(~DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ impl DOMImplementation {
|
|||
}
|
||||
|
||||
pub fn new(owner: &JS<Window>) -> JS<DOMImplementation> {
|
||||
reflect_dom_object(~DOMImplementation::new_inherited(owner.clone()), owner.get(),
|
||||
reflect_dom_object(~DOMImplementation::new_inherited(owner.clone()), owner,
|
||||
DOMImplementationBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ impl DOMParser {
|
|||
}
|
||||
|
||||
pub fn new(owner: &JS<Window>) -> JS<DOMParser> {
|
||||
reflect_dom_object(~DOMParser::new_inherited(owner.clone()), owner.get(),
|
||||
reflect_dom_object(~DOMParser::new_inherited(owner.clone()), owner,
|
||||
DOMParserBinding::Wrap)
|
||||
}
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ impl Element {
|
|||
None => {
|
||||
let doc = self.node.owner_doc();
|
||||
let doc = doc.get();
|
||||
let new_attr = Attr::new_ns(doc.window.get(), local_name.clone(), value.clone(),
|
||||
let new_attr = Attr::new_ns(&doc.window, local_name.clone(), value.clone(),
|
||||
name.clone(), namespace.clone(),
|
||||
prefix);
|
||||
self.attrs.push(new_attr);
|
||||
|
|
|
@ -77,7 +77,7 @@ impl Event {
|
|||
|
||||
pub fn new(window: &JS<Window>) -> JS<Event> {
|
||||
reflect_dom_object(~Event::new_inherited(HTMLEventTypeId),
|
||||
window.get(),
|
||||
window,
|
||||
EventBinding::Wrap)
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ impl FormData {
|
|||
}
|
||||
|
||||
pub fn new(form: Option<JS<HTMLFormElement>>, window: &JS<Window>) -> JS<FormData> {
|
||||
reflect_dom_object(~FormData::new_inherited(form, window.clone()), window.get(), FormDataBinding::Wrap)
|
||||
reflect_dom_object(~FormData::new_inherited(form, window.clone()), window, FormDataBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Constructor(window: &JS<Window>, form: Option<JS<HTMLFormElement>>)
|
||||
|
|
|
@ -32,7 +32,7 @@ impl HTMLCollection {
|
|||
|
||||
pub fn new(window: &JS<Window>, elements: ~[JS<Element>]) -> JS<HTMLCollection> {
|
||||
reflect_dom_object(~HTMLCollection::new_inherited(window.clone(), elements),
|
||||
window.get(), HTMLCollectionBinding::Wrap)
|
||||
window, HTMLCollectionBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Location {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window, page: Rc<Page>) -> JS<Location> {
|
||||
pub fn new(window: &JS<Window>, page: Rc<Page>) -> JS<Location> {
|
||||
reflect_dom_object(~Location::new_inherited(page),
|
||||
window,
|
||||
LocationBinding::Wrap)
|
||||
|
|
|
@ -54,7 +54,7 @@ impl MouseEvent {
|
|||
|
||||
pub fn new(window: &JS<Window>) -> JS<MouseEvent> {
|
||||
reflect_dom_object(~MouseEvent::new_inherited(),
|
||||
window.get(),
|
||||
window,
|
||||
MouseEventBinding::Wrap)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ impl Navigator {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window) -> JS<Navigator> {
|
||||
pub fn new(window: &JS<Window>) -> JS<Navigator> {
|
||||
reflect_dom_object(~Navigator::new_inherited(),
|
||||
window,
|
||||
NavigatorBinding::Wrap)
|
||||
|
|
|
@ -754,10 +754,10 @@ impl Node {
|
|||
pub fn reflect_node<N: Reflectable+NodeBase>
|
||||
(node: ~N,
|
||||
document: &JS<Document>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, *JSObject, ~N) -> *JSObject)
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JS<Window>, ~N) -> *JSObject)
|
||||
-> JS<N> {
|
||||
assert!(node.reflector().get_jsobject().is_null());
|
||||
let node = reflect_dom_object(node, document.get().window.get(), wrap_fn);
|
||||
let node = reflect_dom_object(node, &document.get().window, wrap_fn);
|
||||
assert!(node.reflector().get_jsobject().is_not_null());
|
||||
node
|
||||
}
|
||||
|
|
|
@ -31,18 +31,18 @@ impl NodeList {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: JS<Window>,
|
||||
pub fn new(window: &JS<Window>,
|
||||
list_type: NodeListType) -> JS<NodeList> {
|
||||
reflect_dom_object(~NodeList::new_inherited(window.clone(), list_type),
|
||||
window.get(), NodeListBinding::Wrap)
|
||||
window, NodeListBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn new_simple_list(window: &JS<Window>, elements: ~[JS<Node>]) -> JS<NodeList> {
|
||||
NodeList::new(window.clone(), Simple(elements))
|
||||
NodeList::new(window, Simple(elements))
|
||||
}
|
||||
|
||||
pub fn new_child_list(window: &JS<Window>, node: &JS<Node>) -> JS<NodeList> {
|
||||
NodeList::new(window.clone(), Children(node.clone()))
|
||||
NodeList::new(window, Children(node.clone()))
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
|
|
|
@ -37,7 +37,7 @@ impl UIEvent {
|
|||
|
||||
pub fn new(window: &JS<Window>) -> JS<UIEvent> {
|
||||
reflect_dom_object(~UIEvent::new_inherited(UIEventTypeId),
|
||||
window.get(),
|
||||
window,
|
||||
UIEventBinding::Wrap)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ impl ValidityState {
|
|||
|
||||
pub fn new(window: &JS<Window>) -> JS<ValidityState> {
|
||||
reflect_dom_object(~ValidityState::new_inherited(window.clone()),
|
||||
window.get(),
|
||||
window,
|
||||
ValidityStateBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ use std::comm::Select;
|
|||
use std::hashmap::HashSet;
|
||||
use std::io::timer::Timer;
|
||||
use std::num;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use std::to_bytes::Cb;
|
||||
|
||||
|
@ -176,23 +175,23 @@ impl Window {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn Location(&mut self) -> JS<Location> {
|
||||
pub fn Location(&mut self, abstract_self: &JS<Window>) -> JS<Location> {
|
||||
if self.location.is_none() {
|
||||
self.location = Some(Location::new(self, self.extra.page.clone()));
|
||||
self.location = Some(Location::new(abstract_self, self.extra.page.clone()));
|
||||
}
|
||||
self.location.get_ref().clone()
|
||||
}
|
||||
|
||||
pub fn Console(&mut self) -> JS<Console> {
|
||||
pub fn Console(&mut self, abstract_self: &JS<Window>) -> JS<Console> {
|
||||
if self.console.is_none() {
|
||||
self.console = Some(Console::new(self));
|
||||
self.console = Some(Console::new(abstract_self));
|
||||
}
|
||||
self.console.get_ref().clone()
|
||||
}
|
||||
|
||||
pub fn Navigator(&mut self) -> JS<Navigator> {
|
||||
pub fn Navigator(&mut self, abstract_self: &JS<Window>) -> JS<Navigator> {
|
||||
if self.navigator.is_none() {
|
||||
self.navigator = Some(Navigator::new(self));
|
||||
self.navigator = Some(Navigator::new(abstract_self));
|
||||
}
|
||||
self.navigator.get_ref().clone()
|
||||
}
|
||||
|
@ -311,7 +310,7 @@ impl Window {
|
|||
};
|
||||
|
||||
let raw: *mut Window = &mut *win;
|
||||
let global = WindowBinding::Wrap(cx, ptr::null(), win);
|
||||
let global = WindowBinding::Wrap(cx, win);
|
||||
assert!(global.is_not_null());
|
||||
unsafe {
|
||||
let fn_names = ["window","self"];
|
||||
|
|
|
@ -13,11 +13,11 @@ pub struct WindowProxy {
|
|||
}
|
||||
|
||||
impl WindowProxy {
|
||||
pub fn new(owner: JS<Window>) -> JS<WindowProxy> {
|
||||
pub fn new(owner: &JS<Window>) -> JS<WindowProxy> {
|
||||
let proxy = ~WindowProxy {
|
||||
reflector_: Reflector::new()
|
||||
};
|
||||
reflect_dom_object(proxy, owner.get(), WindowProxyBinding::Wrap)
|
||||
reflect_dom_object(proxy, owner, WindowProxyBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -984,7 +984,7 @@ impl ScriptTask {
|
|||
Some(ref frame) => {
|
||||
// http://dev.w3.org/csswg/cssom-view/#resizing-viewports
|
||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize
|
||||
let window_proxy: JS<WindowProxy> = WindowProxy::new(frame.window.clone());
|
||||
let window_proxy: JS<WindowProxy> = WindowProxy::new(&frame.window);
|
||||
let mut uievent = UIEvent::new(&frame.window);
|
||||
uievent.get_mut().InitUIEvent(~"resize", false, false, Some(window_proxy), 0i32);
|
||||
let event: &mut JS<Event> = &mut EventCast::from(&uievent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue