| 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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // expensive compared to get or set a private property. This class | 65 // expensive compared to get or set a private property. This class |
| 66 // provides a way to cache a private symbol and re-use it. | 66 // provides a way to cache a private symbol and re-use it. |
| 67 class CORE_EXPORT Symbol { | 67 class CORE_EXPORT Symbol { |
| 68 STACK_ALLOCATED(); | 68 STACK_ALLOCATED(); |
| 69 public: | 69 public: |
| 70 bool hasValue(v8::Local<v8::Context> context, v8::Local<v8::Object> obje
ct) const | 70 bool hasValue(v8::Local<v8::Context> context, v8::Local<v8::Object> obje
ct) const |
| 71 { | 71 { |
| 72 return v8CallBoolean(object->HasPrivate(context, m_privateSymbol)); | 72 return v8CallBoolean(object->HasPrivate(context, m_privateSymbol)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Returns the value of the private property if set, or undefined. |
| 76 v8::Local<v8::Value> getOrUndefined(v8::Local<v8::Context> context, v8::
Local<v8::Object> object) const |
| 77 { |
| 78 return v8CallOrCrash(object->GetPrivate(context, m_privateSymbol)); |
| 79 } |
| 80 |
| 81 // Returns the value of the private property if set, or an empty handle. |
| 75 v8::Local<v8::Value> get(v8::Local<v8::Context> context, v8::Local<v8::O
bject> object) const | 82 v8::Local<v8::Value> get(v8::Local<v8::Context> context, v8::Local<v8::O
bject> object) const |
| 76 { | 83 { |
| 77 if (!v8CallBoolean(object->HasPrivate(context, m_privateSymbol))) | 84 if (!v8CallBoolean(object->HasPrivate(context, m_privateSymbol))) |
| 78 return v8::Local<v8::Value>(); | 85 return v8::Local<v8::Value>(); |
| 79 v8::Local<v8::Value> value; | 86 v8::Local<v8::Value> value; |
| 80 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) | 87 if (v8Call(object->GetPrivate(context, m_privateSymbol), value)) |
| 81 return value; | 88 return value; |
| 82 return v8::Local<v8::Value>(); | 89 return v8::Local<v8::Value>(); |
| 83 } | 90 } |
| 84 | 91 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 143 |
| 137 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ | 144 #define V8_PRIVATE_PROPERTY_DECLARE_MEMBER(InterfaceName, KeyName) \ |
| 138 ScopedPersistent<v8::Private> V8_PRIVATE_PROPERTY_MEMBER_NAME(InterfaceName,
KeyName); // NOLINT(readability/naming/underscores) | 145 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) | 146 V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DECLARE_MEMBER) |
| 140 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER | 147 #undef V8_PRIVATE_PROPERTY_DECLARE_MEMBER |
| 141 }; | 148 }; |
| 142 | 149 |
| 143 } // namespace blink | 150 } // namespace blink |
| 144 | 151 |
| 145 #endif // V8PrivateProperty_h | 152 #endif // V8PrivateProperty_h |
| OLD | NEW |