script: Add message to InvalidStateError (#39535)

Adding an optional message to be attached to an InvalidStateError.

Testing: Only a refactor, no behavior change
Fixes: Partially #39053

Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>
This commit is contained in:
Excitable Snowball 2025-09-27 12:23:05 -07:00 committed by GitHub
parent 55d094a871
commit 601ad7e5c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
58 changed files with 182 additions and 168 deletions

View file

@ -149,7 +149,7 @@ impl AudioBufferSourceNodeMethods<crate::DomTypeHolder> for AudioBufferSourceNod
if new_buffer.is_some() {
if self.buffer_set.get() {
// Step 2.
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3.
self.buffer_set.set(true);

View file

@ -146,7 +146,7 @@ impl AudioContextMethods<crate::DomTypeHolder> for AudioContext {
// Step 2.
if self.context.control_thread_state() == ProcessingState::Closed {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}
@ -202,7 +202,7 @@ impl AudioContextMethods<crate::DomTypeHolder> for AudioContext {
// Step 2.
if self.context.control_thread_state() == ProcessingState::Closed {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}

View file

@ -259,7 +259,7 @@ impl AudioNodeMethods<crate::DomTypeHolder> for AudioNode {
match self.upcast::<EventTarget>().type_id() {
EventTargetTypeId::AudioNode(AudioNodeTypeId::AudioDestinationNode) => {
if self.context.is_offline() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
} else if !(1..=MAX_CHANNEL_COUNT).contains(&value) {
return Err(Error::IndexSize);
}
@ -277,10 +277,10 @@ impl AudioNodeMethods<crate::DomTypeHolder> for AudioNode {
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) => {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
},
// XXX We do not support any of the other AudioNodes with
// constraints yet. Add more cases here as we add support
@ -312,7 +312,7 @@ impl AudioNodeMethods<crate::DomTypeHolder> for AudioNode {
match self.upcast::<EventTarget>().type_id() {
EventTargetTypeId::AudioNode(AudioNodeTypeId::AudioDestinationNode) => {
if self.context.is_offline() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::PannerNode) => {
@ -328,10 +328,10 @@ impl AudioNodeMethods<crate::DomTypeHolder> for AudioNode {
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) => {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
},
// XXX We do not support any of the other AudioNodes with
// constraints yet. Add more cases here as we add support
@ -359,7 +359,7 @@ impl AudioNodeMethods<crate::DomTypeHolder> for AudioNode {
if let EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelSplitterNode) =
self.upcast::<EventTarget>().type_id()
{
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
self.channel_interpretation.set(value);

View file

@ -129,7 +129,7 @@ impl AudioParamMethods<crate::DomTypeHolder> for AudioParam {
self.node_type == AudioNodeType::AudioBufferSourceNode &&
(self.param == ParamType::Detune || self.param == ParamType::PlaybackRate)
{
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.automation_rate.set(automation_rate);
@ -274,7 +274,7 @@ impl AudioParamMethods<crate::DomTypeHolder> for AudioParam {
)));
}
if values.len() < 2. as usize {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if *end_time < 0. {

View file

@ -67,7 +67,7 @@ impl AudioScheduledSourceNodeMethods<crate::DomTypeHolder> for AudioScheduledSou
}
if self.has_start.get() || self.has_stop.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let this = Trusted::new(self);
@ -106,7 +106,7 @@ impl AudioScheduledSourceNodeMethods<crate::DomTypeHolder> for AudioScheduledSou
}
if !self.has_start.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.has_stop.set(true);
self.node

View file

@ -292,7 +292,7 @@ impl BaseAudioContextMethods<crate::DomTypeHolder> for BaseAudioContext {
// Step 2.
if self.audio_context_impl.lock().unwrap().state() == ProcessingState::Closed {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}

View file

@ -41,7 +41,7 @@ impl ChannelMergerNode {
);
if node_options.count != 1 || node_options.mode != ChannelCountMode::Explicit {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if options.numberOfInputs < 1 || options.numberOfInputs > MAX_CHANNEL_COUNT {

View file

@ -46,7 +46,7 @@ impl ChannelSplitterNode {
node_options.mode != ChannelCountMode::Explicit ||
node_options.interpretation != ChannelInterpretation::Discrete
{
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let node = AudioNode::new_inherited(

View file

@ -48,7 +48,7 @@ impl IIRFilterNode {
return Err(Error::NotSupported);
}
if options.feedforward.iter().all(|v| **v == 0.0) || *options.feedback[0] == 0.0 {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let node_options =
options

View file

@ -36,7 +36,7 @@ impl MediaStreamAudioSourceNode {
.get_tracks()
.iter()
.find(|t| t.ty() == MediaStreamType::Audio)
.ok_or(Error::InvalidState)?
.ok_or(Error::InvalidState(None))?
.id();
let node = AudioNode::new_inherited(
AudioNodeInit::MediaStreamSourceNode(track),

View file

@ -146,7 +146,7 @@ impl OfflineAudioContextMethods<crate::DomTypeHolder> for OfflineAudioContext {
fn StartRendering(&self, comp: InRealm, can_gc: CanGc) -> Rc<Promise> {
let promise = Promise::new_in_current_realm(comp, can_gc);
if self.rendering_started.get() {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}
self.rendering_started.set(true);

View file

@ -148,7 +148,7 @@ impl OscillatorNodeMethods<crate::DomTypeHolder> for OscillatorNode {
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
fn SetType(&self, type_: OscillatorType) -> ErrorResult {
if type_ == OscillatorType::Custom {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.oscillator_type.set(type_);
self.source_node

View file

@ -86,7 +86,7 @@ impl PannerNode {
return Err(Error::Range("rolloffFactor should be non-negative".into()));
}
if *options.coneOuterGain < 0. || *options.coneOuterGain > 1. {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let options = options.convert();
let node = AudioNode::new_inherited(
@ -356,7 +356,7 @@ impl PannerNodeMethods<crate::DomTypeHolder> for PannerNode {
// https://webaudio.github.io/web-audio-api/#dom-pannernode-coneoutergain
fn SetConeOuterGain(&self, val: Finite<f64>) -> Fallible<()> {
if *val < 0. || *val > 1. {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.cone_outer_gain.set(*val);
let msg = PannerNodeMessage::SetConeGain(self.cone_outer_gain.get());

View file

@ -199,7 +199,7 @@ fn html_constructor(
}
if !check_type(&element) {
throw_dom_exception(cx, global, Error::InvalidState, can_gc);
throw_dom_exception(cx, global, Error::InvalidState(None), can_gc);
return Err(());
} else {
// Step 7.9 Return element.
@ -217,7 +217,7 @@ fn html_constructor(
// Step 13
if !check_type(&element) {
throw_dom_exception(cx, global, Error::InvalidState, can_gc);
throw_dom_exception(cx, global, Error::InvalidState(None), can_gc);
return Err(());
} else {
element

View file

@ -116,7 +116,10 @@ pub(crate) fn create_dom_exception(
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
Error::NotSupported => DOMErrorName::NotSupportedError,
Error::InUseAttribute => DOMErrorName::InUseAttributeError,
Error::InvalidState => DOMErrorName::InvalidStateError,
Error::InvalidState(Some(custom_message)) => {
return new_custom_exception(DOMErrorName::InvalidStateError, custom_message);
},
Error::InvalidState(None) => DOMErrorName::InvalidStateError,
Error::Syntax(Some(custom_message)) => {
return new_custom_exception(DOMErrorName::SyntaxError, custom_message);
},

View file

@ -533,7 +533,7 @@ impl Convert<Error> for BluetoothError {
BluetoothError::NotFound => Error::NotFound(None),
BluetoothError::NotSupported => Error::NotSupported,
BluetoothError::Security => Error::Security,
BluetoothError::InvalidState => Error::InvalidState,
BluetoothError::InvalidState => Error::InvalidState(None),
}
}
}

View file

@ -81,7 +81,7 @@ impl BroadcastChannelMethods<crate::DomTypeHolder> for BroadcastChannel {
fn PostMessage(&self, cx: SafeJSContext, message: HandleValue) -> ErrorResult {
// Step 3, if closed.
if self.closed.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 6, StructuredSerialize(message).

View file

@ -507,7 +507,7 @@ impl CanvasState {
CanvasImageSource::HTMLCanvasElement(ref canvas) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if canvas.get_size().is_empty() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.draw_html_canvas_element(canvas, htmlcanvas, sx, sy, sw, sh, dx, dy, dw, dh)
@ -515,7 +515,7 @@ impl CanvasState {
CanvasImageSource::ImageBitmap(ref bitmap) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if bitmap.is_detached() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.draw_image_bitmap(bitmap, htmlcanvas, sx, sy, sw, sh, dx, dy, dw, dh);
@ -524,7 +524,7 @@ impl CanvasState {
CanvasImageSource::OffscreenCanvas(ref canvas) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if canvas.get_size().is_empty() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.draw_offscreen_canvas(canvas, htmlcanvas, sx, sy, sw, sh, dx, dy, dw, dh)
@ -532,7 +532,7 @@ impl CanvasState {
CanvasImageSource::CSSStyleValue(ref value) => {
let url = value
.get_url(self.base_url.clone())
.ok_or(Error::InvalidState)?;
.ok_or(Error::InvalidState(None))?;
self.fetch_and_draw_image_data(
htmlcanvas, url, None, sx, sy, sw, sh, dx, dy, dw, dh,
)
@ -705,7 +705,7 @@ impl CanvasState {
self.state.borrow().transform,
));
},
OffscreenRenderingContext::Detached => return Err(Error::InvalidState),
OffscreenRenderingContext::Detached => return Err(Error::InvalidState(None)),
}
} else {
self.send_canvas_2d_msg(Canvas2dMsg::DrawEmptyImage(
@ -786,7 +786,7 @@ impl CanvasState {
},
RenderingContext::Placeholder(ref context) => {
let Some(context) = context.context() else {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
match *context {
OffscreenRenderingContext::Context2d(ref context) => context
@ -814,10 +814,12 @@ impl CanvasState {
self.state.borrow().transform,
));
},
OffscreenRenderingContext::Detached => return Err(Error::InvalidState),
OffscreenRenderingContext::Detached => {
return Err(Error::InvalidState(None));
},
}
},
_ => return Err(Error::InvalidState),
_ => return Err(Error::InvalidState(None)),
}
} else {
self.send_canvas_2d_msg(Canvas2dMsg::DrawEmptyImage(
@ -852,7 +854,7 @@ impl CanvasState {
debug!("Fetching image {}.", url);
let snapshot = self
.fetch_image_data(url, cors_setting)
.ok_or(Error::InvalidState)?;
.ok_or(Error::InvalidState(None))?;
let image_size = snapshot.size();
let dw = dw.unwrap_or(image_size.width as f64);
@ -1254,7 +1256,9 @@ impl CanvasState {
return Ok(None);
}
image.get_raster_image_data().ok_or(Error::InvalidState)?
image
.get_raster_image_data()
.ok_or(Error::InvalidState(None))?
},
CanvasImageSource::HTMLVideoElement(ref video) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
@ -1262,36 +1266,41 @@ impl CanvasState {
return Ok(None);
}
video.get_current_frame_data().ok_or(Error::InvalidState)?
video
.get_current_frame_data()
.ok_or(Error::InvalidState(None))?
},
CanvasImageSource::HTMLCanvasElement(ref canvas) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if canvas.get_size().is_empty() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
canvas.get_image_data().ok_or(Error::InvalidState)?
canvas.get_image_data().ok_or(Error::InvalidState(None))?
},
CanvasImageSource::ImageBitmap(ref bitmap) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if bitmap.is_detached() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
bitmap.bitmap_data().clone().ok_or(Error::InvalidState)?
bitmap
.bitmap_data()
.clone()
.ok_or(Error::InvalidState(None))?
},
CanvasImageSource::OffscreenCanvas(ref canvas) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if canvas.get_size().is_empty() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
canvas.get_image_data().ok_or(Error::InvalidState)?
canvas.get_image_data().ok_or(Error::InvalidState(None))?
},
CanvasImageSource::CSSStyleValue(ref value) => value
.get_url(self.base_url.clone())
.and_then(|url| self.fetch_image_data(url, None))
.ok_or(Error::InvalidState)?,
.ok_or(Error::InvalidState(None))?,
};
if repetition.is_empty() {

View file

@ -310,12 +310,12 @@ impl ImageBitmap {
// Step 2. If either options's resizeWidth or options's resizeHeight is present and is 0,
// then return a promise rejected with an "InvalidStateError" DOMException.
if options.resizeWidth.is_some_and(|w| w == 0) {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
if options.resizeHeight.is_some_and(|h| h == 0) {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
@ -346,7 +346,7 @@ impl ImageBitmap {
.queue(task!(reject_promise: move || {
let promise = trusted_promise.root();
promise.reject_error(Error::InvalidState, CanGc::note());
promise.reject_error(Error::InvalidState(None), CanGc::note());
}));
};
@ -357,14 +357,14 @@ impl ImageBitmap {
ImageBitmapSource::HTMLImageElement(ref image) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if !image.is_usable().is_ok_and(|u| u) {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
// If no ImageBitmap object can be constructed, then the promise
// is rejected instead.
let Some(snapshot) = image.get_raster_image_data() else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -373,7 +373,7 @@ impl ImageBitmap {
let Some(bitmap_data) =
ImageBitmap::crop_and_transform_bitmap_data(snapshot, sx, sy, sw, sh, options)
else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -389,20 +389,20 @@ impl ImageBitmap {
ImageBitmapSource::HTMLVideoElement(ref video) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if !video.is_usable() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
// Step 6.1. If image's networkState attribute is NETWORK_EMPTY, then return
// a promise rejected with an "InvalidStateError" DOMException.
if video.is_network_state_empty() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
// If no ImageBitmap object can be constructed, then the promise is rejected instead.
let Some(snapshot) = video.get_current_frame_data() else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -413,7 +413,7 @@ impl ImageBitmap {
let Some(bitmap_data) =
ImageBitmap::crop_and_transform_bitmap_data(snapshot, sx, sy, sw, sh, options)
else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -429,13 +429,13 @@ impl ImageBitmap {
ImageBitmapSource::HTMLCanvasElement(ref canvas) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if canvas.get_size().is_empty() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
// If no ImageBitmap object can be constructed, then the promise is rejected instead.
let Some(snapshot) = canvas.get_image_data() else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -444,7 +444,7 @@ impl ImageBitmap {
let Some(bitmap_data) =
ImageBitmap::crop_and_transform_bitmap_data(snapshot, sx, sy, sw, sh, options)
else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -460,13 +460,13 @@ impl ImageBitmap {
ImageBitmapSource::ImageBitmap(ref bitmap) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if bitmap.is_detached() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
// If no ImageBitmap object can be constructed, then the promise is rejected instead.
let Some(snapshot) = bitmap.bitmap_data().clone() else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -475,7 +475,7 @@ impl ImageBitmap {
let Some(bitmap_data) =
ImageBitmap::crop_and_transform_bitmap_data(snapshot, sx, sy, sw, sh, options)
else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -491,13 +491,13 @@ impl ImageBitmap {
ImageBitmapSource::OffscreenCanvas(ref canvas) => {
// <https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument>
if canvas.get_size().is_empty() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
// If no ImageBitmap object can be constructed, then the promise is rejected instead.
let Some(snapshot) = canvas.get_image_data() else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -506,7 +506,7 @@ impl ImageBitmap {
let Some(bitmap_data) =
ImageBitmap::crop_and_transform_bitmap_data(snapshot, sx, sy, sw, sh, options)
else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};
@ -582,7 +582,7 @@ impl ImageBitmap {
// Step 6.2. If IsDetachedBuffer(buffer) is true, then return a promise rejected
// with an "InvalidStateError" DOMException.
if image_data.is_detached() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
@ -602,7 +602,7 @@ impl ImageBitmap {
let Some(bitmap_data) =
ImageBitmap::crop_and_transform_bitmap_data(snapshot, sx, sy, sw, sh, options)
else {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
};

View file

@ -184,7 +184,7 @@ impl ImageBitmapRenderingContextMethods<crate::DomTypeHolder> for ImageBitmapRen
// is set to true, then throw an "InvalidStateError"
// DOMException.
if image_bitmap.is_detached() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 4. Run the steps to set an ImageBitmapRenderingContext's

View file

@ -92,7 +92,7 @@ impl ImageData {
// then throw an "InvalidStateError" DOMException.
if !matches!(settings.pixelFormat, ImageDataPixelFormat::Rgba_unorm8) {
// we currently support only rgba-unorm8
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// 3. Initialize the data attribute of imageData to source.
HeapBufferSource::<ClampedU8>::from_view(source)
@ -252,12 +252,12 @@ impl ImageDataMethods<crate::DomTypeHolder> for ImageData {
// 2. Let length be the buffer source byte length of data.
let length = data.len();
if length == 0 {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// 3. If length is not a nonzero integral multiple of bytesPerPixel,
// then throw an "InvalidStateError" DOMException.
if length % bytes_per_pixel != 0 {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// 4. Let length be length divided by bytesPerPixel.
let length = length / bytes_per_pixel;

View file

@ -198,12 +198,12 @@ impl Transferable for OffscreenCanvas {
// Step 1. If value's context mode is not equal to none, then throw an
// "InvalidStateError" DOMException.
if !self.context.borrow().is_none() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// TODO(#37882): Allow to transfer with a placeholder canvas element.
if self.placeholder.is_some() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2. Set value's context mode to detached.
@ -294,7 +294,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
// Step 3. Throw an "InvalidStateError" DOMException if the
// OffscreenCanvas object's context mode is detached.
if let Some(OffscreenRenderingContext::Detached) = *self.context.borrow() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
match id.str() {
@ -358,20 +358,20 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
// internal slot is set to true, then throw an "InvalidStateError"
// DOMException.
if let Some(OffscreenRenderingContext::Detached) = *self.context.borrow() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2. If this OffscreenCanvas object's context mode is set to none,
// then throw an "InvalidStateError" DOMException.
if self.context.borrow().is_none() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3. Let image be a newly created ImageBitmap object that
// references the same underlying bitmap data as this OffscreenCanvas
// object's bitmap.
let Some(snapshot) = self.get_image_data() else {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
let image_bitmap = ImageBitmap::new(&self.global(), snapshot, can_gc);
@ -399,7 +399,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
// then return a promise rejected with an "InvalidStateError"
// DOMException.
if let Some(OffscreenRenderingContext::Detached) = *self.context.borrow() {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}
@ -421,7 +421,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
// Step 4. Let bitmap be a copy of this's bitmap.
let Some(mut snapshot) = self.get_image_data() else {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
};

View file

@ -39,7 +39,7 @@ impl Convert<Error> for RulesMutateError {
RulesMutateError::Syntax => Error::Syntax(None),
RulesMutateError::IndexSize => Error::IndexSize,
RulesMutateError::HierarchyRequest => Error::HierarchyRequest,
RulesMutateError::InvalidState => Error::InvalidState,
RulesMutateError::InvalidState => Error::InvalidState(None),
}
}
}

View file

@ -166,7 +166,7 @@ impl DataTransferItemListMethods<crate::DomTypeHolder> for DataTransferItemList
let mut option = self.data_store.borrow_mut();
let data_store = match option.as_mut() {
Some(value) if value.mode() == Mode::ReadWrite => value,
_ => return Err(Error::InvalidState),
_ => return Err(Error::InvalidState(None)),
};
let index = index as usize;

View file

@ -3139,13 +3139,13 @@ impl Document {
}
// Step 6: If document is an XML document, then throw an "InvalidStateError" DOMException.
if !self.is_html_document() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 7: If document's throw-on-dynamic-markup-insertion counter is greater than 0,
// then throw an "InvalidStateError" DOMException.
if self.throw_on_dynamic_markup_insertion_counter.get() > 0 {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 8: If document's active parser was aborted is true, then return.
@ -5663,12 +5663,12 @@ impl DocumentMethods<crate::DomTypeHolder> for Document {
) -> Fallible<DomRoot<Document>> {
// Step 1
if !self.is_html_document() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2
if self.throw_on_dynamic_markup_insertion_counter.get() > 0 {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3
@ -5808,12 +5808,12 @@ impl DocumentMethods<crate::DomTypeHolder> for Document {
fn Close(&self, can_gc: CanGc) -> ErrorResult {
if !self.is_html_document() {
// Step 1.
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2.
if self.throw_on_dynamic_markup_insertion_counter.get() > 0 {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let parser = match self.get_current_parser() {

View file

@ -860,7 +860,7 @@ impl DOMMatrixReadOnlyMethods<crate::DomTypeHolder> for DOMMatrixReadOnly {
!mat.m43.is_finite() ||
!mat.m44.is_finite()
{
return Err(error::Error::InvalidState);
return Err(error::Error::InvalidState(None));
}
let cx = GlobalScope::get_cx();

View file

@ -1132,7 +1132,7 @@ impl EventTargetMethods<crate::DomTypeHolder> for EventTarget {
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
fn DispatchEvent(&self, event: &Event, can_gc: CanGc) -> Fallible<bool> {
if event.dispatching() || !event.initialized() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
event.set_trusted(false);
Ok(self.dispatch_event(event, can_gc))

View file

@ -90,7 +90,7 @@ impl ExtendableEventMethods<crate::DomTypeHolder> for ExtendableEvent {
fn WaitUntil(&self, _cx: JSContext, _val: HandleValue) -> ErrorResult {
// Step 1
if !self.extensions_allowed {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2
// TODO add a extended_promises array to enqueue the `val`

View file

@ -490,7 +490,7 @@ impl FileReader {
// If frs state is "loading", throw an InvalidStateError DOMException.
if self.ready_state.get() == FileReaderReadyState::Loading {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Set frs state to "loading".

View file

@ -129,7 +129,7 @@ impl FormDataMethods<crate::DomTypeHolder> for FormData {
can_gc,
)),
// Step 1.3. If list is null, then throw an "InvalidStateError" DOMException.
None => Err(Error::InvalidState),
None => Err(Error::InvalidState(None)),
};
}

View file

@ -192,7 +192,7 @@ impl GamepadHapticActuatorMethods<crate::DomTypeHolder> for GamepadHapticActuato
let document = self.global().as_window().Document();
if !document.is_fully_active() {
playing_effect_promise.reject_error(Error::InvalidState, can_gc);
playing_effect_promise.reject_error(Error::InvalidState(None), can_gc);
}
self.sequence_id.set(self.sequence_id.get().wrapping_add(1));
@ -259,7 +259,7 @@ impl GamepadHapticActuatorMethods<crate::DomTypeHolder> for GamepadHapticActuato
let document = self.global().as_window().Document();
if !document.is_fully_active() {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}

View file

@ -401,7 +401,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
// > is set to placeholder, the user agent must throw an "InvalidStateError" DOMException and leave the
// > attribute's value unchanged.
if let Some(RenderingContext::Placeholder(_)) = *self.context_mode.borrow() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let value = if value > UNSIGNED_LONG_MAX {
@ -423,7 +423,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
// > is set to placeholder, the user agent must throw an "InvalidStateError" DOMException and leave the
// > attribute's value unchanged.
if let Some(RenderingContext::Placeholder(_)) = *self.context_mode.borrow() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let value = if value > UNSIGNED_LONG_MAX {
@ -446,7 +446,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
) -> Fallible<Option<RootedRenderingContext>> {
// Always throw an InvalidState exception when the canvas is in Placeholder mode (See table in the spec).
if let Some(RenderingContext::Placeholder(_)) = *self.context_mode.borrow() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
Ok(match id.str() {
@ -599,7 +599,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
if self.context_mode.borrow().is_some() {
// Step 1.
// If this canvas element's context mode is not set to none, throw an "InvalidStateError" DOMException.
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
// Step 2.

View file

@ -204,7 +204,7 @@ impl HTMLImageElement {
match self.current_request.borrow().state {
// If image's current request's state is broken, then throw an "InvalidStateError" DOMException.
State::Broken => Err(Error::InvalidState),
State::Broken => Err(Error::InvalidState(None)),
State::CompletelyAvailable => Ok(true),
// If image is not fully decodable, then return bad.
State::PartiallyAvailable | State::Unavailable => Ok(false),

View file

@ -846,13 +846,13 @@ impl HTMLInputElement {
fn step_up_or_down(&self, n: i32, dir: StepDirection, can_gc: CanGc) -> ErrorResult {
// Step 1
if !self.does_value_as_number_apply() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let step_base = self.step_base();
// Step 2
let allowed_value_step = match self.allowed_value_step() {
Some(avs) => avs,
None => return Err(Error::InvalidState),
None => return Err(Error::InvalidState(None)),
};
let minimum = self.minimum();
let maximum = self.maximum();
@ -1716,7 +1716,7 @@ impl HTMLInputElementMethods<crate::DomTypeHolder> for HTMLInputElement {
let fl = FileList::new(&window, vec![], can_gc);
self.filelist.set(Some(&fl));
} else {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
},
}
@ -1765,7 +1765,7 @@ impl HTMLInputElementMethods<crate::DomTypeHolder> for HTMLInputElement {
) -> ErrorResult {
rooted!(in(*cx) let value = value);
if !self.does_value_as_date_apply() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if value.is_null() {
return self.SetValue(DOMString::from(""), can_gc);
@ -1807,7 +1807,7 @@ impl HTMLInputElementMethods<crate::DomTypeHolder> for HTMLInputElement {
if value.is_infinite() {
Err(Error::Type("value is not finite".to_string()))
} else if !self.does_value_as_number_apply() {
Err(Error::InvalidState)
Err(Error::InvalidState(None))
} else if value.is_nan() {
self.SetValue(DOMString::from(""), can_gc)
} else if let Some(converted) = self.convert_number_to_string(value) {

View file

@ -163,7 +163,7 @@ impl IDBDatabaseMethods<crate::DomTypeHolder> for IDBDatabase {
// Step 2: if close flag is set, throw error
if self.closing.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3
@ -198,7 +198,7 @@ impl IDBDatabaseMethods<crate::DomTypeHolder> for IDBDatabase {
// Step 2
let upgrade_transaction = match self.upgrade_transaction.get() {
Some(txn) => txn,
None => return Err(Error::InvalidState),
None => return Err(Error::InvalidState(None)),
};
// Step 3
@ -276,7 +276,7 @@ impl IDBDatabaseMethods<crate::DomTypeHolder> for IDBDatabase {
.is_err()
{
warn!("Object store creation failed in idb thread");
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
self.object_store_names.borrow_mut().push(name);
@ -289,7 +289,7 @@ impl IDBDatabaseMethods<crate::DomTypeHolder> for IDBDatabase {
let transaction = self.upgrade_transaction.get();
let transaction = match transaction {
Some(transaction) => transaction,
None => return Err(Error::InvalidState),
None => return Err(Error::InvalidState(None)),
};
// Step 3
@ -330,7 +330,7 @@ impl IDBDatabaseMethods<crate::DomTypeHolder> for IDBDatabase {
.is_err()
{
warn!("Object store deletion failed in idb thread");
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
Ok(())
}

View file

@ -148,7 +148,7 @@ impl IDBObjectStore {
fn verify_not_deleted(&self) -> ErrorResult {
let db = self.transaction.Db();
if !db.object_store_exists(&self.name.borrow()) {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
Ok(())
}
@ -253,7 +253,7 @@ impl IDBObjectStore {
// Step 10. Let clone be a clone of value in targetRealm during transaction. Rethrow any exceptions.
let cloned_value = structuredclone::write(cx, value, None)?;
let Ok(serialized_value) = bincode::serialize(&cloned_value) else {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
let (sender, receiver) = indexed_db::create_channel(self.global());
@ -638,7 +638,7 @@ impl IDBObjectStoreMethods<crate::DomTypeHolder> for IDBObjectStore {
// Step 5. If transaction is not an upgrade transaction, throw an "InvalidStateError" DOMException.
if transaction.Mode() != IDBTransactionMode::Versionchange {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 6. If transactions state is not active, throw a "TransactionInactiveError" DOMException.
self.check_transaction_active()?;

View file

@ -263,7 +263,7 @@ impl IDBTransactionMethods<crate::DomTypeHolder> for IDBTransaction {
fn ObjectStore(&self, name: DOMString) -> Fallible<DomRoot<IDBObjectStore>> {
// Step 1: If transaction has finished, throw an "InvalidStateError" DOMException.
if self.finished.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2: Check that the object store exists
@ -332,7 +332,7 @@ impl IDBTransactionMethods<crate::DomTypeHolder> for IDBTransaction {
// This only sets the flags, and does not abort the transaction
// see https://www.w3.org/TR/IndexedDB-2/#abort-a-transaction
if self.finished.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
self.active.set(false);

View file

@ -3202,13 +3202,13 @@ impl Node {
)
.map_err(|error| {
error!("Cannot serialize node: {error}");
Error::InvalidState
Error::InvalidState(None)
})?;
// FIXME(ajeffrey): Directly convert UTF8 to DOMString
let string = DOMString::from(String::from_utf8(writer).map_err(|error| {
error!("Cannot serialize node: {error}");
Error::InvalidState
Error::InvalidState(None)
})?);
Ok(string)

View file

@ -201,7 +201,7 @@ impl NodeIterator {
fn accept_node(&self, node: &Node, can_gc: CanGc) -> Fallible<u16> {
// Step 1.
if self.active.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2.
let n = node.NodeType() - 1;

View file

@ -1028,7 +1028,7 @@ impl RangeMethods<crate::DomTypeHolder> for Range {
end.inclusive_ancestors(ShadowIncluding::No)
.any(|n| !n.is_inclusive_ancestor_of(&start) && !n.is::<Text>())
{
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2.

View file

@ -284,7 +284,7 @@ impl SelectionMethods<crate::DomTypeHolder> for Selection {
can_gc,
)
} else {
Err(Error::InvalidState)
Err(Error::InvalidState(None))
}
}
@ -293,7 +293,7 @@ impl SelectionMethods<crate::DomTypeHolder> for Selection {
if let Some(range) = self.range.get() {
self.Collapse(Some(&*range.end_container()), range.end_offset(), can_gc)
} else {
Err(Error::InvalidState)
Err(Error::InvalidState(None))
}
}
@ -365,7 +365,7 @@ impl SelectionMethods<crate::DomTypeHolder> for Selection {
};
} else {
// Step 2
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
Ok(())
}

View file

@ -100,7 +100,7 @@ impl ServiceWorker {
) -> ErrorResult {
// Step 1
if let ServiceWorkerState::Redundant = self.state.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 7
let data = structuredclone::write(cx, message, Some(transfer))?;

View file

@ -63,7 +63,7 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
pub(crate) fn set_dom_start(&self, start: Option<u32>) -> ErrorResult {
// Step 1
if !self.element.selection_api_applies() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2
@ -96,7 +96,7 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
pub(crate) fn set_dom_end(&self, end: Option<u32>) -> ErrorResult {
// Step 1
if !self.element.selection_api_applies() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2
@ -118,7 +118,7 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
pub(crate) fn set_dom_direction(&self, direction: Option<DOMString>) -> ErrorResult {
// Step 1
if !self.element.selection_api_applies() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2
@ -140,7 +140,7 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
) -> ErrorResult {
// Step 1
if !self.element.selection_api_applies() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2
@ -163,7 +163,7 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
) -> ErrorResult {
// Step 1
if !self.element.selection_api_applies() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2

View file

@ -442,7 +442,7 @@ impl TreeWalker {
fn accept_node(&self, node: &Node, can_gc: CanGc) -> Fallible<u16> {
// Step 1.
if self.active.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2.
let n = node.NodeType() - 1;

View file

@ -377,7 +377,7 @@ impl GPUCanvasContextMethods<crate::DomTypeHolder> for GPUCanvasContext {
// 1. If this.[[configuration]] is null, throw an InvalidStateError and return.
let configuration = self.configuration.borrow();
let Some(configuration) = configuration.as_ref() else {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
// 2. Assert this.[[textureDescriptor]] is not null.
let texture_descriptor = self.texture_descriptor.borrow();

View file

@ -259,7 +259,7 @@ impl RTCDataChannel {
fn send(&self, source: &SendSource) -> Fallible<()> {
if self.ready_state.get() != RTCDataChannelState::Open {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let message = match source {

View file

@ -594,7 +594,7 @@ impl RTCPeerConnectionMethods<crate::DomTypeHolder> for RTCPeerConnection {
fn CreateOffer(&self, _options: &RTCOfferOptions, comp: InRealm, can_gc: CanGc) -> Rc<Promise> {
let p = Promise::new_in_current_realm(comp, can_gc);
if self.closed.get() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
self.offer_promises.borrow_mut().push(p.clone());
@ -611,7 +611,7 @@ impl RTCPeerConnectionMethods<crate::DomTypeHolder> for RTCPeerConnection {
) -> Rc<Promise> {
let p = Promise::new_in_current_realm(comp, can_gc);
if self.closed.get() {
p.reject_error(Error::InvalidState, can_gc);
p.reject_error(Error::InvalidState(None), can_gc);
return p;
}
self.answer_promises.borrow_mut().push(p.clone());

View file

@ -143,7 +143,7 @@ impl WebSocket {
fn send_impl(&self, data_byte_len: u64) -> Fallible<bool> {
let return_after_buffer = match self.ready_state.get() {
WebSocketRequestState::Connecting => {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
},
WebSocketRequestState::Open => false,
WebSocketRequestState::Closing | WebSocketRequestState::Closed => true,

View file

@ -105,11 +105,11 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
can_gc: CanGc,
) -> Result<Option<DomRoot<XRViewerPose>>, Error> {
if self.session != reference.upcast::<XRSpace>().session() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if !self.active.get() || !self.animation_frame.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let to_base = if let Some(to_base) = reference.get_base_transform(&self.data) {
@ -139,10 +139,10 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
can_gc: CanGc,
) -> Result<Option<DomRoot<XRPose>>, Error> {
if self.session != space.session() || self.session != base_space.session() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if !self.active.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let space = if let Some(space) = self.get_pose(space) {
space
@ -168,10 +168,10 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
if self.session != space.upcast::<XRSpace>().session() ||
self.session != base_space.session()
{
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if !self.active.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let joint_frame = if let Some(frame) = space.frame(&self.data) {
frame
@ -210,12 +210,12 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
mut radii: CustomAutoRooterGuard<Float32Array>,
) -> Result<bool, Error> {
if !self.active.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
for joint_space in &joint_spaces {
if self.session != joint_space.upcast::<XRSpace>().session() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
}
@ -256,17 +256,17 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
mut transforms: CustomAutoRooterGuard<Float32Array>,
) -> Result<bool, Error> {
if !self.active.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
for space in &spaces {
if self.session != space.session() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
}
if self.session != base_space.session() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
if spaces.len() * 16 > transforms.len() {

View file

@ -57,12 +57,12 @@ impl XRMediaBindingMethods<crate::DomTypeHolder> for XRMediaBinding {
) -> Fallible<DomRoot<XRMediaBinding>> {
// Step 1.
if session.is_ended() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 2.
if !session.is_immersive() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Steps 3-5.

View file

@ -118,7 +118,7 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
if !rotate.i.is_finite() {
// if quaternion has zero norm, we'll get an infinite or NaN
// value for each element. This is preferable to checking for zero.
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let transform = RigidTransform3D::new(rotate, translate);
Ok(XRRigidTransform::new_with_proto(

View file

@ -671,18 +671,18 @@ impl XRSessionMethods<crate::DomTypeHolder> for XRSession {
fn UpdateRenderState(&self, init: &XRRenderStateInit, _: InRealm) -> ErrorResult {
// Step 2
if self.ended.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3:
if let Some(Some(ref layer)) = init.baseLayer {
if Dom::from_ref(layer.session()) != Dom::from_ref(self) {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
}
// Step 4:
if init.inlineVerticalFieldOfView.is_some() && self.is_immersive() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// https://immersive-web.github.io/layers/#updaterenderstatechanges
@ -1045,7 +1045,7 @@ impl XRSessionMethods<crate::DomTypeHolder> for XRSession {
supported_frame_rates.is_empty() ||
self.ended.get()
{
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}

View file

@ -179,7 +179,7 @@ impl XRSystemMethods<crate::DomTypeHolder> for XRSystem {
}
if self.pending_or_active_session() {
promise.reject_error(Error::InvalidState, can_gc);
promise.reject_error(Error::InvalidState(None), can_gc);
return promise;
}

View file

@ -82,17 +82,17 @@ impl XRWebGLBindingMethods<crate::DomTypeHolder> for XRWebGLBinding {
};
// Step 2
if session.is_ended() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// step 3
if context.IsContextLost() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 4
if !session.is_immersive() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
};
// Step 5 throw an InvalidStateError If contexts XR compatible boolean is false.

View file

@ -245,7 +245,7 @@ impl XRWebGLLayerMethods<crate::DomTypeHolder> for XRWebGLLayer {
// Step 2
if session.is_ended() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// XXXManishearth step 3: throw error if context is lost
// XXXManishearth step 4: check XR compat flag for immersive sessions

View file

@ -339,7 +339,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
// Step 1
if let Some(window) = DomRoot::downcast::<Window>(self.global()) {
if !window.Document().is_fully_active() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
}
@ -433,7 +433,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
// Step 1: If thiss state is not opened, then throw an "InvalidStateError" DOMException.
// Step 2: If thiss send() flag is set, then throw an "InvalidStateError" DOMException.
if self.ready_state.get() != XMLHttpRequestState::Opened || self.send_flag.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3: Normalize value.
@ -521,9 +521,9 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
// Step 1
XMLHttpRequestState::HeadersReceived |
XMLHttpRequestState::Loading |
XMLHttpRequestState::Done => Err(Error::InvalidState),
XMLHttpRequestState::Done => Err(Error::InvalidState(None)),
// Step 2
_ if self.send_flag.get() => Err(Error::InvalidState),
_ if self.send_flag.get() => Err(Error::InvalidState(None)),
// Step 3
_ => {
self.with_credentials.set(with_credentials);
@ -541,7 +541,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
fn Send(&self, data: Option<DocumentOrXMLHttpRequestBodyInit>, can_gc: CanGc) -> ErrorResult {
// Step 1, 2
if self.ready_state.get() != XMLHttpRequestState::Opened || self.send_flag.get() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
// Step 3
@ -873,7 +873,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
// DOMException.
match self.ready_state.get() {
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
},
_ => {},
}
@ -907,7 +907,9 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
}
match self.ready_state.get() {
// Step 2
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => Err(Error::InvalidState),
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => {
Err(Error::InvalidState(None))
},
_ => {
if self.sync_in_window() {
// Step 3
@ -969,7 +971,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
}))
},
// Step 1
_ => Err(Error::InvalidState),
_ => Err(Error::InvalidState(None)),
}
}
@ -986,7 +988,7 @@ impl XMLHttpRequestMethods<crate::DomTypeHolder> for XMLHttpRequest {
}
},
// Step 1
_ => Err(Error::InvalidState),
_ => Err(Error::InvalidState(None)),
}
}
}
@ -1672,7 +1674,7 @@ fn serialize_document(doc: &Document) -> Fallible<DOMString> {
let mut writer = vec![];
match serialize(&mut writer, &doc.upcast::<Node>(), SerializeOpts::default()) {
Ok(_) => Ok(DOMString::from(String::from_utf8(writer).unwrap())),
Err(_) => Err(Error::InvalidState),
Err(_) => Err(Error::InvalidState(None)),
}
}

View file

@ -214,7 +214,7 @@ impl XPathResultMethods<crate::DomTypeHolder> for XPathResult {
}
if self.document_changed_since_creation() {
return Err(Error::InvalidState);
return Err(Error::InvalidState(None));
}
let XPathResultValue::Nodeset(nodes) = &*self.value.borrow() else {

View file

@ -28,7 +28,7 @@ pub enum Error {
/// InUseAttributeError DOMException
InUseAttribute,
/// InvalidStateError DOMException
InvalidState,
InvalidState(Option<String>),
/// SyntaxError DOMException
Syntax(Option<String>),
/// NamespaceError DOMException