mirror of
https://github.com/servo/servo.git
synced 2025-10-16 08:20:22 +01:00
De-@mut the script crate.
This commit is contained in:
parent
021d32368d
commit
fa542e5de7
12 changed files with 396 additions and 250 deletions
|
@ -2578,7 +2578,8 @@ def CreateBindingJSObject(descriptor, parent=None):
|
|||
assert not descriptor.createGlobal
|
||||
handler = """
|
||||
let page = page_from_context(aCx);
|
||||
let handler = (*page).js_info.get_ref().dom_static.proxy_handlers.get(&(PrototypeList::id::%s as uint));
|
||||
let mut js_info = (*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,
|
||||
ptr::to_unsafe_ptr(&RUST_PRIVATE_TO_JSVAL(squirrel_away_unique(aObject) as *libc::c_void)),
|
||||
|
@ -2727,7 +2728,8 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
|||
idsToInit.append(props.variableName(False))
|
||||
if len(idsToInit) > 0:
|
||||
setup = CGList([CGGeneric("let page = page_from_context(aCx);"),
|
||||
CGList([CGGeneric("let %s_ids_mut = (*page).js_info.get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::%s as uint));" % (varname, self.descriptor.name)) for varname in idsToInit], '\n')], '\n')
|
||||
CGList([CGGeneric("let mut js_info = (*page).js_info();\n"
|
||||
"let %s_ids_mut = js_info.get().get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::%s as uint));" % (varname, self.descriptor.name)) for varname in idsToInit], '\n')], '\n')
|
||||
initIds = CGList(
|
||||
[CGGeneric("!InitIds(aCx, %s, *%s_ids_mut)" % (varname, varname)) for
|
||||
varname in idsToInit], ' ||\n')
|
||||
|
@ -2884,8 +2886,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
|||
a given interface.
|
||||
"""
|
||||
def __init__(self, descriptor):
|
||||
args = [Argument('*JSContext', 'aCx'), Argument('*JSObject', 'aReceiver'),
|
||||
Argument('*mut bool', 'aEnabled')]
|
||||
args = [Argument('&mut JSPageInfo', 'js_info')]
|
||||
CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface', 'bool', args, pub=True)
|
||||
|
||||
def declare(self):
|
||||
|
@ -2903,7 +2904,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
|||
else:
|
||||
getter = "GetConstructorObject"
|
||||
|
||||
body = "let page = page_from_context(aCx);"
|
||||
body = ""
|
||||
#XXXjdm This self.descriptor.concrete check shouldn't be necessary
|
||||
if not self.descriptor.concrete or self.descriptor.proxy:
|
||||
body += """ let traps = ProxyTraps {
|
||||
|
@ -2937,22 +2938,22 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
|||
getPrototypeOf: ptr::null(),
|
||||
trace: %s
|
||||
};
|
||||
(*page).js_info.get_mut_ref().dom_static.proxy_handlers.insert(PrototypeList::id::%s as uint,
|
||||
CreateProxyHandler(ptr::to_unsafe_ptr(&traps), ptr::to_unsafe_ptr(&Class) as *libc::c_void));
|
||||
js_info.dom_static.proxy_handlers.insert(PrototypeList::id::%s as uint,
|
||||
CreateProxyHandler(ptr::to_unsafe_ptr(&traps), ptr::to_unsafe_ptr(&Class) as *libc::c_void));
|
||||
|
||||
""" % (FINALIZE_HOOK_NAME,
|
||||
('Some(%s)' % TRACE_HOOK_NAME),
|
||||
self.descriptor.name)
|
||||
else:
|
||||
body += """ (*page).js_info.get_ref().dom_static.attribute_ids.insert(PrototypeList::id::%s as uint,
|
||||
body += """ js_info.dom_static.attribute_ids.insert(PrototypeList::id::%s as uint,
|
||||
vec::cast_to_mut(vec::from_slice(sAttributes_ids)));
|
||||
""" % self.descriptor.name
|
||||
body = "" #XXXjdm xray stuff isn't necessary yet
|
||||
|
||||
return (body + " let global: *JSObject = JS_GetGlobalForObject(aCx, aReceiver);\n" +
|
||||
"""
|
||||
*aEnabled = true;
|
||||
return %s(aCx, global, aReceiver).is_not_null();""" % (getter))
|
||||
return (body + """ let cx = js_info.js_context.borrow().ptr;
|
||||
let receiver = js_info.js_compartment.borrow().global_obj.borrow().ptr;
|
||||
let global: *JSObject = JS_GetGlobalForObject(cx, receiver);
|
||||
return %s(cx, global, receiver).is_not_null();""" % (getter))
|
||||
|
||||
def needCx(returnType, arguments, extendedAttributes, considerTypes):
|
||||
return (considerTypes and
|
||||
|
@ -4306,7 +4307,8 @@ class CGXrayHelper(CGAbstractExternMethod):
|
|||
methods = self.properties.methods
|
||||
if methods.hasNonChromeOnly() or methods.hasChromeOnly():
|
||||
methodArgs = "Some(zip_copies(%(methods)s, *method_ids))" % varNames
|
||||
setup += "let method_ids = (*page).js_info.get_ref().dom_static.method_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
|
||||
setup += "let mut js_info = (*page).js_info();\n" \
|
||||
"let method_ids = js_info.get().get_ref().dom_static.method_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
|
||||
else:
|
||||
methodArgs = "None"
|
||||
methodArgs = CGGeneric(methodArgs)
|
||||
|
@ -4314,7 +4316,8 @@ class CGXrayHelper(CGAbstractExternMethod):
|
|||
attrs = self.properties.attrs
|
||||
if attrs.hasNonChromeOnly() or attrs.hasChromeOnly():
|
||||
attrArgs = "Some(zip_copies(%(attrs)s, *attr_ids))" % varNames
|
||||
setup += "let attr_ids = (*page).js_info.get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
|
||||
setup += "let mut js_info = (*page).js_info();\n" \
|
||||
"let attr_ids = js_info.get().get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
|
||||
else:
|
||||
attrArgs = "None"
|
||||
attrArgs = CGGeneric(attrArgs)
|
||||
|
@ -4322,7 +4325,8 @@ class CGXrayHelper(CGAbstractExternMethod):
|
|||
consts = self.properties.consts
|
||||
if consts.hasNonChromeOnly() or consts.hasChromeOnly():
|
||||
constArgs = "Some(zip_copies(%(consts)s, *const_ids))" % varNames
|
||||
setup += "let const_ids = (*page).js_info.get_ref().dom_static.constant_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
|
||||
setup += "let mut js_info = (*page).js_info();\n" \
|
||||
"let const_ids = js_info.get().get_ref().dom_static.constant_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
|
||||
else:
|
||||
constArgs = "None"
|
||||
constArgs = CGGeneric(constArgs)
|
||||
|
@ -4815,7 +4819,8 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
|||
// or through unwrapping a slot or something). We'll punt and get the Window
|
||||
// from the context for now.
|
||||
let page = page_from_context(cx);
|
||||
let global = (*page).frame.get_ref().window.clone();
|
||||
let frame = (*page).frame();
|
||||
let global = frame.get().get_ref().window.clone();
|
||||
let obj = global.reflector().get_jsobject();
|
||||
"""
|
||||
nativeName = MakeNativeName(self._ctor.identifier.name)
|
||||
|
@ -5241,21 +5246,18 @@ class CGDictionary(CGThing):
|
|||
class CGRegisterProtos(CGAbstractMethod):
|
||||
def __init__(self, config):
|
||||
CGAbstractMethod.__init__(self, None, 'Register', 'void',
|
||||
[Argument('@mut Compartment', 'compartment')],
|
||||
[Argument('&mut JSPageInfo', 'js_info')],
|
||||
unsafe=False, pub=True)
|
||||
self.config = config
|
||||
|
||||
def _registerProtos(self):
|
||||
lines = [" assert!(codegen::%sBinding::DefineDOMInterface(\n"
|
||||
" compartment.cx.ptr,\n"
|
||||
" compartment.global_obj.ptr,\n"
|
||||
" &mut unused));" % (desc.name)
|
||||
lines = [" assert!(codegen::%sBinding::DefineDOMInterface(js_info));" % (desc.name)
|
||||
for desc in self.config.getDescriptors(hasInterfaceObject=True,
|
||||
isExternal=False,
|
||||
register=True)]
|
||||
return '\n'.join(lines) + '\n'
|
||||
def definition_body(self):
|
||||
return " let mut unused = false;\n" + self._registerProtos()
|
||||
return self._registerProtos()
|
||||
|
||||
class CGBindingRoot(CGThing):
|
||||
"""
|
||||
|
@ -6322,7 +6324,7 @@ class GlobalGenRoots():
|
|||
for desc in config.getDescriptors(hasInterfaceObject=True,
|
||||
register=True)]
|
||||
curr = CGImports([], [], ['dom::bindings::codegen',
|
||||
'js::rust::Compartment'], defineIncludes, curr)
|
||||
'script_task::JSPageInfo'], defineIncludes, curr)
|
||||
|
||||
# Done.
|
||||
return curr
|
||||
|
|
|
@ -193,11 +193,11 @@ pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth
|
|||
}
|
||||
}
|
||||
|
||||
pub unsafe fn squirrel_away<T>(x: @mut T) -> *Box<T> {
|
||||
pub unsafe fn squirrel_away_unique<T>(x: ~T) -> *Box<T> {
|
||||
cast::transmute(x)
|
||||
}
|
||||
|
||||
pub unsafe fn squirrel_away_unique<T>(x: ~T) -> *Box<T> {
|
||||
pub unsafe fn squirrel_away_unboxed<T>(x: ~T) -> *T {
|
||||
cast::transmute(x)
|
||||
}
|
||||
|
||||
|
@ -556,14 +556,12 @@ pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: c_uint, _vp: *mut JSVa
|
|||
}
|
||||
|
||||
pub fn initialize_global(global: *JSObject) {
|
||||
let protoArray = @mut ([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]);
|
||||
let protoArray = ~([0 as *JSObject, ..PrototypeList::id::_ID_Count as uint]);
|
||||
unsafe {
|
||||
//XXXjdm we should be storing the box pointer instead of the inner
|
||||
let box_ = squirrel_away(protoArray);
|
||||
let inner = ptr::to_unsafe_ptr(&(*box_).data);
|
||||
let box_ = squirrel_away_unboxed(protoArray);
|
||||
JS_SetReservedSlot(global,
|
||||
DOM_PROTOTYPE_SLOT,
|
||||
RUST_PRIVATE_TO_JSVAL(inner as *libc::c_void));
|
||||
RUST_PRIVATE_TO_JSVAL(box_ as *libc::c_void));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -817,8 +815,9 @@ fn global_object_for_js_object(obj: *JSObject) -> *Box<window::Window> {
|
|||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||
unsafe {
|
||||
let win = global_object_for_js_object(obj);
|
||||
match (*win).data.page.js_info {
|
||||
Some(ref info) => info.js_context.ptr,
|
||||
let js_info = (*win).data.page().js_info();
|
||||
match *js_info.get() {
|
||||
Some(ref info) => info.js_context.borrow().ptr,
|
||||
None => fail!("no JS context for DOM global")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -532,7 +532,7 @@ impl Element {
|
|||
let (port, chan) = Chan::new();
|
||||
let addr = node.to_trusted_node_address();
|
||||
let rects =
|
||||
match win.get().page.query_layout(ContentBoxesQuery(addr, chan), port) {
|
||||
match win.get().page().query_layout(ContentBoxesQuery(addr, chan), port) {
|
||||
ContentBoxesResponse(rects) => {
|
||||
rects.map(|r| {
|
||||
ClientRect::new(
|
||||
|
@ -555,7 +555,7 @@ impl Element {
|
|||
let node: JS<Node> = NodeCast::from(abstract_self);
|
||||
let (port, chan) = Chan::new();
|
||||
let addr = node.to_trusted_node_address();
|
||||
match win.get().page.query_layout(ContentBoxQuery(addr, chan), port) {
|
||||
match win.get().page().query_layout(ContentBoxQuery(addr, chan), port) {
|
||||
ContentBoxResponse(rect) => {
|
||||
ClientRect::new(
|
||||
win,
|
||||
|
|
|
@ -147,7 +147,7 @@ impl HTMLImageElement {
|
|||
pub fn Width(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
|
||||
let node: JS<Node> = NodeCast::from(abstract_self);
|
||||
let doc = node.get().owner_doc();
|
||||
let page = doc.get().window.get().page;
|
||||
let page = doc.get().window.get().page();
|
||||
let (port, chan) = Chan::new();
|
||||
let addr = node.to_trusted_node_address();
|
||||
match page.query_layout(ContentBoxQuery(addr, chan), port) {
|
||||
|
@ -167,7 +167,7 @@ impl HTMLImageElement {
|
|||
pub fn Height(&self, abstract_self: &JS<HTMLImageElement>) -> u32 {
|
||||
let node = &self.htmlelement.element.node;
|
||||
let doc = node.owner_doc();
|
||||
let page = doc.get().window.get().page;
|
||||
let page = doc.get().window.get().page();
|
||||
let (port, chan) = Chan::new();
|
||||
let this_node: JS<Node> = NodeCast::from(abstract_self);
|
||||
let addr = this_node.to_trusted_node_address();
|
||||
|
|
|
@ -10,22 +10,38 @@ use dom::window::Window;
|
|||
use servo_util::str::DOMString;
|
||||
|
||||
use script_task::{Page};
|
||||
use std::rc::Rc;
|
||||
|
||||
use extra::serialize::{Encoder, Encodable};
|
||||
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct Location {
|
||||
reflector_: Reflector, //XXXjdm cycle: window->Location->window
|
||||
page: @mut Page,
|
||||
extra: Untraceable,
|
||||
}
|
||||
|
||||
struct Untraceable {
|
||||
page: Rc<Page>,
|
||||
}
|
||||
|
||||
impl<S: Encoder> Encodable<S> for Untraceable {
|
||||
fn encode(&self, s: &mut S) {
|
||||
self.page.borrow().encode(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl Location {
|
||||
pub fn new_inherited(page: @mut Page) -> Location {
|
||||
pub fn new_inherited(page: Rc<Page>) -> Location {
|
||||
Location {
|
||||
reflector_: Reflector::new(),
|
||||
page: page
|
||||
extra: Untraceable {
|
||||
page: page
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &Window, page: @mut Page) -> JS<Location> {
|
||||
pub fn new(window: &Window, page: Rc<Page>) -> JS<Location> {
|
||||
reflect_dom_object(~Location::new_inherited(page),
|
||||
window,
|
||||
LocationBinding::Wrap)
|
||||
|
@ -44,7 +60,7 @@ impl Location {
|
|||
}
|
||||
|
||||
pub fn Href(&self) -> DOMString {
|
||||
self.page.get_url().to_str()
|
||||
self.extra.page.borrow().get_url().to_str()
|
||||
}
|
||||
|
||||
pub fn SetHref(&self, _href: DOMString) -> Fallible<()> {
|
||||
|
|
|
@ -30,6 +30,7 @@ use std::hashmap::HashSet;
|
|||
use std::io::timer::Timer;
|
||||
use std::num;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use std::to_bytes::Cb;
|
||||
|
||||
use extra::serialize::{Encoder, Encodable};
|
||||
|
@ -72,9 +73,7 @@ impl TimerHandle {
|
|||
#[deriving(Encodable)]
|
||||
pub struct Window {
|
||||
eventtarget: EventTarget,
|
||||
page: @mut Page,
|
||||
script_chan: ScriptChan,
|
||||
compositor: @ScriptListener,
|
||||
console: Option<JS<Console>>,
|
||||
location: Option<JS<Location>>,
|
||||
navigator: Option<JS<Navigator>>,
|
||||
|
@ -85,20 +84,30 @@ pub struct Window {
|
|||
}
|
||||
|
||||
struct Untraceable {
|
||||
page: Rc<Page>,
|
||||
compositor: ~ScriptListener,
|
||||
timer_chan: SharedChan<TimerControlMsg>,
|
||||
}
|
||||
|
||||
impl<S: Encoder> Encodable<S> for Untraceable {
|
||||
fn encode(&self, _: &mut S) {
|
||||
fn encode(&self, s: &mut S) {
|
||||
let page = self.page.borrow();
|
||||
page.encode(s);
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn get_cx(&self) -> *JSObject {
|
||||
self.page.js_info.get_ref().js_compartment.cx.ptr
|
||||
let js_info = self.page().js_info();
|
||||
(*js_info.get()).get_ref().js_compartment.borrow().cx.borrow().ptr
|
||||
}
|
||||
|
||||
pub fn page<'a>(&'a self) -> &'a Page {
|
||||
let page = &self.extra.page;
|
||||
page.borrow()
|
||||
}
|
||||
pub fn get_url(&self) -> Url {
|
||||
self.page.get_url()
|
||||
self.page().get_url()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +141,8 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn Document(&self) -> JS<Document> {
|
||||
self.page.frame.get_ref().document.clone()
|
||||
let frame = self.page().frame();
|
||||
(*frame.get()).get_ref().document.clone()
|
||||
}
|
||||
|
||||
pub fn Name(&self) -> DOMString {
|
||||
|
@ -168,7 +178,7 @@ impl Window {
|
|||
|
||||
pub fn Location(&mut self) -> JS<Location> {
|
||||
if self.location.is_none() {
|
||||
self.location = Some(Location::new(self, self.page));
|
||||
self.location = Some(Location::new(self, self.extra.page.clone()));
|
||||
}
|
||||
self.location.get_ref().clone()
|
||||
}
|
||||
|
@ -255,32 +265,32 @@ impl Window {
|
|||
// FIXME This should probably be ReflowForQuery, not Display. All queries currently
|
||||
// currently rely on the display list, which means we can't destroy it by
|
||||
// doing a query reflow.
|
||||
self.page.damage(damage);
|
||||
self.page.reflow(ReflowForDisplay, self.script_chan.clone(), self.compositor);
|
||||
self.page().damage(damage);
|
||||
self.page().reflow(ReflowForDisplay, self.script_chan.clone(), self.extra.compositor);
|
||||
}
|
||||
|
||||
pub fn wait_until_safe_to_modify_dom(&self) {
|
||||
// FIXME: This disables concurrent layout while we are modifying the DOM, since
|
||||
// our current architecture is entirely unsafe in the presence of races.
|
||||
self.page.join_layout();
|
||||
self.page().join_layout();
|
||||
}
|
||||
|
||||
pub fn new(cx: *JSContext,
|
||||
page: @mut Page,
|
||||
page: Rc<Page>,
|
||||
script_chan: ScriptChan,
|
||||
compositor: @ScriptListener,
|
||||
compositor: ~ScriptListener,
|
||||
image_cache_task: ImageCacheTask)
|
||||
-> JS<Window> {
|
||||
let mut win = ~Window {
|
||||
eventtarget: EventTarget::new_inherited(WindowTypeId),
|
||||
page: page,
|
||||
script_chan: script_chan.clone(),
|
||||
compositor: compositor,
|
||||
console: None,
|
||||
extra: Untraceable {
|
||||
compositor: compositor,
|
||||
page: page.clone(),
|
||||
timer_chan: {
|
||||
let (timer_port, timer_chan): (Port<TimerControlMsg>, SharedChan<TimerControlMsg>) = SharedChan::new();
|
||||
let id = page.id.clone();
|
||||
let id = page.borrow().id.clone();
|
||||
spawn_named("timer controller", proc() {
|
||||
loop {
|
||||
match timer_port.recv() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue