diff --git a/components/script/dom/html/htmlbodyelement.rs b/components/script/dom/html/htmlbodyelement.rs index 5c0ec7349e2..32f829e3709 100644 --- a/components/script/dom/html/htmlbodyelement.rs +++ b/components/script/dom/html/htmlbodyelement.rs @@ -41,7 +41,7 @@ impl HTMLBodyElement { } pub(crate) fn new( - cx: &mut js::context::JSContext, + cx: &mut JSContext, local_name: LocalName, prefix: Option, document: &Document, @@ -73,11 +73,14 @@ impl HTMLBodyElementMethods for HTMLBodyElement { make_getter!(Background, "background"); /// - fn SetBackground(&self, input: DOMString, can_gc: CanGc) { + fn SetBackground(&self, cx: &mut JSContext, input: DOMString) { let value = AttrValue::from_resolved_url(&self.owner_document().base_url().get_arc(), input.into()); - self.upcast::() - .set_attribute(&local_name!("background"), value, can_gc); + self.upcast::().set_attribute( + &local_name!("background"), + value, + CanGc::from_cx(cx), + ); } // https://html.spec.whatwg.org/multipage/#windoweventhandlers @@ -146,12 +149,7 @@ impl VirtualMethods for HTMLBodyElement { } } - fn attribute_mutated( - &self, - cx: &mut js::context::JSContext, - attr: &Attr, - mutation: AttributeMutation, - ) { + fn attribute_mutated(&self, cx: &mut JSContext, attr: &Attr, mutation: AttributeMutation) { let do_super_mutate = match (attr.local_name(), mutation) { (name, AttributeMutation::Set(..)) if name.starts_with("on") => { let document = self.owner_document(); diff --git a/components/script/dom/html/htmlfontelement.rs b/components/script/dom/html/htmlfontelement.rs index a259c9dbae9..49b50c416e6 100644 --- a/components/script/dom/html/htmlfontelement.rs +++ b/components/script/dom/html/htmlfontelement.rs @@ -5,6 +5,7 @@ use cssparser::match_ignore_ascii_case; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix, local_name, ns}; +use js::context::JSContext; use js::rust::HandleObject; use style::attr::AttrValue; use style::color::AbsoluteColor; @@ -43,7 +44,7 @@ impl HTMLFontElement { } pub(crate) fn new( - cx: &mut js::context::JSContext, + cx: &mut JSContext, local_name: LocalName, prefix: Option, document: &Document, @@ -100,15 +101,15 @@ impl HTMLFontElementMethods for HTMLFontElement { make_getter!(Face, "face"); // https://html.spec.whatwg.org/multipage/#dom-font-face - make_atomic_setter!(SetFace, "face"); + make_atomic_setter!(cx, SetFace, "face"); // https://html.spec.whatwg.org/multipage/#dom-font-size make_getter!(Size, "size"); /// - fn SetSize(&self, value: DOMString, can_gc: CanGc) { + fn SetSize(&self, cx: &mut JSContext, value: DOMString) { let element = self.upcast::(); - element.set_attribute(&local_name!("size"), parse_size(&value), can_gc); + element.set_attribute(&local_name!("size"), parse_size(&value), CanGc::from_cx(cx)); } } diff --git a/components/script/dom/html/htmlhrelement.rs b/components/script/dom/html/htmlhrelement.rs index 4e53f17954a..974bd69b5fc 100644 --- a/components/script/dom/html/htmlhrelement.rs +++ b/components/script/dom/html/htmlhrelement.rs @@ -62,7 +62,7 @@ impl HTMLHRElementMethods for HTMLHRElement { make_getter!(Align, "align"); // https://html.spec.whatwg.org/multipage/#dom-hr-align - make_atomic_setter!(SetAlign, "align"); + make_atomic_setter!(cx, SetAlign, "align"); // https://html.spec.whatwg.org/multipage/#dom-hr-color make_getter!(Color, "color"); @@ -74,19 +74,19 @@ impl HTMLHRElementMethods for HTMLHRElement { make_bool_getter!(NoShade, "noshade"); // https://html.spec.whatwg.org/multipage/#dom-hr-noshade - make_bool_setter!(SetNoShade, "noshade"); + make_bool_setter!(cx, SetNoShade, "noshade"); // https://html.spec.whatwg.org/multipage/#dom-hr-size make_getter!(Size, "size"); // https://html.spec.whatwg.org/multipage/#dom-hr-size - make_dimension_setter!(SetSize, "size"); + make_dimension_setter!(cx, SetSize, "size"); // make_getter!(Width, "width"); // - make_dimension_setter!(SetWidth, "width"); + make_dimension_setter!(cx, SetWidth, "width"); } /// The result of applying the presentational hint for the `size` attribute. diff --git a/components/script/dom/html/htmltablecolelement.rs b/components/script/dom/html/htmltablecolelement.rs index 99c1e0324b6..f0ec3dccb4a 100644 --- a/components/script/dom/html/htmltablecolelement.rs +++ b/components/script/dom/html/htmltablecolelement.rs @@ -67,7 +67,7 @@ impl HTMLTableColElementMethods for HTMLTableColElement { make_getter!(Width, "width"); // - make_dimension_setter!(SetWidth, "width"); + make_dimension_setter!(cx, SetWidth, "width"); } impl<'dom> LayoutDom<'dom, HTMLTableColElement> { diff --git a/components/script/dom/html/htmltableelement.rs b/components/script/dom/html/htmltableelement.rs index aa896c9cfab..6a0f501fc7a 100644 --- a/components/script/dom/html/htmltableelement.rs +++ b/components/script/dom/html/htmltableelement.rs @@ -471,15 +471,15 @@ impl HTMLTableElementMethods for HTMLTableElement { make_nonzero_dimension_setter!(SetWidth, "width"); // - make_setter!(SetAlign, "align"); + make_setter!(cx, SetAlign, "align"); make_getter!(Align, "align"); // - make_setter!(SetCellPadding, "cellpadding"); + make_setter!(cx, SetCellPadding, "cellpadding"); make_getter!(CellPadding, "cellpadding"); // - make_setter!(SetCellSpacing, "cellspacing"); + make_setter!(cx, SetCellSpacing, "cellspacing"); make_getter!(CellSpacing, "cellspacing"); } diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 39aef38dd01..3044f0948d5 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -263,30 +263,52 @@ macro_rules! make_enumerated_getter( ); ); +macro_rules! make_setter_inner( + ( $self:ident, $value:ident, $htmlname:tt, $can_gc:expr ) => ( + use $crate::dom::bindings::inheritance::Castable; + use $crate::dom::element::Element; + use $crate::script_runtime::CanGc; + let element = $self.upcast::(); + element.set_string_attribute(&html5ever::local_name!($htmlname), $value, $can_gc) + ); +); + // concat_idents! doesn't work for function name positions, so // we have to specify both the content name and the HTML name here #[macro_export] macro_rules! make_setter( ( $attr:ident, $htmlname:tt ) => ( fn $attr(&self, value: DOMString) { - use $crate::dom::bindings::inheritance::Castable; - use $crate::dom::element::Element; - use $crate::script_runtime::CanGc; - let element = self.upcast::(); - element.set_string_attribute(&html5ever::local_name!($htmlname), value, CanGc::deprecated_note()) + make_setter_inner!(self, value, $htmlname, CanGc::deprecated_note()); } ); + ( $cx:ident, $attr:ident, $htmlname:tt ) => ( + fn $attr(&self, $cx: &mut js::context::JSContext, value: DOMString) { + make_setter_inner!(self, value, $htmlname, CanGc::from_cx($cx)); + } + ); +); + +macro_rules! make_bool_setter_inner( + ( $self:ident, $value:ident, $htmlname:tt, $can_gc:expr ) => ( + use $crate::dom::bindings::inheritance::Castable; + use $crate::dom::element::Element; + use $crate::script_runtime::CanGc; + let element = $self.upcast::(); + element.set_bool_attribute(&html5ever::local_name!($htmlname), $value, $can_gc) + ); ); #[macro_export] macro_rules! make_bool_setter( ( $attr:ident, $htmlname:tt ) => ( fn $attr(&self, value: bool) { - use $crate::dom::bindings::inheritance::Castable; - use $crate::dom::element::Element; - use $crate::script_runtime::CanGc; - let element = self.upcast::(); - element.set_bool_attribute(&html5ever::local_name!($htmlname), value, CanGc::deprecated_note()) + make_bool_setter_inner!(self, value, $htmlname, CanGc::deprecated_note()); + } + ); + ( $cx:ident, $attr:ident, $htmlname:tt ) => ( + fn $attr(&self, $cx: &mut js::context::JSContext, value: bool) { + make_bool_setter_inner!(self, value, $htmlname, CanGc::from_cx($cx)); } ); ); @@ -316,7 +338,7 @@ macro_rules! make_uint_setter( #[macro_export] macro_rules! make_clamped_uint_setter( ($attr:ident, $htmlname:tt, $min:expr, $max:expr, $default:expr) => ( - fn $attr(&self, value: u32) { + fn $attr(&self, cx: &mut js::context::JSContext, value: u32) { use $crate::dom::bindings::inheritance::Castable; use $crate::dom::element::Element; use $crate::dom::values::UNSIGNED_LONG_MAX; @@ -328,7 +350,7 @@ macro_rules! make_clamped_uint_setter( }; let element = self.upcast::(); - element.set_uint_attribute(&html5ever::local_name!($htmlname), value, CanGc::deprecated_note()) + element.set_uint_attribute(&html5ever::local_name!($htmlname), value, CanGc::from_cx(cx)) } ); ); @@ -385,28 +407,39 @@ macro_rules! make_atomic_setter( #[macro_export] macro_rules! make_legacy_color_setter( ( $attr:ident, $htmlname:tt ) => ( - fn $attr(&self, value: DOMString) { + fn $attr(&self, cx: &mut js::context::JSContext, value: DOMString) { use $crate::dom::bindings::inheritance::Castable; use $crate::dom::element::Element; use style::attr::AttrValue; use $crate::script_runtime::CanGc; let element = self.upcast::(); let value = AttrValue::from_legacy_color(value.into()); - element.set_attribute(&html5ever::local_name!($htmlname), value, CanGc::deprecated_note()) + element.set_attribute(&html5ever::local_name!($htmlname), value, CanGc::from_cx(cx)) } ); ); +macro_rules! make_dimension_setter_inner( + ( $self:ident, $value:ident, $htmlname:tt, $can_gc:expr ) => ( + use $crate::dom::bindings::inheritance::Castable; + use $crate::dom::element::Element; + use $crate::script_runtime::CanGc; + let element = $self.upcast::(); + let value = AttrValue::from_dimension($value.into()); + element.set_attribute(&html5ever::local_name!($htmlname), value, $can_gc) + ); +); + #[macro_export] macro_rules! make_dimension_setter( ( $attr:ident, $htmlname:tt ) => ( fn $attr(&self, value: DOMString) { - use $crate::dom::bindings::inheritance::Castable; - use $crate::dom::element::Element; - use $crate::script_runtime::CanGc; - let element = self.upcast::(); - let value = AttrValue::from_dimension(value.into()); - element.set_attribute(&html5ever::local_name!($htmlname), value, CanGc::deprecated_note()) + make_dimension_setter_inner!(self, value, $htmlname, CanGc::deprecated_note()); + } + ); + ( $cx:ident, $attr:ident, $htmlname:tt ) => ( + fn $attr(&self, $cx: &mut js::context::JSContext, value: DOMString) { + make_dimension_setter_inner!(self, value, $htmlname, CanGc::from_cx($cx)); } ); ); @@ -414,13 +447,13 @@ macro_rules! make_dimension_setter( #[macro_export] macro_rules! make_nonzero_dimension_setter( ( $attr:ident, $htmlname:tt ) => ( - fn $attr(&self, value: DOMString) { + fn $attr(&self, cx: &mut js::context::JSContext, value: DOMString) { use $crate::dom::bindings::inheritance::Castable; use $crate::dom::element::Element; use $crate::script_runtime::CanGc; let element = self.upcast::(); let value = AttrValue::from_nonzero_dimension(value.into()); - element.set_attribute(&html5ever::local_name!($htmlname), value, CanGc::deprecated_note()) + element.set_attribute(&html5ever::local_name!($htmlname), value, CanGc::from_cx(cx)) } ); ); @@ -522,7 +555,7 @@ macro_rules! define_window_owned_event_handler( } } - fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) { + fn $setter(&self, _cx: &mut js::context::JSContext, listener: Option<::std::rc::Rc<$handler>>) { let document = self.owner_document(); if document.has_browsing_context() { document.window().$setter(listener) diff --git a/components/script_bindings/codegen/Bindings.conf b/components/script_bindings/codegen/Bindings.conf index 5b4f5976948..59ae979b34f 100644 --- a/components/script_bindings/codegen/Bindings.conf +++ b/components/script_bindings/codegen/Bindings.conf @@ -425,7 +425,7 @@ DOMInterfaces = { }, "HTMLBodyElement": { - "canGc": ["SetBackground"] + 'implicitCxSetters': True, }, 'HTMLButtonElement': { @@ -480,7 +480,7 @@ DOMInterfaces = { }, 'HTMLFontElement': { - 'canGc': ['SetSize'] + 'implicitCxSetters': True, }, 'HTMLFormControlsCollection': { @@ -492,10 +492,18 @@ DOMInterfaces = { 'cx': ['CheckValidity', 'ReportValidity'], }, +'HTMLFrameSetElement': { + 'implicitCxSetters': True, +}, + 'HTMLIFrameElement': { 'cx': ['Sandbox', 'SetSrcdoc'], }, +'HTMLHRElement': { + 'implicitCxSetters': True, +}, + 'HTMLImageElement': { 'cx': ['Decode', 'Image', 'ReportValidity', 'SetCrossOrigin'], }, @@ -584,14 +592,20 @@ DOMInterfaces = { 'DeleteTFoot', 'DeleteTHead', 'InsertRow', - 'SetCaption', - 'SetTFoot', - 'SetTHead' ], + 'implicitCxSetters': True, +}, + +'HTMLTableCellElement': { + 'implicitCxSetters': True, +}, +'HTMLTableColElement': { + 'implicitCxSetters': True, }, 'HTMLTableRowElement': { - 'cx': ['DeleteCell', 'InsertCell'] + 'cx': ['DeleteCell', 'InsertCell'], + 'implicitCxSetters': True, }, 'HTMLTableSectionElement': {