syscall-napi 0.0.6 → 0.0.7
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/{.eslintrc → eslint.config.js} +13 -23
- package/lib/index.js +1 -1
- package/native/napilib.h +0 -16
- package/native/syscall.c +5 -25
- package/package.json +4 -5
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
"ecmaVersion": 2021,
|
|
4
|
-
"sourceType": "module",
|
|
5
|
-
"requireConfigFile": false
|
|
6
|
-
},
|
|
7
|
-
"env": {
|
|
8
|
-
"node": true,
|
|
9
|
-
"es2020": true
|
|
10
|
-
},
|
|
11
|
-
"rules": {
|
|
1
|
+
export default {
|
|
2
|
+
rules: {
|
|
12
3
|
"global-require": "off",
|
|
13
4
|
"quote-props": ["warn", "consistent-as-needed"],
|
|
14
|
-
"comma-dangle": ["error", {
|
|
15
|
-
"id-length": ["error", {
|
|
16
|
-
"quotes": ["error", "double", {
|
|
5
|
+
"comma-dangle": ["error", { arrays: "always-multiline", objects: "always-multiline", functions: "never" }],
|
|
6
|
+
"id-length": ["error", { min: 2, properties: "always", exceptions: ["i"] }],
|
|
7
|
+
"quotes": ["error", "double", { allowTemplateLiterals: true }],
|
|
17
8
|
"no-plusplus": "error",
|
|
18
9
|
"no-nested-ternary": "error",
|
|
19
10
|
"no-multiple-empty-lines": "error",
|
|
@@ -26,14 +17,14 @@
|
|
|
26
17
|
"no-import-assign": "error",
|
|
27
18
|
"no-multi-assign": "error",
|
|
28
19
|
"keyword-spacing": "error",
|
|
29
|
-
"max-len": [ "warn", {
|
|
20
|
+
"max-len": [ "warn", { code: 140 } ],
|
|
30
21
|
"max-params": ["error", 4],
|
|
31
22
|
"max-statements": ["error", 15],
|
|
32
23
|
"no-loss-of-precision": "error",
|
|
33
24
|
"no-unreachable-loop": "error",
|
|
34
25
|
"require-atomic-updates": "error",
|
|
35
26
|
"complexity": ["error", 4],
|
|
36
|
-
"max-statements-per-line": ["error", {
|
|
27
|
+
"max-statements-per-line": ["error", { max: 1 }],
|
|
37
28
|
"no-tabs": "error",
|
|
38
29
|
"no-negated-condition": "error",
|
|
39
30
|
"no-use-before-define": "error",
|
|
@@ -50,10 +41,10 @@
|
|
|
50
41
|
"no-new-object": "error",
|
|
51
42
|
"no-new-wrappers": "error",
|
|
52
43
|
"no-useless-concat": "error",
|
|
53
|
-
"no-unused-vars": ["error", {
|
|
44
|
+
"no-unused-vars": ["error", { ignoreRestSiblings: true }],
|
|
54
45
|
"array-bracket-newline": ["error", "consistent"],
|
|
55
46
|
"func-names": ["error", "never"],
|
|
56
|
-
"func-style": ["error", "expression", {
|
|
47
|
+
"func-style": ["error", "expression", { allowArrowFunctions: true }],
|
|
57
48
|
"max-depth": ["error", 4],
|
|
58
49
|
"arrow-parens": "error",
|
|
59
50
|
"no-confusing-arrow": "error",
|
|
@@ -77,15 +68,14 @@
|
|
|
77
68
|
"yoda": "error",
|
|
78
69
|
"indent": ["error", 2],
|
|
79
70
|
"object-curly-spacing": [ "error", "always" ],
|
|
80
|
-
"object-curly-newline": ["error", {
|
|
71
|
+
"object-curly-newline": ["error", { consistent: true, multiline: true }],
|
|
81
72
|
"space-before-blocks": "error",
|
|
82
73
|
"space-before-function-paren": [ "error", "always" ],
|
|
83
74
|
"spaced-comment": "error",
|
|
84
75
|
"no-whitespace-before-property": "error",
|
|
85
|
-
"brace-style": ["error", "1tbs", {
|
|
76
|
+
"brace-style": ["error", "1tbs", { allowSingleLine: false }],
|
|
86
77
|
"eol-last": ["error", "always"],
|
|
87
78
|
"func-call-spacing": ["error", "never"],
|
|
88
|
-
"semi": ["error", "always"]
|
|
79
|
+
"semi": ["error", "always"],
|
|
89
80
|
},
|
|
90
|
-
|
|
91
|
-
}
|
|
81
|
+
};
|
package/lib/index.js
CHANGED
package/native/napilib.h
CHANGED
|
@@ -30,22 +30,6 @@ static napi_status napilib_maybe_throw_by_status(napi_env env, napi_status statu
|
|
|
30
30
|
#define NAPILIB_CHECK(x) do { napi_status ret = x; if(ret != napi_ok) { return napilib_maybe_throw_by_status(env, ret); } } while(0)
|
|
31
31
|
#define NAPILIB_CHECK_GOTO_FAIL(x) if((x) != napi_ok) { goto fail; }
|
|
32
32
|
|
|
33
|
-
static napi_status napilib_create_error_by_errno(napi_env env, int err, napi_value* error) {
|
|
34
|
-
napi_value code;
|
|
35
|
-
napi_value message;
|
|
36
|
-
char c_message[512];
|
|
37
|
-
|
|
38
|
-
const char* orig_err = strerror(err);
|
|
39
|
-
|
|
40
|
-
snprintf(c_message, sizeof(c_message), "%s", orig_err);
|
|
41
|
-
|
|
42
|
-
NAPILIB_CHECK(napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &code));
|
|
43
|
-
NAPILIB_CHECK(napi_create_string_utf8(env, c_message, NAPI_AUTO_LENGTH, &message));
|
|
44
|
-
NAPILIB_CHECK(napi_create_error(env, code, message, error));
|
|
45
|
-
|
|
46
|
-
return napi_ok;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
33
|
static napi_status napilib_throw_error_by_errno(napi_env env, int err) {
|
|
50
34
|
NAPILIB_CHECK(napi_throw_error(env, "", strerror(err)));
|
|
51
35
|
return napi_pending_exception;
|
package/native/syscall.c
CHANGED
|
@@ -11,7 +11,6 @@ struct syscall_ctx {
|
|
|
11
11
|
long num;
|
|
12
12
|
long native_args[7];
|
|
13
13
|
long res;
|
|
14
|
-
long error_code;
|
|
15
14
|
napi_ref arg_refs[7];
|
|
16
15
|
};
|
|
17
16
|
|
|
@@ -26,17 +25,11 @@ static void syscall_work(void* opaque) {
|
|
|
26
25
|
ctx->native_args[4],
|
|
27
26
|
ctx->native_args[5],
|
|
28
27
|
ctx->native_args[6]);
|
|
29
|
-
if(ctx->res < 0) {
|
|
30
|
-
ctx->error_code = errno;
|
|
31
|
-
} else {
|
|
32
|
-
ctx->error_code = 0;
|
|
33
|
-
}
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
static napi_status syscall_done(napi_env env, void* opaque, napi_deferred deferred) {
|
|
37
31
|
struct syscall_ctx* ctx = (struct syscall_ctx*) opaque;
|
|
38
32
|
long res = ctx->res;
|
|
39
|
-
long error_code = ctx->error_code;
|
|
40
33
|
unsigned int i;
|
|
41
34
|
|
|
42
35
|
for(i = 0; i < sizeof(ctx->arg_refs) / sizeof(ctx->arg_refs[0]); i += 1) {
|
|
@@ -48,17 +41,10 @@ static napi_status syscall_done(napi_env env, void* opaque, napi_deferred deferr
|
|
|
48
41
|
|
|
49
42
|
free(ctx);
|
|
50
43
|
|
|
51
|
-
|
|
52
|
-
napi_value error;
|
|
53
|
-
|
|
54
|
-
NAPILIB_CHECK(napilib_create_error_by_errno(env, error_code, &error));
|
|
55
|
-
NAPILIB_CHECK(napi_reject_deferred(env, deferred, error));
|
|
56
|
-
} else {
|
|
57
|
-
napi_value result;
|
|
44
|
+
napi_value result;
|
|
58
45
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
46
|
+
NAPILIB_CHECK(napi_create_bigint_int64(env, res, &result));
|
|
47
|
+
NAPILIB_CHECK(napi_resolve_deferred(env, deferred, result));
|
|
62
48
|
|
|
63
49
|
return napi_ok;
|
|
64
50
|
}
|
|
@@ -147,14 +133,8 @@ static napi_status syscall_sync_entry(napi_env env, napi_value* args, int arg_co
|
|
|
147
133
|
ctx.native_args[5],
|
|
148
134
|
ctx.native_args[6]);
|
|
149
135
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
NAPILIB_CHECK(napilib_create_error_by_errno(env, errno, &error));
|
|
153
|
-
NAPILIB_CHECK(napi_throw(env, error));
|
|
154
|
-
} else {
|
|
155
|
-
NAPILIB_CHECK(napi_create_bigint_int64(env, ctx.res, result));
|
|
156
|
-
}
|
|
157
|
-
|
|
136
|
+
NAPILIB_CHECK(napi_create_bigint_int64(env, ctx.res, result));
|
|
137
|
+
|
|
158
138
|
return napi_ok;
|
|
159
139
|
}
|
|
160
140
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "syscall-napi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "Node.js module to perform promise-based asynchronous syscalls",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -20,9 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/k13-engineering/node-syscall-napi#readme",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"c8": "^
|
|
24
|
-
"eslint": "^7.
|
|
25
|
-
"mocha": "^
|
|
26
|
-
"node-archibald": "^0.0.5"
|
|
23
|
+
"c8": "^10.1.2",
|
|
24
|
+
"eslint": "^9.7.0",
|
|
25
|
+
"mocha": "^10.6.0"
|
|
27
26
|
}
|
|
28
27
|
}
|