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

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

Issue 2170383002: CustomElements: adopt node (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch update Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/V8HTMLElement.h" 5 #include "bindings/core/v8/V8HTMLElement.h"
6 6
7 #include "bindings/core/v8/DOMWrapperWorld.h" 7 #include "bindings/core/v8/DOMWrapperWorld.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptCustomElementDefinition.h" 9 #include "bindings/core/v8/ScriptCustomElementDefinition.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "bindings/core/v8/V8BindingMacros.h" 11 #include "bindings/core/v8/V8BindingMacros.h"
12 #include "bindings/core/v8/V8DOMWrapper.h" 12 #include "bindings/core/v8/V8DOMWrapper.h"
13 #include "bindings/core/v8/V8ThrowException.h" 13 #include "bindings/core/v8/V8ThrowException.h"
14 #include "core/dom/Document.h" 14 #include "core/dom/Document.h"
15 #include "core/dom/Element.h"
15 #include "core/dom/ExceptionCode.h" 16 #include "core/dom/ExceptionCode.h"
16 #include "core/dom/custom/CustomElementsRegistry.h" 17 #include "core/dom/custom/CustomElementsRegistry.h"
17 #include "core/frame/LocalDOMWindow.h" 18 #include "core/frame/LocalDOMWindow.h"
18 #include "platform/RuntimeEnabledFeatures.h" 19 #include "platform/RuntimeEnabledFeatures.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
22 void V8HTMLElement::constructorCustom( 23 void V8HTMLElement::constructorCustom(
23 const v8::FunctionCallbackInfo<v8::Value>& info) 24 const v8::FunctionCallbackInfo<v8::Value>& info)
24 { 25 {
(...skipping 29 matching lines...) Expand all
54 55
55 Element* element; 56 Element* element;
56 if (definition->constructionStack().isEmpty()) { 57 if (definition->constructionStack().isEmpty()) {
57 // This is an element being created with 'new' from script 58 // This is an element being created with 'new' from script
58 // TODO(kojii): When HTMLElementFactory has an option not to queue 59 // TODO(kojii): When HTMLElementFactory has an option not to queue
59 // upgrade, call that instead of HTMLElement. HTMLElement is enough 60 // upgrade, call that instead of HTMLElement. HTMLElement is enough
60 // for now, but type extension will require HTMLElementFactory. 61 // for now, but type extension will require HTMLElementFactory.
61 element = HTMLElement::create( 62 element = HTMLElement::create(
62 QualifiedName(nullAtom, definition->descriptor().localName(), HTMLNa mes::xhtmlNamespaceURI), 63 QualifiedName(nullAtom, definition->descriptor().localName(), HTMLNa mes::xhtmlNamespaceURI),
63 *window->document()); 64 *window->document());
65 // TODO(davaajav): write this as one call to setCustomElementState inste ad of two
64 element->setCustomElementState(CustomElementState::Undefined); 66 element->setCustomElementState(CustomElementState::Undefined);
67 element->setCustomElementState(CustomElementState::Custom);
68 element->setCustomElementDefinition(definition);
65 } else { 69 } else {
66 element = definition->constructionStack().last(); 70 element = definition->constructionStack().last();
67 if (element) { 71 if (element) {
68 // This is an element being upgraded that has called super 72 // This is an element being upgraded that has called super
69 definition->constructionStack().last().clear(); 73 definition->constructionStack().last().clear();
70 } else { 74 } else {
71 // During upgrade an element has invoked the same constructor 75 // During upgrade an element has invoked the same constructor
72 // before calling 'super' and that invocation has poached the 76 // before calling 'super' and that invocation has poached the
73 // element. 77 // element.
74 exceptionState.throwDOMException( 78 exceptionState.throwDOMException(
75 InvalidStateError, 79 InvalidStateError,
76 "this instance is already constructed"); 80 "this instance is already constructed");
77 exceptionState.throwIfNeeded(); 81 exceptionState.throwIfNeeded();
78 return; 82 return;
79 } 83 }
80 } 84 }
81 const WrapperTypeInfo* wrapperType = element->wrapperTypeInfo(); 85 const WrapperTypeInfo* wrapperType = element->wrapperTypeInfo();
82 v8::Local<v8::Object> wrapper = V8DOMWrapper::associateObjectWithWrapper( 86 v8::Local<v8::Object> wrapper = V8DOMWrapper::associateObjectWithWrapper(
83 isolate, 87 isolate,
84 element, 88 element,
85 wrapperType, 89 wrapperType,
86 info.Holder()); 90 info.Holder());
87 // If the element had a wrapper, we now update and return that 91 // If the element had a wrapper, we now update and return that
88 // instead. 92 // instead.
89 v8SetReturnValue(info, wrapper); 93 v8SetReturnValue(info, wrapper);
90 94
91 v8CallOrCrash(wrapper->SetPrototype( 95 v8CallOrCrash(wrapper->SetPrototype(
92 scriptState->context(), 96 scriptState->context(),
93 definition->prototype())); 97 definition->prototype()));
94
95 // TODO(dominicc): Move this to the exactly correct place when
96 // https://github.com/whatwg/html/issues/1297 is closed.
97 element->setCustomElementState(CustomElementState::Custom);
98 } 98 }
99 99
100 } // namespace blink 100 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698