Implement HTMLOptionElement named constructor

This commit is contained in:
teapotd 2019-12-26 02:22:58 +01:00
parent 8002c6bc53
commit 155f69ce48
13 changed files with 136 additions and 93 deletions

View file

@ -8,12 +8,14 @@ use crate::dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
use crate::dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementBinding::HTMLSelectElementMethods;
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::characterdata::CharacterData;
use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::element::{AttributeMutation, CustomElementCreationMode, Element, ElementCreator};
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
@ -22,8 +24,9 @@ use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
use crate::dom::text::Text;
use crate::dom::virtualmethods::VirtualMethods;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use html5ever::{LocalName, Prefix, QualName};
use std::cell::Cell;
use style::element_state::ElementState;
use style::str::{split_html_space_chars, str_join};
@ -72,6 +75,37 @@ impl HTMLOptionElement {
)
}
// https://html.spec.whatwg.org/multipage/#dom-option
pub fn Option(
window: &Window,
text: DOMString,
value: Option<DOMString>,
default_selected: bool,
selected: bool,
) -> Fallible<DomRoot<HTMLOptionElement>> {
let element = Element::create(
QualName::new(None, ns!(html), local_name!("option")),
None,
&window.Document(),
ElementCreator::ScriptCreated,
CustomElementCreationMode::Synchronous,
);
let option = DomRoot::downcast::<HTMLOptionElement>(element).unwrap();
if !text.is_empty() {
option.upcast::<Node>().SetTextContent(Some(text))
}
if let Some(val) = value {
option.SetValue(val)
}
option.SetDefaultSelected(default_selected);
option.set_selectedness(selected);
Ok(option)
}
pub fn set_selectedness(&self, selected: bool) {
self.selectedness.set(selected);
}

View file

