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

Side by Side 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: Rebase; remove default parameters. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "bindings/core/v8/V8HTMLElement.h"
6
7 #include "bindings/core/v8/DOMWrapperWorld.h"
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8BindingMacros.h"
11 #include "bindings/core/v8/V8ThrowException.h"
12 #include "core/dom/Document.h"
13 #include "core/dom/custom/CustomElementDefinition.h"
14 #include "core/dom/custom/CustomElementsRegistry.h"
15 #include "core/frame/LocalDOMWindow.h"
16 #include "platform/RuntimeEnabledFeatures.h"
17
18 namespace blink {
19
20 void V8HTMLElement::constructorCustom(
21 const v8::FunctionCallbackInfo<v8::Value>& info)
22 {
23 DCHECK(info.IsConstructCall());
24
25 v8::Isolate* isolate = info.GetIsolate();
26 ScriptState* scriptState = ScriptState::current(isolate);
27
28 if (!RuntimeEnabledFeatures::customElementsV1Enabled()
29 || !scriptState->world().isMainWorld()) {
30 V8ThrowException::throwTypeError(info.GetIsolate(), "Illegal constructor ");
31 return;
32 }
33
34 LocalDOMWindow* window = scriptState->domWindow();
35 CustomElementDefinition* def =
36 window->customElements(scriptState)->definitionForConstructor(
37 scriptState,
38 info.NewTarget());
39 if (!def) {
40 V8ThrowException::throwTypeError(isolate, "Illegal constructor");
41 return;
42 }
43
44 // TODO(dominicc): Implement cases where the definition's
45 // construction stack is not empty when parser-creation is
46 // implemented.
47 ExceptionState exceptionState(
48 ExceptionState::ConstructionContext,
49 "HTMLElement",
50 info.Holder(),
51 isolate);
52 Element* element = window->document()->createElement(
53 def->localName(),
54 AtomicString(),
55 exceptionState);
56 if (exceptionState.throwIfNeeded())
57 return;
58 v8SetReturnValue(info, element);
59 v8::Local<v8::Object> wrapper =
yosin_UTC9 2016/05/12 01:30:34 Just curiosity, is v8SetReturnValue(info, <C++ poi
bashi 2016/05/12 02:03:25 No. Try toV8() if you need to do. Basically the bi
haraken 2016/05/12 02:13:58 Please do the same thing as the generated code is
bashi 2016/05/12 02:15:18 I thought he asked a common pattten, not this spec
60 info.GetReturnValue().Get().As<v8::Object>();
61 if (wrapper.IsEmpty())
62 return;
63
64 if (!v8CallBoolean(
65 wrapper->SetPrototype(scriptState->context(), def->prototype(isolate))))
yosin_UTC9 2016/05/12 01:30:34 Is info.GetNewTarget().GetProperty("prototype") !=
66 return;
67 }
68
69 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698