summaryrefslogtreecommitdiff
path: root/test/node-api/test_cleanup_hook
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-11-17 12:34:54 -0800
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-12-04 13:58:17 -0800
commit938e11882b96e19b443477571455088baaa054d8 (patch)
treeeb828a60957a2881995ba9a83f44a32a18fbff16 /test/node-api/test_cleanup_hook
parent83ee137c4565112177f22f2c735b266b22262220 (diff)
downloadandroid-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.gz
android-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.bz2
android-node-v8-938e11882b96e19b443477571455088baaa054d8.zip
test: partition N-API tests
Partition test/addons-napi into test/js-native-api and test/node-api to isolate the Node.js-agnostic portion of the N-API tests from the Node.js-specific portion. PR-URL: https://github.com/nodejs/node/pull/24557 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'test/node-api/test_cleanup_hook')
-rw-r--r--test/node-api/test_cleanup_hook/binding.cc24
-rw-r--r--test/node-api/test_cleanup_hook/binding.gyp9
-rw-r--r--test/node-api/test_cleanup_hook/test.js12
3 files changed, 45 insertions, 0 deletions
diff --git a/test/node-api/test_cleanup_hook/binding.cc b/test/node-api/test_cleanup_hook/binding.cc
new file mode 100644
index 0000000000..9426716e67
--- /dev/null
+++ b/test/node-api/test_cleanup_hook/binding.cc
@@ -0,0 +1,24 @@
+#include "node_api.h"
+#include "uv.h"
+#include "../../js-native-api/common.h"
+
+namespace {
+
+void cleanup(void* arg) {
+ printf("cleanup(%d)\n", *static_cast<int*>(arg));
+}
+
+int secret = 42;
+int wrong_secret = 17;
+
+napi_value Init(napi_env env, napi_value exports) {
+ napi_add_env_cleanup_hook(env, cleanup, &wrong_secret);
+ napi_add_env_cleanup_hook(env, cleanup, &secret);
+ napi_remove_env_cleanup_hook(env, cleanup, &wrong_secret);
+
+ return nullptr;
+}
+
+} // anonymous namespace
+
+NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
diff --git a/test/node-api/test_cleanup_hook/binding.gyp b/test/node-api/test_cleanup_hook/binding.gyp
new file mode 100644
index 0000000000..7ede63d94a
--- /dev/null
+++ b/test/node-api/test_cleanup_hook/binding.gyp
@@ -0,0 +1,9 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'binding',
+ 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
+ 'sources': [ 'binding.cc' ]
+ }
+ ]
+}
diff --git a/test/node-api/test_cleanup_hook/test.js b/test/node-api/test_cleanup_hook/test.js
new file mode 100644
index 0000000000..354f444904
--- /dev/null
+++ b/test/node-api/test_cleanup_hook/test.js
@@ -0,0 +1,12 @@
+'use strict';
+const common = require('../../common');
+const assert = require('assert');
+const child_process = require('child_process');
+
+if (process.argv[2] === 'child') {
+ require(`./build/${common.buildType}/binding`);
+} else {
+ const { stdout } =
+ child_process.spawnSync(process.execPath, [__filename, 'child']);
+ assert.strictEqual(stdout.toString().trim(), 'cleanup(42)');
+}