Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created April 1, 2017 20:24
Show Gist options
  • Save gabrielschulhof/a01fa89e98ce1042dd6ec6776eada3b4 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/a01fa89e98ce1042dd6ec6776eada3b4 to your computer and use it in GitHub Desktop.
diff --git a/src/node_api.cc b/src/node_api.cc
index ccf8738..95037a1 100644
--- a/src/node_api.cc
+++ b/src/node_api.cc
@@ -334,6 +334,8 @@ class CallbackWrapperBase : public CallbackWrapper {
_cbdata->GetInternalField(kEnvIndex))->Value());
// Make sure any errors encountered last time we were in N-API are gone.
+ fprintf(stderr, "env->last_error.error_code: %d\n",
+ env->last_error.error_code);
napi_clear_last_error(env);
cb(env, cbinfo_wrapper);
diff --git a/test/addons-napi/test_napi_status/binding.gyp b/test/addons-napi/test_napi_status/binding.gyp
new file mode 100644
index 0000000..01ace54
--- /dev/null
+++ b/test/addons-napi/test_napi_status/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "test_napi_status",
+ "sources": [ "test_napi_status.cc" ]
+ }
+ ]
+}
diff --git a/test/addons-napi/test_napi_status/test.js b/test/addons-napi/test_napi_status/test.js
new file mode 100644
index 0000000..dc2fa1f
--- /dev/null
+++ b/test/addons-napi/test_napi_status/test.js
@@ -0,0 +1,8 @@
+'use strict';
+
+const common = require('../../common');
+const test_napi_status = require(`./build/${common.buildType}/test_napi_status`);
+const assert = require('assert');
+
+test_napi_status.testNapiStatus();
+test_napi_status.testNapiStatus();
diff --git a/test/addons-napi/test_napi_status/test_napi_status.cc b/test/addons-napi/test_napi_status/test_napi_status.cc
new file mode 100644
index 0000000..7520c57
--- /dev/null
+++ b/test/addons-napi/test_napi_status/test_napi_status.cc
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <node_api.h>
+
+void testNapiStatus(napi_env env, napi_callback_info info) {
+ napi_status status;
+ napi_value value;
+ double double_value;
+
+ status = napi_create_string_utf8(env, "xyz", 3, &value);
+ fprintf(stderr, "%d\n", status);
+
+ status = napi_get_value_double(env, value, &double_value);
+ fprintf(stderr, "%d\n", status);
+}
+
+#define DECLARE_NAPI_METHOD(name, func) \
+ { name, func, 0, 0, 0, napi_default, 0 }
+
+void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
+ napi_status status;
+
+ napi_property_descriptor descriptors[] = {
+ DECLARE_NAPI_METHOD("testNapiStatus", testNapiStatus),
+ };
+
+ status = napi_define_properties(
+ env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors);
+ if (status != napi_ok) return;
+}
+
+NAPI_MODULE(addon, Init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment