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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp

Issue 1893983002: Simplify handling of Transferable objects while (de)serializing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove Transferable.cpp, not needed after all. Created 4 years, 8 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/core/v8/ScriptValueSerializer.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp
index 820174814339e6d76408f04fd0a0e4840f542d85..e34b2334a92ef8784f8cd4513f5a1e5cf8b24202 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.cpp
@@ -4,10 +4,7 @@
#include "bindings/core/v8/ScriptValueSerializer.h"
-#include "bindings/core/v8/Transferable.h"
-#include "bindings/core/v8/TransferableArrayBuffer.h"
-#include "bindings/core/v8/TransferableImageBitmap.h"
-#include "bindings/core/v8/TransferableMessagePort.h"
+#include "bindings/core/v8/Transferables.h"
#include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8ArrayBufferView.h"
#include "bindings/core/v8/V8Blob.h"
@@ -689,7 +686,7 @@ static bool isHostObject(v8::Local<v8::Object> object)
return object->InternalFieldCount();
}
-ScriptValueSerializer::ScriptValueSerializer(SerializedScriptValueWriter& writer, TransferableArray* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptState)
+ScriptValueSerializer::ScriptValueSerializer(SerializedScriptValueWriter& writer, const Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptState)
: m_scriptState(scriptState)
, m_writer(writer)
, m_tryCatch(tryCatch)
@@ -700,29 +697,36 @@ ScriptValueSerializer::ScriptValueSerializer(SerializedScriptValueWriter& writer
, m_blobDataHandles(blobDataHandles)
{
ASSERT(!tryCatch.HasCaught());
+ if (transferables)
+ copyTransferables(*transferables);
+}
+
+void ScriptValueSerializer::copyTransferables(const Transferables& transferables)
+{
v8::Local<v8::Object> creationContext = m_scriptState->context()->Global();
- if (!transferables)
- return;
- if (auto* messagePorts = TransferableMessagePort::get(*transferables)) {
- for (size_t i = 0; i < messagePorts->getArray().size(); i++) {
- v8::Local<v8::Object> v8MessagePort = toV8Object(messagePorts->getArray().at(i).get(), creationContext, isolate());
- m_transferredMessagePorts.set(v8MessagePort, i);
- }
+
+ // Also kept in separate ObjectPools, iterate and copy the contents
+ // of each kind of transferable vector.
+
+ const auto& messagePorts = transferables.messagePorts;
+ for (size_t i = 0; i < messagePorts.size(); ++i) {
+ v8::Local<v8::Object> v8MessagePort = toV8Object(messagePorts[i].get(), creationContext, isolate());
+ m_transferredMessagePorts.set(v8MessagePort, i);
}
- if (auto* arrayBuffers = TransferableArrayBuffer::get(*transferables)) {
- for (size_t i = 0; i < arrayBuffers->getArray().size(); i++) {
- v8::Local<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers->getArray().at(i).get(), creationContext, isolate());
- // Coalesce multiple occurences of the same buffer to the first index.
- if (!m_transferredArrayBuffers.contains(v8ArrayBuffer))
- m_transferredArrayBuffers.set(v8ArrayBuffer, i);
- }
+
+ const auto& arrayBuffers = transferables.arrayBuffers;
+ for (size_t i = 0; i < arrayBuffers.size(); ++i) {
+ v8::Local<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers[i].get(), creationContext, isolate());
+ // Coalesce multiple occurences of the same buffer to the first index.
+ if (!m_transferredArrayBuffers.contains(v8ArrayBuffer))
+ m_transferredArrayBuffers.set(v8ArrayBuffer, i);
}
- if (auto* imageBitmaps = TransferableImageBitmap::get(*transferables)) {
- for (size_t i = 0; i < imageBitmaps->getArray().size(); i++) {
- v8::Local<v8::Object> v8ImageBitmap = toV8Object(imageBitmaps->getArray().at(i).get(), creationContext, isolate());
- if (!m_transferredImageBitmaps.contains(v8ImageBitmap))
- m_transferredImageBitmaps.set(v8ImageBitmap, i);
- }
+
+ const auto& imageBitmaps = transferables.imageBitmaps;
+ for (size_t i = 0; i < imageBitmaps.size(); ++i) {
+ v8::Local<v8::Object> v8ImageBitmap = toV8Object(imageBitmaps[i].get(), creationContext, isolate());
+ if (!m_transferredImageBitmaps.contains(v8ImageBitmap))
+ m_transferredImageBitmaps.set(v8ImageBitmap, i);
}
}

Powered by Google App Engine
This is Rietveld 408576698