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 d0d3bd051180dce7ef6a8ad89f2a005361ff7fe8..a3a0866243d8211221ec5cab635bafc2b295a06a 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
@@ -74,19 +74,41 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::forConstructor( |
return static_cast<ScriptCustomElementDefinition*>(definition); |
} |
+static void keepAliveIfNotEmpty(v8::Local<v8::Array>& array, uint32_t index, |
+ const v8::Local<v8::Object>& value, |
+ ScopedPersistent<v8::Object>& persistent, |
+ ScriptState* scriptState) |
+{ |
+ if (value.IsEmpty()) |
+ return; |
+ |
+ v8CallOrCrash(array->Set(scriptState->context(), index, value)); |
+ |
+ persistent.set(scriptState->isolate(), value); |
+ persistent.setPhantom(); |
+} |
+ |
ScriptCustomElementDefinition* ScriptCustomElementDefinition::create( |
ScriptState* scriptState, |
CustomElementsRegistry* registry, |
const CustomElementDescriptor& descriptor, |
const v8::Local<v8::Object>& constructor, |
- const v8::Local<v8::Object>& prototype) |
+ 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 Vector<AtomicString>& observedAttributes) |
{ |
ScriptCustomElementDefinition* definition = |
new ScriptCustomElementDefinition( |
scriptState, |
descriptor, |
constructor, |
- prototype); |
+ prototype, |
+ connectedCallback, |
+ disconnectedCallback, |
+ attributeChangedCallback, |
+ observedAttributes); |
// Add a constructor -> name mapping to the registry. |
v8::Local<v8::Value> nameValue = |
@@ -94,11 +116,17 @@ ScriptCustomElementDefinition* ScriptCustomElementDefinition::create( |
v8::Local<v8::Map> map = |
ensureCustomElementsRegistryMap(scriptState, registry); |
v8CallOrCrash(map->Set(scriptState->context(), constructor, nameValue)); |
- // We add the prototype here to keep it alive; we make it a value |
- // not a key so authors cannot return another constructor as a |
- // prototype to overwrite a constructor in this map. We use the |
- // name because it is unique per-registry. |
- v8CallOrCrash(map->Set(scriptState->context(), nameValue, prototype)); |
+ // We add the prototype and callbacks here to keep them alive. We use the |
+ // name as the key because it is unique per-registry. |
+ v8::Local<v8::Array> array = v8::Array::New(scriptState->isolate(), 4); |
yosin_UTC9
2016/06/01 06:33:33
Could you introduce enum for array index?
Or, use
kojii
2016/06/01 07:19:27
Done, not my favorite, but I can live with it.
|
+ v8CallOrCrash(array->Set(scriptState->context(), 0, prototype)); |
+ keepAliveIfNotEmpty(array, 1, connectedCallback, |
+ definition->m_connectedCallback, scriptState); |
+ keepAliveIfNotEmpty(array, 2, disconnectedCallback, |
+ definition->m_disconnectedCallback, scriptState); |
+ keepAliveIfNotEmpty(array, 3, attributeChangedCallback, |
+ definition->m_attributeChangedCallback, scriptState); |
+ v8CallOrCrash(map->Set(scriptState->context(), nameValue, array)); |
return definition; |
} |
@@ -107,7 +135,11 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition( |
ScriptState* scriptState, |
const CustomElementDescriptor& descriptor, |
const v8::Local<v8::Object>& constructor, |
- const v8::Local<v8::Object>& prototype) |
+ 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 Vector<AtomicString>& observedAttributes) |
: CustomElementDefinition(descriptor) |
, m_constructor(scriptState->isolate(), constructor) |
, m_prototype(scriptState->isolate(), prototype) |
@@ -117,6 +149,12 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition( |
// ScriptCustomElementDefinition::create. |
m_constructor.setPhantom(); |
m_prototype.setPhantom(); |
+ |
+ if (!observedAttributes.isEmpty()) { |
yosin_UTC9
2016/06/01 06:33:33
Prefer early-return style
kojii
2016/06/01 07:19:27
Done.
|
+ m_observedAttributes.reserveCapacityForSize(observedAttributes.size()); |
+ for (const auto& attribute : observedAttributes) |
+ m_observedAttributes.add(attribute); |
+ } |
} |
v8::Local<v8::Object> ScriptCustomElementDefinition::constructor( |