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

Unified Diff: third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp

Issue 2414333003: WebMessaging: Send transferable ArrayBuffers by copy-and-neuter semantics (Closed)
Patch Set: remake Created 4 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: third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp
diff --git a/third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp b/third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp
index a1ac418547a4cff6bd0e2e372237eaf1386184b3..2c72c353341f2e15d6847539947d82c69574f066 100644
--- a/third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp
+++ b/third_party/WebKit/Source/bindings/tests/results/core/V8TestObject.cpp
@@ -67,6 +67,7 @@
#include "bindings/core/v8/VoidCallbackFunction.h"
#include "core/HTMLNames.h"
#include "core/dom/ClassCollection.h"
+#include "core/dom/DOMArrayBufferBase.h"
#include "core/dom/Document.h"
#include "core/dom/FlexibleArrayBufferView.h"
#include "core/dom/TagCollection.h"
@@ -11540,6 +11541,7 @@ static void postMessageImpl(const char* interfaceName, TestObject* instance, con
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
return;
}
+
Transferables transferables;
if (info.Length() > 1) {
const int transferablesArgIndex = 1;
@@ -11547,9 +11549,33 @@ static void postMessageImpl(const char* interfaceName, TestObject* instance, con
return;
}
}
- RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
- if (exceptionState.hadException())
- return;
+
+ RefPtr<SerializedScriptValue> message;
+ if (instance->canTransferArrayBuffer()) {
+ // This instance supports sending array buffers by move semantics.
+ message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ } else {
+ // This instance doesn't support sending array buffers by move
+ // semantics. Emulate it by copy-and-neuter semantics that sends array
+ // buffers by copy semantics and then neuters the original array
haraken 2016/10/19 09:49:28 Just to confirm: Your intention is to NOT copy the
nhiroki 2016/10/19 12:51:53 No. My intention is to copy-transfer the array buf
haraken 2016/10/19 15:40:46 I'm a bit confused. You're ignoring the return va
nhiroki 2016/10/20 07:44:02 SerializedScriptValue::serialize() copies the arra
+ // buffers.
+
+ // Clear transferable array buffers so that the serializer can handle
+ // them by copy semantics.
+ ArrayBufferArray transferableArrayBuffers = transferables.arrayBuffers;
+ transferables.arrayBuffers.clear();
+ message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
+ if (exceptionState.hadException())
+ return;
+
+ // Neuter the original array buffers on the sender context.
+ SerializedScriptValue::transferArrayBufferContents(info.GetIsolate(), transferableArrayBuffers, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ }
+
// FIXME: Only pass context/exceptionState if instance really requires it.
ExecutionContext* context = currentExecutionContext(info.GetIsolate());
instance->postMessage(context, message.release(), transferables.messagePorts, exceptionState);

Powered by Google App Engine
This is Rietveld 408576698