[JSC] Add ArrayBuffer::tryCreate and change the callsites where it is needed
authorjh718.park@samsung.com <jh718.park@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Mar 2016 15:59:20 +0000 (15:59 +0000)
committerjh718.park@samsung.com <jh718.park@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Mar 2016 15:59:20 +0000 (15:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155328

Reviewed by Darin Adler.

Source/JavaScriptCore:

* API/JSTypedArray.cpp:
(JSObjectMakeTypedArray):
(JSObjectMakeArrayBufferWithBytesNoCopy):
* runtime/ArrayBuffer.h:
(JSC::ArrayBuffer::create):
(JSC::ArrayBuffer::tryCreate):
(JSC::ArrayBuffer::createUninitialized):
(JSC::ArrayBuffer::tryCreateUninitialized):
(JSC::ArrayBuffer::createInternal):
* runtime/GenericTypedArrayViewInlines.h:
(JSC::GenericTypedArrayView<Adaptor>::create):
(JSC::GenericTypedArrayView<Adaptor>::createUninitialized):
* runtime/JSArrayBufferConstructor.cpp:
(JSC::constructArrayBuffer):

Source/WebCore:

No new tests, no new behaviours.

* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::processIfEmptyOrDisturbed):
(WebCore::FetchBody::consumeText):
* Modules/fetch/FetchLoader.cpp:
(WebCore::FetchLoader::didFinishLoading):
* bindings/js/JSDOMPromise.h:
(WebCore::char>>):
* dom/MessageEvent.cpp:
(WebCore::MessageEvent::MessageEvent):
* dom/MessageEvent.h:
* fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::didReceiveResponse):
(WebCore::FileReaderLoader::didReceiveData):
(WebCore::FileReaderLoader::arrayBufferResult):
* html/canvas/WebGLBuffer.cpp:
(WebCore::WebGLBuffer::associateBufferDataImpl):
* html/track/DataCue.cpp:
(WebCore::DataCue::DataCue):
(WebCore::DataCue::data):
(WebCore::DataCue::setData):
(WebCore::DataCue::cueContentsMatch):
* html/track/DataCue.h:
* html/track/InbandDataTextTrack.cpp:
(WebCore::InbandDataTextTrack::addDataCue):
(WebCore::InbandDataTextTrack::removeCue):
* platform/mac/SerializedPlatformRepresentationMac.mm:
(WebCore::jsValueWithDataInContext):

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

17 files changed:
Source/JavaScriptCore/API/JSTypedArray.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ArrayBuffer.h
Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h
Source/JavaScriptCore/runtime/JSArrayBufferConstructor.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchBody.cpp
Source/WebCore/Modules/fetch/FetchLoader.cpp
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/dom/MessageEvent.cpp
Source/WebCore/dom/MessageEvent.h
Source/WebCore/fileapi/FileReaderLoader.cpp
Source/WebCore/html/canvas/WebGLBuffer.cpp
Source/WebCore/html/track/DataCue.cpp
Source/WebCore/html/track/DataCue.h
Source/WebCore/html/track/InbandDataTextTrack.cpp
Source/WebCore/platform/mac/SerializedPlatformRepresentationMac.mm

index 2fea93f..2629ac9 100644 (file)
@@ -161,7 +161,7 @@ JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType,
 
     unsigned elementByteSize = elementSize(toTypedArrayType(arrayType));
 
-    RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, elementByteSize);
+    auto buffer = ArrayBuffer::tryCreate(length, elementByteSize);
     JSObject* result = createTypedArray(exec, arrayType, WTFMove(buffer), 0, length);
     if (handleExceptionIfNeeded(exec, exception) == ExceptionStatus::DidThrow)
         return nullptr;
