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

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

Issue 2200303003: Remove v8CallOrCrash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: temp 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/ScriptCustomElementDefinition.h" 5 #include "bindings/core/v8/ScriptCustomElementDefinition.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8BindingMacros.h" 9 #include "bindings/core/v8/V8BindingMacros.h"
10 #include "bindings/core/v8/V8CustomElementsRegistry.h" 10 #include "bindings/core/v8/V8CustomElementsRegistry.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return map.As<v8::Map>(); 42 return map.As<v8::Map>();
43 } 43 }
44 44
45 ScriptCustomElementDefinition* ScriptCustomElementDefinition::forConstructor( 45 ScriptCustomElementDefinition* ScriptCustomElementDefinition::forConstructor(
46 ScriptState* scriptState, 46 ScriptState* scriptState,
47 CustomElementsRegistry* registry, 47 CustomElementsRegistry* registry,
48 const v8::Local<v8::Value>& constructor) 48 const v8::Local<v8::Value>& constructor)
49 { 49 {
50 v8::Local<v8::Map> map = 50 v8::Local<v8::Map> map =
51 ensureCustomElementsRegistryMap(scriptState, registry); 51 ensureCustomElementsRegistryMap(scriptState, registry);
52 v8::Local<v8::Value> nameValue = v8CallOrCrash( 52 v8::Local<v8::Value> nameValue = map->Get(scriptState->context(), constructo r).ToLocalChecked();
53 map->Get(scriptState->context(), constructor));
54 if (!nameValue->IsString()) 53 if (!nameValue->IsString())
55 return nullptr; 54 return nullptr;
56 AtomicString name = toCoreAtomicString(nameValue.As<v8::String>()); 55 AtomicString name = toCoreAtomicString(nameValue.As<v8::String>());
57 56
58 // This downcast is safe because only 57 // This downcast is safe because only
59 // ScriptCustomElementDefinitions have a name associated with a V8 58 // ScriptCustomElementDefinitions have a name associated with a V8
60 // constructor in the map; see 59 // constructor in the map; see
61 // ScriptCustomElementDefinition::create. This relies on three 60 // ScriptCustomElementDefinition::create. This relies on three
62 // things: 61 // things:
63 // 62 //
(...skipping 22 matching lines...) Expand all
86 85
87 template <typename T> 86 template <typename T>
88 static void keepAlive(v8::Local<v8::Array>& array, uint32_t index, 87 static void keepAlive(v8::Local<v8::Array>& array, uint32_t index,
89 const v8::Local<T>& value, 88 const v8::Local<T>& value,
90 ScopedPersistent<T>& persistent, 89 ScopedPersistent<T>& persistent,
91 ScriptState* scriptState) 90 ScriptState* scriptState)
92 { 91 {
93 if (value.IsEmpty()) 92 if (value.IsEmpty())
94 return; 93 return;
95 94
96 v8CallOrCrash(array->Set(scriptState->context(), index, value)); 95 array->Set(scriptState->context(), index, value).ToChecked();
97 96
98 persistent.set(scriptState->isolate(), value); 97 persistent.set(scriptState->isolate(), value);
99 persistent.setPhantom(); 98 persistent.setPhantom();
100 } 99 }
101 100
102 ScriptCustomElementDefinition* ScriptCustomElementDefinition::create( 101 ScriptCustomElementDefinition* ScriptCustomElementDefinition::create(
103 ScriptState* scriptState, 102 ScriptState* scriptState,
104 CustomElementsRegistry* registry, 103 CustomElementsRegistry* registry,
105 const CustomElementDescriptor& descriptor, 104 const CustomElementDescriptor& descriptor,
106 const v8::Local<v8::Object>& constructor, 105 const v8::Local<v8::Object>& constructor,
(...skipping 12 matching lines...) Expand all
119 connectedCallback, 118 connectedCallback,
120 disconnectedCallback, 119 disconnectedCallback,
121 attributeChangedCallback, 120 attributeChangedCallback,
122 observedAttributes); 121 observedAttributes);
123 122
124 // Add a constructor -> name mapping to the registry. 123 // Add a constructor -> name mapping to the registry.
125 v8::Local<v8::Value> nameValue = 124 v8::Local<v8::Value> nameValue =
126 v8String(scriptState->isolate(), descriptor.name()); 125 v8String(scriptState->isolate(), descriptor.name());
127 v8::Local<v8::Map> map = 126 v8::Local<v8::Map> map =
128 ensureCustomElementsRegistryMap(scriptState, registry); 127 ensureCustomElementsRegistryMap(scriptState, registry);
129 v8CallOrCrash(map->Set(scriptState->context(), constructor, nameValue)); 128 map->Set(scriptState->context(), constructor, nameValue).ToLocalChecked();
130 definition->m_constructor.setPhantom(); 129 definition->m_constructor.setPhantom();
131 130
132 // We add the prototype and callbacks here to keep them alive. We use the 131 // We add the prototype and callbacks here to keep them alive. We use the
133 // name as the key because it is unique per-registry. 132 // name as the key because it is unique per-registry.
134 v8::Local<v8::Array> array = v8::Array::New(scriptState->isolate(), 4); 133 v8::Local<v8::Array> array = v8::Array::New(scriptState->isolate(), 4);
135 keepAlive(array, 0, prototype, definition->m_prototype, scriptState); 134 keepAlive(array, 0, prototype, definition->m_prototype, scriptState);
136 keepAlive(array, 1, connectedCallback, definition->m_connectedCallback, scri ptState); 135 keepAlive(array, 1, connectedCallback, definition->m_connectedCallback, scri ptState);
137 keepAlive(array, 2, disconnectedCallback, definition->m_disconnectedCallback , scriptState); 136 keepAlive(array, 2, disconnectedCallback, definition->m_disconnectedCallback , scriptState);
138 keepAlive(array, 3, attributeChangedCallback, definition->m_attributeChanged Callback, scriptState); 137 keepAlive(array, 3, attributeChangedCallback, definition->m_attributeChanged Callback, scriptState);
139 v8CallOrCrash(map->Set(scriptState->context(), nameValue, array)); 138 map->Set(scriptState->context(), nameValue, array).ToLocalChecked();
140 139
141 return definition; 140 return definition;
142 } 141 }
143 142
144 ScriptCustomElementDefinition::ScriptCustomElementDefinition( 143 ScriptCustomElementDefinition::ScriptCustomElementDefinition(
145 ScriptState* scriptState, 144 ScriptState* scriptState,
146 const CustomElementDescriptor& descriptor, 145 const CustomElementDescriptor& descriptor,
147 const v8::Local<v8::Object>& constructor, 146 const v8::Local<v8::Object>& constructor,
148 const v8::Local<v8::Object>& prototype, 147 const v8::Local<v8::Object>& prototype,
149 const v8::Local<v8::Function>& connectedCallback, 148 const v8::Local<v8::Function>& connectedCallback,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 v8String(isolate, name.localName()), 356 v8String(isolate, name.localName()),
358 v8StringOrNull(isolate, oldValue), 357 v8StringOrNull(isolate, oldValue),
359 v8StringOrNull(isolate, newValue), 358 v8StringOrNull(isolate, newValue),
360 v8String(isolate, name.namespaceURI()), 359 v8String(isolate, name.namespaceURI()),
361 }; 360 };
362 runCallback(m_attributeChangedCallback.newLocal(isolate), element, 361 runCallback(m_attributeChangedCallback.newLocal(isolate), element,
363 argc, argv); 362 argc, argv);
364 } 363 }
365 364
366 } // namespace blink 365 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698