Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! src: prefer v8::Global over node::Persistent
  • Loading branch information
addaleax committed Apr 18, 2019
commit ceb827b5c7725bac10a044844b281112f10181a7
1 change: 0 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@
'src/node_options-inl.h',
'src/node_perf.h',
'src/node_perf_common.h',
'src/node_persistent.h',
'src/node_platform.h',
'src/node_process.h',
'src/node_revert.h',
Expand Down
1 change: 0 additions & 1 deletion src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "base_object.h"
#include "env-inl.h"
#include "node_persistent.h"
#include "util-inl.h"
#include "v8.h"

Expand Down
1 change: 0 additions & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "uv.h"
#include "v8.h"
#include "node_perf_common.h"
#include "node_persistent.h"
#include "node_context_data.h"

#include <cstddef>
Expand Down
50 changes: 0 additions & 50 deletions src/node_persistent.h

This file was deleted.

38 changes: 38 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,44 @@ class SlicedArguments : public MaybeStackBuffer<v8::Local<v8::Value>> {
const v8::FunctionCallbackInfo<v8::Value>& args, size_t start = 0);
};

// Convert a v8::PersistentBase, e.g. v8::Global, to a Local, with an extra
// optimization for strong persistent handles.
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 v8::PersistentBase<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 v8::PersistentBase<TypeName>& persistent) {
return *reinterpret_cast<v8::Local<TypeName>*>(
const_cast<v8::PersistentBase<TypeName>*>(&persistent));
}

template <class TypeName>
static inline v8::Local<TypeName> Weak(
v8::Isolate* isolate,
const v8::PersistentBase<TypeName>& persistent) {
return v8::Local<TypeName>::New(isolate, persistent);
}
};

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down