Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 675a8f6

Browse files
Bug 1640839 - Make XRSessionInit.requiredFeatures/optionalFeatures of type sequence<DOMString>. r=mccr8
This was changed in the spec here: immersive-web/webxr#1296 Differential Revision: https://phabricator.services.mozilla.com/D201336
1 parent c9851aa commit 675a8f6

File tree

3 files changed

+20
-42
lines changed

3 files changed

+20
-42
lines changed

dom/vr/XRSystem.cpp

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ already_AddRefed<Promise> XRSystem::IsSessionSupported(XRSessionMode aMode,
122122
}
123123

124124
already_AddRefed<Promise> XRSystem::RequestSession(
125-
JSContext* aCx, XRSessionMode aMode, const XRSessionInit& aOptions,
126-
CallerType aCallerType, ErrorResult& aRv) {
125+
XRSessionMode aMode, const XRSessionInit& aOptions, CallerType aCallerType,
126+
ErrorResult& aRv) {
127127
nsCOMPtr<nsIGlobalObject> global = GetParentObject();
128128
NS_ENSURE_TRUE(global, nullptr);
129129

@@ -166,49 +166,27 @@ already_AddRefed<Promise> XRSystem::RequestSession(
166166
requiredReferenceSpaceTypes.AppendElement(XRReferenceSpaceType::Local);
167167
}
168168

169-
BindingCallContext callCx(aCx, "XRSystem.requestSession");
170-
171169
if (aOptions.mRequiredFeatures.WasPassed()) {
172-
const Sequence<JS::Value>& arr = (aOptions.mRequiredFeatures.Value());
173-
for (const JS::Value& val : arr) {
174-
if (!val.isNull() && !val.isUndefined()) {
175-
bool bFound = false;
176-
JS::Rooted<JS::Value> v(aCx, val);
177-
int index = 0;
178-
if (FindEnumStringIndex<false>(
179-
callCx, v, XRReferenceSpaceTypeValues::strings,
180-
"XRReferenceSpaceType", "Argument 2 of XR.requestSession",
181-
&index)) {
182-
if (index >= 0) {
183-
requiredReferenceSpaceTypes.AppendElement(
184-
static_cast<XRReferenceSpaceType>(index));
185-
bFound = true;
186-
}
187-
}
188-
if (!bFound) {
189-
promise->MaybeRejectWithNotSupportedError(
190-
"A required feature for the XRSession is not available.");
191-
return promise.forget();
192-
}
170+
for (const nsString& val : aOptions.mRequiredFeatures.Value()) {
171+
int index = FindEnumStringIndexImpl(val.BeginReading(), val.Length(),
172+
XRReferenceSpaceTypeValues::strings);
173+
if (index < 0) {
174+
promise->MaybeRejectWithNotSupportedError(
175+
"A required feature for the XRSession is not available.");
176+
return promise.forget();
193177
}
178+
requiredReferenceSpaceTypes.AppendElement(
179+
static_cast<XRReferenceSpaceType>(index));
194180
}
195181
}
196182

197183
if (aOptions.mOptionalFeatures.WasPassed()) {
198-
const Sequence<JS::Value>& arr = (aOptions.mOptionalFeatures.Value());
199-
for (const JS::Value& val : arr) {
200-
if (!val.isNull() && !val.isUndefined()) {
201-
JS::Rooted<JS::Value> v(aCx, val);
202-
int index = 0;
203-
if (FindEnumStringIndex<false>(
204-
callCx, v, XRReferenceSpaceTypeValues::strings,
205-
"XRReferenceSpaceType", "Argument 2 of XR.requestSession",
206-
&index)) {
207-
if (index >= 0) {
208-
optionalReferenceSpaceTypes.AppendElement(
209-
static_cast<XRReferenceSpaceType>(index));
210-
}
211-
}
184+
for (const nsString& val : aOptions.mOptionalFeatures.Value()) {
185+
int index = FindEnumStringIndexImpl(val.BeginReading(), val.Length(),
186+
XRReferenceSpaceTypeValues::strings);
187+
if (index >= 0) {
188+
optionalReferenceSpaceTypes.AppendElement(
189+
static_cast<XRReferenceSpaceType>(index));
212190
}
213191
}
214192
}

dom/vr/XRSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class XRSystem final : public DOMEventTargetHelper,
120120
// WebIDL Members
121121
already_AddRefed<Promise> IsSessionSupported(XRSessionMode aMode,
122122
ErrorResult& aRv);
123-
already_AddRefed<Promise> RequestSession(JSContext* aCx, XRSessionMode aMode,
123+
already_AddRefed<Promise> RequestSession(XRSessionMode aMode,
124124
const XRSessionInit& aOptions,
125125
CallerType aCallerType,
126126
ErrorResult& aRv);

dom/webidl/WebXR.webidl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ enum XRSessionMode {
2727
};
2828

2929
dictionary XRSessionInit {
30-
sequence<any> requiredFeatures;
31-
sequence<any> optionalFeatures;
30+
sequence<DOMString> requiredFeatures;
31+
sequence<DOMString> optionalFeatures;
3232
};
3333

3434
enum XRVisibilityState {

0 commit comments

Comments
 (0)