| OLD | NEW |
| 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(MessageEvent, CachedData) | 25 X(MessageEvent, CachedData) \ |
| 26 X(WebGLRenderingContext, Extensions) \ |
| 27 X(WebGLRenderingContext, Misc) \ |
| 28 X(WebGLRenderingContext, Queries) \ |
| 29 X(WebGLRenderingContext, Samplers) \ |
| 30 X(WebGLRenderingContext, Textures2D) \ |
| 31 X(WebGLRenderingContext, Textures2DArray) \ |
| 32 X(WebGLRenderingContext, Textures3D) \ |
| 33 X(WebGLRenderingContext, TexturesCubeMap) \ |
| 34 X(WebGLFramebuffer, Attachments) \ |
| 35 X(WebGLProgram, Shaders) \ |
| 36 X(WebGLVertexArrayObjectBase, Buffers) |
| 26 | 37 |
| 27 // The getter's name for a private property. | 38 // The getter's name for a private property. |
| 28 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ | 39 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ |
| 29 get##InterfaceName##PrivateKeyName | 40 get##InterfaceName##PrivateKeyName |
| 30 | 41 |
| 31 // The member variable's name for a private property. | 42 // The member variable's name for a private property. |
| 32 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \ | 43 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \ |
| 33 m_symbol##InterfaceName##PrivateKeyName | 44 m_symbol##InterfaceName##PrivateKeyName |
| 34 | 45 |
| 35 // The string used to create a private symbol. Must be unique per V8 instance. | 46 // The string used to create a private symbol. Must be unique per V8 instance. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 WTF_MAKE_NONCOPYABLE(V8PrivateProperty); | 66 WTF_MAKE_NONCOPYABLE(V8PrivateProperty); |
| 56 public: | 67 public: |
| 57 // Provides fast access to V8's private properties. | 68 // Provides fast access to V8's private properties. |
| 58 // | 69 // |
| 59 // Retrieving/creating a global private symbol from a string is very | 70 // Retrieving/creating a global private symbol from a string is very |
| 60 // expensive compared to get or set a private property. This class | 71 // expensive compared to get or set a private property. This class |
| 61 // provides a way to cache a private symbol and re-use it. | 72 // provides a way to cache a private symbol and re-use it. |
| 62 class CORE_EXPORT Symbol { | 73 class CORE_EXPORT Symbol { |
| 63 STACK_ALLOCATED(); | 74 STACK_ALLOCATED(); |
| 64 public: | 75 public: |
| 65 v8::Local<v8::Value> get(v8::Local<v8::Context> context, v8::Local<v8::O
bject> object) | 76 v8::Local<v8::Value> get(v8::Local<v8::Context> context, v8::Local<v8::O
bject> object) const |
| 66 { | 77 { |
| 67 if (!v8CallBoolean(object->HasPrivate(context, m_privateSymbol))) | 78 if (!v8CallBoolean(object->HasPrivate(context, m_privateSymbol))) |
| 68 return v8::Local<v8::Value>(); | 79 return v8::Local<v8::Value>(); |
| 69 v8::Local<v8::Value> value; | 80 v8::Local<v8::Value> value; |
| 70 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) | 81 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) |
| 71 return value; | 82 return value; |
| 72 return v8::Local<v8::Value>(); | 83 return v8::Local<v8::Value>(); |
| 73 } | 84 } |
| 74 | 85 |
| 75 bool set(v8::Local<v8::Context> context, v8::Local<v8::Object> object, v
8::Local<v8::Value> value) | 86 bool set(v8::Local<v8::Context> context, v8::Local<v8::Object> object, v
8::Local<v8::Value> value) const |
| 76 { | 87 { |
| 77 return v8CallBoolean(object->SetPrivate(context, m_privateSymbol, va
lue)); | 88 return v8CallBoolean(object->SetPrivate(context, m_privateSymbol, va
lue)); |
| 78 } | 89 } |
| 79 | 90 |
| 80 private: | 91 private: |
| 81 friend class V8PrivateProperty; | 92 friend class V8PrivateProperty; |
| 82 // V8ServiceWorkerMessageEventInternal is exceptionally allowed to call | 93 // V8ServiceWorkerMessageEventInternal is exceptionally allowed to call |
| 83 // to getFromMainWorld. | 94 // to getFromMainWorld. |
| 84 friend class V8ServiceWorkerMessageEventInternal; | 95 friend class V8ServiceWorkerMessageEventInternal; |
| 85 | 96 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 137 |
| 127 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ | 138 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ |
| 128 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName,
KeyName); // NOLINT(readability/naming/underscores) | 139 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName,
KeyName); // NOLINT(readability/naming/underscores) |
| 129 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) | 140 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) |
| 130 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER | 141 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER |
| 131 }; | 142 }; |
| 132 | 143 |
| 133 } // namespace blink | 144 } // namespace blink |
| 134 | 145 |
| 135 #endif // V8PrivateProperty_h | 146 #endif // V8PrivateProperty_h |
| OLD | NEW |