Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScopedPersistent.h

Issue 2843603002: Move ScriptWrappable and dependencies to platform/bindings (Closed)
Patch Set: Rebase and try again Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef ScopedPersistent_h 31 // This file has been moved to platform/bindings/ScopedPersistent.h.
32 #define ScopedPersistent_h 32 // TODO(adithyas): Remove this file.
33 33 #include "platform/bindings/ScopedPersistent.h"
34 #include <memory>
35
36 #include "bindings/core/v8/ScriptWrappableVisitor.h"
37 #include "platform/wtf/Allocator.h"
38 #include "platform/wtf/Noncopyable.h"
39 #include "v8/include/v8.h"
40
41 namespace blink {
42
43 template <typename T>
44 class ScopedPersistent {
45 USING_FAST_MALLOC(ScopedPersistent);
46 WTF_MAKE_NONCOPYABLE(ScopedPersistent);
47
48 public:
49 ScopedPersistent() {}
50
51 ScopedPersistent(v8::Isolate* isolate, v8::Local<T> handle)
52 : handle_(isolate, handle) {}
53
54 ScopedPersistent(v8::Isolate* isolate, v8::MaybeLocal<T> maybe) {
55 v8::Local<T> local;
56 if (maybe.ToLocal(&local))
57 handle_.Reset(isolate, local);
58 }
59
60 virtual ~ScopedPersistent() { Clear(); }
61
62 ALWAYS_INLINE v8::Local<T> NewLocal(v8::Isolate* isolate) const {
63 return v8::Local<T>::New(isolate, handle_);
64 }
65
66 // If you don't need to get weak callback, use setPhantom instead.
67 // setPhantom is faster than setWeak.
68 template <typename P>
69 void SetWeak(P* parameters,
70 void (*callback)(const v8::WeakCallbackInfo<P>&),
71 v8::WeakCallbackType type = v8::WeakCallbackType::kParameter) {
72 handle_.SetWeak(parameters, callback, type);
73 }
74
75 // Turns this handle into a weak phantom handle without
76 // finalization callback.
77 void SetPhantom() { handle_.SetWeak(); }
78
79 void ClearWeak() { handle_.template ClearWeak<void>(); }
80
81 bool IsEmpty() const { return handle_.IsEmpty(); }
82 bool IsWeak() const { return handle_.IsWeak(); }
83
84 virtual void Set(v8::Isolate* isolate, v8::Local<T> handle) {
85 handle_.Reset(isolate, handle);
86 }
87
88 // Note: This is clear in the std::unique_ptr sense, not the v8::Local sense.
89 void Clear() { handle_.Reset(); }
90
91 bool operator==(const ScopedPersistent<T>& other) {
92 return handle_ == other.handle_;
93 }
94
95 template <class S>
96 bool operator==(const v8::Local<S> other) const {
97 return handle_ == other;
98 }
99
100 ALWAYS_INLINE v8::Persistent<T>& Get() { return handle_; }
101
102 private:
103 v8::Persistent<T> handle_;
104 };
105
106 } // namespace blink
107
108 #endif // ScopedPersistent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698