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

Side by Side Diff: Source/bindings/v8/V8Binding.h

Issue 350863002: Replaced ToV8Value::toV8Value with V8ValueTraits::toV8Value. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolverWithContext.h ('k') | Source/wtf/TypeTraits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 { 221 {
222 ASSERT(isolate); 222 ASSERT(isolate);
223 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedString , length); 223 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedString , length);
224 } 224 }
225 225
226 inline v8::Handle<v8::Value> v8Undefined() 226 inline v8::Handle<v8::Value> v8Undefined()
227 { 227 {
228 return v8::Handle<v8::Value>(); 228 return v8::Handle<v8::Value>();
229 } 229 }
230 230
231 template <class T> 231 // Converts a DOM object to a v8 value.
232 // This is a no-inline version of toV8(). If you want to call toV8()
233 // without creating #include cycles, you can use this function instead.
234 // Each specialized implementation will be generated.
235 template<typename T>
236 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationConte xt, v8::Isolate*);
237
238 template <typename T>
232 struct V8ValueTraits { 239 struct V8ValueTraits {
233 // FIXME: This function requires the associated generated header to be 240 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
234 // included. Also, this function does not match with other V8ValueTraits 241 static v8::Handle<v8::Value> toV8Value(TypeWithoutPointer* const& value, v8: :Handle<v8::Object> creationContext, v8::Isolate* isolate)
235 // classes. Remove this V8ValueTraits if possible.
236 static inline v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8: :Object> creationContext, v8::Isolate* isolate)
237 { 242 {
238 return toV8(WTF::getPtr(value), creationContext, isolate); 243 return toV8NoInline(value, creationContext, isolate);
244 }
245
246 typedef typename WTF::RemoveTemplate<T, RawPtr>::Type TypeWithoutRawPtr;
247 static v8::Handle<v8::Value> toV8Value(const RawPtr<TypeWithoutRawPtr>& valu e, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
248 {
249 return toV8NoInline(value.get(), creationContext, isolate);
250 }
251
252 // HeapVector<RefPtr> requires the following method:
253 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr;
254 static v8::Handle<v8::Value> toV8Value(const RefPtr<TypeWithoutRefPtr>& valu e, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
255 {
256 return toV8NoInline(value.get(), creationContext, isolate);
257 }
258
259 typedef typename WTF::RemoveTemplate<T, PassRefPtr>::Type TypeWithoutPassRef Ptr;
260 static v8::Handle<v8::Value> toV8Value(const PassRefPtr<TypeWithoutPassRefPt r>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
261 {
262 return toV8NoInline(value.get(), creationContext, isolate);
263 }
264
265 typedef typename WTF::RemoveTemplate<T, Member>::Type TypeWithoutMember;
266 static v8::Handle<v8::Value> toV8Value(const Member<TypeWithoutMember>& valu e, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
267 {
268 return toV8NoInline(value.get(), creationContext, isolate);
269 }
270
271 typedef typename WTF::RemoveVector<T, Vector, 0, WTF::DefaultAllocator>::Typ e 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.
272 static v8::Handle<v8::Value> toV8Value(const Vector<TypeWithoutDefaultVector , 0, WTF::DefaultAllocator>& value, v8::Handle<v8::Object> creationContext, v8:: Isolate* isolate)
273 {
274 return v8ArrayNoInline(value, creationContext, isolate);
239 } 275 }
240 }; 276 };
241 277
242 template<> 278 template<>
243 struct V8ValueTraits<String> { 279 struct V8ValueTraits<String> {
244 static inline v8::Handle<v8::Value> toV8Value(const String& value, v8::Handl e<v8::Object>, v8::Isolate* isolate) 280 static inline v8::Handle<v8::Value> toV8Value(const String& value, v8::Handl e<v8::Object>, v8::Isolate* isolate)
245 { 281 {
246 return v8String(isolate, value); 282 return v8String(isolate, value);
247 } 283 }
248 }; 284 };
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 v8SetReturnValue(info, properties); 887 v8SetReturnValue(info, properties);
852 } 888 }
853 889
854 // These methods store hidden values into an array that is stored in the interna l field of a DOM wrapper. 890 // These methods store hidden values into an array that is stored in the interna l field of a DOM wrapper.
855 void addHiddenValueToArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, int cac heIndex, v8::Isolate*); 891 void addHiddenValueToArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, int cac heIndex, v8::Isolate*);
856 void removeHiddenValueFromArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, in t cacheIndex, v8::Isolate*); 892 void removeHiddenValueFromArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, in t cacheIndex, v8::Isolate*);
857 void moveEventListenerToNewWrapper(v8::Handle<v8::Object>, EventListener* oldVal ue, v8::Local<v8::Value> newValue, int cacheIndex, v8::Isolate*); 893 void moveEventListenerToNewWrapper(v8::Handle<v8::Object>, EventListener* oldVal ue, v8::Local<v8::Value> newValue, int cacheIndex, v8::Isolate*);
858 894
859 PassRefPtr<JSONValue> v8ToJSONValue(v8::Isolate*, v8::Handle<v8::Value>, int); 895 PassRefPtr<JSONValue> v8ToJSONValue(v8::Isolate*, v8::Handle<v8::Value>, int);
860 896
861 // Converts a DOM object to a v8 value.
862 // This is a no-inline version of toV8(). If you want to call toV8()
863 // without creating #include cycles, you can use this function instead.
864 // Each specialized implementation will be generated.
865 template<typename T>
866 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationConte xt, v8::Isolate*);
867
868 // ToV8Value<U, Context> is a class that converts a C++ object to a
869 // v8 value. U has to be a class having a static method getCreationContext
870 // which returns an object created from a target context.
871 template<typename U, typename Context>
872 class ToV8Value {
873 public:
874 template<typename T>
875 static v8::Handle<v8::Value> toV8Value(const T& value, Context context, v8:: Isolate* isolate)
876 {
877 // Default implementaion: for types that don't need the context.
878 return V8ValueTraits<T>::toV8Value(value, context, isolate);
879 }
880
881 // Pointer specializations.
882 template<typename T>
883 static v8::Handle<v8::Value> toV8Value(T* const& value, Context context, v8: :Isolate* isolate)
884 {
885 return toV8NoInline(value, context, isolate);
886 }
887 template<typename T>
888 static v8::Handle<v8::Value> toV8Value(const RefPtr<T>& value, Context conte xt, v8::Isolate* isolate)
889 {
890 return toV8Value(value.get(), context, isolate);
891 }
892 template<typename T>
893 static v8::Handle<v8::Value> toV8Value(const PassRefPtr<T>& value, Context c ontext, v8::Isolate* isolate)
894 {
895 return toV8Value(value.get(), context, isolate);
896 }
897 template<typename T>
898 static v8::Handle<v8::Value> toV8Value(const OwnPtr<T>& value, Context conte xt, v8::Isolate* isolate)
899 {
900 return toV8Value(value.get(), context, isolate);
901 }
902 template<typename T>
903 static v8::Handle<v8::Value> toV8Value(const PassOwnPtr<T>& value, Context c ontext, v8::Isolate* isolate)
904 {
905 return toV8Value(value.get(), context, isolate);
906 }
907 template<typename T>
908 static v8::Handle<v8::Value> toV8Value(const RawPtr<T>& value, Context conte xt, v8::Isolate* isolate)
909 {
910 return toV8Value(value.get(), context, isolate);
911 }
912
913 // const char* should use V8ValueTraits.
914 static v8::Handle<v8::Value> toV8Value(const char* const& value, Context con text, v8::Isolate* isolate)
915 {
916 return V8ValueTraits<const char*>::toV8Value(value, context, isolate);
917 }
918
919 template<typename T, size_t inlineCapacity>
920 static v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity>& valu e, Context context, v8::Isolate* isolate)
921 {
922 return v8ArrayNoInline(value, context, isolate);
923 }
924
925 template<typename T, size_t inlineCapacity>
926 static v8::Handle<v8::Value> toV8Value(const HeapVector<T, inlineCapacity>& value, Context context, v8::Isolate* isolate)
927 {
928 return v8ArrayNoInline(value, context, isolate);
929 }
930
931 template<typename T, size_t inlineCapacity>
932 static v8::Handle<v8::Value> toV8Value(const PersistentHeapVector<T, inlineC apacity>& value, Context context, v8::Isolate* isolate)
933 {
934 return v8ArrayNoInline(static_cast<HeapVector<T, inlineCapacity> >(value ), context, isolate);
935 }
936 };
937
938 // Result values for platform object 'deleter' methods, 897 // Result values for platform object 'deleter' methods,
939 // http://www.w3.org/TR/WebIDL/#delete 898 // http://www.w3.org/TR/WebIDL/#delete
940 enum DeleteResult { 899 enum DeleteResult {
941 DeleteSuccess, 900 DeleteSuccess,
942 DeleteReject, 901 DeleteReject,
943 DeleteUnknownProperty 902 DeleteUnknownProperty
944 }; 903 };
945 904
946 class V8IsolateInterruptor : public ThreadState::Interruptor { 905 class V8IsolateInterruptor : public ThreadState::Interruptor {
947 public: 906 public:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 m_block.Reset(); 962 m_block.Reset();
1004 } 963 }
1005 964
1006 private: 965 private:
1007 v8::TryCatch& m_block; 966 v8::TryCatch& m_block;
1008 }; 967 };
1009 968
1010 } // namespace WebCore 969 } // namespace WebCore
1011 970
1012 #endif // V8Binding_h 971 #endif // V8Binding_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolverWithContext.h ('k') | Source/wtf/TypeTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698