| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "bindings/core/v8/ScriptPromiseProperties.h" | 10 #include "platform/PlatformExport.h" |
| 11 #include "bindings/core/v8/V8BindingMacros.h" | 11 #include "platform/bindings/ScriptPromiseProperties.h" |
| 12 #include "bindings/core/v8/V8PerIsolateData.h" | 12 #include "platform/bindings/V8BindingMacros.h" |
| 13 #include "core/CoreExport.h" | 13 #include "platform/bindings/V8PerIsolateData.h" |
| 14 #include "platform/wtf/Allocator.h" | 14 #include "platform/wtf/Allocator.h" |
| 15 #include "platform/wtf/PtrUtil.h" | 15 #include "platform/wtf/PtrUtil.h" |
| 16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 class ScriptWrappable; | 20 class ScriptWrappable; |
| 21 | 21 |
| 22 // TODO(peria): Remove properties just to keep V8 objects alive. | 22 // TODO(peria): Remove properties just to keep V8 objects alive. |
| 23 // e.g. InternalBody.Buffer, InternalBody.Stream, IDBCursor.Request, | 23 // e.g. InternalBody.Buffer, InternalBody.Stream, IDBCursor.Request, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // auto private = V8PrivateProperty::getMessageEventCachedData(isolate); | 81 // auto private = V8PrivateProperty::getMessageEventCachedData(isolate); |
| 82 // v8::Local<v8::Object> object = ...; | 82 // v8::Local<v8::Object> object = ...; |
| 83 // v8::Local<v8::Value> value = private.getOrUndefined(object); | 83 // v8::Local<v8::Value> value = private.getOrUndefined(object); |
| 84 // value = ...; | 84 // value = ...; |
| 85 // private.set(object, value); | 85 // private.set(object, value); |
| 86 // | 86 // |
| 87 // Usage 2) Slow path to create a global private symbol. | 87 // Usage 2) Slow path to create a global private symbol. |
| 88 // const char symbolName[] = "Interface#PrivateKeyName"; | 88 // const char symbolName[] = "Interface#PrivateKeyName"; |
| 89 // auto private = V8PrivateProperty::createSymbol(isolate, symbolName); | 89 // auto private = V8PrivateProperty::createSymbol(isolate, symbolName); |
| 90 // ... | 90 // ... |
| 91 class CORE_EXPORT V8PrivateProperty { | 91 class PLATFORM_EXPORT V8PrivateProperty { |
| 92 USING_FAST_MALLOC(V8PrivateProperty); | 92 USING_FAST_MALLOC(V8PrivateProperty); |
| 93 WTF_MAKE_NONCOPYABLE(V8PrivateProperty); | 93 WTF_MAKE_NONCOPYABLE(V8PrivateProperty); |
| 94 | 94 |
| 95 public: | 95 public: |
| 96 // Provides fast access to V8's private properties. | 96 // Provides fast access to V8's private properties. |
| 97 // | 97 // |
| 98 // Retrieving/creating a global private symbol from a string is very | 98 // Retrieving/creating a global private symbol from a string is very |
| 99 // expensive compared to get or set a private property. This class | 99 // expensive compared to get or set a private property. This class |
| 100 // provides a way to cache a private symbol and re-use it. | 100 // provides a way to cache a private symbol and re-use it. |
| 101 class CORE_EXPORT Symbol { | 101 class PLATFORM_EXPORT Symbol { |
| 102 STACK_ALLOCATED(); | 102 STACK_ALLOCATED(); |
| 103 | 103 |
| 104 public: | 104 public: |
| 105 bool HasValue(v8::Local<v8::Object> object) const { | 105 bool HasValue(v8::Local<v8::Object> object) const { |
| 106 return object->HasPrivate(GetContext(), private_symbol_).ToChecked(); | 106 return object->HasPrivate(GetContext(), private_symbol_).ToChecked(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Returns the value of the private property if set, or undefined. | 109 // Returns the value of the private property if set, or undefined. |
| 110 v8::Local<v8::Value> GetOrUndefined(v8::Local<v8::Object> object) const { | 110 v8::Local<v8::Value> GetOrUndefined(v8::Local<v8::Object> object) const { |
| 111 return object->GetPrivate(GetContext(), private_symbol_).ToLocalChecked(); | 111 return object->GetPrivate(GetContext(), private_symbol_).ToLocalChecked(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // TODO(peria): Do not use this specialized hack for | 214 // TODO(peria): Do not use this specialized hack for |
| 215 // Window#DocumentCachedAccessor. This is required to put v8::Private key in | 215 // Window#DocumentCachedAccessor. This is required to put v8::Private key in |
| 216 // a snapshot, and it cannot be a v8::Eternal<> due to V8 serializer's | 216 // a snapshot, and it cannot be a v8::Eternal<> due to V8 serializer's |
| 217 // requirement. | 217 // requirement. |
| 218 ScopedPersistent<v8::Private> symbol_window_document_cached_accessor_; | 218 ScopedPersistent<v8::Private> symbol_window_document_cached_accessor_; |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 } // namespace blink | 221 } // namespace blink |
| 222 | 222 |
| 223 #endif // V8PrivateProperty_h | 223 #endif // V8PrivateProperty_h |
| OLD | NEW |