Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Unified Diff: Source/bindings/core/v8/SerializedScriptValue.cpp

Issue 606653006: bindings: Adds DOMArrayBuffer, etc. as thin wrappers for ArrayBuffer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/core/v8/SerializedScriptValue.cpp
diff --git a/Source/bindings/core/v8/SerializedScriptValue.cpp b/Source/bindings/core/v8/SerializedScriptValue.cpp
index 24e7542788835be74a556a489b17dc66a217f9fb..223e3875ff1f471f04a964bffb00418d12630f91 100644
--- a/Source/bindings/core/v8/SerializedScriptValue.cpp
+++ b/Source/bindings/core/v8/SerializedScriptValue.cpp
@@ -32,27 +32,28 @@
#include "bindings/core/v8/SerializedScriptValue.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/V8ArrayBuffer.h"
+#include "bindings/core/v8/V8ArrayBufferView.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8Blob.h"
+#include "bindings/core/v8/V8DataView.h"
#include "bindings/core/v8/V8File.h"
#include "bindings/core/v8/V8FileList.h"
+#include "bindings/core/v8/V8Float32Array.h"
+#include "bindings/core/v8/V8Float64Array.h"
#include "bindings/core/v8/V8ImageData.h"
+#include "bindings/core/v8/V8Int16Array.h"
+#include "bindings/core/v8/V8Int32Array.h"
+#include "bindings/core/v8/V8Int8Array.h"
#include "bindings/core/v8/V8MessagePort.h"
+#include "bindings/core/v8/V8Uint16Array.h"
+#include "bindings/core/v8/V8Uint32Array.h"
+#include "bindings/core/v8/V8Uint8Array.h"
+#include "bindings/core/v8/V8Uint8ClampedArray.h"
#include "bindings/core/v8/WorkerScriptController.h"
-#include "bindings/core/v8/custom/V8ArrayBufferCustom.h"
-#include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h"
-#include "bindings/core/v8/custom/V8DataViewCustom.h"
-#include "bindings/core/v8/custom/V8Float32ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Float64ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Int16ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Int32ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Int8ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Uint16ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Uint32ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Uint8ArrayCustom.h"
-#include "bindings/core/v8/custom/V8Uint8ClampedArrayCustom.h"
#include "bindings/modules/v8/V8CryptoKey.h"
#include "bindings/modules/v8/V8DOMFileSystem.h"
+#include "core/dom/DOMArrayBufferDeallocationObserver.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/MessagePort.h"
#include "core/fileapi/Blob.h"
@@ -911,7 +912,7 @@ static v8::Handle<v8::Object> toV8Object(MessagePort* impl, v8::Handle<v8::Objec
return wrapper.As<v8::Object>();
}
-static v8::Handle<v8::ArrayBuffer> toV8Object(ArrayBuffer* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+static v8::Handle<v8::ArrayBuffer> toV8Object(DOMArrayBuffer* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
if (!impl)
return v8::Handle<v8::ArrayBuffer>();
@@ -1373,7 +1374,7 @@ private:
StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object> object, StateBase* next)
{
ASSERT(!object.IsEmpty());
- ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object);
+ DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object);
if (!arrayBufferView)
return 0;
if (!arrayBufferView->buffer())
@@ -1384,7 +1385,7 @@ private:
StateBase* stateOut = doSerializeArrayBuffer(underlyingBuffer, next);
if (stateOut)
return stateOut;
- m_writer.writeArrayBufferView(*arrayBufferView);
+ m_writer.writeArrayBufferView(*arrayBufferView->view());
// This should be safe: we serialize something that we know to be a wrapper (see
// the toV8 call above), so the call to doSerializeArrayBuffer should neither
// cause the system stack to overflow nor should it have potential to reach
@@ -1401,19 +1402,19 @@ private:
StateBase* writeArrayBuffer(v8::Handle<v8::Value> value, StateBase* next)
{
- ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>());
+ DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>());
if (!arrayBuffer)
return 0;
if (arrayBuffer->isNeutered())
return handleError(DataCloneError, "An ArrayBuffer is neutered and could not be cloned.", next);
ASSERT(!m_transferredArrayBuffers.contains(value.As<v8::Object>()));
- m_writer.writeArrayBuffer(*arrayBuffer);
+ m_writer.writeArrayBuffer(*arrayBuffer->buffer());
return 0;
}
StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value> value, uint32_t index, StateBase* next)
{
- ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>());
+ DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(value.As<v8::Object>());
if (!arrayBuffer)
return 0;
if (arrayBuffer->isNeutered())
@@ -2035,7 +2036,7 @@ private:
return nullptr;
const void* bufferStart = m_buffer + m_position;
RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::create(bufferStart, byteLength);
- arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instanceTemplate());
+ arrayBuffer->setDeallocationObserver(DOMArrayBufferDeallocationObserver::instance());
haraken 2014/10/16 05:41:40 We always pass DOMArrayBufferDeallocationObserver:
Yuki 2014/10/16 14:21:50 I found that we can remove most of setDeallocation
m_position += byteLength;
return arrayBuffer.release();
}
@@ -2045,7 +2046,7 @@ private:
RefPtr<ArrayBuffer> arrayBuffer = doReadArrayBuffer();
if (!arrayBuffer)
return false;
- *value = toV8(arrayBuffer.release(), m_scriptState->context()->Global(), isolate());
+ *value = toV8(DOMArrayBuffer::create(arrayBuffer.release()), m_scriptState->context()->Global(), isolate());
return true;
}
@@ -2054,7 +2055,7 @@ private:
ArrayBufferViewSubTag subTag;
uint32_t byteOffset;
uint32_t byteLength;
- RefPtr<ArrayBuffer> arrayBuffer;
+ RefPtr<DOMArrayBuffer> arrayBuffer;
v8::Handle<v8::Value> arrayBufferV8Value;
if (!readArrayBufferViewSubTag(&subTag))
return false;
@@ -2073,58 +2074,58 @@ private:
v8::Handle<v8::Object> creationContext = m_scriptState->context()->Global();
switch (subTag) {
case ByteArrayTag:
- *value = toV8(Int8Array::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
+ *value = toV8(DOMInt8Array::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
break;
case UnsignedByteArrayTag:
- *value = toV8(Uint8Array::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
+ *value = toV8(DOMUint8Array::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
break;
case UnsignedByteClampedArrayTag:
- *value = toV8(Uint8ClampedArray::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
+ *value = toV8(DOMUint8ClampedArray::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
break;
case ShortArrayTag: {
uint32_t shortLength = byteLength / sizeof(int16_t);
if (shortLength * sizeof(int16_t) != byteLength)
return false;
- *value = toV8(Int16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate());
+ *value = toV8(DOMInt16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate());
break;
}
case UnsignedShortArrayTag: {
uint32_t shortLength = byteLength / sizeof(uint16_t);
if (shortLength * sizeof(uint16_t) != byteLength)
return false;
- *value = toV8(Uint16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate());
+ *value = toV8(DOMUint16Array::create(arrayBuffer.release(), byteOffset, shortLength), creationContext, isolate());
break;
}
case IntArrayTag: {
uint32_t intLength = byteLength / sizeof(int32_t);
if (intLength * sizeof(int32_t) != byteLength)
return false;
- *value = toV8(Int32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate());
+ *value = toV8(DOMInt32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate());
break;
}
case UnsignedIntArrayTag: {
uint32_t intLength = byteLength / sizeof(uint32_t);
if (intLength * sizeof(uint32_t) != byteLength)
return false;
- *value = toV8(Uint32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate());
+ *value = toV8(DOMUint32Array::create(arrayBuffer.release(), byteOffset, intLength), creationContext, isolate());
break;
}
case FloatArrayTag: {
uint32_t floatLength = byteLength / sizeof(float);
if (floatLength * sizeof(float) != byteLength)
return false;
- *value = toV8(Float32Array::create(arrayBuffer.release(), byteOffset, floatLength), creationContext, isolate());
+ *value = toV8(DOMFloat32Array::create(arrayBuffer.release(), byteOffset, floatLength), creationContext, isolate());
break;
}
case DoubleArrayTag: {
uint32_t floatLength = byteLength / sizeof(double);
if (floatLength * sizeof(double) != byteLength)
return false;
- *value = toV8(Float64Array::create(arrayBuffer.release(), byteOffset, floatLength), creationContext, isolate());
+ *value = toV8(DOMFloat64Array::create(arrayBuffer.release(), byteOffset, floatLength), creationContext, isolate());
break;
}
case DataViewTag:
- *value = toV8(DataView::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
+ *value = toV8(DOMDataView::create(arrayBuffer.release(), byteOffset, byteLength), creationContext, isolate());
break;
default:
return false;
@@ -2697,8 +2698,8 @@ public:
return false;
v8::Handle<v8::Object> result = m_arrayBuffers.at(index);
if (result.IsEmpty()) {
- RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_arrayBufferContents->at(index));
- buffer->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instanceTemplate());
+ RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(m_arrayBufferContents->at(index));
+ buffer->setDeallocationObserver(DOMArrayBufferDeallocationObserver::instance());
v8::Isolate* isolate = m_reader.scriptState()->isolate();
v8::Handle<v8::Object> creationContext = m_reader.scriptState()->context()->Global();
isolate->AdjustAmountOfExternalAllocatedMemory(buffer->byteLength());
@@ -2881,7 +2882,7 @@ SerializedScriptValue::SerializedScriptValue()
{
}
-static void neuterArrayBufferInAllWorlds(ArrayBuffer* object)
+static void neuterArrayBufferInAllWorlds(DOMArrayBuffer* object)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (isMainThread()) {
@@ -2916,7 +2917,7 @@ PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu
OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContentsArray(arrayBuffers.size()));
- HashSet<ArrayBuffer*> visited;
+ HashSet<DOMArrayBuffer*> visited;
for (size_t i = 0; i < arrayBuffers.size(); i++) {
if (visited.contains(arrayBuffers[i].get()))
continue;
@@ -3036,7 +3037,7 @@ bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int
}
ports.append(port.release());
} else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) {
- RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v8::Object>::Cast(transferrable));
+ RefPtr<DOMArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Handle<v8::Object>::Cast(transferrable));
if (arrayBuffers.contains(arrayBuffer)) {
exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer.");
return false;

Powered by Google App Engine
This is Rietveld 408576698