| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // auto private = V8PrivateProperty::getMessageEventCachedData(isolate); | 82 // auto private = V8PrivateProperty::getMessageEventCachedData(isolate); |
| 83 // v8::Local<v8::Object> object = ...; | 83 // v8::Local<v8::Object> object = ...; |
| 84 // v8::Local<v8::Value> value = private.getOrUndefined(object); | 84 // v8::Local<v8::Value> value = private.getOrUndefined(object); |
| 85 // value = ...; | 85 // value = ...; |
| 86 // private.set(object, value); | 86 // private.set(object, value); |
| 87 // | 87 // |
| 88 // Usage 2) Slow path to create a global private symbol. | 88 // Usage 2) Slow path to create a global private symbol. |
| 89 // const char symbolName[] = "Interface#PrivateKeyName"; | 89 // const char symbolName[] = "Interface#PrivateKeyName"; |
| 90 // auto private = V8PrivateProperty::createSymbol(isolate, symbolName); | 90 // auto private = V8PrivateProperty::createSymbol(isolate, symbolName); |
| 91 // ... | 91 // ... |
| 92 class CORE_EXPORT V8PrivateProperty { | 92 class PLATFORM_EXPORT V8PrivateProperty { |
| 93 USING_FAST_MALLOC(V8PrivateProperty); | 93 USING_FAST_MALLOC(V8PrivateProperty); |
| 94 WTF_MAKE_NONCOPYABLE(V8PrivateProperty); | 94 WTF_MAKE_NONCOPYABLE(V8PrivateProperty); |
| 95 | 95 |
| 96 public: | 96 public: |
| 97 // Provides fast access to V8's private properties. | 97 // Provides fast access to V8's private properties. |
| 98 // | 98 // |
| 99 // Retrieving/creating a global private symbol from a string is very | 99 // Retrieving/creating a global private symbol from a string is very |
| 100 // expensive compared to get or set a private property. This class | 100 // expensive compared to get or set a private property. This class |
| 101 // provides a way to cache a private symbol and re-use it. | 101 // provides a way to cache a private symbol and re-use it. |
| 102 class CORE_EXPORT Symbol { | 102 class PLATFORM_EXPORT Symbol { |
| 103 STACK_ALLOCATED(); | 103 STACK_ALLOCATED(); |
| 104 | 104 |
| 105 public: | 105 public: |
| 106 bool HasValue(v8::Local<v8::Object> object) const { | 106 bool HasValue(v8::Local<v8::Object> object) const { |
| 107 return object->HasPrivate(GetContext(), private_symbol_).ToChecked(); | 107 return object->HasPrivate(GetContext(), private_symbol_).ToChecked(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Returns the value of the private property if set, or undefined. | 110 // Returns the value of the private property if set, or undefined. |
| 111 v8::Local<v8::Value> GetOrUndefined(v8::Local<v8::Object> object) const { | 111 v8::Local<v8::Value> GetOrUndefined(v8::Local<v8::Object> object) const { |
| 112 return object->GetPrivate(GetContext(), private_symbol_).ToLocalChecked(); | 112 return object->GetPrivate(GetContext(), private_symbol_).ToLocalChecked(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // TODO(peria): Do not use this specialized hack for | 215 // TODO(peria): Do not use this specialized hack for |
| 216 // Window#DocumentCachedAccessor. This is required to put v8::Private key in | 216 // Window#DocumentCachedAccessor. This is required to put v8::Private key in |
| 217 // a snapshot, and it cannot be a v8::Eternal<> due to V8 serializer's | 217 // a snapshot, and it cannot be a v8::Eternal<> due to V8 serializer's |
| 218 // requirement. | 218 // requirement. |
| 219 ScopedPersistent<v8::Private> symbol_window_document_cached_accessor_; | 219 ScopedPersistent<v8::Private> symbol_window_document_cached_accessor_; |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 } // namespace blink | 222 } // namespace blink |
| 223 | 223 |
| 224 #endif // V8PrivateProperty_h | 224 #endif // V8PrivateProperty_h |
| OLD | NEW |