Index: third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
index de725ff62ad418e8ad81b48123a14d602e1e0ba3..17af27eddc08ed087b75a733daf2f8e409dd7759 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
@@ -4,6 +4,7 @@ |
#include "bindings/core/v8/ScriptCustomElementDefinition.h" |
+#include "bindings/core/v8/ScriptController.h" |
#include "bindings/core/v8/ScriptState.h" |
#include "bindings/core/v8/V8Binding.h" |
#include "bindings/core/v8/V8BindingMacros.h" |
@@ -80,9 +81,10 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::forConstructor( |
return static_cast<ScriptCustomElementDefinition*>(definition); |
} |
+template <typename T> |
static void keepAlive(v8::Local<v8::Array>& array, uint32_t index, |
- const v8::Local<v8::Object>& value, |
- ScopedPersistent<v8::Object>& persistent, |
+ const v8::Local<T>& value, |
+ ScopedPersistent<T>& persistent, |
ScriptState* scriptState) |
{ |
if (value.IsEmpty()) |
@@ -100,9 +102,9 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::create( |
const CustomElementDescriptor& descriptor, |
const v8::Local<v8::Object>& constructor, |
const v8::Local<v8::Object>& prototype, |
- const v8::Local<v8::Object>& connectedCallback, |
- const v8::Local<v8::Object>& disconnectedCallback, |
- const v8::Local<v8::Object>& attributeChangedCallback, |
+ const v8::Local<v8::Function>& connectedCallback, |
+ const v8::Local<v8::Function>& disconnectedCallback, |
+ const v8::Local<v8::Function>& attributeChangedCallback, |
const HashSet<AtomicString>& observedAttributes) |
{ |
ScriptCustomElementDefinition* definition = |
@@ -141,15 +143,15 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition( |
const CustomElementDescriptor& descriptor, |
const v8::Local<v8::Object>& constructor, |
const v8::Local<v8::Object>& prototype, |
- const v8::Local<v8::Object>& connectedCallback, |
- const v8::Local<v8::Object>& disconnectedCallback, |
- const v8::Local<v8::Object>& attributeChangedCallback, |
+ const v8::Local<v8::Function>& connectedCallback, |
+ const v8::Local<v8::Function>& disconnectedCallback, |
+ const v8::Local<v8::Function>& attributeChangedCallback, |
const HashSet<AtomicString>& observedAttributes) |
: CustomElementDefinition(descriptor) |
, m_scriptState(scriptState) |
, m_constructor(scriptState->isolate(), constructor) |
- , m_observedAttributes(observedAttributes) |
{ |
+ m_observedAttributes = observedAttributes; |
dominicc (has gone to gerrit)
2016/06/14 09:19:45
We should make the CustomElementDefinition take ob
|
} |
// https://html.spec.whatwg.org/multipage/scripting.html#upgrades |
@@ -209,4 +211,72 @@ ScriptValue ScriptCustomElementDefinition::getConstructorForScript() |
return ScriptValue(m_scriptState.get(), constructor()); |
} |
+bool ScriptCustomElementDefinition::hasConnectedCallback() const |
+{ |
+ return !m_connectedCallback.isEmpty(); |
+} |
+ |
+bool ScriptCustomElementDefinition::hasDisconnectedCallback() const |
+{ |
+ return !m_disconnectedCallback.isEmpty(); |
+} |
+ |
+void ScriptCustomElementDefinition::runCallback( |
+ ScopedPersistent<v8::Function>& callback, |
+ Element* element, int argc, v8::Local<v8::Value> argv[]) |
+{ |
+ if (!m_scriptState->contextIsValid()) |
+ return; |
+ ScriptState::Scope scope(m_scriptState.get()); |
+ v8::Isolate* isolate = m_scriptState->isolate(); |
+ |
+ // Invoke custom element reactions |
+ // https://html.spec.whatwg.org/multipage/scripting.html#invoke-custom-element-reactions |
+ // If this throws any exception, then report the exception. |
+ v8::TryCatch tryCatch(isolate); |
+ tryCatch.SetVerbose(true); |
+ |
+ ExecutionContext* executionContext = m_scriptState->getExecutionContext(); |
+ v8::Local<v8::Value> elementHandle = toV8(element, |
+ m_scriptState->context()->Global(), isolate); |
+ ScriptController::callFunction( |
+ executionContext, |
+ callback.newLocal(isolate), |
+ elementHandle, |
+ argc, argv, isolate); |
+} |
+ |
+void ScriptCustomElementDefinition::runConnectedCallback(Element* element) |
+{ |
+ runCallback(m_connectedCallback, element); |
+} |
+ |
+void ScriptCustomElementDefinition::runDisconnectedCallback(Element* element) |
+{ |
+ runCallback(m_disconnectedCallback, element); |
+} |
+ |
+static v8::Local<v8::Value> v8StringOrNull(v8::Isolate* isolate, |
dominicc (has gone to gerrit)
2016/06/14 09:19:45
This is a nice little helper; maybe this should li
|
+ const AtomicString& value) |
+{ |
+ if (value.isNull()) |
+ return v8::Null(isolate); |
+ return v8String(isolate, value); |
+} |
+ |
+void ScriptCustomElementDefinition::runAttributeChangedCallback( |
+ Element* element, const QualifiedName& name, |
+ const AtomicString& oldValue, const AtomicString& newValue) |
+{ |
+ v8::Isolate* isolate = m_scriptState->isolate(); |
dominicc (has gone to gerrit)
2016/06/14 09:19:45
This needs to set up the ScriptState::Scope just l
|
+ const int argc = 4; |
+ v8::Local<v8::Value> argv[argc] = { |
+ v8String(isolate, name.localName()), |
+ v8StringOrNull(isolate, oldValue), |
+ v8StringOrNull(isolate, newValue), |
+ v8String(isolate, name.namespaceURI()), |
+ }; |
+ runCallback(m_attributeChangedCallback, element, argc, argv); |
+} |
+ |
} // namespace blink |