Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 template <typename T> | 230 template <typename T> |
| 231 struct V8ValueTraits { | 231 struct V8ValueTraits { |
| 232 static v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object > creationContext, v8::Isolate* isolate) | 232 static v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object > creationContext, v8::Isolate* isolate) |
| 233 { | 233 { |
| 234 if (!WTF::getPtr(value)) | 234 if (!WTF::getPtr(value)) |
| 235 return v8::Null(isolate); | 235 return v8::Null(isolate); |
| 236 return toV8NoInline(WTF::getPtr(value), creationContext, isolate); | 236 return toV8NoInline(WTF::getPtr(value), creationContext, isolate); |
| 237 } | 237 } |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 template <typename T, size_t inlineCapacity, typename Allocator> | |
| 241 struct V8ValueTraits<WTF::Vector<T, inlineCapacity, Allocator> > { | |
| 242 static v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity, Alloc ator>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 243 { | |
| 244 return v8ArrayNoInline(value, creationContext, isolate); | |
| 245 } | |
| 246 }; | |
| 247 | |
| 248 template <typename T, size_t inlineCapacity> | |
| 249 struct V8ValueTraits<HeapVector<T, inlineCapacity> > { | |
| 250 static v8::Handle<v8::Value> toV8Value(const HeapVector<T, inlineCapacity>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 251 { | |
| 252 return v8ArrayNoInline(value, creationContext, isolate); | |
| 253 } | |
| 254 }; | |
| 255 | |
| 256 template<> | 240 template<> |
| 257 struct V8ValueTraits<String> { | 241 struct V8ValueTraits<String> { |
| 258 static inline v8::Handle<v8::Value> toV8Value(const String& value, v8::Handl e<v8::Object>, v8::Isolate* isolate) | 242 static inline v8::Handle<v8::Value> toV8Value(const String& value, v8::Handl e<v8::Object>, v8::Isolate* isolate) |
| 259 { | 243 { |
| 260 return v8String(isolate, value); | 244 return v8String(isolate, value); |
| 261 } | 245 } |
| 262 }; | 246 }; |
| 263 | 247 |
| 264 template<> | 248 template<> |
| 265 struct V8ValueTraits<AtomicString> { | 249 struct V8ValueTraits<AtomicString> { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 { | 395 { |
| 412 v8::Local<v8::Array> result = v8::Array::New(isolate, iterator.size()); | 396 v8::Local<v8::Array> result = v8::Array::New(isolate, iterator.size()); |
| 413 int index = 0; | 397 int index = 0; |
| 414 typename Vector<T, inlineCapacity>::const_iterator end = iterator.end(); | 398 typename Vector<T, inlineCapacity>::const_iterator end = iterator.end(); |
| 415 typedef V8ValueTraits<T> TraitsType; | 399 typedef V8ValueTraits<T> TraitsType; |
| 416 for (typename Vector<T, inlineCapacity>::const_iterator iter = iterator.begi n(); iter != end; ++iter) | 400 for (typename Vector<T, inlineCapacity>::const_iterator iter = iterator.begi n(); iter != end; ++iter) |
| 417 result->Set(v8::Integer::New(isolate, index++), TraitsType::toV8Value(*i ter, creationContext, isolate)); | 401 result->Set(v8::Integer::New(isolate, index++), TraitsType::toV8Value(*i ter, creationContext, isolate)); |
| 418 return result; | 402 return result; |
| 419 } | 403 } |
| 420 | 404 |
| 405 template <typename T, size_t inlineCapacity, typename Allocator> | |
| 406 struct V8ValueTraits<WTF::Vector<T, inlineCapacity, Allocator> > { | |
|
yhirano
2014/07/23 01:51:52
Can you tell me why you move toV8Value functions?
gavinp
2014/07/23 01:57:24
Type deduction across namespaces for function temp
| |
| 407 static v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity, Alloc ator>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 408 { | |
| 409 return v8Array(value, creationContext, isolate); | |
| 410 } | |
| 411 }; | |
| 412 | |
| 421 template<typename T, size_t inlineCapacity> | 413 template<typename T, size_t inlineCapacity> |
| 422 v8::Handle<v8::Value> v8Array(const HeapVector<T, inlineCapacity>& iterator, v8: :Handle<v8::Object> creationContext, v8::Isolate* isolate) | 414 v8::Handle<v8::Value> v8Array(const HeapVector<T, inlineCapacity>& iterator, v8: :Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 423 { | 415 { |
| 424 v8::Local<v8::Array> result = v8::Array::New(isolate, iterator.size()); | 416 v8::Local<v8::Array> result = v8::Array::New(isolate, iterator.size()); |
| 425 int index = 0; | 417 int index = 0; |
| 426 typename HeapVector<T, inlineCapacity>::const_iterator end = iterator.end(); | 418 typename HeapVector<T, inlineCapacity>::const_iterator end = iterator.end(); |
| 427 typedef V8ValueTraits<T> TraitsType; | 419 typedef V8ValueTraits<T> TraitsType; |
| 428 for (typename HeapVector<T, inlineCapacity>::const_iterator iter = iterator. begin(); iter != end; ++iter) | 420 for (typename HeapVector<T, inlineCapacity>::const_iterator iter = iterator. begin(); iter != end; ++iter) |
| 429 result->Set(v8::Integer::New(isolate, index++), TraitsType::toV8Value(*i ter, creationContext, isolate)); | 421 result->Set(v8::Integer::New(isolate, index++), TraitsType::toV8Value(*i ter, creationContext, isolate)); |
| 430 return result; | 422 return result; |
| 431 } | 423 } |
| 432 | 424 |
| 433 template<typename T, size_t inlineCapacity> | 425 template <typename T, size_t inlineCapacity> |
| 434 v8::Handle<v8::Value> v8ArrayNoInline(const Vector<T, inlineCapacity>& iterator, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | 426 struct V8ValueTraits<HeapVector<T, inlineCapacity> > { |
| 435 { | 427 static v8::Handle<v8::Value> toV8Value(const HeapVector<T, inlineCapacity>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 436 v8::Local<v8::Array> result = v8::Array::New(isolate, iterator.size()); | 428 { |
| 437 int index = 0; | 429 return v8Array(value, creationContext, isolate); |
| 438 typename Vector<T, inlineCapacity>::const_iterator end = iterator.end(); | 430 } |
| 439 for (typename Vector<T, inlineCapacity>::const_iterator iter = iterator.begi n(); iter != end; ++iter) | 431 }; |
| 440 result->Set(v8::Integer::New(isolate, index++), toV8NoInline(WTF::getPtr (*iter), creationContext, isolate)); | |
| 441 return result; | |
| 442 } | |
| 443 | |
| 444 template<typename T, size_t inlineCapacity> | |
| 445 v8::Handle<v8::Value> v8ArrayNoInline(const HeapVector<T, inlineCapacity>& itera tor, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 446 { | |
| 447 v8::Local<v8::Array> result = v8::Array::New(isolate, iterator.size()); | |
| 448 int index = 0; | |
| 449 typename HeapVector<T, inlineCapacity>::const_iterator end = iterator.end(); | |
| 450 for (typename HeapVector<T, inlineCapacity>::const_iterator iter = iterator. begin(); iter != end; ++iter) | |
| 451 result->Set(v8::Integer::New(isolate, index++), toV8NoInline(WTF::getPtr (*iter), creationContext, isolate)); | |
| 452 return result; | |
| 453 } | |
| 454 | 432 |
| 455 // Conversion flags, used in toIntXX/toUIntXX. | 433 // Conversion flags, used in toIntXX/toUIntXX. |
| 456 enum IntegerConversionConfiguration { | 434 enum IntegerConversionConfiguration { |
| 457 NormalConversion, | 435 NormalConversion, |
| 458 EnforceRange, | 436 EnforceRange, |
| 459 Clamp | 437 Clamp |
| 460 }; | 438 }; |
| 461 | 439 |
| 462 // Convert a value to a 8-bit signed integer. The conversion fails if the | 440 // Convert a value to a 8-bit signed integer. The conversion fails if the |
| 463 // value cannot be converted to a number or the range violated per WebIDL: | 441 // value cannot be converted to a number or the range violated per WebIDL: |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 m_block.Reset(); | 971 m_block.Reset(); |
| 994 } | 972 } |
| 995 | 973 |
| 996 private: | 974 private: |
| 997 v8::TryCatch& m_block; | 975 v8::TryCatch& m_block; |
| 998 }; | 976 }; |
| 999 | 977 |
| 1000 } // namespace blink | 978 } // namespace blink |
| 1001 | 979 |
| 1002 #endif // V8Binding_h | 980 #endif // V8Binding_h |
| OLD | NEW |