Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 #include "bindings/core/v8/WrapperTypeInfo.h" | 34 #include "bindings/core/v8/WrapperTypeInfo.h" |
| 35 #include "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
| 36 #include "platform/heap/Handle.h" | 36 #include "platform/heap/Handle.h" |
| 37 #include "wtf/Noncopyable.h" | 37 #include "wtf/Noncopyable.h" |
| 38 #include "wtf/TypeTraits.h" | 38 #include "wtf/TypeTraits.h" |
| 39 #include <v8.h> | 39 #include <v8.h> |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 /** | 43 // ScriptWrappable wraps a V8 object and its WrapperTypeInfo. |
| 44 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. | 44 // |
| 45 * | 45 // ScriptWrappable acts much like a v8::Persistent<> in that it keeps a |
| 46 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a | 46 // V8 object alive. |
|
haraken
2016/08/23 07:55:40
This is not really correct. ScriptWrappable keeps
Yuki
2016/08/23 09:49:52
I've rewritten the class comment.
| |
| 47 * V8 object alive. | |
| 48 * | |
| 49 * The state transitions are: | |
| 50 * - new: an empty ScriptWrappable. | |
| 51 * - setWrapper: install a v8::Persistent (or empty) | |
| 52 * - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter): | |
| 53 * remove v8::Persistent and become empty. | |
| 54 */ | |
| 55 class CORE_EXPORT ScriptWrappable { | 47 class CORE_EXPORT ScriptWrappable { |
| 56 WTF_MAKE_NONCOPYABLE(ScriptWrappable); | 48 WTF_MAKE_NONCOPYABLE(ScriptWrappable); |
| 57 public: | 49 public: |
| 58 ScriptWrappable() { } | 50 ScriptWrappable() { } |
| 59 | 51 |
| 60 template<typename T> | 52 template<typename T> |
| 61 T* toImpl() | 53 T* toImpl() |
| 62 { | 54 { |
| 63 // All ScriptWrappables are managed by the Blink GC heap; check that | 55 // All ScriptWrappables are managed by the Blink GC heap; check that |
| 64 // |T| is a garbage collected type. | 56 // |T| is a garbage collected type. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 83 | 75 |
| 84 // Creates and returns a new wrapper object. | 76 // Creates and returns a new wrapper object. |
| 85 virtual v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creat ionContext); | 77 virtual v8::Local<v8::Object> wrap(v8::Isolate*, v8::Local<v8::Object> creat ionContext); |
| 86 | 78 |
| 87 // Associates the instance with the given |wrapper| if this instance is not | 79 // Associates the instance with the given |wrapper| if this instance is not |
| 88 // yet associated with any wrapper. Returns the wrapper already associated | 80 // yet associated with any wrapper. Returns the wrapper already associated |
| 89 // or |wrapper| if not yet associated. | 81 // or |wrapper| if not yet associated. |
| 90 // The caller should always use the returned value rather than |wrapper|. | 82 // The caller should always use the returned value rather than |wrapper|. |
| 91 virtual v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const Wrapp erTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; | 83 virtual v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const Wrapp erTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; |
| 92 | 84 |
| 85 virtual bool hasPendingActivity() const { return false; } | |
|
haraken
2016/08/23 07:55:40
Add a comment.
| |
| 86 | |
| 93 // Associates this instance with the given |wrapper| if this instance is not | 87 // Associates this instance with the given |wrapper| if this instance is not |
| 94 // yet associated with any wrapper. Returns true if the given wrapper is | 88 // yet associated with any wrapper. Returns true if the given wrapper is |
| 95 // associated with this instance, or false if this instance is already | 89 // associated with this instance, or false if this instance is already |
| 96 // associated with a wrapper. In the latter case, |wrapper| will be updated | 90 // associated with a wrapper. In the latter case, |wrapper| will be updated |
| 97 // to the existing wrapper. | 91 // to the existing wrapper. |
| 98 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo , v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN | 92 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo , v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN |
| 99 { | 93 { |
| 100 ASSERT(!wrapper.IsEmpty()); | 94 ASSERT(!wrapper.IsEmpty()); |
| 101 if (UNLIKELY(containsWrapper())) { | 95 if (UNLIKELY(containsWrapper())) { |
| 102 wrapper = mainWorldWrapper(isolate); | 96 wrapper = mainWorldWrapper(isolate); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 return containsWrapper(); | 131 return containsWrapper(); |
| 138 } | 132 } |
| 139 | 133 |
| 140 void setReference(const v8::Persistent<v8::Object>& parent, v8::Isolate* iso late) | 134 void setReference(const v8::Persistent<v8::Object>& parent, v8::Isolate* iso late) |
| 141 { | 135 { |
| 142 isolate->SetReference(parent, m_mainWorldWrapper); | 136 isolate->SetReference(parent, m_mainWorldWrapper); |
| 143 } | 137 } |
| 144 | 138 |
| 145 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); } | 139 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); } |
| 146 | 140 |
| 147 /** | 141 // Mark wrapper of this ScriptWrappable as alive in V8. Only marks |
| 148 * Mark wrapper of this ScriptWrappable as alive in V8. Only marks | 142 // wrapper in the main world. To mark wrappers in all worlds call |
| 149 * wrapper in the main world. To mark wrappers in all worlds call | 143 // ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*) |
| 150 * ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*) | |
| 151 */ | |
| 152 void markWrapper(const WrapperVisitor*) const; | 144 void markWrapper(const WrapperVisitor*) const; |
| 153 | 145 |
| 154 DECLARE_VIRTUAL_TRACE_WRAPPERS() {}; | 146 DECLARE_VIRTUAL_TRACE_WRAPPERS() {}; |
| 155 | 147 |
| 156 // With Oilpan we don't need a ScriptWrappable destructor. | |
| 157 // | |
| 158 // 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not nee ded | |
| 159 // because Oilpan is not using reference counting at all. If containsWrapper () is true, | |
| 160 // it means that ScriptWrappable still has a wrapper. In this case, the dest ructor | |
| 161 // must not be called since the wrapper has a persistent handle back to this ScriptWrappable object. | |
| 162 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of more things are | |
| 163 // already broken), we must not hit the RELEASE_ASSERT. | |
| 164 | |
| 165 private: | 148 private: |
| 166 // These classes are exceptionally allowed to use mainWorldWrapper(). | 149 // These classes are exceptionally allowed to use mainWorldWrapper(). |
| 167 friend class DOMDataStore; | 150 friend class DOMDataStore; |
| 168 friend class V8HiddenValue; | 151 friend class V8HiddenValue; |
| 169 friend class V8PrivateProperty; | 152 friend class V8PrivateProperty; |
| 170 friend class WebGLRenderingContextBase; | 153 friend class WebGLRenderingContextBase; |
| 171 | 154 |
| 172 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const | 155 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const |
| 173 { | 156 { |
| 174 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper); | 157 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 205 // in X's cpp code, and instantiate X, i.e. "template class X;". | 188 // in X's cpp code, and instantiate X, i.e. "template class X;". |
| 206 #define DECLARE_WRAPPERTYPEINFO() \ | 189 #define DECLARE_WRAPPERTYPEINFO() \ |
| 207 public: \ | 190 public: \ |
| 208 const WrapperTypeInfo* wrapperTypeInfo() const override; \ | 191 const WrapperTypeInfo* wrapperTypeInfo() const override; \ |
| 209 private: \ | 192 private: \ |
| 210 typedef void end_of_define_wrappertypeinfo_not_reached_t | 193 typedef void end_of_define_wrappertypeinfo_not_reached_t |
| 211 | 194 |
| 212 } // namespace blink | 195 } // namespace blink |
| 213 | 196 |
| 214 #endif // ScriptWrappable_h | 197 #endif // ScriptWrappable_h |
| OLD | NEW |