Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp

Issue 2035623002: Implement the script parts of custom element upgrade steps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ce-upgrade-in-document-dom-merge2
Patch Set: Do not assign in conditional to unbreak windows builder. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8e60471ce2a3df6acc8fdd65b304c94e65bf49d3..b382f5e9821d045d33e7d2ce6790c20bfbead92e 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptCustomElementDefinition.cpp
@@ -6,8 +6,14 @@
#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 "bindings/core/v8/V8ThrowException.h"
+#include "core/dom/ExceptionCode.h"
+#include "v8.h"
#include "wtf/Allocator.h"
namespace blink {
@@ -120,6 +126,45 @@ ScriptCustomElementDefinition::ScriptCustomElementDefinition(
m_prototype.setPhantom();
}
+// 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
+ // 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::Value> result;
+ if (!v8Call(V8ScriptRunner::callAsConstructor(
+ isolate,
+ constructor(),
+ executionContext,
+ 0,
+ nullptr),
+ result))
+ return false;
+
+ if (V8Element::toImplWithTypeCheck(isolate, result) != element) {
+ V8ThrowException::throwException(
+ V8ThrowException::createDOMException(
+ m_scriptState->isolate(),
+ InvalidStateError,
+ "custom element constructors must call super() first and must "
+ "not return a different object",
+ constructor()),
+ m_scriptState->isolate());
+ return false;
+ }
+
+ return true;
+}
+
v8::Local<v8::Object> ScriptCustomElementDefinition::constructor() const
{
DCHECK(!m_constructor.isEmpty());

Powered by Google App Engine
This is Rietveld 408576698