[JSC] Drop PassRefPtr from ArrayBuffer
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 06:04:16 +0000 (06:04 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 06:04:16 +0000 (06:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168455

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

This patch finally drops all the PassRefPtr in JSC.
We changed PassRefPtr<ArrayBuffer> to RefPtr<ArrayBuffer>&&.
Since ArrayBuffer may be nullptr if the array is neutered,
we hold it as RefPtr<> instead of Ref<>.

And we also drops 2 files, TypedArrayBase.h and IntegralTypedArrayBase.h.
They are not used (and they are not referenced from the project file).

* inspector/JavaScriptCallFrame.h:
* jsc.cpp:
(functionDollarAgentReceiveBroadcast):
* runtime/ArrayBufferView.cpp:
(JSC::ArrayBufferView::ArrayBufferView):
* runtime/ArrayBufferView.h:
(JSC::ArrayBufferView::possiblySharedBuffer):
(JSC::ArrayBufferView::unsharedBuffer):
(JSC::ArrayBufferView::verifySubRangeLength):
(JSC::ArrayBufferView::clampOffsetAndNumElements):
* runtime/ClassInfo.h:
* runtime/DataView.cpp:
(JSC::DataView::DataView):
(JSC::DataView::create):
* runtime/DataView.h:
* runtime/GenericTypedArrayView.h:
* runtime/GenericTypedArrayViewInlines.h:
(JSC::GenericTypedArrayView<Adaptor>::GenericTypedArrayView):
(JSC::GenericTypedArrayView<Adaptor>::create):
(JSC::GenericTypedArrayView<Adaptor>::subarray):
* runtime/IntegralTypedArrayBase.h: Removed.
* runtime/JSArrayBuffer.cpp:
(JSC::JSArrayBuffer::JSArrayBuffer):
(JSC::JSArrayBuffer::create):
* runtime/JSArrayBuffer.h:
* runtime/JSArrayBufferPrototype.cpp:
(JSC::arrayBufferProtoFuncSlice):
* runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::ConstructionContext::ConstructionContext):
* runtime/JSArrayBufferView.h:
* runtime/JSArrayBufferViewInlines.h:
(JSC::JSArrayBufferView::possiblySharedImpl):
(JSC::JSArrayBufferView::unsharedImpl):
* runtime/JSCell.cpp:
(JSC::JSCell::slowDownAndWasteMemory):
(JSC::JSCell::getTypedArrayImpl):
* runtime/JSCell.h:
* runtime/JSDataView.cpp:
(JSC::JSDataView::create):
(JSC::JSDataView::possiblySharedTypedImpl):
(JSC::JSDataView::unsharedTypedImpl):
(JSC::JSDataView::getTypedArrayImpl):
* runtime/JSDataView.h:
* runtime/JSGenericTypedArrayView.h:
* runtime/JSGenericTypedArrayViewConstructorInlines.h:
(JSC::constructGenericTypedArrayViewWithArguments):
* runtime/JSGenericTypedArrayViewInlines.h:
(JSC::JSGenericTypedArrayView<Adaptor>::create):
(JSC::JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl):
(JSC::JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl):
(JSC::JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl):
* runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
(JSC::genericTypedArrayViewPrivateFuncSubarrayCreate):
* runtime/JSTypedArrays.cpp:
(JSC::createUint8TypedArray):
* runtime/TypedArrayBase.h: Removed.

Source/WebCore:

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readArrayBufferView):
* css/FontFace.cpp:
(WebCore::FontFace::create):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitData):
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::AVFWrapper::shouldWaitForLoadingOfResource):
* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
(WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212535 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JavaScriptCallFrame.h
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/ArrayBufferView.cpp
Source/JavaScriptCore/runtime/ArrayBufferView.h
Source/JavaScriptCore/runtime/ClassInfo.h
Source/JavaScriptCore/runtime/DataView.cpp
Source/JavaScriptCore/runtime/DataView.h
Source/JavaScriptCore/runtime/GenericTypedArrayView.h
Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/IntegralTypedArrayBase.h [deleted file]
Source/JavaScriptCore/runtime/JSArrayBuffer.cpp
Source/JavaScriptCore/runtime/JSArrayBuffer.h
Source/JavaScriptCore/runtime/JSArrayBufferPrototype.cpp
Source/JavaScriptCore/runtime/JSArrayBufferView.cpp
Source/JavaScriptCore/runtime/JSArrayBufferView.h
Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h
Source/JavaScriptCore/runtime/JSCell.cpp
Source/JavaScriptCore/runtime/JSCell.h
Source/JavaScriptCore/runtime/JSDataView.cpp
Source/JavaScriptCore/runtime/JSDataView.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructorInlines.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h
Source/JavaScriptCore/runtime/JSTypedArrays.cpp
Source/JavaScriptCore/runtime/TypedArrayBase.h [deleted file]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/css/FontFace.cpp
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp
Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

index 81abeba..1aa7345 100644 (file)
@@ -1,3 +1,75 @@
+2017-02-16  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Drop PassRefPtr from ArrayBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=168455
+
+        Reviewed by Geoffrey Garen.
+
+        This patch finally drops all the PassRefPtr in JSC.
+        We changed PassRefPtr<ArrayBuffer> to RefPtr<ArrayBuffer>&&.
+        Since ArrayBuffer may be nullptr if the array is neutered,
+        we hold it as RefPtr<> instead of Ref<>.
+
+        And we also drops 2 files, TypedArrayBase.h and IntegralTypedArrayBase.h.
+        They are not used (and they are not referenced from the project file).
+
+        * inspector/JavaScriptCallFrame.h:
+        * jsc.cpp:
+        (functionDollarAgentReceiveBroadcast):
+        * runtime/ArrayBufferView.cpp:
+        (JSC::ArrayBufferView::ArrayBufferView):
+        * runtime/ArrayBufferView.h:
+        (JSC::ArrayBufferView::possiblySharedBuffer):
+        (JSC::ArrayBufferView::unsharedBuffer):
+        (JSC::ArrayBufferView::verifySubRangeLength):
+        (JSC::ArrayBufferView::clampOffsetAndNumElements):
+        * runtime/ClassInfo.h:
+        * runtime/DataView.cpp:
+        (JSC::DataView::DataView):
+        (JSC::DataView::create):
+        * runtime/DataView.h:
+        * runtime/GenericTypedArrayView.h:
+        * runtime/GenericTypedArrayViewInlines.h:
+        (JSC::GenericTypedArrayView<Adaptor>::GenericTypedArrayView):
+        (JSC::GenericTypedArrayView<Adaptor>::create):
+        (JSC::GenericTypedArrayView<Adaptor>::subarray):
+        * runtime/IntegralTypedArrayBase.h: Removed.
+        * runtime/JSArrayBuffer.cpp:
+        (JSC::JSArrayBuffer::JSArrayBuffer):
+        (JSC::JSArrayBuffer::create):
+        * runtime/JSArrayBuffer.h:
+        * runtime/JSArrayBufferPrototype.cpp:
+        (JSC::arrayBufferProtoFuncSlice):
+        * runtime/JSArrayBufferView.cpp:
+        (JSC::JSArrayBufferView::ConstructionContext::ConstructionContext):
+        * runtime/JSArrayBufferView.h:
+        * runtime/JSArrayBufferViewInlines.h:
+        (JSC::JSArrayBufferView::possiblySharedImpl):
+        (JSC::JSArrayBufferView::unsharedImpl):
+        * runtime/JSCell.cpp:
+        (JSC::JSCell::slowDownAndWasteMemory):
+        (JSC::JSCell::getTypedArrayImpl):
+        * runtime/JSCell.h:
+        * runtime/JSDataView.cpp:
+        (JSC::JSDataView::create):
+        (JSC::JSDataView::possiblySharedTypedImpl):
+        (JSC::JSDataView::unsharedTypedImpl):
+        (JSC::JSDataView::getTypedArrayImpl):
+        * runtime/JSDataView.h:
+        * runtime/JSGenericTypedArrayView.h:
+        * runtime/JSGenericTypedArrayViewConstructorInlines.h:
+        (JSC::constructGenericTypedArrayViewWithArguments):
+        * runtime/JSGenericTypedArrayViewInlines.h:
+        (JSC::JSGenericTypedArrayView<Adaptor>::create):
+        (JSC::JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl):
+        (JSC::JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl):
+        (JSC::JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl):
+        * runtime/JSGenericTypedArrayViewPrototypeFunctions.h:
+        (JSC::genericTypedArrayViewPrivateFuncSubarrayCreate):
+        * runtime/JSTypedArrays.cpp:
+        (JSC::createUint8TypedArray):
+        * runtime/TypedArrayBase.h: Removed.
+
 2017-02-16  Keith Miller  <keith_miller@apple.com>
 
         ASSERTION FAILED: vm.heap.mutatorState() == MutatorState::Running || vm.apiLock().ownerThread() != std::this_thread::get_id()
index 6af492e..ee1f8ae 100644 (file)
@@ -29,7 +29,6 @@
 #include "debugger/DebuggerCallFrame.h"
 #include "interpreter/CallFrame.h"
 #include <wtf/Forward.h>
-#include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/TextPosition.h>
 
index 4a60261..057ba41 100644 (file)
@@ -2553,7 +2553,8 @@ EncodedJSValue JSC_HOST_CALL functionDollarAgentReceiveBroadcast(ExecState* exec
     }
     
     RefPtr<ArrayBuffer> nativeBuffer = ArrayBuffer::create(message->releaseContents());
-    JSArrayBuffer* jsBuffer = JSArrayBuffer::create(vm, exec->lexicalGlobalObject()->arrayBufferStructure(nativeBuffer->sharingMode()), nativeBuffer);
+    ArrayBufferSharingMode sharingMode = nativeBuffer->sharingMode();
+    JSArrayBuffer* jsBuffer = JSArrayBuffer::create(vm, exec->lexicalGlobalObject()->arrayBufferStructure(sharingMode), WTFMove(nativeBuffer));
     
     MarkedArgumentBuffer args;
     args.append(jsBuffer);
index c0befc4..9fed7c7 100644 (file)
 namespace JSC {
 
 ArrayBufferView::ArrayBufferView(
-    PassRefPtr<ArrayBuffer> buffer,
+    RefPtr<ArrayBuffer>&& buffer,
     unsigned byteOffset)
         : m_byteOffset(byteOffset)
         , m_isNeuterable(true)
-        , m_buffer(buffer)
+        , m_buffer(WTFMove(buffer))
 {
     m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_byteOffset) : 0;
 }
index 55f346e..e76e6e2 100644 (file)
@@ -29,7 +29,6 @@
 #include "TypedArrayType.h"
 #include <algorithm>
 #include <limits.h>
-#include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
@@ -48,16 +47,16 @@ public:
         return !m_buffer || m_buffer->isNeutered();
     }
     
