| 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 30 matching lines...) Expand all Loading... |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 class Node; | 43 class Node; |
| 44 struct WrapperTypeInfo; | 44 struct WrapperTypeInfo; |
| 45 | 45 |
| 46 class V8DOMWrapper { | 46 class V8DOMWrapper { |
| 47 public: | 47 public: |
| 48 static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creationCo
ntext, const WrapperTypeInfo*, ScriptWrappableBase*, v8::Isolate*); | 48 static v8::Local<v8::Object> createWrapper(v8::Handle<v8::Object> creationCo
ntext, const WrapperTypeInfo*, ScriptWrappableBase*, v8::Isolate*); |
| 49 | 49 |
| 50 template<typename V8T, typename T> | 50 template<typename V8T, typename T> |
| 51 static v8::Handle<v8::Object> associateObjectWithWrapper(PassRefPtr<T>, cons
t WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*); | 51 static v8::Handle<v8::Object> associateObjectWithWrapper(v8::Isolate*, PassR
efPtr<T>, const WrapperTypeInfo*, v8::Handle<v8::Object>); |
| 52 template<typename V8T, typename T> | 52 template<typename V8T, typename T> |
| 53 static v8::Handle<v8::Object> associateObjectWithWrapper(RawPtr<T> object, c
onst WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Isola
te* isolate) | 53 static v8::Handle<v8::Object> associateObjectWithWrapper(v8::Isolate* isolat
e, RawPtr<T> object, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Obje
ct> wrapper) |
| 54 { | 54 { |
| 55 return associateObjectWithWrapper<V8T, T>(object.get(), wrapperTypeInfo,
wrapper, isolate); | 55 return associateObjectWithWrapper<V8T, T>(isolate, object.get(), wrapper
TypeInfo, wrapper); |
| 56 } | 56 } |
| 57 template<typename V8T, typename T> | 57 template<typename V8T, typename T> |
| 58 static v8::Handle<v8::Object> associateObjectWithWrapper(T*, const WrapperTy
peInfo*, v8::Handle<v8::Object>, v8::Isolate*); | 58 static v8::Handle<v8::Object> associateObjectWithWrapper(v8::Isolate*, T*, c
onst WrapperTypeInfo*, v8::Handle<v8::Object>); |
| 59 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(ScriptWr
appable*, const WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*); | 59 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(v8::Isol
ate*, ScriptWrappable*, const WrapperTypeInfo*, v8::Handle<v8::Object>); |
| 60 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(Node*, c
onst WrapperTypeInfo*, v8::Handle<v8::Object>, v8::Isolate*); | 60 static v8::Handle<v8::Object> associateObjectWithWrapperNonTemplate(v8::Isol
ate*, Node*, const WrapperTypeInfo*, v8::Handle<v8::Object>); |
| 61 static void setNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*, Sc
riptWrappableBase*); | 61 static void setNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*, Sc
riptWrappableBase*); |
| 62 static void clearNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*); | 62 static void clearNativeInfo(v8::Handle<v8::Object>, const WrapperTypeInfo*); |
| 63 | 63 |
| 64 static bool isDOMWrapper(v8::Handle<v8::Value>); | 64 static bool isDOMWrapper(v8::Handle<v8::Value>); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, const Wr
apperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* scriptWrappableBase) | 67 inline void V8DOMWrapper::setNativeInfo(v8::Handle<v8::Object> wrapper, const Wr
apperTypeInfo* wrapperTypeInfo, ScriptWrappableBase* scriptWrappableBase) |
| 68 { | 68 { |
| 69 ASSERT(wrapper->InternalFieldCount() >= 2); | 69 ASSERT(wrapper->InternalFieldCount() >= 2); |
| 70 ASSERT(scriptWrappableBase); | 70 ASSERT(scriptWrappableBase); |
| 71 ASSERT(wrapperTypeInfo); | 71 ASSERT(wrapperTypeInfo); |
| 72 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, scriptWra
ppableBase); | 72 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, scriptWra
ppableBase); |
| 73 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 73 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, const
WrapperTypeInfo* wrapperTypeInfo) | 76 inline void V8DOMWrapper::clearNativeInfo(v8::Handle<v8::Object> wrapper, const
WrapperTypeInfo* wrapperTypeInfo) |
| 77 { | 77 { |
| 78 ASSERT(wrapper->InternalFieldCount() >= 2); | 78 ASSERT(wrapper->InternalFieldCount() >= 2); |
| 79 ASSERT(wrapperTypeInfo); | 79 ASSERT(wrapperTypeInfo); |
| 80 // clearNativeInfo() is used only by NP objects, which are not garbage colle
cted. | 80 // clearNativeInfo() is used only by NP objects, which are not garbage colle
cted. |
| 81 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject); | 81 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject); |
| 82 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 82 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
| 83 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0); | 83 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0); |
| 84 } | 84 } |
| 85 | 85 |
| 86 template<typename V8T, typename T> | 86 template<typename V8T, typename T> |
| 87 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassRefPt
r<T> object, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrap
per, v8::Isolate* isolate) | 87 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isola
te* isolate, PassRefPtr<T> object, const WrapperTypeInfo* wrapperTypeInfo, v8::H
andle<v8::Object> wrapper) |
| 88 { | 88 { |
| 89 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object.ge
t())); | 89 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object.ge
t())); |
| 90 ASSERT(isDOMWrapper(wrapper)); | 90 ASSERT(isDOMWrapper(wrapper)); |
| 91 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, wrapperTyp
eInfo); | 91 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, wrapperTyp
eInfo); |
| 92 return wrapper; | 92 return wrapper; |
| 93 } | 93 } |
| 94 | 94 |
| 95 template<typename V8T, typename T> | 95 template<typename V8T, typename T> |
| 96 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(T* object
, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Is
olate* isolate) | 96 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isola
te* isolate, T* object, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::O
bject> wrapper) |
| 97 { | 97 { |
| 98 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object)); | 98 setNativeInfo(wrapper, wrapperTypeInfo, V8T::toScriptWrappableBase(object)); |
| 99 ASSERT(isDOMWrapper(wrapper)); | 99 ASSERT(isDOMWrapper(wrapper)); |
| 100 DOMDataStore::setWrapper<V8T>(object, wrapper, isolate, wrapperTypeInfo); | 100 DOMDataStore::setWrapper<V8T>(object, wrapper, isolate, wrapperTypeInfo); |
| 101 return wrapper; | 101 return wrapper; |
| 102 } | 102 } |
| 103 | 103 |
| 104 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat
e(ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::
Object> wrapper, v8::Isolate* isolate) | 104 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat
e(v8::Isolate* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTyp
eInfo, v8::Handle<v8::Object> wrapper) |
| 105 { | 105 { |
| 106 wrapperTypeInfo->refObject(impl->toScriptWrappableBase()); | 106 wrapperTypeInfo->refObject(impl->toScriptWrappableBase()); |
| 107 setNativeInfo(wrapper, wrapperTypeInfo, impl->toScriptWrappableBase()); | 107 setNativeInfo(wrapper, wrapperTypeInfo, impl->toScriptWrappableBase()); |
| 108 ASSERT(isDOMWrapper(wrapper)); | 108 ASSERT(isDOMWrapper(wrapper)); |
| 109 DOMDataStore::setWrapperNonTemplate(impl, wrapper, isolate, wrapperTypeInfo)
; | 109 DOMDataStore::setWrapperNonTemplate(impl, wrapper, isolate, wrapperTypeInfo)
; |
| 110 return wrapper; | 110 return wrapper; |
| 111 } | 111 } |
| 112 | 112 |
| 113 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat
e(Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wra
pper, v8::Isolate* isolate) | 113 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapperNonTemplat
e(v8::Isolate* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::
Handle<v8::Object> wrapper) |
| 114 { | 114 { |
| 115 wrapperTypeInfo->refObject(ScriptWrappable::fromNode(node)->toScriptWrappabl
eBase()); | 115 wrapperTypeInfo->refObject(ScriptWrappable::fromNode(node)->toScriptWrappabl
eBase()); |
| 116 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node)->toS
criptWrappableBase()); | 116 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node)->toS
criptWrappableBase()); |
| 117 ASSERT(isDOMWrapper(wrapper)); | 117 ASSERT(isDOMWrapper(wrapper)); |
| 118 DOMDataStore::setWrapperNonTemplate(node, wrapper, isolate, wrapperTypeInfo)
; | 118 DOMDataStore::setWrapperNonTemplate(node, wrapper, isolate, wrapperTypeInfo)
; |
| 119 return wrapper; | 119 return wrapper; |
| 120 } | 120 } |
| 121 | 121 |
| 122 class V8WrapperInstantiationScope { | 122 class V8WrapperInstantiationScope { |
| 123 public: | 123 public: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 149 v8::Handle<v8::Context> context() const { return m_context; } | 149 v8::Handle<v8::Context> context() const { return m_context; } |
| 150 | 150 |
| 151 private: | 151 private: |
| 152 bool m_didEnterContext; | 152 bool m_didEnterContext; |
| 153 v8::Handle<v8::Context> m_context; | 153 v8::Handle<v8::Context> m_context; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| 157 | 157 |
| 158 #endif // V8DOMWrapper_h | 158 #endif // V8DOMWrapper_h |
| OLD | NEW |