Rename variables that refer to global objects.

This clarifies whether those variables will point to a Window object or an
arbitrary global object.

Note in particular that all IDL Constructors will accept an arbitrary global
object.
This commit is contained in:
Ms2ger 2014-07-15 12:09:21 +02:00
parent ab1a188e95
commit f963ed99ac
21 changed files with 95 additions and 92 deletions

View file

@ -114,8 +114,8 @@ pub struct CallSetup {
impl CallSetup {
pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup {
let win = global_object_for_js_object(callback.callback()).root();
let cx = win.deref().get_cx();
let global = global_object_for_js_object(callback.callback()).root();
let cx = global.deref().get_cx();
CallSetup {
cx: cx,
_handling: handling

View file

@ -373,10 +373,10 @@ pub trait Reflectable {
pub fn reflect_dom_object<T: Reflectable>
(obj: Box<T>,
window: &JSRef<window::Window>,
global: &JSRef<window::Window>,
wrap_fn: extern "Rust" fn(*mut JSContext, &JSRef<window::Window>, Box<T>) -> Temporary<T>)
-> Temporary<T> {
wrap_fn(window.get_cx(), window, obj)
wrap_fn(global.get_cx(), global, obj)
}
#[allow(raw_pointer_deriving)]

View file

@ -18,27 +18,27 @@ pub enum BlobType {
#[deriving(Encodable)]
pub struct Blob {
reflector_: Reflector,
window: JS<Window>,
global: JS<Window>,
type_: BlobType
}
impl Blob {
pub fn new_inherited(window: &JSRef<Window>) -> Blob {
pub fn new_inherited(global: &JSRef<Window>) -> Blob {
Blob {
reflector_: Reflector::new(),
window: JS::from_rooted(window),
global: JS::from_rooted(global),
type_: BlobTypeId
}
}
pub fn new(window: &JSRef<Window>) -> Temporary<Blob> {
reflect_dom_object(box Blob::new_inherited(window),
window,
pub fn new(global: &JSRef<Window>) -> Temporary<Blob> {
reflect_dom_object(box Blob::new_inherited(global),
global,
BlobBinding::Wrap)
}
pub fn Constructor(window: &JSRef<Window>) -> Fallible<Temporary<Blob>> {
Ok(Blob::new(window))
pub fn Constructor(global: &JSRef<Window>) -> Fallible<Temporary<Blob>> {
Ok(Blob::new(global))
}
}

View file

@ -38,8 +38,8 @@ impl Comment {
Node::reflect_node(box node, document, CommentBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>, data: DOMString) -> Fallible<Temporary<Comment>> {
let document = owner.Document().root();
pub fn Constructor(global: &JSRef<Window>, data: DOMString) -> Fallible<Temporary<Comment>> {
let document = global.Document().root();
Ok(Comment::new(data, &*document))
}
}

View file

@ -20,8 +20,8 @@ impl Console {
}
}
pub fn new(window: &JSRef<Window>) -> Temporary<Console> {
reflect_dom_object(box Console::new_inherited(), window, ConsoleBinding::Wrap)
pub fn new(global: &JSRef<Window>) -> Temporary<Console> {
reflect_dom_object(box Console::new_inherited(), global, ConsoleBinding::Wrap)
}
}

View file

@ -43,20 +43,20 @@ impl CustomEvent {
}
}
pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<CustomEvent> {
pub fn new_uninitialized(global: &JSRef<Window>) -> Temporary<CustomEvent> {
reflect_dom_object(box CustomEvent::new_inherited(CustomEventTypeId),
window,
global,
CustomEventBinding::Wrap)
}
pub fn new(window: &JSRef<Window>, type_: DOMString, bubbles: bool, cancelable: bool, detail: JSVal) -> Temporary<CustomEvent> {
let ev = CustomEvent::new_uninitialized(window).root();
ev.deref().InitCustomEvent(window.deref().get_cx(), type_, bubbles, cancelable, detail);
pub fn new(global: &JSRef<Window>, type_: DOMString, bubbles: bool, cancelable: bool, detail: JSVal) -> Temporary<CustomEvent> {
let ev = CustomEvent::new_uninitialized(global).root();
ev.deref().InitCustomEvent(global.get_cx(), type_, bubbles, cancelable, detail);
Temporary::from_rooted(&*ev)
}
pub fn Constructor(owner: &JSRef<Window>,
pub fn Constructor(global: &JSRef<Window>,
type_: DOMString,
init: &CustomEventBinding::CustomEventInit) -> Fallible<Temporary<CustomEvent>>{
Ok(CustomEvent::new(owner, type_, init.parent.bubbles, init.parent.cancelable, init.detail))
Ok(CustomEvent::new(global, type_, init.parent.bubbles, init.parent.cancelable, init.detail))
}
}

View file

@ -222,8 +222,8 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<Document>> {
Ok(Document::new(owner, None, NonHTMLDocument, None))
pub fn Constructor(global: &JSRef<Window>) -> Fallible<Temporary<Document>> {
Ok(Document::new(global, None, NonHTMLDocument, None))
}
pub fn new(window: &JSRef<Window>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>) -> Temporary<Document> {

View file

@ -40,8 +40,8 @@ impl DocumentFragment {
Node::reflect_node(box node, document, DocumentFragmentBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<DocumentFragment>> {
let document = owner.Document();
pub fn Constructor(global: &JSRef<Window>) -> Fallible<Temporary<DocumentFragment>> {
let document = global.Document();
let document = document.root();
Ok(DocumentFragment::new(&document.root_ref()))

View file

@ -72,12 +72,12 @@ impl DOMException {
}
}
pub fn new(window: &JSRef<Window>, code: DOMErrorName) -> Temporary<DOMException> {
reflect_dom_object(box DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap)
pub fn new(global: &JSRef<Window>, code: DOMErrorName) -> Temporary<DOMException> {
reflect_dom_object(box DOMException::new_inherited(code), global, DOMExceptionBinding::Wrap)
}
pub fn new_from_error(window: &JSRef<Window>, code: Error) -> Temporary<DOMException> {
DOMException::new(window, DOMErrorName::from_error(code))
pub fn new_from_error(global: &JSRef<Window>, code: Error) -> Temporary<DOMException> {
DOMException::new(global, DOMErrorName::from_error(code))
}
}

View file

@ -13,25 +13,25 @@ use servo_util::str::DOMString;
#[deriving(Encodable)]
pub struct DOMParser {
pub owner: JS<Window>, //XXXjdm Document instead?
pub window: JS<Window>, //XXXjdm Document instead?
pub reflector_: Reflector
}
impl DOMParser {
pub fn new_inherited(owner: &JSRef<Window>) -> DOMParser {
pub fn new_inherited(window: &JSRef<Window>) -> DOMParser {
DOMParser {
owner: JS::from_rooted(owner),
window: JS::from_rooted(window),
reflector_: Reflector::new()
}
}
pub fn new(owner: &JSRef<Window>) -> Temporary<DOMParser> {
reflect_dom_object(box DOMParser::new_inherited(owner), owner,
pub fn new(window: &JSRef<Window>) -> Temporary<DOMParser> {
reflect_dom_object(box DOMParser::new_inherited(window), window,
DOMParserBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<DOMParser>> {
Ok(DOMParser::new(owner))
pub fn Constructor(global: &JSRef<Window>) -> Fallible<Temporary<DOMParser>> {
Ok(DOMParser::new(global))
}
}
@ -45,13 +45,13 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
_s: DOMString,
ty: DOMParserBinding::SupportedType)
-> Fallible<Temporary<Document>> {
let owner = self.owner.root();
let window = self.window.root();
match ty {
Text_html => {
Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some("text/html".to_string())))
Ok(Document::new(&window.root_ref(), None, HTMLDocument, Some("text/html".to_string())))
}
Text_xml => {
Ok(Document::new(&owner.root_ref(), None, NonHTMLDocument, Some("text/xml".to_string())))
Ok(Document::new(&window.root_ref(), None, NonHTMLDocument, Some("text/xml".to_string())))
}
_ => {
Err(FailureUnknown)

View file

@ -85,17 +85,17 @@ impl Event {
}
}
pub fn new_uninitialized(window: &JSRef<Window>) -> Temporary<Event> {
pub fn new_uninitialized(global: &JSRef<Window>) -> Temporary<Event> {
reflect_dom_object(box Event::new_inherited(HTMLEventTypeId),
window,
global,
EventBinding::Wrap)
}
pub fn new(window: &JSRef<Window>,
pub fn new(global: &JSRef<Window>,
type_: DOMString,
can_bubble: bool,
cancelable: bool) -> Temporary<Event> {
let event = Event::new_uninitialized(window).root();
let event = Event::new_uninitialized(global).root();
event.deref().InitEvent(type_, can_bubble, cancelable);
Temporary::from_rooted(&*event)
}

View file

@ -17,9 +17,9 @@ pub struct File {
}
impl File {
pub fn new_inherited(window: &JSRef<Window>, _file_bits: &JSRef<Blob>, name: DOMString) -> File {
pub fn new_inherited(global: &JSRef<Window>, _file_bits: &JSRef<Blob>, name: DOMString) -> File {
File {
blob: Blob::new_inherited(window),
blob: Blob::new_inherited(global),
name: name,
type_: FileTypeId
}
@ -27,9 +27,9 @@ impl File {
// the relevant subfields of file_bits should be copied over
}
pub fn new(window: &JSRef<Window>, file_bits: &JSRef<Blob>, name: DOMString) -> Temporary<File> {
reflect_dom_object(box File::new_inherited(window, file_bits, name),
window,
pub fn new(global: &JSRef<Window>, file_bits: &JSRef<Blob>, name: DOMString) -> Temporary<File> {
reflect_dom_object(box File::new_inherited(global, file_bits, name),
global,
FileBinding::Wrap)
}
}

View file

@ -45,8 +45,8 @@ impl FormData {
reflect_dom_object(box FormData::new_inherited(form, window), window, FormDataBinding::Wrap)
}
pub fn Constructor(window: &JSRef<Window>, form: Option<JSRef<HTMLFormElement>>) -> Fallible<Temporary<FormData>> {
Ok(FormData::new(form, window))
pub fn Constructor(global: &JSRef<Window>, form: Option<JSRef<HTMLFormElement>>) -> Fallible<Temporary<FormData>> {
Ok(FormData::new(form, global))
}
}
@ -115,9 +115,9 @@ trait PrivateFormDataHelpers{
impl PrivateFormDataHelpers for FormData {
fn get_file_from_blob(&self, value: &JSRef<Blob>, filename: Option<DOMString>) -> Temporary<File> {
let global = self.window.root();
let window = self.window.root();
let f: Option<&JSRef<File>> = FileCast::to_ref(value);
let name = filename.unwrap_or(f.map(|inner| inner.name.clone()).unwrap_or("blob".to_string()));
File::new(&*global, value, name)
File::new(&*window, value, name)
}
}

View file

@ -83,10 +83,11 @@ impl MouseEvent {
Temporary::from_rooted(&*ev)
}
pub fn Constructor(owner: &JSRef<Window>,
pub fn Constructor(global: &JSRef<Window>,
type_: DOMString,
init: &MouseEventBinding::MouseEventInit) -> Fallible<Temporary<MouseEvent>> {
let event = MouseEvent::new(owner, type_, init.parent.parent.bubbles,
let event = MouseEvent::new(global, type_,
init.parent.parent.bubbles,
init.parent.parent.cancelable,
init.parent.view.root_ref(),
init.parent.detail,

View file

@ -34,21 +34,21 @@ impl ProgressEvent {
total: total
}
}
pub fn new(window: &JSRef<Window>, type_: DOMString,
pub fn new(global: &JSRef<Window>, type_: DOMString,
can_bubble: bool, cancelable: bool,
length_computable: bool, loaded: u64, total: u64) -> Temporary<ProgressEvent> {
let ev = reflect_dom_object(box ProgressEvent::new_inherited(length_computable, loaded, total),
window,
global,
ProgressEventBinding::Wrap).root();
let event: &JSRef<Event> = EventCast::from_ref(&*ev);
event.InitEvent(type_, can_bubble, cancelable);
Temporary::from_rooted(&*ev)
}
pub fn Constructor(owner: &JSRef<Window>,
pub fn Constructor(global: &JSRef<Window>,
type_: DOMString,
init: &ProgressEventBinding::ProgressEventInit)
-> Fallible<Temporary<ProgressEvent>> {
let ev = ProgressEvent::new(owner, type_, init.parent.bubbles, init.parent.cancelable,
let ev = ProgressEvent::new(global, type_, init.parent.bubbles, init.parent.cancelable,
init.lengthComputable, init.loaded, init.total);
Ok(ev)
}

View file

@ -22,7 +22,7 @@ use std::cell::Cell;
#[deriving(Encodable)]
pub struct TestBinding {
pub reflector: Reflector,
pub window: Cell<JS<Window>>,
pub global: Cell<JS<Window>>,
}
pub trait TestBindingMethods {
@ -279,20 +279,20 @@ pub trait TestBindingMethods {
impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
fn InterfaceAttribute(&self) -> Temporary<Blob> {
let window = self.window.get().root();
Blob::new(&*window)
let global = self.global.get().root();
Blob::new(&*global)
}
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
let window = self.window.get().root();
Some(Blob::new(&*window))
let global = self.global.get().root();
Some(Blob::new(&*global))
}
fn ReceiveInterface(&self) -> Temporary<Blob> {
let window = self.window.get().root();
Blob::new(&*window)
let global = self.global.get().root();
Blob::new(&*global)
}
fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>> {
let window = self.window.get().root();
Some(Blob::new(&*window))
let global = self.global.get().root();
Some(Blob::new(&*global))
}
}

View file

@ -38,8 +38,8 @@ impl Text {
Node::reflect_node(box node, document, TextBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>, text: DOMString) -> Fallible<Temporary<Text>> {
let document = owner.Document().root();
pub fn Constructor(global: &JSRef<Window>, text: DOMString) -> Fallible<Temporary<Text>> {
let document = global.Document().root();
Ok(Text::new(text, &*document))
}
}

View file

@ -54,10 +54,10 @@ impl UIEvent {
Temporary::from_rooted(&*ev)
}
pub fn Constructor(owner: &JSRef<Window>,
pub fn Constructor(global: &JSRef<Window>,
type_: DOMString,
init: &UIEventBinding::UIEventInit) -> Fallible<Temporary<UIEvent>> {
let event = UIEvent::new(owner, type_,
let event = UIEvent::new(global, type_,
init.parent.bubbles, init.parent.cancelable,
init.view.root_ref(), init.detail);
Ok(event)

View file

@ -31,12 +31,12 @@ impl URLSearchParams {
}
}
pub fn new(window: &JSRef<Window>) -> Temporary<URLSearchParams> {
reflect_dom_object(box URLSearchParams::new_inherited(), window, URLSearchParamsBinding::Wrap)
pub fn new(global: &JSRef<Window>) -> Temporary<URLSearchParams> {
reflect_dom_object(box URLSearchParams::new_inherited(), global, URLSearchParamsBinding::Wrap)
}
pub fn Constructor(window: &JSRef<Window>, init: Option<StringOrURLSearchParams>) -> Fallible<Temporary<URLSearchParams>> {
let usp = URLSearchParams::new(window).root();
pub fn Constructor(global: &JSRef<Window>, init: Option<StringOrURLSearchParams>) -> Fallible<Temporary<URLSearchParams>> {
let usp = URLSearchParams::new(global).root();
match init {
Some(eString(_s)) => {
// XXXManishearth we need to parse the input here

View file

@ -130,13 +130,13 @@ pub struct XMLHttpRequest {
}
impl XMLHttpRequest {
pub fn new_inherited(owner: &JSRef<Window>) -> XMLHttpRequest {
pub fn new_inherited(global: &JSRef<Window>) -> XMLHttpRequest {
let xhr = XMLHttpRequest {
eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId),
ready_state: Traceable::new(Cell::new(Unsent)),
timeout: Traceable::new(Cell::new(0u32)),
with_credentials: Traceable::new(Cell::new(false)),
upload: Cell::new(JS::from_rooted(&XMLHttpRequestUpload::new(owner))),
upload: Cell::new(JS::from_rooted(&XMLHttpRequestUpload::new(global))),
response_url: "".to_string(),
status: Traceable::new(Cell::new(0)),
status_text: Traceable::new(RefCell::new(ByteString::new(vec!()))),
@ -155,7 +155,7 @@ impl XMLHttpRequest {
upload_complete: Traceable::new(Cell::new(false)),
upload_events: Traceable::new(Cell::new(false)),
global: JS::from_rooted(owner),
global: JS::from_rooted(global),
pinned_count: Traceable::new(Cell::new(0)),
timer: Untraceable::new(RefCell::new(Timer::new().unwrap())),
fetch_time: Traceable::new(Cell::new(0)),
@ -164,13 +164,13 @@ impl XMLHttpRequest {
};
xhr
}
pub fn new(window: &JSRef<Window>) -> Temporary<XMLHttpRequest> {
reflect_dom_object(box XMLHttpRequest::new_inherited(window),
window,
pub fn new(global: &JSRef<Window>) -> Temporary<XMLHttpRequest> {
reflect_dom_object(box XMLHttpRequest::new_inherited(global),
global,
XMLHttpRequestBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<XMLHttpRequest>> {
Ok(XMLHttpRequest::new(owner))
pub fn Constructor(global: &JSRef<Window>) -> Fallible<Temporary<XMLHttpRequest>> {
Ok(XMLHttpRequest::new(global))
}
pub fn handle_xhr_progress(addr: TrustedXHRAddress, progress: XHRProgress) {
@ -719,9 +719,10 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
fn change_ready_state(&self, rs: XMLHttpRequestState) {
assert!(self.ready_state.deref().get() != rs)
self.ready_state.deref().set(rs);
let win = &*self.global.root();
let event =
Event::new(win, "readystatechange".to_string(), false, true).root();
let global = self.global.root();
let event = Event::new(&*global,
"readystatechange".to_string(),
false, true).root();
let target: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
target.dispatch_event_with_target(None, &*event).ok();
}
@ -839,9 +840,10 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
}
fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option<u64>) {
let win = &*self.global.root();
let global = self.global.root();
let upload_target = &*self.upload.get().root();
let progressevent = ProgressEvent::new(win, type_, false, false,
let progressevent = ProgressEvent::new(&*global,
type_, false, false,
total.is_some(), loaded,
total.unwrap_or(0)).root();
let target: &JSRef<EventTarget> = if upload {

View file

@ -22,9 +22,9 @@ impl XMLHttpRequestUpload {
eventtarget:XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestUploadTypeId)
}
}
pub fn new(window: &JSRef<Window>) -> Temporary<XMLHttpRequestUpload> {
pub fn new(global: &JSRef<Window>) -> Temporary<XMLHttpRequestUpload> {
reflect_dom_object(box XMLHttpRequestUpload::new_inherited(),
window,
global,
XMLHttpRequestUploadBinding::Wrap)
}
}