syscall-napi 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/native/syscall.c CHANGED
@@ -30,6 +30,9 @@ static void syscall_work(void* opaque) {
30
30
  static napi_status syscall_done(napi_env env, void* opaque, napi_deferred deferred) {
31
31
  struct syscall_ctx* ctx = (struct syscall_ctx*) opaque;
32
32
  long res = ctx->res;
33
+ napi_value result;
34
+ napi_value js_errno;
35
+ napi_value js_ret;
33
36
  unsigned int i;
34
37
 
35
38
  for(i = 0; i < sizeof(ctx->arg_refs) / sizeof(ctx->arg_refs[0]); i += 1) {
@@ -41,9 +44,19 @@ static napi_status syscall_done(napi_env env, void* opaque, napi_deferred deferr
41
44
 
42
45
  free(ctx);
43
46
 
44
- napi_value result;
47
+ NAPILIB_CHECK(napi_create_object(env, &result));
48
+
49
+ if (res < 0) {
50
+ NAPILIB_CHECK(napi_create_int32(env, errno, &js_errno));
51
+ NAPILIB_CHECK(napi_set_named_property(env, result, "errno", js_errno));
52
+ } else {
53
+ NAPILIB_CHECK(napi_create_int32(env, 0, &js_errno));
54
+ NAPILIB_CHECK(napi_set_named_property(env, result, "errno", js_errno));
55
+
56
+ NAPILIB_CHECK(napi_create_bigint_int64(env, res, &js_ret));
57
+ NAPILIB_CHECK(napi_set_named_property(env, result, "ret", js_ret));
58
+ }
45
59
 
46
- NAPILIB_CHECK(napi_create_bigint_int64(env, res, &result));
47
60
  NAPILIB_CHECK(napi_resolve_deferred(env, deferred, result));
48
61
 
49
62
  return napi_ok;
@@ -93,8 +106,11 @@ static napi_status syscall_async_entry(napi_env env, napi_value* args, int arg_c
93
106
  return napi_ok;
94
107
  }
95
108
 
96
- static napi_status syscall_sync_entry(napi_env env, napi_value* args, int arg_count, napi_value* result) {
109
+ static napi_status syscall_sync_entry(napi_env env, napi_value* args, int arg_count, napi_value* result_ptr) {
97
110
  int i;
111
+ napi_value result;
112
+ napi_value js_errno;
113
+ napi_value js_ret;
98
114
  struct syscall_ctx ctx;
99
115
  memset(&ctx, 0, sizeof(ctx));
100
116
 
@@ -133,7 +149,20 @@ static napi_status syscall_sync_entry(napi_env env, napi_value* args, int arg_co
133
149
  ctx.native_args[5],
134
150
  ctx.native_args[6]);
135
151
 
136
- NAPILIB_CHECK(napi_create_bigint_int64(env, ctx.res, result));
152
+ NAPILIB_CHECK(napi_create_object(env, &result));
153
+
154
+ if (ctx.res < 0) {
155
+ NAPILIB_CHECK(napi_create_int32(env, errno, &js_errno));
156
+ NAPILIB_CHECK(napi_set_named_property(env, result, "errno", js_errno));
157
+ } else {
158
+ NAPILIB_CHECK(napi_create_int32(env, 0, &js_errno));
159
+ NAPILIB_CHECK(napi_set_named_property(env, result, "errno", js_errno));
160
+
161
+ NAPILIB_CHECK(napi_create_bigint_int64(env, ctx.res, &js_ret));
162
+ NAPILIB_CHECK(napi_set_named_property(env, result, "ret", js_ret));
163
+ }
164
+
165
+ *result_ptr = result;
137
166
 
138
167
  return napi_ok;
139
168
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "syscall-napi",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "description": "Node.js module to perform promise-based asynchronous syscalls",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -20,8 +20,12 @@
20
20
  },
21
21
  "homepage": "https://github.com/k13-engineering/node-syscall-napi#readme",
22
22
  "devDependencies": {
23
- "c8": "^10.1.2",
24
- "eslint": "^9.7.0",
25
- "mocha": "^10.6.0"
23
+ "c8": "^10.1.3",
24
+ "eslint": "^9.32.0",
25
+ "mocha": "^11.7.1",
26
+ "node-archibald": "^0.0.6"
27
+ },
28
+ "dependencies": {
29
+
26
30
  }
27
31
  }
package/test/basic.js CHANGED
@@ -6,12 +6,14 @@ import sys from "../lib/index.js";
6
6
 
7
7
  describe("basic", () => {
8
8
  it("should run getpid() correctly [async]", async () => {
9
- const pid = await sys.syscall(sys.__NR_getpid);
9
+ const { errno, ret: pid } = await sys.syscall(sys.__NR_getpid);
10
+ assert.equal(errno, 0);
10
11
  assert.equal(pid, process.pid);
11
12
  });
12
13
 
13
14
  it("should run getpid() correctly [sync]", () => {
14
- const pid = sys.syscall.sync(sys.__NR_getpid);
15
+ const { errno, ret: pid } = sys.syscall.sync(sys.__NR_getpid);
16
+ assert.equal(errno, 0);
15
17
  assert.equal(pid, process.pid);
16
18
  });
17
19
  });