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" |
Ben Murdoch | 197021e | 2014-07-20 18:26:29 -0700 | [diff] [blame^] | 32 | #include "bindings/core/v8/V8CustomElementLifecycleCallbacks.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 33 | |
Ben Murdoch | 197021e | 2014-07-20 18:26:29 -0700 | [diff] [blame^] | 34 | #include "bindings/core/v8/CustomElementBinding.h" |
| 35 | #include "bindings/core/v8/DOMDataStore.h" |
| 36 | #include "bindings/core/v8/ScriptController.h" |
| 37 | #include "bindings/core/v8/V8Binding.h" |
Torne (Richard Coles) | f6b7aed | 2014-06-09 12:01:17 +0100 | [diff] [blame] | 38 | #include "bindings/core/v8/V8Element.h" |
Ben Murdoch | 197021e | 2014-07-20 18:26:29 -0700 | [diff] [blame^] | 39 | #include "bindings/core/v8/V8HiddenValue.h" |
| 40 | #include "bindings/core/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) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 53 | PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks::create(ScriptState* scriptState, 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) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 55 | v8::Isolate* isolate = scriptState->isolate(); |
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) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 66 | return adoptRef(new V8CustomElementLifecycleCallbacks(scriptState, 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) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 92 | V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptState* scriptState, 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) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 93 | : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChanged)) |
Torne (Richard Coles) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 94 | , ContextLifecycleObserver(scriptState->executionContext()) |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 95 | , m_owner(0) |
Torne (Richard Coles) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 96 | , m_scriptState(scriptState) |
| 97 | , m_prototype(scriptState->isolate(), prototype) |
| 98 | , m_created(scriptState->isolate(), created) |
| 99 | , m_attached(scriptState->isolate(), attached) |
| 100 | , m_detached(scriptState->isolate(), detached) |
| 101 | , m_attributeChanged(scriptState->isolate(), attributeChanged) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 102 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 103 | m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 104 | |
| 105 | #define MAKE_WEAK(Var, _) \ |
| 106 | if (!m_##Var.isEmpty()) \ |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 107 | m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 108 | |
| 109 | CALLBACK_LIST(MAKE_WEAK) |
| 110 | #undef MAKE_WEAK |
| 111 | } |
| 112 | |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 113 | V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() |
| 114 | { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 115 | if (!executionContext()) |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 116 | return 0; |
| 117 | |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 118 | v8::Handle<v8::Context> context = m_scriptState->context(); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 119 | if (context.IsEmpty()) |
| 120 | return 0; |
| 121 | |
| 122 | return V8PerContextData::from(context); |
| 123 | } |
| 124 | |
| 125 | V8CustomElementLifecycleCallbacks::~V8CustomElementLifecycleCallbacks() |
| 126 | { |
| 127 | if (!m_owner) |
| 128 | return; |
| 129 | |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 130 | v8::HandleScope handleScope(m_scriptState->isolate()); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 131 | if (V8PerContextData* perContextData = creationContextData()) |
| 132 | perContextData->clearCustomElementBinding(m_owner); |
| 133 | } |
| 134 | |
| 135 | bool V8CustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owner, PassOwnPtr<CustomElementBinding> binding) |
| 136 | { |
| 137 | ASSERT(!m_owner); |
| 138 | |
| 139 | V8PerContextData* perContextData = creationContextData(); |
| 140 | if (!perContextData) |
| 141 | return false; |
| 142 | |
| 143 | m_owner = owner; |
| 144 | |
| 145 | // Bindings retrieve the prototype when needed from per-context data. |
| 146 | perContextData->addCustomElementBinding(owner, binding); |
| 147 | |
| 148 | return true; |
| 149 | } |
| 150 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 151 | void V8CustomElementLifecycleCallbacks::created(Element* element) |
| 152 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 153 | // FIXME: callbacks while paused should be queued up for execution to |
| 154 | // continue then be delivered in order rather than delivered immediately. |
| 155 | // Bug 329665 tracks similar behavior for other synchronous events. |
| 156 | if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 157 | return; |
| 158 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 159 | element->setCustomElementState(Element::Upgraded); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 160 | |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame] | 161 | if (m_scriptState->contextIsEmpty()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 162 | return; |
Bo Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 163 | ScriptState::Scope scope(m_scriptState.get()); |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame] | 164 | v8::Isolate* isolate = m_scriptState->isolate(); |
| 165 | v8::Handle<v8::Context> context = m_scriptState->context(); |
Torne (Richard Coles) | d6cdb82 | 2014-06-03 10:59:05 +0100 | [diff] [blame] | 166 | v8::Handle<v8::Object> receiver = m_scriptState->world().domDataStore().get<V8Element>(element, isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 167 | if (!receiver.IsEmpty()) { |
| 168 | // Swizzle the prototype of the existing wrapper. We don't need to |
| 169 | // worry about non-existent wrappers; they will get the right |
| 170 | // prototype when wrapped. |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 171 | v8::Handle<v8::Object> prototype = m_prototype.newLocal(isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 172 | if (prototype.IsEmpty()) |
| 173 | return; |
| 174 | receiver->SetPrototype(prototype); |
| 175 | } |
| 176 | |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 177 | v8::Handle<v8::Function> callback = m_created.newLocal(isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 178 | if (callback.IsEmpty()) |
| 179 | return; |
| 180 | |
| 181 | if (receiver.IsEmpty()) |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 182 | receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 183 | |
| 184 | ASSERT(!receiver.IsEmpty()); |
| 185 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 186 | InspectorInstrumentation::willExecuteCustomElementCallback(element); |
| 187 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 188 | v8::TryCatch exceptionCatcher; |
| 189 | exceptionCatcher.SetVerbose(true); |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 190 | ScriptController::callFunction(executionContext(), callback, receiver, 0, 0, isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 193 | void V8CustomElementLifecycleCallbacks::attached(Element* element) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 194 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 195 | call(m_attached, element); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 198 | void V8CustomElementLifecycleCallbacks::detached(Element* element) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 199 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 200 | call(m_detached, element); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 204 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 205 | // FIXME: callbacks while paused should be queued up for execution to |
| 206 | // continue then be delivered in order rather than delivered immediately. |
| 207 | // Bug 329665 tracks similar behavior for other synchronous events. |
| 208 | if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 209 | return; |
| 210 | |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame] | 211 | if (m_scriptState->contextIsEmpty()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 212 | return; |
Bo Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 213 | ScriptState::Scope scope(m_scriptState.get()); |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame] | 214 | v8::Isolate* isolate = m_scriptState->isolate(); |
| 215 | v8::Handle<v8::Context> context = m_scriptState->context(); |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 216 | v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 217 | ASSERT(!receiver.IsEmpty()); |
| 218 | |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 219 | v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 220 | if (callback.IsEmpty()) |
| 221 | return; |
| 222 | |
| 223 | v8::Handle<v8::Value> argv[] = { |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 224 | v8String(isolate, name), |
| 225 | oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null(isolate)) : v8::Handle<v8::Value>(v8String(isolate, oldValue)), |
| 226 | newValue.isNull() ? v8::Handle<v8::Value>(v8::Null(isolate)) : v8::Handle<v8::Value>(v8String(isolate, newValue)) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 227 | }; |
| 228 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 229 | InspectorInstrumentation::willExecuteCustomElementCallback(element); |
| 230 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 231 | v8::TryCatch exceptionCatcher; |
| 232 | exceptionCatcher.SetVerbose(true); |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 233 | ScriptController::callFunction(executionContext(), callback, receiver, WTF_ARRAY_LENGTH(argv), argv, isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void V8CustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function>& weakCallback, Element* element) |
| 237 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 238 | // FIXME: callbacks while paused should be queued up for execution to |
| 239 | // continue then be delivered in order rather than delivered immediately. |
| 240 | // Bug 329665 tracks similar behavior for other synchronous events. |
| 241 | if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 242 | return; |
| 243 | |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame] | 244 | if (m_scriptState->contextIsEmpty()) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 245 | return; |
Bo Liu | f91f5fa | 2014-05-01 10:37:55 -0700 | [diff] [blame] | 246 | ScriptState::Scope scope(m_scriptState.get()); |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame] | 247 | v8::Isolate* isolate = m_scriptState->isolate(); |
| 248 | v8::Handle<v8::Context> context = m_scriptState->context(); |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 249 | v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 250 | if (callback.IsEmpty()) |
| 251 | return; |
| 252 | |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 253 | v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 254 | ASSERT(!receiver.IsEmpty()); |
| 255 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 256 | InspectorInstrumentation::willExecuteCustomElementCallback(element); |
| 257 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 258 | v8::TryCatch exceptionCatcher; |
| 259 | exceptionCatcher.SetVerbose(true); |
Ben Murdoch | aafa69c | 2014-04-03 12:30:15 +0100 | [diff] [blame] | 260 | ScriptController::callFunction(executionContext(), callback, receiver, 0, 0, isolate); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | } // namespace WebCore |