Skip to content

Commit

Permalink
Add a CallbackScope class
Browse files Browse the repository at this point in the history
All credit to Vladimir Kurchatkin, who created the original patch in
nodejs#5691 (comment).
  • Loading branch information
DemiMarie committed May 23, 2017
1 parent eebc262 commit 4a2b032
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,14 @@ Local<Value> MakeCallback(Isolate* isolate,
MakeCallback(env, recv.As<Value>(), callback, argc, argv));
}

CallbackScope::CallbackScope(Isolate* isolate): isolate_(isolate) {
}

CallbackScope::~CallbackScope() {
Environment* env = Environment::GetCurrent(isolate_);
Environment::AsyncCallbackScope callback_scope(env);
env->KickNextTick(&callback_scope);
}

enum encoding ParseEncoding(const char* encoding,
enum encoding default_encoding) {
Expand Down
12 changes: 12 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#include "v8.h" // NOLINT(build/include_order)
#include "node_version.h" // NODE_MODULE_VERSION
#include "util.h"

#define NODE_MAKE_VERSION(major, minor, patch) \
((major) * 0x1000 + (minor) * 0x100 + (patch))
Expand Down Expand Up @@ -171,6 +172,17 @@ NODE_EXTERN v8::Local<v8::Value> MakeCallback(
int argc,
v8::Local<v8::Value>* argv);

class NODE_EXTERN CallbackScope {
public:
explicit CallbackScope(v8::Isolate* isolate);
~CallbackScope();

private:
v8::Isolate* isolate_;

DISALLOW_COPY_AND_ASSIGN(CallbackScope);
};

} // namespace node

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down

0 comments on commit 4a2b032

Please sign in to comment.