diff --git a/components/script/dom/webidls/XRWebGLBinding.webidl b/components/script/dom/webidls/XRWebGLBinding.webidl index 5823423ef86..f4ee859eeaf 100644 --- a/components/script/dom/webidls/XRWebGLBinding.webidl +++ b/components/script/dom/webidls/XRWebGLBinding.webidl @@ -5,7 +5,7 @@ // https://immersive-web.github.io/layers/#XRWebGLBindingtype [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"] interface XRWebGLBinding { - constructor(XRSession session, XRWebGLRenderingContext context); + [Throws] constructor(XRSession session, XRWebGLRenderingContext context); // readonly attribute double nativeProjectionScaleFactor; diff --git a/components/script/dom/xrwebglbinding.rs b/components/script/dom/xrwebglbinding.rs index 6e05543d2f9..145937c0227 100644 --- a/components/script/dom/xrwebglbinding.rs +++ b/components/script/dom/xrwebglbinding.rs @@ -7,6 +7,7 @@ use js::rust::HandleObject; use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye; use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::XRWebGLBinding_Binding::XRWebGLBindingMethods; +use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContext_Binding::WebGLRenderingContextMethods; use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::{ XRCubeLayerInit, XRCylinderLayerInit, XREquirectLayerInit, XRProjectionLayerInit, XRQuadLayerInit, XRTextureType, @@ -69,14 +70,33 @@ impl XRWebGLBindingMethods for XRWebGLBinding { can_gc: CanGc, session: &XRSession, context: WebGLRenderingContextOrWebGL2RenderingContext, - ) -> DomRoot { + ) -> Fallible> { let context = match context { WebGLRenderingContextOrWebGL2RenderingContext::WebGLRenderingContext(ctx) => ctx, WebGLRenderingContextOrWebGL2RenderingContext::WebGL2RenderingContext(ctx) => { ctx.base_context() }, }; - XRWebGLBinding::new(global, proto, session, &context, can_gc) + // Step 2 + if session.is_ended() { + return Err(Error::InvalidState); + } + + // step 3 + if context.IsContextLost() { + return Err(Error::InvalidState); + } + + // Step 4 + if !session.is_immersive() { + return Err(Error::InvalidState); + }; + + // Step 5 throw an InvalidStateError If context’s XR compatible boolean is false. + + Ok(XRWebGLBinding::new( + global, proto, session, &context, can_gc, + )) } /// diff --git a/tests/wpt/meta/webxr/layers/xrWebGLBinding_constructor.https.html.ini b/tests/wpt/meta/webxr/layers/xrWebGLBinding_constructor.https.html.ini index cff3ce1cfde..0214eddfee1 100644 --- a/tests/wpt/meta/webxr/layers/xrWebGLBinding_constructor.https.html.ini +++ b/tests/wpt/meta/webxr/layers/xrWebGLBinding_constructor.https.html.ini @@ -1,7 +1,7 @@ [xrWebGLBinding_constructor.https.html] + expected: ERROR [Ensure that XRWebGLBinding's constructor throws appropriate errors using webgl2] - expected: FAIL + expected: NOTRUN [Ensure that XRWebGLBinding's constructor throws appropriate errors using webgl] - expected: FAIL - + expected: TIMEOUT