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

De-@mut the script crate. #1755

Merged
merged 1 commit into from Feb 28, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -60,6 +60,9 @@ impl ScriptListener for CompositorChan {
port.recv();
}

fn dup(&self) -> ~ScriptListener {
~self.clone() as ~ScriptListener
}
}

/// Implementation of the abstract `RenderListener` interface.
@@ -134,7 +134,7 @@ impl Pipeline {
};

ScriptTask::create(id,
compositor_chan.clone(),
~compositor_chan.clone(),
layout_chan.clone(),
script_port,
script_chan.clone(),
@@ -94,6 +94,7 @@ pub trait ScriptListener : Clone {
fn invalidate_rect(&self, PipelineId, Rect<uint>);
fn scroll_fragment_point(&self, PipelineId, Point2D<f32>);
fn close(&self);
fn dup(&self) -> ~ScriptListener;
}

impl<S: Encoder> Encodable<S> for @ScriptListener {
@@ -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 @@ def definition_body(self):
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 @@ def definition_body(self):
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 @@ def definition_body(self):
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,23 +4307,26 @@ def definition_body(self):
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)

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)

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 @@ def generate_code(self):
// 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 @@ def getDictionaryDependencies(dictionary):
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 @@ def RegisterBindings(config):
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<()> {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.