@ -3,9 +3,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://html.spec.whatwg.org/multipage/#htmloptionelement
[Exposed=Window/*, NamedConstructor=Option(optional DOMString text = "", optional DOMString value,
[Exposed=Window, NamedConstructor=Option(optional DOMString text = "", optional DOMString value,
optional boolean defaultSelected = false,
optional boolean selected = false)*/]
optional boolean selected = false)]
interface HTMLOptionElement : HTMLElement {
[HTMLConstructor] constructor();

View file

@ -2106,9 +2106,6 @@
[HTMLSelectElement interface: attribute willValidate]
expected: FAIL
[HTMLOptionElement interface: named constructor]
expected: FAIL
[HTMLMarqueeElement interface: attribute hspace]
expected: FAIL
@ -2253,9 +2250,6 @@
[HTMLInputElement interface: createInput("url") must inherit property "checkValidity()" with the proper type]
expected: FAIL
[HTMLOptionElement interface: named constructor prototype property]
expected: FAIL
[HTMLInputElement interface: createInput("week") must inherit property "validationMessage" with the proper type]
expected: FAIL
@ -3147,9 +3141,6 @@
[HTMLInputElement interface: calling stepDown(long) on createInput("password") with too few arguments must throw TypeError]
expected: FAIL
[HTMLOptionElement interface: named constructor object]
expected: FAIL
[HTMLFrameElement interface: document.createElement("frame") must inherit property "frameBorder" with the proper type]
expected: FAIL
@ -3261,9 +3252,6 @@
[HTMLMarqueeElement interface: attribute bgColor]
expected: FAIL
[Stringification of new Option()]
expected: FAIL
[HTMLInputElement interface: createInput("file") must inherit property "width" with the proper type]
expected: FAIL
@ -3309,9 +3297,6 @@
[HTMLAreaElement interface: document.createElement("area") must inherit property "coords" with the proper type]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "label" with the proper type]
expected: FAIL
[HTMLTableCellElement interface: document.createElement("th") must inherit property "chOff" with the proper type]
expected: FAIL
@ -3348,9 +3333,6 @@
[HTMLMarqueeElement interface: document.createElement("marquee") must inherit property "scrollAmount" with the proper type]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "form" with the proper type]
expected: FAIL
[HTMLInputElement interface: createInput("datetime-local") must inherit property "reportValidity()" with the proper type]
expected: FAIL
@ -3441,9 +3423,6 @@
[HTMLSelectElement interface: operation setCustomValidity(DOMString)]
expected: FAIL
[HTMLOptionElement interface: named constructor name]
expected: FAIL
[HTMLVideoElement interface: document.createElement("video") must inherit property "height" with the proper type]
expected: FAIL
@ -3456,9 +3435,6 @@
[HTMLTableElement interface: attribute rules]
expected: FAIL
[HTMLOptionElement interface: named constructor length]
expected: FAIL
[HTMLInputElement interface: createInput("email") must inherit property "stepUp(long)" with the proper type]
expected: FAIL
@ -3744,9 +3720,6 @@
[HTMLInputElement interface: document.createElement("input") must inherit property "valueAsNumber" with the proper type]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "disabled" with the proper type]
expected: FAIL
[HTMLFieldSetElement interface: attribute name]
expected: FAIL
@ -3963,9 +3936,6 @@
[HTMLAreaElement interface: attribute noHref]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "value" with the proper type]
expected: FAIL
[HTMLInputElement interface: createInput("number") must inherit property "valueAsNumber" with the proper type]
expected: FAIL
@ -4182,9 +4152,6 @@
[HTMLMarqueeElement interface: document.createElement("marquee") must inherit property "trueSpeed" with the proper type]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "selected" with the proper type]
expected: FAIL
[HTMLElement interface: attribute contentEditable]
expected: FAIL
@ -4290,9 +4257,6 @@
[HTMLFormElement interface: document.createElement("form") must inherit property "rel" with the proper type]
expected: FAIL
[HTMLOptionElement must be primary interface of new Option()]
expected: FAIL
[HTMLIFrameElement interface: attribute allowPaymentRequest]
expected: FAIL
@ -4350,9 +4314,6 @@
[HTMLBodyElement interface: document.createElement("body") must inherit property "vLink" with the proper type]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "text" with the proper type]
expected: FAIL
[HTMLMediaElement interface: new Audio() must inherit property "seekable" with the proper type]
expected: FAIL
@ -4521,9 +4482,6 @@
[HTMLMediaElement interface: operation getStartDate()]
expected: FAIL
[HTMLOptionElement interface: new Option() must inherit property "defaultSelected" with the proper type]
expected: FAIL
[HTMLInputElement interface: createInput("email") must inherit property "list" with the proper type]
expected: FAIL
@ -5028,3 +4986,6 @@
[SVGAElement includes HTMLHyperlinkElementUtils: member names are unique]
expected: FAIL
[HTMLOptionElement interface: named constructor without 'new']
expected: FAIL

View file

@ -1,5 +0,0 @@
[htmloptionscollection.html]
type: testharness
[HTMLOptionsCollection.add method insert HTMLOptionElement Option element]
expected: FAIL

View file

@ -1,6 +1,5 @@
[form-validation-checkValidity.html]
type: testharness
expected: ERROR
[[INPUT in TEXT status\] no constraint]
expected: FAIL
@ -427,3 +426,27 @@
[[INPUT in EMAIL status\] not suffering from being too long (in a form)]
expected: FAIL
[[select\] no constraint (in a form)]
expected: FAIL
[[select\] suffering from being missing (in a form)]
expected: FAIL
[[textarea\] suffering from being missing (in a form)]
expected: FAIL
[[select\] no constraint]
expected: FAIL
[[select\] suffering from being missing]
expected: FAIL
[[textarea\] no constraint]
expected: FAIL
[[textarea\] suffering from being missing]
expected: FAIL
[[textarea\] no constraint (in a form)]
expected: FAIL

View file

@ -1,6 +1,5 @@
[form-validation-reportValidity.html]
type: testharness
expected: ERROR
[[INPUT in TEXT status\] no constraint]
expected: FAIL
@ -433,3 +432,27 @@
[[INPUT in EMAIL status\] not suffering from being too long (in a form)]
expected: FAIL
[[select\] no constraint (in a form)]
expected: FAIL
[[select\] suffering from being missing (in a form)]
expected: FAIL
[[textarea\] suffering from being missing (in a form)]
expected: FAIL
[[select\] no constraint]
expected: FAIL
[[select\] suffering from being missing]
expected: FAIL
[[textarea\] no constraint]
expected: FAIL
[[textarea\] suffering from being missing]
expected: FAIL
[[textarea\] no constraint (in a form)]
expected: FAIL

