mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Use attribute getter/setter macros for misc DOM attributes.
This fixes a few minor bugs. Also adds some better testing for "unsigned long" attributes.
This commit is contained in:
parent
285e29c066
commit
cf8f2b1874
9 changed files with 214 additions and 67 deletions
|
@ -81,15 +81,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-button-type
|
||||
fn Type(&self) -> DOMString {
|
||||
let mut ty = self.upcast::<Element>().get_string_attribute(&atom!("type"));
|
||||
ty.make_ascii_lowercase();
|
||||
// https://html.spec.whatwg.org/multipage/#attr-button-type
|
||||
match &*ty {
|
||||
"reset" | "button" | "menu" => ty,
|
||||
_ => "submit".to_owned()
|
||||
}
|
||||
}
|
||||
make_enumerated_getter!(Type, "submit", ("reset") | ("button") | ("menu"));
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-button-type
|
||||
make_setter!(SetType, "type");
|
||||
|
|
|
@ -14,7 +14,7 @@ use dom::bindings::global::GlobalRef;
|
|||
use dom::bindings::js::{LayoutJS, Root};
|
||||
use dom::bindings::refcounted::Trusted;
|
||||
use dom::document::Document;
|
||||
use dom::element::{AttributeMutation, Element};
|
||||
use dom::element::AttributeMutation;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
|
||||
|
@ -196,11 +196,8 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-ismap
|
||||
make_bool_getter!(IsMap);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-ismap
|
||||
fn SetIsMap(&self, is_map: bool) {
|
||||
self.upcast::<Element>().set_string_attribute(&atom!("ismap"), is_map.to_string())
|
||||
}
|
||||
make_bool_setter!(SetIsMap, "ismap");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||
fn Width(&self) -> u32 {
|
||||
|
@ -210,9 +207,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||
fn SetWidth(&self, width: u32) {
|
||||
self.upcast::<Element>().set_uint_attribute(&atom!("width"), width)
|
||||
}
|
||||
make_uint_setter!(SetWidth, "width");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||
fn Height(&self) -> u32 {
|
||||
|
@ -222,9 +217,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||
fn SetHeight(&self, height: u32) {
|
||||
self.upcast::<Element>().set_uint_attribute(&atom!("height"), height)
|
||||
}
|
||||
make_uint_setter!(SetHeight, "height");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth
|
||||
fn NaturalWidth(&self) -> u32 {
|
||||
|
|
|
@ -91,9 +91,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
|||
make_bool_getter!(Disabled);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-option-disabled
|
||||
fn SetDisabled(&self, disabled: bool) {
|
||||
self.upcast::<Element>().set_bool_attribute(&atom!("disabled"), disabled)
|
||||
}
|
||||
make_bool_setter!(SetDisabled, "disabled");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
||||
fn Text(&self) -> DOMString {
|
||||
|
|
|
@ -53,7 +53,7 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement {
|
|||
make_uint_getter!(ColSpan, "colspan", DEFAULT_COLSPAN);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tdth-colspan
|
||||
make_uint_setter!(SetColSpan, "colspan");
|
||||
make_uint_setter!(SetColSpan, "colspan", DEFAULT_COLSPAN);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tdth-cellindex
|
||||
fn CellIndex(&self) -> i32 {
|
||||
|
|
|
@ -912,36 +912,6 @@
|
|||
[img.crossOrigin: IDL set to "USE-CREDENTIALS" followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to "" followed by hasAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to "" followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to undefined followed by hasAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to undefined followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to null followed by hasAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to null followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to false followed by hasAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to false followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to NaN followed by hasAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[img.isMap: IDL set to NaN followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[img.width: IDL set to 1 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -22107,3 +22077,75 @@
|
|||
[data.itemValue (<data value>): IDL set to object "test-valueOf" followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[object.hspace: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[object.hspace: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[object.hspace: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[object.hspace: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[object.vspace: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[object.vspace: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[object.vspace: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[object.vspace: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[video.width: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[video.width: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[video.width: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[video.width: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[video.height: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[video.height: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[video.height: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[video.height: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.width: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.width: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.width: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.width: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.height: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.height: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.height: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[canvas.height: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -10869,3 +10869,75 @@
|
|||
[data.itemValue (<data value>): IDL set to object "test-valueOf" followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[applet.hspace: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[applet.hspace: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[applet.hspace: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[applet.hspace: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[applet.vspace: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[applet.vspace: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[applet.vspace: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[applet.vspace: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.hspace: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.hspace: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.hspace: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.hspace: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollAmount: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollAmount: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollAmount: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollAmount: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollDelay: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollDelay: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollDelay: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.scrollDelay: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.vspace: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.vspace: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.vspace: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[marquee.vspace: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -17691,3 +17691,51 @@
|
|||
[data.itemValue (<data value>): IDL set to object "test-valueOf" followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[colgroup.span: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[colgroup.span: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[colgroup.span: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[colgroup.span: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[col.span: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[col.span: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[col.span: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[col.span: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[td.rowSpan: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[td.rowSpan: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[td.rowSpan: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[td.rowSpan: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[th.rowSpan: IDL set to 2147483648 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[th.rowSpan: IDL set to 2147483648 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
[th.rowSpan: IDL set to 4294967295 followed by getAttribute()]
|
||||
expected: FAIL
|
||||
|
||||
[th.rowSpan: IDL set to 4294967295 followed by IDL get]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
type: testharness
|
||||
[ask for reset on node remove, non multiple.]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -139,10 +139,9 @@ var maxUnsigned = 4294967295;
|
|||
*
|
||||
* Note that all tests/expected values are only baselines, and can be expanded
|
||||
* with additional tests hardcoded into the function for particular types if
|
||||
* necessary (e.g., enum). null means "default" as a DOM expected value, and
|
||||
* "throw an INDEX_SIZE_ERR exception" as an IDL expected value. (This is a
|
||||
* kind of stupid and fragile convention, but it's simple and works for now.)
|
||||
* Expected DOM values are cast to strings by adding "".
|
||||
* necessary. For example, a special codepath is used for enums, and for
|
||||
* IDL setters which throw an exception. null means "defaultVal" is the
|
||||
* expected value. Expected DOM values are cast to strings by adding "".
|
||||
*
|
||||
* TODO: Test strings that aren't valid UTF-16. Desired behavior is not clear
|
||||
* here at the time of writing, see
|
||||
|
@ -379,8 +378,8 @@ ReflectionTests.typeMap = {
|
|||
}
|
||||
return parsed;
|
||||
},
|
||||
"idlTests": [minInt, -36, -1, 0, 1, maxInt],
|
||||
"idlDomExpected": [null, null, null, 0, 1, maxInt]
|
||||
"idlTests": [minInt, -36, -1, 0, 1, maxInt],
|
||||
"idlDomExpected": [null/*exception*/, null/*exception*/, null/*exception*/, 0, 1, maxInt]
|
||||
},
|
||||
/**
|
||||
* "If a reflecting IDL attribute is an unsigned integer type (unsigned
|
||||
|
@ -416,8 +415,9 @@ ReflectionTests.typeMap = {
|
|||
}
|
||||
return parsed;
|
||||
},
|
||||
"idlTests": [0, 1, 257, 2147483647, "-0"],
|
||||
"idlIdlExpected": [0, 1, 257, 2147483647, 0]
|
||||
"idlTests": [0, 1, 257, maxInt, "-0", maxInt + 1, maxUnsigned],
|
||||
"idlIdlExpected": [0, 1, 257, maxInt, 0, null, null],
|
||||
"idlDomExpected": [0, 1, 257, maxInt, 0, null, null],
|
||||
},
|
||||
/**
|
||||
* "If a reflecting IDL attribute is an unsigned integer type (unsigned
|
||||
|
@ -457,8 +457,8 @@ ReflectionTests.typeMap = {
|
|||
}
|
||||
return parsed;
|
||||
},
|
||||
"idlTests": [0, 1, 2147483647],
|
||||
"idlDomExpected": [null, 1, 2147483647]
|
||||
"idlTests": [0, 1, maxInt, maxInt + 1, maxUnsigned],
|
||||
"idlDomExpected": [null/*exception*/, 1, maxInt, null, null]
|
||||
},
|
||||
/**
|
||||
* "If a reflecting IDL attribute is a floating point number type (double),
|
||||
|
@ -610,8 +610,8 @@ ReflectionTests.doReflects = function(data, idlName, idlObj, domName, domObj) {
|
|||
var domTests = typeInfo.domTests.slice(0);
|
||||
var domExpected = typeInfo.domExpected.map(function(val) { return val === null ? defaultVal : val; });
|
||||
var idlTests = typeInfo.idlTests.slice(0);
|
||||
var idlDomExpected = typeInfo.idlDomExpected.slice(0);
|
||||
var idlIdlExpected = typeInfo.idlIdlExpected.slice(0);
|
||||
var idlDomExpected = typeInfo.idlDomExpected.map(function(val) { return val === null ? defaultVal : val; });
|
||||
var idlIdlExpected = typeInfo.idlIdlExpected.map(function(val) { return val === null ? defaultVal : val; });
|
||||
switch (data.type) {
|
||||
// Extra tests and other special-casing
|
||||
case "boolean":
|
||||
|
@ -712,7 +712,8 @@ ReflectionTests.doReflects = function(data, idlName, idlObj, domName, domObj) {
|
|||
}
|
||||
|
||||
for (var i = 0; i < idlTests.length; i++) {
|
||||
if (idlDomExpected[i] === null && data.type != "enum") {
|
||||
if ((data.type == "limited long" && idlTests[i] < 0) ||
|
||||
(data.type == "limited unsigned long" && idlTests[i] == 0)) {
|
||||
ReflectionHarness.testException("INDEX_SIZE_ERR", function() {
|
||||
idlObj[idlName] = idlTests[i];
|
||||
}, "IDL set to " + ReflectionHarness.stringRep(idlTests[i]) + " must throw INDEX_SIZE_ERR");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue