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

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

Issue 2781443002: [Bindings] Specialize WindowDocument symbol in V8PrivateProperty (Closed)
Patch Set: Specialize createV8Private to use ForApi Created 3 years, 8 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 #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 21 matching lines...) Expand all
32 X(IDBObserver, Callback) \ 32 X(IDBObserver, Callback) \
33 X(IntersectionObserver, Callback) \ 33 X(IntersectionObserver, Callback) \
34 X(MessageEvent, CachedData) \ 34 X(MessageEvent, CachedData) \
35 X(MutationObserver, Callback) \ 35 X(MutationObserver, Callback) \
36 X(NamedConstructor, Initialized) \ 36 X(NamedConstructor, Initialized) \
37 X(PerformanceObserver, Callback) \ 37 X(PerformanceObserver, Callback) \
38 X(SameObject, NotificationActions) \ 38 X(SameObject, NotificationActions) \
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)
44 43
45 // The getter's name for a private property. 44 // The getter's name for a private property.
46 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ 45 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \
47 get##InterfaceName##PrivateKeyName 46 get##InterfaceName##PrivateKeyName
48 47
49 // The member variable's name for a private property. 48 // The member variable's name for a private property.
50 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \ 49 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \
51 m_symbol##InterfaceName##PrivateKeyName 50 m_symbol##InterfaceName##PrivateKeyName
52 51
53 // The string used to create a private symbol. Must be unique per V8 instance. 52 // The string used to create a private symbol. Must be unique per V8 instance.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 InterfaceName, \ 146 InterfaceName, \
148 KeyName))); /* NOLINT(readability/naming/underscores) */ \ 147 KeyName))); /* NOLINT(readability/naming/underscores) */ \
149 } \ 148 } \
150 return Symbol( \ 149 return Symbol( \
151 privateProp->V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName) \ 150 privateProp->V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName) \
152 .Get(isolate)); \ 151 .Get(isolate)); \
153 } 152 }
154 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DEFINE_GETTER) 153 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DEFINE_GETTER)
155 #undef V8_PRIVATE_PROPERTY_DEFINE_GETTER 154 #undef V8_PRIVATE_PROPERTY_DEFINE_GETTER
156 155
156 static Symbol getWindowDocumentCachedAccessor(v8::Isolate* isolate) {
157 static constexpr char kSymbol[] = "Window#DocumentCachedAccessor";
158 V8PrivateProperty* privateProp =
159 V8PerIsolateData::from(isolate)->privateProperty();
160 if (UNLIKELY(privateProp->m_symbolWindowDocumentCachedAccessor.isEmpty())) {
161 privateProp->m_symbolWindowDocumentCachedAccessor.set(
162 isolate, createCachedV8Private(isolate, kSymbol, sizeof(kSymbol)));
163 }
164 return Symbol(
165 privateProp->m_symbolWindowDocumentCachedAccessor.newLocal(isolate));
166 }
167
157 static Symbol createSymbol(v8::Isolate* isolate, 168 static Symbol createSymbol(v8::Isolate* isolate,
158 const char* symbol, 169 const char* symbol,
159 size_t length) { 170 size_t length) {
160 return Symbol(createV8Private(isolate, symbol, length)); 171 return Symbol(createV8Private(isolate, symbol, length));
161 } 172 }
162 173
163 private: 174 private:
164 V8PrivateProperty() {} 175 V8PrivateProperty() {}
165 176
166 static v8::Local<v8::Private> createV8Private(v8::Isolate*, 177 static v8::Local<v8::Private> createV8Private(v8::Isolate*,
167 const char* symbol, 178 const char* symbol,
168 size_t length); 179 size_t length);
180 static v8::Local<v8::Private> createCachedV8Private(v8::Isolate*,
181 const char* symbol,
182 size_t length);
169 183
170 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ 184 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \
171 v8::Eternal<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME( \ 185 v8::Eternal<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME( \
172 InterfaceName, KeyName); // NOLINT(readability/naming/underscores) 186 InterfaceName, KeyName); // NOLINT(readability/naming/underscores)
173 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) 187 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER)
174 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER 188 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER
189
190 // TODO(peria): Do not use this specialized hack for
191 // Window#DocumentCachedAccessor. This is required to put v8::Private key in
192 // a snapshot, and it cannot be a v8::Eternal<> due to V8 serializer's
193 // requirement.
194 ScopedPersistent<v8::Private> m_symbolWindowDocumentCachedAccessor;
jbroman 2017/03/30 15:55:55 Out of curiosity, now that we're using v8::Private
peria 2017/03/31 04:26:50 Yes, I'm thinking so.
175 }; 195 };
176 196
177 } // namespace blink 197 } // namespace blink
178 198
179 #endif // V8PrivateProperty_h 199 #endif // V8PrivateProperty_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698