View file

@ -1,6 +1,5 @@
[form-validation-validity-customError.html]
type: testharness
expected: ERROR
[[input\] The validity.customError must be true if the custom validity error message is not empty]
expected: FAIL
@ -13,3 +12,15 @@
[[button\] The validity.customError must be false if the custom validity error message is empty]
expected: FAIL
[[select\] The validity.customError must be false i the custom validity error message is empty]
expected: FAIL
[[select\] The validity.customError must be true if the custom validity error message is not empty]
expected: FAIL
[[textarea\] The validity.customError must be false if the custom validity error message is empty]
expected: FAIL
[[textarea\] The validity.customError must be true if the custom validity error message is not empty]
expected: FAIL

View file

@ -1,6 +1,5 @@
[form-validation-validity-valid.html]
type: testharness
expected: ERROR
[[INPUT in TEXT status\] validity.valid must be false if validity.tooLong is true]
expected: FAIL
@ -154,3 +153,6 @@
[[INPUT in DATETIME-LOCAL status\] validity.valid must be false if validity.valueMissing is true]
expected: FAIL
[[textarea\] validity.valid must be false if validity.valueMissing is true]
expected: FAIL

View file

@ -1,6 +1,5 @@
[form-validation-validity-valueMissing.html]
type: testharness
expected: ERROR
[[INPUT in TEXT status\] The required attribute is not set]
expected: FAIL
@ -304,3 +303,15 @@
[[INPUT in DATETIME-LOCAL status\] The value attribute is empty string]
expected: FAIL
[[textarea\] The value is not empty]
expected: FAIL
[[textarea\] The value is empty]
expected: FAIL
[[textarea\] The required attribute is not set]
expected: FAIL
[[select\] Selected the option with value equals to empty]
expected: FAIL

View file

@ -1,6 +1,5 @@
[form-validation-willValidate.html]
type: testharness
expected: ERROR
[[INPUT in HIDDEN status\] Must be barred from the constraint validation]
expected: FAIL
@ -268,3 +267,21 @@
[[output\] The willValidate attribute must be false since OUTPUT is not a submittable element]
expected: FAIL
[[textarea\] Must be barred from the constraint validation]
expected: FAIL
[[textarea\] The willValidate attribute must be false if it has a datalist ancestor]
expected: FAIL
[[textarea\] The willValidate attribute must be true if an element is mutable]
expected: FAIL
[[select\] The willValidate attribute must be false if it has a datalist ancestor]
expected: FAIL
[[select\] The willValidate attribute must be true if an element is mutable]
expected: FAIL
[[select\] Must be barred from the constraint validation]
expected: FAIL

View file

@ -1,35 +0,0 @@
[option-element-constructor.html]
type: testharness
[Option constructor with no arguments]
expected: FAIL
[Option constructor with falsy arguments]
expected: FAIL
[Option constructor creates HTMLOptionElement with specified text and value]
expected: FAIL
[Option constructor handles selectedness correctly when specified with defaultSelected only]
expected: FAIL
[Option constructor handles selectedness correctly, even when incongruous with defaultSelected]
expected: FAIL
[Option constructor treats undefined text and value correctly]
expected: FAIL
[Option constructor treats empty text and value correctly]
expected: FAIL
[Option constructor treats falsy selected and defaultSelected correctly]
expected: FAIL
[Option constructor treats truthy selected and defaultSelected correctly]
expected: FAIL
[Option constructor does not set dirtiness (so, manipulating the selected content attribute still updates the selected IDL attribute)]
expected: FAIL
[Prototype of object created with named constructor]
expected: FAIL

View file

@ -19024,7 +19024,7 @@
"testharness"
],
"mozilla/interfaces.html": [
"08e8181e6e639caeaecd84c16d582c0ec3f99474",
"945a8b33a109b0cc37db9351f94b9afd3eac798e",
"testharness"
],
"mozilla/interfaces.js": [

View file

@ -186,6 +186,7 @@ test_interfaces([
"NodeList",
"OfflineAudioCompletionEvent",
"OfflineAudioContext",
"Option",
"OscillatorNode",
"PageTransitionEvent",
"PannerNode",