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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp

Issue 2024073002: Add callbacks to ScriptCustomElementDefinition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dominicc, yosin review Created 4 years, 7 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
Index: third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp
index 39da9922a20331c868b3889186b2f20796ec9a0a..dcd2186f3c598e6552ead0066dafffdc805c80e3 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinitionBuilder.cpp
@@ -60,17 +60,21 @@ bool ScriptCustomElementDefinitionBuilder::checkConstructorNotRegistered()
return true;
}
-bool ScriptCustomElementDefinitionBuilder::checkPrototype()
+bool ScriptCustomElementDefinitionBuilder::valueForName(
+ const v8::Local<v8::Object>& object, const char* name,
+ v8::Local<v8::Value>& value) const
{
v8::Isolate* isolate = m_scriptState->isolate();
v8::Local<v8::Context> context = m_scriptState->context();
- v8::Local<v8::String> prototypeString =
- v8AtomicString(isolate, "prototype");
+ v8::Local<v8::String> nameString = v8AtomicString(isolate, name);
+ return v8Call(object->Get(context, nameString), value);
+}
+
+bool ScriptCustomElementDefinitionBuilder::checkPrototype()
+{
v8::Local<v8::Value> prototypeValue;
- if (!v8Call(
- m_constructor->Get(context, prototypeString), prototypeValue)) {
+ if (!valueForName(m_constructor, "prototype", prototypeValue))
return false;
- }
if (!prototypeValue->IsObject()) {
m_exceptionState.throwTypeError(
"constructor prototype is not an object");
@@ -82,6 +86,60 @@ bool ScriptCustomElementDefinitionBuilder::checkPrototype()
return true;
}
+bool ScriptCustomElementDefinitionBuilder::callableForName(const char* name,
+ v8::Local<v8::Object>& callback) const
+{
+ v8::Local<v8::Value> value;
+ if (!valueForName(m_prototype, name, value))
+ return false;
+ if (value->IsUndefined())
+ return true;
+ if (!value->IsObject()) {
+ m_exceptionState.throwTypeError(
+ String::format("\"%s\" is not an object", name));
+ return false;
+ }
+ callback = value.As<v8::Object>();
+ if (!callback->IsCallable()) {
+ m_exceptionState.throwTypeError(
+ String::format("\"%s\" is not callable", name));
+ return false;
+ }
+ return true;
+}
+
+bool ScriptCustomElementDefinitionBuilder::cacheObservedAttributes()
+{
+ const char* observedAttributes = "observedAttributes";
yosin_UTC9 2016/06/02 04:30:31 const char* const kObservedAttributes = "observedA
kojii 2016/06/02 04:47:13 Done.
+ v8::Local<v8::Value> observedAttributesValue;
+ if (!valueForName(m_constructor, observedAttributes, observedAttributesValue))
+ return false;
+ if (observedAttributesValue->IsUndefined())
+ return true;
+ Vector<AtomicString> list = toImplArray<Vector<AtomicString>>(
+ observedAttributesValue, 0, m_scriptState->isolate(), m_exceptionState);
+ if (m_exceptionState.hadException())
+ return false;
+ if (list.isEmpty())
+ return true;
+ m_observedAttributes.reserveCapacityForSize(list.size());
+ for (const auto& attribute : list)
+ m_observedAttributes.add(attribute);
+ return true;
+}
+
+bool ScriptCustomElementDefinitionBuilder::cacheProperties()
+{
+
+ const char* connectedCallback = "connectedCallback";
yosin_UTC9 2016/06/02 04:30:31 const char* const kConnectedCallback= "connectedCa
kojii 2016/06/02 04:47:13 Done.
+ const char* disconnectedCallback = "disconnectedCallback";
+ const char* attributeChangedCallback = "attributeChangedCallback";
+ return cacheObservedAttributes()
+ && callableForName(connectedCallback, m_connectedCallback)
+ && callableForName(disconnectedCallback, m_disconnectedCallback)
+ && callableForName(attributeChangedCallback, m_attributeChangedCallback);
+}
+
CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build(
const CustomElementDescriptor& descriptor)
{
@@ -90,7 +148,11 @@ CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build(
m_registry,
descriptor,
m_constructor,
- m_prototype);
+ m_prototype,
+ m_connectedCallback,
+ m_disconnectedCallback,
+ m_attributeChangedCallback,
+ m_observedAttributes);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698