Bug 1529298 - Add BufferContents::createFoo functions for every kind so that the templaty, harder-to-search-for create function can be removed. r=sfink
☠☠ backed out by eed1098d0d6c ☠ ☠
authorJeff Walden <jwalden@mit.edu>
Mon, 18 Feb 2019 22:52:42 -0800
changeset 460371 6cc3cd982953405eaa669248b103c5cc6b987d57
parent 460370 d80ce47bba5278fb6779bfa248d214c6da358ea8
child 460372 6f66e6c059df0b3a13307c83ffb98b821cd592a4
push id112082
push userjwalden@mit.edu
push dateFri, 22 Feb 2019 02:22:21 +0000
treeherdermozilla-inbound@d80b681a68e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1529298
milestone67.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 1529298 - Add BufferContents::createFoo functions for every kind so that the templaty, harder-to-search-for create function can be removed. r=sfink
js/src/vm/ArrayBufferObject.cpp
js/src/vm/ArrayBufferObject.h
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -974,17 +974,17 @@ bool js::CreateWasmBuffer(JSContext* cx,
   buffer->setIsPreparedForAsmJS();
   return true;
 }
 
 ArrayBufferObject::BufferContents ArrayBufferObject::createMappedContents(
     int fd, size_t offset, size_t length) {
   void* data =
       gc::AllocateMappedContent(fd, offset, length, ARRAY_BUFFER_ALIGNMENT);
-  return BufferContents::create<MAPPED>(data);
+  return BufferContents::createMapped(data);
 }
 
 uint8_t* ArrayBufferObject::inlineDataPointer() const {
   return static_cast<uint8_t*>(fixedData(JSCLASS_RESERVED_SLOTS(&class_)));
 }
 
 uint8_t* ArrayBufferObject::dataPointer() const {
   return static_cast<uint8_t*>(getFixedSlot(DATA_SLOT).toPrivate());
@@ -1141,17 +1141,17 @@ Maybe<uint32_t> js::WasmArrayBufferMaxSi
   }
 
   WasmArrayRawBuffer* newRawBuf =
       WasmArrayRawBuffer::Allocate(newSize, Nothing());
   if (!newRawBuf) {
     return false;
   }
   BufferContents contents =
-      BufferContents::create<WASM>(newRawBuf->dataPointer());
+      BufferContents::createWasm(newRawBuf->dataPointer());
   newBuf->initialize(newSize, contents, OwnsData);
 
   memcpy(newBuf->dataPointer(), oldBuf->dataPointer(), oldBuf->byteLength());
   ArrayBufferObject::detach(cx, oldBuf,
                             BufferContents::createMalloced(nullptr));
   return true;
 }
 
@@ -1328,34 +1328,34 @@ ArrayBufferObject* ArrayBufferObject::cr
   obj->setFlags(0);
   obj->setFirstView(nullptr);
   obj->setDataPointer(BufferContents::createMalloced(nullptr), DoesntOwnData);
 
   return obj;
 }
 
 ArrayBufferObject* ArrayBufferObject::createFromNewRawBuffer(
-    JSContext* cx, WasmArrayRawBuffer* buffer, uint32_t initialSize) {
+    JSContext* cx, WasmArrayRawBuffer* rawBuffer, uint32_t initialSize) {
   AutoSetNewObjectMetadata metadata(cx);
-  ArrayBufferObject* obj = NewBuiltinClassInstance<ArrayBufferObject>(cx);
-  if (!obj) {
-    WasmArrayRawBuffer::Release(buffer->dataPointer());
+  ArrayBufferObject* buffer = NewBuiltinClassInstance<ArrayBufferObject>(cx);
+  if (!buffer) {
+    WasmArrayRawBuffer::Release(rawBuffer->dataPointer());
     return nullptr;
   }
 
-  obj->setByteLength(initialSize);
-  obj->setFlags(0);
-  obj->setFirstView(nullptr);
+  buffer->setByteLength(initialSize);
+  buffer->setFlags(0);
+  buffer->setFirstView(nullptr);
 
-  auto contents = BufferContents::create<WASM>(buffer->dataPointer());
-  obj->setDataPointer(contents, OwnsData);
+  auto contents = BufferContents::createWasm(rawBuffer->dataPointer());
+  buffer->setDataPointer(contents, OwnsData);
 
   cx->updateMallocCounter(initialSize);
 
-  return obj;
+  return buffer;
 }
 
 /* static */ ArrayBufferObject::BufferContents ArrayBufferObject::stealContents(
     JSContext* cx, Handle<ArrayBufferObject*> buffer,
     bool hasStealableContents) {
   // While wasm buffers cannot generally be transferred by content, the
   // stealContents() is used internally by the impl of memory growth.
   MOZ_ASSERT_IF(hasStealableContents,
@@ -1810,18 +1810,17 @@ JS_PUBLIC_API JSObject* JS_NewMappedArra
                                                             void* data) {
   AssertHeapIsIdle();
   CHECK_THREAD(cx);
 
   MOZ_ASSERT(data);
 
   using BufferContents = ArrayBufferObject::BufferContents;
 
-  BufferContents contents =
-      BufferContents::create<ArrayBufferObject::MAPPED>(data);
+  BufferContents contents = BufferContents::createMapped(data);
   return ArrayBufferObject::createForContents(cx, nbytes, contents,
                                               ArrayBufferObject::OwnsData);
 }
 
 JS_PUBLIC_API void* JS_CreateMappedArrayBufferContents(int fd, size_t offset,
                                                        size_t length) {
   return ArrayBufferObject::createMappedContents(fd, offset, length).data();
 }
--- a/js/src/vm/ArrayBufferObject.h
+++ b/js/src/vm/ArrayBufferObject.h
@@ -255,33 +255,36 @@ class ArrayBufferObject : public ArrayBu
       MOZ_ASSERT((kind_ & ~KIND_MASK) == 0);
       MOZ_ASSERT_IF(free_ || freeUserData_, kind_ == EXTERNAL);
 
       // It is the caller's responsibility to ensure that the
       // BufferContents does not outlive the data.
     }
 
    public:
-    template <BufferKind Kind>
-    static BufferContents create(void* data) {
-      return BufferContents(static_cast<uint8_t*>(data), Kind);
-    }
-
     static BufferContents createInlineData(void* data) {
       return BufferContents(static_cast<uint8_t*>(data), INLINE_DATA);
     }
 
     static BufferContents createMalloced(void* data) {
       return BufferContents(static_cast<uint8_t*>(data), MALLOCED);
     }
 
     static BufferContents createUserOwned(void* data) {
       return BufferContents(static_cast<uint8_t*>(data), USER_OWNED);
     }
 
+    static BufferContents createWasm(void* data) {
+      return BufferContents(static_cast<uint8_t*>(data), WASM);
+    }
+
+    static BufferContents createMapped(void* data) {
+      return BufferContents(static_cast<uint8_t*>(data), MAPPED);
+    }
+
     static BufferContents createExternal(void* data,
                                          JS::BufferContentsFreeFunc freeFunc,
                                          void* freeUserData = nullptr) {
       return BufferContents(static_cast<uint8_t*>(data), EXTERNAL, freeFunc,
                             freeUserData);
     }
 
     static BufferContents createFailed() {