Remove all traces of Box representation from bindings. Work around file read runtime problem.

This commit is contained in:
Josh Matthews 2014-03-14 12:55:57 -04:00 committed by Lars Bergstrom
parent bbac8aa5c3
commit f279abbf9f
8 changed files with 31 additions and 45 deletions

View file

@ -13,8 +13,9 @@ static READ_SIZE: uint = 1024;
fn read_all(reader: &mut io::Stream, progress_chan: &Chan<ProgressMsg>) fn read_all(reader: &mut io::Stream, progress_chan: &Chan<ProgressMsg>)
-> Result<(), ()> { -> Result<(), ()> {
loop { loop {
match (reader.read_bytes(READ_SIZE)) { let mut buf = ~[];
Ok(data) => progress_chan.send(Payload(data)), match (reader.push_bytes(&mut buf, READ_SIZE)) {
Ok(_) => progress_chan.send(Payload(buf)),
Err(e) => match e.kind { Err(e) => match e.kind {
io::EndOfFile => return Ok(()), io::EndOfFile => return Ok(()),
_ => return Err(()), _ => return Err(()),

View file

@ -389,7 +389,7 @@ class CGMethodCall(CGThing):
class FakeCastableDescriptor(): class FakeCastableDescriptor():
def __init__(self, descriptor): def __init__(self, descriptor):
self.castable = True self.castable = True
self.nativeType = "*Box<%s>" % descriptor.concreteType self.nativeType = "*%s" % descriptor.concreteType
self.name = descriptor.name self.name = descriptor.name
class FakeInterface: class FakeInterface:
def inheritanceDepth(self): def inheritanceDepth(self):
@ -2066,7 +2066,7 @@ def CreateBindingJSObject(descriptor, parent=None):
let handler = js_info.get().get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint)); let handler = js_info.get().get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
""" % descriptor.name """ % descriptor.name
create += handler + """ let obj = NewProxyObject(aCx, *handler, create += handler + """ let obj = NewProxyObject(aCx, *handler,
&PrivateValue(squirrel_away_unique(aObject) as *libc::c_void), &PrivateValue(squirrel_away_unboxed(aObject) as *libc::c_void),
proto, %s, proto, %s,
ptr::null(), ptr::null()); ptr::null(), ptr::null());
if obj.is_null() { if obj.is_null() {
@ -2084,7 +2084,7 @@ def CreateBindingJSObject(descriptor, parent=None):
} }
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32, JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
PrivateValue(squirrel_away_unique(aObject) as *libc::c_void)); PrivateValue(squirrel_away_unboxed(aObject) as *libc::c_void));
""" """
return create return create
@ -2388,7 +2388,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
body = "" #XXXjdm xray stuff isn't necessary yet body = "" #XXXjdm xray stuff isn't necessary yet
return (body + """ let cx = js_info.js_context.borrow().ptr; return (body + """ let cx = js_info.js_context.borrow().ptr;
let receiver = js_info.js_compartment.borrow().global_obj.borrow().ptr; let receiver = js_info.js_compartment.borrow().global_obj;
let global: *JSObject = JS_GetGlobalForObject(cx, receiver); let global: *JSObject = JS_GetGlobalForObject(cx, receiver);
return %s(cx, global, receiver).is_not_null();""" % (getter)) return %s(cx, global, receiver).is_not_null();""" % (getter))
@ -2693,7 +2693,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
" return false as JSBool;\n" " return false as JSBool;\n"
"}\n" "}\n"
"\n" "\n"
"let this: *Box<%s>;" % self.descriptor.concreteType)) "let this: *%s;" % self.descriptor.concreteType))
def generate_code(self): def generate_code(self):
assert(False) # Override me assert(False) # Override me
@ -2721,7 +2721,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.method = method self.method = method
name = method.identifier.name name = method.identifier.name
args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'), args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'),
Argument('*mut Box<%s>' % descriptor.concreteType, 'this'), Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args) CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
@ -2732,13 +2732,13 @@ class CGSpecializedMethod(CGAbstractExternMethod):
argsPre = [] argsPre = []
if name in self.descriptor.needsAbstract: if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = ' let mut abstract_this = %s::from_box(this);\n' % abstractName extraPre = ' let mut abstract_this = %s::from_raw(this);\n' % abstractName
argsPre = ['&mut abstract_this'] argsPre = ['&mut abstract_this']
return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(),
self.descriptor, self.method), self.descriptor, self.method),
pre=extraPre + pre=extraPre +
" let obj = (*obj.unnamed);\n" + " let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).data;\n").define() " let this = &mut *this;\n").define()
class CGGenericGetter(CGAbstractBindingMethod): class CGGenericGetter(CGAbstractBindingMethod):
""" """
@ -2776,7 +2776,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
name = 'get_' + attr.identifier.name name = 'get_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'), args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'), Argument('JSHandleObject', 'obj'),
Argument('*mut Box<%s>' % descriptor.concreteType, 'this'), Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'vp') ] Argument('*mut JSVal', 'vp') ]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@ -2790,7 +2790,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
getter=True)) getter=True))
if name in self.descriptor.needsAbstract: if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = ' let mut abstract_this = %s::from_box(this);\n' % abstractName extraPre = ' let mut abstract_this = %s::from_raw(this);\n' % abstractName
argsPre = ['&mut abstract_this'] argsPre = ['&mut abstract_this']
if self.attr.type.nullable() or not infallible: if self.attr.type.nullable() or not infallible:
nativeName = "Get" + nativeName nativeName = "Get" + nativeName
@ -2798,7 +2798,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
self.descriptor, self.attr)), self.descriptor, self.attr)),
pre=extraPre + pre=extraPre +
" let obj = (*obj.unnamed);\n" + " let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).data;\n").define() " let this = &mut *this;\n").define()
class CGGenericSetter(CGAbstractBindingMethod): class CGGenericSetter(CGAbstractBindingMethod):
""" """
@ -2842,7 +2842,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
name = 'set_' + attr.identifier.name name = 'set_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'), args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'), Argument('JSHandleObject', 'obj'),
Argument('*mut Box<%s>' % descriptor.concreteType, 'this'), Argument('*mut %s' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'argv')] Argument('*mut JSVal', 'argv')]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@ -2853,13 +2853,13 @@ class CGSpecializedSetter(CGAbstractExternMethod):
extraPre = '' extraPre = ''
if name in self.descriptor.needsAbstract: if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = ' let mut abstract_this = %s::from_box(this);\n' % abstractName extraPre = ' let mut abstract_this = %s::from_raw(this);\n' % abstractName
argsPre = ['&mut abstract_this'] argsPre = ['&mut abstract_this']
return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName,
self.descriptor, self.attr)), self.descriptor, self.attr)),
pre=extraPre + pre=extraPre +
" let obj = (*obj.unnamed);\n" + " let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).data;\n").define() " let this = &mut *this;\n").define()
def infallibleForMember(member, type, descriptorProvider): def infallibleForMember(member, type, descriptorProvider):
""" """
@ -3891,8 +3891,8 @@ class CGProxyUnwrap(CGAbstractMethod):
obj = js::UnwrapObject(obj); obj = js::UnwrapObject(obj);
}*/ }*/
//MOZ_ASSERT(IsProxy(obj)); //MOZ_ASSERT(IsProxy(obj));
let box_: *Box<%s> = cast::transmute(GetProxyPrivate(obj).to_private()); let box_: *%s = cast::transmute(GetProxyPrivate(obj).to_private());
return cast::transmute(&(*box_).data);""" % (self.descriptor.concreteType) return cast::transmute(&*box_);""" % (self.descriptor.concreteType)
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
def __init__(self, descriptor): def __init__(self, descriptor):
@ -4201,7 +4201,7 @@ class CGAbstractClassHook(CGAbstractExternMethod):
def definition_body_prologue(self): def definition_body_prologue(self):
return """ return """
let this: *%s = &(*unwrap::<*Box<%s>>(obj)).data; let this: *%s = &*unwrap::<*%s>(obj);
""" % (self.descriptor.concreteType, self.descriptor.concreteType) """ % (self.descriptor.concreteType, self.descriptor.concreteType)
def definition_body(self): def definition_body(self):
@ -4796,7 +4796,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::utils::{NativePropertyHooks}', 'dom::bindings::utils::{NativePropertyHooks}',
'dom::bindings::utils::global_object_for_js_object', 'dom::bindings::utils::global_object_for_js_object',
'dom::bindings::utils::{Reflectable}', 'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}', 'dom::bindings::utils::{squirrel_away_unboxed}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}', 'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}', 'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}',
'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}', 'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}',
@ -4825,7 +4825,6 @@ class CGBindingRoot(CGThing):
'std::str', 'std::str',
'std::num', 'std::num',
'std::intrinsics::uninit', 'std::intrinsics::uninit',
'std::raw::Box',
]) ])
# Add the auto-generated comment. # Add the auto-generated comment.

