Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp

Issue 18789002: Implement Custom Elements' attributeChangedCallback. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Sync to tip. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/V8CustomElementLifecycleCallbacks.h ('k') | Source/bindings/v8/V8HiddenPropertyName.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
diff --git a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
index 200c905f14c5869ac5acf3e94f9c771820f74cdd..62d711157746f964896a9f05284d720fbfb57d17 100644
--- a/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
+++ b/Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp
@@ -42,13 +42,15 @@
namespace WebCore {
-PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks::create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created)
+PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks::create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> attributeChanged)
{
// A given object can only be used as a Custom Element prototype once, see isCustomElementInterfacePrototypeObject
- ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElementCreated()).IsEmpty());
+ ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElementCreated()).IsEmpty() && prototype->GetHiddenValue(V8HiddenPropertyName::customElementAttributeChanged()).IsEmpty());
if (!created.IsEmpty())
prototype->SetHiddenValue(V8HiddenPropertyName::customElementCreated(), created);
- return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext, prototype, created));
+ if (!attributeChanged.IsEmpty())
+ prototype->SetHiddenValue(V8HiddenPropertyName::customElementAttributeChanged(), attributeChanged);
+ return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext, prototype, created, attributeChanged));
}
template <typename T>
@@ -57,16 +59,19 @@ static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>*
handle->clear();
}
-V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created)
- : CustomElementLifecycleCallbacks(Created)
+V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> attributeChanged)
+ : CustomElementLifecycleCallbacks(CallbackType(Created | (attributeChanged.IsEmpty() ? None : AttributeChanged)))
, ActiveDOMCallback(scriptExecutionContext)
, m_world(DOMWrapperWorld::current())
, m_prototype(prototype)
, m_created(created)
+ , m_attributeChanged(attributeChanged)
{
m_prototype.makeWeak(&m_prototype, weakCallback<v8::Object>);
if (!m_created.isEmpty())
m_created.makeWeak(&m_created, weakCallback<v8::Function>);
+ if (!m_attributeChanged.isEmpty())
+ m_attributeChanged.makeWeak(&m_attributeChanged, weakCallback<v8::Function>);
}
void V8CustomElementLifecycleCallbacks::created(Element* element)
@@ -109,4 +114,35 @@ void V8CustomElementLifecycleCallbacks::created(Element* element)
ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0);
}
+void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
+{
+ if (!canInvokeCallback())
+ return;
+
+ v8::HandleScope handleScope;
+ v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get());
+ if (context.IsEmpty())
+ return;
+
+ v8::Context::Scope scope(context);
+ v8::Isolate* isolate = context->GetIsolate();
+
+ v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).As<v8::Object>();
+ ASSERT(!receiver.IsEmpty());
+
+ v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate);
+ if (callback.IsEmpty())
+ return;
+
+ v8::Handle<v8::Value> argv[] = {
+ v8String(name, isolate),
+ oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::Value>(v8String(oldValue, isolate)),
+ newValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::Value>(v8String(newValue, isolate))
+ };
+
+ v8::TryCatch exceptionCatcher;
+ exceptionCatcher.SetVerbose(true);
+ ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, sizeof(argv) / sizeof(v8::Handle<v8::Value>), argv);
+}
+
} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/V8CustomElementLifecycleCallbacks.h ('k') | Source/bindings/v8/V8HiddenPropertyName.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698