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

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

Issue 1952893003: Implement custom element construction and some 'define' checks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use DCHECK, revert RuntimeEnabledFeatures.in. 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
new file mode 100644
index 0000000000000000000000000000000000000000..14a68a21380f984853faa3980367e9928ef04184
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/custom/V8HTMLElementCustom.cpp
@@ -0,0 +1,72 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bindings/core/v8/V8HTMLElement.h"
+
+#include "bindings/core/v8/DOMWrapperWorld.h"
+#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/V8Binding.h"
+#include "bindings/core/v8/V8ThrowException.h"
+#include "core/dom/Document.h"
+#include "core/dom/custom/CustomElementDefinition.h"
+#include "core/dom/custom/CustomElementsRegistry.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "platform/RuntimeEnabledFeatures.h"
+
+namespace blink {
+
+void V8HTMLElement::constructorCustom(
+ const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ DCHECK(info.IsConstructCall());
+ v8::Isolate* isolate = info.GetIsolate();
+
+ if (!RuntimeEnabledFeatures::customElementsV1Enabled()
+ || !DOMWrapperWorld::current(isolate).isMainWorld()) {
+ V8ThrowException::throwIllegalConstructorTypeError(isolate);
+ return;
+ }
+
+ Document* document = toDocument(currentExecutionContext(isolate));
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ CustomElementDefinition* def =
+ document->domWindow()->customElements()->definitionForConstructor(
+ context,
+ info.NewTarget());
+ if (!def) {
+ V8ThrowException::throwIllegalConstructorTypeError(isolate);
+ 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 = document->createElement(
+ def->localName(),
+ AtomicString(),
+ exceptionState);
+ if (exceptionState.throwIfNeeded())
+ return;
+ v8::Local<v8::Object> wrapper = element->wrap(isolate, info.Holder());
Yuki 2016/05/11 01:59:02 Please prefer using toV8() rather than wrap() meth
+ info.GetReturnValue().Set(wrapper);
haraken 2016/05/10 09:04:22 Can we use v8SetReturnValue(info, wrapper)? I'm a
yosin_UTC9 2016/05/10 13:10:59 I think we don't need to set return value for cons
dominicc (has gone to gerrit) 2016/05/11 02:31:49 Hmm, I actually did start with the HTMLElement con
dominicc (has gone to gerrit) 2016/05/11 02:31:49 We do in this case because we are returning a diff
yosin_UTC9 2016/05/11 03:49:55 AFIK, return value of constructor isn't used. I tr
+ if (wrapper.IsEmpty())
+ return;
+
+ v8::Maybe<bool> couldSetPrototype =
+ wrapper->SetPrototype(context, def->prototype(isolate));
yosin_UTC9 2016/05/10 13:10:59 Can we use new.target.constructor.prototype? If so
dominicc (has gone to gerrit) 2016/05/11 02:31:49 I was wondering about this too; I filed https://gi
yosin_UTC9 2016/05/11 03:49:55 Can we change spec to pass tagName to super? If so
+ if (couldSetPrototype.IsNothing())
+ return;
+ if (!couldSetPrototype.FromJust()) {
haraken 2016/05/10 09:04:22 V8BindingMacros.h provides macros to avoid develop
+ // TODO(dominicc): Find out when SetPrototype can fail and write a
+ // test for this.
haraken 2016/05/10 09:04:22 You can use v8CallOrCrash. (In practice, it will n
+ return;
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698