| OLD | NEW |
| 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 #ifndef ToV8_h | 5 #ifndef ToV8_h |
| 6 #define ToV8_h | 6 #define ToV8_h |
| 7 | 7 |
| 8 // ToV8() provides C++ -> V8 conversion. Note that ToV8() can return an empty | 8 // ToV8() provides C++ -> V8 conversion. Note that ToV8() can return an empty |
| 9 // handle. Call sites must check IsEmpty() before using return value. | 9 // handle. Call sites must check IsEmpty() before using return value. |
| 10 | 10 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (v8Value.IsEmpty()) | 253 if (v8Value.IsEmpty()) |
| 254 v8Value = v8::Undefined(isolate); | 254 v8Value = v8::Undefined(isolate); |
| 255 if (!v8CallBoolean(object->CreateDataProperty( | 255 if (!v8CallBoolean(object->CreateDataProperty( |
| 256 isolate->GetCurrentContext(), v8String(isolate, value[i].first), | 256 isolate->GetCurrentContext(), v8String(isolate, value[i].first), |
| 257 v8Value))) | 257 v8Value))) |
| 258 return v8::Local<v8::Value>(); | 258 return v8::Local<v8::Value>(); |
| 259 } | 259 } |
| 260 return object; | 260 return object; |
| 261 } | 261 } |
| 262 | 262 |
| 263 template <typename T> |
| 264 inline v8::Local<v8::Value> ToV8(const HeapVector<std::pair<String, T>>& value, |
| 265 v8::Local<v8::Object> creationContext, |
| 266 v8::Isolate* isolate) { |
| 267 v8::Local<v8::Object> object; |
| 268 { |
| 269 v8::Context::Scope contextScope(creationContext->CreationContext()); |
| 270 object = v8::Object::New(isolate); |
| 271 } |
| 272 for (unsigned i = 0; i < value.size(); ++i) { |
| 273 v8::Local<v8::Value> v8Value = ToV8(value[i].second, object, isolate); |
| 274 if (v8Value.IsEmpty()) |
| 275 v8Value = v8::Undefined(isolate); |
| 276 if (!v8CallBoolean(object->CreateDataProperty( |
| 277 isolate->GetCurrentContext(), v8String(isolate, value[i].first), |
| 278 v8Value))) |
| 279 return v8::Local<v8::Value>(); |
| 280 } |
| 281 return object; |
| 282 } |
| 283 |
| 263 template <typename Sequence> | 284 template <typename Sequence> |
| 264 inline v8::Local<v8::Value> toV8SequenceInternal( | 285 inline v8::Local<v8::Value> toV8SequenceInternal( |
| 265 const Sequence& sequence, | 286 const Sequence& sequence, |
| 266 v8::Local<v8::Object> creationContext, | 287 v8::Local<v8::Object> creationContext, |
| 267 v8::Isolate* isolate) { | 288 v8::Isolate* isolate) { |
| 268 v8::Local<v8::Array> array; | 289 v8::Local<v8::Array> array; |
| 269 { | 290 { |
| 270 v8::Context::Scope contextScope(creationContext->CreationContext()); | 291 v8::Context::Scope contextScope(creationContext->CreationContext()); |
| 271 array = v8::Array::New(isolate, sequence.size()); | 292 array = v8::Array::New(isolate, sequence.size()); |
| 272 } | 293 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // Cannot define in ScriptValue because of the circular dependency between toV8 | 329 // Cannot define in ScriptValue because of the circular dependency between toV8 |
| 309 // and ScriptValue | 330 // and ScriptValue |
| 310 template <typename T> | 331 template <typename T> |
| 311 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value) { | 332 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value) { |
| 312 return ScriptValue(scriptState, ToV8(std::forward<T>(value), scriptState)); | 333 return ScriptValue(scriptState, ToV8(std::forward<T>(value), scriptState)); |
| 313 } | 334 } |
| 314 | 335 |
| 315 } // namespace blink | 336 } // namespace blink |
| 316 | 337 |
| 317 #endif // ToV8_h | 338 #endif // ToV8_h |
| OLD | NEW |