Skip to content

Commit

Permalink
auto merge of #2633 : Ms2ger/servo/derefmut, r=pcwalton
Browse files Browse the repository at this point in the history
Part of #1854.
  • Loading branch information
bors-servo committed Jun 10, 2014
2 parents 57e8be0 + a493d7f commit c12119b
Show file tree
Hide file tree
Showing 22 changed files with 405 additions and 390 deletions.
8 changes: 4 additions & 4 deletions src/components/main/layout/wrapper.rs
Expand Up @@ -112,7 +112,7 @@ pub trait TLayoutNode {
fail!("not an iframe element!")
}
let iframe_element: JS<HTMLIFrameElement> = self.get_jsmanaged().transmute_copy();
let size = (*iframe_element.unsafe_get()).size.unwrap();
let size = (*iframe_element.unsafe_get()).size.deref().get().unwrap();
(size.pipeline_id, size.subpage_id)
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
fail!("not text!")
}
let text: JS<Text> = self.get_jsmanaged().transmute_copy();
(*text.unsafe_get()).characterdata.data.to_str()
(*text.unsafe_get()).characterdata.data.deref().borrow().clone()
}
}
}
Expand Down Expand Up @@ -494,7 +494,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> {
fail!("not text!")
}
let text: JS<Text> = self.get_jsmanaged().transmute_copy();
(*text.unsafe_get()).characterdata.data.to_str()
(*text.unsafe_get()).characterdata.data.deref().borrow().clone()
}
}
}
Expand Down Expand Up @@ -636,7 +636,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
Some(TextNodeTypeId) => {
unsafe {
let text: JS<Text> = self.get_jsmanaged().transmute_copy();
if !is_whitespace((*text.unsafe_get()).characterdata.data.as_slice()) {
if !is_whitespace((*text.unsafe_get()).characterdata.data.deref().borrow().as_slice()) {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/script/dom/bindings/utils.rs
Expand Up @@ -632,7 +632,7 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut
IDLInterface::get_prototype_depth(None::<window::Window>))
.unwrap()
.root();
win.deref().browser_context.get_ref().window_proxy()
win.deref().browser_context.deref().borrow().get_ref().window_proxy()
}
}

Expand Down
47 changes: 25 additions & 22 deletions src/components/script/dom/characterdata.rs
Expand Up @@ -5,18 +5,21 @@
//! DOM bindings for `CharacterData`.

use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, NodeCast};
use dom::bindings::js::JSRef;
use dom::bindings::error::{Fallible, ErrorResult, IndexSize};
use dom::bindings::js::JSRef;
use dom::bindings::trace::Untraceable;
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{CommentNodeTypeId, Node, NodeTypeId, TextNodeTypeId, ProcessingInstructionNodeTypeId, NodeHelpers};
use servo_util::str::DOMString;

use std::cell::RefCell;

#[deriving(Encodable)]
pub struct CharacterData {
pub node: Node,
pub data: DOMString,
pub data: Untraceable<RefCell<DOMString>>,
}

