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

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

Issue 2335203006: Add [CachedAccessor] attribute to cache (almost) constant accessors (window.document). (Closed)
Patch Set: Polishing + naming revisited Created 4 years, 3 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 "bindings/core/v8/ScopedPersistent.h" 8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/ScriptPromiseProperties.h" 9 #include "bindings/core/v8/ScriptPromiseProperties.h"
10 #include "bindings/core/v8/V8BindingMacros.h" 10 #include "bindings/core/v8/V8BindingMacros.h"
11 #include "bindings/core/v8/V8PerIsolateData.h" 11 #include "bindings/core/v8/V8PerIsolateData.h"
12 #include "core/CoreExport.h" 12 #include "core/CoreExport.h"
13 #include "wtf/Allocator.h" 13 #include "wtf/Allocator.h"
14 #include "wtf/PtrUtil.h" 14 #include "wtf/PtrUtil.h"
15 #include <memory> 15 #include <memory>
16 #include <v8.h> 16 #include <v8.h>
17 17
18 namespace blink { 18 namespace blink {
19 19
20 class ScriptState; 20 class ScriptState;
21 class ScriptWrappable; 21 class ScriptWrappable;
22 22
23 // Apply |X| for each pair of (InterfaceName, PrivateKeyName). 23 // Apply |X| for each pair of (InterfaceName, PrivateKeyName).
24 #define V8_PRIVATE_PROPERTY_FOR_EACH(X) \ 24 #define V8_PRIVATE_PROPERTY_FOR_EACH(X) \
25 X(CustomEvent, Detail) \ 25 X(CustomEvent, Detail) \
26 X(DOMException, Error) \ 26 X(DOMException, Error) \
27 X(ErrorEvent, Error) \ 27 X(ErrorEvent, Error) \
28 X(IDBObserver, Callback) \ 28 X(IDBObserver, Callback) \
29 X(IntersectionObserver, Callback) \ 29 X(IntersectionObserver, Callback) \
30 X(MessageEvent, CachedData) \ 30 X(MessageEvent, CachedData) \
31 X(MutationObserver, Callback) \ 31 X(MutationObserver, Callback) \
32 X(PerformanceObserver, Callback) \ 32 X(PerformanceObserver, Callback) \
33 X(PrivateScriptRunner, IsInitialized) \ 33 X(PrivateScriptRunner, IsInitialized) \
34 X(SameObject, NotificationActions) \ 34 X(SameObject, NotificationActions) \
35 X(SameObject, NotificationData) \ 35 X(SameObject, NotificationData) \
36 X(SameObject, NotificationVibrate) \ 36 X(SameObject, NotificationVibrate) \
37 X(V8NodeFilterCondition, Filter) 37 X(V8NodeFilterCondition, Filter) \
38 X(Window, Document)
haraken 2016/09/20 14:15:03 I'd prefer X(Window, DocumentCachedAccessor) to av
38 39
39 // The getter's name for a private property. 40 // The getter's name for a private property.
40 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ 41 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \
41 get##InterfaceName##PrivateKeyName 42 get##InterfaceName##PrivateKeyName
42 43
43 // The member variable's name for a private property. 44 // The member variable's name for a private property.
44 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \ 45 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \
45 m_symbol##InterfaceName##PrivateKeyName 46 m_symbol##InterfaceName##PrivateKeyName
46 47
47 // The string used to create a private symbol. Must be unique per V8 instance. 48 // The string used to create a private symbol. Must be unique per V8 instance.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) 95 if (v8Call(object->GetPrivate(context, m_privateSymbol), value))
95 return value; 96 return value;
96 return v8::Local<v8::Value>(); 97 return v8::Local<v8::Value>();
97 } 98 }
98 99
99 bool set(v8::Local<v8::Context> context, v8::Local<v8::Object> object, v 8::Local<v8::Value> value) const 100 bool set(v8::Local<v8::Context> context, v8::Local<v8::Object> object, v 8::Local<v8::Value> value) const
100 { 101 {
101 return v8CallBoolean(object->SetPrivate(context, m_privateSymbol, va lue)); 102 return v8CallBoolean(object->SetPrivate(context, m_privateSymbol, va lue));
102 } 103 }
103 104
105 v8::Local<v8::Private> getPrivate()
106 {
107 return m_privateSymbol;
108 }
109
104 private: 110 private:
105 friend class V8PrivateProperty; 111 friend class V8PrivateProperty;
106 // The following classes are exceptionally allowed to call to 112 // The following classes are exceptionally allowed to call to
107 // getFromMainWorld. 113 // getFromMainWorld.
108 friend class V8CustomEvent; 114 friend class V8CustomEvent;
109 friend class V8ServiceWorkerMessageEventInternal; 115 friend class V8ServiceWorkerMessageEventInternal;
110 116
111 explicit Symbol(v8::Local<v8::Private> privateSymbol) 117 explicit Symbol(v8::Local<v8::Private> privateSymbol)
112 : m_privateSymbol(privateSymbol) { } 118 : m_privateSymbol(privateSymbol) { }
113 119
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 157
152 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ 158 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \
153 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName); // NOLINT(readability/naming/underscores) 159 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, KeyName); // NOLINT(readability/naming/underscores)
154 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) 160 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER)
155 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER 161 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER
156 }; 162 };
157 163
158 } // namespace blink 164 } // namespace blink
159 165
160 #endif // V8PrivateProperty_h 166 #endif // V8PrivateProperty_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698