Skip to content

Commit

Permalink
auto merge of #3569 : andrewguertin/servo/mutnullablejs, r=Manishearth
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Oct 4, 2014
2 parents a6cd13c + 815a701 commit d23e45f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
42 changes: 21 additions & 21 deletions components/script/dom/document.rs
Expand Up @@ -89,13 +89,13 @@ pub struct Document {
pub is_html_document: bool,
url: Untraceable<Url>,
quirks_mode: Untraceable<Cell<QuirksMode>>,
images: Cell<Option<JS<HTMLCollection>>>,
embeds: Cell<Option<JS<HTMLCollection>>>,
links: Cell<Option<JS<HTMLCollection>>>,
forms: Cell<Option<JS<HTMLCollection>>>,
scripts: Cell<Option<JS<HTMLCollection>>>,
anchors: Cell<Option<JS<HTMLCollection>>>,
applets: Cell<Option<JS<HTMLCollection>>>,
images: MutNullableJS<HTMLCollection>,
embeds: MutNullableJS<HTMLCollection>,
links: MutNullableJS<HTMLCollection>,
forms: MutNullableJS<HTMLCollection>,
scripts: MutNullableJS<HTMLCollection>,
anchors: MutNullableJS<HTMLCollection>,
applets: MutNullableJS<HTMLCollection>,
}

impl DocumentDerived for EventTarget {
Expand Down Expand Up @@ -327,13 +327,13 @@ impl Document {
// http://dom.spec.whatwg.org/#concept-document-encoding
encoding_name: Traceable::new(RefCell::new("utf-8".to_string())),
is_html_document: is_html_document == HTMLDocument,
images: Cell::new(None),
embeds: Cell::new(None),
links: Cell::new(None),
forms: Cell::new(None),
scripts: Cell::new(None),
anchors: Cell::new(None),
applets: Cell::new(None),
images: Default::default(),
embeds: Default::default(),
links: Default::default(),
forms: Default::default(),
scripts: Default::default(),
anchors: Default::default(),
applets: Default::default(),
}
}

Expand Down Expand Up @@ -789,7 +789,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box ImagesFilter;
self.images.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.images.get().as_ref().unwrap().clone())
self.images.get().unwrap()
}

fn Embeds(self) -> Temporary<HTMLCollection> {
Expand All @@ -799,7 +799,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box EmbedsFilter;
self.embeds.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.embeds.get().as_ref().unwrap().clone())
self.embeds.get().unwrap()
}

fn Plugins(self) -> Temporary<HTMLCollection> {
Expand All @@ -813,7 +813,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box LinksFilter;
self.links.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.links.get().as_ref().unwrap().clone())
self.links.get().unwrap()
}

fn Forms(self) -> Temporary<HTMLCollection> {
Expand All @@ -823,7 +823,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box FormsFilter;
self.forms.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.forms.get().as_ref().unwrap().clone())
self.forms.get().unwrap()
}

fn Scripts(self) -> Temporary<HTMLCollection> {
Expand All @@ -833,7 +833,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box ScriptsFilter;
self.scripts.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.scripts.get().as_ref().unwrap().clone())
self.scripts.get().unwrap()
}

fn Anchors(self) -> Temporary<HTMLCollection> {
Expand All @@ -843,7 +843,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box AnchorsFilter;
self.anchors.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.anchors.get().as_ref().unwrap().clone())
self.anchors.get().unwrap()
}

fn Applets(self) -> Temporary<HTMLCollection> {
Expand All @@ -854,7 +854,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let filter = box AppletsFilter;
self.applets.assign(Some(HTMLCollection::create(*window, root, filter)));
}
Temporary::new(self.applets.get().as_ref().unwrap().clone())
self.applets.get().unwrap()
}

fn Location(self) -> Temporary<Location> {
Expand Down
9 changes: 5 additions & 4 deletions components/script/dom/htmlcanvaselement.rs
Expand Up @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElemen
use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
use dom::bindings::global::Window;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalSettable};
use dom::bindings::trace::Traceable;
use dom::bindings::utils::{Reflectable, Reflector};
use dom::canvasrenderingcontext2d::CanvasRenderingContext2D;
Expand All @@ -24,6 +24,7 @@ use string_cache::Atom;
use geom::size::Size2D;

use std::cell::Cell;
use std::default::Default;