@@ -292,7 +292,7 @@ JSObjectRef JSObjectMakeArrayBufferWithBytesNoCopy(JSContextRef ctx, void* bytes
     ExecState* exec = toJS(ctx);
     JSLockHolder locker(exec);
 
-    RefPtr<ArrayBuffer> buffer = ArrayBuffer::createFromBytes(bytes, byteLength, [=](void* p) {
+    auto buffer = ArrayBuffer::createFromBytes(bytes, byteLength, [=](void* p) {
         if (bytesDeallocator)
             bytesDeallocator(p, deallocatorContext);
     });
index e537694..dcf8900 100644 (file)
@@ -1,3 +1,25 @@
+2016-03-21  Joonghun Park  <jh718.park@samsung.com>
+
+        [JSC] Add ArrayBuffer::tryCreate and change the callsites where it is needed
+        https://bugs.webkit.org/show_bug.cgi?id=155328
+
+        Reviewed by Darin Adler.
+
+        * API/JSTypedArray.cpp:
+        (JSObjectMakeTypedArray):
+        (JSObjectMakeArrayBufferWithBytesNoCopy):
+        * runtime/ArrayBuffer.h:
+        (JSC::ArrayBuffer::create):
+        (JSC::ArrayBuffer::tryCreate):
+        (JSC::ArrayBuffer::createUninitialized):
+        (JSC::ArrayBuffer::tryCreateUninitialized):
+        (JSC::ArrayBuffer::createInternal):
+        * runtime/GenericTypedArrayViewInlines.h:
+        (JSC::GenericTypedArrayView<Adaptor>::create):
+        (JSC::GenericTypedArrayView<Adaptor>::createUninitialized):
+        * runtime/JSArrayBufferConstructor.cpp:
+        (JSC::constructArrayBuffer):
+
 2016-03-20  Dan Bernstein  <mitz@apple.com>
 
         [Mac] Determine TARGET_MAC_OS_X_VERSION_MAJOR from MACOSX_DEPLOYMENT_TARGET rather than from MAC_OS_X_VERSION_MAJOR
index b3d7ec6..31d87e6 100644 (file)
@@ -97,15 +97,19 @@ private:
 
 class ArrayBuffer : public GCIncomingRefCounted<ArrayBuffer> {
 public:
-    static inline RefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize);
-    static inline RefPtr<ArrayBuffer> create(ArrayBuffer*);
-    static inline RefPtr<ArrayBuffer> create(const void* source, unsigned byteLength);
+    static inline Ref<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize);
+    static inline Ref<ArrayBuffer> create(ArrayBuffer&);
+    static inline Ref<ArrayBuffer> create(const void* source, unsigned byteLength);
     static inline Ref<ArrayBuffer> create(ArrayBufferContents&);
     static inline Ref<ArrayBuffer> createAdopted(const void* data, unsigned byteLength);
     static inline Ref<ArrayBuffer> createFromBytes(const void* data, unsigned byteLength, ArrayBufferDestructorFunction&&);
+    static inline RefPtr<ArrayBuffer> tryCreate(unsigned numElements, unsigned elementByteSize);
+    static inline RefPtr<ArrayBuffer> tryCreate(ArrayBuffer&);
+    static inline RefPtr<ArrayBuffer> tryCreate(const void* source, unsigned byteLength);
 
     // Only for use by Uint8ClampedArray::createUninitialized and SharedBuffer::createArrayBuffer.
-    static inline RefPtr<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize);
+    static inline Ref<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize);
+    static inline RefPtr<ArrayBuffer> tryCreateUninitialized(unsigned numElements, unsigned elementByteSize);
 
     inline void* data();
     inline const void* data() const;
@@ -128,8 +132,9 @@ public:
     ~ArrayBuffer() { }
 
 private:
-    static inline RefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
-
+    static inline Ref<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
+    static inline Ref<ArrayBuffer> createInternal(ArrayBufferContents&, const void*, unsigned);
+    static inline RefPtr<ArrayBuffer> tryCreate(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
     inline ArrayBuffer(ArrayBufferContents&);
     inline RefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const;
     inline unsigned clampIndex(int index) const;
@@ -153,26 +158,25 @@ int ArrayBuffer::clampValue(int x, int left, int right)
     return x;
 }
 
-RefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize)
+Ref<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize)
 {
-    return create(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize);
+    auto buffer = tryCreate(numElements, elementByteSize);
+    if (!buffer)
+        CRASH();
+    return buffer.releaseNonNull();
 }
 
-RefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other)
+Ref<ArrayBuffer> ArrayBuffer::create(ArrayBuffer& other)
 {
-    return ArrayBuffer::create(other->data(), other->byteLength());
+    return ArrayBuffer::create(other.data(), other.byteLength());
 }
 
-RefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength)
+Ref<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength)
 {
-    ArrayBufferContents contents;
-    ArrayBufferContents::tryAllocate(byteLength, 1, ArrayBufferContents::ZeroInitialize, contents);
-    if (!contents.m_data)
-        return nullptr;
-    auto buffer = adoptRef(*new ArrayBuffer(contents));
-    ASSERT(!byteLength || source);
-    memcpy(buffer->data(), source, byteLength);
-    return WTFMove(buffer);
+    auto buffer = tryCreate(source, byteLength);
+    if (!buffer)
+        CRASH();
+    return buffer.releaseNonNull();
 }
 
 Ref<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents)
@@ -191,12 +195,52 @@ Ref<ArrayBuffer> ArrayBuffer::createFromBytes(const void* data, unsigned byteLen
     return create(contents);
 }
 
-RefPtr<ArrayBuffer> ArrayBuffer::createUninitialized(unsigned numElements, unsigned elementByteSize)
+RefPtr<ArrayBuffer> ArrayBuffer::tryCreate(unsigned numElements, unsigned elementByteSize)
+{
+    return tryCreate(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize);
+}
+
+RefPtr<ArrayBuffer> ArrayBuffer::tryCreate(ArrayBuffer& other)
+{
+    return tryCreate(other.data(), other.byteLength());
+}
+
+RefPtr<ArrayBuffer> ArrayBuffer::tryCreate(const void* source, unsigned byteLength)
+{
+    ArrayBufferContents contents;
+    ArrayBufferContents::tryAllocate(byteLength, 1, ArrayBufferContents::ZeroInitialize, contents);
+    if (!contents.m_data)
+        return nullptr;
+    return createInternal(contents, source, byteLength);
+}
+
+Ref<ArrayBuffer> ArrayBuffer::createUninitialized(unsigned numElements, unsigned elementByteSize)
 {
     return create(numElements, elementByteSize, ArrayBufferContents::DontInitialize);
 }
 
-RefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
+RefPtr<ArrayBuffer> ArrayBuffer::tryCreateUninitialized(unsigned numElements, unsigned elementByteSize)
+{
+    return tryCreate(numElements, elementByteSize, ArrayBufferContents::DontInitialize);
+}
+
+Ref<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
+{
+    auto buffer = tryCreate(numElements, elementByteSize, policy);
+    if (!buffer)
+        CRASH();
+    return buffer.releaseNonNull();
+}
+
+Ref<ArrayBuffer> ArrayBuffer::createInternal(ArrayBufferContents& contents, const void* source, unsigned byteLength)
+{
+    ASSERT(!byteLength || source);
+    auto buffer = adoptRef(*new ArrayBuffer(contents));
+    memcpy(buffer->data(), source, byteLength);
+    return buffer;
+}
+
+RefPtr<ArrayBuffer> ArrayBuffer::tryCreate(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
 {
     ArrayBufferContents contents;
     ArrayBufferContents::tryAllocate(numElements, elementByteSize, policy, contents);
index 2537269..a8737ee 100644 (file)
@@ -42,7 +42,7 @@ GenericTypedArrayView<Adaptor>::GenericTypedArrayView(
 template<typename Adaptor>
 RefPtr<GenericTypedArrayView<Adaptor>> GenericTypedArrayView<Adaptor>::create(unsigned length)
 {
-    RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, sizeof(typename Adaptor::Type));
+    auto buffer = ArrayBuffer::tryCreate(length, sizeof(typename Adaptor::Type));
     if (!buffer)
         return nullptr;
     return create(buffer.release(), 0, length);
@@ -75,7 +75,7 @@ RefPtr<GenericTypedArrayView<Adaptor>>
 GenericTypedArrayView<Adaptor>::createUninitialized(unsigned length)
 {
     RefPtr<ArrayBuffer> buffer =
-        ArrayBuffer::createUninitialized(length, sizeof(typename Adaptor::Type));
+        ArrayBuffer::tryCreateUninitialized(length, sizeof(typename Adaptor::Type));
     if (!buffer)
         return nullptr;
     return create(buffer.release(), 0, length);
index cf456f3..2be03f8 100644 (file)
@@ -92,7 +92,7 @@ static EncodedJSValue JSC_HOST_CALL constructArrayBuffer(ExecState* exec)
         length = 0;
     }
     
-    RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, 1);
+    auto buffer = ArrayBuffer::tryCreate(length, 1);
     if (!buffer)
         return throwVMError(exec, createOutOfMemoryError(exec));
 
index 06ad629..61b0f14 100644 (file)
@@ -1,3 +1,40 @@
+2016-03-21  Joonghun Park  <jh718.park@samsung.com>
+
+        [JSC] Add ArrayBuffer::tryCreate and change the callsites where it is needed
+        https://bugs.webkit.org/show_bug.cgi?id=155328
+
+        Reviewed by Darin Adler.
+
+        No new tests, no new behaviours.
+
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::processIfEmptyOrDisturbed):
+        (WebCore::FetchBody::consumeText):
+        * Modules/fetch/FetchLoader.cpp:
+        (WebCore::FetchLoader::didFinishLoading):
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::char>>):
+        * dom/MessageEvent.cpp:
+        (WebCore::MessageEvent::MessageEvent):
+        * dom/MessageEvent.h:
+        * fileapi/FileReaderLoader.cpp:
+        (WebCore::FileReaderLoader::didReceiveResponse):
+        (WebCore::FileReaderLoader::didReceiveData):
+        (WebCore::FileReaderLoader::arrayBufferResult):
+        * html/canvas/WebGLBuffer.cpp:
+        (WebCore::WebGLBuffer::associateBufferDataImpl):
+        * html/track/DataCue.cpp:
+        (WebCore::DataCue::DataCue):
+        (WebCore::DataCue::data):
+        (WebCore::DataCue::setData):
+        (WebCore::DataCue::cueContentsMatch):
+        * html/track/DataCue.h:
+        * html/track/InbandDataTextTrack.cpp:
+        (WebCore::InbandDataTextTrack::addDataCue):
+        (WebCore::InbandDataTextTrack::removeCue):
+        * platform/mac/SerializedPlatformRepresentationMac.mm:
+        (WebCore::jsValueWithDataInContext):
+
 2016-02-03  Sergio Villar Senin  <svillar@igalia.com>
 
         [css-grid] Fix percentage tracks' size computation in grids with gutters
