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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 static v8::Local<v8::Object> createWrapper(v8::Isolate*, v8::Local<v8::Objec
t> creationContext, const WrapperTypeInfo*, ScriptWrappable*); | 52 static v8::Local<v8::Object> createWrapper(v8::Isolate*, v8::Local<v8::Objec
t> creationContext, const WrapperTypeInfo*, ScriptWrappable*); |
53 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); | 53 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); |
54 | 54 |
55 // Associates the given ScriptWrappable with the given |wrapper| if the | 55 // Associates the given ScriptWrappable with the given |wrapper| if the |
56 // ScriptWrappable is not yet associated with any wrapper. Returns the | 56 // ScriptWrappable is not yet associated with any wrapper. Returns the |
57 // wrapper already associated or |wrapper| if not yet associated. | 57 // wrapper already associated or |wrapper| if not yet associated. |
58 // The caller should always use the returned value rather than |wrapper|. | 58 // The caller should always use the returned value rather than |wrapper|. |
59 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Script
Wrappable*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_R
ETURN; | 59 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Script
Wrappable*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_R
ETURN; |
60 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Node*,
const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; | 60 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Node*,
const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; |
61 static void setNativeInfo(v8::Local<v8::Object>, const WrapperTypeInfo*, Scr
iptWrappable*); | 61 static void setNativeInfo(v8::Local<v8::Object>, const WrapperTypeInfo*, Scr
iptWrappable*); |
62 static void clearNativeInfo(v8::Local<v8::Object>, const WrapperTypeInfo*); | |
63 // hasInternalFieldsSet only checks if the value has the internal fields for | 62 // hasInternalFieldsSet only checks if the value has the internal fields for |
64 // wrapper obejct and type, and does not check if it's valid or not. The | 63 // wrapper obejct and type, and does not check if it's valid or not. The |
65 // value may not be a Blink's wrapper object. In order to make sure of it, | 64 // value may not be a Blink's wrapper object. In order to make sure of it, |
66 // Use isWrapper function instead. | 65 // Use isWrapper function instead. |
67 CORE_EXPORT static bool hasInternalFieldsSet(v8::Local<v8::Value>); | 66 CORE_EXPORT static bool hasInternalFieldsSet(v8::Local<v8::Value>); |
68 }; | 67 }; |
69 | 68 |
70 inline void V8DOMWrapper::setNativeInfo(v8::Local<v8::Object> wrapper, const Wra
pperTypeInfo* wrapperTypeInfo, ScriptWrappable* scriptWrappable) | 69 inline void V8DOMWrapper::setNativeInfo(v8::Local<v8::Object> wrapper, const Wra
pperTypeInfo* wrapperTypeInfo, ScriptWrappable* scriptWrappable) |
71 { | 70 { |
72 ASSERT(wrapper->InternalFieldCount() >= 2); | 71 ASSERT(wrapper->InternalFieldCount() >= 2); |
73 ASSERT(scriptWrappable); | 72 ASSERT(scriptWrappable); |
74 ASSERT(wrapperTypeInfo); | 73 ASSERT(wrapperTypeInfo); |
75 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, scriptWra
ppable); | 74 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, scriptWra
ppable); |
76 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | 75 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); |
77 } | 76 } |
78 | 77 |
79 inline void V8DOMWrapper::clearNativeInfo(v8::Local<v8::Object> wrapper, const W
rapperTypeInfo* wrapperTypeInfo) | |
80 { | |
81 ASSERT(wrapper->InternalFieldCount() >= 2); | |
82 ASSERT(wrapperTypeInfo); | |
83 // clearNativeInfo() is used only by NP objects, which are not garbage colle
cted. | |
84 ASSERT(wrapperTypeInfo->gcType == WrapperTypeInfo::RefCountedObject); | |
85 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperTypeIndex, const_cast<
WrapperTypeInfo*>(wrapperTypeInfo)); | |
86 wrapper->SetAlignedPointerInInternalField(v8DOMWrapperObjectIndex, 0); | |
87 } | |
88 | |
89 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::L
ocal<v8::Object> wrapper) | 78 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, ScriptWrappable* impl, const WrapperTypeInfo* wrapperTypeInfo, v8::L
ocal<v8::Object> wrapper) |
90 { | 79 { |
91 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { | 80 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { |
92 wrapperTypeInfo->refObject(impl); | 81 wrapperTypeInfo->wrapperCreated(); |
93 setNativeInfo(wrapper, wrapperTypeInfo, impl); | 82 setNativeInfo(wrapper, wrapperTypeInfo, impl); |
94 ASSERT(hasInternalFieldsSet(wrapper)); | 83 ASSERT(hasInternalFieldsSet(wrapper)); |
95 } | 84 } |
96 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); | 85 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); |
97 return wrapper; | 86 return wrapper; |
98 } | 87 } |
99 | 88 |
100 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Ob
ject> wrapper) | 89 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(v8::Isolat
e* isolate, Node* node, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Ob
ject> wrapper) |
101 { | 90 { |
102 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { | 91 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { |
103 wrapperTypeInfo->refObject(ScriptWrappable::fromNode(node)); | 92 wrapperTypeInfo->wrapperCreated(); |
104 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node))
; | 93 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node))
; |
105 ASSERT(hasInternalFieldsSet(wrapper)); | 94 ASSERT(hasInternalFieldsSet(wrapper)); |
106 } | 95 } |
107 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node)
); | 96 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node)
); |
108 return wrapper; | 97 return wrapper; |
109 } | 98 } |
110 | 99 |
111 class V8WrapperInstantiationScope { | 100 class V8WrapperInstantiationScope { |
112 STACK_ALLOCATED(); | 101 STACK_ALLOCATED(); |
113 public: | 102 public: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 151 |
163 bool m_didEnterContext; | 152 bool m_didEnterContext; |
164 v8::Local<v8::Context> m_context; | 153 v8::Local<v8::Context> m_context; |
165 v8::TryCatch m_tryCatch; | 154 v8::TryCatch m_tryCatch; |
166 bool m_convertExceptions; | 155 bool m_convertExceptions; |
167 }; | 156 }; |
168 | 157 |
169 } // namespace blink | 158 } // namespace blink |
170 | 159 |
171 #endif // V8DOMWrapper_h | 160 #endif // V8DOMWrapper_h |
OLD | NEW |