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

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

Issue 2011553008: [Binding] [Refactoring] Move some create() from SerializedScriptValueFactory to SerializedScriptValu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/SerializedScriptValue.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp
index 9af8a7808228d9e8c3bcbba3452c4e762254b06b..f7e7ac52ddc031401e8f6d57145306db43ea3679 100644
--- a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp
@@ -58,11 +58,44 @@
namespace blink {
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create()
+{
+ return adoptRef(new SerializedScriptValue);
+}
+
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const String& data)
+{
+ return adoptRef(new SerializedScriptValue(data));
+}
+
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const char* data, size_t length)
+{
+ if (!data)
+ return create();
+
+ // Decode wire data from big endian to host byte order.
+ DCHECK(!(length % sizeof(UChar)));
+ size_t stringLength = length / sizeof(UChar);
+ StringBuffer<UChar> buffer(stringLength);
+ const UChar* src = reinterpret_cast<const UChar*>(data);
+ UChar* dst = buffer.characters();
+ for (size_t i = 0; i < stringLength; i++)
+ dst[i] = ntohs(src[i]);
+
+ return adoptRef(new SerializedScriptValue(String::adopt(buffer)));
+}
+
SerializedScriptValue::SerializedScriptValue()
: m_externallyAllocatedMemory(0)
{
}
+SerializedScriptValue::SerializedScriptValue(const String& wireData)
+ : m_data(wireData.isolatedCopy())
+ , m_externallyAllocatedMemory(0)
+{
+}
+
SerializedScriptValue::~SerializedScriptValue()
{
// If the allocated memory was not registered before, then this class is likely
@@ -215,12 +248,6 @@ void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, const Arr
m_arrayBufferContentsArray = std::move(contents);
}
-SerializedScriptValue::SerializedScriptValue(const String& wireData)
- : m_externallyAllocatedMemory(0)
-{
- m_data = wireData.isolatedCopy();
-}
-
v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messagePorts)
{
return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0);

Powered by Google App Engine
This is Rietveld 408576698