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 de725ff62ad418e8ad81b48123a14d602e1e0ba3..255e4cdf3babf8e3ddaf531ae016fb91c79d3c3f 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp |
| @@ -13,6 +13,8 @@ |
| #include "bindings/core/v8/V8ScriptRunner.h" |
| #include "bindings/core/v8/V8ThrowException.h" |
| #include "core/dom/ExceptionCode.h" |
| +#include "core/html/HTMLElement.h" |
| +#include "core/html/HTMLUnknownElement.h" |
| #include "v8.h" |
| #include "wtf/Allocator.h" |
| @@ -152,12 +154,63 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition( |
| { |
| } |
| +HTMLElement* ScriptCustomElementDefinition::createElementByRunningConstructor( |
| + Document& document, const QualifiedName& tagName, |
| + ExceptionState& exceptionState) |
| +{ |
| + // Create an element |
| + // https://dom.spec.whatwg.org/#concept-create-element |
| + // 6. If definition is non-null |
| + // 6.1. If the synchronous custom elements flag is set: |
| + // 6.1.2. Set result to Construct(C). Rethrow any exceptions. |
| + Element* element; |
| + { |
| + v8::TryCatch tryCatch(m_scriptState->isolate()); |
| + element = runConstructor(); |
| + if (tryCatch.HasCaught()) { |
| + exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| + return nullptr; |
| + } |
| + } |
| + |
| + // 6.1.3. through 6.1.9. |
| + errorForConstructorResult(element, document, tagName, exceptionState); |
|
dominicc (has gone to gerrit)
2016/06/10 06:13:28
Could we call this checkConstructorResult or somet
kojii
2016/06/10 19:01:45
Done.
|
| + if (exceptionState.hadException()) |
| + return nullptr; |
| + |
| + DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); |
| + return toHTMLElement(element); |
| +} |
| + |
| +HTMLElement* ScriptCustomElementDefinition::createElementByRunningConstructor( |
| + Document& document, const QualifiedName& tagName) |
| +{ |
| + // When invoked from "create an element for a token": |
| + // https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token |
| + // 7. If this step throws an exception, then report the exception, and |
| + // let element be instead a new element that implements HTMLUnknownElement, |
| + // with no attributes, namespace set to given namespace, namespace prefix |
| + // set to null, custom element state "undefined", and node document set to |
| + // document. |
| + v8::Isolate* isolate = m_scriptState->isolate(); |
|
dominicc (has gone to gerrit)
2016/06/10 06:13:28
When the parser calls this there will not be a han
kojii
2016/06/10 19:01:44
Done.
|
| + v8::TryCatch tryCatch(isolate); |
| + tryCatch.SetVerbose(true); |
| + ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomElement", constructor(), isolate); |
| + |
| + HTMLElement* element = createElementByRunningConstructor(document, tagName, exceptionState); |
| + if (!exceptionState.throwIfNeeded() && element && !tryCatch.HasCaught()) |
|
dominicc (has gone to gerrit)
2016/06/10 06:13:28
exceptionState.throwIfNeeded() will set tryCatch.H
kojii
2016/06/10 19:01:44
Done.
|
| + return element; |
| + |
| + element = HTMLUnknownElement::create(tagName, document); |
| + element->setCustomElementState(CustomElementState::Undefined); |
| + return element; |
|
dominicc (has gone to gerrit)
2016/06/10 06:13:28
Maybe reversing the condition and putting HTMLUnkn
kojii
2016/06/10 19:01:45
Done.
|
| +} |
| + |
| // https://html.spec.whatwg.org/multipage/scripting.html#upgrades |
| bool ScriptCustomElementDefinition::runConstructor(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 |
| @@ -165,18 +218,11 @@ bool ScriptCustomElementDefinition::runConstructor(Element* element) |
| v8::TryCatch tryCatch(isolate); |
| tryCatch.SetVerbose(true); |
| - ExecutionContext* executionContext = m_scriptState->getExecutionContext(); |
| - v8::Local<v8::Value> result; |
| - if (!v8Call(V8ScriptRunner::callAsConstructor( |
| - isolate, |
| - constructor(), |
| - executionContext, |
| - 0, |
| - nullptr), |
| - result)) |
| + Element* result = runConstructor(); |
| + if (!result) |
| return false; |
| - if (V8Element::toImplWithTypeCheck(isolate, result) != element) { |
| + if (result != element) { |
| V8ThrowException::throwException( |
| V8ThrowException::createDOMException( |
| m_scriptState->isolate(), |
| @@ -191,6 +237,26 @@ bool ScriptCustomElementDefinition::runConstructor(Element* element) |
| return true; |
| } |
| +Element* ScriptCustomElementDefinition::runConstructor() |
| +{ |
| + if (!m_scriptState->contextIsValid()) |
|
dominicc (has gone to gerrit)
2016/06/10 06:13:28
I'm not sure this is right; all the calls are from
kojii
2016/06/10 19:01:45
Removed and the one above revived. Started to unde
|
| + return nullptr; |
| + ScriptState::Scope scope(m_scriptState.get()); |
| + v8::Isolate* isolate = m_scriptState->isolate(); |
| + ExecutionContext* executionContext = m_scriptState->getExecutionContext(); |
| + v8::Local<v8::Value> result; |
| + if (!v8Call(V8ScriptRunner::callAsConstructor( |
| + isolate, |
| + constructor(), |
| + executionContext, |
| + 0, |
| + nullptr), |
| + result)) { |
| + return nullptr; |
| + } |
| + return V8Element::toImplWithTypeCheck(isolate, result); |
| +} |
| + |
| v8::Local<v8::Object> ScriptCustomElementDefinition::constructor() const |
| { |
| DCHECK(!m_constructor.isEmpty()); |