View file

@ -9,7 +9,6 @@ use layout_interface::TrustedNodeAddress;
use std::cast; use std::cast;
use std::cell::RefCell; use std::cell::RefCell;
use std::raw::Box;
pub struct JS<T> { pub struct JS<T> {
priv ptr: RefCell<*mut T> priv ptr: RefCell<*mut T>
@ -50,13 +49,6 @@ impl<T: Reflectable> JS<T> {
} }
pub unsafe fn from_box(box_: *mut Box<T>) -> JS<T> {
let raw: *mut T = &mut (*box_).data;
JS {
ptr: RefCell::new(raw)
}
}
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<T> { pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<T> {
JS { JS {
ptr: RefCell::new(inner as *mut T) ptr: RefCell::new(inner as *mut T)

View file

@ -17,7 +17,6 @@ use std::ptr;
use std::ptr::null; use std::ptr::null;
use std::str; use std::str;
use std::vec; use std::vec;
use std::raw::Box;
use js::glue::*; use js::glue::*;
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily}; use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction}; use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction};
@ -121,10 +120,10 @@ pub fn unwrap_object<T>(obj: *JSObject, proto_id: PrototypeList::id::ID, proto_d
pub fn unwrap_jsmanaged<T: Reflectable>(obj: *JSObject, pub fn unwrap_jsmanaged<T: Reflectable>(obj: *JSObject,
proto_id: PrototypeList::id::ID, proto_id: PrototypeList::id::ID,
proto_depth: uint) -> Result<JS<T>, ()> { proto_depth: uint) -> Result<JS<T>, ()> {
let result: Result<*mut Box<T>, ()> = unwrap_object(obj, proto_id, proto_depth); let result: Result<*mut T, ()> = unwrap_object(obj, proto_id, proto_depth);
result.map(|unwrapped| { result.map(|unwrapped| {
unsafe { unsafe {
JS::from_box(unwrapped) JS::from_raw(unwrapped)
} }
}) })
} }
@ -136,10 +135,6 @@ pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth
} }
} }
pub unsafe fn squirrel_away_unique<T>(x: ~T) -> *Box<T> {
cast::transmute(x)
}
pub unsafe fn squirrel_away_unboxed<T>(x: ~T) -> *T { pub unsafe fn squirrel_away_unboxed<T>(x: ~T) -> *T {
cast::transmute(x) cast::transmute(x)
} }
@ -437,7 +432,6 @@ pub fn reflect_dom_object<T: Reflectable>
#[deriving(Eq)] #[deriving(Eq)]
pub struct Reflector { pub struct Reflector {
object: *JSObject, object: *JSObject,
force_box_layout: @int,
} }
impl Reflector { impl Reflector {
@ -455,7 +449,6 @@ impl Reflector {
pub fn new() -> Reflector { pub fn new() -> Reflector {
Reflector { Reflector {
object: ptr::null(), object: ptr::null(),
force_box_layout: @1,
} }
} }
} }
@ -651,8 +644,8 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
let clasp = JS_GetClass(global); let clasp = JS_GetClass(global);
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0); assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
// FIXME(jdm): Either don't hardcode or sanity assert prototype stuff. // FIXME(jdm): Either don't hardcode or sanity assert prototype stuff.
match unwrap_object::<*mut Box<window::Window>>(global, PrototypeList::id::Window, 1) { match unwrap_object::<*mut window::Window>(global, PrototypeList::id::Window, 1) {
Ok(win) => JS::from_box(win), Ok(win) => JS::from_raw(win),
Err(_) => fail!("found DOM global that doesn't unwrap to Window"), Err(_) => fail!("found DOM global that doesn't unwrap to Window"),
} }
} }

