diff options
author | yvt <i@yvt.jp> | 2021-07-11 22:22:43 +0900 |
---|---|---|
committer | yvt <i@yvt.jp> | 2021-07-11 22:22:43 +0900 |
commit | fd177a9199baa580d17f992af51544d4afd5f69e (patch) | |
tree | 17b964ad2d58964b9f4c6c8984383dce5ec9ac05 | |
parent | 28c670d6c3bfa084fc99f913f3f1caa87e6d7dbd (diff) | |
parent | 4181962504cbdec05232c53f9ab2bab17d045530 (diff) | |
download | servo-fd177a9199baa580d17f992af51544d4afd5f69e.tar.gz servo-fd177a9199baa580d17f992af51544d4afd5f69e.zip |
Merge remote-tracking branch 'upstream/master' into feat-cow-infra
9 files changed, 92 insertions, 55 deletions
diff --git a/Cargo.lock b/Cargo.lock index e4c617c4b4e..5545a73432e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3808,7 +3808,7 @@ dependencies = [ [[package]] name = "mozjs" version = "0.14.1" -source = "git+https://github.com/servo/rust-mozjs#fe738cca3320ffcbc4c520ced79c2141ceabf42d" +source = "git+https://github.com/servo/rust-mozjs#a8b688ad32a852172536443d77baa844f59a23fa" dependencies = [ "cc", "lazy_static", diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 4a102aacb45..791bb687568 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -3479,6 +3479,9 @@ let traps = ProxyTraps { delete_: Some(%(delete)s), enumerate: None, getPrototypeIfOrdinary: Some(proxyhandler::get_prototype_if_ordinary), + getPrototype: None, + setPrototype: None, + setImmutablePrototype: None, preventExtensions: Some(proxyhandler::prevent_extensions), isExtensible: Some(proxyhandler::is_extensible), has: None, diff --git a/components/script/dom/htmlprogresselement.rs b/components/script/dom/htmlprogresselement.rs index dcd2f018734..718d1999256 100644 --- a/components/script/dom/htmlprogresselement.rs +++ b/components/script/dom/htmlprogresselement.rs @@ -4,8 +4,10 @@ use crate::dom::bindings::codegen::Bindings::HTMLProgressElementBinding::HTMLProgressElementMethods; use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::num::Finite; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::document::Document; +use crate::dom::element::Element; use crate::dom::htmlelement::HTMLElement; use crate::dom::node::Node; use crate::dom::nodelist::NodeList; @@ -48,4 +50,76 @@ impl HTMLProgressElement { impl HTMLProgressElementMethods for HTMLProgressElement { // https://html.spec.whatwg.org/multipage/#dom-lfe-labels make_labels_getter!(Labels, labels_node_list); + + // https://html.spec.whatwg.org/multipage/#dom-progress-value + fn Value(&self) -> Finite<f64> { + // In case of missing `value`, parse error, or negative `value`, `value` should be + // interpreted as 0. As `get_string_attribute` returns an empty string in case the + // attribute is missing, this case is handeled as the default of the `map_or` function. + // + // It is safe to wrap the number coming from `parse_floating_point_number` as it will + // return Err on inf and nan + self.upcast::<Element>() + .get_string_attribute(&local_name!("value")) + .parse_floating_point_number() + .map_or(Finite::wrap(0.0), |v| { + if v < 0.0 { + Finite::wrap(0.0) + } else { + Finite::wrap(v.min(*self.Max())) + } + }) + } + + // https://html.spec.whatwg.org/multipage/#dom-progress-value + fn SetValue(&self, new_val: Finite<f64>) { + if 0.0 <= *new_val { + self.upcast::<Element>() + .set_string_attribute(&local_name!("value"), (*new_val).to_string().into()); + } + } + + // https://html.spec.whatwg.org/multipage/#dom-progress-max + fn Max(&self) -> Finite<f64> { + // In case of missing `max`, parse error, or negative `max`, `max` should be interpreted as + // 1.0. As `get_string_attribute` returns an empty string in case the attribute is missing, + // these cases are handeled by `map_or` + self.upcast::<Element>() + .get_string_attribute(&local_name!("max")) + .parse_floating_point_number() + .map_or(Finite::wrap(1.0), |m| { + if m <= 0.0 { + Finite::wrap(1.0) + } else { + Finite::wrap(m) + } + }) + } + + // https://html.spec.whatwg.org/multipage/#dom-progress-max + fn SetMax(&self, new_val: Finite<f64>) { + self.upcast::<Element>() + .set_string_attribute(&local_name!("max"), (*new_val).to_string().into()); + } + + // https://html.spec.whatwg.org/multipage/#dom-progress-position + fn Position(&self) -> Finite<f64> { + let value = self + .upcast::<Element>() + .get_string_attribute(&local_name!("value")); + if value.is_empty() { + Finite::wrap(-1.0) + } else { + let value = self.Value(); + let max = self.Max(); + // An unsafe Finite constructor might be nice here, as it's unlikely for the + // compiler to infer the following guarantees. It is probably premature + // optimization though. + // + // Safety: `ret` have to be a finite, defined number. This is the case since both + // value and max is finite, max > 0, and a value >> max cannot exist, as + // Self::Value(&self) enforces value <= max. + Finite::wrap(*value / *max) + } + } } diff --git a/components/script/dom/webidls/HTMLProgressElement.webidl b/components/script/dom/webidls/HTMLProgressElement.webidl index c901e379659..0c25d86977a 100644 --- a/components/script/dom/webidls/HTMLProgressElement.webidl +++ b/components/script/dom/webidls/HTMLProgressElement.webidl @@ -7,10 +7,10 @@ interface HTMLProgressElement : HTMLElement { [HTMLConstructor] constructor(); - // [CEReactions] - // attribute double value; - // [CEReactions] - // attribute double max; - // readonly attribute double position; + [CEReactions] + attribute double value; + [CEReactions] + attribute double max; + readonly attribute double position; readonly attribute NodeList labels; }; diff --git a/components/script/dom/windowproxy.rs b/components/script/dom/windowproxy.rs index 0f92e4b3367..244b42dc8a5 100644 --- a/components/script/dom/windowproxy.rs +++ b/components/script/dom/windowproxy.rs @@ -1040,6 +1040,8 @@ unsafe extern "C" fn get_prototype_if_ordinary( } static PROXY_HANDLER: ProxyTraps = ProxyTraps { + // TODO: These traps should change their behavior depending on + // `IsPlatformObjectSameOrigin(this.[[Window]])` enter: None, getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor), defineProperty: Some(defineProperty), @@ -1047,6 +1049,9 @@ static PROXY_HANDLER: ProxyTraps = ProxyTraps { delete_: None, enumerate: None, getPrototypeIfOrdinary: Some(get_prototype_if_ordinary), + getPrototype: None, // TODO: return `null` if cross origin-domain + setPrototype: None, + setImmutablePrototype: None, preventExtensions: None, isExtensible: None, has: Some(has), @@ -1189,6 +1194,9 @@ static XORIGIN_PROXY_HANDLER: ProxyTraps = ProxyTraps { delete_: Some(delete_xorigin), enumerate: None, getPrototypeIfOrdinary: None, + getPrototype: None, + setPrototype: None, + setImmutablePrototype: None, preventExtensions: Some(preventExtensions_xorigin), isExtensible: None, has: Some(has_xorigin), diff --git a/tests/wpt/metadata/custom-elements/reactions/HTMLProgressElement.html.ini b/tests/wpt/metadata/custom-elements/reactions/HTMLProgressElement.html.ini index 19974beabaf..73f6be71795 100644 --- a/tests/wpt/metadata/custom-elements/reactions/HTMLProgressElement.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/HTMLProgressElement.html.ini @@ -1,13 +1 @@ -[HTMLProgressElement.html] - [max on HTMLProgressElement must enqueue an attributeChanged reaction when replacing an existing attribute] - expected: FAIL - - [max on HTMLProgressElement must enqueue an attributeChanged reaction when adding max content attribute] - expected: FAIL - - [value on HTMLProgressElement must enqueue an attributeChanged reaction when adding value content attribute] - expected: FAIL - - [value on HTMLProgressElement must enqueue an attributeChanged reaction when replacing an existing attribute] - expected: FAIL - +[HTMLProgressElement.html]
\ No newline at end of file diff --git a/tests/wpt/metadata/html/dom/idlharness.https.html.ini b/tests/wpt/metadata/html/dom/idlharness.https.html.ini index f2a27054b52..e710581f2e7 100644 --- a/tests/wpt/metadata/html/dom/idlharness.https.html.ini +++ b/tests/wpt/metadata/html/dom/idlharness.https.html.ini @@ -2313,9 +2313,6 @@ [HTMLAudioElement interface: named constructor without 'new'] expected: FAIL - [HTMLProgressElement interface: document.createElement("progress") must inherit property "value" with the proper type] - expected: FAIL - [HTMLEmbedElement interface: attribute name] expected: FAIL @@ -2343,12 +2340,6 @@ [HTMLInputElement interface: createInput("tel") must inherit property "align" with the proper type] expected: FAIL - [HTMLProgressElement interface: document.createElement("progress") must inherit property "position" with the proper type] - expected: FAIL - - [HTMLProgressElement interface: attribute position] - expected: FAIL - [HTMLAreaElement interface: attribute shape] expected: FAIL @@ -2490,9 +2481,6 @@ [HTMLInputElement interface: createInput("month") must inherit property "autofocus" with the proper type] expected: FAIL - [HTMLProgressElement interface: document.createElement("progress") must inherit property "max" with the proper type] - expected: FAIL - [HTMLMediaElement interface: document.createElement("audio") must inherit property "seekable" with the proper type] expected: FAIL @@ -2727,9 +2715,6 @@ [HTMLInputElement interface: createInput("reset") must inherit property "useMap" with the proper type] expected: FAIL - [HTMLProgressElement interface: attribute max] - expected: FAIL - [HTMLBRElement interface: attribute clear] expected: FAIL @@ -3627,9 +3612,6 @@ [HTMLAreaElement interface: document.createElement("area") must inherit property "download" with the proper type] expected: FAIL - [HTMLProgressElement interface: attribute value] - expected: FAIL - [HTMLTableSectionElement interface: document.createElement("tbody") must inherit property "chOff" with the proper type] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress-2.html.ini b/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress-2.html.ini index 4c7bbd6a7e2..86b2b7a9c59 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress-2.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress-2.html.ini @@ -1,14 +1,2 @@ [progress-2.html] type: testharness - [progress position equals -1] - expected: FAIL - - [progress value equals 0] - expected: FAIL - - [progress value equals .5] - expected: FAIL - - [progress position equals 0] - expected: FAIL - diff --git a/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress.window.js.ini b/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress.window.js.ini index 63a0690d30f..6de39c99fe5 100644 --- a/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress.window.js.ini +++ b/tests/wpt/metadata/html/semantics/forms/the-progress-element/progress.window.js.ini @@ -1,8 +1,2 @@ [progress.window.html] type: testharness - [If value > max, then current value = max] - expected: FAIL - - [If value < max, then current value = value] - expected: FAIL - |