diff options
Diffstat (limited to 'components/script')
22 files changed, 72 insertions, 109 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 8a169fe2c31..cf918feb8e3 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -18,6 +18,7 @@ from WebIDL import ( BuiltinTypes, IDLBuiltinType, IDLNullValue, + IDLNullableType, IDLType, IDLInterfaceMember, IDLUndefinedValue, @@ -4555,6 +4556,8 @@ class CGProxySpecialOperation(CGPerSignatureCall): signature = operation.signatures()[0] (returnType, arguments) = signature + if operation.isGetter() and not returnType.nullable(): + returnType = IDLNullableType(returnType.location, returnType) # We pass len(arguments) as the final argument so that the # CGPerSignatureCall won't do any argument conversion of its own. @@ -4577,8 +4580,6 @@ class CGProxySpecialOperation(CGPerSignatureCall): self.cgRoot.prepend(instantiateJSToNativeConversionTemplate( template, templateValues, declType, argument.identifier.name)) self.cgRoot.prepend(CGGeneric("rooted!(in(cx) let value = desc.value);")) - elif operation.isGetter(): - self.cgRoot.prepend(CGGeneric("let mut found = false;")) def getArguments(self): def process(arg): @@ -4587,10 +4588,6 @@ class CGProxySpecialOperation(CGPerSignatureCall): argVal += ".r()" return argVal args = [(a, process(a)) for a in self.arguments] - if self.idlNode.isGetter(): - args.append((FakeArgument(BuiltinTypes[IDLBuiltinType.Types.boolean], - self.idlNode), - "&mut found")) return args def wrap_return_value(self): @@ -4598,7 +4595,7 @@ class CGProxySpecialOperation(CGPerSignatureCall): return "" wrap = CGGeneric(wrapForType(**self.templateValues)) - wrap = CGIfWrapper("found", wrap) + wrap = CGIfWrapper("let Some(result) = result", wrap) return "\n" + wrap.define() @@ -4974,7 +4971,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): " let this = UnwrapProxy(proxy);\n" + " let this = &*this;\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" + - " *bp = found;\n" + + " *bp = result.is_some();\n" + " return true;\n" + "}\n\n") else: @@ -4990,7 +4987,7 @@ if RUST_JSID_IS_STRING(id) { } if !has_on_proto { %s - *bp = found; + *bp = result.is_some(); return true; } } @@ -5274,7 +5271,9 @@ class CGInterfaceTrait(CGThing): infallible = 'infallible' in descriptor.getExtendedAttributes(operation) if operation.isGetter(): - arguments = method_arguments(descriptor, rettype, arguments, trailing=("found", "&mut bool")) + if not rettype.nullable(): + rettype = IDLNullableType(rettype.location, rettype) + arguments = method_arguments(descriptor, rettype, arguments) # If this interface 'supports named properties', then we # should be able to access 'supported property names' diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 076a2283b67..0335a7498c0 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -100,18 +100,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-item fn Item(&self, index: u32) -> DOMString { - let index = index as usize; - let elem = self.owner.upcast::<Element>(); - let style_attribute = elem.style_attribute().borrow(); - style_attribute.as_ref().and_then(|declarations| { - declarations.declarations.get(index) - }).map(|&(ref declaration, importance)| { - let mut css = declaration.to_css_string(); - if importance.important() { - css += " !important"; - } - DOMString::from(css) - }).unwrap_or_else(DOMString::new) + self.IndexedGetter(index).unwrap_or_default() } // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue @@ -333,10 +322,19 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { } // https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface - fn IndexedGetter(&self, index: u32, found: &mut bool) -> DOMString { - let rval = self.Item(index); - *found = index < self.Length(); - rval + fn IndexedGetter(&self, index: u32) -> Option<DOMString> { + let index = index as usize; + let elem = self.owner.upcast::<Element>(); + let style_attribute = elem.style_attribute().borrow(); + style_attribute.as_ref().and_then(|declarations| { + declarations.declarations.get(index) + }).map(|&(ref declaration, importance)| { + let mut css = declaration.to_css_string(); + if importance.important() { + css += " !important"; + } + DOMString::from(css) + }) } // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 6a06adcafc7..55ef9c9f654 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -91,7 +91,7 @@ use euclid::point::Point2D; use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode}; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::JS_GetRuntime; -use js::jsapi::{JSContext, JSObject, JSRuntime, JS_NewPlainObject}; +use js::jsapi::{JSContext, JSObject, JSRuntime}; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{Key, KeyModifiers, KeyState}; use msg::constellation_msg::{PipelineId, ReferrerPolicy, SubpageId}; @@ -2691,8 +2691,7 @@ impl DocumentMethods for Document { #[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) - -> NonZero<*mut JSObject> { + fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> { #[derive(JSTraceable, HeapSizeOf)] struct NamedElementFilter { name: Atom, @@ -2758,28 +2757,23 @@ impl DocumentMethods for Document { .peekable(); if let Some(first) = elements.next() { if elements.peek().is_none() { - *found = true; // TODO: Step 2. // Step 3. return unsafe { - NonZero::new(first.reflector().get_jsobject().get()) + Some(NonZero::new(first.reflector().get_jsobject().get())) }; } } else { - *found = false; - return unsafe { - NonZero::new(JS_NewPlainObject(cx)) - }; + return None; } } // Step 4. - *found = true; let filter = NamedElementFilter { name: name, }; let collection = HTMLCollection::create(self.window(), root, box filter); unsafe { - NonZero::new(collection.reflector().get_jsobject().get()) + Some(NonZero::new(collection.reflector().get_jsobject().get())) } } diff --git a/components/script/dom/domrectlist.rs b/components/script/dom/domrectlist.rs index adb246158f4..86774a49ff3 100644 --- a/components/script/dom/domrectlist.rs +++ b/components/script/dom/domrectlist.rs @@ -52,8 +52,7 @@ impl DOMRectListMethods for DOMRectList { } // check-tidy: no specs after this line - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<DOMRect>> { - *found = index < self.rects.len() as u32; + fn IndexedGetter(&self, index: u32) -> Option<Root<DOMRect>> { self.Item(index) } } diff --git a/components/script/dom/domstringmap.rs b/components/script/dom/domstringmap.rs index c5e534d242e..11479d6b5df 100644 --- a/components/script/dom/domstringmap.rs +++ b/components/script/dom/domstringmap.rs @@ -47,10 +47,8 @@ impl DOMStringMapMethods for DOMStringMap { } // https://html.spec.whatwg.org/multipage/#dom-domstringmap-nameditem - fn NamedGetter(&self, name: DOMString, found: &mut bool) -> DOMString { - let attr = self.element.get_custom_attr(name); - *found = attr.is_some(); - attr.unwrap_or_default() + fn NamedGetter(&self, name: DOMString) -> Option<DOMString> { + self.element.get_custom_attr(name) } // https://html.spec.whatwg.org/multipage/#the-domstringmap-interface:supported-property-names diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 364b6366282..c1c09de94c2 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -171,9 +171,7 @@ impl DOMTokenListMethods for DOMTokenList { } // check-tidy: no specs after this line - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<DOMString> { - let item = self.Item(index); - *found = item.is_some(); - item + fn IndexedGetter(&self, index: u32) -> Option<DOMString> { + self.Item(index) } } diff --git a/components/script/dom/filelist.rs b/components/script/dom/filelist.rs index 4f8e976f5f7..8adbe1ed467 100644 --- a/components/script/dom/filelist.rs +++ b/components/script/dom/filelist.rs @@ -55,9 +55,7 @@ impl FileListMethods for FileList { } // check-tidy: no specs after this line - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<File>> { - let item = self.Item(index); - *found = item.is_some(); - item + fn IndexedGetter(&self, index: u32) -> Option<Root<File>> { + self.Item(index) } } diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 95134556bc0..2f226590719 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -317,17 +317,13 @@ impl HTMLCollectionMethods for HTMLCollection { } // https://dom.spec.whatwg.org/#dom-htmlcollection-item - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Element>> { - let maybe_elem = self.Item(index); - *found = maybe_elem.is_some(); - maybe_elem + fn IndexedGetter(&self, index: u32) -> Option<Root<Element>> { + self.Item(index) } // check-tidy: no specs after this line - fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<Root<Element>> { - let maybe_elem = self.NamedItem(name); - *found = maybe_elem.is_some(); - maybe_elem + fn NamedGetter(&self, name: DOMString) -> Option<Root<Element>> { + self.NamedItem(name) } // https://dom.spec.whatwg.org/#interface-htmlcollection diff --git a/components/script/dom/htmlformcontrolscollection.rs b/components/script/dom/htmlformcontrolscollection.rs index 9229b854b26..e52a541225f 100644 --- a/components/script/dom/htmlformcontrolscollection.rs +++ b/components/script/dom/htmlformcontrolscollection.rs @@ -77,10 +77,8 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection { } // https://html.spec.whatwg.org/multipage/#dom-htmlformcontrolscollection-nameditem - fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<RadioNodeListOrElement> { - let maybe_elem = self.NamedItem(name); - *found = maybe_elem.is_some(); - maybe_elem + fn NamedGetter(&self, name: DOMString) -> Option<RadioNodeListOrElement> { + self.NamedItem(name) } // https://html.spec.whatwg.org/multipage/#the-htmlformcontrolscollection-interface:supported-property-names @@ -93,7 +91,7 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection { // https://github.com/servo/servo/issues/5875 // // https://dom.spec.whatwg.org/#dom-htmlcollection-item - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Element>> { - self.collection.IndexedGetter(index, found) + fn IndexedGetter(&self, index: u32) -> Option<Root<Element>> { + self.collection.IndexedGetter(index) } } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index db9e3cb8d41..fa16618b564 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -230,9 +230,9 @@ impl HTMLFormElementMethods for HTMLFormElement { } // https://html.spec.whatwg.org/multipage/#dom-form-item - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Element>> { + fn IndexedGetter(&self, index: u32) -> Option<Root<Element>> { let elements = self.Elements(); - elements.IndexedGetter(index, found) + elements.IndexedGetter(index) } } diff --git a/components/script/dom/mimetypearray.rs b/components/script/dom/mimetypearray.rs index 96fc48c86d0..de820f6d06a 100644 --- a/components/script/dom/mimetypearray.rs +++ b/components/script/dom/mimetypearray.rs @@ -46,12 +46,12 @@ impl MimeTypeArrayMethods for MimeTypeArray { } // https://html.spec.whatwg.org/multipage/#dom-mimetypearray-item - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Root<MimeType>> { + fn IndexedGetter(&self, _index: u32) -> Option<Root<MimeType>> { None } // check-tidy: no specs after this line - fn NamedGetter(&self, _name: DOMString, _found: &mut bool) -> Option<Root<MimeType>> { + fn NamedGetter(&self, _name: DOMString) -> Option<Root<MimeType>> { None } diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs index 10b6b8982ae..9edc1b1e93b 100644 --- a/components/script/dom/namednodemap.rs +++ b/components/script/dom/namednodemap.rs @@ -85,17 +85,13 @@ impl NamedNodeMapMethods for NamedNodeMap { } // https://dom.spec.whatwg.org/#dom-namednodemap-item - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Attr>> { - let item = self.Item(index); - *found = item.is_some(); - item + fn IndexedGetter(&self, index: u32) -> Option<Root<Attr>> { + self.Item(index) } // check-tidy: no specs after this line - fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<Root<Attr>> { - let item = self.GetNamedItem(name); - *found = item.is_some(); - item + fn NamedGetter(&self, name: DOMString) -> Option<Root<Attr>> { + self.GetNamedItem(name) } // https://heycam.github.io/webidl/#dfn-supported-property-names diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs index 2503378187e..8f8a5515592 100644 --- a/components/script/dom/nodelist.rs +++ b/components/script/dom/nodelist.rs @@ -75,10 +75,8 @@ impl NodeListMethods for NodeList { } // https://dom.spec.whatwg.org/#dom-nodelist-item - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Node>> { - let item = self.Item(index); - *found = item.is_some(); - item + fn IndexedGetter(&self, index: u32) -> Option<Root<Node>> { + self.Item(index) } } diff --git a/components/script/dom/plugin.rs b/components/script/dom/plugin.rs index dc4ca4fe42d..222e9a2840a 100644 --- a/components/script/dom/plugin.rs +++ b/components/script/dom/plugin.rs @@ -45,12 +45,12 @@ impl PluginMethods for Plugin { } // https://html.spec.whatwg.org/multipage/#dom-plugin-item - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Root<MimeType>> { + fn IndexedGetter(&self, _index: u32) -> Option<Root<MimeType>> { unreachable!() } // check-tidy: no specs after this line - fn NamedGetter(&self, _name: DOMString, _found: &mut bool) -> Option<Root<MimeType>> { + fn NamedGetter(&self, _name: DOMString) -> Option<Root<MimeType>> { unreachable!() } diff --git a/components/script/dom/pluginarray.rs b/components/script/dom/pluginarray.rs index aabba4928a4..aa6b779280d 100644 --- a/components/script/dom/pluginarray.rs +++ b/components/script/dom/pluginarray.rs @@ -50,12 +50,12 @@ impl PluginArrayMethods for PluginArray { } // https://html.spec.whatwg.org/multipage/#dom-pluginarray-item - fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Root<Plugin>> { + fn IndexedGetter(&self, _index: u32) -> Option<Root<Plugin>> { None } // check-tidy: no specs after this line - fn NamedGetter(&self, _name: DOMString, _found: &mut bool) -> Option<Root<Plugin>> { + fn NamedGetter(&self, _name: DOMString) -> Option<Root<Plugin>> { None } diff --git a/components/script/dom/radionodelist.rs b/components/script/dom/radionodelist.rs index d88fc69eacd..9bbdae00c85 100644 --- a/components/script/dom/radionodelist.rs +++ b/components/script/dom/radionodelist.rs @@ -105,7 +105,7 @@ impl RadioNodeListMethods for RadioNodeList { // https://github.com/servo/servo/issues/5875 // // https://dom.spec.whatwg.org/#dom-nodelist-item - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Node>> { - self.node_list.IndexedGetter(index, found) + fn IndexedGetter(&self, index: u32) -> Option<Root<Node>> { + self.node_list.IndexedGetter(index) } } diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index d6d1e1968f8..7827cdb6b15 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -136,10 +136,8 @@ impl StorageMethods for Storage { } // check-tidy: no specs after this line - fn NamedGetter(&self, name: DOMString, found: &mut bool) -> Option<DOMString> { - let item = self.GetItem(name); - *found = item.is_some(); - item + fn NamedGetter(&self, name: DOMString) -> Option<DOMString> { + self.GetItem(name) } fn NamedSetter(&self, name: DOMString, value: DOMString) -> ErrorResult { diff --git a/components/script/dom/stylesheetlist.rs b/components/script/dom/stylesheetlist.rs index 1b7eb643e50..721ac06525c 100644 --- a/components/script/dom/stylesheetlist.rs +++ b/components/script/dom/stylesheetlist.rs @@ -46,9 +46,7 @@ impl StyleSheetListMethods for StyleSheetList { } // check-tidy: no specs after this line - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<StyleSheet>>{ - let item = self.Item(index); - *found = item.is_some(); - item + fn IndexedGetter(&self, index: u32) -> Option<Root<StyleSheet>> { + self.Item(index) } } diff --git a/components/script/dom/testbindingiterable.rs b/components/script/dom/testbindingiterable.rs index 1e462a98531..2ad0df6dbb6 100644 --- a/components/script/dom/testbindingiterable.rs +++ b/components/script/dom/testbindingiterable.rs @@ -34,10 +34,8 @@ impl TestBindingIterable { impl TestBindingIterableMethods for TestBindingIterable { fn Add(&self, v: DOMString) { self.vals.borrow_mut().push(v); } fn Length(&self) -> u32 { self.vals.borrow().len() as u32 } - fn GetItem(&self, n: u32) -> DOMString { self.vals.borrow().get(n as usize).unwrap().clone() } - fn IndexedGetter(&self, n: u32, found: &mut bool) -> DOMString { - let s = self.GetItem(n); - *found = true; - s + fn GetItem(&self, n: u32) -> DOMString { self.IndexedGetter(n).unwrap_or_default() } + fn IndexedGetter(&self, n: u32) -> Option<DOMString> { + self.vals.borrow().get(n as usize).cloned() } } diff --git a/components/script/dom/testbindingproxy.rs b/components/script/dom/testbindingproxy.rs index 3308639305c..45e66bc5919 100644 --- a/components/script/dom/testbindingproxy.rs +++ b/components/script/dom/testbindingproxy.rs @@ -23,10 +23,10 @@ impl TestBindingProxyMethods for TestBindingProxy { fn SetItem(&self, _: u32, _: DOMString) -> () {} fn RemoveItem(&self, _: DOMString) -> () {} fn Stringifier(&self) -> DOMString { DOMString::new() } - fn IndexedGetter(&self, _: u32, _: &mut bool) -> DOMString { DOMString::new() } + fn IndexedGetter(&self, _: u32) -> Option<DOMString> { None } fn NamedDeleter(&self, _: DOMString) -> () {} fn IndexedSetter(&self, _: u32, _: DOMString) -> () {} fn NamedSetter(&self, _: DOMString, _: DOMString) -> () {} - fn NamedGetter(&self, _: DOMString, _: &mut bool) -> DOMString { DOMString::new() } + fn NamedGetter(&self, _: DOMString) -> Option<DOMString> { None } } diff --git a/components/script/dom/touchlist.rs b/components/script/dom/touchlist.rs index ae5313e855e..14bb8a68766 100644 --- a/components/script/dom/touchlist.rs +++ b/components/script/dom/touchlist.rs @@ -42,9 +42,7 @@ impl TouchListMethods for TouchList { } /// https://w3c.github.io/touch-events/#widl-TouchList-item-getter-Touch-unsigned-long-index - fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<Touch>> { - let item = self.Item(index); - *found = item.is_some(); - item + fn IndexedGetter(&self, index: u32) -> Option<Root<Touch>> { + self.Item(index) } } diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 348fb4056cc..1a00f67b80c 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -88,8 +88,7 @@ impl XMLDocumentMethods for XMLDocument { } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString, found: &mut bool) - -> NonZero<*mut JSObject> { - self.upcast::<Document>().NamedGetter(_cx, name, found) + fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> { + self.upcast::<Document>().NamedGetter(_cx, name) } } |