OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 template <typename T> | 86 template <typename T> |
87 static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& da
ta) | 87 static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& da
ta) |
88 { | 88 { |
89 data.GetParameter()->clear(); | 89 data.GetParameter()->clear(); |
90 } | 90 } |
91 | 91 |
92 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ExecutionCo
ntext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Functi
on> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detache
d, v8::Handle<v8::Function> attributeChanged) | 92 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ExecutionCo
ntext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Functi
on> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detache
d, v8::Handle<v8::Function> attributeChanged) |
93 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang
ed)) | 93 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang
ed)) |
94 , ContextLifecycleObserver(executionContext) | 94 , ContextLifecycleObserver(executionContext) |
95 , m_isolate(toIsolate(executionContext)) | |
96 , m_owner(0) | 95 , m_owner(0) |
97 , m_world(DOMWrapperWorld::current(m_isolate)) | 96 , m_scriptState(NewScriptState::current(toIsolate(executionContext))) |
98 , m_prototype(m_isolate, prototype) | 97 , m_prototype(m_scriptState->isolate(), prototype) |
99 , m_created(m_isolate, created) | 98 , m_created(m_scriptState->isolate(), created) |
100 , m_attached(m_isolate, attached) | 99 , m_attached(m_scriptState->isolate(), attached) |
101 , m_detached(m_isolate, detached) | 100 , m_detached(m_scriptState->isolate(), detached) |
102 , m_attributeChanged(m_isolate, attributeChanged) | 101 , m_attributeChanged(m_scriptState->isolate(), attributeChanged) |
103 { | 102 { |
104 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); | 103 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); |
105 | 104 |
106 #define MAKE_WEAK(Var, _) \ | 105 #define MAKE_WEAK(Var, _) \ |
107 if (!m_##Var.isEmpty()) \ | 106 if (!m_##Var.isEmpty()) \ |
108 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); | 107 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); |
109 | 108 |
110 CALLBACK_LIST(MAKE_WEAK) | 109 CALLBACK_LIST(MAKE_WEAK) |
111 #undef MAKE_WEAK | 110 #undef MAKE_WEAK |
112 } | 111 } |
113 | 112 |
114 V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() | 113 V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() |
115 { | 114 { |
116 if (!executionContext()) | 115 if (!executionContext()) |
117 return 0; | 116 return 0; |
118 | 117 |
119 v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world); | 118 v8::Handle<v8::Context> context = m_scriptState->context(); |
120 if (context.IsEmpty()) | 119 if (context.IsEmpty()) |
121 return 0; | 120 return 0; |
122 | 121 |
123 return V8PerContextData::from(context); | 122 return V8PerContextData::from(context); |
124 } | 123 } |
125 | 124 |
126 V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() | 125 V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() |
127 { | 126 { |
128 if (!m_owner) | 127 if (!m_owner) |
129 return; | 128 return; |
130 | 129 |
131 v8::HandleScope handleScope(m_isolate); | 130 v8::HandleScope handleScope(m_scriptState->isolate()); |
132 if (V8PerContextData* perContextData = creationContextData()) | 131 if (V8PerContextData* perContextData = creationContextData()) |
133 perContextData->clearCustomElementBinding(m_owner); | 132 perContextData->clearCustomElementBinding(m_owner); |
134 } | 133 } |
135 | 134 |
136 bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owne
r, PassOwnPtr<CustomElementBinding> binding) | 135 bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owne
r, PassOwnPtr<CustomElementBinding> binding) |
137 { | 136 { |
138 ASSERT(!m_owner); | 137 ASSERT(!m_owner); |
139 | 138 |
140 V8PerContextData* perContextData = creationContextData(); | 139 V8PerContextData* perContextData = creationContextData(); |
141 if (!perContextData) | 140 if (!perContextData) |
(...skipping 10 matching lines...) Expand all Loading... |
152 void V8CustomElementLifecycleCallbacks::created(Element* element) | 151 void V8CustomElementLifecycleCallbacks::created(Element* element) |
153 { | 152 { |
154 // FIXME: callbacks while paused should be queued up for execution to | 153 // FIXME: callbacks while paused should be queued up for execution to |
155 // continue then be delivered in order rather than delivered immediately. | 154 // continue then be delivered in order rather than delivered immediately. |
156 // Bug 329665 tracks similar behavior for other synchronous events. | 155 // Bug 329665 tracks similar behavior for other synchronous events. |
157 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 156 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
158 return; | 157 return; |
159 | 158 |
160 element->setCustomElementState(Element::Upgraded); | 159 element->setCustomElementState(Element::Upgraded); |
161 | 160 |
162 v8::HandleScope handleScope(m_isolate); | 161 v8::Isolate* isolate = m_scriptState->isolate(); |
163 v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world); | 162 v8::HandleScope handleScope(isolate); |
| 163 v8::Handle<v8::Context> context = m_scriptState->context(); |
164 if (context.IsEmpty()) | 164 if (context.IsEmpty()) |
165 return; | 165 return; |
166 | 166 |
167 v8::Context::Scope scope(context); | 167 v8::Context::Scope scope(context); |
168 | 168 |
169 v8::Handle<v8::Object> receiver = DOMDataStore::current(m_isolate).get<V8Ele
ment>(element, m_isolate); | 169 v8::Handle<v8::Object> receiver = DOMDataStore::current(isolate).get<V8Eleme
nt>(element, isolate); |
170 if (!receiver.IsEmpty()) { | 170 if (!receiver.IsEmpty()) { |
171 // Swizzle the prototype of the existing wrapper. We don't need to | 171 // Swizzle the prototype of the existing wrapper. We don't need to |
172 // worry about non-existent wrappers; they will get the right | 172 // worry about non-existent wrappers; they will get the right |
173 // prototype when wrapped. | 173 // prototype when wrapped. |
174 v8::Handle<v8::Object> prototype = m_prototype.newLocal(m_isolate); | 174 v8::Handle<v8::Object> prototype = m_prototype.newLocal(isolate); |
175 if (prototype.IsEmpty()) | 175 if (prototype.IsEmpty()) |
176 return; | 176 return; |
177 receiver->SetPrototype(prototype); | 177 receiver->SetPrototype(prototype); |
178 } | 178 } |
179 | 179 |
180 v8::Handle<v8::Function> callback = m_created.newLocal(m_isolate); | 180 v8::Handle<v8::Function> callback = m_created.newLocal(isolate); |
181 if (callback.IsEmpty()) | 181 if (callback.IsEmpty()) |
182 return; | 182 return; |
183 | 183 |
184 if (receiver.IsEmpty()) | 184 if (receiver.IsEmpty()) |
185 receiver = toV8(element, context->Global(), m_isolate).As<v8::Object>(); | 185 receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
186 | 186 |
187 ASSERT(!receiver.IsEmpty()); | 187 ASSERT(!receiver.IsEmpty()); |
188 | 188 |
189 InspectorInstrumentation::willExecuteCustomElementCallback(element); | 189 InspectorInstrumentation::willExecuteCustomElementCallback(element); |
190 | 190 |
191 v8::TryCatch exceptionCatcher; | 191 v8::TryCatch exceptionCatcher; |
192 exceptionCatcher.SetVerbose(true); | 192 exceptionCatcher.SetVerbose(true); |
193 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
m_isolate); | 193 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); |
194 } | 194 } |
195 | 195 |
196 void V8CustomElementLifecycleCallbacks::attached(Element* element) | 196 void V8CustomElementLifecycleCallbacks::attached(Element* element) |
197 { | 197 { |
198 call(m_attached, element); | 198 call(m_attached, element); |
199 } | 199 } |
200 | 200 |
201 void V8CustomElementLifecycleCallbacks::detached(Element* element) | 201 void V8CustomElementLifecycleCallbacks::detached(Element* element) |
202 { | 202 { |
203 call(m_detached, element); | 203 call(m_detached, element); |
204 } | 204 } |
205 | 205 |
206 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) | 206 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
207 { | 207 { |
208 // FIXME: callbacks while paused should be queued up for execution to | 208 // FIXME: callbacks while paused should be queued up for execution to |
209 // continue then be delivered in order rather than delivered immediately. | 209 // continue then be delivered in order rather than delivered immediately. |
210 // Bug 329665 tracks similar behavior for other synchronous events. | 210 // Bug 329665 tracks similar behavior for other synchronous events. |
211 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 211 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
212 return; | 212 return; |
213 | 213 |
214 v8::HandleScope handleScope(m_isolate); | 214 v8::Isolate* isolate = m_scriptState->isolate(); |
215 v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world); | 215 v8::HandleScope handleScope(isolate); |
| 216 v8::Handle<v8::Context> context = m_scriptState->context(); |
216 if (context.IsEmpty()) | 217 if (context.IsEmpty()) |
217 return; | 218 return; |
218 | 219 |
219 v8::Context::Scope scope(context); | 220 v8::Context::Scope scope(context); |
220 | 221 |
221 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), m_isolate
).As<v8::Object>(); | 222 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
222 ASSERT(!receiver.IsEmpty()); | 223 ASSERT(!receiver.IsEmpty()); |
223 | 224 |
224 v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(m_isolate); | 225 v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate); |
225 if (callback.IsEmpty()) | 226 if (callback.IsEmpty()) |
226 return; | 227 return; |
227 | 228 |
228 v8::Handle<v8::Value> argv[] = { | 229 v8::Handle<v8::Value> argv[] = { |
229 v8String(m_isolate, name), | 230 v8String(isolate, name), |
230 oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null(m_isolate)) : v8::Han
dle<v8::Value>(v8String(m_isolate, oldValue)), | 231 oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null(isolate)) : v8::Handl
e<v8::Value>(v8String(isolate, oldValue)), |
231 newValue.isNull() ? v8::Handle<v8::Value>(v8::Null(m_isolate)) : v8::Han
dle<v8::Value>(v8String(m_isolate, newValue)) | 232 newValue.isNull() ? v8::Handle<v8::Value>(v8::Null(isolate)) : v8::Handl
e<v8::Value>(v8String(isolate, newValue)) |
232 }; | 233 }; |
233 | 234 |
234 InspectorInstrumentation::willExecuteCustomElementCallback(element); | 235 InspectorInstrumentation::willExecuteCustomElementCallback(element); |
235 | 236 |
236 v8::TryCatch exceptionCatcher; | 237 v8::TryCatch exceptionCatcher; |
237 exceptionCatcher.SetVerbose(true); | 238 exceptionCatcher.SetVerbose(true); |
238 ScriptController::callFunction(executionContext(), callback, receiver, WTF_A
RRAY_LENGTH(argv), argv, m_isolate); | 239 ScriptController::callFunction(executionContext(), callback, receiver, WTF_A
RRAY_LENGTH(argv), argv, isolate); |
239 } | 240 } |
240 | 241 |
241 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function
>& weakCallback, Element* element) | 242 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function
>& weakCallback, Element* element) |
242 { | 243 { |
243 // FIXME: callbacks while paused should be queued up for execution to | 244 // FIXME: callbacks while paused should be queued up for execution to |
244 // continue then be delivered in order rather than delivered immediately. | 245 // continue then be delivered in order rather than delivered immediately. |
245 // Bug 329665 tracks similar behavior for other synchronous events. | 246 // Bug 329665 tracks similar behavior for other synchronous events. |
246 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 247 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
247 return; | 248 return; |
248 | 249 |
249 v8::HandleScope handleScope(m_isolate); | 250 v8::Isolate* isolate = m_scriptState->isolate(); |
250 v8::Handle<v8::Context> context = toV8Context(executionContext(), *m_world); | 251 v8::HandleScope handleScope(isolate); |
| 252 v8::Handle<v8::Context> context = m_scriptState->context(); |
251 if (context.IsEmpty()) | 253 if (context.IsEmpty()) |
252 return; | 254 return; |
253 | 255 |
254 v8::Context::Scope scope(context); | 256 v8::Context::Scope scope(context); |
255 | 257 |
256 v8::Handle<v8::Function> callback = weakCallback.newLocal(m_isolate); | 258 v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate); |
257 if (callback.IsEmpty()) | 259 if (callback.IsEmpty()) |
258 return; | 260 return; |
259 | 261 |
260 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), m_isolate
).As<v8::Object>(); | 262 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
261 ASSERT(!receiver.IsEmpty()); | 263 ASSERT(!receiver.IsEmpty()); |
262 | 264 |
263 InspectorInstrumentation::willExecuteCustomElementCallback(element); | 265 InspectorInstrumentation::willExecuteCustomElementCallback(element); |
264 | 266 |
265 v8::TryCatch exceptionCatcher; | 267 v8::TryCatch exceptionCatcher; |
266 exceptionCatcher.SetVerbose(true); | 268 exceptionCatcher.SetVerbose(true); |
267 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
m_isolate); | 269 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); |
268 } | 270 } |
269 | 271 |
270 } // namespace WebCore | 272 } // namespace WebCore |
OLD | NEW |