Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include "config.h" |
| 32 | #include "bindings/v8/V8CustomElementLifecycleCallbacks.h" |
| 33 | |
| 34 | #include "V8Element.h" |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 35 | #include "bindings/v8/CustomElementBinding.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 36 | #include "bindings/v8/DOMDataStore.h" |
| 37 | #include "bindings/v8/ScriptController.h" |
| 38 | #include "bindings/v8/V8Binding.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame^] | 39 | #include "bindings/v8/V8HiddenValue.h" |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 40 | #include "bindings/v8/V8PerContextData.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 41 | #include "core/dom/ExecutionContext.h" |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 42 | #include "core/inspector/InspectorInstrumentation.h" |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 43 | #include "wtf/PassOwnPtr.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 44 | |
| 45 | namespace WebCore { |
| 46 | |
| 47 | #define CALLBACK_LIST(V) \ |
| 48 | V(created, Created) \ |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 49 | V(attached, Attached) \ |
| 50 | V(detached, Detached) \ |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 51 | V(attributeChanged, AttributeChanged) |
| 52 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 53 | PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks::create(ExecutionContext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detached, v8::Handle<v8::Function> attributeChanged) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 54 | { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 55 | v8::Isolate* isolate = toIsolate(executionContext); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 56 | // A given object can only be used as a Custom Element prototype |
| 57 | // once; see customElementIsInterfacePrototypeObject |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame^] | 58 | #define SET_HIDDEN_VALUE(Value, Name) \ |
| 59 | ASSERT(V8HiddenValue::getHiddenValue(isolate, prototype, V8HiddenValue::customElement##Name(isolate)).IsEmpty()); \ |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 60 | if (!Value.IsEmpty()) \ |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame^] | 61 | V8HiddenValue::setHiddenValue(isolate, prototype, V8HiddenValue::customElement##Name(isolate), Value); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 62 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame^] | 63 | CALLBACK_LIST(SET_HIDDEN_VALUE) |
| 64 | #undef SET_HIDDEN_VALUE |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 65 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 66 | return adoptRef(new V8CustomElementLifecycleCallbacks(executionContext, prototype, created, attached, detached, attributeChanged)); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 69 | static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detached, v8::Handle<v8::Function> attributeChanged) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 70 | { |
| 71 | // V8 Custom Elements always run created to swizzle prototypes. |
| 72 | int flags = CustomElementLifecycleCallbacks::Created; |
| 73 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 74 | if (!attached.IsEmpty()) |
| 75 | flags |= CustomElementLifecycleCallbacks::Attached; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 76 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 77 | if (!detached.IsEmpty()) |
| 78 | flags |= CustomElementLifecycleCallbacks::Detached; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 79 | |
| 80 | if (!attributeChanged.IsEmpty()) |
| 81 | flags |= CustomElementLifecycleCallbacks::AttributeChanged; |
| 82 | |
| 83 | return CustomElementLifecycleCallbacks::CallbackType(flags); |
| 84 | } |
| 85 | |
| 86 | template <typename T> |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 87 | static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& data) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 88 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 89 | data.GetParameter()->clear(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 92 | V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ExecutionContext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detached, v8::Handle<v8::Function> attributeChanged) |
| 93 | : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChanged)) |
| 94 | , ContextLifecycleObserver(executionContext) |
| 95 | , m_isolate(toIsolate(executionContext)) |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 96 | , m_owner(0) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 97 | , m_world(DOMWrapperWorld::current(m_isolate)) |
| 98 | , m_prototype(m_isolate, prototype) |
| 99 | , m_created(m_isolate, created) |
| 100 | , m_attached(m_isolate, attached) |
| 101 | , m_detached(m_isolate, detached) |
| 102 | , m_attributeChanged(m_isolate, attributeChanged) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 103 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 104 | m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 105 | |
| 106 | #define MAKE_WEAK(Var, _) \ |
| 107 | if (!m_##Var.isEmpty()) \ |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 108 | m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 109 | |
| 110 | CALLBACK_LIST(MAKE_WEAK) |
| 111 | #undef MAKE_WEAK |
| 112 | } |
| 113 | |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 114 | V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() |
| 115 | { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 116 | if (!executionContext()) |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 117 | return 0; |
| 118 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 119 | v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get()); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 120 | if (context.IsEmpty()) |
| 121 | return 0; |
| 122 | |
| 123 | return V8PerContextData::from(context); |
| 124 | } |
| 125 | |
| 126 | V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() |
| 127 | { |
| 128 | if (!m_owner) |
| 129 | return; |
| 130 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 131 | v8::HandleScope handleScope(m_isolate); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 132 | if (V8PerContextData* perContextData = creationContextData()) |
| 133 | perContextData->clearCustomElementBinding(m_owner); |
| 134 | } |
| 135 | |
| 136 | bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owner, PassOwnPtr<CustomElementBinding> binding) |
| 137 | { |
| 138 | ASSERT(!m_owner); |
| 139 | |
| 140 | V8PerContextData* perContextData = creationContextData(); |
| 141 | if (!perContextData) |
| 142 | return false; |
| 143 | |
| 144 | m_owner = owner; |
| 145 | |
| 146 | // Bindings retrieve the prototype when needed from per-context data. |
| 147 | perContextData->addCustomElementBinding(owner, binding); |
| 148 | |
| 149 | return true; |
| 150 | } |
| 151 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 152 | void V8CustomElementLifecycleCallbacks::created(Element* element) |
| 153 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 154 | // FIXME: callbacks while paused should be queued up for execution to |
| 155 | // continue then be delivered in order rather than delivered immediately. |
| 156 | // Bug 329665 tracks similar behavior for other synchronous events. |
| 157 | if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 158 | return; |
| 159 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 160 | element->setCustomElementState(Element::Upgraded); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 161 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 162 | v8::HandleScope handleScope(m_isolate); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 163 | v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 164 | if (context.IsEmpty()) |
| 165 | return; |
| 166 | |
| 167 | v8::Context::Scope scope(context); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 168 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 169 | v8::Handle<v8::Object> receiver = DOMDataStore::current(m_isolate).get<V8Element>(element, m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 170 | if (!receiver.IsEmpty()) { |
| 171 | // Swizzle the prototype of the existing wrapper. We don't need to |
| 172 | // worry about non-existent wrappers; they will get the right |
| 173 | // prototype when wrapped. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 174 | v8::Handle<v8::Object> prototype = m_prototype.newLocal(m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 175 | if (prototype.IsEmpty()) |
| 176 | return; |
| 177 | receiver->SetPrototype(prototype); |
| 178 | } |
| 179 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 180 | v8::Handle<v8::Function> callback = m_created.newLocal(m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 181 | if (callback.IsEmpty()) |
| 182 | return; |
| 183 | |
| 184 | if (receiver.IsEmpty()) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 185 | receiver = toV8(element, context->Global(), m_isolate).As<v8::Object>(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 186 | |
| 187 | ASSERT(!receiver.IsEmpty()); |
| 188 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 189 | InspectorInstrumentation::willExecuteCustomElementCallback(element); |
| 190 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 191 | v8::TryCatch exceptionCatcher; |
| 192 | exceptionCatcher.SetVerbose(true); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 193 | ScriptController::callFunction(executionContext(), callback, receiver, 0, 0, m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 194 | } |
| 195 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 196 | void V8CustomElementLifecycleCallbacks::attached(Element* element) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 197 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 198 | call(m_attached, element); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 199 | } |
| 200 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 201 | void V8CustomElementLifecycleCallbacks::detached(Element* element) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 202 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 203 | call(m_detached, element); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 207 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 208 | // FIXME: callbacks while paused should be queued up for execution to |
| 209 | // continue then be delivered in order rather than delivered immediately. |
| 210 | // Bug 329665 tracks similar behavior for other synchronous events. |
| 211 | if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 212 | return; |
| 213 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 214 | v8::HandleScope handleScope(m_isolate); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 215 | v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 216 | if (context.IsEmpty()) |
| 217 | return; |
| 218 | |
| 219 | v8::Context::Scope scope(context); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 220 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 221 | v8::Handle<v8::Object> receiver = toV8(element, context->Global(), m_isolate).As<v8::Object>(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 222 | ASSERT(!receiver.IsEmpty()); |
| 223 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 224 | v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 225 | if (callback.IsEmpty()) |
| 226 | return; |
| 227 | |
| 228 | v8::Handle<v8::Value> argv[] = { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 229 | v8String(m_isolate, name), |
| 230 | oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null(m_isolate)) : v8::Handle<v8::Value>(v8String(m_isolate, oldValue)), |
| 231 | newValue.isNull() ? v8::Handle<v8::Value>(v8::Null(m_isolate)) : v8::Handle<v8::Value>(v8String(m_isolate, newValue)) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 232 | }; |
| 233 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 234 | InspectorInstrumentation::willExecuteCustomElementCallback(element); |
| 235 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 236 | v8::TryCatch exceptionCatcher; |
| 237 | exceptionCatcher.SetVerbose(true); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 238 | ScriptController::callFunction(executionContext(), callback, receiver, WTF_ARRAY_LENGTH(argv), argv, m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function>& weakCallback, Element* element) |
| 242 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 243 | // FIXME: callbacks while paused should be queued up for execution to |
| 244 | // continue then be delivered in order rather than delivered immediately. |
| 245 | // Bug 329665 tracks similar behavior for other synchronous events. |
| 246 | if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 247 | return; |
| 248 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 249 | v8::HandleScope handleScope(m_isolate); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 250 | v8::Handle<v8::Context> context = toV8Context(executionContext(), m_world.get()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 251 | if (context.IsEmpty()) |
| 252 | return; |
| 253 | |
| 254 | v8::Context::Scope scope(context); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 255 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 256 | v8::Handle<v8::Function> callback = weakCallback.newLocal(m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 257 | if (callback.IsEmpty()) |
| 258 | return; |
| 259 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 260 | v8::Handle<v8::Object> receiver = toV8(element, context->Global(), m_isolate).As<v8::Object>(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 261 | ASSERT(!receiver.IsEmpty()); |
| 262 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 263 | InspectorInstrumentation::willExecuteCustomElementCallback(element); |
| 264 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 265 | v8::TryCatch exceptionCatcher; |
| 266 | exceptionCatcher.SetVerbose(true); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 267 | ScriptController::callFunction(executionContext(), callback, receiver, 0, 0, m_isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | } // namespace WebCore |