View file

@ -561,8 +561,8 @@ impl NodeHelpers for JS<Node> {
if object.is_null() { if object.is_null() {
fail!("Attempted to create a `JS<Node>` from an invalid pointer!") fail!("Attempted to create a `JS<Node>` from an invalid pointer!")
} }
let boxed_node: *mut Box<Node> = utils::unwrap(object); let boxed_node: *mut Node = utils::unwrap(object);
JS::from_box(boxed_node) JS::from_raw(boxed_node)
} }
} }

View file

@ -521,6 +521,7 @@ pub fn parse_html(page: &Page,
} }
} }
debug!("finished parsing");
css_chan.send(CSSTaskExit); css_chan.send(CSSTaskExit);
js_chan.send(JSTaskExit); js_chan.send(JSTaskExit);

View file

@ -655,7 +655,7 @@ impl ScriptTask {
let this_value = if timer_data.args.len() > 0 { let this_value = if timer_data.args.len() > 0 {
fail!("NYI") fail!("NYI")
} else { } else {
js_info.get().get_ref().js_compartment.borrow().global_obj.borrow().ptr js_info.get().get_ref().js_compartment.borrow().global_obj
}; };
// TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`. // TODO: Support extra arguments. This requires passing a `*JSVal` array as `argv`.
@ -880,7 +880,7 @@ impl ScriptTask {
let (cx, global_obj) = { let (cx, global_obj) = {
let js_info = page.js_info(); let js_info = page.js_info();
(js_info.get().get_ref().js_context.clone(), (js_info.get().get_ref().js_context.clone(),
js_info.get().get_ref().js_compartment.borrow().global_obj.clone()) js_info.get().get_ref().js_compartment.borrow().global_obj)
}; };
cx.borrow().evaluate_script(global_obj, cx.borrow().evaluate_script(global_obj,
file.data.clone(), file.data.clone(),

@ -1 +1 @@
Subproject commit ed44fea3c91cd664cde0ea672309ca460e32cc50 Subproject commit b6981797b0177de75fa003e8921912f7e42ead98