diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-04-17 23:16:22 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-04-30 00:23:33 +0200 |
commit | 723d5c058fa180684df13bd2a83bbf3ca6201957 (patch) | |
tree | 6aeb4bc88e6c437853327cced05ab797827c22f2 /src/node_persistent.h | |
parent | 095bd569aef4fec433ddb26e681eaabff1f7fd10 (diff) | |
download | android-node-v8-723d5c058fa180684df13bd2a83bbf3ca6201957.tar.gz android-node-v8-723d5c058fa180684df13bd2a83bbf3ca6201957.tar.bz2 android-node-v8-723d5c058fa180684df13bd2a83bbf3ca6201957.zip |
src: prefer v8::Global over node::Persistent
`v8::Global` is essentially a nicer variant of `node::Persistent` that,
in addition to reset-on-destroy, also implements move semantics.
This commit makes the necessary replacements, removes
`node::Persistent` and (now-)unnecessary inclusions of the
`node_persistent.h` header, and makes some of the functions that
take Persistents as arguments more generic so that they work with all
`v8::PersistentBase` flavours.
PR-URL: https://github.com/nodejs/node/pull/27287
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_persistent.h')
-rw-r--r-- | src/node_persistent.h | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/node_persistent.h b/src/node_persistent.h deleted file mode 100644 index 6126ebc6c2..0000000000 --- a/src/node_persistent.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SRC_NODE_PERSISTENT_H_ -#define SRC_NODE_PERSISTENT_H_ - -#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#include "v8.h" - -namespace node { - -template <typename T> -struct ResetInDestructorPersistentTraits { - static const bool kResetInDestructor = true; - template <typename S, typename M> - // Disallow copy semantics by leaving this unimplemented. - inline static void Copy( - const v8::Persistent<S, M>&, - v8::Persistent<T, ResetInDestructorPersistentTraits<T>>*); -}; - -// v8::Persistent does not reset the object slot in its destructor. That is -// acknowledged as a flaw in the V8 API and expected to change in the future -// but for now node::Persistent is the easier and safer alternative. -template <typename T> -using Persistent = v8::Persistent<T, ResetInDestructorPersistentTraits<T>>; - -class PersistentToLocal { - public: - // If persistent.IsWeak() == false, then do not call persistent.Reset() - // while the returned Local<T> is still in scope, it will destroy the - // reference to the object. - template <class TypeName> - static inline v8::Local<TypeName> Default( - v8::Isolate* isolate, - const Persistent<TypeName>& persistent) { - if (persistent.IsWeak()) { - return PersistentToLocal::Weak(isolate, persistent); - } else { - return PersistentToLocal::Strong(persistent); - } - } - - // Unchecked conversion from a non-weak Persistent<T> to Local<T>, - // use with care! - // - // Do not call persistent.Reset() while the returned Local<T> is still in - // scope, it will destroy the reference to the object. - template <class TypeName> - static inline v8::Local<TypeName> Strong( - const Persistent<TypeName>& persistent) { - return *reinterpret_cast<v8::Local<TypeName>*>( - const_cast<Persistent<TypeName>*>(&persistent)); - } - - template <class TypeName> - static inline v8::Local<TypeName> Weak( - v8::Isolate* isolate, - const Persistent<TypeName>& persistent) { - return v8::Local<TypeName>::New(isolate, persistent); - } -}; - -} // namespace node - -#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_NODE_PERSISTENT_H_ |