index 31dd0ee..6ce56de 100644 (file)
@@ -97,7 +97,7 @@ bool FetchBody::processIfEmptyOrDisturbed(Consumer::Type type, DeferredWrapper&
             promise.reject<ExceptionCode>(SYNTAX_ERR);
             return true;
         case Consumer::Type::ArrayBuffer:
-            promise.resolve(ArrayBuffer::create(nullptr, 0));
+            promise.resolve(ArrayBuffer::tryCreate(nullptr, 0));
             return true;
         default:
             ASSERT_NOT_REACHED();
@@ -174,7 +174,7 @@ void FetchBody::consumeText(Consumer::Type type, DeferredWrapper&& promise)
 
     if (type == Consumer::Type::ArrayBuffer) {
         Vector<char> data = extractFromText();
-        promise.resolve<RefPtr<ArrayBuffer>>(ArrayBuffer::create(data.data(), data.size()));
+        promise.resolve<RefPtr<ArrayBuffer>>(ArrayBuffer::tryCreate(data.data(), data.size()));
         return;
     }
     String contentType = Blob::normalizedContentType(extractMIMETypeFromMediaType(m_mimeType));
index 97bc977..834a7ad 100644 (file)
@@ -100,7 +100,7 @@ void FetchLoader::didReceiveData(const char* value, int size)
 void FetchLoader::didFinishLoading(unsigned long, double)
 {
     if (m_type == Type::ArrayBuffer)
-        m_client.didFinishLoadingAsArrayBuffer(m_data ? m_data->createArrayBuffer() : ArrayBuffer::create(nullptr, 0));
+        m_client.didFinishLoadingAsArrayBuffer(m_data ? m_data->createArrayBuffer() : ArrayBuffer::tryCreate(nullptr, 0));
     else
         m_client.didFinishLoadingAsText(m_data ? TextResourceDecoder::create(ASCIILiteral("text/plain"), "UTF-8")->decodeAndFlush(m_data->data(), m_data->size()): String());
     m_data = nullptr;
index beed606..57cb3bd 100644 (file)
@@ -173,7 +173,7 @@ inline void DeferredWrapper::resolve<Vector<unsigned char>>(const Vector<unsigne
     ASSERT(m_globalObject);
     JSC::ExecState* exec = m_globalObject->globalExec();
     JSC::JSLockHolder locker(exec);
-    RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(result.data(), result.size());
+    auto buffer = ArrayBuffer::tryCreate(result.data(), result.size());
     resolve(*exec, toJS(exec, m_globalObject.get(), buffer.get()));
 }
 
index de4084f..6abc86c 100644 (file)
@@ -102,7 +102,7 @@ MessageEvent::MessageEvent(PassRefPtr<Blob> data, const String& origin)
 {
 }
 
-MessageEvent::MessageEvent(RefPtr<ArrayBuffer>&& data, const String& origin)
+MessageEvent::MessageEvent(Ref<ArrayBuffer>&& data, const String& origin)
     : Event(eventNames().messageEvent, false, false)
     , m_dataType(DataTypeArrayBuffer)
     , m_dataAsArrayBuffer(WTFMove(data))
index c888148..068cb8e 100644 (file)
@@ -71,7 +71,7 @@ public:
     {
         return adoptRef(*new MessageEvent(data, origin));
     }
-    static Ref<MessageEvent> create(RefPtr<ArrayBuffer>&& data, const String& origin = String())
+    static Ref<MessageEvent> create(Ref<ArrayBuffer>&& data, const String& origin = String())
     {
         return adoptRef(*new MessageEvent(WTFMove(data), origin));
     }
@@ -127,7 +127,7 @@ private:
 
     explicit MessageEvent(const String& data, const String& origin);
     explicit MessageEvent(PassRefPtr<Blob> data, const String& origin);
-    explicit MessageEvent(RefPtr<ArrayBuffer>&& data, const String& origin);
+    explicit MessageEvent(Ref<ArrayBuffer>&& data, const String& origin);
 
     DataType m_dataType;
     Deprecated::ScriptValue m_dataAsScriptValue;
index a80a2ab..47caab1 100644 (file)
@@ -157,7 +157,7 @@ void FileReaderLoader::didReceiveResponse(unsigned long, const ResourceResponse&
     }
 
     ASSERT(!m_rawData);
-    m_rawData = ArrayBuffer::create(static_cast<unsigned>(length), 1);
+    m_rawData = ArrayBuffer::tryCreate(static_cast<unsigned>(length), 1);
 
     if (!m_rawData) {
         failed(FileError::NOT_READABLE_ERR);
@@ -194,7 +194,7 @@ void FileReaderLoader::didReceiveData(const char* data, int dataLength)
                 return;
             }
             newLength = std::max(newLength, m_totalBytes + m_totalBytes / 4 + 1);
-            RefPtr<ArrayBuffer> newData = ArrayBuffer::create(newLength, 1);
+            auto newData = ArrayBuffer::tryCreate(newLength, 1);
             if (!newData) {
                 // Not enough memory.
                 failed(FileError::NOT_READABLE_ERR);
@@ -277,7 +277,7 @@ RefPtr<ArrayBuffer> FileReaderLoader::arrayBufferResult() const
         return m_rawData;
 
     // Otherwise, return a copy.
-    return ArrayBuffer::create(m_rawData.get());
+    return ArrayBuffer::create(*m_rawData);
 }
 
 String FileReaderLoader::stringResult()
index e5b0867..6bd23ce 100644 (file)
@@ -69,7 +69,7 @@ bool WebGLBuffer::associateBufferDataImpl(const void* data, GC3Dsizeiptr byteLen
         m_byteLength = byteLength;
         clearCachedMaxIndices();
         if (byteLength) {
-            m_elementArrayBuffer = ArrayBuffer::create(byteLength, 1);
+            m_elementArrayBuffer = ArrayBuffer::tryCreate(byteLength, 1);
             if (!m_elementArrayBuffer) {
                 m_byteLength = 0;
                 return false;
index 10be29f..39a78ad 100644 (file)
@@ -50,10 +50,10 @@ DataCue::DataCue(ScriptExecutionContext& context, const MediaTime& start, const
 }
 
 #if ENABLE(DATACUE_VALUE)
-DataCue::DataCue(ScriptExecutionContext& context, const MediaTime& start, const MediaTime& end, PassRefPtr<SerializedPlatformRepresentation> platformValue, const String& type)
+DataCue::DataCue(ScriptExecutionContext& context, const MediaTime& start, const MediaTime& end, RefPtr<SerializedPlatformRepresentation>&& platformValue, const String& type)
     : TextTrackCue(context, start, end)
     , m_type(type)
-    , m_platformValue(platformValue)
+    , m_platformValue(WTFMove(platformValue))
 {
 }
 
@@ -75,7 +75,7 @@ DataCue::~DataCue()
 #endif
 }
 
-PassRefPtr<ArrayBuffer> DataCue::data() const
+RefPtr<ArrayBuffer> DataCue::data() const
 {
 #if ENABLE(DATACUE_VALUE)
     if (m_platformValue)
@@ -85,7 +85,7 @@ PassRefPtr<ArrayBuffer> DataCue::data() const
     if (!m_data)
         return nullptr;
 
-    return ArrayBuffer::create(m_data.get());
+    return ArrayBuffer::create(*m_data);
 }
 
 void DataCue::setData(ArrayBuffer* data, ExceptionCode& ec)
@@ -102,7 +102,7 @@ void DataCue::setData(ArrayBuffer* data, ExceptionCode& ec)
     m_value = JSC::JSValue();
 #endif
 
-    m_data = ArrayBuffer::create(data);
+    m_data = ArrayBuffer::create(*data);
 }
 
 DataCue* toDataCue(TextTrackCue* cue)
@@ -132,10 +132,10 @@ bool DataCue::cueContentsMatch(const TextTrackCue& cue) const
         return false;
 
 #if ENABLE(DATACUE_VALUE)
-    RefPtr<SerializedPlatformRepresentation> otherPlatformValue = dataCue->platformValue();
+    const SerializedPlatformRepresentation* otherPlatformValue = dataCue->platformValue();
     if ((otherPlatformValue && !m_platformValue) || (!otherPlatformValue && m_platformValue))
         return false;
-    if (m_platformValue && !m_platformValue->isEqual(*otherPlatformValue.get()))
+    if (m_platformValue && !m_platformValue->isEqual(*otherPlatformValue))
         return false;
 
     JSC::JSValue thisValue = value(nullptr);
index 200794d..d71fb81 100644 (file)
@@ -61,9 +61,9 @@ public:
     }
 
 #if ENABLE(DATACUE_VALUE)
-    static Ref<DataCue> create(ScriptExecutionContext& context, const MediaTime& start, const MediaTime& end, PassRefPtr<SerializedPlatformRepresentation> platformValue, const String& type)
+    static Ref<DataCue> create(ScriptExecutionContext& context, const MediaTime& start, const MediaTime& end, RefPtr<SerializedPlatformRepresentation>&& platformValue, const String& type)
     {
-        return adoptRef(*new DataCue(context, start, end, platformValue, type));
+        return adoptRef(*new DataCue(context, start, end, WTFMove(platformValue), type));
     }
 
     static Ref<DataCue> create(ScriptExecutionContext& context, const MediaTime& start, const MediaTime& end, JSC::JSValue value, const String& type)
@@ -75,11 +75,11 @@ public:
     virtual ~DataCue();
     CueType cueType() const override { return Data; }
 
-    PassRefPtr<ArrayBuffer> data() const;
+    RefPtr<ArrayBuffer> data() const;
     void setData(ArrayBuffer*, ExceptionCode&);
 
 #if ENABLE(DATACUE_VALUE)
-    const PassRefPtr<SerializedPlatformRepresentation> platformValue() const { return m_platformValue; }
+    const SerializedPlatformRepresentation* platformValue() const { return m_platformValue.get(); }
 
     JSC::JSValue value(JSC::ExecState*) const;
     void setValue(JSC::ExecState*, JSC::JSValue);
@@ -96,7 +96,7 @@ protected:
     DataCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, ArrayBuffer*, const String&, ExceptionCode&);
     DataCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, const void*, unsigned);
 #if ENABLE(DATACUE_VALUE)
