Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of work on bindings #397

Merged
merged 10 commits into from Apr 24, 2013

Remove all traces of owned DOM objects. This DOM is all about sharing.

  • Loading branch information
jdm committed Apr 23, 2013
commit 6fbf40988faf757a3bfa9b60be0dd131379c27c6
@@ -25,10 +25,6 @@ impl CacheableWrapper for ClientRect {
unsafe { cast::transmute(&self.wrapper) }
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"nyi")
}

fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
ClientRectBinding::Wrap(cx, scope, self, &mut unused)
@@ -24,10 +24,6 @@ impl CacheableWrapper for ClientRectList {
unsafe { cast::transmute(&self.wrapper) }
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"nyi")
}

fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
ClientRectListBinding::Wrap(cx, scope, self, &mut unused)
@@ -2439,7 +2439,7 @@ def CreateBindingJSObject(descriptor, parent):
let handler = (*content).dom_static.proxy_handlers.get(&(prototypes::id::%s as uint));
""" % descriptor.name
create = handler + """ let obj = NewProxyObject(aCx, *handler,
ptr::addr_of(&RUST_PRIVATE_TO_JSVAL(squirrel_away_ref(aObject) as *libc::c_void)),
ptr::addr_of(&RUST_PRIVATE_TO_JSVAL(squirrel_away(aObject) as *libc::c_void)),
proto, %s,
ptr::null(), ptr::null());
if obj.is_null() {
@@ -2454,15 +2454,15 @@ def CreateBindingJSObject(descriptor, parent):
}
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
RUST_PRIVATE_TO_JSVAL(squirrel_away_ref(aObject) as *libc::c_void));
RUST_PRIVATE_TO_JSVAL(squirrel_away(aObject) as *libc::c_void));
"""
return create % parent

class CGWrapWithCacheMethod(CGAbstractMethod):
def __init__(self, descriptor):
assert descriptor.interface.hasInterfacePrototypeObject()
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aScope'),
Argument('&mut BindingReference<' + descriptor.nativeType + '>', 'aObject'),
Argument('@mut ' + descriptor.nativeType, 'aObject'),
Argument('*mut bool', 'aTriedToWrap')]
CGAbstractMethod.__init__(self, descriptor, 'Wrap_', '*JSObject', args)

@@ -2505,8 +2505,7 @@ def __init__(self, descriptor):
CGAbstractMethod.__init__(self, descriptor, 'Wrap', '*JSObject', args, inline=True, pub=True)

def definition_body(self):
return " let mut binding = BindingReference(Right(aObject)); \
return Wrap_(aCx, aScope, &mut binding, aTriedToWrap);"
return "return Wrap_(aCx, aScope, aObject, aTriedToWrap);"

class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
def __init__(self, descriptor):
@@ -145,10 +145,6 @@ impl CacheableWrapper for Document {
unsafe { cast::transmute(&self.wrapper) }
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"need to implement wrapping");
}

fn wrap_object_shared(@mut self, cx: *JSContext, _scope: *JSObject) -> *JSObject {
let content = task_from_context(cx);
unsafe { create((*content).compartment.get(), self) }
@@ -11,10 +11,6 @@ impl CacheableWrapper for DOMParser {
unsafe { cast::transmute(&self.wrapper) }
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"need to implement wrapping");
}

fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
DOMParserBinding::Wrap(cx, scope, self, &mut unused)
@@ -31,10 +31,6 @@ impl CacheableWrapper for HTMLCollection {
unsafe { cast::transmute(&self.wrapper) }
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"nyi")
}

fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
HTMLCollectionBinding::Wrap(cx, scope, self, &mut unused)
@@ -167,10 +167,6 @@ impl CacheableWrapper for AbstractNode {
}
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"need to implement wrapping");
}

fn wrap_object_shared(@mut self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"need to implement wrapping");
}
@@ -130,12 +130,6 @@ pub unsafe fn squirrel_away<T>(x: @mut T) -> *rust_box<T> {
y
}

pub unsafe fn squirrel_away_unique<T>(x: ~T) -> *rust_box<T> {
let y: *rust_box<T> = cast::reinterpret_cast(&x);
cast::forget(x);
y
}

//XXX very incomplete
pub fn jsval_to_str(cx: *JSContext, v: JSVal) -> Result<~str, ()> {
let jsstr;
@@ -561,7 +555,6 @@ pub fn initialize_global(global: *JSObject) {

pub trait CacheableWrapper {
fn get_wrappercache(&mut self) -> &mut WrapperCache;
fn wrap_object_unique(~self, cx: *JSContext, scope: *JSObject) -> *JSObject;
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject;
}

@@ -623,39 +616,10 @@ pub fn WrapNativeParent(cx: *JSContext, scope: *JSObject, mut p: @mut CacheableW
wrapper
}

pub struct BindingReference<T>(Either<~T, @mut T>);

pub trait BindingObject {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper;
}

pub impl<T: BindingObject + CacheableWrapper> BindingReference<T> {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
match **self {
Left(ref obj) => obj.GetParentObject(cx),
Right(ref obj) => obj.GetParentObject(cx)
}
}

fn get_wrappercache(&mut self) -> &mut WrapperCache {
match **self {
Left(ref mut obj) => obj.get_wrappercache(),
Right(ref mut obj) => obj.get_wrappercache()
}
}
}

pub fn squirrel_away_ref<R>(obj: &mut BindingReference<R>) -> *rust_box<R> {
let mut tmp: BindingReference<R> = unstable::intrinsics::init();
tmp <-> *obj;
unsafe {
match tmp {
BindingReference(Left(obj)) => squirrel_away_unique(obj),
BindingReference(Right(obj)) => squirrel_away(obj)
}
}
}

pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
vp: *JSVal) -> bool {
unsafe {
@@ -159,10 +159,6 @@ impl CacheableWrapper for Window {
unsafe { cast::transmute(&self.wrapper) }
}

fn wrap_object_unique(~self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"should this be called?");
}

fn wrap_object_shared(@mut self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
fail!(~"should this be called?");
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.