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

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

Issue 2029923003: Recursively defining custom elements should not lead to redefinition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 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/ScriptCustomElementDefinitionBuilder.h" 5 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.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/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
11 #include "bindings/core/v8/ScriptValue.h" 11 #include "bindings/core/v8/ScriptValue.h"
12 #include "bindings/core/v8/V8Binding.h" 12 #include "bindings/core/v8/V8Binding.h"
13 #include "bindings/core/v8/V8BindingMacros.h" 13 #include "bindings/core/v8/V8BindingMacros.h"
14 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 ScriptCustomElementDefinitionBuilder* ScriptCustomElementDefinitionBuilder
19 ::s_stack = nullptr;
20
18 ScriptCustomElementDefinitionBuilder::ScriptCustomElementDefinitionBuilder( 21 ScriptCustomElementDefinitionBuilder::ScriptCustomElementDefinitionBuilder(
19 ScriptState* scriptState, 22 ScriptState* scriptState,
20 CustomElementsRegistry* registry, 23 CustomElementsRegistry* registry,
21 const ScriptValue& constructor, 24 const ScriptValue& constructor,
22 ExceptionState& exceptionState) 25 ExceptionState& exceptionState)
23 : m_scriptState(scriptState) 26 : m_prev(s_stack)
27 , m_scriptState(scriptState)
24 , m_registry(registry) 28 , m_registry(registry)
25 , m_constructorValue(constructor.v8Value()) 29 , m_constructorValue(constructor.v8Value())
26 , m_exceptionState(exceptionState) 30 , m_exceptionState(exceptionState)
27 { 31 {
32 s_stack = this;
33 }
34
35 ScriptCustomElementDefinitionBuilder::~ScriptCustomElementDefinitionBuilder()
36 {
37 s_stack = m_prev;
28 } 38 }
29 39
30 bool ScriptCustomElementDefinitionBuilder::checkConstructorIntrinsics() 40 bool ScriptCustomElementDefinitionBuilder::checkConstructorIntrinsics()
31 { 41 {
32 DCHECK(m_scriptState->world().isMainWorld()); 42 DCHECK(m_scriptState->world().isMainWorld());
33 43
34 // The signature of CustomElementsRegistry.define says this is a 44 // The signature of CustomElementsRegistry.define says this is a
35 // Function 45 // Function
36 // https://html.spec.whatwg.org/multipage/scripting.html#customelementsregis try 46 // https://html.spec.whatwg.org/multipage/scripting.html#customelementsregis try
37 CHECK(m_constructorValue->IsFunction()); 47 CHECK(m_constructorValue->IsFunction());
(...skipping 12 matching lines...) Expand all
50 m_scriptState.get(), 60 m_scriptState.get(),
51 m_registry, 61 m_registry,
52 m_constructor)) { 62 m_constructor)) {
53 63
54 // Constructor is already registered. 64 // Constructor is already registered.
55 m_exceptionState.throwDOMException( 65 m_exceptionState.throwDOMException(
56 NotSupportedError, 66 NotSupportedError,
57 "this constructor has already been used with this registry"); 67 "this constructor has already been used with this registry");
58 return false; 68 return false;
59 } 69 }
70 for (auto builder = m_prev; builder; builder = builder->m_prev) {
71 CHECK(!builder->m_constructor.IsEmpty());
72 if (m_registry != builder->m_registry
73 || m_constructor != builder->m_constructor) {
74 continue;
75 }
76 m_exceptionState.throwDOMException(
77 NotSupportedError,
78 "this constructor is already being defined in this registry");
79 return false;
80 }
60 return true; 81 return true;
61 } 82 }
62 83
63 bool ScriptCustomElementDefinitionBuilder::checkPrototype() 84 bool ScriptCustomElementDefinitionBuilder::checkPrototype()
64 { 85 {
65 v8::Isolate* isolate = m_scriptState->isolate(); 86 v8::Isolate* isolate = m_scriptState->isolate();
66 v8::Local<v8::Context> context = m_scriptState->context(); 87 v8::Local<v8::Context> context = m_scriptState->context();
67 v8::Local<v8::String> prototypeString = 88 v8::Local<v8::String> prototypeString =
68 v8AtomicString(isolate, "prototype"); 89 v8AtomicString(isolate, "prototype");
69 v8::Local<v8::Value> prototypeValue; 90 v8::Local<v8::Value> prototypeValue;
(...skipping 17 matching lines...) Expand all
87 { 108 {
88 return ScriptCustomElementDefinition::create( 109 return ScriptCustomElementDefinition::create(
89 m_scriptState.get(), 110 m_scriptState.get(),
90 m_registry, 111 m_registry,
91 descriptor, 112 descriptor,
92 m_constructor, 113 m_constructor,
93 m_prototype); 114 m_prototype);
94 } 115 }
95 116
96 } // namespace blink 117 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698