| 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 TraceWrapperV8Reference_h | 5 // This file has been moved to platform/bindings/TraceWrapperV8Reference.h. |
| 6 #define TraceWrapperV8Reference_h | 6 // TODO(adithyas): Remove this file. |
| 7 | 7 #include "platform/bindings/TraceWrapperV8Reference.h" |
| 8 #include "bindings/core/v8/ScriptWrappableVisitor.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 /** | |
| 13 * TraceWrapperV8Reference is used to trace from Blink to V8. If wrapper | |
| 14 * tracing is disabled, the reference is a weak v8::Persistent. Otherwise, | |
| 15 * the reference is (strongly) traced by wrapper tracing. | |
| 16 * | |
| 17 * TODO(mlippautz): Use a better handle type than v8::Persistent. | |
| 18 */ | |
| 19 template <typename T> | |
| 20 class TraceWrapperV8Reference { | |
| 21 public: | |
| 22 explicit TraceWrapperV8Reference(void* parent) : parent_(parent) {} | |
| 23 | |
| 24 TraceWrapperV8Reference(v8::Isolate* isolate, | |
| 25 void* parent, | |
| 26 v8::Local<T> handle) | |
| 27 : parent_(parent) { | |
| 28 InternalSet(isolate, handle); | |
| 29 handle_.SetWeak(); | |
| 30 } | |
| 31 | |
| 32 ~TraceWrapperV8Reference() { Clear(); } | |
| 33 | |
| 34 void Set(v8::Isolate* isolate, v8::Local<T> handle) { | |
| 35 InternalSet(isolate, handle); | |
| 36 handle_.SetWeak(); | |
| 37 } | |
| 38 | |
| 39 template <typename P> | |
| 40 void Set(v8::Isolate* isolate, | |
| 41 v8::Local<T> handle, | |
| 42 P* parameters, | |
| 43 void (*callback)(const v8::WeakCallbackInfo<P>&), | |
| 44 v8::WeakCallbackType type = v8::WeakCallbackType::kParameter) { | |
| 45 InternalSet(isolate, handle); | |
| 46 handle_.SetWeak(parameters, callback, type); | |
| 47 } | |
| 48 | |
| 49 ALWAYS_INLINE v8::Local<T> NewLocal(v8::Isolate* isolate) const { | |
| 50 return v8::Local<T>::New(isolate, handle_); | |
| 51 } | |
| 52 | |
| 53 bool IsEmpty() const { return handle_.IsEmpty(); } | |
| 54 void Clear() { handle_.Reset(); } | |
| 55 ALWAYS_INLINE v8::Persistent<T>& Get() { return handle_; } | |
| 56 | |
| 57 template <typename S> | |
| 58 const TraceWrapperV8Reference<S>& Cast() const { | |
| 59 return reinterpret_cast<const TraceWrapperV8Reference<S>&>( | |
| 60 const_cast<const TraceWrapperV8Reference<T>&>(*this)); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 inline void InternalSet(v8::Isolate* isolate, v8::Local<T> handle) { | |
| 65 handle_.Reset(isolate, handle); | |
| 66 ScriptWrappableVisitor::WriteBarrier(isolate, parent_, &Cast<v8::Value>()); | |
| 67 } | |
| 68 | |
| 69 v8::Persistent<T> handle_; | |
| 70 void* parent_; | |
| 71 }; | |
| 72 | |
| 73 } // namespace blink | |
| 74 | |
| 75 #endif // TraceWrapperV8Reference_h | |
| OLD | NEW |