Chromium Code Reviews| Index: Source/bindings/v8/V8Binding.h |
| diff --git a/Source/bindings/v8/V8Binding.h b/Source/bindings/v8/V8Binding.h |
| index fabf358f47dffc22efec18c3542c31523343cb76..f7bcfee6768bba0ce383780841d8d65d832529f8 100644 |
| --- a/Source/bindings/v8/V8Binding.h |
| +++ b/Source/bindings/v8/V8Binding.h |
| @@ -228,14 +228,50 @@ inline v8::Handle<v8::Value> v8Undefined() |
| return v8::Handle<v8::Value>(); |
| } |
| -template <class T> |
| +// Converts a DOM object to a v8 value. |
| +// This is a no-inline version of toV8(). If you want to call toV8() |
| +// without creating #include cycles, you can use this function instead. |
| +// Each specialized implementation will be generated. |
| +template<typename T> |
| +v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*); |
| + |
| +template <typename T> |
| struct V8ValueTraits { |
| - // FIXME: This function requires the associated generated header to be |
| - // included. Also, this function does not match with other V8ValueTraits |
| - // classes. Remove this V8ValueTraits if possible. |
| - static inline v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| + typedef typename WTF::RemovePointer<T>::Type TypeWithoutPointer; |
|
yhirano
2014/06/24 09:24:09
[optional] You can use WTF::getPtr if you prefer.
tasak
2014/06/26 05:04:02
I see.
Since I'm using RemoveTemplate below, I wil
|
| + static v8::Handle<v8::Value> toV8Value(TypeWithoutPointer* const& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| + { |
| + return toV8NoInline(value, creationContext, isolate); |
| + } |
| + |
| + typedef typename WTF::RemoveTemplate<T, RawPtr>::Type TypeWithoutRawPtr; |
| + static v8::Handle<v8::Value> toV8Value(const RawPtr<TypeWithoutRawPtr>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| + { |
| + return toV8NoInline(value.get(), creationContext, isolate); |
| + } |
| + |
| + // HeapVector<RefPtr> requires the following method: |
| + typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; |
| + static v8::Handle<v8::Value> toV8Value(const RefPtr<TypeWithoutRefPtr>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| + { |
| + return toV8NoInline(value.get(), creationContext, isolate); |
| + } |
| + |
| + typedef typename WTF::RemoveTemplate<T, PassRefPtr>::Type TypeWithoutPassRefPtr; |
| + static v8::Handle<v8::Value> toV8Value(const PassRefPtr<TypeWithoutPassRefPtr>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| + { |
| + return toV8NoInline(value.get(), creationContext, isolate); |
| + } |
| + |
| + typedef typename WTF::RemoveTemplate<T, Member>::Type TypeWithoutMember; |
| + static v8::Handle<v8::Value> toV8Value(const Member<TypeWithoutMember>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| + { |
| + return toV8NoInline(value.get(), creationContext, isolate); |
| + } |
| + |
| + typedef typename WTF::RemoveVector<T, Vector, 0, WTF::DefaultAllocator>::Type TypeWithoutDefaultVector; |
|
yhirano
2014/06/24 09:24:09
You can use the partial template specialization. S
tasak
2014/06/26 05:04:02
I see. Thanks.
Done.
|
| + static v8::Handle<v8::Value> toV8Value(const Vector<TypeWithoutDefaultVector, 0, WTF::DefaultAllocator>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| { |
| - return toV8(WTF::getPtr(value), creationContext, isolate); |
| + return v8ArrayNoInline(value, creationContext, isolate); |
| } |
| }; |
| @@ -858,83 +894,6 @@ void moveEventListenerToNewWrapper(v8::Handle<v8::Object>, EventListener* oldVal |
| PassRefPtr<JSONValue> v8ToJSONValue(v8::Isolate*, v8::Handle<v8::Value>, int); |
| -// Converts a DOM object to a v8 value. |
| -// This is a no-inline version of toV8(). If you want to call toV8() |
| -// without creating #include cycles, you can use this function instead. |
| -// Each specialized implementation will be generated. |
| -template<typename T> |
| -v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*); |
| - |
| -// ToV8Value<U, Context> is a class that converts a C++ object to a |
| -// v8 value. U has to be a class having a static method getCreationContext |
| -// which returns an object created from a target context. |
| -template<typename U, typename Context> |
| -class ToV8Value { |
| -public: |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(const T& value, Context context, v8::Isolate* isolate) |
| - { |
| - // Default implementaion: for types that don't need the context. |
| - return V8ValueTraits<T>::toV8Value(value, context, isolate); |
| - } |
| - |
| - // Pointer specializations. |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(T* const& value, Context context, v8::Isolate* isolate) |
| - { |
| - return toV8NoInline(value, context, isolate); |
| - } |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(const RefPtr<T>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return toV8Value(value.get(), context, isolate); |
| - } |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(const PassRefPtr<T>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return toV8Value(value.get(), context, isolate); |
| - } |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(const OwnPtr<T>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return toV8Value(value.get(), context, isolate); |
| - } |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(const PassOwnPtr<T>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return toV8Value(value.get(), context, isolate); |
| - } |
| - template<typename T> |
| - static v8::Handle<v8::Value> toV8Value(const RawPtr<T>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return toV8Value(value.get(), context, isolate); |
| - } |
| - |
| - // const char* should use V8ValueTraits. |
| - static v8::Handle<v8::Value> toV8Value(const char* const& value, Context context, v8::Isolate* isolate) |
| - { |
| - return V8ValueTraits<const char*>::toV8Value(value, context, isolate); |
| - } |
| - |
| - template<typename T, size_t inlineCapacity> |
| - static v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return v8ArrayNoInline(value, context, isolate); |
| - } |
| - |
| - template<typename T, size_t inlineCapacity> |
| - static v8::Handle<v8::Value> toV8Value(const HeapVector<T, inlineCapacity>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return v8ArrayNoInline(value, context, isolate); |
| - } |
| - |
| - template<typename T, size_t inlineCapacity> |
| - static v8::Handle<v8::Value> toV8Value(const PersistentHeapVector<T, inlineCapacity>& value, Context context, v8::Isolate* isolate) |
| - { |
| - return v8ArrayNoInline(static_cast<HeapVector<T, inlineCapacity> >(value), context, isolate); |
| - } |
| -}; |
| - |
| // Result values for platform object 'deleter' methods, |
| // http://www.w3.org/TR/WebIDL/#delete |
| enum DeleteResult { |