-    PassRefPtr<ArrayBuffer> possiblySharedBuffer() const
+    RefPtr<ArrayBuffer> possiblySharedBuffer() const
     {
         if (isNeutered())
-            return 0;
+            return nullptr;
         return m_buffer;
     }
     
-    PassRefPtr<ArrayBuffer> unsharedBuffer() const
+    RefPtr<ArrayBuffer> unsharedBuffer() const
     {
-        PassRefPtr<ArrayBuffer> result = possiblySharedBuffer();
+        RefPtr<ArrayBuffer> result = possiblySharedBuffer();
         RELEASE_ASSERT(!result->isShared());
         return result;
     }
@@ -100,9 +99,9 @@ public:
 
     // Helper to verify that a given sub-range of an ArrayBuffer is
     // within range.
-    static bool verifySubRangeLength(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned numElements, size_t size)
+    static bool verifySubRangeLength(const ArrayBuffer& buffer, unsigned byteOffset, unsigned numElements, size_t size)
     {
-        unsigned byteLength = buffer->byteLength();
+        unsigned byteLength = buffer.byteLength();
         if (byteOffset > byteLength)
             return false;
         unsigned remainingElements = (byteLength - byteOffset) / size;
@@ -114,7 +113,7 @@ public:
     virtual JSArrayBufferView* wrap(ExecState*, JSGlobalObject*) = 0;
     
 protected:
-    JS_EXPORT_PRIVATE ArrayBufferView(PassRefPtr<ArrayBuffer>, unsigned byteOffset);
+    JS_EXPORT_PRIVATE ArrayBufferView(RefPtr<ArrayBuffer>&&, unsigned byteOffset);
 
     inline bool setImpl(ArrayBufferView*, unsigned byteOffset);
 
@@ -130,20 +129,20 @@ protected:
     // output offset is in number of bytes from the underlying buffer's view.
     template <typename T>
     static void clampOffsetAndNumElements(
-        PassRefPtr<ArrayBuffer> buffer,
+        const ArrayBuffer& buffer,
         unsigned arrayByteOffset,
         unsigned *offset,
         unsigned *numElements)
     {
         unsigned maxOffset = (UINT_MAX - arrayByteOffset) / sizeof(T);
         if (*offset > maxOffset) {
-            *offset = buffer->byteLength();
+            *offset = buffer.byteLength();
             *numElements = 0;
             return;
         }
         *offset = arrayByteOffset + *offset * sizeof(T);
-        *offset = std::min(buffer->byteLength(), *offset);
-        unsigned remainingElements = (buffer->byteLength() - *offset) / sizeof(T);
+        *offset = std::min(buffer.byteLength(), *offset);
+        unsigned remainingElements = (buffer.byteLength() - *offset) / sizeof(T);
         *numElements = std::min(remainingElements, *numElements);
     }
 
index 2b2157c..480aea2 100644 (file)
@@ -99,7 +99,7 @@ struct MethodTable {
     typedef ArrayBuffer* (*SlowDownAndWasteMemory)(JSArrayBufferView*);
     SlowDownAndWasteMemory slowDownAndWasteMemory;
     
-    typedef PassRefPtr<ArrayBufferView> (*GetTypedArrayImpl)(JSArrayBufferView*);
+    typedef RefPtr<ArrayBufferView> (*GetTypedArrayImpl)(JSArrayBufferView*);
     GetTypedArrayImpl getTypedArrayImpl;
 
     typedef bool (*PreventExtensionsFunctionPtr)(JSObject*, ExecState*);
index b10ca40..3b5871b 100644 (file)
 
 namespace JSC {
 
-DataView::DataView(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned byteLength)
-    : ArrayBufferView(buffer, byteOffset)
+DataView::DataView(RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned byteLength)
+    : ArrayBufferView(WTFMove(buffer), byteOffset)
     , m_byteLength(byteLength)
 {
 }
 
 Ref<DataView> DataView::create(
-    PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned byteLength)
+    RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned byteLength)
 {
-    return adoptRef(*new DataView(buffer, byteOffset, byteLength));
+    return adoptRef(*new DataView(WTFMove(buffer), byteOffset, byteLength));
 }
 
-Ref<DataView> DataView::create(PassRefPtr<ArrayBuffer> passedBuffer)
+Ref<DataView> DataView::create(RefPtr<ArrayBuffer>&& buffer)
 {
-    RefPtr<ArrayBuffer> buffer = passedBuffer;
-    return create(buffer, 0, buffer->byteLength());
+    unsigned byteLength = buffer->byteLength();
+    return create(WTFMove(buffer), 0, byteLength);
 }
 
 JSArrayBufferView* DataView::wrap(ExecState* exec, JSGlobalObject* globalObject)
index 2281479..66363a7 100644 (file)
 
 #include "ArrayBufferView.h"
 #include <wtf/FlipBytes.h>
-#include <wtf/PassRefPtr.h>
 
 namespace JSC {
 
 class DataView : public ArrayBufferView {
 protected:
-    DataView(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned byteLength);
+    DataView(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned byteLength);
     
 public:
-    JS_EXPORT_PRIVATE static Ref<DataView> create(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned length);
-    static Ref<DataView> create(PassRefPtr<ArrayBuffer>);
+    JS_EXPORT_PRIVATE static Ref<DataView> create(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
+    static Ref<DataView> create(RefPtr<ArrayBuffer>&&);
     
     unsigned byteLength() const override
     {
index fd48c9c..347b651 100644 (file)
@@ -33,12 +33,12 @@ namespace JSC {
 template<typename Adaptor>
 class GenericTypedArrayView : public ArrayBufferView {
 protected:
-    GenericTypedArrayView(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned length);
+    GenericTypedArrayView(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
 
 public:
     static RefPtr<GenericTypedArrayView> create(unsigned length);
     static RefPtr<GenericTypedArrayView> create(const typename Adaptor::Type* array, unsigned length);
-    static RefPtr<GenericTypedArrayView> create(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned length);
+    static RefPtr<GenericTypedArrayView> create(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
     
     static RefPtr<GenericTypedArrayView> createUninitialized(unsigned length);
     
index da7a453..1b6da56 100644 (file)
@@ -32,8 +32,8 @@ namespace JSC {
 
 template<typename Adaptor>
 GenericTypedArrayView<Adaptor>::GenericTypedArrayView(
-    PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
-    : ArrayBufferView(buffer, byteOffset)
+    RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length)
+    : ArrayBufferView(WTFMove(buffer), byteOffset)
     , m_length(length)
 {
 }
@@ -58,10 +58,10 @@ RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
 
 template<typename Adaptor>
 RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(
-    PassRefPtr<ArrayBuffer> passedBuffer, unsigned byteOffset, unsigned length)
+    RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length)
 {
-    RefPtr<ArrayBuffer> buffer = passedBuffer;
-    if (!verifySubRangeLength(buffer, byteOffset, length, sizeof(typename Adaptor::Type))
+    ASSERT(buffer);
+    if (!ArrayBufferView::verifySubRangeLength(*buffer, byteOffset, length, sizeof(typename Adaptor::Type))
         || !verifyByteOffsetAlignment(byteOffset, sizeof(typename Adaptor::Type))) {
         return nullptr;
     }
@@ -94,7 +94,8 @@ GenericTypedArrayView<Adaptor>::subarray(int start, int end) const
     unsigned offset, length;
     calculateOffsetAndLength(start, end, this->length(), &offset, &length);
     ArrayBuffer* buffer = possiblySharedBuffer();
-    clampOffsetAndNumElements<Adaptor::Type>(buffer, byteOffset(), &offset, &length);
+    ASSERT(buffer);
+    clampOffsetAndNumElements<Adaptor::Type>(*buffer, byteOffset(), &offset, &length);
     return create(buffer, offset, length);
 }
 
diff --git a/Source/JavaScriptCore/runtime/IntegralTypedArrayBase.h b/Source/JavaScriptCore/runtime/IntegralTypedArrayBase.h
deleted file mode 100644 (file)
index c8149f6..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Copyright (c) 2010, Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#pragma once
-
-#include "TypedArrayBase.h"
-#include <limits>
-#include <wtf/MathExtras.h>
-
-// Base class for all WebGL<T>Array types holding integral
-// (non-floating-point) values.
-
-namespace JSC {
-
-template <typename T>
-class IntegralTypedArrayBase : public TypedArrayBase<T> {
-public:
-    void set(unsigned index, double value)
-    {
-        if (index >= TypedArrayBase<T>::m_length)
-            return;
-        if (std::isnan(value)) // Clamp NaN to 0
-            value = 0;
-        // The double cast is necessary to get the correct wrapping
-        // for out-of-range values with Int32Array and Uint32Array.
-        TypedArrayBase<T>::data()[index] = static_cast<T>(static_cast<int64_t>(value));
-    }
-
-protected:
-    IntegralTypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
-        : TypedArrayBase<T>(buffer, byteOffset, length)
-    {
-    }
-
-};
-
-} // namespace JSC
index 7a7faac..b24b6db 100644 (file)
@@ -35,7 +35,7 @@ namespace JSC {
 const ClassInfo JSArrayBuffer::s_info = {
     "ArrayBuffer", &Base::s_info, 0, CREATE_METHOD_TABLE(JSArrayBuffer)};
 
-JSArrayBuffer::JSArrayBuffer(VM& vm, Structure* structure, PassRefPtr<ArrayBuffer> arrayBuffer)
+JSArrayBuffer::JSArrayBuffer(VM& vm, Structure* structure, RefPtr<ArrayBuffer>&& arrayBuffer)
     : Base(vm, structure)
     , m_impl(arrayBuffer.get())
 {
@@ -50,12 +50,11 @@ void JSArrayBuffer::finishCreation(VM& vm, JSGlobalObject* globalObject)
 }
 
 JSArrayBuffer* JSArrayBuffer::create(
-    VM& vm, Structure* structure, PassRefPtr<ArrayBuffer> passedBuffer)
+    VM& vm, Structure* structure, RefPtr<ArrayBuffer>&& buffer)
 {
-    RefPtr<ArrayBuffer> buffer = passedBuffer;
     JSArrayBuffer* result =
         new (NotNull, allocateCell<JSArrayBuffer>(vm.heap))
-        JSArrayBuffer(vm, structure, buffer);
+        JSArrayBuffer(vm, structure, WTFMove(buffer));
     result->finishCreation(vm, structure->globalObject());
     return result;
 }
index 59287e1..91427a9 100644 (file)
@@ -36,12 +36,12 @@ public:
     static const unsigned StructureFlags = Base::StructureFlags;
     
 protected:
-    JSArrayBuffer(VM&, Structure*, PassRefPtr<ArrayBuffer>);
+    JSArrayBuffer(VM&, Structure*, RefPtr<ArrayBuffer>&&);
     void finishCreation(VM&, JSGlobalObject*);
     
 public:
     // This function will register the new wrapper with the vm's TypedArrayController.
-    JS_EXPORT_PRIVATE static JSArrayBuffer* create(VM&, Structure*, PassRefPtr<ArrayBuffer>);
+    JS_EXPORT_PRIVATE static JSArrayBuffer* create(VM&, Structure*, RefPtr<ArrayBuffer>&&);
 
     ArrayBuffer* impl() const { return m_impl; }
     
index b803d95..3c76bf9 100644 (file)
@@ -65,7 +65,7 @@ static EncodedJSValue JSC_HOST_CALL arrayBufferProtoFuncSlice(ExecState* exec)
     
     Structure* structure = callee->globalObject()->arrayBufferStructure(newBuffer->sharingMode());
     
-    JSArrayBuffer* result = JSArrayBuffer::create(vm, structure, newBuffer);
+    JSArrayBuffer* result = JSArrayBuffer::create(vm, structure, WTFMove(newBuffer));
     
     return JSValue::encode(result);
 }
index a3b3888..76b7fcd 100644 (file)
@@ -103,7 +103,7 @@ JSArrayBufferView::ConstructionContext::ConstructionContext(
 }
 
 JSArrayBufferView::ConstructionContext::ConstructionContext(
-    VM& vm, Structure* structure, PassRefPtr<ArrayBuffer> arrayBuffer,
+    VM& vm, Structure* structure, RefPtr<ArrayBuffer>&& arrayBuffer,
     unsigned byteOffset, unsigned length)
     : m_structure(structure)
     , m_length(length)
@@ -116,7 +116,7 @@ JSArrayBufferView::ConstructionContext::ConstructionContext(
 }
 
 JSArrayBufferView::ConstructionContext::ConstructionContext(
-    Structure* structure, PassRefPtr<ArrayBuffer> arrayBuffer,
+    Structure* structure, RefPtr<ArrayBuffer>&& arrayBuffer,
     unsigned byteOffset, unsigned length, DataViewTag)
     : m_structure(structure)
     , m_length(length)
index 7e51d51..447c83a 100644 (file)
@@ -122,12 +122,12 @@ protected:
         ConstructionContext(Structure*, uint32_t length, void* vector);
         
         JS_EXPORT_PRIVATE ConstructionContext(
-            VM&, Structure*, PassRefPtr<ArrayBuffer>,
+            VM&, Structure*, RefPtr<ArrayBuffer>&&,
             unsigned byteOffset, unsigned length);
         
         enum DataViewTag { DataView };
         ConstructionContext(
-            Structure*, PassRefPtr<ArrayBuffer>,
+            Structure*, RefPtr<ArrayBuffer>&&,
             unsigned byteOffset, unsigned length, DataViewTag);
         
         bool operator!() const { return !m_structure; }
@@ -162,8 +162,8 @@ public:
     ArrayBuffer* possiblySharedBuffer();
     JSArrayBuffer* unsharedJSBuffer(ExecState* exec);
     JSArrayBuffer* possiblySharedJSBuffer(ExecState* exec);
-    PassRefPtr<ArrayBufferView> unsharedImpl();
-    PassRefPtr<ArrayBufferView> possiblySharedImpl();
+    RefPtr<ArrayBufferView> unsharedImpl();
+    RefPtr<ArrayBufferView> possiblySharedImpl();
     bool isNeutered() { return hasArrayBuffer() && !vector(); }
     void neuter();
     
index b99567d..d5c727f 100644 (file)
@@ -61,14 +61,14 @@ inline ArrayBuffer* JSArrayBufferView::existingBufferInButterfly()
     return butterfly()->indexingHeader()->arrayBuffer();
 }
 
-inline PassRefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
+inline RefPtr<ArrayBufferView> JSArrayBufferView::possiblySharedImpl()
 {
     return methodTable()->getTypedArrayImpl(this);
 }
 
-inline PassRefPtr<ArrayBufferView> JSArrayBufferView::unsharedImpl()
+inline RefPtr<ArrayBufferView> JSArrayBufferView::unsharedImpl()
 {
-    PassRefPtr<ArrayBufferView> result = possiblySharedImpl();
+    RefPtr<ArrayBufferView> result = possiblySharedImpl();
     RELEASE_ASSERT(!result->isShared());
     return result;
 }
index 3ef831d..acdd4e8 100644 (file)
@@ -250,13 +250,13 @@ bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const Proper
 ArrayBuffer* JSCell::slowDownAndWasteMemory(JSArrayBufferView*)
 {
     RELEASE_ASSERT_NOT_REACHED();
-    return 0;
+    return nullptr;
 }
 
-PassRefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
+RefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
 {
     RELEASE_ASSERT_NOT_REACHED();
-    return 0;
+    return nullptr;
 }
 
 uint32_t JSCell::getEnumerableLength(ExecState*, JSObject*)
index c45eea3..1464bb5 100644 (file)
@@ -253,7 +253,7 @@ protected:
     static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
     JS_EXPORT_PRIVATE static ArrayBuffer* slowDownAndWasteMemory(JSArrayBufferView*);
-    JS_EXPORT_PRIVATE static PassRefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
+    JS_EXPORT_PRIVATE static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
 
 private:
     friend class LLIntOffsetsExtractor;
index f4afebb..1f67fbd 100644 (file)
@@ -44,14 +44,14 @@ JSDataView::JSDataView(VM& vm, ConstructionContext& context, ArrayBuffer* buffer
 }
 
 JSDataView* JSDataView::create(
-    ExecState* exec, Structure* structure, PassRefPtr<ArrayBuffer> passedBuffer,
+    ExecState* exec, Structure* structure, RefPtr<ArrayBuffer>&& buffer,
     unsigned byteOffset, unsigned byteLength)
 {
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
-    RefPtr<ArrayBuffer> buffer = passedBuffer;
-    if (!ArrayBufferView::verifySubRangeLength(buffer, byteOffset, byteLength, sizeof(uint8_t))) {
+    ASSERT(buffer);
+    if (!ArrayBufferView::verifySubRangeLength(*buffer, byteOffset, byteLength, sizeof(uint8_t))) {
         throwVMError(exec, scope, createRangeError(exec, ASCIILiteral("Length out of range of buffer")));
         return nullptr;
     }
@@ -60,7 +60,7 @@ JSDataView* JSDataView::create(
         return nullptr;
     }
     ConstructionContext context(
-        structure, buffer, byteOffset, byteLength, ConstructionContext::DataView);
+        structure, buffer.copyRef(), byteOffset, byteLength, ConstructionContext::DataView);
     ASSERT(context);
     JSDataView* result =
         new (NotNull, allocateCell<JSDataView>(vm.heap)) JSDataView(vm, context, buffer.get());
@@ -92,12 +92,12 @@ bool JSDataView::setIndex(ExecState*, unsigned, JSValue)
     return false;
 }
 
-PassRefPtr<DataView> JSDataView::possiblySharedTypedImpl()
+RefPtr<DataView> JSDataView::possiblySharedTypedImpl()
 {
     return DataView::create(possiblySharedBuffer(), byteOffset(), length());
 }
 
-PassRefPtr<DataView> JSDataView::unsharedTypedImpl()
+RefPtr<DataView> JSDataView::unsharedTypedImpl()
 {
     return DataView::create(unsharedBuffer(), byteOffset(), length());
 }
@@ -183,7 +183,7 @@ ArrayBuffer* JSDataView::slowDownAndWasteMemory(JSArrayBufferView*)
     return 0;
 }
 
-PassRefPtr<ArrayBufferView> JSDataView::getTypedArrayImpl(JSArrayBufferView* object)
+RefPtr<ArrayBufferView> JSDataView::getTypedArrayImpl(JSArrayBufferView* object)
 {
     JSDataView* thisObject = jsCast<JSDataView*>(object);
     return thisObject->possiblySharedTypedImpl();
index cae3a92..f42032e 100644 (file)
@@ -40,7 +40,7 @@ protected:
     
 public:
     JS_EXPORT_PRIVATE static JSDataView* create(
-        ExecState*, Structure*, PassRefPtr<ArrayBuffer>, unsigned byteOffset,
+        ExecState*, Structure*, RefPtr<ArrayBuffer>&&, unsigned byteOffset,
         unsigned byteLength);
     
     // Dummy methods, which don't actually work; these are just in place to
@@ -57,8 +57,8 @@ public:
         return m_buffer;
     }
     
-    PassRefPtr<DataView> possiblySharedTypedImpl();
-    PassRefPtr<DataView> unsharedTypedImpl();
+    RefPtr<DataView> possiblySharedTypedImpl();
+    RefPtr<DataView> unsharedTypedImpl();
     
     static const TypedArrayType TypedArrayStorageType = TypeDataView;
 
@@ -71,7 +71,7 @@ protected:
     static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
 
     static ArrayBuffer* slowDownAndWasteMemory(JSArrayBufferView*);
-    static PassRefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
+    static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
     
 public:
     static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
index 6109706..8a76cab 100644 (file)
@@ -107,9 +107,9 @@ public:
     static JSGenericTypedArrayView* create(ExecState*, Structure*, unsigned length);
     static JSGenericTypedArrayView* createWithFastVector(ExecState*, Structure*, unsigned length, void* vector);
     static JSGenericTypedArrayView* createUninitialized(ExecState*, Structure*, unsigned length);
-    static JSGenericTypedArrayView* create(ExecState*, Structure*, PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned length);
-    static JSGenericTypedArrayView* create(VM&, Structure*, PassRefPtr<typename Adaptor::ViewType> impl);
-    static JSGenericTypedArrayView* create(Structure*, JSGlobalObject*, PassRefPtr<typename Adaptor::ViewType> impl);
+    static JSGenericTypedArrayView* create(ExecState*, Structure*, RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length);
+    static JSGenericTypedArrayView* create(VM&, Structure*, RefPtr<typename Adaptor::ViewType>&& impl);
+    static JSGenericTypedArrayView* create(Structure*, JSGlobalObject*, RefPtr<typename Adaptor::ViewType>&& impl);
     
     unsigned byteLength() const { return m_length * sizeof(typename Adaptor::Type); }
     size_t byteSize() const { return sizeOf(m_length, sizeof(typename Adaptor::Type)); }
@@ -225,8 +225,8 @@ public:
     // then it will have thrown an exception.
     bool set(ExecState*, unsigned offset, JSObject*, unsigned objectOffset, unsigned length, CopyType type = CopyType::Unobservable);
     
-    PassRefPtr<typename Adaptor::ViewType> possiblySharedTypedImpl();
-    PassRefPtr<typename Adaptor::ViewType> unsharedTypedImpl();
+    RefPtr<typename Adaptor::ViewType> possiblySharedTypedImpl();
+    RefPtr<typename Adaptor::ViewType> unsharedTypedImpl();
 
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
     {
@@ -291,7 +291,7 @@ protected:
     // Allocates the full-on native buffer and moves data into the C heap if
     // necessary. Note that this never allocates in the GC heap.
     static ArrayBuffer* slowDownAndWasteMemory(JSArrayBufferView*);
-    static PassRefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
+    static RefPtr<ArrayBufferView> getTypedArrayImpl(JSArrayBufferView*);
 
 private:
     // Returns true if successful, and false on error; it will throw on error.
index 448ab92..3ee95a0 100644 (file)
@@ -135,7 +135,7 @@ inline JSObject* constructGenericTypedArrayViewWithArguments(ExecState* exec, St
         }
 
         scope.release();
-        return ViewClass::create(exec, structure, buffer, offset, length);
+        return ViewClass::create(exec, structure, WTFMove(buffer), offset, length);
     }
     ASSERT(!offset && !lengthOpt);
     
index 621de25..f019659 100644 (file)
@@ -97,14 +97,14 @@ JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::createUninit
 
 template<typename Adaptor>
 JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::create(
-    ExecState* exec, Structure* structure, PassRefPtr<ArrayBuffer> passedBuffer,
+    ExecState* exec, Structure* structure, RefPtr<ArrayBuffer>&& buffer,
     unsigned byteOffset, unsigned length)
 {
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    RefPtr<ArrayBuffer> buffer = passedBuffer;
     size_t size = sizeof(typename Adaptor::Type);
-    if (!ArrayBufferView::verifySubRangeLength(buffer, byteOffset, length, size)) {
+    ASSERT(buffer);
+    if (!ArrayBufferView::verifySubRangeLength(*buffer, byteOffset, length, size)) {
         throwException(exec, scope, createRangeError(exec, "Length out of range of buffer"));
         return nullptr;
     }
@@ -112,7 +112,7 @@ JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::create(
         throwException(exec, scope, createRangeError(exec, "Byte offset is not aligned"));
         return nullptr;
     }
-    ConstructionContext context(vm, structure, buffer, byteOffset, length);
+    ConstructionContext context(vm, structure, WTFMove(buffer), byteOffset, length);
     ASSERT(context);
     JSGenericTypedArrayView* result =
         new (NotNull, allocateCell<JSGenericTypedArrayView>(vm.heap))
@@ -123,10 +123,9 @@ JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::create(
 
 template<typename Adaptor>
 JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::create(
-    VM& vm, Structure* structure, PassRefPtr<typename Adaptor::ViewType> impl)
+    VM& vm, Structure* structure, RefPtr<typename Adaptor::ViewType>&& impl)
 {
-    RefPtr<ArrayBuffer> buffer = impl->possiblySharedBuffer();
-    ConstructionContext context(vm, structure, buffer, impl->byteOffset(), impl->length());
+    ConstructionContext context(vm, structure, impl->possiblySharedBuffer(), impl->byteOffset(), impl->length());
     ASSERT(context);
     JSGenericTypedArrayView* result =
         new (NotNull, allocateCell<JSGenericTypedArrayView>(vm.heap))
@@ -138,9 +137,9 @@ JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::create(
 template<typename Adaptor>
 JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::create(
     Structure* structure, JSGlobalObject* globalObject,
-    PassRefPtr<typename Adaptor::ViewType> impl)
+    RefPtr<typename Adaptor::ViewType>&& impl)
 {
-    return create(globalObject->vm(), structure, impl);
+    return create(globalObject->vm(), structure, WTFMove(impl));
 }
 
 template<typename Adaptor>
@@ -322,13 +321,13 @@ bool JSGenericTypedArrayView<Adaptor>::set(
 }
 
 template<typename Adaptor>
-PassRefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl()
+RefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::possiblySharedTypedImpl()
 {
     return Adaptor::ViewType::create(possiblySharedBuffer(), byteOffset(), length());
 }
 
 template<typename Adaptor>
-PassRefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl()
+RefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::unsharedTypedImpl()
 {
     return Adaptor::ViewType::create(unsharedBuffer(), byteOffset(), length());
 }
@@ -590,8 +589,7 @@ ArrayBuffer* JSGenericTypedArrayView<Adaptor>::slowDownAndWasteMemory(JSArrayBuf
 }
 
 template<typename Adaptor>
-PassRefPtr<ArrayBufferView>
-JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl(JSArrayBufferView* object)
+RefPtr<ArrayBufferView> JSGenericTypedArrayView<Adaptor>::getTypedArrayImpl(JSArrayBufferView* object)
 {
     JSGenericTypedArrayView* thisObject = jsCast<JSGenericTypedArrayView*>(object);
     return thisObject->possiblySharedTypedImpl();
index 874baa6..2cbcad3 100644 (file)
@@ -556,7 +556,7 @@ EncodedJSValue JSC_HOST_CALL genericTypedArrayViewPrivateFuncSubarrayCreate(VM&v
 
         scope.release();
         return JSValue::encode(ViewClass::create(
-            exec, structure, arrayBuffer,
+            exec, structure, WTFMove(arrayBuffer),
             thisObject->byteOffset() + offset * ViewClass::elementSize,
             length));
     }
index b88d9f4..169308e 100644 (file)
@@ -49,9 +49,9 @@ MAKE_S_INFO(Uint32);
 MAKE_S_INFO(Float32);
 MAKE_S_INFO(Float64);
 
-JSUint8Array* createUint8TypedArray(ExecState* exec, Structure* structure, RefPtr<ArrayBuffer>&& passedBuffer, unsigned byteOffset, unsigned length)
+JSUint8Array* createUint8TypedArray(ExecState* exec, Structure* structure, RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length)
 {
-    return JSUint8Array::create(exec, structure, std::forward<RefPtr<ArrayBuffer>>(passedBuffer), byteOffset, length);
+    return JSUint8Array::create(exec, structure, WTFMove(buffer), byteOffset, length);
 }
 
 
diff --git a/Source/JavaScriptCore/runtime/TypedArrayBase.h b/Source/JavaScriptCore/runtime/TypedArrayBase.h
deleted file mode 100644 (file)
index 8a68761..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Copyright (c) 2010, Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#pragma once
-
-#include "ArrayBuffer.h"
-#include "ArrayBufferView.h"
-
-namespace JSC {
-
-template <typename T>
-class TypedArrayBase : public ArrayBufferView {
-public:
-    T* data() const { return static_cast<T*>(baseAddress()); }
-
-    bool set(TypedArrayBase<T>* array, unsigned offset)
-    {
-        return setImpl(array, offset * sizeof(T));
-    }
-
-    bool setRange(const T* data, size_t dataLength, unsigned offset)
-    {
-        return setRangeImpl(reinterpret_cast<const char*>(data), dataLength * sizeof(T), offset * sizeof(T));
-    }
-
-    bool zeroRange(unsigned offset, size_t length)
-    {
-        return zeroRangeImpl(offset * sizeof(T), length * sizeof(T));
-    }
-
-    // Overridden from ArrayBufferView. This must be public because of
-    // rules about inheritance of members in template classes, and
-    // because it is accessed via pointers to subclasses.
-    unsigned length() const
-    {
-        return m_length;
-    }
-
-    virtual unsigned byteLength() const
-    {
-        return m_length * sizeof(T);
-    }
-
-    // Invoked by the indexed getter. Does not perform range checks; caller
-    // is responsible for doing so and returning undefined as necessary.
-    T item(unsigned index) const
-    {
-        ASSERT_WITH_SECURITY_IMPLICATION(index < TypedArrayBase<T>::m_length);
-        return TypedArrayBase<T>::data()[index];
-    }
-
-    bool checkInboundData(unsigned offset, unsigned pos) const
-    {
-        return (offset <= m_length
-            && offset + pos <= m_length
-            // check overflow
-            && offset + pos >= offset);
-    }
-
-protected:
-    TypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
-        : ArrayBufferView(buffer, byteOffset)
-        , m_length(length)
-    {
-    }
-
-    template <class Subclass>
-    static PassRefPtr<Subclass> create(unsigned length)
-    {
-        RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, sizeof(T));
-        if (!buffer.get())
-            return 0;
-        return create<Subclass>(buffer.release(), 0, length);
-    }
-
-    template <class Subclass>
-    static PassRefPtr<Subclass> create(const T* array, unsigned length)
-    {
-        RefPtr<Subclass> a = create<Subclass>(length);
-        if (a)
-            for (unsigned i = 0; i < length; ++i)
-                a->set(i, array[i]);
-        return a.release();
-    }
-
-    template <class Subclass>
-    static RefPtr<Subclass> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
-    {
-        RefPtr<ArrayBuffer> buf(buffer);
-        if (!verifySubRange<T>(buf, byteOffset, length))
-            return nullptr;
-
-        return adoptRef(new Subclass(buf.release(), byteOffset, length));
-    }
-
-    template <class Subclass>
-    static RefPtr<Subclass> createUninitialized(unsigned length)
-    {
-        RefPtr<ArrayBuffer> buffer = ArrayBuffer::createUninitialized(length, sizeof(T));
-        if (!buffer.get())
-            return nullptr;
-        return create<Subclass>(buffer.release(), 0, length);
-    }
-
-    template <class Subclass>
-    RefPtr<Subclass> subarrayImpl(int start, int end) const
-    {
-        unsigned offset, length;
-        calculateOffsetAndLength(start, end, m_length, &offset, &length);
-        clampOffsetAndNumElements<T>(buffer(), m_byteOffset, &offset, &length);
-        return create<Subclass>(buffer(), offset, length);
-    }
-
-    virtual void neuter()
-    {
-        ArrayBufferView::neuter();
-        m_length = 0;
-    }
-
-    // We do not want to have to access this via a virtual function in subclasses,
-    // which is why it is protected rather than private.
-    unsigned m_length;
-};
-
-} // namespace JSC
-
-using JSC::TypedArrayBase;
index c8964e1..f4f27c6 100644 (file)
@@ -1,3 +1,23 @@
+2017-02-16  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Drop PassRefPtr from ArrayBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=168455
+
+        Reviewed by Geoffrey Garen.
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneDeserializer::readArrayBufferView):
+        * css/FontFace.cpp:
+        (WebCore::FontFace::create):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
+        (WebCore::MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitData):
+        * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
+        (WebCore::AVFWrapper::shouldWaitForLoadingOfResource):
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
+        (WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
+
 2017-02-16  Simon Fraser  <simon.fraser@apple.com>
 
         REGRESSION(r212439): Web Inspector Toolbar / Window appears broken
index 4a741b7..c9904c0 100644 (file)
@@ -1856,34 +1856,34 @@ private:
         RefPtr<ArrayBuffer> arrayBuffer = toPossiblySharedArrayBuffer(vm, arrayBufferObj);
         switch (arrayBufferViewSubtag) {
         case DataViewTag:
-            arrayBufferView = getJSValue(DataView::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = getJSValue(DataView::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Int8ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Int8Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Int8Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint8ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint8Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint8Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint8ClampedArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint8ClampedArray::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint8ClampedArray::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Int16ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Int16Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Int16Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint16ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint16Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint16Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Int32ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Int32Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Int32Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Uint32ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Uint32Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Uint32Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Float32ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Float32Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Float32Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         case Float64ArrayTag:
-            arrayBufferView = toJS(m_exec, m_globalObject, Float64Array::create(arrayBuffer, byteOffset, length).get());
+            arrayBufferView = toJS(m_exec, m_globalObject, Float64Array::create(WTFMove(arrayBuffer), byteOffset, length).get());
             return true;
         default:
             return false;
index b74cab4..6fb77c0 100644 (file)
@@ -72,7 +72,8 @@ ExceptionOr<Ref<FontFace>> FontFace::create(Document& document, const String& fa
             return { };
         },
         [&] (RefPtr<ArrayBuffer>& arrayBuffer) -> ExceptionOr<void> {
-            auto arrayBufferView = JSC::Uint8Array::create(arrayBuffer, 0, arrayBuffer->byteLength());
+            unsigned byteLength = arrayBuffer->byteLength();
+            auto arrayBufferView = JSC::Uint8Array::create(WTFMove(arrayBuffer), 0, byteLength);
             dataRequiresAsynchronousLoading = populateFontFaceWithArrayBuffer(result->backing(), arrayBufferView.releaseNonNull());
             return { };
         }
index 7ab7ecb..fef95df 100644 (file)
@@ -41,7 +41,9 @@
 #include "Settings.h"
 #include "SoftLinking.h"
 #include <CoreMedia/CoreMedia.h>
+#include <heap/HeapInlines.h>
 #include <runtime/DataView.h>
+#include <runtime/TypedArrayInlines.h>
 #include <runtime/Uint16Array.h>
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
@@ -1028,7 +1030,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     RefPtr<ArrayBuffer> initDataBuffer = initData->unsharedBuffer();
 
     // Use a DataView to read uint32 values from the buffer, as Uint32Array requires the reads be aligned on 4-byte boundaries. 
-    RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer, 0, initDataBuffer->byteLength());
+    RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, initDataBuffer->byteLength());
     uint32_t offset = 0;
     bool status = true;
 
@@ -1037,7 +1039,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     if (!status || offset + keyURILength > initData->length())
         return false;
 
-    RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer, offset, keyURILength);
+    RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), offset, keyURILength);
     if (!keyURIArray)
         return false;
 
@@ -1049,7 +1051,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     if (!status || offset + keyIDLength > initData->length())
         return false;
 
-    RefPtr<Uint8Array> keyIDArray = Uint8Array::create(initDataBuffer, offset, keyIDLength);
+    RefPtr<Uint8Array> keyIDArray = Uint8Array::create(initDataBuffer.copyRef(), offset, keyIDLength);
     if (!keyIDArray)
         return false;
 
@@ -1061,7 +1063,7 @@ bool MediaPlayerPrivateAVFoundation::extractKeyURIKeyIDAndCertificateFromInitDat
     if (!status || offset + certificateLength > initData->length())
         return false;
 
-    certificate = Uint8Array::create(initDataBuffer, offset, certificateLength);
+    certificate = Uint8Array::create(WTFMove(initDataBuffer), offset, certificateLength);
     if (!certificate)
         return false;
 
index cbd0c3c..e4d0f91 100644 (file)
@@ -1911,13 +1911,14 @@ bool AVFWrapper::shouldWaitForLoadingOfResource(AVCFAssetResourceLoadingRequestR
         // [4 bytes: keyURI size], [keyURI size bytes: keyURI]
         unsigned keyURISize = keyURI.length() * sizeof(UChar);
         RefPtr<ArrayBuffer> initDataBuffer = ArrayBuffer::create(4 + keyURISize, 1);
-        RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer, 0, initDataBuffer->byteLength());
+        RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, initDataBuffer->byteLength());
         initDataView->set<uint32_t>(0, keyURISize, true);
 
-        RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer, 4, keyURI.length());
+        RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), 4, keyURI.length());
         keyURIArray->setRange(reinterpret_cast<const uint16_t*>(StringView(keyURI).upconvertedCharacters().get()), keyURI.length() / sizeof(unsigned char), 0);
 
-        RefPtr<Uint8Array> initData = Uint8Array::create(initDataBuffer, 0, initDataBuffer->byteLength());
+        unsigned byteLength = initDataBuffer->byteLength();
+        RefPtr<Uint8Array> initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
         if (!m_owner->player()->keyNeeded(initData.get()))
             return false;
 
index 26156ac..2990f7c 100644 (file)
@@ -38,6 +38,7 @@
 #import <AVFoundation/AVAsset.h>
 #import <AVFoundation/AVAssetResourceLoader.h>
 #import <objc/objc-runtime.h>
+#import <runtime/TypedArrayInlines.h>
 #import <wtf/MainThread.h>
 
 SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
@@ -100,7 +101,8 @@ RefPtr<Uint8Array> CDMSessionAVFoundationObjC::generateKeyRequest(const String&
     destinationURL = String();
 
     RefPtr<ArrayBuffer> keyRequestBuffer = ArrayBuffer::create([keyRequest.get() bytes], [keyRequest.get() length]);
-    return Uint8Array::create(keyRequestBuffer, 0, keyRequestBuffer->byteLength());
+    unsigned byteLength = keyRequestBuffer->byteLength();
+    return Uint8Array::create(WTFMove(keyRequestBuffer), 0, byteLength);
 }
 
 void CDMSessionAVFoundationObjC::releaseKeys()
index 168fad1..f038da0 100644 (file)
@@ -1770,19 +1770,22 @@ bool MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource(AVAssetR
         // [4 bytes: keyURI size], [keyURI size bytes: keyURI]
         unsigned keyURISize = keyURI.length() * sizeof(UChar);
         RefPtr<ArrayBuffer> initDataBuffer = ArrayBuffer::create(4 + keyURISize, 1);
-        RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer, 0, initDataBuffer->byteLength());
+        unsigned byteLength = initDataBuffer->byteLength();
+        RefPtr<JSC::DataView> initDataView = JSC::DataView::create(initDataBuffer.copyRef(), 0, byteLength);
         initDataView->set<uint32_t>(0, keyURISize, true);
 
-        RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer, 4, keyURI.length());
+        RefPtr<Uint16Array> keyURIArray = Uint16Array::create(initDataBuffer.copyRef(), 4, keyURI.length());
         keyURIArray->setRange(StringView(keyURI).upconvertedCharacters(), keyURI.length() / sizeof(unsigned char), 0);
 
-        RefPtr<Uint8Array> initData = Uint8Array::create(initDataBuffer, 0, initDataBuffer->byteLength());
+        RefPtr<Uint8Array> initData = Uint8Array::create(WTFMove(initDataBuffer), 0, byteLength);
         if (!player()->keyNeeded(initData.get()))
             return false;
 
         m_keyURIToRequestMap.set(keyURI, avRequest);
         return true;
-    } else if (scheme == "clearkey") {
+    }
+
+    if (scheme == "clearkey") {
         String keyID = [[[avRequest request] URL] resourceSpecifier];
         StringView keyIDView(keyID);
         CString utf8EncodedKeyId = UTF8Encoding().encode(keyIDView, URLEncodedEntitiesForUnencodables);