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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return 0; | 118 return 0; |
119 | 119 |
120 return V8PerContextData::from(context); | 120 return V8PerContextData::from(context); |
121 } | 121 } |
122 | 122 |
123 V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() | 123 V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() |
124 { | 124 { |
125 if (!m_owner) | 125 if (!m_owner) |
126 return; | 126 return; |
127 | 127 |
128 v8::HandleScope handleScope; | 128 v8::HandleScope handleScope(getIsolateFromScriptExecutionContext(scriptExecu
tionContext())); |
129 if (V8PerContextData* perContextData = creationContextData()) | 129 if (V8PerContextData* perContextData = creationContextData()) |
130 perContextData->clearCustomElementBinding(m_owner); | 130 perContextData->clearCustomElementBinding(m_owner); |
131 } | 131 } |
132 | 132 |
133 bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owne
r, PassOwnPtr<CustomElementBinding> binding) | 133 bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owne
r, PassOwnPtr<CustomElementBinding> binding) |
134 { | 134 { |
135 ASSERT(!m_owner); | 135 ASSERT(!m_owner); |
136 | 136 |
137 V8PerContextData* perContextData = creationContextData(); | 137 V8PerContextData* perContextData = creationContextData(); |
138 if (!perContextData) | 138 if (!perContextData) |
139 return false; | 139 return false; |
140 | 140 |
141 m_owner = owner; | 141 m_owner = owner; |
142 | 142 |
143 // Bindings retrieve the prototype when needed from per-context data. | 143 // Bindings retrieve the prototype when needed from per-context data. |
144 perContextData->addCustomElementBinding(owner, binding); | 144 perContextData->addCustomElementBinding(owner, binding); |
145 | 145 |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 void V8CustomElementLifecycleCallbacks::created(Element* element) | 149 void V8CustomElementLifecycleCallbacks::created(Element* element) |
150 { | 150 { |
151 if (!canInvokeCallback()) | 151 if (!canInvokeCallback()) |
152 return; | 152 return; |
153 | 153 |
154 element->setCustomElementState(Element::Upgraded); | 154 element->setCustomElementState(Element::Upgraded); |
155 | 155 |
156 v8::HandleScope handleScope; | 156 v8::Isolate* isolate = getIsolateFromScriptExecutionContext(scriptExecutionC
ontext()); |
| 157 v8::HandleScope handleScope(isolate); |
157 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 158 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
158 if (context.IsEmpty()) | 159 if (context.IsEmpty()) |
159 return; | 160 return; |
160 | 161 |
161 v8::Context::Scope scope(context); | 162 v8::Context::Scope scope(context); |
162 v8::Isolate* isolate = context->GetIsolate(); | |
163 | 163 |
164 v8::Handle<v8::Object> receiver = DOMDataStore::current(isolate)->get<V8Elem
ent>(element, isolate); | 164 v8::Handle<v8::Object> receiver = DOMDataStore::current(isolate)->get<V8Elem
ent>(element, isolate); |
165 if (!receiver.IsEmpty()) { | 165 if (!receiver.IsEmpty()) { |
166 // Swizzle the prototype of the existing wrapper. We don't need to | 166 // Swizzle the prototype of the existing wrapper. We don't need to |
167 // worry about non-existent wrappers; they will get the right | 167 // worry about non-existent wrappers; they will get the right |
168 // prototype when wrapped. | 168 // prototype when wrapped. |
169 v8::Handle<v8::Object> prototype = m_prototype.newLocal(isolate); | 169 v8::Handle<v8::Object> prototype = m_prototype.newLocal(isolate); |
170 if (prototype.IsEmpty()) | 170 if (prototype.IsEmpty()) |
171 return; | 171 return; |
172 receiver->SetPrototype(prototype); | 172 receiver->SetPrototype(prototype); |
(...skipping 21 matching lines...) Expand all Loading... |
194 void V8CustomElementLifecycleCallbacks::leftDocument(Element* element) | 194 void V8CustomElementLifecycleCallbacks::leftDocument(Element* element) |
195 { | 195 { |
196 call(m_leftDocument, element); | 196 call(m_leftDocument, element); |
197 } | 197 } |
198 | 198 |
199 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) | 199 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
200 { | 200 { |
201 if (!canInvokeCallback()) | 201 if (!canInvokeCallback()) |
202 return; | 202 return; |
203 | 203 |
204 v8::HandleScope handleScope; | 204 v8::Isolate* isolate = getIsolateFromScriptExecutionContext(scriptExecutionC
ontext()); |
| 205 v8::HandleScope handleScope(isolate); |
205 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 206 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
206 if (context.IsEmpty()) | 207 if (context.IsEmpty()) |
207 return; | 208 return; |
208 | 209 |
209 v8::Context::Scope scope(context); | 210 v8::Context::Scope scope(context); |
210 v8::Isolate* isolate = context->GetIsolate(); | |
211 | 211 |
212 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); | 212 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
213 ASSERT(!receiver.IsEmpty()); | 213 ASSERT(!receiver.IsEmpty()); |
214 | 214 |
215 v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate); | 215 v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate); |
216 if (callback.IsEmpty()) | 216 if (callback.IsEmpty()) |
217 return; | 217 return; |
218 | 218 |
219 v8::Handle<v8::Value> argv[] = { | 219 v8::Handle<v8::Value> argv[] = { |
220 v8String(name, isolate), | 220 v8String(name, isolate), |
221 oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V
alue>(v8String(oldValue, isolate)), | 221 oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V
alue>(v8String(oldValue, isolate)), |
222 newValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V
alue>(v8String(newValue, isolate)) | 222 newValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V
alue>(v8String(newValue, isolate)) |
223 }; | 223 }; |
224 | 224 |
225 v8::TryCatch exceptionCatcher; | 225 v8::TryCatch exceptionCatcher; |
226 exceptionCatcher.SetVerbose(true); | 226 exceptionCatcher.SetVerbose(true); |
227 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, WTF_ARRAY_LENGTH(argv), argv); | 227 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, WTF_ARRAY_LENGTH(argv), argv); |
228 } | 228 } |
229 | 229 |
230 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function
>& weakCallback, Element* element) | 230 void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function
>& weakCallback, Element* element) |
231 { | 231 { |
232 if (!canInvokeCallback()) | 232 if (!canInvokeCallback()) |
233 return; | 233 return; |
234 | 234 |
235 v8::HandleScope handleScope; | 235 v8::HandleScope handleScope(getIsolateFromScriptExecutionContext(scriptExecu
tionContext())); |
236 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 236 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
237 if (context.IsEmpty()) | 237 if (context.IsEmpty()) |
238 return; | 238 return; |
239 | 239 |
240 v8::Context::Scope scope(context); | 240 v8::Context::Scope scope(context); |
241 v8::Isolate* isolate = context->GetIsolate(); | 241 v8::Isolate* isolate = context->GetIsolate(); |
242 | 242 |
243 v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate); | 243 v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate); |
244 if (callback.IsEmpty()) | 244 if (callback.IsEmpty()) |
245 return; | 245 return; |
246 | 246 |
247 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); | 247 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
248 ASSERT(!receiver.IsEmpty()); | 248 ASSERT(!receiver.IsEmpty()); |
249 | 249 |
250 v8::TryCatch exceptionCatcher; | 250 v8::TryCatch exceptionCatcher; |
251 exceptionCatcher.SetVerbose(true); | 251 exceptionCatcher.SetVerbose(true); |
252 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0); | 252 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0); |
253 } | 253 } |
254 | 254 |
255 } // namespace WebCore | 255 } // namespace WebCore |
OLD | NEW |