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

Unified Diff: Source/bindings/core/dart/V8Converter.cpp

Issue 1724593002: Fix broken code passing typed data from Dart to V8. Attempted to match patterns in SerializeScriptV… (Closed) Base URL: https://chromium.googlesource.com/dart/dartium/blink.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « Source/bindings/core/dart/DartJsInterop.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/dart/V8Converter.cpp
diff --git a/Source/bindings/core/dart/V8Converter.cpp b/Source/bindings/core/dart/V8Converter.cpp
index 2200818f5c2df1a4bcfa81b3279b17e9d4bfa88c..d51ac57880bfc01be1a7712469bfcc821b746b16 100644
--- a/Source/bindings/core/dart/V8Converter.cpp
+++ b/Source/bindings/core/dart/V8Converter.cpp
@@ -513,7 +513,10 @@ Dart_Handle V8Converter::mapToDart(v8::Handle<v8::Object> object, V8ToDartMap& m
v8::Handle<v8::Value> V8Converter::arrayBufferToV8(Dart_Handle value, Dart_Handle& exception)
{
ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate();
- return blink::toV8(DartUtilities::dartToExternalizedArrayBuffer(value, exception).get(), state->context()->Global(), state->isolate());
+ RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(DartUtilities::dartToExternalizedArrayBuffer(value, exception));
+ v8::Handle<v8::Object> global = state->context()->Global();
+ v8::Isolate* v8Isolate = state->isolate();
+ return blink::toV8(arrayBuffer.get(), global, v8Isolate);
}
Dart_Handle V8Converter::arrayBufferToDart(v8::Handle<v8::Object> object, Dart_Handle& exception)
@@ -525,31 +528,71 @@ v8::Handle<v8::Value> V8Converter::arrayBufferViewToV8(Dart_Handle value, Dart_H
{
RefPtr<ArrayBufferView> view = DartUtilities::dartToExternalizedArrayBufferView(value, exception);
ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate();
+ unsigned byteOffset = view->byteOffset();
+ // this is copied from ScriptValueSerializer.
+ int elementByteSize = 1;
+ ArrayBuffer* data = view->buffer().get();
switch (view->type()) {
case ArrayBufferView::TypeInt8:
- return blink::toV8(static_cast<Int8Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMInt8Array::ValueType);
+ break;
case ArrayBufferView::TypeUint8:
- return blink::toV8(static_cast<Uint8Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMUint8Array::ValueType);
+ break;
case ArrayBufferView::TypeUint8Clamped:
- return blink::toV8(static_cast<Uint8ClampedArray*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMUint8ClampedArray::ValueType);
+ break;
case ArrayBufferView::TypeInt16:
- return blink::toV8(static_cast<Int16Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMInt16Array::ValueType);
+ break;
case ArrayBufferView::TypeUint16:
- return blink::toV8(static_cast<Uint16Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMUint16Array::ValueType);
+ break;
case ArrayBufferView::TypeInt32:
- return blink::toV8(static_cast<Int32Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMInt32Array::ValueType);
+ break;
case ArrayBufferView::TypeUint32:
- return blink::toV8(static_cast<Uint32Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMUint32Array::ValueType);
+ break;
case ArrayBufferView::TypeFloat32:
- return blink::toV8(static_cast<Float32Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMFloat32Array::ValueType);
+ break;
case ArrayBufferView::TypeFloat64:
- return blink::toV8(static_cast<Float64Array*>(view.get()), state->context()->Global(), state->isolate());
+ elementByteSize = sizeof(DOMFloat64Array::ValueType);
+ break;
+ case ArrayBufferView::TypeDataView:
+ elementByteSize = sizeof(DOMDataView::ValueType);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ unsigned numElements = view->byteLength() / elementByteSize;
+
+ switch (view->type()) {
+ case ArrayBufferView::TypeInt8:
+ return blink::toV8(DOMInt8Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeUint8:
+ return blink::toV8(DOMUint8Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeUint8Clamped:
+ return blink::toV8(DOMUint8ClampedArray::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeInt16:
+ return blink::toV8(DOMInt16Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeUint16:
+ return blink::toV8(DOMUint16Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeInt32:
+ return blink::toV8(DOMInt32Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeUint32:
+ return blink::toV8(DOMUint32Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeFloat32:
+ return blink::toV8(DOMFloat32Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
+ case ArrayBufferView::TypeFloat64:
+ return blink::toV8(DOMFloat64Array::create(data, byteOffset, numElements), state->context()->Global(), state->isolate());
case ArrayBufferView::TypeDataView:
{
+ RefPtr<DOMArrayBufferView> domArrayBuffView = adoptRef(new DOMArrayBufferView(view.get()));
// TODO(terry): Had to move protected constructor to public in
// core/dom/DOMArrayBufferView.h
- RefPtr<DOMArrayBufferView> domArrayBuffView = new DOMArrayBufferView(view.get());
return blink::toV8(DOMDataView::create(domArrayBuffView->bufferBase(),
domArrayBuffView->byteOffset(),
domArrayBuffView->byteLength()),
« no previous file with comments | « Source/bindings/core/dart/DartJsInterop.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698