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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 { | 212 { |
213 ASSERT(isolate); | 213 ASSERT(isolate); |
214 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedString
, length); | 214 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedString
, length); |
215 } | 215 } |
216 | 216 |
217 inline v8::Handle<v8::Value> v8Undefined() | 217 inline v8::Handle<v8::Value> v8Undefined() |
218 { | 218 { |
219 return v8::Handle<v8::Value>(); | 219 return v8::Handle<v8::Value>(); |
220 } | 220 } |
221 | 221 |
222 template <class T> | 222 // Converts a DOM object to a v8 value. |
| 223 // This is a no-inline version of toV8(). If you want to call toV8() |
| 224 // without creating #include cycles, you can use this function instead. |
| 225 // Each specialized implementation will be generated. |
| 226 template<typename T> |
| 227 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationConte
xt, v8::Isolate*); |
| 228 |
| 229 template <typename T> |
223 struct V8ValueTraits { | 230 struct V8ValueTraits { |
224 // FIXME: This function requires the associated generated header to be | 231 typedef typename WTF::RemovePointer<T>::Type TypeWithoutPointer; |
225 // included. Also, this function does not match with other V8ValueTraits | 232 static v8::Handle<v8::Value> toV8Value(TypeWithoutPointer* const& value, v8:
:Handle<v8::Object> creationContext, v8::Isolate* isolate) |
226 // classes. Remove this V8ValueTraits if possible. | |
227 static inline v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8:
:Object> creationContext, v8::Isolate* isolate) | |
228 { | 233 { |
229 return toV8(WTF::getPtr(value), creationContext, isolate); | 234 return toV8NoInline(value, creationContext, isolate); |
| 235 } |
| 236 |
| 237 typedef typename WTF::RemoveTemplate<T, RawPtr>::Type TypeWithoutRawPtr; |
| 238 static v8::Handle<v8::Value> toV8Value(const RawPtr<TypeWithoutRawPtr>& valu
e, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 239 { |
| 240 return toV8NoInline(value.get(), creationContext, isolate); |
| 241 } |
| 242 |
| 243 // HeapVector<RefPtr> requires the following method: |
| 244 typedef typename WTF::RemoveTemplate<T, RefPtr>::Type TypeWithoutRefPtr; |
| 245 static v8::Handle<v8::Value> toV8Value(const RefPtr<TypeWithoutRefPtr>& valu
e, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 246 { |
| 247 return toV8NoInline(value.get(), creationContext, isolate); |
| 248 } |
| 249 |
| 250 typedef typename WTF::RemoveTemplate<T, PassRefPtr>::Type TypeWithoutPassRef
Ptr; |
| 251 static v8::Handle<v8::Value> toV8Value(const PassRefPtr<TypeWithoutPassRefPt
r>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 252 { |
| 253 return toV8NoInline(value.get(), creationContext, isolate); |
| 254 } |
| 255 |
| 256 typedef typename WTF::RemoveTemplate<T, Member>::Type TypeWithoutMember; |
| 257 static v8::Handle<v8::Value> toV8Value(const Member<TypeWithoutMember>& valu
e, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 258 { |
| 259 return toV8NoInline(value.get(), creationContext, isolate); |
230 } | 260 } |
231 }; | 261 }; |
232 | 262 |
| 263 template <typename T, size_t inlineCapacity, typename Allocator> |
| 264 struct V8ValueTraits<WTF::Vector<T, inlineCapacity, Allocator> > { |
| 265 static v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity, Alloc
ator>& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 266 { |
| 267 return v8ArrayNoInline(value, creationContext, isolate); |
| 268 } |
| 269 }; |
| 270 |
233 template<> | 271 template<> |
234 struct V8ValueTraits<String> { | 272 struct V8ValueTraits<String> { |
235 static inline v8::Handle<v8::Value> toV8Value(const String& value, v8::Handl
e<v8::Object>, v8::Isolate* isolate) | 273 static inline v8::Handle<v8::Value> toV8Value(const String& value, v8::Handl
e<v8::Object>, v8::Isolate* isolate) |
236 { | 274 { |
237 return v8String(isolate, value); | 275 return v8String(isolate, value); |
238 } | 276 } |
239 }; | 277 }; |
240 | 278 |
241 template<> | 279 template<> |
242 struct V8ValueTraits<AtomicString> { | 280 struct V8ValueTraits<AtomicString> { |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 v8SetReturnValue(info, properties); | 913 v8SetReturnValue(info, properties); |
876 } | 914 } |
877 | 915 |
878 // These methods store hidden values into an array that is stored in the interna
l field of a DOM wrapper. | 916 // These methods store hidden values into an array that is stored in the interna
l field of a DOM wrapper. |
879 void addHiddenValueToArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, int cac
heIndex, v8::Isolate*); | 917 void addHiddenValueToArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, int cac
heIndex, v8::Isolate*); |
880 void removeHiddenValueFromArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, in
t cacheIndex, v8::Isolate*); | 918 void removeHiddenValueFromArray(v8::Handle<v8::Object>, v8::Local<v8::Value>, in
t cacheIndex, v8::Isolate*); |
881 void moveEventListenerToNewWrapper(v8::Handle<v8::Object>, EventListener* oldVal
ue, v8::Local<v8::Value> newValue, int cacheIndex, v8::Isolate*); | 919 void moveEventListenerToNewWrapper(v8::Handle<v8::Object>, EventListener* oldVal
ue, v8::Local<v8::Value> newValue, int cacheIndex, v8::Isolate*); |
882 | 920 |
883 PassRefPtr<JSONValue> v8ToJSONValue(v8::Isolate*, v8::Handle<v8::Value>, int); | 921 PassRefPtr<JSONValue> v8ToJSONValue(v8::Isolate*, v8::Handle<v8::Value>, int); |
884 | 922 |
885 // Converts a DOM object to a v8 value. | |
886 // This is a no-inline version of toV8(). If you want to call toV8() | |
887 // without creating #include cycles, you can use this function instead. | |
888 // Each specialized implementation will be generated. | |
889 template<typename T> | |
890 v8::Handle<v8::Value> toV8NoInline(T* impl, v8::Handle<v8::Object> creationConte
xt, v8::Isolate*); | |
891 | |
892 // ToV8Value<U, Context> is a class that converts a C++ object to a | |
893 // v8 value. U has to be a class having a static method getCreationContext | |
894 // which returns an object created from a target context. | |
895 template<typename U, typename Context> | |
896 class ToV8Value { | |
897 public: | |
898 template<typename T> | |
899 static v8::Handle<v8::Value> toV8Value(const T& value, Context context, v8::
Isolate* isolate) | |
900 { | |
901 // Default implementaion: for types that don't need the context. | |
902 return V8ValueTraits<T>::toV8Value(value, context, isolate); | |
903 } | |
904 | |
905 // Pointer specializations. | |
906 template<typename T> | |
907 static v8::Handle<v8::Value> toV8Value(T* const& value, Context context, v8:
:Isolate* isolate) | |
908 { | |
909 return toV8NoInline(value, context, isolate); | |
910 } | |
911 template<typename T> | |
912 static v8::Handle<v8::Value> toV8Value(const RefPtr<T>& value, Context conte
xt, v8::Isolate* isolate) | |
913 { | |
914 return toV8Value(value.get(), context, isolate); | |
915 } | |
916 template<typename T> | |
917 static v8::Handle<v8::Value> toV8Value(const PassRefPtr<T>& value, Context c
ontext, v8::Isolate* isolate) | |
918 { | |
919 return toV8Value(value.get(), context, isolate); | |
920 } | |
921 template<typename T> | |
922 static v8::Handle<v8::Value> toV8Value(const OwnPtr<T>& value, Context conte
xt, v8::Isolate* isolate) | |
923 { | |
924 return toV8Value(value.get(), context, isolate); | |
925 } | |
926 template<typename T> | |
927 static v8::Handle<v8::Value> toV8Value(const PassOwnPtr<T>& value, Context c
ontext, v8::Isolate* isolate) | |
928 { | |
929 return toV8Value(value.get(), context, isolate); | |
930 } | |
931 template<typename T> | |
932 static v8::Handle<v8::Value> toV8Value(const RawPtr<T>& value, Context conte
xt, v8::Isolate* isolate) | |
933 { | |
934 return toV8Value(value.get(), context, isolate); | |
935 } | |
936 | |
937 // const char* should use V8ValueTraits. | |
938 static v8::Handle<v8::Value> toV8Value(const char* const& value, Context con
text, v8::Isolate* isolate) | |
939 { | |
940 return V8ValueTraits<const char*>::toV8Value(value, context, isolate); | |
941 } | |
942 | |
943 template<typename T, size_t inlineCapacity> | |
944 static v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity>& valu
e, Context context, v8::Isolate* isolate) | |
945 { | |
946 return v8ArrayNoInline(value, context, isolate); | |
947 } | |
948 | |
949 template<typename T, size_t inlineCapacity> | |
950 static v8::Handle<v8::Value> toV8Value(const HeapVector<T, inlineCapacity>&
value, Context context, v8::Isolate* isolate) | |
951 { | |
952 return v8ArrayNoInline(value, context, isolate); | |
953 } | |
954 | |
955 template<typename T, size_t inlineCapacity> | |
956 static v8::Handle<v8::Value> toV8Value(const PersistentHeapVector<T, inlineC
apacity>& value, Context context, v8::Isolate* isolate) | |
957 { | |
958 return v8ArrayNoInline(static_cast<HeapVector<T, inlineCapacity> >(value
), context, isolate); | |
959 } | |
960 }; | |
961 | |
962 // Result values for platform object 'deleter' methods, | 923 // Result values for platform object 'deleter' methods, |
963 // http://www.w3.org/TR/WebIDL/#delete | 924 // http://www.w3.org/TR/WebIDL/#delete |
964 enum DeleteResult { | 925 enum DeleteResult { |
965 DeleteSuccess, | 926 DeleteSuccess, |
966 DeleteReject, | 927 DeleteReject, |
967 DeleteUnknownProperty | 928 DeleteUnknownProperty |
968 }; | 929 }; |
969 | 930 |
970 class V8IsolateInterruptor : public ThreadState::Interruptor { | 931 class V8IsolateInterruptor : public ThreadState::Interruptor { |
971 public: | 932 public: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 m_block.Reset(); | 988 m_block.Reset(); |
1028 } | 989 } |
1029 | 990 |
1030 private: | 991 private: |
1031 v8::TryCatch& m_block; | 992 v8::TryCatch& m_block; |
1032 }; | 993 }; |
1033 | 994 |
1034 } // namespace WebCore | 995 } // namespace WebCore |
1035 | 996 |
1036 #endif // V8Binding_h | 997 #endif // V8Binding_h |
OLD | NEW |