Bug 1363925: Part 2 - Support inferring array length from typed arrays. r?mccr8 draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 21 Apr 2018 18:04:22 -0700
changeset 786312 df5a929d58916e01ad9bcbdf08a668d05f3c5ccf
parent 786311 645b96164cd69ecbc9c52fa8d599bb652bdc4df2
child 786313 c9e05c9374aac0226f03f3dc170e5e16ad6c4831
push id107433
push usermaglione.k@gmail.com
push dateSun, 22 Apr 2018 22:24:27 +0000
reviewersmccr8
bugs1363925
milestone61.0a1
Bug 1363925: Part 2 - Support inferring array length from typed arrays. r?mccr8 MozReview-Commit-ID: FI5ggNE68v7
js/xpconnect/src/XPCWrappedNative.cpp
--- 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;
 }