mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #13100 - nox:better-getters, r=Ms2ger
Use Option<T> to return from getters <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13100) <!-- Reviewable:end -->
This commit is contained in:
commit
3649a356c8
32 changed files with 164 additions and 154 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue