Bug 1316829 - DataViews are part of ArrayBufferView. - r=waldo
authorJeff Gilbert (:jgilbert) <jgilbert@mozilla.com>
Fri, 11 Nov 2016 17:43:53 -0800
changeset 438657 e12e761d2106b1c5ea836462177617e147176ee5
parent 438656 71543633d754b08008cfd83b1399842786c4a4bf
child 438658 23f093950ea27057476dc2fe404dd23291ea5870
push id35794
push usersledru@mozilla.com
push dateMon, 14 Nov 2016 22:18:09 +0000
reviewerswaldo
bugs1316829
milestone52.0a1
Bug 1316829 - DataViews are part of ArrayBufferView. - r=waldo MozReview-Commit-ID: L0Xauoo2nJh
dom/canvas/WebGLContext.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -2508,28 +2508,37 @@ WebGLContext::StartVRPresentation()
             TextureFlags::ORIGIN_BOTTOM_LEFT);
 
     screen->Morph(Move(factory));
     return true;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
+static inline size_t
+SizeOfViewElem(const dom::ArrayBufferView& view)
+{
+    const auto& elemType = view.Type();
+    if (elemType == js::Scalar::MaxTypedArrayViewType) // DataViews.
+        return 1;
+
+    return js::Scalar::byteSize(elemType);
+}
+
 bool
 WebGLContext::ValidateArrayBufferView(const char* funcName,
                                       const dom::ArrayBufferView& view, GLuint elemOffset,
                                       GLuint elemCountOverride, uint8_t** const out_bytes,
                                       size_t* const out_byteLen)
 {
     view.ComputeLengthAndData();
     uint8_t* const bytes = view.DataAllowShared();
     const size_t byteLen = view.LengthAllowShared();
 
-    const auto& elemType = view.Type();
-    const auto& elemSize = js::Scalar::byteSize(elemType);
+    const auto& elemSize = SizeOfViewElem(view);
 
     size_t elemCount = byteLen / elemSize;
     if (elemOffset > elemCount) {
         ErrorInvalidValue("%s: Invalid offset into ArrayBufferView.", funcName);
         return false;
     }
     elemCount -= elemOffset;