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

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

Issue 1985623002: [WIP] Custom element upgrades (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a C++-only test.' Created 4 years, 7 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/custom/V8HTMLElementCustom.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp
index 2f9ed0437bfe3009ccf01fea01046813b08efb51..3e6ed3363ae61864cca9e4b4b45bd7c8cf196917 100644
--- a/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp
@@ -12,6 +12,7 @@
#include "bindings/core/v8/V8DOMWrapper.h"
#include "bindings/core/v8/V8ThrowException.h"
#include "core/dom/Document.h"
+#include "core/dom/ExceptionCode.h"
#include "core/dom/custom/CustomElementsRegistry.h"
#include "core/frame/LocalDOMWindow.h"
#include "platform/RuntimeEnabledFeatures.h"
@@ -28,48 +29,65 @@ void V8HTMLElement::constructorCustom(
if (!RuntimeEnabledFeatures::customElementsV1Enabled()
|| !scriptState->world().isMainWorld()) {
- V8ThrowException::throwTypeError(info.GetIsolate(), "Illegal constructor");
+ V8ThrowException::throwTypeError(
+ info.GetIsolate(),
+ "Illegal constructor");
return;
}
LocalDOMWindow* window = scriptState->domWindow();
- ScriptCustomElementDefinition* def =
+ ScriptCustomElementDefinition* definition =
ScriptCustomElementDefinition::forConstructor(
scriptState,
window->customElements(),
info.NewTarget());
- if (!def) {
+ if (!definition) {
V8ThrowException::throwTypeError(isolate, "Illegal constructor");
return;
}
- // TODO(dominicc): Implement cases where the definition's
- // construction stack is not empty when parser-creation is
- // implemented.
-
ExceptionState exceptionState(
ExceptionState::ConstructionContext,
"HTMLElement",
info.Holder(),
isolate);
- Element* element = window->document()->createElement(
- def->descriptor().localName(),
- AtomicString(),
- exceptionState);
- if (exceptionState.throwIfNeeded())
+
+ Element* element;
+ if (definition->constructionStack().isEmpty()) {
+ // This is an element being created with 'new' from script
+ element = window->document()->createElement(
+ definition->descriptor().localName(),
+ AtomicString(),
+ exceptionState);
+ if (exceptionState.throwIfNeeded())
+ return;
+ } else if ((element = definition->constructionStack().last())) {
+ // This is an element being upgraded that has called super
+ definition->constructionStack().last().clear();
+ } else {
+ // During upgrade an element has invoked the same constructor
+ // before calling 'super' and that invocation has poached the
+ // element.
+ exceptionState.throwDOMException(
+ InvalidStateError,
+ "this instance is already constructed");
+ exceptionState.throwIfNeeded();
return;
+ }
const WrapperTypeInfo* wrapperType = element->wrapperTypeInfo();
v8::Local<v8::Object> wrapper = V8DOMWrapper::associateObjectWithWrapper(
isolate,
element,
wrapperType,
info.This());
+ // If the element had a wrapper, we now update and return that
+ // instead.
+ v8SetReturnValue(info, wrapper);
- if (!v8CallBoolean(wrapper->SetPrototype(
+ bool setPrototype = v8CallOrCrash(wrapper->SetPrototype(
scriptState->context(),
- def->prototype(scriptState)))) {
- return;
- }
+ definition->prototype(scriptState)));
+ CHECK(setPrototype);
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/V8ScriptRunner.cpp ('k') | third_party/WebKit/Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698