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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 template <typename T> | 84 template <typename T> |
85 static void weakCallback(const v8::WeakCallbackInfo<ScopedPersistent<T>>& data) | 85 static void weakCallback(const v8::WeakCallbackInfo<ScopedPersistent<T>>& data) |
86 { | 86 { |
87 data.GetParameter()->clear(); | 87 data.GetParameter()->clear(); |
88 } | 88 } |
89 | 89 |
90 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptState
* scriptState, v8::Local<v8::Object> prototype, v8::MaybeLocal<v8::Function> cre
ated, v8::MaybeLocal<v8::Function> attached, v8::MaybeLocal<v8::Function> detach
ed, v8::MaybeLocal<v8::Function> attributeChanged) | 90 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptState
* scriptState, v8::Local<v8::Object> prototype, v8::MaybeLocal<v8::Function> cre
ated, v8::MaybeLocal<v8::Function> attached, v8::MaybeLocal<v8::Function> detach
ed, v8::MaybeLocal<v8::Function> attributeChanged) |
91 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang
ed)) | 91 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang
ed)) |
92 , ContextLifecycleObserver(scriptState->executionContext()) | 92 , ContextLifecycleObserver(scriptState->getExecutionContext()) |
93 , m_scriptState(scriptState) | 93 , m_scriptState(scriptState) |
94 , m_prototype(scriptState->isolate(), prototype) | 94 , m_prototype(scriptState->isolate(), prototype) |
95 , m_created(scriptState->isolate(), created) | 95 , m_created(scriptState->isolate(), created) |
96 , m_attached(scriptState->isolate(), attached) | 96 , m_attached(scriptState->isolate(), attached) |
97 , m_detached(scriptState->isolate(), detached) | 97 , m_detached(scriptState->isolate(), detached) |
98 , m_attributeChanged(scriptState->isolate(), attributeChanged) | 98 , m_attributeChanged(scriptState->isolate(), attributeChanged) |
99 { | 99 { |
100 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); | 100 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); |
101 | 101 |
102 #define MAKE_WEAK(Var, _) \ | 102 #define MAKE_WEAK(Var, _) \ |
103 if (!m_##Var.isEmpty()) \ | 103 if (!m_##Var.isEmpty()) \ |
104 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); | 104 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); |
105 | 105 |
106 CALLBACK_LIST(MAKE_WEAK) | 106 CALLBACK_LIST(MAKE_WEAK) |
107 #undef MAKE_WEAK | 107 #undef MAKE_WEAK |
108 } | 108 } |
109 | 109 |
110 V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() | 110 V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() |
111 { | 111 { |
112 if (!executionContext()) | 112 if (!getExecutionContext()) |
113 return 0; | 113 return 0; |
114 | 114 |
115 v8::Local<v8::Context> context = m_scriptState->context(); | 115 v8::Local<v8::Context> context = m_scriptState->context(); |
116 if (context.IsEmpty()) | 116 if (context.IsEmpty()) |
117 return 0; | 117 return 0; |
118 | 118 |
119 return V8PerContextData::from(context); | 119 return V8PerContextData::from(context); |
120 } | 120 } |
121 | 121 |
122 V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() | 122 V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() |
(...skipping 11 matching lines...) Expand all Loading... |
134 // references; see CALLBACK_LIST(SET_HIDDEN_VALUE). | 134 // references; see CALLBACK_LIST(SET_HIDDEN_VALUE). |
135 perContextData->addCustomElementBinding(owner, std::move(binding)); | 135 perContextData->addCustomElementBinding(owner, std::move(binding)); |
136 return true; | 136 return true; |
137 } | 137 } |
138 | 138 |
139 void V8CustomElementLifecycleCallbacks::created(Element* element) | 139 void V8CustomElementLifecycleCallbacks::created(Element* element) |
140 { | 140 { |
141 // FIXME: callbacks while paused should be queued up for execution to | 141 // FIXME: callbacks while paused should be queued up for execution to |
142 // continue then be delivered in order rather than delivered immediately. | 142 // continue then be delivered in order rather than delivered immediately. |
143 // Bug 329665 tracks similar behavior for other synchronous events. | 143 // Bug 329665 tracks similar behavior for other synchronous events. |
144 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 144 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop
ped()) |
145 return; | 145 return; |
146 | 146 |
147 if (!m_scriptState->contextIsValid()) | 147 if (!m_scriptState->contextIsValid()) |
148 return; | 148 return; |
149 | 149 |
150 element->setCustomElementState(Element::Upgraded); | 150 element->setCustomElementState(Element::Upgraded); |
151 | 151 |
152 ScriptState::Scope scope(m_scriptState.get()); | 152 ScriptState::Scope scope(m_scriptState.get()); |
153 v8::Isolate* isolate = m_scriptState->isolate(); | 153 v8::Isolate* isolate = m_scriptState->isolate(); |
154 v8::Local<v8::Context> context = m_scriptState->context(); | 154 v8::Local<v8::Context> context = m_scriptState->context(); |
155 v8::Local<v8::Value> receiverValue = toV8(element, context->Global(), isolat
e); | 155 v8::Local<v8::Value> receiverValue = toV8(element, context->Global(), isolat
e); |
156 if (receiverValue.IsEmpty()) | 156 if (receiverValue.IsEmpty()) |
157 return; | 157 return; |
158 v8::Local<v8::Object> receiver = receiverValue.As<v8::Object>(); | 158 v8::Local<v8::Object> receiver = receiverValue.As<v8::Object>(); |
159 | 159 |
160 // Swizzle the prototype of the wrapper. | 160 // Swizzle the prototype of the wrapper. |
161 v8::Local<v8::Object> prototype = m_prototype.newLocal(isolate); | 161 v8::Local<v8::Object> prototype = m_prototype.newLocal(isolate); |
162 if (prototype.IsEmpty()) | 162 if (prototype.IsEmpty()) |
163 return; | 163 return; |
164 if (!v8CallBoolean(receiver->SetPrototype(context, prototype))) | 164 if (!v8CallBoolean(receiver->SetPrototype(context, prototype))) |
165 return; | 165 return; |
166 | 166 |
167 v8::Local<v8::Function> callback = m_created.newLocal(isolate); | 167 v8::Local<v8::Function> callback = m_created.newLocal(isolate); |
168 if (callback.IsEmpty()) | 168 if (callback.IsEmpty()) |
169 return; | 169 return; |
170 | 170 |
171 v8::TryCatch exceptionCatcher(isolate); | 171 v8::TryCatch exceptionCatcher(isolate); |
172 exceptionCatcher.SetVerbose(true); | 172 exceptionCatcher.SetVerbose(true); |
173 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); | 173 ScriptController::callFunction(getExecutionContext(), callback, receiver, 0,
0, isolate); |
174 } | 174 } |
175 | 175 |
176 void V8CustomElementLifecycleCallbacks::attached(Element* element) | 176 void V8CustomElementLifecycleCallbacks::attached(Element* element) |
177 { | 177 { |
178 call(m_attached, element); | 178 call(m_attached, element); |
179 } | 179 } |
180 | 180 |
181 void V8CustomElementLifecycleCallbacks::detached(Element* element) | 181 void V8CustomElementLifecycleCallbacks::detached(Element* element) |
182 { | 182 { |
183 call(m_detached, element); | 183 call(m_detached, element); |
184 } | 184 } |
185 | 185 |
186 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) | 186 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
187 { | 187 { |
188 // FIXME: callbacks while paused should be queued up for execution to | 188 // FIXME: callbacks while paused should be queued up for execution to |
189 // continue then be delivered in order rather than delivered immediately. | 189 // continue then be delivered in order rather than delivered immediately. |
190 // Bug 329665 tracks similar behavior for other synchronous events. | 190 // Bug 329665 tracks similar behavior for other synchronous events. |
191 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 191 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop
ped()) |
192 return; | 192 return; |
193 | 193 |
194 if (!m_scriptState->contextIsValid()) | 194 if (!m_scriptState->contextIsValid()) |
195 return; | 195 return; |
196 ScriptState::Scope scope(m_scriptState.get()); | 196 ScriptState::Scope scope(m_scriptState.get()); |
197 v8::Isolate* isolate = m_scriptState->isolate(); | 197 v8::Isolate* isolate = m_scriptState->isolate(); |
198 v8::Local<v8::Context> context = m_scriptState->context(); | 198 v8::Local<v8::Context> context = m_scriptState->context(); |
199 v8::Local<v8::Value> receiver = toV8(element, context->Global(), isolate); | 199 v8::Local<v8::Value> receiver = toV8(element, context->Global(), isolate); |
200 if (receiver.IsEmpty()) | 200 if (receiver.IsEmpty()) |
201 return; | 201 return; |
202 | 202 |
203 v8::Local<v8::Function> callback = m_attributeChanged.newLocal(isolate); | 203 v8::Local<v8::Function> callback = m_attributeChanged.newLocal(isolate); |
204 if (callback.IsEmpty()) | 204 if (callback.IsEmpty()) |
205 return; | 205 return; |
206 | 206 |
207 v8::Local<v8::Value> argv[] = { | 207 v8::Local<v8::Value> argv[] = { |
208 v8String(isolate, name), | 208 v8String(isolate, name), |
209 oldValue.isNull() ? v8::Local<v8::Value>(v8::Null(isolate)) : v8::Local<
v8::Value>(v8String(isolate, oldValue)), | 209 oldValue.isNull() ? v8::Local<v8::Value>(v8::Null(isolate)) : v8::Local<
v8::Value>(v8String(isolate, oldValue)), |
210 newValue.isNull() ? v8::Local<v8::Value>(v8::Null(isolate)) : v8::Local<
v8::Value>(v8String(isolate, newValue)) | 210 newValue.isNull() ? v8::Local<v8::Value>(v8::Null(isolate)) : v8::Local<
v8::Value>(v8String(isolate, newValue)) |
211 }; | 211 }; |
212 | 212 |
213 v8::TryCatch exceptionCatcher(isolate); | 213 v8::TryCatch exceptionCatcher(isolate); |
214 exceptionCatcher.SetVerbose(true); | 214 exceptionCatcher.SetVerbose(true); |
215 ScriptController::callFunction(executionContext(), callback, receiver, WTF_A
RRAY_LENGTH(argv), argv, isolate); | 215 ScriptController::callFunction(getExecutionContext(), callback, receiver, WT
F_ARRAY_LENGTH(argv), argv, isolate); |
216 } | 216 } |
217 | 217 |
218 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function
>& weakCallback, Element* element) | 218 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function
>& weakCallback, Element* element) |
219 { | 219 { |
220 // FIXME: callbacks while paused should be queued up for execution to | 220 // FIXME: callbacks while paused should be queued up for execution to |
221 // continue then be delivered in order rather than delivered immediately. | 221 // continue then be delivered in order rather than delivered immediately. |
222 // Bug 329665 tracks similar behavior for other synchronous events. | 222 // Bug 329665 tracks similar behavior for other synchronous events. |
223 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 223 if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStop
ped()) |
224 return; | 224 return; |
225 | 225 |
226 if (!m_scriptState->contextIsValid()) | 226 if (!m_scriptState->contextIsValid()) |
227 return; | 227 return; |
228 ScriptState::Scope scope(m_scriptState.get()); | 228 ScriptState::Scope scope(m_scriptState.get()); |
229 v8::Isolate* isolate = m_scriptState->isolate(); | 229 v8::Isolate* isolate = m_scriptState->isolate(); |
230 v8::Local<v8::Context> context = m_scriptState->context(); | 230 v8::Local<v8::Context> context = m_scriptState->context(); |
231 v8::Local<v8::Function> callback = weakCallback.newLocal(isolate); | 231 v8::Local<v8::Function> callback = weakCallback.newLocal(isolate); |
232 if (callback.IsEmpty()) | 232 if (callback.IsEmpty()) |
233 return; | 233 return; |
234 | 234 |
235 v8::Local<v8::Value> receiver = toV8(element, context->Global(), isolate); | 235 v8::Local<v8::Value> receiver = toV8(element, context->Global(), isolate); |
236 if (receiver.IsEmpty()) | 236 if (receiver.IsEmpty()) |
237 return; | 237 return; |
238 | 238 |
239 v8::TryCatch exceptionCatcher(isolate); | 239 v8::TryCatch exceptionCatcher(isolate); |
240 exceptionCatcher.SetVerbose(true); | 240 exceptionCatcher.SetVerbose(true); |
241 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); | 241 ScriptController::callFunction(getExecutionContext(), callback, receiver, 0,
0, isolate); |
242 } | 242 } |
243 | 243 |
244 DEFINE_TRACE(V8CustomElementLifecycleCallbacks) | 244 DEFINE_TRACE(V8CustomElementLifecycleCallbacks) |
245 { | 245 { |
246 CustomElementLifecycleCallbacks::trace(visitor); | 246 CustomElementLifecycleCallbacks::trace(visitor); |
247 ContextLifecycleObserver::trace(visitor); | 247 ContextLifecycleObserver::trace(visitor); |
248 } | 248 } |
249 | 249 |
250 } // namespace blink | 250 } // namespace blink |
OLD | NEW |