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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8PrivateProperty.h

Issue 2770043003: Refactor V8PrivateProperty to use an array.
Patch Set: move the DCHECK before the indexing Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/V8PrivateProperty.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef V8PrivateProperty_h 5 #ifndef V8PrivateProperty_h
6 #define V8PrivateProperty_h 6 #define V8PrivateProperty_h
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "bindings/core/v8/ScriptPromiseProperties.h" 10 #include "bindings/core/v8/ScriptPromiseProperties.h"
(...skipping 28 matching lines...) Expand all
39 X(SameObject, NotificationData) \ 39 X(SameObject, NotificationData) \
40 X(SameObject, NotificationVibrate) \ 40 X(SameObject, NotificationVibrate) \
41 X(SameObject, PerformanceLongTaskTimingAttribution) \ 41 X(SameObject, PerformanceLongTaskTimingAttribution) \
42 X(V8NodeFilterCondition, Filter) \ 42 X(V8NodeFilterCondition, Filter) \
43 X(Window, DocumentCachedAccessor) 43 X(Window, DocumentCachedAccessor)
44 44
45 // The getter's name for a private property. 45 // The getter's name for a private property.
46 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ 46 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \
47 get##InterfaceName##PrivateKeyName 47 get##InterfaceName##PrivateKeyName
48 48
49 // The member variable's name for a private property.
50 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \
51 m_symbol##InterfaceName##PrivateKeyName
52
53 // The string used to create a private symbol. Must be unique per V8 instance. 49 // The string used to create a private symbol. Must be unique per V8 instance.
54 #define V8_PRIVATE_PROPERTY_SYMBOL_STRING(InterfaceName, PrivateKeyName) \ 50 #define V8_PRIVATE_PROPERTY_SYMBOL_STRING(InterfaceName, PrivateKeyName) \
55 #InterfaceName "#" #PrivateKeyName // NOLINT(whitespace/indent) 51 #InterfaceName "#" #PrivateKeyName // NOLINT(whitespace/indent)
56 52
57 // Provides access to V8's private properties. 53 // Provides access to V8's private properties.
58 // 54 //
59 // Usage 1) Fast path to use a pre-registered symbol. 55 // Usage 1) Fast path to use a pre-registered symbol.
60 // auto private = V8PrivateProperty::getMessageEventCachedData(isolate); 56 // auto private = V8PrivateProperty::getMessageEventCachedData(isolate);
61 // v8::Local<v8::Context> context = ...; 57 // v8::Local<v8::Context> context = ...;
62 // v8::Local<v8::Object> object = ...; 58 // v8::Local<v8::Object> object = ...;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // Only friend classes are allowed to use this API. 122 // Only friend classes are allowed to use this API.
127 v8::Local<v8::Value> getFromMainWorld(ScriptState*, ScriptWrappable*); 123 v8::Local<v8::Value> getFromMainWorld(ScriptState*, ScriptWrappable*);
128 124
129 v8::Local<v8::Private> m_privateSymbol; 125 v8::Local<v8::Private> m_privateSymbol;
130 }; 126 };
131 127
132 static std::unique_ptr<V8PrivateProperty> create() { 128 static std::unique_ptr<V8PrivateProperty> create() {
133 return WTF::wrapUnique(new V8PrivateProperty()); 129 return WTF::wrapUnique(new V8PrivateProperty());
134 } 130 }
135 131
136 #define V8_PRIVATE_PROPERTY_DEFINE_GETTER(InterfaceName, KeyName) \ 132 enum SymbolID {
137 static Symbol V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, KeyName)( \ 133 #define V8_PRIVATE_PROPERTY_ENUMERATOR(InterfaceName, PrivateKeyName) \
138 v8::Isolate * isolate) /* NOLINT(readability/naming/underscores) */ \ 134 k##InterfaceName##PrivateKeyName,
139 { \ 135 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_ENUMERATOR)
140 V8PrivateProperty* privateProp = \ 136 #undef V8_PRIVATE_PROPERTY_ENUMERATOR
141 V8PerIsolateData::from(isolate)->privateProperty(); \ 137 kSymbolCount
142 if (UNLIKELY(privateProp \ 138 };
143 ->V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName) \ 139
144 .IsEmpty())) { \ 140 static Symbol get(v8::Isolate* isolate, SymbolID symbolID) {
145 privateProp->V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName) \ 141 V8PrivateProperty* privateProp =
146 .Set( \ 142 V8PerIsolateData::from(isolate)->privateProperty();
147 isolate, \ 143 DCHECK_GE(symbolID, 0);
148 createV8Private( \ 144 DCHECK_LT(symbolID, kSymbolCount);
149 isolate, \ 145 auto& symbol = privateProp->m_symbols[symbolID];
150 V8_PRIVATE_PROPERTY_SYMBOL_STRING(InterfaceName, KeyName), \ 146 if (UNLIKELY(symbol.IsEmpty()))
151 sizeof V8_PRIVATE_PROPERTY_SYMBOL_STRING( \ 147 privateProp->initialize(isolate, symbolID);
152 InterfaceName, \ 148 DCHECK(!symbol.IsEmpty());
153 KeyName))); /* NOLINT(readability/naming/underscores) */ \ 149 return Symbol(symbol.Get(isolate));
154 } \ 150 }
155 return Symbol( \ 151
156 privateProp->V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName) \ 152 #define V8_PRIVATE_PROPERTY_DEFINE_GETTER(InterfaceName, KeyName) \
157 .Get(isolate)); \ 153 static Symbol V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, KeyName)( \
154 v8::Isolate * isolate) /* NOLINT(readability/naming/underscores) */ \
155 { \
156 return get(isolate, k##InterfaceName##KeyName); \
158 } 157 }
159 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DEFINE_GETTER) 158 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DEFINE_GETTER)
160 #undef V8_PRIVATE_PROPERTY_DEFINE_GETTER 159 #undef V8_PRIVATE_PROPERTY_DEFINE_GETTER
161 160
162 static Symbol createSymbol(v8::Isolate* isolate, 161 static Symbol createSymbol(v8::Isolate* isolate,
163 const char* symbol, 162 const char* symbol,
164 size_t length) { 163 size_t length) {
165 return Symbol(createV8Private(isolate, symbol, length)); 164 return Symbol(createV8Private(isolate, symbol, length));
166 } 165 }
167 166
168 private: 167 private:
169 V8PrivateProperty() {} 168 V8PrivateProperty() {}
170 169
170 void initialize(v8::Isolate*, SymbolID);
171
171 static v8::Local<v8::Private> createV8Private(v8::Isolate*, 172 static v8::Local<v8::Private> createV8Private(v8::Isolate*,
172 const char* symbol, 173 const char* symbol,
173 size_t length); 174 size_t length);
174 175
175 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ 176 v8::Eternal<v8::Private> m_symbols[kSymbolCount];
176 v8::Eternal<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME( \
177 InterfaceName, KeyName); // NOLINT(readability/naming/underscores)
178 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER)
179 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER
180 }; 177 };
181 178
182 } // namespace blink 179 } // namespace blink
183 180
184 #endif // V8PrivateProperty_h 181 #endif // V8PrivateProperty_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/V8PrivateProperty.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698