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

Unified Diff: Source/bindings/modules/v8/SerializedScriptValueForModules.cpp

Issue 718383003: bindings: fixed incorrect dependency of SerializedScriptValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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/modules/v8/SerializedScriptValueForModules.cpp
diff --git a/Source/bindings/modules/v8/SerializedScriptValueForModules.cpp b/Source/bindings/modules/v8/SerializedScriptValueForModules.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f2a147eeab1341f17f312fe14f305405f8ac3f46
--- /dev/null
+++ b/Source/bindings/modules/v8/SerializedScriptValueForModules.cpp
@@ -0,0 +1,71 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "bindings/modules/v8/SerializedScriptValueForModules.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/modules/v8/ScriptValueSerializerForModules.h"
+#include "core/dom/ExceptionCode.h"
+#include "wtf/Assertions.h"
+#include "wtf/ByteOrder.h"
+#include "wtf/text/StringBuffer.h"
+
+namespace blink {
+
+SerializedScriptValueForModules::SerializedScriptValueForModules(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8::Isolate* isolate)
+ : SerializedScriptValue()
+{
+ SerializedScriptValueInternal::WriterForModules writer;
+ SerializedScriptValueInternal::Serializer::Status status;
+ String errorMessage;
+ {
+ v8::TryCatch tryCatch;
+ SerializedScriptValueInternal::SerializerForModules serializer(writer, messagePorts, arrayBuffers, blobInfo, blobDataHandles(), tryCatch, ScriptState::current(isolate));
+ status = serializer.serialize(value);
+ if (status == SerializedScriptValueInternal::Serializer::JSException) {
+ // If there was a JS exception thrown, re-throw it.
+ exceptionState.rethrowV8Exception(tryCatch.Exception());
+ return;
+ }
+ errorMessage = serializer.errorMessage();
+ }
+ switch (status) {
+ case SerializedScriptValueInternal::Serializer::InputError:
+ case SerializedScriptValueInternal::Serializer::DataCloneError:
+ exceptionState.throwDOMException(DataCloneError, errorMessage);
+ return;
+ case SerializedScriptValueInternal::Serializer::Success:
+ setData(writer.takeWireString());
+ ASSERT(data().impl()->hasOneRef());
+ if (arrayBuffers && arrayBuffers->size())
+ transferArrayBuffers(isolate, *arrayBuffers, exceptionState);
+ return;
+ case SerializedScriptValueInternal::Serializer::JSException:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ ASSERT_NOT_REACHED();
+}
+
+v8::Handle<v8::Value> SerializedScriptValueForModules::deserialize(v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo)
+{
+ if (!data().impl())
+ return v8::Null(isolate);
+ COMPILE_ASSERT(sizeof(SerializedScriptValueInternal::Writer::BufferValueType) == 2, BufferValueTypeIsTwoBytes);
+ data().ensure16Bit();
+ // FIXME: SerializedScriptValue shouldn't use String for its underlying
+ // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
+ // information stored in m_data isn't even encoded in UTF-16. Instead,
+ // unicode characters are encoded as UTF-8 with two code units per UChar.
+ SerializedScriptValueInternal::ReaderForModules reader(reinterpret_cast<const uint8_t*>(data().impl()->characters16()), 2 * data().length(), blobInfo, blobDataHandles(), ScriptState::current(isolate));
+ SerializedScriptValueInternal::DeserializerForModules deserializer(reader, messagePorts, arrayBufferContentsArray());
+
+ // deserialize() can run arbitrary script (e.g., setters), which could result in |this| being destroyed.
+ // Holding a RefPtr ensures we are alive (along with our internal data) throughout the operation.
+ RefPtr<SerializedScriptValue> protect(this);
+ return deserializer.deserialize();
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698