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

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

Issue 718383003: bindings: fixed incorrect dependency of SerializedScriptValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added fast/js/structured-clone.html 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/SerializedScriptValueForModulesFactory.cpp
diff --git a/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp b/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..afcd4b609fd5785d74b5194b08041324b9a7cec6
--- /dev/null
+++ b/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp
@@ -0,0 +1,78 @@
+// 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/SerializedScriptValueForModulesFactory.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/SerializedScriptValue.h"
+#include "bindings/modules/v8/ScriptValueSerializerForModules.h"
+#include "core/dom/ExceptionCode.h"
+
+namespace blink {
+
+PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8::Isolate* isolate)
+{
+ RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory::create();
+ SerializedScriptValueWriterForModules writer;
+ ScriptValueSerializer::Status status;
+ String errorMessage;
+ {
+ v8::TryCatch tryCatch;
+ status = SerializedScriptValueFactory::doSerialize(value, writer, messagePorts, arrayBuffers, blobInfo, serializedValue.get(), tryCatch, errorMessage, isolate);
+ if (status == ScriptValueSerializer::JSException) {
+ // If there was a JS exception thrown, re-throw it.
+ exceptionState.rethrowV8Exception(tryCatch.Exception());
+ return serializedValue.release();
+ }
+ }
+ switch (status) {
+ case ScriptValueSerializer::InputError:
+ case ScriptValueSerializer::DataCloneError:
+ exceptionState.throwDOMException(DataCloneError, errorMessage);
+ return serializedValue.release();
+ case ScriptValueSerializer::Success:
+ transferData(serializedValue.get(), writer, arrayBuffers, exceptionState, isolate);
+ return serializedValue.release();
+ case ScriptValueSerializer::JSException:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ ASSERT_NOT_REACHED();
+ return serializedValue.release();
+}
+
+PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create(const String& data, v8::Isolate* isolate)
+{
+ SerializedScriptValueWriterForModules writer;
+ writer.writeWebCoreString(data);
+ String wireData = writer.takeWireString();
+ return createFromWire(wireData);
+}
+
+ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerialize(v8::Handle<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessage, v8::Isolate* isolate)
+{
+ ScriptValueSerializerForModules serializer(writer, messagePorts, arrayBuffers, blobInfo, blobDataHandles, tryCatch, ScriptState::current(isolate));
+ ScriptValueSerializer::Status status = serializer.serialize(value);
+ errorMessage = serializer.errorMessage();
+ return status;
+}
+
+v8::Handle<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String& data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBufferContentsArray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo)
+{
+ if (!data.impl())
+ return v8::Null(isolate);
+ COMPILE_ASSERT(sizeof(SerializedScriptValueWriter::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.
+ SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState::current(isolate));
+ ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBufferContentsArray);
+ return deserializer.deserialize();
+}
+
+} // namespace blink
+
« no previous file with comments | « Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.h ('k') | Source/bindings/modules/v8/v8.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698