| 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(PrivateScriptRunner, IsInitialized) \ | 26 X(PrivateScriptRunner, IsInitialized) \ |
| 27 X(IntersectionObserver, Callback) \ | 27 X(IntersectionObserver, Callback) \ |
| 28 X(MutationObserver, Callback) \ | 28 X(MutationObserver, Callback) \ |
| 29 X(PerformanceObserver, Callback) \ | 29 X(PerformanceObserver, Callback) \ |
| 30 X(V8NodeFilterCondition, Filter) | 30 X(V8NodeFilterCondition, Filter) \ |
| 31 X(WebGLRenderingContext, Extensions) \ |
| 32 X(WebGLRenderingContext, Misc) \ |
| 33 X(WebGLRenderingContext, Queries) \ |
| 34 X(WebGLRenderingContext, Samplers) \ |
| 35 X(WebGLRenderingContext, Textures2D) \ |
| 36 X(WebGLRenderingContext, Textures2DArray) \ |
| 37 X(WebGLRenderingContext, Textures3D) \ |
| 38 X(WebGLRenderingContext, TexturesCubeMap) \ |
| 39 X(WebGLFramebuffer, Attachments) \ |
| 40 X(WebGLProgram, Shaders) \ |
| 41 X(WebGLVertexArrayObjectBase, Buffers) |
| 31 | 42 |
| 32 // The getter's name for a private property. | 43 // The getter's name for a private property. |
| 33 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ | 44 #define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \ |
| 34 get##InterfaceName##PrivateKeyName | 45 get##InterfaceName##PrivateKeyName |
| 35 | 46 |
| 36 // The member variable's name for a private property. | 47 // The member variable's name for a private property. |
| 37 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \ | 48 #define V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName, PrivateKeyName) \ |
| 38 m_symbol##InterfaceName##PrivateKeyName | 49 m_symbol##InterfaceName##PrivateKeyName |
| 39 | 50 |
| 40 // The string used to create a private symbol. Must be unique per V8 instance. | 51 // The string used to create a private symbol. Must be unique per V8 instance. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 65 // expensive compared to get or set a private property. This class | 76 // expensive compared to get or set a private property. This class |
| 66 // provides a way to cache a private symbol and re-use it. | 77 // provides a way to cache a private symbol and re-use it. |
| 67 class CORE_EXPORT Symbol { | 78 class CORE_EXPORT Symbol { |
| 68 STACK_ALLOCATED(); | 79 STACK_ALLOCATED(); |
| 69 public: | 80 public: |
| 70 bool hasValue(v8::Local<v8::Context> context, v8::Local<v8::Object> obje
ct) const | 81 bool hasValue(v8::Local<v8::Context> context, v8::Local<v8::Object> obje
ct) const |
| 71 { | 82 { |
| 72 return v8CallBoolean(object->HasPrivate(context, m_privateSymbol)); | 83 return v8CallBoolean(object->HasPrivate(context, m_privateSymbol)); |
| 73 } | 84 } |
| 74 | 85 |
| 86 v8::Local<v8::Value> getOrUndefined(v8::Local<v8::Context> context, v8::
Local<v8::Object> object) const |
| 87 { |
| 88 return v8CallOrCrash(object->GetPrivate(context, m_privateSymbol)); |
| 89 } |
| 90 |
| 75 v8::Local<v8::Value> get(v8::Local<v8::Context> context, v8::Local<v8::O
bject> object) const | 91 v8::Local<v8::Value> get(v8::Local<v8::Context> context, v8::Local<v8::O
bject> object) const |
| 76 { | 92 { |
| 77 if (!v8CallBoolean(object->HasPrivate(context, m_privateSymbol))) | 93 if (!v8CallBoolean(object->HasPrivate(context, m_privateSymbol))) |
| 78 return v8::Local<v8::Value>(); | 94 return v8::Local<v8::Value>(); |
| 79 v8::Local<v8::Value> value; | 95 v8::Local<v8::Value> value; |
| 80 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) | 96 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) |
| 81 return value; | 97 return value; |
| 82 return v8::Local<v8::Value>(); | 98 return v8::Local<v8::Value>(); |
| 83 } | 99 } |
| 84 | 100 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 152 |
| 137 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ | 153 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ |
| 138 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName,
KeyName); // NOLINT(readability/naming/underscores) | 154 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName,
KeyName); // NOLINT(readability/naming/underscores) |
| 139 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) | 155 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) |
| 140 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER | 156 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER |
| 141 }; | 157 }; |
| 142 | 158 |
| 143 } // namespace blink | 159 } // namespace blink |
| 144 | 160 |
| 145 #endif // V8PrivateProperty_h | 161 #endif // V8PrivateProperty_h |
| OLD | NEW |