Bug 1640839 - Make XRSessionInit.requiredFeatures/optionalFeatures of type sequence<DOMString>. r=mccr8

This was changed in the spec here: https://github.com/immersive-web/webxr/pull/1296

Differential Revision: https://phabricator.services.mozilla.com/D201336
This commit is contained in:
Peter Van der Beken 2024-03-02 07:50:21 +00:00
Родитель c9851aa621
Коммит 675a8f65a9
3 изменённых файлов: 20 добавлений и 42 удалений

Просмотреть файл

@ -122,8 +122,8 @@ already_AddRefed<Promise> XRSystem::IsSessionSupported(XRSessionMode aMode,
}
already_AddRefed<Promise> XRSystem::RequestSession(
JSContext* aCx, XRSessionMode aMode, const XRSessionInit& aOptions,
CallerType aCallerType, ErrorResult& aRv) {
XRSessionMode aMode, const XRSessionInit& aOptions, CallerType aCallerType,
ErrorResult& aRv) {
nsCOMPtr<nsIGlobalObject> global = GetParentObject();
NS_ENSURE_TRUE(global, nullptr);
@ -166,49 +166,27 @@ already_AddRefed<Promise> XRSystem::RequestSession(
requiredReferenceSpaceTypes.AppendElement(XRReferenceSpaceType::Local);
}
BindingCallContext callCx(aCx, "XRSystem.requestSession");
if (aOptions.mRequiredFeatures.WasPassed()) {
const Sequence<JS::Value>& arr = (aOptions.mRequiredFeatures.Value());
for (const JS::Value& val : arr) {
if (!val.isNull() && !val.isUndefined()) {
bool bFound = false;
JS::Rooted<JS::Value> v(aCx, val);
int index = 0;
if (FindEnumStringIndex<false>(
callCx, v, XRReferenceSpaceTypeValues::strings,
"XRReferenceSpaceType", "Argument 2 of XR.requestSession",
&index)) {
if (index >= 0) {
requiredReferenceSpaceTypes.AppendElement(
static_cast<XRReferenceSpaceType>(index));
bFound = true;
}
}
if (!bFound) {
promise->MaybeRejectWithNotSupportedError(
"A required feature for the XRSession is not available.");
return promise.forget();
}
for (const nsString& val : aOptions.mRequiredFeatures.Value()) {
int index = FindEnumStringIndexImpl(val.BeginReading(), val.Length(),
XRReferenceSpaceTypeValues::strings);
if (index < 0) {
promise->MaybeRejectWithNotSupportedError(
"A required feature for the XRSession is not available.");
return promise.forget();
}
requiredReferenceSpaceTypes.AppendElement(
static_cast<XRReferenceSpaceType>(index));
}
}
if (aOptions.mOptionalFeatures.WasPassed()) {
const Sequence<JS::Value>& arr = (aOptions.mOptionalFeatures.Value());
for (const JS::Value& val : arr) {
if (!val.isNull() && !val.isUndefined()) {
JS::Rooted<JS::Value> v(aCx, val);
int index = 0;
if (FindEnumStringIndex<false>(
callCx, v, XRReferenceSpaceTypeValues::strings,
"XRReferenceSpaceType", "Argument 2 of XR.requestSession",
&index)) {
if (index >= 0) {
optionalReferenceSpaceTypes.AppendElement(
static_cast<XRReferenceSpaceType>(index));
}
}
for (const nsString& val : aOptions.mOptionalFeatures.Value()) {
int index = FindEnumStringIndexImpl(val.BeginReading(), val.Length(),
XRReferenceSpaceTypeValues::strings);
if (index >= 0) {
optionalReferenceSpaceTypes.AppendElement(
static_cast<XRReferenceSpaceType>(index));
}
}
}

Просмотреть файл

@ -120,7 +120,7 @@ class XRSystem final : public DOMEventTargetHelper,
// WebIDL Members
already_AddRefed<Promise> IsSessionSupported(XRSessionMode aMode,
ErrorResult& aRv);
already_AddRefed<Promise> RequestSession(JSContext* aCx, XRSessionMode aMode,
already_AddRefed<Promise> RequestSession(XRSessionMode aMode,
const XRSessionInit& aOptions,
CallerType aCallerType,
ErrorResult& aRv);

Просмотреть файл

@ -27,8 +27,8 @@ enum XRSessionMode {
};
dictionary XRSessionInit {
sequence<any> requiredFeatures;
sequence<any> optionalFeatures;
sequence<DOMString> requiredFeatures;
sequence<DOMString> optionalFeatures;
};
enum XRVisibilityState {