diff --git a/components/script/dom/elementinternals.rs b/components/script/dom/elementinternals.rs index 308515b853b..5a35cd5caaf 100644 --- a/components/script/dom/elementinternals.rs +++ b/components/script/dom/elementinternals.rs @@ -6,6 +6,7 @@ use std::cell::Cell; use dom_struct::dom_struct; use html5ever::local_name; +use js::context::JSContext; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::ElementInternalsBinding::{ @@ -362,19 +363,19 @@ impl ElementInternalsMethods for ElementInternals { } /// - fn CheckValidity(&self, can_gc: CanGc) -> Fallible { + fn CheckValidity(&self, cx: &mut JSContext) -> Fallible { if !self.is_target_form_associated() { return Err(Error::NotSupported(None)); } - Ok(self.check_validity(can_gc)) + Ok(self.check_validity(cx)) } /// - fn ReportValidity(&self, can_gc: CanGc) -> Fallible { + fn ReportValidity(&self, cx: &mut JSContext) -> Fallible { if !self.is_target_form_associated() { return Err(Error::NotSupported(None)); } - Ok(self.report_validity(can_gc)) + Ok(self.report_validity(cx)) } /// diff --git a/components/script/dom/html/htmlbuttonelement.rs b/components/script/dom/html/htmlbuttonelement.rs index b8f0cc7daaa..ae25308e4a1 100644 --- a/components/script/dom/html/htmlbuttonelement.rs +++ b/components/script/dom/html/htmlbuttonelement.rs @@ -7,6 +7,7 @@ use std::default::Default; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix, local_name}; +use js::context::JSContext; use js::rust::HandleObject; use stylo_dom::ElementState; @@ -182,13 +183,13 @@ impl HTMLButtonElementMethods for HTMLButtonElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/html/htmlfieldsetelement.rs b/components/script/dom/html/htmlfieldsetelement.rs index 0752e0bd056..2f39dd7407c 100644 --- a/components/script/dom/html/htmlfieldsetelement.rs +++ b/components/script/dom/html/htmlfieldsetelement.rs @@ -6,6 +6,7 @@ use std::default::Default; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix, local_name}; +use js::context::JSContext; use js::rust::HandleObject; use stylo_dom::ElementState; @@ -127,13 +128,13 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/html/htmlformelement.rs b/components/script/dom/html/htmlformelement.rs index b0133dd7ef3..a4d83344b66 100644 --- a/components/script/dom/html/htmlformelement.rs +++ b/components/script/dom/html/htmlformelement.rs @@ -12,6 +12,7 @@ use encoding_rs::{Encoding, UTF_8}; use headers::{ContentType, HeaderMapExt}; use html5ever::{LocalName, Prefix, local_name, ns}; use http::Method; +use js::context::JSContext; use js::rust::HandleObject; use mime::{self, Mime}; use net_traits::http_percent_encode; @@ -649,13 +650,13 @@ impl HTMLFormElementMethods for HTMLFormElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.static_validation(can_gc).is_ok() + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.static_validation(CanGc::from_cx(cx)).is_ok() } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.interactive_validation(can_gc).is_ok() + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.interactive_validation(CanGc::from_cx(cx)).is_ok() } } diff --git a/components/script/dom/html/htmlinputelement.rs b/components/script/dom/html/htmlinputelement.rs index 145fcbe2534..dd98f238495 100644 --- a/components/script/dom/html/htmlinputelement.rs +++ b/components/script/dom/html/htmlinputelement.rs @@ -21,6 +21,7 @@ use encoding_rs::Encoding; use fonts::{ByteIndex, TextByteRange}; use html5ever::{LocalName, Prefix, QualName, local_name, ns}; use itertools::Itertools; +use js::context::JSContext; use js::jsapi::{ ClippedTime, DateGetMsecSinceEpoch, Handle, JS_ClearPendingException, JSObject, NewDateObject, NewUCRegExpObject, ObjectIsDate, RegExpFlag_UnicodeSets, RegExpFlags, @@ -2125,13 +2126,13 @@ impl HTMLInputElementMethods for HTMLInputElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/html/htmlobjectelement.rs b/components/script/dom/html/htmlobjectelement.rs index cbab933a748..fe9db2c1b78 100644 --- a/components/script/dom/html/htmlobjectelement.rs +++ b/components/script/dom/html/htmlobjectelement.rs @@ -6,6 +6,7 @@ use std::default::Default; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix, local_name, ns}; +use js::context::JSContext; use js::rust::HandleObject; use pixels::RasterImage; use servo_arc::Arc; @@ -111,13 +112,13 @@ impl HTMLObjectElementMethods for HTMLObjectElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/html/htmloutputelement.rs b/components/script/dom/html/htmloutputelement.rs index 295dcb987b4..30d3018c936 100644 --- a/components/script/dom/html/htmloutputelement.rs +++ b/components/script/dom/html/htmloutputelement.rs @@ -4,6 +4,7 @@ use dom_struct::dom_struct; use html5ever::{LocalName, Prefix, local_name}; +use js::context::JSContext; use js::rust::HandleObject; use crate::dom::attr::Attr; @@ -133,13 +134,13 @@ impl HTMLOutputElementMethods for HTMLOutputElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/html/htmlselectelement.rs b/components/script/dom/html/htmlselectelement.rs index 0fd5a087ddf..d0fdb251cbd 100644 --- a/components/script/dom/html/htmlselectelement.rs +++ b/components/script/dom/html/htmlselectelement.rs @@ -9,6 +9,7 @@ use dom_struct::dom_struct; use embedder_traits::EmbedderControlRequest; use embedder_traits::{SelectElementOption, SelectElementOptionOrOptgroup}; use html5ever::{LocalName, Prefix, QualName, local_name, ns}; +use js::context::JSContext; use js::rust::HandleObject; use style::attr::AttrValue; use stylo_dom::ElementState; @@ -656,13 +657,13 @@ impl HTMLSelectElementMethods for HTMLSelectElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/html/htmltextareaelement.rs b/components/script/dom/html/htmltextareaelement.rs index d302061c01f..17e9d687818 100644 --- a/components/script/dom/html/htmltextareaelement.rs +++ b/components/script/dom/html/htmltextareaelement.rs @@ -10,6 +10,7 @@ use dom_struct::dom_struct; use embedder_traits::{EmbedderControlRequest, InputMethodRequest, InputMethodType}; use fonts::{ByteIndex, TextByteRange}; use html5ever::{LocalName, Prefix, local_name, ns}; +use js::context::JSContext; use js::rust::HandleObject; use layout_api::wrapper_traits::{ScriptSelection, SharedSelection}; use script_bindings::codegen::GenericBindings::CharacterDataBinding::CharacterDataMethods; @@ -558,13 +559,13 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { } /// - fn CheckValidity(&self, can_gc: CanGc) -> bool { - self.check_validity(can_gc) + fn CheckValidity(&self, cx: &mut JSContext) -> bool { + self.check_validity(cx) } /// - fn ReportValidity(&self, can_gc: CanGc) -> bool { - self.report_validity(can_gc) + fn ReportValidity(&self, cx: &mut JSContext) -> bool { + self.report_validity(cx) } /// diff --git a/components/script/dom/validation.rs b/components/script/dom/validation.rs index 725ee6e60ae..b66ee1ea643 100755 --- a/components/script/dom/validation.rs +++ b/components/script/dom/validation.rs @@ -1,6 +1,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use js::context::JSContext; + use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; use crate::dom::bindings::codegen::Bindings::HTMLOrSVGElementBinding::FocusOptions; use crate::dom::bindings::inheritance::Castable; @@ -39,11 +41,11 @@ pub(crate) trait Validatable { } /// - fn check_validity(&self, can_gc: CanGc) -> bool { - if self.is_instance_validatable() && !self.satisfies_constraints(can_gc) { + fn check_validity(&self, cx: &mut JSContext) -> bool { + if self.is_instance_validatable() && !self.satisfies_constraints(CanGc::from_cx(cx)) { self.as_element() .upcast::() - .fire_cancelable_event(atom!("invalid"), can_gc); + .fire_cancelable_event(atom!("invalid"), CanGc::from_cx(cx)); false } else { true @@ -51,13 +53,13 @@ pub(crate) trait Validatable { } /// - fn report_validity(&self, can_gc: CanGc) -> bool { + fn report_validity(&self, cx: &mut JSContext) -> bool { // Step 1. if !self.is_instance_validatable() { return true; } - if self.satisfies_constraints(can_gc) { + if self.satisfies_constraints(CanGc::from_cx(cx)) { return true; } @@ -66,19 +68,19 @@ pub(crate) trait Validatable { let report = self .as_element() .upcast::() - .fire_cancelable_event(atom!("invalid"), can_gc); + .fire_cancelable_event(atom!("invalid"), CanGc::from_cx(cx)); // Step 1.2. If `report` is true, for the element, // report the problem, run focusing steps, scroll into view. if report { - let flags = self.validity_state(can_gc).invalid_flags(); + let flags = self.validity_state(CanGc::from_cx(cx)).invalid_flags(); println!( "Validation error: {}", - validation_message_for_flags(&self.validity_state(can_gc), flags) + validation_message_for_flags(&self.validity_state(CanGc::from_cx(cx)), flags) ); if let Some(html_elem) = self.as_element().downcast::() { // Run focusing steps and scroll into view. - html_elem.Focus(&FocusOptions::default(), can_gc); + html_elem.Focus(&FocusOptions::default(), CanGc::from_cx(cx)); } } diff --git a/components/script_bindings/codegen/Bindings.conf b/components/script_bindings/codegen/Bindings.conf index f71911484d6..6a3daac622b 100644 --- a/components/script_bindings/codegen/Bindings.conf +++ b/components/script_bindings/codegen/Bindings.conf @@ -260,7 +260,8 @@ DOMInterfaces = { }, 'ElementInternals': { - 'canGc': ['CheckValidity', 'GetLabels', 'GetValidity', 'SetValidity', 'ReportValidity', 'States'], + 'canGc': ['GetLabels', 'GetValidity', 'SetValidity', 'States'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'EventSource': { @@ -406,7 +407,8 @@ DOMInterfaces = { }, 'HTMLButtonElement': { - 'canGc': ['CheckValidity', 'ReportValidity', 'SetBackground', 'SetCustomValidity', 'Validity'], + 'canGc': ['SetBackground', 'SetCustomValidity', 'Validity'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLCanvasElement': { @@ -431,7 +433,8 @@ DOMInterfaces = { }, 'HTMLFieldSetElement': { - 'canGc': ['CheckValidity', 'Elements', 'ReportValidity', 'SetCustomValidity', 'Validity'], + 'canGc': ['Elements', 'SetCustomValidity', 'Validity'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLFontElement': { @@ -443,7 +446,8 @@ DOMInterfaces = { }, 'HTMLFormElement': { - 'canGc': ['CheckValidity', 'Elements', 'IndexedGetter', 'NamedGetter', 'RequestSubmit', 'ReportValidity', 'Submit', 'Reset', 'SetRel', 'RelList'], + 'canGc': ['Elements', 'IndexedGetter', 'NamedGetter', 'RequestSubmit', 'Submit', 'Reset', 'SetRel', 'RelList'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLIFrameElement': { @@ -451,11 +455,13 @@ DOMInterfaces = { }, 'HTMLImageElement': { - 'canGc': ['RequestSubmit', 'ReportValidity', 'Reset','SetRel', 'Decode', 'SetCrossOrigin'], + 'canGc': ['RequestSubmit', 'Reset','SetRel', 'Decode', 'SetCrossOrigin'], + 'cx': ['ReportValidity'], }, 'HTMLInputElement': { - 'canGc': ['ReportValidity', 'SetValue', 'SetValueAsNumber', 'SetValueAsDate', 'StepUp', 'StepDown', 'CheckValidity', 'ReportValidity', 'GetLabels', 'SetCustomValidity', 'Validity', 'SetChecked'], + 'canGc': ['SetValue', 'SetValueAsNumber', 'SetValueAsDate', 'StepUp', 'StepDown','GetLabels', 'SetCustomValidity', 'Validity', 'SetChecked'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLLinkElement': { @@ -474,11 +480,13 @@ DOMInterfaces = { }, 'HTMLMeterElement': { - 'canGc': ['SetValue', 'SetMin', 'SetMax', 'SetLow', 'SetHigh', 'SetOptimum', 'CheckValidity', 'ReportValidity'] + 'canGc': ['SetValue', 'SetMin', 'SetMax', 'SetLow', 'SetHigh', 'SetOptimum'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLObjectElement': { - 'canGc': ['CheckValidity', 'ReportValidity', 'SetCustomValidity', 'Validity'], + 'canGc': ['SetCustomValidity', 'Validity'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLOptionElement': { @@ -490,7 +498,8 @@ DOMInterfaces = { }, 'HTMLOutputElement': { - 'canGc': ['ReportValidity', 'SetDefaultValue', 'SetValue', 'CheckValidity', 'SetCustomValidity', 'Validity'], + 'canGc': ['SetDefaultValue', 'SetValue', 'SetCustomValidity', 'Validity'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLProgressElement': { @@ -502,7 +511,8 @@ DOMInterfaces = { }, 'HTMLSelectElement': { - 'canGc': ['ReportValidity', 'SetLength', 'IndexedSetter', 'CheckValidity', 'SetSelectedIndex', 'SetCustomValidity', 'SetValue', 'Validity'], + 'canGc': ['SetLength', 'IndexedSetter', 'SetSelectedIndex', 'SetCustomValidity', 'SetValue', 'Validity'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLStyleElement': { @@ -526,7 +536,8 @@ DOMInterfaces = { }, 'HTMLTextAreaElement': { - 'canGc': ['ReportValidity', 'SetDefaultValue', 'CheckValidity', 'SetCustomValidity', 'SetValue', 'Validity'], + 'canGc': ['SetDefaultValue', 'SetCustomValidity', 'SetValue', 'Validity'], + 'cx': ['CheckValidity', 'ReportValidity'], }, 'HTMLTitleElement': {