Bug 1079844 - Convert the JS_NeuterArrayBufferObject API to detachment terminology. r=till
authorJeff Walden <jwalden@mit.edu>
Mon, 25 Jan 2016 14:01:13 -0800
changeset 281727 293ec7dbc37f68d49140f2417ac100cc5a618234
parent 281726 5bab1e2c84914dba29497f5c97bf76665e34a3e4
child 281728 ec6b32b76f5f205054667718000ec144bda27dbb
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 - Convert the JS_NeuterArrayBufferObject API to detachment terminology. r=till
js/src/builtin/TestingFunctions.cpp
js/src/jsapi-tests/testMappedArrayBuffer.cpp
js/src/jsapi.h
js/src/jsfriendapi.h
js/src/vm/ArrayBufferObject.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -2063,33 +2063,34 @@ Neuter(JSContext* cx, unsigned argc, Val
     if (!JS_ValueToObject(cx, args[0], &obj))
         return false;
 
     if (!obj) {
         JS_ReportError(cx, "neuter must be passed an object");
         return false;
     }
 
-    NeuterDataDisposition changeData;
     RootedString str(cx, JS::ToString(cx, args[1]));
     if (!str)
         return false;
     JSAutoByteString dataDisposition(cx, str);
     if (!dataDisposition)
         return false;
+
+    DetachDataDisposition changeData;
     if (strcmp(dataDisposition.ptr(), "same-data") == 0) {
         changeData = KeepData;
     } else if (strcmp(dataDisposition.ptr(), "change-data") == 0) {
         changeData = ChangeData;
     } else {
         JS_ReportError(cx, "unknown parameter 2 to neuter()");
         return false;
     }
 
-    if (!JS_NeuterArrayBuffer(cx, obj, changeData))
+    if (!JS_DetachArrayBuffer(cx, obj, changeData))
         return false;
 
     args.rval().setUndefined();
     return true;
 }
 
 static bool
 HelperThreadCount(JSContext* cx, unsigned argc, Value* vp)
--- a/js/src/jsapi-tests/testMappedArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testMappedArrayBuffer.cpp
@@ -35,18 +35,18 @@ BEGIN_TEST(testMappedArrayBuffer_bug9451
     CHECK(CreateNewObject(11, 12) == nullptr);
 
     // Offset + length greater than file size.
     CHECK(CreateNewObject(8, sizeof(test_data) - 7) == nullptr);
 
     // Release the mapped content.
     CHECK(TestReleaseContents());
 
-    // Neuter mapped array buffer.
-    CHECK(TestNeuterObject());
+    // Detach mapped array buffer.
+    CHECK(TestDetachObject());
 
     // Clone mapped array buffer.
     CHECK(TestCloneObject());
 
     // Steal mapped array buffer contents.
     CHECK(TestStealContents());
 
     // Transfer mapped array buffer contents.
@@ -107,21 +107,21 @@ bool TestReleaseContents()
     close(fd);
     if (!ptr)
         return false;
     JS_ReleaseMappedArrayBufferContents(ptr, 12);
 
     return true;
 }
 
-bool TestNeuterObject()
+bool TestDetachObject()
 {
     JS::RootedObject obj(cx, CreateNewObject(8, 12));
     CHECK(obj);
-    JS_NeuterArrayBuffer(cx, obj, ChangeData);
+    JS_DetachArrayBuffer(cx, obj, ChangeData);
     CHECK(isNeutered(obj));
 
     return true;
 }
 
 bool TestCloneObject()
 {
     JS::RootedObject obj1(cx, CreateNewObject(8, 12));
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3451,17 +3451,17 @@ JS_NewMappedArrayBufferWithContents(JSCo
  */
 extern JS_PUBLIC_API(void*)
 JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length);
 
 /**
  * Release the allocated resource of mapped array buffer contents before the
  * object is created.
  * If a new object has been created by JS_NewMappedArrayBufferWithContents()
- * with this content, then JS_NeuterArrayBuffer() should be used instead to
+ * with this content, then JS_DetachArrayBuffer() should be used instead to
  * release the resource used by the object.
  */
 extern JS_PUBLIC_API(void)
 JS_ReleaseMappedArrayBufferContents(void* contents, size_t length);
 
 extern JS_PUBLIC_API(JS::Value)
 JS_GetReservedSlot(JSObject* obj, uint32_t index);
 
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -2023,33 +2023,35 @@ JS_GetArrayBufferViewData(JSObject* obj,
  * 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 true for JS_IsArrayBufferViewObject().
  */
 extern JS_FRIEND_API(JSObject*)
 JS_GetArrayBufferViewBuffer(JSContext* cx, JS::HandleObject obj, bool* isSharedMemory);
 
-typedef enum {
+enum DetachDataDisposition {
     ChangeData,
     KeepData
-} NeuterDataDisposition;
+};
 
 /**
- * Set an ArrayBuffer's length to 0 and neuter all of its views.
+ * Detach an ArrayBuffer, causing all associated views to no longer refer to
+ * the ArrayBuffer's original attached memory.
  *
  * The |changeData| argument is a hint to inform internal behavior with respect
- * to the internal pointer to the ArrayBuffer's data after being neutered.
- * There is no guarantee it will be respected.  But if it is respected, the
- * ArrayBuffer's internal data pointer will, or will not, have changed
- * accordingly.
+ * to the ArrayBuffer's internal pointer to associated data.  |ChangeData|
+ * attempts to set the internal pointer to fresh memory of the same size as the
+ * original memory; |KeepData| attempts to preserve the original pointer, even
+ * 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_NeuterArrayBuffer(JSContext* cx, JS::HandleObject obj,
-                     NeuterDataDisposition changeData);
+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
  * unwrapping.
  */
 extern JS_FRIEND_API(bool)
 JS_IsNeuteredArrayBufferObject(JSObject* obj);
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -1122,18 +1122,18 @@ JS_GetArrayBufferData(JSObject* obj, boo
         return nullptr;
     if (!IsArrayBuffer(obj))
         return nullptr;
     *isSharedMemory = false;
     return AsArrayBuffer(obj).dataPointer();
 }
 
 JS_FRIEND_API(bool)
-JS_NeuterArrayBuffer(JSContext* cx, HandleObject obj,
-                     NeuterDataDisposition changeData)
+JS_DetachArrayBuffer(JSContext* cx, HandleObject obj,
+                     DetachDataDisposition changeData)
 {
     if (!obj->is<ArrayBufferObject>()) {
         JS_ReportError(cx, "ArrayBuffer object required");
         return false;
     }
 
     Rooted<ArrayBufferObject*> buffer(cx, &obj->as<ArrayBufferObject>());