mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Remove all traces of Box representation from bindings. Work around file read runtime problem.
This commit is contained in:
parent
bbac8aa5c3
commit
f279abbf9f
8 changed files with 31 additions and 45 deletions
|
@ -13,8 +13,9 @@ static READ_SIZE: uint = 1024;
|
|||
fn read_all(reader: &mut io::Stream, progress_chan: &Chan<ProgressMsg>)
|
||||
-> Result<(), ()> {
|
||||
loop {
|
||||
match (reader.read_bytes(READ_SIZE)) {
|
||||
Ok(data) => progress_chan.send(Payload(data)),
|
||||
let mut buf = ~[];
|
||||
match (reader.push_bytes(&mut buf, READ_SIZE)) {
|
||||
Ok(_) => progress_chan.send(Payload(buf)),
|
||||
Err(e) => match e.kind {
|
||||
io::EndOfFile => return Ok(()),
|
||||
_ => return Err(()),
|
||||
|
|
|
@ -389,7 +389,7 @@ class CGMethodCall(CGThing):
|
|||
class FakeCastableDescriptor():
|
||||
def __init__(self, descriptor):
|
||||
self.castable = True
|
||||
self.nativeType = "*Box<%s>" % descriptor.concreteType
|
||||
self.nativeType = "*%s" % descriptor.concreteType
|
||||
self.name = descriptor.name
|
||||
class FakeInterface:
|
||||
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));
|
||||
""" % descriptor.name
|
||||
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,
|
||||
ptr::null(), ptr::null());
|
||||
if obj.is_null() {
|
||||
|
@ -2084,7 +2084,7 @@ def CreateBindingJSObject(descriptor, parent=None):
|
|||
}
|
||||
|
||||
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
|
||||
|
||||
|
@ -2388,7 +2388,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
|||
body = "" #XXXjdm xray stuff isn't necessary yet
|
||||
|
||||
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);
|
||||
return %s(cx, global, receiver).is_not_null();""" % (getter))
|
||||
|
||||
|
@ -2693,7 +2693,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
|
|||
" return false as JSBool;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"let this: *Box<%s>;" % self.descriptor.concreteType))
|
||||
"let this: *%s;" % self.descriptor.concreteType))
|
||||
|
||||
def generate_code(self):
|
||||
assert(False) # Override me
|
||||
|
@ -2721,7 +2721,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
|
|||
self.method = method
|
||||
name = method.identifier.name
|
||||
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')]
|
||||
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
|
||||
|
||||
|
@ -2732,13 +2732,13 @@ class CGSpecializedMethod(CGAbstractExternMethod):
|
|||
argsPre = []
|
||||
if name in self.descriptor.needsAbstract:
|
||||
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']
|
||||
return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(),
|
||||
self.descriptor, self.method),
|
||||
pre=extraPre +
|
||||
" let obj = (*obj.unnamed);\n" +
|
||||
" let this = &mut (*this).data;\n").define()
|
||||
" let this = &mut *this;\n").define()
|
||||
|
||||
class CGGenericGetter(CGAbstractBindingMethod):
|
||||
"""
|
||||
|
@ -2776,7 +2776,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
|||
name = 'get_' + attr.identifier.name
|
||||
args = [ Argument('*JSContext', 'cx'),
|
||||
Argument('JSHandleObject', 'obj'),
|
||||
Argument('*mut Box<%s>' % descriptor.concreteType, 'this'),
|
||||
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
||||
Argument('*mut JSVal', 'vp') ]
|
||||
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
|
||||
|
||||
|
@ -2790,7 +2790,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
|||
getter=True))
|
||||
if name in self.descriptor.needsAbstract:
|
||||
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']
|
||||
if self.attr.type.nullable() or not infallible:
|
||||
nativeName = "Get" + nativeName
|
||||
|
@ -2798,7 +2798,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
|||
self.descriptor, self.attr)),
|
||||
pre=extraPre +
|
||||
" let obj = (*obj.unnamed);\n" +
|
||||
" let this = &mut (*this).data;\n").define()
|
||||
" let this = &mut *this;\n").define()
|
||||
|
||||
class CGGenericSetter(CGAbstractBindingMethod):
|
||||
"""
|
||||
|
@ -2842,7 +2842,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
|||
name = 'set_' + attr.identifier.name
|
||||
args = [ Argument('*JSContext', 'cx'),
|
||||
Argument('JSHandleObject', 'obj'),
|
||||
Argument('*mut Box<%s>' % descriptor.concreteType, 'this'),
|
||||
Argument('*mut %s' % descriptor.concreteType, 'this'),
|
||||
Argument('*mut JSVal', 'argv')]
|
||||
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
|
||||
|
||||
|
@ -2853,13 +2853,13 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
|||
extraPre = ''
|
||||
if name in self.descriptor.needsAbstract:
|
||||
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']
|
||||
return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName,
|
||||
self.descriptor, self.attr)),
|
||||
pre=extraPre +
|
||||
" let obj = (*obj.unnamed);\n" +
|
||||
" let this = &mut (*this).data;\n").define()
|
||||
" let this = &mut *this;\n").define()
|
||||
|
||||
def infallibleForMember(member, type, descriptorProvider):
|
||||
"""
|
||||
|
@ -3891,8 +3891,8 @@ class CGProxyUnwrap(CGAbstractMethod):
|
|||
obj = js::UnwrapObject(obj);
|
||||
}*/
|
||||
//MOZ_ASSERT(IsProxy(obj));
|
||||
let box_: *Box<%s> = cast::transmute(GetProxyPrivate(obj).to_private());
|
||||
return cast::transmute(&(*box_).data);""" % (self.descriptor.concreteType)
|
||||
let box_: *%s = cast::transmute(GetProxyPrivate(obj).to_private());
|
||||
return cast::transmute(&*box_);""" % (self.descriptor.concreteType)
|
||||
|
||||
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||
def __init__(self, descriptor):
|
||||
|
@ -4201,7 +4201,7 @@ class CGAbstractClassHook(CGAbstractExternMethod):
|
|||
|
||||
def definition_body_prologue(self):
|
||||
return """
|
||||
let this: *%s = &(*unwrap::<*Box<%s>>(obj)).data;
|
||||
let this: *%s = &*unwrap::<*%s>(obj);
|
||||
""" % (self.descriptor.concreteType, self.descriptor.concreteType)
|
||||
|
||||
def definition_body(self):
|
||||
|
@ -4796,7 +4796,7 @@ class CGBindingRoot(CGThing):
|
|||
'dom::bindings::utils::{NativePropertyHooks}',
|
||||
'dom::bindings::utils::global_object_for_js_object',
|
||||
'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::{unwrap_object, VoidVal, with_gc_disabled}',
|
||||
'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}',
|
||||
|
@ -4825,7 +4825,6 @@ class CGBindingRoot(CGThing):
|
|||
'std::str',
|
||||
'std::num',
|
||||
'std::intrinsics::uninit',
|
||||
'std::raw::Box',
|
||||
])
|
||||
|
||||
# Add the auto-generated comment.
|
||||
|
|
|
@ -9,7 +9,6 @@ use layout_interface::TrustedNodeAddress;
|
|||
|
||||
use std::cast;
|
||||
use std::cell::RefCell;
|
||||
use std::raw::Box;
|
||||
|
||||
pub struct JS<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> {
|
||||
JS {
|
||||
ptr: RefCell::new(inner as *mut T)
|
||||
|
|
|
@ -17,7 +17,6 @@ use std::ptr;
|
|||
use std::ptr::null;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
use std::raw::Box;
|
||||
use js::glue::*;
|
||||
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
|
||||
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,
|
||||
proto_id: PrototypeList::id::ID,
|
||||
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| {
|
||||
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 {
|
||||
cast::transmute(x)
|
||||
}
|
||||
|
@ -437,7 +432,6 @@ pub fn reflect_dom_object<T: Reflectable>
|
|||
#[deriving(Eq)]
|
||||
pub struct Reflector {
|
||||
object: *JSObject,
|
||||
force_box_layout: @int,
|
||||
}
|
||||
|
||||
impl Reflector {
|
||||
|
@ -455,7 +449,6 @@ impl Reflector {
|
|||
pub fn new() -> Reflector {
|
||||
Reflector {
|
||||
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);
|
||||
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
|
||||
// FIXME(jdm): Either don't hardcode or sanity assert prototype stuff.
|
||||
match unwrap_object::<*mut Box<window::Window>>(global, PrototypeList::id::Window, 1) {
|
||||
Ok(win) => JS::from_box(win),
|
||||
match unwrap_object::<*mut window::Window>(global, PrototypeList::id::Window, 1) {
|
||||
Ok(win) => JS::from_raw(win),
|
||||
Err(_) => fail!("found DOM global that doesn't unwrap to Window"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -561,8 +561,8 @@ impl NodeHelpers for JS<Node> {
|
|||
if object.is_null() {
|
||||
fail!("Attempted to create a `JS<Node>` from an invalid pointer!")
|
||||
}
|
||||
let boxed_node: *mut Box<Node> = utils::unwrap(object);
|
||||
JS::from_box(boxed_node)
|
||||
let boxed_node: *mut Node = utils::unwrap(object);
|
||||
JS::from_raw(boxed_node)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -521,6 +521,7 @@ pub fn parse_html(page: &Page,
|
|||
}
|
||||
}
|
||||
|
||||
debug!("finished parsing");
|
||||
css_chan.send(CSSTaskExit);
|
||||
js_chan.send(JSTaskExit);
|
||||
|
||||
|
|
|
@ -655,7 +655,7 @@ impl ScriptTask {
|
|||
let this_value = if timer_data.args.len() > 0 {
|
||||
fail!("NYI")
|
||||
} 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`.
|
||||
|
@ -880,7 +880,7 @@ impl ScriptTask {
|
|||
let (cx, global_obj) = {
|
||||
let js_info = page.js_info();
|
||||
(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,
|
||||
file.data.clone(),
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ed44fea3c91cd664cde0ea672309ca460e32cc50
|
||||
Subproject commit b6981797b0177de75fa003e8921912f7e42ead98
|
Loading…
Add table
Add a link
Reference in a new issue