0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/addons/at-exit/binding.cc
Ben Noordhuis 1f17f88071 src, test: fix up ObjectWrap, make test-addons
V8 was upgraded from 3.22 to 3.24 in commit 1c7bf24.  Upgrade source
files in test/addons/ and automatically generated tests from
doc/api/addons.markdown to the new V8 API.

This coincidentally fixes a bug in src/node_object_wrap.h where it was
still using the old V8 weak persistent handle interface, which is gone
in 3.24.
2014-03-14 00:41:04 +04:00

47 lines
1.0 KiB
C++

#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::Isolate;
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) {
// FIXME(bnoordhuis) Isolate::GetCurrent() is on its way out.
Isolate* isolate = Isolate::GetCurrent();
HandleScope handle_scope(isolate);
assert(arg == 0);
Local<Object> obj = Object::New(isolate);
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);