static DefaultWidth: u32 = 300;
static DefaultHeight: u32 = 150;
Expand All @@ -32,7 +33,7 @@ static DefaultHeight: u32 = 150;
#[must_root]
pub struct HTMLCanvasElement {
pub htmlelement: HTMLElement,
context: Traceable<Cell<Option<JS<CanvasRenderingContext2D>>>>,
context: Traceable<MutNullableJS<CanvasRenderingContext2D>>,
width: Traceable<Cell<u32>>,
height: Traceable<Cell<u32>>,
}
Expand All @@ -47,7 +48,7 @@ impl HTMLCanvasElement {
fn new_inherited(localName: DOMString, document: JSRef<Document>) -> HTMLCanvasElement {
HTMLCanvasElement {
htmlelement: HTMLElement::new_inherited(HTMLCanvasElementTypeId, localName, document),
context: Traceable::new(Cell::new(None)),
context: Traceable::new(Default::default()),
width: Traceable::new(Cell::new(DefaultWidth)),
height: Traceable::new(Cell::new(DefaultHeight)),
}
Expand Down Expand Up @@ -90,7 +91,7 @@ impl<'a> HTMLCanvasElementMethods for JSRef<'a, HTMLCanvasElement> {
let context = CanvasRenderingContext2D::new(&Window(*window), self, Size2D(w, h));
self.context.assign(Some(context));
}
self.context.get().map(|context| Temporary::new(context))
self.context.get()
}
}

Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/window.rs
Expand Up @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::error::{Fallible, InvalidCharacter};
use dom::bindings::global;
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalSettable};
use dom::bindings::trace::{Traceable, Untraceable};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::browsercontext::BrowserContext;
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct Window {
performance: MutNullableJS<Performance>,
pub navigationStart: u64,
pub navigationStartPrecise: f64,
screen: Cell<Option<JS<Screen>>>,
screen: MutNullableJS<Screen>,
}

impl Window {
Expand Down Expand Up @@ -338,7 +338,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
let screen = Screen::new(self);
self.screen.assign(Some(screen));
}
Temporary::new(self.screen.get().as_ref().unwrap().clone())
self.screen.get().unwrap()
}

fn Debug(self, message: DOMString) {
Expand Down Expand Up @@ -542,7 +542,7 @@ impl Window {
performance: Default::default(),
navigationStart: time::get_time().sec as u64,
navigationStartPrecise: time::precise_time_s(),
screen: Cell::new(None),
screen: Default::default(),
};

WindowBinding::Wrap(cx, win)
Expand Down
22 changes: 11 additions & 11 deletions components/script/dom/workerglobalscope.rs
Expand Up @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScop
use dom::bindings::error::{ErrorResult, Fallible, Syntax, Network, FailureUnknown};
use dom::bindings::trace::Untraceable;
use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalSettable};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::console::Console;
use dom::eventtarget::{EventTarget, WorkerGlobalScopeTypeId};
Expand All @@ -21,7 +21,7 @@ use servo_util::str::DOMString;
use js::jsapi::JSContext;
use js::rust::Cx;

use std::cell::Cell;
use std::default::Default;
use std::rc::Rc;
use url::{Url, UrlParser};

Expand All @@ -39,9 +39,9 @@ pub struct WorkerGlobalScope {
js_context: Untraceable<Rc<Cx>>,
resource_task: Untraceable<ResourceTask>,
script_chan: ScriptChan,
location: Cell<Option<JS<WorkerLocation>>>,
navigator: Cell<Option<JS<WorkerNavigator>>>,
console: Cell<Option<JS<Console>>>,
location: MutNullableJS<WorkerLocation>,
navigator: MutNullableJS<WorkerNavigator>,
console: MutNullableJS<Console>,
}

impl WorkerGlobalScope {
Expand All @@ -56,9 +56,9 @@ impl WorkerGlobalScope {
js_context: Untraceable::new(cx),
resource_task: Untraceable::new(resource_task),
script_chan: script_chan,
location: Cell::new(None),
navigator: Cell::new(None),
console: Cell::new(None),
location: Default::default(),
navigator: Default::default(),
console: Default::default(),
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
let location = WorkerLocation::new(self, self.worker_url.deref().clone());
self.location.assign(Some(location));
}
Temporary::new(self.location.get().as_ref().unwrap().clone())
self.location.get().unwrap()
}

fn ImportScripts(self, url_strings: Vec<DOMString>) -> ErrorResult {
Expand Down Expand Up @@ -129,15 +129,15 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
let navigator = WorkerNavigator::new(self);
self.navigator.assign(Some(navigator));
}
Temporary::new(self.navigator.get().as_ref().unwrap().clone())
self.navigator.get().unwrap()
}

fn Console(self) -> Temporary<Console> {
if self.console.get().is_none() {
let console = Console::new(&global::Worker(self));
self.console.assign(Some(console));
}
Temporary::new(self.console.get().as_ref().unwrap().clone())
self.console.get().unwrap()
}

fn Btoa(self, btoa: DOMString) -> Fallible<DOMString> {
Expand Down

0 comments on commit d23e45f

Please sign in to comment.