diff options
Diffstat (limited to 'components/script')
41 files changed, 182 insertions, 146 deletions
diff --git a/components/script/canvas_context.rs b/components/script/canvas_context.rs index 752b749c97c..8bf188a5aa9 100644 --- a/components/script/canvas_context.rs +++ b/components/script/canvas_context.rs @@ -64,8 +64,13 @@ pub(crate) trait CanvasContext { } } -impl HTMLCanvasElementOrOffscreenCanvas { - pub(crate) fn size(&self) -> Size2D<u64> { +pub(crate) trait CanvasHelpers { + fn size(&self) -> Size2D<u64>; + fn canvas(&self) -> Option<&HTMLCanvasElement>; +} + +impl CanvasHelpers for HTMLCanvasElementOrOffscreenCanvas { + fn size(&self) -> Size2D<u64> { match self { HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => { canvas.get_size().cast() @@ -74,7 +79,7 @@ impl HTMLCanvasElementOrOffscreenCanvas { } } - pub(crate) fn canvas(&self) -> Option<&HTMLCanvasElement> { + fn canvas(&self) -> Option<&HTMLCanvasElement> { match self { HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => Some(canvas), HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(canvas) => canvas.placeholder(), diff --git a/components/script/dom/analysernode.rs b/components/script/dom/analysernode.rs index 7af43192b19..85d6a18af9f 100644 --- a/components/script/dom/analysernode.rs +++ b/components/script/dom/analysernode.rs @@ -11,7 +11,7 @@ use servo_media::audio::analyser_node::AnalysisEngine; use servo_media::audio::block::Block; use servo_media::audio::node::AudioNodeInit; -use crate::dom::audionode::AudioNode; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper}; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::AnalyserNodeBinding::{ diff --git a/components/script/dom/audiobuffersourcenode.rs b/components/script/dom/audiobuffersourcenode.rs index 4123553d0ff..a0a5226cd6a 100644 --- a/components/script/dom/audiobuffersourcenode.rs +++ b/components/script/dom/audiobuffersourcenode.rs @@ -13,6 +13,7 @@ use servo_media::audio::buffer_source_node::{ use servo_media::audio::node::{AudioNodeInit, AudioNodeMessage, AudioNodeType}; use servo_media::audio::param::ParamType; +use crate::conversions::Convert; use crate::dom::audiobuffer::AudioBuffer; use crate::dom::audioparam::AudioParam; use crate::dom::audioscheduledsourcenode::AudioScheduledSourceNode; @@ -52,7 +53,7 @@ impl AudioBufferSourceNode { ) -> Fallible<AudioBufferSourceNode> { let node_options = Default::default(); let source_node = AudioScheduledSourceNode::new_inherited( - AudioNodeInit::AudioBufferSourceNode(options.into()), + AudioNodeInit::AudioBufferSourceNode(options.convert()), context, node_options, 0, /* inputs */ @@ -274,18 +275,18 @@ impl AudioBufferSourceNodeMethods<crate::DomTypeHolder> for AudioBufferSourceNod } } -impl<'a> From<&'a AudioBufferSourceOptions> for AudioBufferSourceNodeOptions { - fn from(options: &'a AudioBufferSourceOptions) -> Self { - Self { - buffer: options +impl Convert<AudioBufferSourceNodeOptions> for &AudioBufferSourceOptions { + fn convert(self) -> AudioBufferSourceNodeOptions { + AudioBufferSourceNodeOptions { + buffer: self .buffer .as_ref() .and_then(|b| (*b.as_ref()?.get_channels()).clone()), - detune: *options.detune, - loop_enabled: options.loop_, - loop_end: Some(*options.loopEnd), - loop_start: Some(*options.loopStart), - playback_rate: *options.playbackRate, + detune: *self.detune, + loop_enabled: self.loop_, + loop_end: Some(*self.loopEnd), + loop_start: Some(*self.loopStart), + playback_rate: *self.playbackRate, } } } diff --git a/components/script/dom/audiodestinationnode.rs b/components/script/dom/audiodestinationnode.rs index c6297bc6e46..c20620336d0 100644 --- a/components/script/dom/audiodestinationnode.rs +++ b/components/script/dom/audiodestinationnode.rs @@ -4,7 +4,7 @@ use dom_struct::dom_struct; -use crate::dom::audionode::{AudioNode, MAX_CHANNEL_COUNT}; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper, MAX_CHANNEL_COUNT}; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::AudioDestinationNodeMethods; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ diff --git a/components/script/dom/audionode.rs b/components/script/dom/audionode.rs index 7a4d13c04d6..422b517bc94 100644 --- a/components/script/dom/audionode.rs +++ b/components/script/dom/audionode.rs @@ -387,8 +387,17 @@ impl Convert<ServoMediaChannelInterpretation> for ChannelInterpretation { } } -impl AudioNodeOptions { - pub(crate) fn unwrap_or( +pub(crate) trait AudioNodeOptionsHelper { + fn unwrap_or( + &self, + count: u32, + mode: ChannelCountMode, + interpretation: ChannelInterpretation, + ) -> UnwrappedAudioNodeOptions; +} + +impl AudioNodeOptionsHelper for AudioNodeOptions { + fn unwrap_or( &self, count: u32, mode: ChannelCountMode, diff --git a/components/script/dom/bindings/buffer_source.rs b/components/script/dom/bindings/buffer_source.rs index 1407d1388b2..d3879f2bcff 100644 --- a/components/script/dom/bindings/buffer_source.rs +++ b/components/script/dom/bindings/buffer_source.rs @@ -39,8 +39,7 @@ use js::typedarray::{ TypedArray, TypedArrayElement, TypedArrayElementCreator, }; -use crate::dom::bindings::error::Error; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, Fallible}; #[cfg(feature = "webgpu")] use crate::dom::globalscope::GlobalScope; use crate::script_runtime::{CanGc, JSContext}; diff --git a/components/script/dom/bindings/function.rs b/components/script/dom/bindings/function.rs index 86f4903b07d..2419dd05272 100644 --- a/components/script/dom/bindings/function.rs +++ b/components/script/dom/bindings/function.rs @@ -36,7 +36,7 @@ macro_rules! native_raw_obj_fn { #[allow(clippy::macro_metavars_in_unsafe)] unsafe { let name: &std::ffi::CStr = $name; - let raw_fun = $crate::dom::bindings::import::module::jsapi::JS_NewFunction( + let raw_fun = js::jsapi::JS_NewFunction( *$cx, Some(wrapper), $nargs, @@ -44,7 +44,7 @@ macro_rules! native_raw_obj_fn { name.as_ptr() as *const std::ffi::c_char, ); assert!(!raw_fun.is_null()); - $crate::dom::bindings::import::module::jsapi::JS_GetFunctionObject(raw_fun) + js::jsapi::JS_GetFunctionObject(raw_fun) } }}; } diff --git a/components/script/dom/biquadfilternode.rs b/components/script/dom/biquadfilternode.rs index 00fefe5ecf6..635dddd92c6 100644 --- a/components/script/dom/biquadfilternode.rs +++ b/components/script/dom/biquadfilternode.rs @@ -14,7 +14,7 @@ use servo_media::audio::node::{AudioNodeInit, AudioNodeMessage, AudioNodeType}; use servo_media::audio::param::ParamType; use crate::conversions::Convert; -use crate::dom::audionode::AudioNode; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper}; use crate::dom::audioparam::AudioParam; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ diff --git a/components/script/dom/bytelengthqueuingstrategy.rs b/components/script/dom/bytelengthqueuingstrategy.rs index a9c2cda360e..3be16eb1599 100644 --- a/components/script/dom/bytelengthqueuingstrategy.rs +++ b/components/script/dom/bytelengthqueuingstrategy.rs @@ -18,7 +18,7 @@ use super::bindings::error::Fallible; use super::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use super::bindings::root::DomRoot; use super::types::GlobalScope; -use crate::dom::bindings::import::module::get_dictionary_property; +use crate::dom::bindings::utils::get_dictionary_property; use crate::native_fn; use crate::script_runtime::CanGc; diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index cda7bed08f7..d2728f79a27 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -10,7 +10,7 @@ use profile_traits::ipc; use script_layout_interface::HTMLCanvasDataSource; use servo_url::ServoUrl; -use crate::canvas_context::{CanvasContext, LayoutCanvasRenderingContextHelpers}; +use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers}; use crate::canvas_state::CanvasState; use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::{ CanvasDirection, CanvasFillRule, CanvasImageSource, CanvasLineCap, CanvasLineJoin, diff --git a/components/script/dom/channelmergernode.rs b/components/script/dom/channelmergernode.rs index 9f027b60e21..e39bf69dbb4 100644 --- a/components/script/dom/channelmergernode.rs +++ b/components/script/dom/channelmergernode.rs @@ -7,7 +7,8 @@ use js::rust::HandleObject; use servo_media::audio::channel_node::ChannelNodeOptions; use servo_media::audio::node::AudioNodeInit; -use crate::dom::audionode::{AudioNode, MAX_CHANNEL_COUNT}; +use crate::conversions::Convert; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper, MAX_CHANNEL_COUNT}; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ ChannelCountMode, ChannelInterpretation, @@ -47,12 +48,13 @@ impl ChannelMergerNode { return Err(Error::IndexSize); } + let num_inputs = options.numberOfInputs; let node = AudioNode::new_inherited( - AudioNodeInit::ChannelMergerNode(options.into()), + AudioNodeInit::ChannelMergerNode(options.convert()), context, node_options, - options.numberOfInputs, // inputs - 1, // outputs + num_inputs, // inputs + 1, // outputs )?; Ok(ChannelMergerNode { node }) } @@ -97,10 +99,10 @@ impl ChannelMergerNodeMethods<crate::DomTypeHolder> for ChannelMergerNode { } } -impl<'a> From<&'a ChannelMergerOptions> for ChannelNodeOptions { - fn from(options: &'a ChannelMergerOptions) -> Self { - Self { - channels: options.numberOfInputs as u8, +impl Convert<ChannelNodeOptions> for ChannelMergerOptions { + fn convert(self) -> ChannelNodeOptions { + ChannelNodeOptions { + channels: self.numberOfInputs as u8, } } } diff --git a/components/script/dom/channelsplitternode.rs b/components/script/dom/channelsplitternode.rs index ca7f0074669..67ac479efeb 100644 --- a/components/script/dom/channelsplitternode.rs +++ b/components/script/dom/channelsplitternode.rs @@ -6,7 +6,7 @@ use dom_struct::dom_struct; use js::rust::HandleObject; use servo_media::audio::node::AudioNodeInit; -use crate::dom::audionode::{AudioNode, MAX_CHANNEL_COUNT}; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper, MAX_CHANNEL_COUNT}; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ ChannelCountMode, ChannelInterpretation, diff --git a/components/script/dom/constantsourcenode.rs b/components/script/dom/constantsourcenode.rs index 88fbb433104..308cff83345 100644 --- a/components/script/dom/constantsourcenode.rs +++ b/components/script/dom/constantsourcenode.rs @@ -10,6 +10,7 @@ use servo_media::audio::constant_source_node::ConstantSourceNodeOptions as Servo use servo_media::audio::node::{AudioNodeInit, AudioNodeType}; use servo_media::audio::param::ParamType; +use crate::conversions::Convert; use crate::dom::audioparam::AudioParam; use crate::dom::audioscheduledsourcenode::AudioScheduledSourceNode; use crate::dom::baseaudiocontext::BaseAudioContext; @@ -38,8 +39,9 @@ impl ConstantSourceNode { can_gc: CanGc, ) -> Fallible<ConstantSourceNode> { let node_options = Default::default(); + let offset = *options.offset; let source_node = AudioScheduledSourceNode::new_inherited( - AudioNodeInit::ConstantSourceNode(options.into()), + AudioNodeInit::ConstantSourceNode(options.convert()), context, node_options, /* 2, MAX, Speakers */ 0, /* inputs */ @@ -53,7 +55,7 @@ impl ConstantSourceNode { AudioNodeType::ConstantSourceNode, ParamType::Offset, AutomationRate::A_rate, - *options.offset, + offset, f32::MIN, f32::MAX, can_gc, @@ -110,10 +112,10 @@ impl ConstantSourceNodeMethods<crate::DomTypeHolder> for ConstantSourceNode { } } -impl<'a> From<&'a ConstantSourceOptions> for ServoMediaConstantSourceOptions { - fn from(options: &'a ConstantSourceOptions) -> Self { - Self { - offset: *options.offset, +impl Convert<ServoMediaConstantSourceOptions> for ConstantSourceOptions { + fn convert(self) -> ServoMediaConstantSourceOptions { + ServoMediaConstantSourceOptions { + offset: *self.offset, } } } diff --git a/components/script/dom/defaultteeunderlyingsource.rs b/components/script/dom/defaultteeunderlyingsource.rs index 6372e562baa..5895297d982 100644 --- a/components/script/dom/defaultteeunderlyingsource.rs +++ b/components/script/dom/defaultteeunderlyingsource.rs @@ -12,7 +12,7 @@ use js::rust::HandleValue as SafeHandleValue; use super::bindings::root::{DomRoot, MutNullableDom}; use super::types::{ReadableStream, ReadableStreamDefaultReader}; -use crate::dom::bindings::import::module::Error; +use crate::dom::bindings::error::Error; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; use crate::dom::bindings::root::Dom; use crate::dom::defaultteereadrequest::DefaultTeeReadRequest; diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 0f7664a75d3..43e62b528d8 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -25,6 +25,7 @@ use servo_url::ServoUrl; use style::str::HTML_SPACE_CHARACTERS; use stylo_atoms::Atom; +use crate::conversions::Convert; use crate::dom::beforeunloadevent::BeforeUnloadEvent; use crate::dom::bindings::callback::{CallbackContainer, CallbackFunction, ExceptionHandling}; use crate::dom::bindings::cell::DomRefCell; @@ -384,7 +385,7 @@ impl EventListeners { } #[dom_struct] -pub(crate) struct EventTarget { +pub struct EventTarget { reflector_: Reflector, handlers: DomRefCell<HashMapTracedValues<Atom, EventListeners, BuildHasherDefault<FnvHasher>>>, } @@ -944,7 +945,7 @@ impl EventTargetMethods<crate::DomTypeHolder> for EventTarget { listener: Option<Rc<EventListener>>, options: AddEventListenerOptionsOrBoolean, ) { - self.add_event_listener(ty, listener, options.into()) + self.add_event_listener(ty, listener, options.convert()) } // https://dom.spec.whatwg.org/#dom-eventtarget-removeeventlistener @@ -954,7 +955,7 @@ impl EventTargetMethods<crate::DomTypeHolder> for EventTarget { listener: Option<Rc<EventListener>>, options: EventListenerOptionsOrBoolean, ) { - self.remove_event_listener(ty, listener, options.into()) + self.remove_event_listener(ty, listener, options.convert()) } // https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent @@ -976,11 +977,11 @@ impl VirtualMethods for EventTarget { } } -impl From<AddEventListenerOptionsOrBoolean> for AddEventListenerOptions { - fn from(options: AddEventListenerOptionsOrBoolean) -> Self { - match options { +impl Convert<AddEventListenerOptions> for AddEventListenerOptionsOrBoolean { + fn convert(self) -> AddEventListenerOptions { + match self { AddEventListenerOptionsOrBoolean::AddEventListenerOptions(options) => options, - AddEventListenerOptionsOrBoolean::Boolean(capture) => Self { + AddEventListenerOptionsOrBoolean::Boolean(capture) => AddEventListenerOptions { parent: EventListenerOptions { capture }, once: false, passive: None, @@ -989,11 +990,11 @@ impl From<AddEventListenerOptionsOrBoolean> for AddEventListenerOptions { } } -impl From<EventListenerOptionsOrBoolean> for EventListenerOptions { - fn from(options: EventListenerOptionsOrBoolean) -> Self { - match options { +impl Convert<EventListenerOptions> for EventListenerOptionsOrBoolean { + fn convert(self) -> EventListenerOptions { + match self { EventListenerOptionsOrBoolean::EventListenerOptions(options) => options, - EventListenerOptionsOrBoolean::Boolean(capture) => Self { capture }, + EventListenerOptionsOrBoolean::Boolean(capture) => EventListenerOptions { capture }, } } } diff --git a/components/script/dom/gainnode.rs b/components/script/dom/gainnode.rs index d17cbffdb61..c3854be719a 100644 --- a/components/script/dom/gainnode.rs +++ b/components/script/dom/gainnode.rs @@ -10,7 +10,8 @@ use servo_media::audio::gain_node::GainNodeOptions; use servo_media::audio::node::{AudioNodeInit, AudioNodeType}; use servo_media::audio::param::ParamType; -use crate::dom::audionode::AudioNode; +use crate::conversions::Convert; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper}; use crate::dom::audioparam::AudioParam; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ @@ -42,8 +43,9 @@ impl GainNode { options .parent .unwrap_or(2, ChannelCountMode::Max, ChannelInterpretation::Speakers); + let gain = *options.gain; let node = AudioNode::new_inherited( - AudioNodeInit::GainNode(options.into()), + AudioNodeInit::GainNode(options.convert()), context, node_options, 1, // inputs @@ -56,9 +58,9 @@ impl GainNode { AudioNodeType::GainNode, ParamType::Gain, AutomationRate::A_rate, - *options.gain, // default value - f32::MIN, // min value - f32::MAX, // max value + gain, // default value + f32::MIN, // min value + f32::MAX, // max value can_gc, ); Ok(GainNode { @@ -112,10 +114,8 @@ impl GainNodeMethods<crate::DomTypeHolder> for GainNode { } } -impl<'a> From<&'a GainOptions> for GainNodeOptions { - fn from(options: &'a GainOptions) -> Self { - Self { - gain: *options.gain, - } +impl Convert<GainNodeOptions> for GainOptions { + fn convert(self) -> GainNodeOptions { + GainNodeOptions { gain: *self.gain } } } diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index b12a6cd0f4a..42a526ce348 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -29,7 +29,9 @@ use style::attr::AttrValue; use crate::canvas_context::CanvasContext as _; pub(crate) use crate::canvas_context::*; +use crate::conversions::Convert; use crate::dom::attr::Attr; +use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::cell::{DomRefCell, Ref, ref_filter_map}; use crate::dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::{ BlobCallback, HTMLCanvasElementMethods, RenderingContext, @@ -39,7 +41,6 @@ use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGL use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas; use crate::dom::bindings::conversions::ConversionResult; use crate::dom::bindings::error::{Error, Fallible}; -use crate::dom::bindings::import::module::ExceptionHandling; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::num::Finite; use crate::dom::bindings::refcounted::Trusted; @@ -342,9 +343,9 @@ impl HTMLCanvasElement { fn get_gl_attributes(cx: JSContext, options: HandleValue) -> Option<GLContextAttributes> { unsafe { match WebGLContextAttributes::new(cx, options) { - Ok(ConversionResult::Success(ref attrs)) => Some(From::from(attrs)), - Ok(ConversionResult::Failure(ref error)) => { - throw_type_error(*cx, error); + Ok(ConversionResult::Success(attrs)) => Some(attrs.convert()), + Ok(ConversionResult::Failure(error)) => { + throw_type_error(*cx, &error); None }, _ => { @@ -702,15 +703,15 @@ impl VirtualMethods for HTMLCanvasElement { } } -impl<'a> From<&'a WebGLContextAttributes> for GLContextAttributes { - fn from(attrs: &'a WebGLContextAttributes) -> GLContextAttributes { +impl Convert<GLContextAttributes> for WebGLContextAttributes { + fn convert(self) -> GLContextAttributes { GLContextAttributes { - alpha: attrs.alpha, - depth: attrs.depth, - stencil: attrs.stencil, - antialias: attrs.antialias, - premultiplied_alpha: attrs.premultipliedAlpha, - preserve_drawing_buffer: attrs.preserveDrawingBuffer, + alpha: self.alpha, + depth: self.depth, + stencil: self.stencil, + antialias: self.antialias, + premultiplied_alpha: self.premultipliedAlpha, + preserve_drawing_buffer: self.preserveDrawingBuffer, } } } diff --git a/components/script/dom/iirfilternode.rs b/components/script/dom/iirfilternode.rs index e057536997b..20578ec6d4a 100644 --- a/components/script/dom/iirfilternode.rs +++ b/components/script/dom/iirfilternode.rs @@ -12,7 +12,8 @@ use js::typedarray::Float32Array; use servo_media::audio::iir_filter_node::{IIRFilterNode as IIRFilter, IIRFilterNodeOptions}; use servo_media::audio::node::AudioNodeInit; -use crate::dom::audionode::AudioNode; +use crate::conversions::Convert; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper}; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ ChannelCountMode, ChannelInterpretation, @@ -53,7 +54,9 @@ impl IIRFilterNode { options .parent .unwrap_or(2, ChannelCountMode::Max, ChannelInterpretation::Speakers); - let init_options = options.into(); + let feedforward = (*options.feedforward).to_vec(); + let feedback = (*options.feedback).to_vec(); + let init_options = options.clone().convert(); let node = AudioNode::new_inherited( AudioNodeInit::IIRFilterNode(init_options), context, @@ -63,8 +66,8 @@ impl IIRFilterNode { )?; Ok(IIRFilterNode { node, - feedforward: (*options.feedforward).to_vec(), - feedback: (*options.feedback).to_vec(), + feedforward, + feedback, }) } @@ -139,12 +142,11 @@ impl IIRFilterNodeMethods<crate::DomTypeHolder> for IIRFilterNode { } } -impl<'a> From<&'a IIRFilterOptions> for IIRFilterNodeOptions { - fn from(options: &'a IIRFilterOptions) -> Self { - let feedforward: Vec<f64> = - (*options.feedforward.iter().map(|v| **v).collect_vec()).to_vec(); - let feedback: Vec<f64> = (*options.feedback.iter().map(|v| **v).collect_vec()).to_vec(); - Self { +impl Convert<IIRFilterNodeOptions> for IIRFilterOptions { + fn convert(self) -> IIRFilterNodeOptions { + let feedforward: Vec<f64> = (*self.feedforward.iter().map(|v| **v).collect_vec()).to_vec(); + let feedback: Vec<f64> = (*self.feedback.iter().map(|v| **v).collect_vec()).to_vec(); + IIRFilterNodeOptions { feedforward: Arc::new(feedforward), feedback: Arc::new(feedback), } diff --git a/components/script/dom/intersectionobserver.rs b/components/script/dom/intersectionobserver.rs index cc9cba87cc4..c8a761a627c 100644 --- a/components/script/dom/intersectionobserver.rs +++ b/components/script/dom/intersectionobserver.rs @@ -23,8 +23,7 @@ use super::intersectionobserverrootmargin::IntersectionObserverRootMargin; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::IntersectionObserverBinding::IntersectionObserverInit; use crate::dom::bindings::codegen::UnionTypes::{DoubleOrDoubleSequence, ElementOrDocument}; -use crate::dom::bindings::error::Error; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::num::Finite; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{Dom, DomRoot}; diff --git a/components/script/dom/mediastreamaudiodestinationnode.rs b/components/script/dom/mediastreamaudiodestinationnode.rs index 773db19ee86..f8d43cd86d6 100644 --- a/components/script/dom/mediastreamaudiodestinationnode.rs +++ b/components/script/dom/mediastreamaudiodestinationnode.rs @@ -9,7 +9,7 @@ use servo_media::audio::node::AudioNodeInit; use servo_media::streams::MediaStreamType; use crate::dom::audiocontext::AudioContext; -use crate::dom::audionode::AudioNode; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper}; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ AudioNodeOptions, ChannelCountMode, ChannelInterpretation, }; diff --git a/components/script/dom/notification.rs b/components/script/dom/notification.rs index 8661e5f9add..738c448d93d 100644 --- a/components/script/dom/notification.rs +++ b/components/script/dom/notification.rs @@ -2,6 +2,7 @@ * 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 std::rc::Rc; use std::time::{SystemTime, UNIX_EPOCH}; use dom_struct::dom_struct; @@ -24,8 +25,7 @@ use crate::dom::bindings::codegen::Bindings::PermissionStatusBinding::{ PermissionDescriptor, PermissionName, PermissionState, }; use crate::dom::bindings::codegen::UnionTypes::UnsignedLongOrUnsignedLongSequence; -use crate::dom::bindings::error::Error; -use crate::dom::bindings::import::module::{Fallible, Rc}; +use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::reflect_dom_object_with_proto; use crate::dom::bindings::root::{Dom, DomRoot}; diff --git a/components/script/dom/oscillatornode.rs b/components/script/dom/oscillatornode.rs index 4134fb3815c..d52cd6b7866 100644 --- a/components/script/dom/oscillatornode.rs +++ b/components/script/dom/oscillatornode.rs @@ -15,6 +15,7 @@ use servo_media::audio::oscillator_node::{ use servo_media::audio::param::ParamType; use crate::conversions::Convert; +use crate::dom::audionode::AudioNodeOptionsHelper; use crate::dom::audioparam::AudioParam; use crate::dom::audioscheduledsourcenode::AudioScheduledSourceNode; use crate::dom::baseaudiocontext::BaseAudioContext; diff --git a/components/script/dom/pannernode.rs b/components/script/dom/pannernode.rs index 7c007fd1af3..ca9512082c9 100644 --- a/components/script/dom/pannernode.rs +++ b/components/script/dom/pannernode.rs @@ -14,7 +14,7 @@ use servo_media::audio::panner_node::{ use servo_media::audio::param::{ParamDir, ParamType}; use crate::conversions::Convert; -use crate::dom::audionode::AudioNode; +use crate::dom::audionode::{AudioNode, AudioNodeOptionsHelper}; use crate::dom::audioparam::AudioParam; use crate::dom::baseaudiocontext::BaseAudioContext; use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ diff --git a/components/script/dom/permissionstatus.rs b/components/script/dom/permissionstatus.rs index 6626903c30f..433fe119f85 100644 --- a/components/script/dom/permissionstatus.rs +++ b/components/script/dom/permissionstatus.rs @@ -3,7 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::cell::Cell; -use std::fmt::{self, Display, Formatter}; use dom_struct::dom_struct; @@ -63,9 +62,3 @@ impl PermissionStatusMethods<crate::DomTypeHolder> for PermissionStatus { // https://w3c.github.io/permissions/#dom-permissionstatus-onchange event_handler!(change, GetOnchange, SetOnchange); } - -impl Display for PermissionName { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{}", self.as_str()) - } -} diff --git a/components/script/dom/readablebytestreamcontroller.rs b/components/script/dom/readablebytestreamcontroller.rs index 1de27414fd6..eab48ea32a7 100644 --- a/components/script/dom/readablebytestreamcontroller.rs +++ b/components/script/dom/readablebytestreamcontroller.rs @@ -25,9 +25,8 @@ use crate::dom::bindings::buffer_source::{ Constructor, byte_size, create_array_buffer_with_size, create_buffer_source_with_constructor, }; use crate::dom::bindings::codegen::Bindings::ReadableByteStreamControllerBinding::ReadableByteStreamControllerMethods; -use crate::dom::bindings::error::ErrorToJsval; -use crate::dom::bindings::import::module::UnionTypes::ReadableStreamDefaultControllerOrReadableByteStreamController as Controller; -use crate::dom::bindings::import::module::{Error, Fallible}; +use crate::dom::bindings::codegen::UnionTypes::ReadableStreamDefaultControllerOrReadableByteStreamController as Controller; +use crate::dom::bindings::error::{Error, ErrorToJsval, Fallible}; use crate::dom::bindings::reflector::{DomGlobal, Reflector}; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::trace::RootedTraceableBox; diff --git a/components/script/dom/readablestream.rs b/components/script/dom/readablestream.rs index 52e12a9a248..1a20aa68d0b 100644 --- a/components/script/dom/readablestream.rs +++ b/components/script/dom/readablestream.rs @@ -24,8 +24,7 @@ use crate::dom::bindings::codegen::Bindings::ReadableStreamDefaultReaderBinding: use crate::dom::bindings::codegen::Bindings::ReadableStreamDefaultControllerBinding::ReadableStreamDefaultController_Binding::ReadableStreamDefaultControllerMethods; use crate::dom::bindings::codegen::Bindings::UnderlyingSourceBinding::UnderlyingSource as JsUnderlyingSource; use crate::dom::bindings::conversions::{ConversionBehavior, ConversionResult}; -use crate::dom::bindings::error::{Error, ErrorToJsval}; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, ErrorToJsval, Fallible}; use crate::dom::bindings::codegen::UnionTypes::ReadableStreamDefaultReaderOrReadableStreamBYOBReader as ReadableStreamReader; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{DomRoot, MutNullableDom, Dom}; diff --git a/components/script/dom/readablestreambyobreader.rs b/components/script/dom/readablestreambyobreader.rs index 30e97b6356d..745b9ef21ac 100644 --- a/components/script/dom/readablestreambyobreader.rs +++ b/components/script/dom/readablestreambyobreader.rs @@ -21,8 +21,7 @@ use super::bindings::reflector::reflect_dom_object; use super::readablestreamgenericreader::ReadableStreamGenericReader; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::ReadableStreamBYOBReaderBinding::ReadableStreamBYOBReaderMethods; -use crate::dom::bindings::error::{Error, ErrorToJsval}; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, ErrorToJsval, Fallible}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::trace::RootedTraceableBox; diff --git a/components/script/dom/readablestreambyobrequest.rs b/components/script/dom/readablestreambyobrequest.rs index 286de7e892e..3ec84ebc28d 100644 --- a/components/script/dom/readablestreambyobrequest.rs +++ b/components/script/dom/readablestreambyobrequest.rs @@ -11,7 +11,7 @@ use super::bindings::cell::DomRefCell; use super::bindings::reflector::reflect_dom_object; use super::bindings::root::DomRoot; use crate::dom::bindings::codegen::Bindings::ReadableStreamBYOBRequestBinding::ReadableStreamBYOBRequestMethods; -use crate::dom::bindings::import::module::{Error, Fallible}; +use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::reflector::Reflector; use crate::dom::bindings::root::MutNullableDom; use crate::dom::readablebytestreamcontroller::ReadableByteStreamController; diff --git a/components/script/dom/readablestreamdefaultreader.rs b/components/script/dom/readablestreamdefaultreader.rs index 967cdcbf9b4..f71de6ac73c 100644 --- a/components/script/dom/readablestreamdefaultreader.rs +++ b/components/script/dom/readablestreamdefaultreader.rs @@ -20,8 +20,7 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::ReadableStreamDefaultReaderBinding::{ ReadableStreamDefaultReaderMethods, ReadableStreamReadResult, }; -use crate::dom::bindings::error::{Error, ErrorToJsval}; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, ErrorToJsval, Fallible}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::trace::RootedTraceableBox; diff --git a/components/script/dom/readablestreamgenericreader.rs b/components/script/dom/readablestreamgenericreader.rs index ccd7eca830e..b3767f48267 100644 --- a/components/script/dom/readablestreamgenericreader.rs +++ b/components/script/dom/readablestreamgenericreader.rs @@ -9,8 +9,7 @@ use js::rust::HandleValue as SafeHandleValue; use super::readablestream::ReaderType; use super::types::ReadableStream; -use crate::dom::bindings::error::{Error, ErrorToJsval}; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, ErrorToJsval, Fallible}; use crate::dom::bindings::reflector::DomGlobal; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::globalscope::GlobalScope; diff --git a/components/script/dom/stereopannernode.rs b/components/script/dom/stereopannernode.rs index 8a05ae6416d..c2643bc90d7 100644 --- a/components/script/dom/stereopannernode.rs +++ b/components/script/dom/stereopannernode.rs @@ -8,6 +8,8 @@ use servo_media::audio::node::{AudioNodeInit, AudioNodeType}; use servo_media::audio::param::ParamType; use servo_media::audio::stereo_panner::StereoPannerOptions as ServoMediaStereoPannerOptions; +use crate::conversions::Convert; +use crate::dom::audionode::AudioNodeOptionsHelper; use crate::dom::audioparam::AudioParam; use crate::dom::audioscheduledsourcenode::AudioScheduledSourceNode; use crate::dom::baseaudiocontext::BaseAudioContext; @@ -48,8 +50,9 @@ impl StereoPannerNode { if node_options.count > 2 || node_options.count == 0 { return Err(Error::NotSupported); } + let pan = *options.pan; let source_node = AudioScheduledSourceNode::new_inherited( - AudioNodeInit::StereoPannerNode(options.into()), + AudioNodeInit::StereoPannerNode(options.convert()), context, node_options, 1, /* inputs */ @@ -63,7 +66,7 @@ impl StereoPannerNode { AudioNodeType::StereoPannerNode, ParamType::Pan, AutomationRate::A_rate, - *options.pan, + pan, -1., 1., CanGc::note(), @@ -120,8 +123,8 @@ impl StereoPannerNodeMethods<crate::DomTypeHolder> for StereoPannerNode { } } -impl<'a> From<&'a StereoPannerOptions> for ServoMediaStereoPannerOptions { - fn from(options: &'a StereoPannerOptions) -> Self { - Self { pan: *options.pan } +impl Convert<ServoMediaStereoPannerOptions> for StereoPannerOptions { + fn convert(self) -> ServoMediaStereoPannerOptions { + ServoMediaStereoPannerOptions { pan: *self.pan } } } diff --git a/components/script/dom/subtlecrypto.rs b/components/script/dom/subtlecrypto.rs index 17c3ff752ae..a0211819a19 100644 --- a/components/script/dom/subtlecrypto.rs +++ b/components/script/dom/subtlecrypto.rs @@ -38,7 +38,6 @@ use crate::dom::bindings::codegen::UnionTypes::{ ArrayBufferViewOrArrayBuffer, ArrayBufferViewOrArrayBufferOrJsonWebKey, }; use crate::dom::bindings::error::{Error, Fallible}; -use crate::dom::bindings::import::module::SafeJSContext; use crate::dom::bindings::refcounted::{Trusted, TrustedPromise}; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; use crate::dom::bindings::root::DomRoot; @@ -258,7 +257,7 @@ impl SubtleCryptoMethods<crate::DomTypeHolder> for SubtleCrypto { /// <https://w3c.github.io/webcrypto/#SubtleCrypto-method-sign> fn Sign( &self, - cx: SafeJSContext, + cx: JSContext, algorithm: AlgorithmIdentifier, key: &CryptoKey, data: ArrayBufferViewOrArrayBuffer, @@ -341,7 +340,7 @@ impl SubtleCryptoMethods<crate::DomTypeHolder> for SubtleCrypto { /// <https://w3c.github.io/webcrypto/#SubtleCrypto-method-verify> fn Verify( &self, - cx: SafeJSContext, + cx: JSContext, algorithm: AlgorithmIdentifier, key: &CryptoKey, signature: ArrayBufferViewOrArrayBuffer, @@ -429,7 +428,7 @@ impl SubtleCryptoMethods<crate::DomTypeHolder> for SubtleCrypto { /// <https://w3c.github.io/webcrypto/#SubtleCrypto-method-digest> fn Digest( &self, - cx: SafeJSContext, + cx: JSContext, algorithm: AlgorithmIdentifier, data: ArrayBufferViewOrArrayBuffer, comp: InRealm, @@ -533,7 +532,7 @@ impl SubtleCryptoMethods<crate::DomTypeHolder> for SubtleCrypto { /// <https://w3c.github.io/webcrypto/#SubtleCrypto-method-deriveKey> fn DeriveKey( &self, - cx: SafeJSContext, + cx: JSContext, algorithm: AlgorithmIdentifier, base_key: &CryptoKey, derived_key_type: AlgorithmIdentifier, @@ -663,7 +662,7 @@ impl SubtleCryptoMethods<crate::DomTypeHolder> for SubtleCrypto { /// <https://w3c.github.io/webcrypto/#dfn-SubtleCrypto-method-deriveBits> fn DeriveBits( &self, - cx: SafeJSContext, + cx: JSContext, algorithm: AlgorithmIdentifier, base_key: &CryptoKey, length: Option<u32>, @@ -2631,7 +2630,11 @@ fn data_to_jwk_params(alg: &str, size: &str, key: &[u8]) -> (DOMString, DOMStrin (jwk_alg, DOMString::from(data)) } -impl KeyAlgorithm { +trait AlgorithmFromName { + fn from_name(name: DOMString, out: MutableHandleObject, cx: JSContext); +} + +impl AlgorithmFromName for KeyAlgorithm { /// Fill the object referenced by `out` with an [KeyAlgorithm] /// of the specified name and size. #[allow(unsafe_code)] @@ -2644,7 +2647,16 @@ impl KeyAlgorithm { } } -impl HmacKeyAlgorithm { +trait AlgorithmFromLengthAndHash { + fn from_length_and_hash( + length: u32, + hash: DigestAlgorithm, + out: MutableHandleObject, + cx: JSContext, + ); +} + +impl AlgorithmFromLengthAndHash for HmacKeyAlgorithm { #[allow(unsafe_code)] fn from_length_and_hash( length: u32, @@ -2666,7 +2678,11 @@ impl HmacKeyAlgorithm { } } -impl AesKeyAlgorithm { +trait AlgorithmFromNameAndSize { + fn from_name_and_size(name: DOMString, size: u16, out: MutableHandleObject, cx: JSContext); +} + +impl AlgorithmFromNameAndSize for AesKeyAlgorithm { /// Fill the object referenced by `out` with an [AesKeyAlgorithm] /// of the specified name and size. #[allow(unsafe_code)] diff --git a/components/script/dom/underlyingsourcecontainer.rs b/components/script/dom/underlyingsourcecontainer.rs index 173cbf922b1..e219bbb7b8a 100644 --- a/components/script/dom/underlyingsourcecontainer.rs +++ b/components/script/dom/underlyingsourcecontainer.rs @@ -12,8 +12,8 @@ use js::rust::{Handle as SafeHandle, HandleObject, HandleValue as SafeHandleValu use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::codegen::Bindings::UnderlyingSourceBinding::UnderlyingSource as JsUnderlyingSource; -use crate::dom::bindings::import::module::Error; -use crate::dom::bindings::import::module::UnionTypes::ReadableStreamDefaultControllerOrReadableByteStreamController as Controller; +use crate::dom::bindings::codegen::UnionTypes::ReadableStreamDefaultControllerOrReadableByteStreamController as Controller; +use crate::dom::bindings::error::Error; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::defaultteeunderlyingsource::DefaultTeeUnderlyingSource; diff --git a/components/script/dom/webgpu/gpucanvascontext.rs b/components/script/dom/webgpu/gpucanvascontext.rs index fd621ebc335..1f5de8ea194 100644 --- a/components/script/dom/webgpu/gpucanvascontext.rs +++ b/components/script/dom/webgpu/gpucanvascontext.rs @@ -19,7 +19,7 @@ use webrender_api::units::DeviceIntSize; use super::gpuconvert::convert_texture_descriptor; use super::gputexture::GPUTexture; -use crate::canvas_context::CanvasContext; +use crate::canvas_context::{CanvasContext, CanvasHelpers}; use crate::conversions::Convert; use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods; use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUTexture_Binding::GPUTextureMethods; diff --git a/components/script/dom/webgpu/gpucompilationinfo.rs b/components/script/dom/webgpu/gpucompilationinfo.rs index 70fcd3f5398..a2f0cc3ff89 100644 --- a/components/script/dom/webgpu/gpucompilationinfo.rs +++ b/components/script/dom/webgpu/gpucompilationinfo.rs @@ -7,8 +7,8 @@ use js::rust::MutableHandleValue; use webgpu::ShaderCompilationInfo; use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUCompilationInfoMethods; -use crate::dom::bindings::import::module::DomRoot; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto}; +use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::utils::to_frozen_array; use crate::dom::globalscope::GlobalScope; use crate::dom::types::GPUCompilationMessage; diff --git a/components/script/dom/webgpu/gpudevice.rs b/components/script/dom/webgpu/gpudevice.rs index 681d90e40e3..c5f4638479d 100644 --- a/components/script/dom/webgpu/gpudevice.rs +++ b/components/script/dom/webgpu/gpudevice.rs @@ -21,6 +21,7 @@ use webgpu::{ use super::gpu::AsyncWGPUListener; use super::gpudevicelostinfo::GPUDeviceLostInfo; +use super::gpuerror::AsWebGpu; use super::gpupipelineerror::GPUPipelineError; use super::gpusupportedlimits::GPUSupportedLimits; use crate::conversions::Convert; diff --git a/components/script/dom/webgpu/gpuerror.rs b/components/script/dom/webgpu/gpuerror.rs index 3456b09165e..8b9d643d8b9 100644 --- a/components/script/dom/webgpu/gpuerror.rs +++ b/components/script/dom/webgpu/gpuerror.rs @@ -90,8 +90,12 @@ impl Convert<GPUErrorFilter> for ErrorFilter { } } -impl GPUErrorFilter { - pub(crate) fn as_webgpu(&self) -> ErrorFilter { +pub(crate) trait AsWebGpu { + fn as_webgpu(&self) -> ErrorFilter; +} + +impl AsWebGpu for GPUErrorFilter { + fn as_webgpu(&self) -> ErrorFilter { match self { GPUErrorFilter::Validation => ErrorFilter::Validation, GPUErrorFilter::Out_of_memory => ErrorFilter::OutOfMemory, diff --git a/components/script/dom/webgpu/gpurenderbundleencoder.rs b/components/script/dom/webgpu/gpurenderbundleencoder.rs index 2e7a1cc8f35..1353f46dd5b 100644 --- a/components/script/dom/webgpu/gpurenderbundleencoder.rs +++ b/components/script/dom/webgpu/gpurenderbundleencoder.rs @@ -16,7 +16,7 @@ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ GPUIndexFormat, GPURenderBundleDescriptor, GPURenderBundleEncoderDescriptor, GPURenderBundleEncoderMethods, }; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::Fallible; use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::USVString; diff --git a/components/script/dom/webxr/xrwebgllayer.rs b/components/script/dom/webxr/xrwebgllayer.rs index e06ae3fd3b6..0e93e583c6f 100644 --- a/components/script/dom/webxr/xrwebgllayer.rs +++ b/components/script/dom/webxr/xrwebgllayer.rs @@ -11,6 +11,7 @@ use js::rust::HandleObject; use webxr_api::{ContextId as WebXRContextId, LayerId, LayerInit, Viewport}; use crate::canvas_context::CanvasContext as _; +use crate::conversions::Convert; use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants; use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::{ @@ -35,15 +36,15 @@ use crate::dom::xrview::XRView; use crate::dom::xrviewport::XRViewport; use crate::script_runtime::CanGc; -impl<'a> From<&'a XRWebGLLayerInit> for LayerInit { - fn from(init: &'a XRWebGLLayerInit) -> LayerInit { +impl Convert<LayerInit> for XRWebGLLayerInit { + fn convert(self) -> LayerInit { LayerInit::WebGLLayer { - alpha: init.alpha, - antialias: init.antialias, - depth: init.depth, - stencil: init.stencil, - framebuffer_scale_factor: *init.framebufferScaleFactor as f32, - ignore_depth_values: init.ignoreDepthValues, + alpha: self.alpha, + antialias: self.antialias, + depth: self.depth, + stencil: self.stencil, + framebuffer_scale_factor: *self.framebufferScaleFactor as f32, + ignore_depth_values: self.ignoreDepthValues, } } } @@ -271,7 +272,7 @@ impl XRWebGLLayerMethods<crate::DomTypeHolder> for XRWebGLLayer { // Step 9.3. "Allocate and initialize resources compatible with session’s XR device, // including GPU accessible memory buffers, as required to support the compositing of layer." let context_id = WebXRContextId::from(context.context_id()); - let layer_init = LayerInit::from(init); + let layer_init: LayerInit = init.convert(); let layer_id = session .with_session(|session| session.create_layer(context_id, layer_init)) .map_err(|_| Error::Operation)?; diff --git a/components/script/dom/writablestream.rs b/components/script/dom/writablestream.rs index 9d86f65d858..7de6b013169 100644 --- a/components/script/dom/writablestream.rs +++ b/components/script/dom/writablestream.rs @@ -21,8 +21,7 @@ use crate::dom::bindings::codegen::Bindings::QueuingStrategyBinding::QueuingStra use crate::dom::bindings::codegen::Bindings::UnderlyingSinkBinding::UnderlyingSink; use crate::dom::bindings::codegen::Bindings::WritableStreamBinding::WritableStreamMethods; use crate::dom::bindings::conversions::ConversionResult; -use crate::dom::bindings::error::Error; -use crate::dom::bindings::import::module::Fallible; +use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto}; use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom}; use crate::dom::countqueuingstrategy::{extract_high_water_mark, extract_size_algorithm}; diff --git a/components/script/security_manager.rs b/components/script/security_manager.rs index 391a54f30dd..223fd5e005a 100644 --- a/components/script/security_manager.rs +++ b/components/script/security_manager.rs @@ -49,6 +49,7 @@ pub(crate) struct SecurityPolicyViolationReport { line_number: u32, column_number: u32, original_policy: String, + #[serde(serialize_with = "serialize_disposition")] disposition: SecurityPolicyViolationEventDisposition, } @@ -170,11 +171,12 @@ impl Convert<SecurityPolicyViolationEventInit> for SecurityPolicyViolationReport } } -impl Serialize for SecurityPolicyViolationEventDisposition { - fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { - match self { - Self::Report => serializer.serialize_str("report"), - Self::Enforce => serializer.serialize_str("enforce"), - } +fn serialize_disposition<S: serde::Serializer>( + val: &SecurityPolicyViolationEventDisposition, + serializer: S, +) -> Result<S::Ok, S::Error> { + match val { + SecurityPolicyViolationEventDisposition::Report => serializer.serialize_str("report"), + SecurityPolicyViolationEventDisposition::Enforce => serializer.serialize_str("enforce"), } } |