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

Side by Side Diff: Source/bindings/core/v8/SerializedScriptValueFactory.cpp

Issue 1111163003: Replace v8::Handle<> with v8::Local<> in bindings/core/v8/* (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/SerializedScriptValueFactory.h" 6 #include "bindings/core/v8/SerializedScriptValueFactory.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptValueSerializer.h" 9 #include "bindings/core/v8/ScriptValueSerializer.h"
10 #include "wtf/ByteOrder.h" 10 #include "wtf/ByteOrder.h"
11 #include "wtf/text/StringBuffer.h" 11 #include "wtf/text/StringBuffer.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 SerializedScriptValueFactory* SerializedScriptValueFactory::m_instance = 0; 15 SerializedScriptValueFactory* SerializedScriptValueFactory::m_instance = 0;
16 16
17 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Handl e<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffe rs, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8::Isolate* iso late) 17 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Local <v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffer s, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8::Isolate* isol ate)
18 { 18 {
19 RefPtr<SerializedScriptValue> serializedValue = create(); 19 RefPtr<SerializedScriptValue> serializedValue = create();
20 SerializedScriptValueWriter writer; 20 SerializedScriptValueWriter writer;
21 ScriptValueSerializer::Status status; 21 ScriptValueSerializer::Status status;
22 String errorMessage; 22 String errorMessage;
23 { 23 {
24 v8::TryCatch tryCatch; 24 v8::TryCatch tryCatch;
25 status = doSerialize(value, writer, messagePorts, arrayBuffers, blobInfo , serializedValue.get(), tryCatch, errorMessage, isolate); 25 status = doSerialize(value, writer, messagePorts, arrayBuffers, blobInfo , serializedValue.get(), tryCatch, errorMessage, isolate);
26 if (status == ScriptValueSerializer::JSException) { 26 if (status == ScriptValueSerializer::JSException) {
27 // If there was a JS exception thrown, re-throw it. 27 // If there was a JS exception thrown, re-throw it.
(...skipping 10 matching lines...) Expand all
38 transferData(serializedValue.get(), writer, arrayBuffers, exceptionState , isolate); 38 transferData(serializedValue.get(), writer, arrayBuffers, exceptionState , isolate);
39 return serializedValue.release(); 39 return serializedValue.release();
40 case ScriptValueSerializer::JSException: 40 case ScriptValueSerializer::JSException:
41 ASSERT_NOT_REACHED(); 41 ASSERT_NOT_REACHED();
42 break; 42 break;
43 } 43 }
44 ASSERT_NOT_REACHED(); 44 ASSERT_NOT_REACHED();
45 return serializedValue.release(); 45 return serializedValue.release();
46 } 46 }
47 47
48 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Handl e<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffe rs, ExceptionState& exceptionState, v8::Isolate* isolate) 48 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Local <v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffer s, ExceptionState& exceptionState, v8::Isolate* isolate)
49 { 49 {
50 return create(value, messagePorts, arrayBuffers, 0, exceptionState, isolate) ; 50 return create(value, messagePorts, arrayBuffers, 0, exceptionState, isolate) ;
51 } 51 }
52 52
53 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::createAndSwallow Exceptions(v8::Isolate* isolate, v8::Handle<v8::Value> value) 53 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::createAndSwallow Exceptions(v8::Isolate* isolate, v8::Local<v8::Value> value)
54 { 54 {
55 TrackExceptionState exceptionState; 55 TrackExceptionState exceptionState;
56 return create(value, 0, 0, exceptionState, isolate); 56 return create(value, 0, 0, exceptionState, isolate);
57 } 57 }
58 58
59 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(const Scr iptValue& value, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8: :Isolate* isolate) 59 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(const Scr iptValue& value, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8: :Isolate* isolate)
60 { 60 {
61 ASSERT(isolate->InContext()); 61 ASSERT(isolate->InContext());
62 return create(value.v8Value(), 0, 0, blobInfo, exceptionState, isolate); 62 return create(value.v8Value(), 0, 0, blobInfo, exceptionState, isolate);
63 } 63 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 void SerializedScriptValueFactory::transferData(SerializedScriptValue* serialize dValue, SerializedScriptValueWriter& writer, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate) 103 void SerializedScriptValueFactory::transferData(SerializedScriptValue* serialize dValue, SerializedScriptValueWriter& writer, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate)
104 { 104 {
105 serializedValue->setData(writer.takeWireString()); 105 serializedValue->setData(writer.takeWireString());
106 ASSERT(serializedValue->data().impl()->hasOneRef()); 106 ASSERT(serializedValue->data().impl()->hasOneRef());
107 if (!arrayBuffers || !arrayBuffers->size()) 107 if (!arrayBuffers || !arrayBuffers->size())
108 return; 108 return;
109 serializedValue->transferArrayBuffers(isolate, *arrayBuffers, exceptionState ); 109 serializedValue->transferArrayBuffers(isolate, *arrayBuffers, exceptionState );
110 } 110 }
111 111
112 ScriptValueSerializer::Status SerializedScriptValueFactory::doSerialize(v8::Hand le<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortArray* mess agePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, Serialized ScriptValue* serializedValue, v8::TryCatch& tryCatch, String& errorMessage, v8:: Isolate* isolate) 112 ScriptValueSerializer::Status SerializedScriptValueFactory::doSerialize(v8::Loca l<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortArray* messa gePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, SerializedS criptValue* serializedValue, v8::TryCatch& tryCatch, String& errorMessage, v8::I solate* isolate)
113 { 113 {
114 return doSerialize(value, writer, messagePorts, arrayBuffers, blobInfo, seri alizedValue->blobDataHandles(), tryCatch, errorMessage, isolate); 114 return doSerialize(value, writer, messagePorts, arrayBuffers, blobInfo, seri alizedValue->blobDataHandles(), tryCatch, errorMessage, isolate);
115 } 115 }
116 116
117 ScriptValueSerializer::Status SerializedScriptValueFactory::doSerialize(v8::Hand le<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortArray* mess agePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, BlobDataHa ndleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessage, v8::Isol ate* isolate) 117 ScriptValueSerializer::Status SerializedScriptValueFactory::doSerialize(v8::Loca l<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortArray* messa gePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, BlobDataHan dleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessage, v8::Isola te* isolate)
118 { 118 {
119 ScriptValueSerializer serializer(writer, messagePorts, arrayBuffers, blobInf o, blobDataHandles, tryCatch, ScriptState::current(isolate)); 119 ScriptValueSerializer serializer(writer, messagePorts, arrayBuffers, blobInf o, blobDataHandles, tryCatch, ScriptState::current(isolate));
120 ScriptValueSerializer::Status status = serializer.serialize(value); 120 ScriptValueSerializer::Status status = serializer.serialize(value);
121 errorMessage = serializer.errorMessage(); 121 errorMessage = serializer.errorMessage();
122 return status; 122 return status;
123 } 123 }
124 124
125 v8::Handle<v8::Value> SerializedScriptValueFactory::deserialize(SerializedScript Value* value, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlo bInfoArray* blobInfo) 125 v8::Local<v8::Value> SerializedScriptValueFactory::deserialize(SerializedScriptV alue* value, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlob InfoArray* blobInfo)
126 { 126 {
127 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. 127 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed.
128 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. 128 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation.
129 RefPtr<SerializedScriptValue> protect(value); 129 RefPtr<SerializedScriptValue> protect(value);
130 return deserialize(value->data(), value->blobDataHandles(), value->arrayBuff erContentsArray(), isolate, messagePorts, blobInfo); 130 return deserialize(value->data(), value->blobDataHandles(), value->arrayBuff erContentsArray(), isolate, messagePorts, blobInfo);
131 } 131 }
132 132
133 v8::Handle<v8::Value> SerializedScriptValueFactory::deserialize(String& data, Bl obDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBufferContentsA rray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArr ay* blobInfo) 133 v8::Local<v8::Value> SerializedScriptValueFactory::deserialize(String& data, Blo bDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBufferContentsAr ray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArra y* blobInfo)
134 { 134 {
135 if (!data.impl()) 135 if (!data.impl())
136 return v8::Null(isolate); 136 return v8::Null(isolate);
137 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes"); 137 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes");
138 data.ensure16Bit(); 138 data.ensure16Bit();
139 // FIXME: SerializedScriptValue shouldn't use String for its underlying 139 // FIXME: SerializedScriptValue shouldn't use String for its underlying
140 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The 140 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
141 // information stored in m_data isn't even encoded in UTF-16. Instead, 141 // information stored in m_data isn't even encoded in UTF-16. Instead,
142 // unicode characters are encoded as UTF-8 with two code units per UChar. 142 // unicode characters are encoded as UTF-8 with two code units per UChar.
143 SerializedScriptValueReader reader(reinterpret_cast<const uint8_t*>(data.imp l()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState: :current(isolate)); 143 SerializedScriptValueReader reader(reinterpret_cast<const uint8_t*>(data.imp l()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState: :current(isolate));
144 ScriptValueDeserializer deserializer(reader, messagePorts, arrayBufferConten tsArray); 144 ScriptValueDeserializer deserializer(reader, messagePorts, arrayBufferConten tsArray);
145 145
146 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. 146 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed.
147 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. 147 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation.
148 return deserializer.deserialize(); 148 return deserializer.deserialize();
149 } 149 }
150 150
151 151
152 } // namespace blink 152 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/SerializedScriptValueFactory.h ('k') | Source/bindings/core/v8/SerializedScriptValueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698