Bug 1363925: Part 2 - Support inferring array length from typed arrays. r?mccr8
MozReview-Commit-ID: FI5ggNE68v7
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -1346,20 +1346,25 @@ CallMethodHelper::GetArraySizeFromParam(
// it in the right slot so that we can find it again when cleaning up the params.
// from the array.
if (paramIndex >= mArgc && maybeArray.isObject()) {
MOZ_ASSERT(mMethodInfo->GetParam(paramIndex).IsOptional());
RootedObject arrayOrNull(mCallContext, maybeArray.isObject() ? &maybeArray.toObject()
: nullptr);
bool isArray;
- if (!JS_IsArrayObject(mCallContext, maybeArray, &isArray) ||
- !isArray ||
- !JS_GetArrayLength(mCallContext, arrayOrNull, &GetDispatchParam(paramIndex)->val.u32))
- {
+ bool ok = false;
+ if (JS_IsArrayObject(mCallContext, maybeArray, &isArray) && isArray) {
+ ok = JS_GetArrayLength(mCallContext, arrayOrNull, &GetDispatchParam(paramIndex)->val.u32);
+ } else if (JS_IsTypedArrayObject(&maybeArray.toObject())) {
+ GetDispatchParam(paramIndex)->val.u32 = JS_GetTypedArrayLength(&maybeArray.toObject());
+ ok = true;
+ }
+
+ if (!ok) {
return Throw(NS_ERROR_XPC_CANT_CONVERT_OBJECT_TO_ARRAY, mCallContext);
}
}
*result = GetDispatchParam(paramIndex)->val.u32;
return true;
}