diff options
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 58995645c27..f6f06e7d851 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.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 core::nonzero::NonZero; use document_loader::{DocumentLoader, LoadType}; use dom::activation::{ActivationSource, synthetic_click_activation}; use dom::attr::Attr; @@ -116,7 +117,6 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::default::Default; use std::iter::once; use std::mem; -use std::ptr; use std::rc::Rc; use std::sync::Arc; use string_cache::{Atom, QualName}; @@ -2710,8 +2710,9 @@ impl DocumentMethods for Document { self.set_body_attribute(&atom!("text"), value) } + #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString, found: &mut bool) -> *mut JSObject { + fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> { #[derive(JSTraceable, HeapSizeOf)] struct NamedElementFilter { name: Atom, @@ -2777,23 +2778,24 @@ impl DocumentMethods for Document { .peekable(); if let Some(first) = elements.next() { if elements.peek().is_none() { - *found = true; // TODO: Step 2. // Step 3. - return first.reflector().get_jsobject().get(); + return unsafe { + Some(NonZero::new(first.reflector().get_jsobject().get())) + }; } } else { - *found = false; - return ptr::null_mut(); + return None; } } // Step 4. - *found = true; let filter = NamedElementFilter { name: name, }; let collection = HTMLCollection::create(self.window(), root, box filter); - collection.reflector().get_jsobject().get() + unsafe { + Some(NonZero::new(collection.reflector().get_jsobject().get())) + } } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names |