Chromium Code Reviews| 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..71a418583cb6868de7b52a744d5580237408e7fd 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::getValue( |
| + 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 (!getValue(m_constructor, "prototype", prototypeValue)) |
| return false; |
| - } |
| if (!prototypeValue->IsObject()) { |
| m_exceptionState.throwTypeError( |
| "constructor prototype is not an object"); |
| @@ -82,15 +86,54 @@ bool ScriptCustomElementDefinitionBuilder::checkPrototype() |
| return true; |
| } |
| +bool ScriptCustomElementDefinitionBuilder::getCallable(const char* name, |
|
yosin_UTC9
2016/06/02 01:33:38
It is better to return Optional, or v8::Maybe<v8::
|
| + v8::Local<v8::Object>& callback) const |
| +{ |
| + v8::Local<v8::Value> value; |
| + if (!getValue(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::cacheProperties() |
| +{ |
| + const char* observedAttributes = "observedAttributes"; |
| + v8::Local<v8::Value> observedAttributesValue; |
| + if (!getValue(m_constructor, observedAttributes, observedAttributesValue)) |
| + return false; |
| + if (!observedAttributesValue->IsUndefined()) { |
| + m_observedAttributes = toImplArray<Vector<AtomicString>>( |
| + observedAttributesValue, 0, m_scriptState->isolate(), |
| + m_exceptionState); |
| + if (m_exceptionState.hadException()) |
| + return false; |
| + } |
| + |
| + const char* connectedCallback = "connectedCallback"; |
| + const char* disconnectedCallback = "disconnectedCallback"; |
| + const char* attributeChangedCallback = "attributeChangedCallback"; |
| + return getCallable(connectedCallback, m_connectedCallback) |
|
dominicc (has gone to gerrit)
2016/06/02 00:31:27
Please add unit tests which detach the window in c
|
| + && getCallable(disconnectedCallback, m_disconnectedCallback) |
| + && getCallable(attributeChangedCallback, m_attributeChangedCallback); |
| +} |
| + |
| CustomElementDefinition* ScriptCustomElementDefinitionBuilder::build( |
| const CustomElementDescriptor& descriptor) |
| { |
| - return ScriptCustomElementDefinition::create( |
| - m_scriptState.get(), |
| - m_registry, |
| - descriptor, |
| - m_constructor, |
| - m_prototype); |
| + return ScriptCustomElementDefinition::create(descriptor, *this); |
| } |
| } // namespace blink |