impl CharacterDataDerived for EventTarget {
Expand All @@ -34,56 +37,56 @@ impl CharacterData {
pub fn new_inherited(id: NodeTypeId, data: DOMString, document: &JSRef<Document>) -> CharacterData {
CharacterData {
node: Node::new_inherited(id, document),
data: data
data: Untraceable::new(RefCell::new(data)),
}
}
}

pub trait CharacterDataMethods {
fn Data(&self) -> DOMString;
fn SetData(&mut self, arg: DOMString) -> ErrorResult;
fn SetData(&self, arg: DOMString) -> ErrorResult;
fn Length(&self) -> u32;
fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString>;
fn AppendData(&mut self, arg: DOMString) -> ErrorResult;
fn InsertData(&mut self, _offset: u32, _arg: DOMString) -> ErrorResult;
fn DeleteData(&mut self, _offset: u32, _count: u32) -> ErrorResult;
fn ReplaceData(&mut self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult;
fn AppendData(&self, arg: DOMString) -> ErrorResult;
fn InsertData(&self, _offset: u32, _arg: DOMString) -> ErrorResult;
fn DeleteData(&self, _offset: u32, _count: u32) -> ErrorResult;
fn ReplaceData(&self, _offset: u32, _count: u32, _arg: DOMString) -> ErrorResult;
fn Remove(&self);
}

impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
fn Data(&self) -> DOMString {
self.data.clone()
self.data.deref().borrow().clone()
}

fn SetData(&mut self, arg: DOMString) -> ErrorResult {
self.data = arg;
fn SetData(&self, arg: DOMString) -> ErrorResult {
*self.data.deref().borrow_mut() = arg;
Ok(())
}

fn Length(&self) -> u32 {
self.data.len() as u32
self.data.deref().borrow().len() as u32
}

fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> {
Ok(self.data.as_slice().slice(offset as uint, count as uint).to_str())
Ok(self.data.deref().borrow().as_slice().slice(offset as uint, count as uint).to_string())
}

fn AppendData(&mut self, arg: DOMString) -> ErrorResult {
self.data.push_str(arg.as_slice());
fn AppendData(&self, arg: DOMString) -> ErrorResult {
self.data.deref().borrow_mut().push_str(arg.as_slice());
Ok(())
}

fn InsertData(&mut self, offset: u32, arg: DOMString) -> ErrorResult {
fn InsertData(&self, offset: u32, arg: DOMString) -> ErrorResult {
self.ReplaceData(offset, 0, arg)
}

fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult {
fn DeleteData(&self, offset: u32, count: u32) -> ErrorResult {
self.ReplaceData(offset, count, "".to_string())
}

fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
let length = self.data.len() as u32;
fn ReplaceData(&self, offset: u32, count: u32, arg: DOMString) -> ErrorResult {
let length = self.data.deref().borrow().len() as u32;
if offset > length {
return Err(IndexSize);
}
Expand All @@ -92,10 +95,10 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> {
} else {
count
};
let mut data = self.data.as_slice().slice(0, offset as uint).to_string();
let mut data = self.data.deref().borrow().as_slice().slice(0, offset as uint).to_string();
data.push_str(arg.as_slice());
data.push_str(self.data.as_slice().slice((offset + count) as uint, length as uint));
self.data = data.into_owned();
data.push_str(self.data.deref().borrow().as_slice().slice((offset + count) as uint, length as uint));
*self.data.deref().borrow_mut() = data.into_owned();
// FIXME: Once we have `Range`, we should implement step7 to step11
Ok(())
}
Expand Down
22 changes: 12 additions & 10 deletions src/components/script/dom/customevent.rs
Expand Up @@ -14,10 +14,12 @@ use js::jsapi::JSContext;
use js::jsval::{JSVal, NullValue};
use servo_util::str::DOMString;

use std::cell::Cell;

#[deriving(Encodable)]
pub struct CustomEvent {
event: Event,
detail: Traceable<JSVal>
detail: Traceable<Cell<Traceable<JSVal>>>,
}

impl CustomEventDerived for Event {
Expand All @@ -28,7 +30,7 @@ impl CustomEventDerived for Event {

pub trait CustomEventMethods {
fn Detail(&self, _cx: *mut JSContext) -> JSVal;
fn InitCustomEvent(&mut self, _cx: *mut JSContext,
fn InitCustomEvent(&self, _cx: *mut JSContext,
type_: DOMString, can_bubble: bool,
cancelable: bool, detail: JSVal);
}
Expand All @@ -37,7 +39,7 @@ impl CustomEvent {
pub fn new_inherited(type_id: EventTypeId) -> CustomEvent {
CustomEvent {
event: Event::new_inherited(type_id),
detail: Traceable::new(NullValue())
detail: Traceable::new(Cell::new(Traceable::new(NullValue()))),
}
}

Expand All @@ -47,8 +49,8 @@ impl CustomEvent {
CustomEventBinding::Wrap)
}
pub fn new(window: &JSRef<Window>, type_: DOMString, bubbles: bool, cancelable: bool, detail: JSVal) -> Temporary<CustomEvent> {
let mut ev = CustomEvent::new_uninitialized(window).root();
ev.InitCustomEvent(window.deref().get_cx(), type_, bubbles, cancelable, detail);
let ev = CustomEvent::new_uninitialized(window).root();
ev.deref().InitCustomEvent(window.deref().get_cx(), type_, bubbles, cancelable, detail);
Temporary::from_rooted(&*ev)
}
pub fn Constructor(owner: &JSRef<Window>,
Expand All @@ -60,17 +62,17 @@ impl CustomEvent {

impl<'a> CustomEventMethods for JSRef<'a, CustomEvent> {
fn Detail(&self, _cx: *mut JSContext) -> JSVal {
self.detail.deref().clone()
*self.detail.deref().get()
}

fn InitCustomEvent(&mut self,
_cx: *mut JSContext,
fn InitCustomEvent(&self,
_cx: *mut JSContext,
type_: DOMString,
can_bubble: bool,
cancelable: bool,
detail: JSVal) {
self.detail = Traceable::new(detail);
let event: &mut JSRef<Event> = EventCast::from_mut_ref(self);
self.detail.deref().set(Traceable::new(detail));
let event: &JSRef<Event> = EventCast::from_ref(self);
event.InitEvent(type_, can_bubble, cancelable);
}
}
Expand Down
46 changes: 23 additions & 23 deletions src/components/script/dom/document.rs
Expand Up @@ -49,7 +49,7 @@ use servo_util::str::{DOMString, null_str_as_empty_ref};
use collections::hashmap::HashMap;
use js::jsapi::JSContext;
use std::ascii::StrAsciiExt;
use std::cell::Cell;
use std::cell::{Cell, RefCell};
use url::{Url, from_str};

#[deriving(Eq,Encodable)]
Expand All @@ -66,10 +66,10 @@ pub struct Document {
pub idmap: HashMap<DOMString, Vec<JS<Element>>>,
pub implementation: Cell<Option<JS<DOMImplementation>>>,
pub content_type: DOMString,
pub encoding_name: DOMString,
pub encoding_name: Untraceable<RefCell<DOMString>>,
pub is_html_document: bool,
pub url: Untraceable<Url>,
pub quirks_mode: Untraceable<QuirksMode>,
pub quirks_mode: Untraceable<Cell<QuirksMode>>,
}

impl DocumentDerived for EventTarget {
Expand All @@ -81,8 +81,8 @@ impl DocumentDerived for EventTarget {
pub trait DocumentHelpers {
fn url<'a>(&'a self) -> &'a Url;
fn quirks_mode(&self) -> QuirksMode;
fn set_quirks_mode(&mut self, mode: QuirksMode);
fn set_encoding_name(&mut self, name: DOMString);
fn set_quirks_mode(&self, mode: QuirksMode);
fn set_encoding_name(&self, name: DOMString);
fn content_changed(&self);
fn damage_and_reflow(&self, damage: DocumentDamageLevel);
fn wait_until_safe_to_modify_dom(&self);
Expand All @@ -97,15 +97,15 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
}

fn quirks_mode(&self) -> QuirksMode {
*self.quirks_mode
self.quirks_mode.deref().get()
}

fn set_quirks_mode(&mut self, mode: QuirksMode) {
*self.quirks_mode = mode;
fn set_quirks_mode(&self, mode: QuirksMode) {
self.quirks_mode.deref().set(mode);
}

fn set_encoding_name(&mut self, name: DOMString) {
self.encoding_name = name;
fn set_encoding_name(&self, name: DOMString) {
*self.encoding_name.deref().borrow_mut() = name;
}

fn content_changed(&self) {
Expand Down Expand Up @@ -227,9 +227,9 @@ impl Document {
},
url: Untraceable::new(url),
// http://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: Untraceable::new(NoQuirks),
quirks_mode: Untraceable::new(Cell::new(NoQuirks)),
// http://dom.spec.whatwg.org/#concept-document-encoding
encoding_name: "utf-8".to_string(),
encoding_name: Untraceable::new(RefCell::new("utf-8".to_string())),
is_html_document: is_html_document == HTMLDocument,
}
}
Expand Down Expand Up @@ -331,9 +331,9 @@ pub trait DocumentMethods {
fn Children(&self) -> Temporary<HTMLCollection>;
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>>;
fn GetOnclick(&self) -> Option<EventHandlerNonNull>;
fn SetOnclick(&mut self, listener: Option<EventHandlerNonNull>);
fn SetOnclick(&self, listener: Option<EventHandlerNonNull>);
fn GetOnload(&self) -> Option<EventHandlerNonNull>;
fn SetOnload(&mut self, listener: Option<EventHandlerNonNull>);
fn SetOnload(&self, listener: Option<EventHandlerNonNull>);
}

impl<'a> DocumentMethods for JSRef<'a, Document> {
Expand All @@ -358,15 +358,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {

// http://dom.spec.whatwg.org/#dom-document-compatmode
fn CompatMode(&self) -> DOMString {
match *self.quirks_mode {
match self.quirks_mode.deref().get() {
NoQuirks => "CSS1Compat".to_string(),
LimitedQuirks | FullQuirks => "BackCompat".to_string()
}
}

// http://dom.spec.whatwg.org/#dom-document-characterset
fn CharacterSet(&self) -> DOMString {
self.encoding_name.as_slice().to_ascii_lower()
self.encoding_name.deref().borrow().as_slice().to_ascii_lower()
}

// http://dom.spec.whatwg.org/#dom-document-content_type
Expand Down Expand Up @@ -430,7 +430,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
return Err(InvalidCharacter);
}
let local_name = local_name.as_slice().to_ascii_lower();
Ok(build_element_from_tag(local_name, self))
Ok(build_element_from_tag(local_name, namespace::HTML, self))
}

// http://dom.spec.whatwg.org/#dom-document-createelementns
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}

if ns == namespace::HTML {
Ok(build_element_from_tag(local_name_from_qname, self))
Ok(build_element_from_tag(local_name_from_qname, ns, self))
} else {
Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, self))
}
Expand Down Expand Up @@ -567,7 +567,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
for child in title_elem.children() {
if child.is_text() {
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
title.push_str(text.deref().characterdata.data.as_slice());
title.push_str(text.deref().characterdata.data.deref().borrow().as_slice());
}
}
});
Expand Down Expand Up @@ -826,8 +826,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
eventtarget.get_event_handler_common("click")
}

fn SetOnclick(&mut self, listener: Option<EventHandlerNonNull>) {
let eventtarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(self);
fn SetOnclick(&self, listener: Option<EventHandlerNonNull>) {
let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
eventtarget.set_event_handler_common("click", listener)
}

Expand All @@ -836,8 +836,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
eventtarget.get_event_handler_common("load")
}

fn SetOnload(&mut self, listener: Option<EventHandlerNonNull>) {
let eventtarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(self);
fn SetOnload(&self, listener: Option<EventHandlerNonNull>) {
let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(self);
eventtarget.set_event_handler_common("load", listener)
}
}

0 comments on commit c12119b

Please sign in to comment.