Chromium Code Reviews| 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 879fac4ecdfd1b38f444b0883ebaad761c1bde21..4c0867fef08a47d3940de6cd7d91abbe9b7ff210 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 HashSet<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,19 @@ 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)); |
| + definition->m_constructor.setPhantom(); |
| + |
| + // 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); |
| +#define V(index, name) \ |
|
yosin_UTC9
2016/06/02 04:30:31
No need to use macro, it is hard to read.
Name |V
kojii
2016/06/02 04:47:13
Done, reverted the macro as per your suggestion.
|
| + keepAliveIfNotEmpty(array, index, name, definition->m_##name, scriptState) |
| + V(0, prototype); |
| + V(1, connectedCallback); |
| + V(2, disconnectedCallback); |
| + V(3, attributeChangedCallback); |
| +#undef V |
| + v8CallOrCrash(map->Set(scriptState->context(), nameValue, array)); |
| return definition; |
| } |
| @@ -107,17 +137,16 @@ 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 HashSet<AtomicString>& observedAttributes) |
| : CustomElementDefinition(descriptor) |
| , m_scriptState(scriptState) |
| , m_constructor(scriptState->isolate(), constructor) |
| - , m_prototype(scriptState->isolate(), prototype) |
| + , m_observedAttributes(observedAttributes) |
| { |
| - // These objects are kept alive by references from the |
| - // CustomElementsRegistry wrapper set up by |
| - // ScriptCustomElementDefinition::create. |
| - m_constructor.setPhantom(); |
| - m_prototype.setPhantom(); |
| } |
| v8::Local<v8::Object> ScriptCustomElementDefinition::constructor() const |