Bug 1499045 part 1 - Simplify ArrayBufferViewObject::bufferEither a bit and remove ArrayBufferViewObject::bufferObject. r=jwalden
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 22 Oct 2018 14:46:07 +0000
changeset 490759 33dd2766eab8fd99cc3345b9984ee597e2306caa
parent 490758 42412209a3220de529f13d8ab51987e7a55c0213
child 490760 0e5ef9469604871660a21dc37e3a553125b5f533
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjwalden
bugs1499045
milestone64.0a1
Bug 1499045 part 1 - Simplify ArrayBufferViewObject::bufferEither a bit and remove ArrayBufferViewObject::bufferObject. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D8726
js/src/vm/ArrayBufferViewObject.h
js/src/vm/TypedArrayObject.cpp
js/src/vm/TypedArrayObject.h
--- a/js/src/vm/ArrayBufferViewObject.h
+++ b/js/src/vm/ArrayBufferViewObject.h
@@ -98,45 +98,42 @@ class ArrayBufferViewObject : public Nat
     }
 
     static Value bufferValue(const ArrayBufferViewObject* view) {
         return view->getFixedSlot(BUFFER_SLOT);
     }
     bool hasBuffer() const {
         return bufferValue(this).isObject();
     }
-    JSObject* bufferObject() const {
-        return bufferValue(this).toObjectOrNull();
-    }
 
     ArrayBufferObject* bufferUnshared() const {
         MOZ_ASSERT(!isSharedMemory());
-        JSObject* obj = bufferObject();
+        ArrayBufferObjectMaybeShared* obj = bufferEither();
         if (!obj) {
             return nullptr;
         }
         return &obj->as<ArrayBufferObject>();
     }
     SharedArrayBufferObject* bufferShared() const {
         MOZ_ASSERT(isSharedMemory());
-        JSObject* obj = bufferObject();
+        ArrayBufferObjectMaybeShared* obj = bufferEither();
         if (!obj) {
             return nullptr;
         }
         return &obj->as<SharedArrayBufferObject>();
     }
     ArrayBufferObjectMaybeShared* bufferEither() const {
-        JSObject* obj = bufferObject();
+        JSObject* obj = bufferValue(this).toObjectOrNull();
         if (!obj) {
             return nullptr;
         }
-        if (isSharedMemory()) {
-            return &obj->as<SharedArrayBufferObject>();
-        }
-        return &obj->as<ArrayBufferObject>();
+        MOZ_ASSERT(isSharedMemory()
+                   ? obj->is<SharedArrayBufferObject>()
+                   : obj->is<ArrayBufferObject>());
+        return &obj->as<ArrayBufferObjectMaybeShared>();
     }
 
     bool hasDetachedBuffer() const {
         // Shared buffers can't be detached.
         if (isSharedMemory()) {
             return false;
         }
 
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -1108,17 +1108,17 @@ GetBufferSpeciesConstructor(JSContext* c
         return nullptr;
     }
 
     // Use the current global's ArrayBuffer if the override is set.
     if (override == SpeciesConstructorOverride::ArrayBuffer) {
         return defaultCtor;
     }
 
-    RootedObject obj(cx, typedArray->bufferObject());
+    RootedObject obj(cx, typedArray->bufferEither());
     if (!obj) {
         MOZ_ASSERT(!isWrapped);
 
         // The buffer was never exposed to content code, so if
         // 1. %ArrayBufferPrototype%.constructor == %ArrayBuffer%, and
         // 2. %ArrayBuffer%[@@species] == ArrayBufferSpecies
         // we don't have to reify the buffer object and can simply return the
         // default arrray buffer constructor.
@@ -1141,17 +1141,17 @@ GetBufferSpeciesConstructor(JSContext* c
                 return defaultCtor;
             }
         }
 
         if (!TypedArrayObject::ensureHasBuffer(cx, typedArray)) {
             return nullptr;
         }
 
-        obj.set(typedArray->bufferObject());
+        obj.set(typedArray->bufferEither());
     } else {
         if (isWrapped && !cx->compartment()->wrap(cx, &obj)) {
             return nullptr;
         }
     }
 
     return SpeciesConstructor(cx, obj, defaultCtor, IsArrayBufferSpecies);
 }
--- a/js/src/vm/TypedArrayObject.h
+++ b/js/src/vm/TypedArrayObject.h
@@ -50,21 +50,20 @@ class TypedArrayObject : public ArrayBuf
     static bool sameBuffer(Handle<TypedArrayObject*> a, Handle<TypedArrayObject*> b) {
         // Inline buffers.
         if (!a->hasBuffer() || !b->hasBuffer()) {
             return a.get() == b.get();
         }
 
         // Shared buffers.
         if (a->isSharedMemory() && b->isSharedMemory()) {
-            return (a->bufferObject()->as<SharedArrayBufferObject>().globalID() ==
-                    b->bufferObject()->as<SharedArrayBufferObject>().globalID());
+            return a->bufferShared()->globalID() == b->bufferShared()->globalID();
         }
 
-        return a->bufferObject() == b->bufferObject();
+        return a->bufferEither() == b->bufferEither();
     }
 
     static const Class classes[Scalar::MaxTypedArrayViewType];
     static const Class protoClasses[Scalar::MaxTypedArrayViewType];
     static const Class sharedTypedArrayPrototypeClass;
 
     static const Class* classForType(Scalar::Type type) {
         MOZ_ASSERT(type < Scalar::MaxTypedArrayViewType);