| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 template <typename T> | 84 template <typename T> |
| 85 static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>*
handle) | 85 static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>*
handle) |
| 86 { | 86 { |
| 87 handle->clear(); | 87 handle->clear(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu
tionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handl
e<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Fu
nction> leftView, v8::Handle<v8::Function> attributeChanged) | 90 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu
tionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handl
e<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Fu
nction> leftView, v8::Handle<v8::Function> attributeChanged) |
| 91 : CustomElementLifecycleCallbacks(flagSet(enteredView, leftView, attributeCh
anged)) | 91 : CustomElementLifecycleCallbacks(flagSet(enteredView, leftView, attributeCh
anged)) |
| 92 , ActiveDOMCallback(scriptExecutionContext) | 92 , ActiveDOMCallback(scriptExecutionContext) |
| 93 , m_world(DOMWrapperWorld::current()) | 93 , m_world(DOMWrapperWorld::current()) |
| 94 , m_prototype(isolateForScriptExecutionContext(scriptExecutionContext), prot
otype) | 94 , m_prototype(toIsolate(scriptExecutionContext), prototype) |
| 95 , m_created(isolateForScriptExecutionContext(scriptExecutionContext), create
d) | 95 , m_created(toIsolate(scriptExecutionContext), created) |
| 96 , m_enteredView(isolateForScriptExecutionContext(scriptExecutionContext), en
teredView) | 96 , m_enteredView(toIsolate(scriptExecutionContext), enteredView) |
| 97 , m_leftView(isolateForScriptExecutionContext(scriptExecutionContext), leftV
iew) | 97 , m_leftView(toIsolate(scriptExecutionContext), leftView) |
| 98 , m_attributeChanged(isolateForScriptExecutionContext(scriptExecutionContext
), attributeChanged) | 98 , m_attributeChanged(toIsolate(scriptExecutionContext), attributeChanged) |
| 99 , m_owner(0) | 99 , m_owner(0) |
| 100 { | 100 { |
| 101 m_prototype.makeWeak(&m_prototype, weakCallback<v8::Object>); | 101 m_prototype.makeWeak(&m_prototype, weakCallback<v8::Object>); |
| 102 | 102 |
| 103 #define MAKE_WEAK(Var, _) \ | 103 #define MAKE_WEAK(Var, _) \ |
| 104 if (!m_##Var.isEmpty()) \ | 104 if (!m_##Var.isEmpty()) \ |
| 105 m_##Var.makeWeak(&m_##Var, weakCallback<v8::Function>); | 105 m_##Var.makeWeak(&m_##Var, weakCallback<v8::Function>); |
| 106 | 106 |
| 107 CALLBACK_LIST(MAKE_WEAK) | 107 CALLBACK_LIST(MAKE_WEAK) |
| 108 #undef MAKE_WEAK | 108 #undef MAKE_WEAK |
| 109 } | 109 } |
| 110 | 110 |
| 111 V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() | 111 V8PerContextData* V8CustomElementLifecycleCallbacks::creationContextData() |
| 112 { | 112 { |
| 113 if (!scriptExecutionContext()) | 113 if (!scriptExecutionContext()) |
| 114 return 0; | 114 return 0; |
| 115 | 115 |
| 116 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 116 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
| 117 if (context.IsEmpty()) | 117 if (context.IsEmpty()) |
| 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(isolateForScriptExecutionContext(scriptExecution
Context())); | 128 v8::HandleScope handleScope(toIsolate(scriptExecutionContext())); |
| 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::Isolate* isolate = isolateForScriptExecutionContext(scriptExecutionConte
xt()); | 156 v8::Isolate* isolate = toIsolate(scriptExecutionContext()); |
| 157 v8::HandleScope handleScope(isolate); | 157 v8::HandleScope handleScope(isolate); |
| 158 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 158 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
| 159 if (context.IsEmpty()) | 159 if (context.IsEmpty()) |
| 160 return; | 160 return; |
| 161 | 161 |
| 162 v8::Context::Scope scope(context); | 162 v8::Context::Scope scope(context); |
| 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 194 void V8CustomElementLifecycleCallbacks::leftView(Element* element) | 194 void V8CustomElementLifecycleCallbacks::leftView(Element* element) |
| 195 { | 195 { |
| 196 call(m_leftView, element); | 196 call(m_leftView, 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::Isolate* isolate = isolateForScriptExecutionContext(scriptExecutionConte
xt()); | 204 v8::Isolate* isolate = toIsolate(scriptExecutionContext()); |
| 205 v8::HandleScope handleScope(isolate); | 205 v8::HandleScope handleScope(isolate); |
| 206 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 206 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
| 207 if (context.IsEmpty()) | 207 if (context.IsEmpty()) |
| 208 return; | 208 return; |
| 209 | 209 |
| 210 v8::Context::Scope scope(context); | 210 v8::Context::Scope scope(context); |
| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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, isolate); | 227 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, WTF_ARRAY_LENGTH(argv), argv, isolate); |
| 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(isolateForScriptExecutionContext(scriptExecution
Context())); | 235 v8::HandleScope handleScope(toIsolate(scriptExecutionContext())); |
| 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, isolate); | 252 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0, isolate); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace WebCore | 255 } // namespace WebCore |
| OLD | NEW |