From ab90c718ebc39fe94166bca8061be578edf53c18 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Thu, 16 Oct 2014 10:48:23 +0900 Subject: [PATCH 1/2] Add the comment about to use `mem::transmute()` for values contained in DOMRefCell. --- components/script/dom/element.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d9f995720a8..fab5feff560 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1084,11 +1084,13 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { impl<'a> style::TElement<'a> for JSRef<'a, Element> { fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> { self.get_attribute(namespace.clone(), attr).root().map(|attr| { + // This transmute is used to cheat the lifetime restriction. unsafe { mem::transmute(attr.value().as_slice()) } }) } fn get_attrs(self, attr: &Atom) -> Vec<&'a str> { self.get_attributes(attr).iter().map(|attr| attr.root()).map(|attr| { + // This transmute is used to cheat the lifetime restriction. unsafe { mem::transmute(attr.value().as_slice()) } }).collect() } From 2bdcc0e2c0c24b084185e67fdd7900fee88c11cb Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Thu, 16 Oct 2014 11:17:00 +0900 Subject: [PATCH 2/2] Use DOMRefCell for HTMLInputElement's field that is borrowed from other tasks. --- components/script/dom/htmlinputelement.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 776ff10244d..7b9358afd61 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -2,6 +2,7 @@ * 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 dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; @@ -27,7 +28,6 @@ use string_cache::Atom; use std::ascii::OwnedStrAsciiExt; use std::cell::{Cell, RefCell}; -use std::mem; static DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; static DEFAULT_RESET_VALUE: &'static str = "Reset"; @@ -52,7 +52,7 @@ pub struct HTMLInputElement { input_type: Cell, checked: Cell, uncommitted_value: RefCell>, - value: RefCell>, + value: DOMRefCell>, size: Cell, } @@ -71,7 +71,7 @@ impl HTMLInputElement { input_type: Cell::new(InputText), checked: Cell::new(false), uncommitted_value: RefCell::new(None), - value: RefCell::new(None), + value: DOMRefCell::new(None), size: Cell::new(DEFAULT_INPUT_SIZE), } } @@ -91,21 +91,17 @@ pub trait LayoutHTMLInputElementHelpers { impl LayoutHTMLInputElementHelpers for HTMLInputElement { #[allow(unrooted_must_root)] unsafe fn get_value_for_layout(&self) -> String { - unsafe fn get_raw_value(input: &HTMLInputElement) -> Option { - mem::transmute::<&RefCell>, &Option>(&input.value).clone() - } - match self.input_type.get() { InputCheckbox | InputRadio => "".to_string(), InputFile | InputImage => "".to_string(), - InputButton(ref default) => get_raw_value(self) + InputButton(ref default) => self.value.borrow_for_layout().clone() .or_else(|| default.map(|v| v.to_string())) .unwrap_or_else(|| "".to_string()), InputPassword => { - let raw = get_raw_value(self).unwrap_or_else(|| "".to_string()); + let raw = self.value.borrow_for_layout().clone().unwrap_or_else(|| "".to_string()); String::from_char(raw.len(), '*') } - _ => get_raw_value(self).unwrap_or_else(|| "".to_string()), + _ => self.value.borrow_for_layout().clone().unwrap_or_else(|| "".to_string()), } }