Bug 1079844 - Rename JS_IsNeuteredArrayBufferObject to JS_IsDetachedArrayBufferObject. r=till
authorJeff Walden <jwalden@mit.edu>
Mon, 25 Jan 2016 14:01:13 -0800
changeset 281728 ec6b32b76f5f205054667718000ec144bda27dbb
parent 281727 293ec7dbc37f68d49140f2417ac100cc5a618234
child 281729 332b15daa544d423271116b671499f2bd94d5f9e
push id70898
push userjwalden@mit.edu
push dateTue, 26 Jan 2016 19:18:23 +0000
treeherdermozilla-inbound@82fa5db23a4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1079844
milestone47.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 1079844 - Rename JS_IsNeuteredArrayBufferObject to JS_IsDetachedArrayBufferObject. r=till
dom/workers/XMLHttpRequest.cpp
js/src/jsapi-tests/testArrayBuffer.cpp
js/src/jsapi-tests/testMappedArrayBuffer.cpp
js/src/jsfriendapi.h
js/src/vm/ArrayBufferObject.cpp
--- a/dom/workers/XMLHttpRequest.cpp
+++ b/dom/workers/XMLHttpRequest.cpp
@@ -1207,21 +1207,21 @@ EventRunnable::PreDispatch(JSContext* aC
       } else {
         bool doClone = true;
         JS::Rooted<JS::Value> transferable(aCx);
         JS::Rooted<JSObject*> obj(aCx, response.isObjectOrNull() ?
                                   response.toObjectOrNull() : nullptr);
         if (obj && JS_IsArrayBufferObject(obj)) {
           // Use cached response if the arraybuffer has been transfered.
           if (mProxy->mArrayBufferResponseWasTransferred) {
-            MOZ_ASSERT(JS_IsNeuteredArrayBufferObject(obj));
+            MOZ_ASSERT(JS_IsDetachedArrayBufferObject(obj));
             mUseCachedArrayBufferResponse = true;
             doClone = false;
           } else {
-            MOZ_ASSERT(!JS_IsNeuteredArrayBufferObject(obj));
+            MOZ_ASSERT(!JS_IsDetachedArrayBufferObject(obj));
             JS::AutoValueArray<1> argv(aCx);
             argv[0].set(response);
             obj = JS_NewArrayObject(aCx, argv);
             if (obj) {
               transferable.setObject(*obj);
               // Only cache the response when the readyState is DONE.
               if (xhr->ReadyState() == nsIXMLHttpRequest::DONE) {
                 mProxy->mArrayBufferResponseWasTransferred = true;
--- a/js/src/jsapi-tests/testArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testArrayBuffer.cpp
@@ -53,30 +53,17 @@ BEGIN_TEST(testArrayBuffer_bug720949_ste
         }
         CHECK(JS_GetElement(cx, view, 0, &v));
         CHECK(v.isInt32(MAGIC_VALUE_2));
 
         // Steal the contents
         void* contents = JS_StealArrayBufferContents(cx, obj);
         CHECK(contents != nullptr);
 
-        // Check that the original ArrayBuffer is neutered
-        CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), 0u);
-        CHECK(JS_GetProperty(cx, obj, "byteLength", &v));
-        CHECK(v.isInt32(0));
-        CHECK(JS_GetProperty(cx, view, "byteLength", &v));
-        CHECK(v.isInt32(0));
-        CHECK(JS_GetProperty(cx, view, "byteOffset", &v));
-        CHECK(v.isInt32(0));
-        CHECK(JS_GetProperty(cx, view, "length", &v));
-        CHECK(v.isInt32(0));
-        CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), 0u);
-        v.setUndefined();
-        JS_GetElement(cx, obj, 0, &v);
-        CHECK(v.isUndefined());
+        CHECK(JS_IsDetachedArrayBufferObject(obj));
 
         // Transfer to a new ArrayBuffer
         JS::RootedObject dst(cx, JS_NewArrayBufferWithContents(cx, size, contents));
         CHECK(JS_IsArrayBufferObject(dst));
         {
             JS::AutoCheckCannotGC nogc;
             bool sharedDummy;
             (void) JS_GetArrayBufferData(obj, &sharedDummy, nogc);
@@ -115,17 +102,17 @@ BEGIN_TEST(testArrayBuffer_bug720949_vie
     {
         buffer = JS_NewArrayBuffer(cx, 2000);
         JS::RootedObject view(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 0, -1));
         void* contents = JS_StealArrayBufferContents(cx, buffer);
         CHECK(contents != nullptr);
         JS_free(nullptr, contents);
         GC(cx);
         CHECK(isNeutered(view));
-        CHECK(isNeutered(buffer));
+        CHECK(JS_IsDetachedArrayBufferObject(buffer));
         view = nullptr;
         GC(cx);
         buffer = nullptr;
         GC(cx);
     }
 
     // Two views
     {
@@ -141,17 +128,17 @@ BEGIN_TEST(testArrayBuffer_bug720949_vie
 
         // Neuter
         void* contents = JS_StealArrayBufferContents(cx, buffer);
         CHECK(contents != nullptr);
         JS_free(nullptr, contents);
 
         CHECK(isNeutered(view1));
         CHECK(isNeutered(view2));
-        CHECK(isNeutered(buffer));
+        CHECK(JS_IsDetachedArrayBufferObject(buffer));
 
         view1 = nullptr;
         GC(cx);
         view2 = nullptr;
         GC(cx);
         buffer = nullptr;
         GC(cx);
     }
--- a/js/src/jsapi-tests/testMappedArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testMappedArrayBuffer.cpp
@@ -112,17 +112,17 @@ bool TestReleaseContents()
     return true;
 }
 
 bool TestDetachObject()
 {
     JS::RootedObject obj(cx, CreateNewObject(8, 12));
     CHECK(obj);
     JS_DetachArrayBuffer(cx, obj, ChangeData);
-    CHECK(isNeutered(obj));
+    CHECK(JS_IsDetachedArrayBufferObject(obj));
 
     return true;
 }
 
 bool TestCloneObject()
 {
     JS::RootedObject obj1(cx, CreateNewObject(8, 12));
     CHECK(obj1);
@@ -139,17 +139,17 @@ bool TestCloneObject()
 
 bool TestStealContents()
 {
     JS::RootedObject obj(cx, CreateNewObject(8, 12));
     CHECK(obj);
     void* contents = JS_StealArrayBufferContents(cx, obj);
     CHECK(contents);
     CHECK(memcmp(contents, test_data + 8, 12) == 0);
-    CHECK(isNeutered(obj));
+    CHECK(JS_IsDetachedArrayBufferObject(obj));
 
     return true;
 }
 
 bool TestTransferObject()
 {
     JS::RootedObject obj1(cx, CreateNewObject(8, 12));
     CHECK(obj1);
@@ -163,27 +163,21 @@ bool TestTransferObject()
     JS::RootedValue transferable(cx, JS::ObjectValue(*obj));
 
     JSAutoStructuredCloneBuffer cloned_buffer;
     CHECK(cloned_buffer.write(cx, v1, transferable, nullptr, nullptr));
     JS::RootedValue v2(cx);
     CHECK(cloned_buffer.read(cx, &v2, nullptr, nullptr));
     JS::RootedObject obj2(cx, v2.toObjectOrNull());
     CHECK(VerifyObject(obj2, 8, 12, true));
-    CHECK(isNeutered(obj1));
+    CHECK(JS_IsDetachedArrayBufferObject(obj1));
 
     return true;
 }
 
-bool isNeutered(JS::HandleObject obj)
-{
-    JS::RootedValue v(cx);
-    return JS_GetProperty(cx, obj, "byteLength", &v) && v.toInt32() == 0;
-}
-
 static void GC(JSContext* cx)
 {
     JS_GC(JS_GetRuntime(cx));
     // Trigger another to wait for background finalization to end.
     JS_GC(JS_GetRuntime(cx));
 }
 
 END_TEST(testMappedArrayBuffer_bug945152)
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -1894,17 +1894,17 @@ JS_IsSharedArrayBufferObject(JSObject* o
 extern JS_FRIEND_API(uint32_t)
 JS_GetArrayBufferByteLength(JSObject* obj);
 
 extern JS_FRIEND_API(uint32_t)
 JS_GetSharedArrayBufferByteLength(JSObject* obj);
 
 /**
  * Return true if the arrayBuffer contains any data. This will return false for
- * ArrayBuffer.prototype and neutered ArrayBuffers.
+ * ArrayBuffer.prototype and detached ArrayBuffers.
  *
  * |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known
  * that it would pass such a test: it is an ArrayBuffer or a wrapper of an
  * ArrayBuffer, and the unwrapping will succeed.
  */
 extern JS_FRIEND_API(bool)
 JS_ArrayBufferHasData(JSObject* obj);
 
@@ -2015,19 +2015,18 @@ JS_GetFloat64ArrayData(JSObject* obj, bo
 /**
  * Same as above, but for any kind of ArrayBufferView. Prefer the type-specific
  * versions when possible.
  */
 extern JS_FRIEND_API(void*)
 JS_GetArrayBufferViewData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
 
 /**
- * Return the ArrayBuffer or SharedArrayBuffer underlying an
- * ArrayBufferView. If the buffer has been neutered, this will still
- * return the neutered buffer. |obj| must be an object that would
+ * Return the ArrayBuffer or SharedArrayBuffer underlying an ArrayBufferView.
+ * This may return a detached buffer.  |obj| must be an object that would
  * return true for JS_IsArrayBufferViewObject().
  */
 extern JS_FRIEND_API(JSObject*)
 JS_GetArrayBufferViewBuffer(JSContext* cx, JS::HandleObject obj, bool* isSharedMemory);
 
 enum DetachDataDisposition {
     ChangeData,
     KeepData
@@ -2044,22 +2043,22 @@ enum DetachDataDisposition {
  * while the ArrayBuffer appears observably detached.  There is no guarantee
  * this parameter is respected -- it's only a hint.
  */
 extern JS_FRIEND_API(bool)
 JS_DetachArrayBuffer(JSContext* cx, JS::HandleObject obj,
                      DetachDataDisposition changeData);
 
 /**
- * Check whether the obj is ArrayBufferObject and neutered. Note that this
- * may return false if a security wrapper is encountered that denies the
+ * Check whether the obj is a detached ArrayBufferObject. Note that this may
+ * return false if a security wrapper is encountered that denies the
  * unwrapping.
  */
 extern JS_FRIEND_API(bool)
-JS_IsNeuteredArrayBufferObject(JSObject* obj);
+JS_IsDetachedArrayBufferObject(JSObject* obj);
 
 /**
  * Check whether obj supports JS_GetDataView* APIs.
  */
 JS_FRIEND_API(bool)
 JS_IsDataViewObject(JSObject* obj);
 
 /**
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -1150,17 +1150,17 @@ JS_DetachArrayBuffer(JSContext* cx, Hand
         if (!ArrayBufferObject::neuter(cx, buffer, buffer->contents()))
             return false;
     }
 
     return true;
 }
 
 JS_FRIEND_API(bool)
-JS_IsNeuteredArrayBufferObject(JSObject* obj)
+JS_IsDetachedArrayBufferObject(JSObject* obj)
 {
     obj = CheckedUnwrap(obj);
     if (!obj)
         return false;
 
     return obj->is<ArrayBufferObject>() && obj->as<ArrayBufferObject>().isNeutered();
 }