Bug 1674777 part 11 - Change JS_GetTypedArrayLength return type from uint32_t to size_t. r=sfink
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 10 Feb 2021 11:23:00 +0000
changeset 566800 ce348dc698371692817127de918fe4e1e262dffb
parent 566799 03c71d1fa7f823e8bb23433503446d0fce37cff8
child 566801 a5b7b61ae1480501748963bb85ee2ddcab86df83
push id38190
push userbtara@mozilla.com
push dateWed, 10 Feb 2021 21:50:51 +0000
treeherdermozilla-central@569826c0fd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1674777
milestone87.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1674777 part 11 - Change JS_GetTypedArrayLength return type from uint32_t to size_t. r=sfink The callers in AudioWorkletNode.cpp are just comparing the length to the expected length to guard against detachment. Differential Revision: https://phabricator.services.mozilla.com/D103903
dom/media/webaudio/AudioWorkletNode.cpp
js/public/experimental/TypedData.h
js/src/jsapi-tests/testLargeArrayBuffers.cpp
js/src/vm/TypedArrayObject.cpp
--- a/dom/media/webaudio/AudioWorkletNode.cpp
+++ b/dom/media/webaudio/AudioWorkletNode.cpp
@@ -365,17 +365,17 @@ static bool PrepareBufferArrays(JSContex
                                 ArrayElementInit aInit) {
   MOZ_ASSERT(aBlocks.Length() == aPorts->mPorts.length());
   for (size_t i = 0; i < aBlocks.Length(); ++i) {
     size_t channelCount = aBlocks[i].ChannelCount();
     WorkletNodeEngine::Channels& portRef = aPorts->mPorts[i];
 
     auto& float32ArraysRef = portRef.mFloat32Arrays;
     for (auto& channelRef : float32ArraysRef) {
-      uint32_t length = JS_GetTypedArrayLength(channelRef);
+      size_t length = JS_GetTypedArrayLength(channelRef);
       if (length != WEBAUDIO_BLOCK_SIZE) {
         // Script has detached array buffers.  Create new objects.
         JSObject* array = JS_NewFloat32Array(aCx, WEBAUDIO_BLOCK_SIZE);
         if (NS_WARN_IF(!array)) {
           return false;
         }
         channelRef = array;
       } else if (aInit == ArrayElementInit::Zero) {
@@ -537,17 +537,17 @@ void WorkletNodeEngine::ProcessBlocksOnP
       AudioBlockCopyChannelWithScale(channelData[c], volume, dest);
     }
   }
 
   TrackTime tick = mDestination->GraphTimeToTrackTime(aFrom);
   // Compute and copy parameter values to JS objects.
   for (size_t i = 0; i < mParamTimelines.Length(); ++i) {
     const auto& float32Arrays = mParameters.mFloat32Arrays[i];
-    uint32_t length = JS_GetTypedArrayLength(float32Arrays);
+    size_t length = JS_GetTypedArrayLength(float32Arrays);
 
     // If the Float32Array that is supposed to hold the values for a particular
     // AudioParam has been detached, error out. This is being worked on in
     // https://github.com/WebAudio/web-audio-api/issues/1933 and
     // https://bugzilla.mozilla.org/show_bug.cgi?id=1619486
     if (length != WEBAUDIO_BLOCK_SIZE) {
       return;
     }
@@ -576,17 +576,17 @@ void WorkletNodeEngine::ProcessBlocksOnP
   }
 
   // Copy output values from JS objects.
   for (size_t o = 0; o < aOutput.Length(); ++o) {
     AudioBlock* output = &aOutput[o];
     size_t channelCount = output->ChannelCount();
     const auto& float32Arrays = mOutputs.mPorts[o].mFloat32Arrays;
     for (size_t c = 0; c < channelCount; ++c) {
-      uint32_t length = JS_GetTypedArrayLength(float32Arrays[c]);
+      size_t length = JS_GetTypedArrayLength(float32Arrays[c]);
       if (length != WEBAUDIO_BLOCK_SIZE) {
         // ArrayBuffer has been detached.  Behavior is unspecified.
         // https://github.com/WebAudio/web-audio-api/issues/1933 and
         // https://bugzilla.mozilla.org/show_bug.cgi?id=1619486
         return;
       }
       JS::AutoCheckCannotGC nogc;
       bool isShared;
--- a/js/public/experimental/TypedData.h
+++ b/js/public/experimental/TypedData.h
@@ -294,17 +294,17 @@ extern JS_FRIEND_API js::Scalar::Type JS
 
 /**
  * Return the number of elements in a typed array.
  *
  * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow
  * be known that it would pass such a test: it is a typed array or a wrapper of
  * a typed array, and the unwrapping will succeed.
  */
-extern JS_FRIEND_API uint32_t JS_GetTypedArrayLength(JSObject* obj);
+extern JS_FRIEND_API size_t JS_GetTypedArrayLength(JSObject* obj);
 
 /**
  * Return the byte offset from the start of an ArrayBuffer to the start of a
  * typed array view.
  *
  * |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow
  * be known that it would pass such a test: it is a typed array or a wrapper of
  * a typed array, and the unwrapping will succeed.
--- a/js/src/jsapi-tests/testLargeArrayBuffers.cpp
+++ b/js/src/jsapi-tests/testLargeArrayBuffers.cpp
@@ -47,16 +47,17 @@ BEGIN_TEST(testLargeArrayBuffers) {
   // New Uint8Array
   {
     RootedObject tarr(cx, JS_NewUint8Array(cx, nbytes));
     CHECK(JS_IsTypedArrayObject(tarr));
     CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(tarr), 0u);
     CHECK_EQUAL(JS_GetArrayBufferViewByteLength(tarr), nbytes);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(tarr), 0u);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(tarr), nbytes);
+    CHECK_EQUAL(JS_GetTypedArrayLength(tarr), nbytes);
 
     length = 0;
     js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data);
     CHECK_EQUAL(length, nbytes);
 
     length = 0;
     js::GetUint8ArrayLengthAndData(tarr, &length, &isShared, &data);
     CHECK_EQUAL(length, nbytes);
@@ -74,16 +75,17 @@ BEGIN_TEST(testLargeArrayBuffers) {
   {
     RootedObject tarr(cx,
                       JS_NewInt16ArrayWithBuffer(cx, buffer, 0, nbytes / 2));
     CHECK(JS_IsTypedArrayObject(tarr));
     CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(tarr), 0u);
     CHECK_EQUAL(JS_GetArrayBufferViewByteLength(tarr), nbytes);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(tarr), 0u);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(tarr), nbytes);
+    CHECK_EQUAL(JS_GetTypedArrayLength(tarr), nbytes / 2);
 
     length = 0;
     js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data);
     CHECK_EQUAL(length, nbytes);
 
     length = 0;
     int16_t* int16Data;
     js::GetInt16ArrayLengthAndData(tarr, &length, &isShared, &int16Data);
@@ -118,16 +120,17 @@ BEGIN_TEST(testLargeArrayBuffers) {
   {
     RootedObject tarr(cx,
                       JS_NewInt8ArrayWithBuffer(cx, buffer, nbytes - 200, 32));
     CHECK(JS_IsTypedArrayObject(tarr));
     CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(tarr), nbytes - 200);
     CHECK_EQUAL(JS_GetArrayBufferViewByteLength(tarr), 32u);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(tarr), nbytes - 200);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(tarr), 32u);
+    CHECK_EQUAL(JS_GetTypedArrayLength(tarr), 32u);
   }
 
   // DataView with large byteOffset.
   {
     RootedObject dv(cx, JS_NewDataView(cx, buffer, nbytes - 200, 32));
     CHECK(JS_IsArrayBufferViewObject(dv));
     CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(dv), nbytes - 200);
     CHECK_EQUAL(JS_GetArrayBufferViewByteLength(dv), 32u);
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -2699,22 +2699,22 @@ struct ExternalTypeOf<uint8_clamped> {
 
 JS_FOR_EACH_TYPED_ARRAY(IMPL_TYPED_ARRAY_JSAPI_CONSTRUCTORS)
 #undef IMPL_TYPED_ARRAY_JSAPI_CONSTRUCTORS
 
 JS_FRIEND_API bool JS_IsTypedArrayObject(JSObject* obj) {
   return obj->canUnwrapAs<TypedArrayObject>();
 }
 
-JS_FRIEND_API uint32_t JS_GetTypedArrayLength(JSObject* obj) {
+JS_FRIEND_API size_t JS_GetTypedArrayLength(JSObject* obj) {
   TypedArrayObject* tarr = obj->maybeUnwrapAs<TypedArrayObject>();
   if (!tarr) {
     return 0;
   }
-  return tarr->length().deprecatedGetUint32();
+  return tarr->length().get();
 }
 
 JS_FRIEND_API size_t JS_GetTypedArrayByteOffset(JSObject* obj) {
   TypedArrayObject* tarr = obj->maybeUnwrapAs<TypedArrayObject>();
   if (!tarr) {
     return 0;
   }
   return tarr->byteOffset().get();