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

Refactor the script task to conform to current coding style #457

Merged
merged 1 commit into from May 16, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -12,8 +12,8 @@ use scripting::script_task::{task_from_context, global_script_context};
pub impl ClientRect {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.compartment.get().cx.ptr;
let owner = script_context.window.get();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
@@ -37,7 +37,7 @@ impl BindingObject for ClientRect {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).window.get() as @mut CacheableWrapper
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
@@ -11,8 +11,8 @@ use scripting::script_task::{task_from_context, global_script_context};
pub impl ClientRectList {
fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.compartment.get().cx.ptr;
let owner = script_context.window.get();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
@@ -21,7 +21,9 @@ pub impl ClientRectList {

impl CacheableWrapper for ClientRectList {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
unsafe {
cast::transmute(&self.wrapper)
}
}

fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
@@ -33,6 +35,8 @@ impl CacheableWrapper for ClientRectList {
impl BindingObject for ClientRectList {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe { (*script_context).window.get() as @mut CacheableWrapper }
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
@@ -3615,7 +3615,7 @@ def generate_code(self):
// or through unwrapping a slot or something). We'll punt and get the Window
// from the context for now.
let script_context = task_from_context(cx);
let global = (*script_context).window.get();
let global = (*script_context).root_frame.get_ref().window;
let obj = global.get_wrappercache().get_wrapper();
"""
preArgs = ["global"]
@@ -146,6 +146,9 @@ impl CacheableWrapper for Document {

fn wrap_object_shared(@mut self, cx: *JSContext, _scope: *JSObject) -> *JSObject {
let script_context = task_from_context(cx);
unsafe { create((*script_context).compartment.get(), self) }
unsafe {
create((*script_context).js_compartment, self)
}
}
}

@@ -12,8 +12,8 @@ use scripting::script_task::{task_from_context, global_script_context};
pub impl Event_ {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.compartment.get().cx.ptr;
let owner = script_context.window.get();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
@@ -34,7 +34,9 @@ impl CacheableWrapper for Event_ {
impl BindingObject for Event_ {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe { (*script_context).window.get() as @mut CacheableWrapper }
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}

@@ -5,15 +5,16 @@
use dom::bindings::codegen::EventTargetBinding;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::eventtarget::EventTarget;

use js::glue::bindgen::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
use scripting::script_task::{task_from_context, global_script_context};

pub impl EventTarget {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.compartment.get().cx.ptr;
let owner = script_context.window.get();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
@@ -34,7 +35,9 @@ impl CacheableWrapper for EventTarget {
impl BindingObject for EventTarget {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe { (*script_context).window.get() as @mut CacheableWrapper }
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}

@@ -48,7 +51,9 @@ impl DerivedWrapper for EventTarget {
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
unsafe {
*vp = RUST_OBJECT_TO_JSVAL(obj)
};
return 1;
}
}
@@ -11,8 +11,8 @@ use scripting::script_task::{task_from_context, global_script_context};
pub impl HTMLCollection {
fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.compartment.get().cx.ptr;
let owner = script_context.window.get();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
@@ -22,13 +22,17 @@ pub impl HTMLCollection {
impl BindingObject for HTMLCollection {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe { (*script_context).window.get() as @mut CacheableWrapper }
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}

impl CacheableWrapper for HTMLCollection {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
unsafe {
cast::transmute(&self.wrapper)
}
}

fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
@@ -164,8 +164,7 @@ pub unsafe fn domstring_to_jsval(cx: *JSContext, string: &DOMString) -> JSVal {
pub fn get_compartment(cx: *JSContext) -> @mut Compartment {
unsafe {
let script_context = task_from_context(cx);
let compartment = (*script_context).compartment.expect(~"Should always have compartment \
when executing JS code");
let compartment = (*script_context).js_compartment;
assert!(cx == compartment.cx.ptr);
compartment
}
@@ -25,7 +25,7 @@ pub fn Document(root: AbstractNode, window: Option<@mut Window>) -> @mut Documen
wrapper: WrapperCache::new(),
window: window
};
let compartment = global_script_context().compartment.get();
let compartment = global_script_context().js_compartment;
do root.with_base |base| {
assert!(base.wrapper.get_wrapper().is_not_null());
let rootable = base.wrapper.get_rootable();
@@ -38,7 +38,7 @@ pub fn Document(root: AbstractNode, window: Option<@mut Window>) -> @mut Documen
#[unsafe_destructor]
impl Drop for Document {
fn finalize(&self) {
let compartment = global_script_context().compartment.get();
let compartment = global_script_context().js_compartment;
do self.root.with_base |base| {
assert!(base.wrapper.get_wrapper().is_not_null());
let rootable = base.wrapper.get_rootable();
@@ -22,7 +22,7 @@ impl DOMParser {
wrapper: WrapperCache::new()
};

let cx = global_script_context().compartment.get().cx.ptr;
let cx = global_script_context().js_compartment.cx.ptr;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
parser.wrap_object_shared(cx, scope);
@@ -391,7 +391,7 @@ impl Node {
let mut node = AbstractNode {
obj: transmute(node),
};
let cx = global_script_context().compartment.get().cx.ptr;
let cx = global_script_context().js_compartment.cx.ptr;
node::create(cx, &mut node);
node
}
@@ -2,14 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use scripting::script_task::{ControlMsg, ExitMsg, ScriptContext, Timer, global_script_context};
use dom::bindings::utils::WrapperCache;
use dom::bindings::window;
use dom::event::Event;
use js::jsapi::JSVal;
use scripting::script_task::{ControlMsg, ExitMsg, FireTimerMsg, ScriptContext};
use scripting::script_task::{global_script_context};
use util::task::spawn_listener;

use core::comm::{Port, Chan, SharedChan};
use js::jsapi::JSVal;
use std::timer;
use std::uv_global_loop;

@@ -90,20 +91,21 @@ pub fn Window(script_chan: comm::SharedChan<ControlMsg>,
let win = @mut Window {
wrapper: WrapperCache::new(),
dom_event_chan: dom_event_chan,
timer_chan: do spawn_listener |timer_port: Port<TimerControlMsg>| {
loop {
match timer_port.recv() {
TimerMessage_Close => break,
TimerMessage_Fire(td) => {
script_chan.send(Timer(td));
timer_chan: {
do spawn_listener |timer_port: Port<TimerControlMsg>| {
loop {
match timer_port.recv() {
TimerMessage_Close => break,
TimerMessage_Fire(td) => script_chan.send(FireTimerMsg(td)),
TimerMessage_TriggerExit => script_chan.send(ExitMsg),
}
TimerMessage_TriggerExit => script_chan.send(ExitMsg)
}
}
},
script_context: script_context
script_context: script_context,
};
let compartment = global_script_context().compartment.get();

let compartment = global_script_context().js_compartment;
window::create(compartment, win);
win
}
@@ -6,7 +6,7 @@ use compositing::CompositorImpl;
use dom::event::Event;
use layout::layout_task::LayoutTask;
use layout::layout_task;
use scripting::script_task::{ExecuteMsg, ParseMsg, ScriptTask};
use scripting::script_task::{ExecuteMsg, LoadMsg, ScriptTask};
use scripting::script_task;
use util::task::spawn_listener;

@@ -55,11 +55,11 @@ impl Engine {
let opts = opts.take();
let layout_task = LayoutTask(render_task.clone(), image_cache_task.clone(), opts);

let script_task = ScriptTask(layout_task.clone(),
dom_event_port.take(),
dom_event_chan.take(),
resource_task.clone(),
image_cache_task.clone());
let script_task = ScriptTask::new(layout_task.clone(),
dom_event_port.take(),
dom_event_chan.take(),
resource_task.clone(),
image_cache_task.clone());

Engine {
request_port: request,
@@ -83,15 +83,15 @@ impl Engine {
match request {
LoadUrlMsg(url) => {
if url.path.ends_with(".js") {
self.script_task.send(ExecuteMsg(url))
self.script_task.chan.send(ExecuteMsg(url))
} else {
self.script_task.send(ParseMsg(url))
self.script_task.chan.send(LoadMsg(url))
}
return true
}

ExitMsg(sender) => {
self.script_task.send(script_task::ExitMsg);
self.script_task.chan.send(script_task::ExitMsg);
self.layout_task.send(layout_task::ExitMsg);

let (response_port, response_chan) = comm::stream();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.