-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lets native addons register exit hooks that run after the event loop has quit but before the VM is killed. Fixes #3147.
- Loading branch information
1 parent
6f82b9f
commit e4a8d26
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#undef NDEBUG | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <node.h> | ||
#include <v8.h> | ||
|
||
using node::AtExit; | ||
using v8::Handle; | ||
using v8::HandleScope; | ||
using v8::Local; | ||
using v8::Object; | ||
|
||
static char cookie[] = "yum yum"; | ||
static int at_exit_cb1_called = 0; | ||
static int at_exit_cb2_called = 0; | ||
|
||
static void at_exit_cb1(void* arg) { | ||
HandleScope scope; | ||
assert(arg == 0); | ||
Local<Object> obj = Object::New(); | ||
assert(!obj.IsEmpty()); // assert VM is still alive | ||
assert(obj->IsObject()); | ||
at_exit_cb1_called++; | ||
} | ||
|
||
static void at_exit_cb2(void* arg) { | ||
assert(arg == static_cast<void*>(cookie)); | ||
at_exit_cb2_called++; | ||
} | ||
|
||
static void sanity_check(void) { | ||
assert(at_exit_cb1_called == 1); | ||
assert(at_exit_cb2_called == 2); | ||
} | ||
|
||
void init(Handle<Object> target) { | ||
AtExit(at_exit_cb1); | ||
AtExit(at_exit_cb2, cookie); | ||
AtExit(at_exit_cb2, cookie); | ||
atexit(sanity_check); | ||
} | ||
|
||
NODE_MODULE(binding, init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var binding = require('./build/Release/binding'); |