| 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 5a931d54967b5aac91082bd8081988fdefd640f1..20fc8ab190c51d2645ef91af5c6c11404d73a2c6 100644
|
| --- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
|
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
|
| @@ -6,8 +6,12 @@
|
|
|
| #include "bindings/core/v8/ScriptState.h"
|
| #include "bindings/core/v8/V8Binding.h"
|
| +#include "bindings/core/v8/V8BindingMacros.h"
|
| #include "bindings/core/v8/V8CustomElementsRegistry.h"
|
| +#include "bindings/core/v8/V8Element.h"
|
| #include "bindings/core/v8/V8HiddenValue.h"
|
| +#include "bindings/core/v8/V8ScriptRunner.h"
|
| +#include "v8.h"
|
| #include "wtf/Allocator.h"
|
|
|
| namespace blink {
|
| @@ -153,6 +157,7 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition(
|
| const v8::Local<v8::Object>& constructor,
|
| const v8::Local<v8::Object>& prototype)
|
| : CustomElementDefinition(descriptor)
|
| + , m_scriptState(scriptState)
|
| , m_constructor(scriptState->isolate(), constructor)
|
| , m_prototype(scriptState->isolate(), prototype)
|
| {
|
| @@ -163,6 +168,40 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition(
|
| m_prototype.setPhantom();
|
| }
|
|
|
| +// https://html.spec.whatwg.org/multipage/scripting.html#upgrades
|
| +bool ScriptCustomElementDefinition::upgrade(Element* element)
|
| +{
|
| + if (!m_scriptState->contextIsValid())
|
| + return false;
|
| + ScriptState::Scope scope(m_scriptState.get());
|
| + v8::Isolate* isolate = m_scriptState->isolate();
|
| +
|
| + // Step 5 says to rethrow the exception; but there is no one to
|
| + // catch it. The side effect is to report the error.
|
| + v8::TryCatch tryCatch(isolate);
|
| + tryCatch.SetVerbose(true);
|
| +
|
| + ExecutionContext* executionContext = m_scriptState->getExecutionContext();
|
| + v8::Local<v8::Object> ctor = constructor(m_scriptState.get());
|
| + v8::Local<v8::Value> result;
|
| + if (!v8Call(V8ScriptRunner::callAsConstructor(
|
| + isolate,
|
| + ctor,
|
| + executionContext,
|
| + 0,
|
| + nullptr),
|
| + result))
|
| + return false;
|
| +
|
| + if (V8Element::toImplWithTypeCheck(isolate, result) != element) {
|
| + // TODO(dominicc): Throw InvalidStateError. Maybe Upgrade should
|
| + // take ExceptionState&?
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| v8::Local<v8::Object> ScriptCustomElementDefinition::constructor(
|
| ScriptState* scriptState) const
|
| {
|
|
|