bare-module 4.7.0 → 4.8.0
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/README.md +371 -47
- package/binding.c +38 -21
- package/index.js +259 -134
- package/lib/constants.js +2 -1
- package/lib/errors.js +33 -13
- package/lib/protocol.js +9 -9
- package/package.json +4 -3
- package/prebuilds/android-arm/bare-module.bare +0 -0
- package/prebuilds/android-arm64/bare-module.bare +0 -0
- package/prebuilds/android-ia32/bare-module.bare +0 -0
- package/prebuilds/android-x64/bare-module.bare +0 -0
- package/prebuilds/darwin-arm64/bare-module.bare +0 -0
- package/prebuilds/darwin-x64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-module.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-module.bare +0 -0
- package/prebuilds/linux-arm64/bare-module.bare +0 -0
- package/prebuilds/linux-x64/bare-module.bare +0 -0
- package/prebuilds/win32-arm64/bare-module.bare +0 -0
- package/prebuilds/win32-x64/bare-module.bare +0 -0
package/binding.c
CHANGED
|
@@ -16,7 +16,7 @@ typedef struct {
|
|
|
16
16
|
} bare_module_context_t;
|
|
17
17
|
|
|
18
18
|
static js_module_t *
|
|
19
|
-
bare_module__on_static_import
|
|
19
|
+
bare_module__on_static_import(js_env_t *env, js_value_t *specifier, js_value_t *assertions, js_module_t *referrer, void *data) {
|
|
20
20
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
21
21
|
|
|
22
22
|
int err;
|
|
@@ -66,7 +66,7 @@ err:
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
static js_module_t *
|
|
69
|
-
bare_module__on_dynamic_import
|
|
69
|
+
bare_module__on_dynamic_import(js_env_t *env, js_value_t *specifier, js_value_t *assertions, js_value_t *referrer, void *data) {
|
|
70
70
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
71
71
|
|
|
72
72
|
int err;
|
|
@@ -109,7 +109,7 @@ err:
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
static void
|
|
112
|
-
bare_module__on_evaluate
|
|
112
|
+
bare_module__on_evaluate(js_env_t *env, js_module_t *module, void *data) {
|
|
113
113
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
114
114
|
|
|
115
115
|
int err;
|
|
@@ -150,7 +150,7 @@ err:
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
static void
|
|
153
|
-
bare_module__on_meta
|
|
153
|
+
bare_module__on_meta(js_env_t *env, js_module_t *module, js_value_t *meta, void *data) {
|
|
154
154
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
155
155
|
|
|
156
156
|
int err;
|
|
@@ -193,7 +193,7 @@ err:
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
static js_value_t *
|
|
196
|
-
bare_module_init
|
|
196
|
+
bare_module_init(js_env_t *env, js_callback_info_t *info) {
|
|
197
197
|
int err;
|
|
198
198
|
|
|
199
199
|
size_t argc = 4;
|
|
@@ -229,7 +229,7 @@ bare_module_init (js_env_t *env, js_callback_info_t *info) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
static js_value_t *
|
|
232
|
-
bare_module_destroy
|
|
232
|
+
bare_module_destroy(js_env_t *env, js_callback_info_t *info) {
|
|
233
233
|
int err;
|
|
234
234
|
|
|
235
235
|
size_t argc = 1;
|
|
@@ -260,7 +260,7 @@ bare_module_destroy (js_env_t *env, js_callback_info_t *info) {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
static js_value_t *
|
|
263
|
-
bare_module_create_function
|
|
263
|
+
bare_module_create_function(js_env_t *env, js_callback_info_t *info) {
|
|
264
264
|
int err;
|
|
265
265
|
|
|
266
266
|
size_t argc = 4;
|
|
@@ -308,7 +308,7 @@ err:
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
static js_value_t *
|
|
311
|
-
bare_module_create_module
|
|
311
|
+
bare_module_create_module(js_env_t *env, js_callback_info_t *info) {
|
|
312
312
|
int err;
|
|
313
313
|
|
|
314
314
|
size_t argc = 4;
|
|
@@ -346,7 +346,7 @@ bare_module_create_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
static js_value_t *
|
|
349
|
-
bare_module_create_synthetic_module
|
|
349
|
+
bare_module_create_synthetic_module(js_env_t *env, js_callback_info_t *info) {
|
|
350
350
|
int err;
|
|
351
351
|
|
|
352
352
|
size_t argc = 3;
|
|
@@ -396,7 +396,7 @@ err:
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
static js_value_t *
|
|
399
|
-
bare_module_delete_module
|
|
399
|
+
bare_module_delete_module(js_env_t *env, js_callback_info_t *info) {
|
|
400
400
|
int err;
|
|
401
401
|
|
|
402
402
|
size_t argc = 1;
|
|
@@ -418,7 +418,7 @@ bare_module_delete_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
static js_value_t *
|
|
421
|
-
bare_module_set_export
|
|
421
|
+
bare_module_set_export(js_env_t *env, js_callback_info_t *info) {
|
|
422
422
|
int err;
|
|
423
423
|
|
|
424
424
|
size_t argc = 3;
|
|
@@ -439,7 +439,7 @@ bare_module_set_export (js_env_t *env, js_callback_info_t *info) {
|
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
static js_value_t *
|
|
442
|
-
bare_module_run_module
|
|
442
|
+
bare_module_run_module(js_env_t *env, js_callback_info_t *info) {
|
|
443
443
|
int err;
|
|
444
444
|
|
|
445
445
|
size_t argc = 3;
|
|
@@ -501,7 +501,7 @@ bare_module_run_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
501
501
|
}
|
|
502
502
|
|
|
503
503
|
static js_value_t *
|
|
504
|
-
bare_module_get_namespace
|
|
504
|
+
bare_module_get_namespace(js_env_t *env, js_callback_info_t *info) {
|
|
505
505
|
int err;
|
|
506
506
|
|
|
507
507
|
size_t argc = 1;
|
|
@@ -522,32 +522,36 @@ bare_module_get_namespace (js_env_t *env, js_callback_info_t *info) {
|
|
|
522
522
|
}
|
|
523
523
|
|
|
524
524
|
static js_value_t *
|
|
525
|
-
bare_module_exists
|
|
525
|
+
bare_module_exists(js_env_t *env, js_callback_info_t *info) {
|
|
526
526
|
int err;
|
|
527
527
|
|
|
528
528
|
uv_loop_t *loop;
|
|
529
529
|
err = js_get_env_loop(env, &loop);
|
|
530
530
|
assert(err == 0);
|
|
531
531
|
|
|
532
|
-
js_value_t *argv[
|
|
533
|
-
size_t argc =
|
|
532
|
+
js_value_t *argv[2];
|
|
533
|
+
size_t argc = 2;
|
|
534
534
|
|
|
535
535
|
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
536
536
|
assert(err == 0);
|
|
537
537
|
|
|
538
|
-
assert(argc ==
|
|
538
|
+
assert(argc == 2);
|
|
539
539
|
|
|
540
540
|
utf8_t path[4096];
|
|
541
541
|
err = js_get_value_string_utf8(env, argv[0], path, 4096, NULL);
|
|
542
542
|
assert(err == 0);
|
|
543
543
|
|
|
544
|
+
uint32_t mode;
|
|
545
|
+
err = js_get_value_uint32(env, argv[1], &mode);
|
|
546
|
+
assert(err == 0);
|
|
547
|
+
|
|
544
548
|
uv_fs_t req;
|
|
545
549
|
uv_fs_stat(loop, &req, (char *) path, NULL);
|
|
546
550
|
|
|
547
551
|
uv_stat_t *st = req.result < 0 ? NULL : req.ptr;
|
|
548
552
|
|
|
549
553
|
js_value_t *result;
|
|
550
|
-
err = js_get_boolean(env, st && st->st_mode &
|
|
554
|
+
err = js_get_boolean(env, st && st->st_mode & mode, &result);
|
|
551
555
|
assert(err == 0);
|
|
552
556
|
|
|
553
557
|
uv_fs_req_cleanup(&req);
|
|
@@ -556,7 +560,7 @@ bare_module_exists (js_env_t *env, js_callback_info_t *info) {
|
|
|
556
560
|
}
|
|
557
561
|
|
|
558
562
|
static js_value_t *
|
|
559
|
-
bare_module_realpath
|
|
563
|
+
bare_module_realpath(js_env_t *env, js_callback_info_t *info) {
|
|
560
564
|
int err;
|
|
561
565
|
|
|
562
566
|
uv_loop_t *loop;
|
|
@@ -601,7 +605,7 @@ err:
|
|
|
601
605
|
}
|
|
602
606
|
|
|
603
607
|
static js_value_t *
|
|
604
|
-
bare_module_read
|
|
608
|
+
bare_module_read(js_env_t *env, js_callback_info_t *info) {
|
|
605
609
|
int err;
|
|
606
610
|
|
|
607
611
|
uv_loop_t *loop;
|
|
@@ -679,7 +683,7 @@ err:
|
|
|
679
683
|
}
|
|
680
684
|
|
|
681
685
|
static js_value_t *
|
|
682
|
-
bare_module_exports
|
|
686
|
+
bare_module_exports(js_env_t *env, js_value_t *exports) {
|
|
683
687
|
int err;
|
|
684
688
|
|
|
685
689
|
#define V(name, fn) \
|
|
@@ -707,6 +711,19 @@ bare_module_exports (js_env_t *env, js_value_t *exports) {
|
|
|
707
711
|
V("read", bare_module_read)
|
|
708
712
|
#undef V
|
|
709
713
|
|
|
714
|
+
#define V(name, n) \
|
|
715
|
+
{ \
|
|
716
|
+
js_value_t *val; \
|
|
717
|
+
err = js_create_uint32(env, n, &val); \
|
|
718
|
+
assert(err == 0); \
|
|
719
|
+
err = js_set_named_property(env, exports, name, val); \
|
|
720
|
+
assert(err == 0); \
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
V("FILE", S_IFREG)
|
|
724
|
+
V("DIR", S_IFDIR)
|
|
725
|
+
#undef V
|
|
726
|
+
|
|
710
727
|
return exports;
|
|
711
728
|
}
|
|
712
729
|
|