Auto merge of #25373 - pshaughn:ce_options_string, r=jdm

let document.createElement[NS] accept a string for options

The string actually does nothing, but spec and WPT don't want it to do anything. https://dom.spec.whatwg.org/#dom-document-createelement only cares about the options value when it's a dictionary, and the WPT test on the string case is just that it isn't throwing an exception.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25008

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2019-12-23 22:21:47 -05:00 committed by GitHub
commit dadbc36f8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 18 deletions

View file

@ -11,7 +11,6 @@ use crate::dom::bindings::callback::ExceptionHandling;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::BeforeUnloadEventBinding::BeforeUnloadEventBinding::BeforeUnloadEventMethods;
use crate::dom::bindings::codegen::Bindings::DocumentBinding;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::ElementCreationOptions;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, DocumentReadyState,
};
@ -25,7 +24,7 @@ use crate::dom::bindings::codegen::Bindings::TouchBinding::TouchMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::{
FrameRequestCallback, ScrollBehavior, WindowMethods,
};
use crate::dom::bindings::codegen::UnionTypes::NodeOrString;
use crate::dom::bindings::codegen::UnionTypes::{NodeOrString, StringOrElementCreationOptions};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::num::Finite;
@ -3622,7 +3621,7 @@ impl DocumentMethods for Document {
fn CreateElement(
&self,
mut local_name: DOMString,
options: &ElementCreationOptions,
options: StringOrElementCreationOptions,
) -> Fallible<DomRoot<Element>> {
if xml_name_type(&local_name) == InvalidXMLName {
debug!("Not a valid element name");
@ -3643,7 +3642,12 @@ impl DocumentMethods for Document {
};
let name = QualName::new(None, ns, LocalName::from(local_name));
let is = options.is.as_ref().map(|is| LocalName::from(&**is));
let is = match options {
StringOrElementCreationOptions::String(_) => None,
StringOrElementCreationOptions::ElementCreationOptions(options) => {
options.is.as_ref().map(|is| LocalName::from(&**is))
},
};
Ok(Element::create(
name,
is,
@ -3658,11 +3662,16 @@ impl DocumentMethods for Document {
&self,
namespace: Option<DOMString>,
qualified_name: DOMString,
options: &ElementCreationOptions,
options: StringOrElementCreationOptions,
) -> Fallible<DomRoot<Element>> {
let (namespace, prefix, local_name) = validate_and_extract(namespace, &qualified_name)?;
let name = QualName::new(prefix, namespace, local_name);
let is = options.is.as_ref().map(|is| LocalName::from(&**is));
let is = match options {
StringOrElementCreationOptions::String(_) => None,
StringOrElementCreationOptions::ElementCreationOptions(options) => {
options.is.as_ref().map(|is| LocalName::from(&**is))
},
};
Ok(Element::create(
name,
is,

View file

@ -9,6 +9,7 @@ use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
DocumentMethods, ElementCreationOptions,
};
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::UnionTypes::StringOrElementCreationOptions;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
@ -105,10 +106,13 @@ impl DOMImplementationMethods for DOMImplementation {
let maybe_elem = if qname.is_empty() {
None
} else {
let options = ElementCreationOptions { is: None };
let options =
StringOrElementCreationOptions::ElementCreationOptions(ElementCreationOptions {
is: None,
});
match doc
.upcast::<Document>()
.CreateElementNS(maybe_namespace, qname, &options)
.CreateElementNS(maybe_namespace, qname, options)
{
Err(error) => return Err(error),
Ok(elem) => Some(elem),

View file

@ -34,9 +34,10 @@ interface Document : Node {
HTMLCollection getElementsByClassName(DOMString classNames);
[CEReactions, NewObject, Throws]
Element createElement(DOMString localName, optional ElementCreationOptions options = {});
Element createElement(DOMString localName, optional (DOMString or ElementCreationOptions) options = {});
[CEReactions, NewObject, Throws]
Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional ElementCreationOptions options = {});
Element createElementNS(DOMString? namespace, DOMString qualifiedName,
optional (DOMString or ElementCreationOptions) options = {});
[NewObject]
DocumentFragment createDocumentFragment();
[NewObject]

View file

@ -1,7 +1,3 @@
[Document-createElement.html]
[document.createElement must create an instance of autonomous custom elements when it has is attribute]
expected: FAIL
[document.createElement()'s second argument is to be ignored when it's a string]
expected: FAIL

View file

@ -1,4 +0,0 @@
[Document-createElementNS.html]
[document.createElementNS()'s third argument is to be ignored when it's a string]
expected: FAIL