-    DataCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, PassRefPtr<SerializedPlatformRepresentation>, const String&);
+    DataCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, RefPtr<SerializedPlatformRepresentation>&&, const String&);
     DataCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, JSC::JSValue, const String&);
 #endif
 
index 95c0302..13acad1 100644 (file)
@@ -65,18 +65,18 @@ void InbandDataTextTrack::addDataCue(InbandTextTrackPrivate*, const MediaTime& s
     if (m_incompleteCueMap.find(platformValue.get()) != m_incompleteCueMap.end())
         return;
 
-    RefPtr<DataCue> cue = DataCue::create(*scriptExecutionContext(), start, end, platformValue, type);
-    if (hasCue(cue.get(), TextTrackCue::IgnoreDuration)) {
+    auto cue = DataCue::create(*scriptExecutionContext(), start, end, platformValue.copyRef(), type);
+    if (hasCue(cue.ptr(), TextTrackCue::IgnoreDuration)) {
         LOG(Media, "InbandDataTextTrack::addDataCue ignoring already added cue: start=%s, end=%s\n", toString(cue->startTime()).utf8().data(), toString(cue->endTime()).utf8().data());
         return;
     }
 
     if (end.isPositiveInfinite() && mediaElement()) {
         cue->setEndTime(mediaElement()->durationMediaTime());
-        m_incompleteCueMap.add(platformValue, cue);
+        m_incompleteCueMap.add(WTFMove(platformValue), cue.copyRef());
     }
 
-    addCue(cue.release(), ASSERT_NO_EXCEPTION);
+    addCue(WTFMove(cue), ASSERT_NO_EXCEPTION);
 }
 
 void InbandDataTextTrack::updateDataCue(InbandTextTrackPrivate*, const MediaTime& start, const MediaTime& inEnd, PassRefPtr<SerializedPlatformRepresentation> prpPlatformValue)
@@ -125,10 +125,10 @@ void InbandDataTextTrack::removeCue(TextTrackCue* cue, ExceptionCode& ec)
 {
     ASSERT(cue->cueType() == TextTrackCue::Data);
 
-    RefPtr<SerializedPlatformRepresentation> platformValue = toDataCue(cue)->platformValue().get();
-    auto iter = m_incompleteCueMap.find(platformValue.get());
+    SerializedPlatformRepresentation* platformValue = const_cast<SerializedPlatformRepresentation*>(toDataCue(cue)->platformValue());
+    auto iter = m_incompleteCueMap.find(platformValue);
     if (iter != m_incompleteCueMap.end())
-        m_incompleteCueMap.remove(platformValue.get());
+        m_incompleteCueMap.remove(platformValue);
 
     InbandTextTrack::removeCue(cue, ec);
 }
index a6f6961..69ad417 100644 (file)
@@ -144,7 +144,7 @@ static JSValue *jsValueWithValueInContext(id value, JSContext *context)
 
 static JSValue *jsValueWithDataInContext(NSData *data, JSContext *context)
 {
-    RefPtr<ArrayBuffer> dataArray = ArrayBuffer::create([data bytes], [data length]);
+    auto dataArray = ArrayBuffer::tryCreate([data bytes], [data length]);
 
     JSC::ExecState* exec = toJS([context JSGlobalContextRef]);
     JSC::JSValue array = toJS(exec, JSC::jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), dataArray.get());