OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 class V8DOMWrapper { | 43 class V8DOMWrapper { |
44 public: | 44 public: |
45 #ifndef NDEBUG | 45 #ifndef NDEBUG |
46 // Checks if a v8 value can be a DOM wrapper | 46 // Checks if a v8 value can be a DOM wrapper |
47 static bool maybeDOMWrapper(v8::Handle<v8::Value>); | 47 static bool maybeDOMWrapper(v8::Handle<v8::Value>); |
48 #endif | 48 #endif |
49 | 49 |
50 static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creati
onContext, WrapperTypeInfo*, void*, v8::Isolate*); | 50 static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creati
onContext, WrapperTypeInfo*, void*, v8::Isolate*); |
51 | 51 |
52 template<typename T> | 52 template<typename V8T, typename T> |
53 static inline v8::Handle<v8::Object> associateObjectWithWrapper(PassRefP
tr<T>, WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfigurat
ion::Lifetime); | 53 static inline v8::Handle<v8::Object> associateObjectWithWrapper(PassRefP
tr<T>, WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*, WrapperConfigurat
ion::Lifetime); |
54 static inline void setNativeInfo(v8::Handle<v8::Object>, WrapperTypeInfo
*, void*); | 54 static inline void setNativeInfo(v8::Handle<v8::Object>, WrapperTypeInfo
*, void*); |
55 static inline void clearNativeInfo(v8::Handle<v8::Object>, WrapperTypeIn
fo*); | 55 static inline void clearNativeInfo(v8::Handle<v8::Object>, WrapperTypeIn
fo*); |
56 | 56 |
57 static bool isDOMWrapper(v8::Handle<v8::Value>); | 57 static bool isDOMWrapper(v8::Handle<v8::Value>); |
58 static bool isWrapperOfType(v8::Handle<v8::Value>, WrapperTypeInfo*); | 58 static bool isWrapperOfType(v8::Handle<v8::Value>, WrapperTypeInfo*); |
59 }; | 59 }; |
60 | 60 |
61 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, Wrap
perTypeInfo* type, void* object) | 61 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, Wrap
perTypeInfo* type, void* object) |
62 { | 62 { |
63 ASSERT(wrapper->InternalFieldCount() >= 2); | 63 ASSERT(wrapper->InternalFieldCount() >= 2); |
64 ASSERT(object); | 64 ASSERT(object); |
65 ASSERT(type); | 65 ASSERT(type); |
66 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, objec
t); | 66 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, objec
t); |
67 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, type); | 67 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, type); |
68 } | 68 } |
69 | 69 |
70 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, Wr
apperTypeInfo* type) | 70 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, Wr
apperTypeInfo* type) |
71 { | 71 { |
72 ASSERT(wrapper->InternalFieldCount() >= 2); | 72 ASSERT(wrapper->InternalFieldCount() >= 2); |
73 ASSERT(type); | 73 ASSERT(type); |
74 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, type); | 74 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, type); |
75 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0); | 75 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0); |
76 } | 76 } |
77 | 77 |
78 template<typename T> | 78 template<typename V8T, typename T> |
79 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassR
efPtr<T> object, WrapperTypeInfo* type, v8::Handle<v8::Object> wrapper, v8::Isol
ate* isolate, WrapperConfiguration::Lifetime lifetime) | 79 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassR
efPtr<T> object, WrapperTypeInfo* type, v8::Handle<v8::Object> wrapper, v8::Isol
ate* isolate, WrapperConfiguration::Lifetime lifetime) |
80 { | 80 { |
81 setNativeInfo(wrapper, type, object.get()); | 81 setNativeInfo(wrapper, type, V8T::toInternalPointer(object.get())); |
82 ASSERT(maybeDOMWrapper(wrapper)); | 82 ASSERT(maybeDOMWrapper(wrapper)); |
83 WrapperConfiguration configuration = buildWrapperConfiguration(object.ge
t(), lifetime); | 83 WrapperConfiguration configuration = buildWrapperConfiguration(object.ge
t(), lifetime); |
84 DOMDataStore::setWrapper(object.leakRef(), wrapper, isolate, configurati
on); | 84 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, config
uration); |
85 return wrapper; | 85 return wrapper; |
86 } | 86 } |
87 | 87 |
88 } | 88 } |
89 | 89 |
90 #endif // V8DOMWrapper_h | 90 #endif // V8DOMWrapper_h |
OLD | NEW |