@scriptc/cli-darwin-x64 0.2.1 → 0.2.2
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/dist/THIRD_PARTY_NOTICES +1 -1
- package/dist/bin/scriptc +0 -0
- package/dist/bin/scriptc.json +1 -1
- package/dist/lib/declarations/scriptc-node-fallback.d.ts +59 -4
- package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
- package/dist/lib/llvm/package.json +1 -1
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_island.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_web.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_island.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_web.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-x64/package.json +1 -1
- package/dist/lib/runtime-darwin-x64/runtime-pack.json +177 -177
- package/dist/lib/runtime-sources/package.json +1 -1
- package/dist/lib/runtime-sources/src/scr_abort.c +5 -0
- package/dist/lib/runtime-sources/src/scr_async.c +12 -4
- package/dist/lib/runtime-sources/src/scr_async_dyn.c +118 -24
- package/dist/lib/runtime-sources/src/scr_bytes.c +226 -0
- package/dist/lib/runtime-sources/src/scr_bytes_io.c +52 -5
- package/dist/lib/runtime-sources/src/scr_crypto_async.c +22 -2
- package/dist/lib/runtime-sources/src/scr_dyn_invoke.c +181 -43
- package/dist/lib/runtime-sources/src/scr_fetch.c +45 -1
- package/dist/lib/runtime-sources/src/scr_file_handle.c +31 -0
- package/dist/lib/runtime-sources/src/scr_island.c +1188 -392
- package/dist/lib/runtime-sources/src/scr_island_manifest.h +11 -9
- package/dist/lib/runtime-sources/src/scr_json.c +449 -52
- package/dist/lib/runtime-sources/src/scr_json.test.ts +1 -0
- package/dist/lib/runtime-sources/src/scr_lib.c +816 -34
- package/dist/lib/runtime-sources/src/scr_qs.c +10 -0
- package/dist/lib/runtime-sources/src/scr_regex.c +42 -5
- package/dist/lib/runtime-sources/src/scr_runtime.h +67 -8
- package/dist/lib/runtime-sources/src/scr_text_decoder_labels.h +12 -12
- package/dist/lib/runtime-sources/src/scr_url.c +34 -7
- package/dist/lib/runtime-sources/src/scr_web.c +129 -26
- package/package.json +1 -1
|
@@ -72,9 +72,11 @@ static void scr_dyn_display_buf(ScrJsonBuf *b, const ScrDyn *d) {
|
|
|
72
72
|
case SCR_DYN_ARR:
|
|
73
73
|
for (size_t i = 0; i < d->v.arr.len; i++) {
|
|
74
74
|
if (i > 0) scr_jb_putc(b, ',');
|
|
75
|
-
|
|
76
|
-
if (e
|
|
77
|
-
scr_dyn_display_buf(b, e);
|
|
75
|
+
ScrDyn *e = scr_dyn_arr_at(d, (double)i);
|
|
76
|
+
if (!e) return;
|
|
77
|
+
if (e->kind != SCR_DYN_UNDEF && e->kind != SCR_DYN_NULL) scr_dyn_display_buf(b, e);
|
|
78
|
+
scr_dyn_release(e);
|
|
79
|
+
if (scr_exc_pending()) return;
|
|
78
80
|
}
|
|
79
81
|
return;
|
|
80
82
|
case SCR_DYN_OBJ: {
|
|
@@ -217,7 +219,7 @@ static ScrDyn *dyn_call_cb(ScrDyn *cb, ScrDyn *item, size_t i, ScrDyn *recv) {
|
|
|
217
219
|
/* The callable-callback gate: JS's "<String(cb)> is not a function". */
|
|
218
220
|
static bool dyn_cb_check(ScrDyn *const *args, size_t argc) {
|
|
219
221
|
ScrDyn *cb = argc > 0 ? args[0] : scr_dyn_undefined();
|
|
220
|
-
if (cb
|
|
222
|
+
if (scr_dyn_is_callable(cb)) return true;
|
|
221
223
|
/* An ENGINE function is callable — scr_dyn_call's JSVAL arm routes it
|
|
222
224
|
* (the loops below call through scr_dyn_call, which converts the checked-dynamic tree
|
|
223
225
|
* element arguments per the uniform crossing). A wrapped NON-function
|
|
@@ -451,10 +453,8 @@ ScrDyn *scr_dyn_array_proto_call(ScrDyn *recv, ScrStr *method, ScrDyn *args) {
|
|
|
451
453
|
bool present = dyn_borrow_present(recv, i);
|
|
452
454
|
if (scr_exc_pending()) { scr_dyn_release(out); return NULL; }
|
|
453
455
|
if (!present) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
scr_dyn_release(out);
|
|
457
|
-
return NULL;
|
|
456
|
+
scr_dyn_arr_push_hole(out);
|
|
457
|
+
continue;
|
|
458
458
|
}
|
|
459
459
|
ScrDyn *item = dyn_borrow_item(recv, i);
|
|
460
460
|
if (!item) { scr_dyn_release(out); return NULL; }
|
|
@@ -514,10 +514,7 @@ ScrDyn *scr_dyn_array_proto_call(ScrDyn *recv, ScrStr *method, ScrDyn *args) {
|
|
|
514
514
|
if (scr_exc_pending()) { scr_dyn_release(out); return NULL; }
|
|
515
515
|
if (!present) {
|
|
516
516
|
if (map) {
|
|
517
|
-
|
|
518
|
-
static const char msg[] = "Array.prototype.map over sparse array-like values is not supported yet";
|
|
519
|
-
scr_throw_error_msg(SCR_ERR_ERROR, msg, sizeof msg - 1);
|
|
520
|
-
return NULL;
|
|
517
|
+
scr_dyn_arr_push_hole(out);
|
|
521
518
|
}
|
|
522
519
|
continue;
|
|
523
520
|
}
|
|
@@ -655,34 +652,51 @@ static bool dyn_arr_flatten(ScrDyn *out, const ScrDyn *source, double depth, siz
|
|
|
655
652
|
scr_throw_error_msg_code(SCR_ERR_ERROR, message, sizeof message - 1, "SC2020");
|
|
656
653
|
return false;
|
|
657
654
|
}
|
|
658
|
-
|
|
655
|
+
if (!dyn_borrow_present((ScrDyn *)source, i)) { if (scr_exc_pending()) return false; continue; }
|
|
656
|
+
ScrDyn *item = dyn_borrow_item((ScrDyn *)source, i);
|
|
657
|
+
if (!item) return false;
|
|
659
658
|
if (depth > 0 && item->kind == SCR_DYN_TYPED_REF && scr_dyn_isl_is_array(item)) {
|
|
660
659
|
ScrDyn *view = scr_dyn_typed_ref_materialize(item);
|
|
661
|
-
if (!view || scr_exc_pending()) { scr_dyn_release(view); return false; }
|
|
660
|
+
if (!view || scr_exc_pending()) { scr_dyn_release(view); scr_dyn_release(item); return false; }
|
|
662
661
|
bool ok = dyn_arr_flatten(out, view, depth - 1, visits);
|
|
663
662
|
scr_dyn_release(view);
|
|
663
|
+
scr_dyn_release(item);
|
|
664
664
|
if (!ok) return false;
|
|
665
665
|
continue;
|
|
666
666
|
}
|
|
667
667
|
if (depth > 0 && item->kind == SCR_DYN_ARR) {
|
|
668
|
-
|
|
668
|
+
bool ok = dyn_arr_flatten(out, item, depth - 1, visits);
|
|
669
|
+
scr_dyn_release(item);
|
|
670
|
+
if (!ok) return false;
|
|
669
671
|
} else {
|
|
670
|
-
scr_dyn_arr_push(out,
|
|
672
|
+
scr_dyn_arr_push(out, item);
|
|
671
673
|
}
|
|
672
674
|
}
|
|
673
675
|
return true;
|
|
674
676
|
}
|
|
675
677
|
|
|
676
|
-
static
|
|
678
|
+
static bool dyn_arr_copy_item(ScrDyn *out, const ScrDyn *source, size_t index, bool preserve_hole) {
|
|
679
|
+
if (preserve_hole && !dyn_borrow_present((ScrDyn *)source, index)) {
|
|
680
|
+
if (scr_exc_pending()) return false;
|
|
681
|
+
scr_dyn_arr_push_hole(out);
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
ScrDyn *item = scr_dyn_arr_at(source, (double)index);
|
|
685
|
+
if (!item) return false;
|
|
686
|
+
scr_dyn_arr_push(out, item);
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
static bool dyn_arr_reversed_copy(ScrDyn *out, const ScrDyn *source) {
|
|
677
691
|
for (size_t i = source->v.arr.len; i > 0; i--)
|
|
678
|
-
|
|
692
|
+
if (!dyn_arr_copy_item(out, source, i - 1, false)) return false;
|
|
693
|
+
return true;
|
|
679
694
|
}
|
|
680
695
|
|
|
681
696
|
/* Names each prototype declares BEYOND what's implemented here — these
|
|
682
697
|
* fence loudly instead of mis-answering "is not a function". */
|
|
683
698
|
static bool dyn_arr_proto_unimpl(const char *m) {
|
|
684
|
-
static const char *names[] = { "
|
|
685
|
-
"toString", "toLocaleString", NULL };
|
|
699
|
+
static const char *names[] = { "toString", "toLocaleString", NULL };
|
|
686
700
|
for (size_t i = 0; names[i]; i++) if (dyn_name_is(m, names[i])) return true;
|
|
687
701
|
return false;
|
|
688
702
|
}
|
|
@@ -806,15 +820,15 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
806
820
|
|
|
807
821
|
/* OBJ method calls follow the native prototype chain while binding the
|
|
808
822
|
* original receiver as `this`. */
|
|
809
|
-
if (recv->kind == SCR_DYN_OBJ) {
|
|
823
|
+
if (recv->kind == SCR_DYN_OBJ || recv->kind == SCR_DYN_PROXY) {
|
|
810
824
|
ScrDyn *m = scr_dyn_obj_read(recv, method, strlen(method));
|
|
811
|
-
if (m && (m
|
|
825
|
+
if (m && (scr_dyn_is_callable(m) ||
|
|
812
826
|
/* a WRAPPED engine function stored as a dyn member: the
|
|
813
827
|
* routed call (scr_dyn_call's JSVAL arm) runs it. */
|
|
814
828
|
(m->kind == SCR_DYN_JSVAL && scr_dyn_isl_typeof_is(m, "function")))) {
|
|
815
829
|
/* JS binds the receiver for the call (`obj.method()` — this === obj):
|
|
816
830
|
* the ambient-receiver window (scr_runtime.h). */
|
|
817
|
-
scr_dyn_this_push_dyn(recv);
|
|
831
|
+
scr_dyn_this_push_dyn(callback_recv ? callback_recv : recv);
|
|
818
832
|
ScrDyn *r = scr_dyn_call(m, args, argc, what);
|
|
819
833
|
scr_dyn_this_pop();
|
|
820
834
|
scr_dyn_release(m);
|
|
@@ -874,6 +888,26 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
874
888
|
if ((recv->kind == SCR_DYN_SYMBOL || recv->kind == SCR_DYN_BIGINT || recv->kind == SCR_DYN_NUM || recv->kind == SCR_DYN_BOOL || recv->kind == SCR_DYN_STR) &&
|
|
875
889
|
dyn_name_is(method, "valueOf")) return scr_dyn_retain(recv);
|
|
876
890
|
|
|
891
|
+
if (recv->kind == SCR_DYN_NUM && dyn_name_is(method, "toFixed")) {
|
|
892
|
+
double digits = dyn_index_arg(args, argc, 0, 0, what);
|
|
893
|
+
if (scr_exc_pending()) return NULL;
|
|
894
|
+
ScrStr *text = scr_num_to_fixed(recv->v.num, digits);
|
|
895
|
+
if (scr_exc_pending()) { scr_str_release(text); return NULL; }
|
|
896
|
+
ScrDyn *result = scr_dyn_new_str(text);
|
|
897
|
+
scr_str_release(text);
|
|
898
|
+
return result;
|
|
899
|
+
}
|
|
900
|
+
if (recv->kind == SCR_DYN_NUM && dyn_name_is(method, "toExponential")) {
|
|
901
|
+
if (argc && args[0]->kind != SCR_DYN_UNDEF) {
|
|
902
|
+
dyn_throw_unsupported("Number", method);
|
|
903
|
+
return NULL;
|
|
904
|
+
}
|
|
905
|
+
ScrStr *text = scr_num_to_exponential(recv->v.num);
|
|
906
|
+
ScrDyn *result = scr_dyn_new_str(text);
|
|
907
|
+
scr_str_release(text);
|
|
908
|
+
return result;
|
|
909
|
+
}
|
|
910
|
+
|
|
877
911
|
if (recv->kind == SCR_DYN_STR) {
|
|
878
912
|
ScrStr *s = recv->v.str;
|
|
879
913
|
if (dyn_name_is(method, "slice")) {
|
|
@@ -906,7 +940,32 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
906
940
|
}
|
|
907
941
|
|
|
908
942
|
if (recv->kind == SCR_DYN_ARR) {
|
|
943
|
+
if (dyn_name_is(method, "keys") || dyn_name_is(method, "values") || dyn_name_is(method, "entries"))
|
|
944
|
+
return scr_dyn_native_handle_iterator(callback_recv ? callback_recv : recv,
|
|
945
|
+
dyn_name_is(method, "keys") ? 1 : dyn_name_is(method, "entries") ? 2 : 0);
|
|
909
946
|
size_t len = recv->v.arr.len;
|
|
947
|
+
if (recv->v.arr.presence) {
|
|
948
|
+
bool sparse = false;
|
|
949
|
+
for (size_t i = 0; i < len; i++) if (!recv->v.arr.presence[i]) { sparse = true; break; }
|
|
950
|
+
if (!sparse) { free(recv->v.arr.presence); recv->v.arr.presence = NULL; }
|
|
951
|
+
else if (dyn_name_is(method, "forEach") || dyn_name_is(method, "map") || dyn_name_is(method, "filter") ||
|
|
952
|
+
dyn_name_is(method, "some") || dyn_name_is(method, "every") || dyn_name_is(method, "find") ||
|
|
953
|
+
dyn_name_is(method, "findIndex") || dyn_name_is(method, "findLast") || dyn_name_is(method, "findLastIndex") ||
|
|
954
|
+
dyn_name_is(method, "reduce") || dyn_name_is(method, "reduceRight") || dyn_name_is(method, "slice") ||
|
|
955
|
+
dyn_name_is(method, "indexOf") || dyn_name_is(method, "lastIndexOf") || dyn_name_is(method, "includes")) {
|
|
956
|
+
ScrDyn *pack = scr_dyn_new_arr();
|
|
957
|
+
for (size_t i = 0; i < argc; i++) scr_dyn_arr_push(pack, scr_dyn_retain(args[i]));
|
|
958
|
+
ScrStr *name = scr_str_new(method, strlen(method));
|
|
959
|
+
ScrDyn *result = scr_dyn_array_proto_call(callback_recv ? callback_recv : recv, name, pack);
|
|
960
|
+
scr_str_release(name);
|
|
961
|
+
scr_dyn_release(pack);
|
|
962
|
+
return result;
|
|
963
|
+
} else if (dyn_arr_proto_mutates(method) && !dyn_name_is(method, "fill") && !dyn_name_is(method, "push") && !dyn_name_is(method, "pop") && !dyn_name_is(method, "shift")) {
|
|
964
|
+
static const char message[] = "This checked array mutation over holes is not supported yet";
|
|
965
|
+
scr_throw_error_msg_code(SCR_ERR_ERROR, message, sizeof message - 1, "SC2020");
|
|
966
|
+
return NULL;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
910
969
|
size_t splice_start = 0;
|
|
911
970
|
size_t splice_removed = 0;
|
|
912
971
|
if (dyn_arr_proto_mutates(method)) {
|
|
@@ -970,7 +1029,10 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
970
1029
|
}
|
|
971
1030
|
if (dyn_name_is(method, "pop")) {
|
|
972
1031
|
if (len == 0) return scr_dyn_retain(scr_dyn_undefined());
|
|
973
|
-
|
|
1032
|
+
ScrDyn *result = scr_dyn_arr_at(recv, (double)(len - 1));
|
|
1033
|
+
if (!result) return NULL;
|
|
1034
|
+
scr_dyn_release(recv->v.arr.items[--recv->v.arr.len]);
|
|
1035
|
+
return result;
|
|
974
1036
|
}
|
|
975
1037
|
if (dyn_name_is(method, "shift")) {
|
|
976
1038
|
if (len == 0) return scr_dyn_retain(scr_dyn_undefined());
|
|
@@ -990,6 +1052,7 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
990
1052
|
}
|
|
991
1053
|
ScrDyn *first = recv->v.arr.items[0];
|
|
992
1054
|
memmove(recv->v.arr.items, recv->v.arr.items + 1, (len - 1) * sizeof(ScrDyn *));
|
|
1055
|
+
if (recv->v.arr.presence) memmove(recv->v.arr.presence, recv->v.arr.presence + 1, len - 1);
|
|
993
1056
|
recv->v.arr.len = len - 1;
|
|
994
1057
|
return first; /* ownership moves out */
|
|
995
1058
|
}
|
|
@@ -1048,7 +1111,7 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1048
1111
|
if (!dyn_arr_length_unchanged(recv, len)) return NULL;
|
|
1049
1112
|
double idx = iD < 0 ? (double)len + iD : iD;
|
|
1050
1113
|
if (idx < 0 || idx >= (double)len) return scr_dyn_retain(scr_dyn_undefined());
|
|
1051
|
-
return
|
|
1114
|
+
return scr_dyn_arr_at(recv, idx);
|
|
1052
1115
|
}
|
|
1053
1116
|
if (dyn_name_is(method, "indexOf") || dyn_name_is(method, "lastIndexOf") ||
|
|
1054
1117
|
dyn_name_is(method, "includes")) {
|
|
@@ -1106,15 +1169,19 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1106
1169
|
if (dyn_name_is(method, "join")) {
|
|
1107
1170
|
ScrJsonBuf b;
|
|
1108
1171
|
scr_jb_init(&b);
|
|
1172
|
+
ScrStr *separator = argc > 0 && args[0]->kind != SCR_DYN_UNDEF
|
|
1173
|
+
? scr_dyn_string_coerce_js(args[0]) : scr_str_new(",", 1);
|
|
1174
|
+
if (!separator) { free(b.data); return NULL; }
|
|
1109
1175
|
for (size_t i = 0; i < len; i++) {
|
|
1110
|
-
if (i > 0)
|
|
1111
|
-
|
|
1112
|
-
|
|
1176
|
+
if (i > 0) for (size_t j = 0; j < separator->len; j++) scr_jb_putc(&b, separator->data[j]);
|
|
1177
|
+
ScrDyn *e = scr_dyn_arr_at(recv, (double)i);
|
|
1178
|
+
if (e) {
|
|
1179
|
+
if (e->kind != SCR_DYN_UNDEF && e->kind != SCR_DYN_NULL) scr_dyn_display_buf(&b, e);
|
|
1180
|
+
scr_dyn_release(e);
|
|
1113
1181
|
}
|
|
1114
|
-
|
|
1115
|
-
if (e->kind == SCR_DYN_UNDEF || e->kind == SCR_DYN_NULL) continue;
|
|
1116
|
-
scr_dyn_display_buf(&b, e);
|
|
1182
|
+
if (!e || scr_exc_pending()) { scr_str_release(separator); free(b.data); return NULL; }
|
|
1117
1183
|
}
|
|
1184
|
+
scr_str_release(separator);
|
|
1118
1185
|
ScrStr *joined = scr_jb_finish(&b);
|
|
1119
1186
|
ScrDyn *r = scr_dyn_new_str(joined); /* retains */
|
|
1120
1187
|
scr_str_release(joined);
|
|
@@ -1122,7 +1189,9 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1122
1189
|
}
|
|
1123
1190
|
if (dyn_name_is(method, "concat")) {
|
|
1124
1191
|
ScrDyn *out = scr_dyn_new_arr();
|
|
1125
|
-
for (size_t i = 0; i < len; i++)
|
|
1192
|
+
for (size_t i = 0; i < len; i++) {
|
|
1193
|
+
if (!dyn_arr_copy_item(out, recv, i, true)) { scr_dyn_release(out); return NULL; }
|
|
1194
|
+
}
|
|
1126
1195
|
for (size_t a = 0; a < argc; a++) {
|
|
1127
1196
|
ScrDyn *view = args[a]->kind == SCR_DYN_TYPED_REF && scr_dyn_isl_is_array(args[a])
|
|
1128
1197
|
? scr_dyn_typed_ref_materialize(args[a]) : NULL;
|
|
@@ -1130,7 +1199,7 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1130
1199
|
const ScrDyn *source = view ? view : args[a];
|
|
1131
1200
|
if (source->kind == SCR_DYN_ARR) {
|
|
1132
1201
|
for (size_t i = 0; i < source->v.arr.len; i++) {
|
|
1133
|
-
|
|
1202
|
+
if (!dyn_arr_copy_item(out, source, i, true)) { scr_dyn_release(view); scr_dyn_release(out); return NULL; }
|
|
1134
1203
|
}
|
|
1135
1204
|
} else {
|
|
1136
1205
|
scr_dyn_arr_push(out, scr_dyn_retain(args[a]));
|
|
@@ -1161,7 +1230,7 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1161
1230
|
}
|
|
1162
1231
|
if (dyn_name_is(method, "toReversed")) {
|
|
1163
1232
|
ScrDyn *out = scr_dyn_new_arr();
|
|
1164
|
-
dyn_arr_reversed_copy(out, recv);
|
|
1233
|
+
if (!dyn_arr_reversed_copy(out, recv)) { scr_dyn_release(out); return NULL; }
|
|
1165
1234
|
return out;
|
|
1166
1235
|
}
|
|
1167
1236
|
if (dyn_name_is(method, "with")) {
|
|
@@ -1176,15 +1245,17 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1176
1245
|
}
|
|
1177
1246
|
ScrDyn *replacement = argc > 1 ? args[1] : scr_dyn_undefined();
|
|
1178
1247
|
ScrDyn *out = scr_dyn_new_arr();
|
|
1179
|
-
for (size_t i = 0; i < len; i++)
|
|
1180
|
-
|
|
1248
|
+
for (size_t i = 0; i < len; i++) {
|
|
1249
|
+
if ((size_t)index == i) scr_dyn_arr_push(out, scr_dyn_retain(replacement));
|
|
1250
|
+
else if (!dyn_arr_copy_item(out, recv, i, false)) { scr_dyn_release(out); return NULL; }
|
|
1251
|
+
}
|
|
1181
1252
|
return out;
|
|
1182
1253
|
}
|
|
1183
1254
|
if (dyn_name_is(method, "toSpliced")) {
|
|
1184
1255
|
double startD = dyn_index_arg(args, argc, 0, 0, what);
|
|
1185
1256
|
if (scr_exc_pending()) return NULL;
|
|
1186
1257
|
size_t start = dyn_rel_index(startD, len);
|
|
1187
|
-
size_t delete_count = len - start;
|
|
1258
|
+
size_t delete_count = argc == 0 ? 0 : len - start;
|
|
1188
1259
|
if (argc > 1) {
|
|
1189
1260
|
double countD = dyn_index_arg(args, argc, 1, 0, what);
|
|
1190
1261
|
if (scr_exc_pending()) return NULL;
|
|
@@ -1192,9 +1263,9 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1192
1263
|
}
|
|
1193
1264
|
if (!dyn_arr_length_unchanged(recv, len)) return NULL;
|
|
1194
1265
|
ScrDyn *out = scr_dyn_new_arr();
|
|
1195
|
-
for (size_t i = 0; i < start; i++)
|
|
1266
|
+
for (size_t i = 0; i < start; i++) if (!dyn_arr_copy_item(out, recv, i, false)) { scr_dyn_release(out); return NULL; }
|
|
1196
1267
|
for (size_t i = 2; i < argc; i++) scr_dyn_arr_push(out, scr_dyn_retain(args[i]));
|
|
1197
|
-
for (size_t i = start + delete_count; i < len; i++)
|
|
1268
|
+
for (size_t i = start + delete_count; i < len; i++) if (!dyn_arr_copy_item(out, recv, i, false)) { scr_dyn_release(out); return NULL; }
|
|
1198
1269
|
return out;
|
|
1199
1270
|
}
|
|
1200
1271
|
if (dyn_name_is(method, "fill")) {
|
|
@@ -1212,8 +1283,14 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1212
1283
|
}
|
|
1213
1284
|
ScrDyn *fill = argc ? args[0] : scr_dyn_undefined();
|
|
1214
1285
|
for (size_t i = start; i < end; i++) {
|
|
1286
|
+
if (recv->non_extensible && !scr_dyn_arr_has_index(recv, i)) {
|
|
1287
|
+
static const char message[] = "Cannot add property, object is not extensible";
|
|
1288
|
+
scr_throw_error_msg(SCR_ERR_TYPE, message, sizeof message - 1);
|
|
1289
|
+
return NULL;
|
|
1290
|
+
}
|
|
1215
1291
|
ScrDyn *old = recv->v.arr.items[i];
|
|
1216
1292
|
recv->v.arr.items[i] = scr_dyn_retain(fill);
|
|
1293
|
+
if (recv->v.arr.presence) recv->v.arr.presence[i] = 1;
|
|
1217
1294
|
scr_dyn_release(old);
|
|
1218
1295
|
}
|
|
1219
1296
|
return scr_dyn_retain(recv);
|
|
@@ -1330,7 +1407,9 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1330
1407
|
ScrDyn *out = scr_dyn_new_arr();
|
|
1331
1408
|
size_t n = recv->v.arr.len;
|
|
1332
1409
|
for (size_t i = 0; i < n && i < recv->v.arr.len; i++) {
|
|
1333
|
-
|
|
1410
|
+
if (!dyn_borrow_present(recv, i)) { if (scr_exc_pending()) { scr_dyn_release(out); return NULL; } continue; }
|
|
1411
|
+
ScrDyn *item = dyn_borrow_item(recv, i);
|
|
1412
|
+
if (!item) { scr_dyn_release(out); return NULL; }
|
|
1334
1413
|
ScrDyn *r = dyn_call_cb(
|
|
1335
1414
|
cb, item, i, callback_recv ? callback_recv : recv);
|
|
1336
1415
|
scr_dyn_release(item);
|
|
@@ -1343,7 +1422,8 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1343
1422
|
}
|
|
1344
1423
|
if (r->kind == SCR_DYN_ARR) {
|
|
1345
1424
|
for (size_t j = 0; j < r->v.arr.len; j++) {
|
|
1346
|
-
scr_dyn_arr_push(out,
|
|
1425
|
+
if (dyn_borrow_present(r, j)) scr_dyn_arr_push(out, dyn_borrow_item(r, j));
|
|
1426
|
+
if (scr_exc_pending()) { scr_dyn_release(r); scr_dyn_release(out); return NULL; }
|
|
1347
1427
|
}
|
|
1348
1428
|
scr_dyn_release(r);
|
|
1349
1429
|
} else if (scr_dyn_isl_is_array(r)) {
|
|
@@ -1393,7 +1473,7 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1393
1473
|
return NULL;
|
|
1394
1474
|
}
|
|
1395
1475
|
ScrDyn *out = scr_dyn_new_arr();
|
|
1396
|
-
for (size_t i = 0; i < len; i++)
|
|
1476
|
+
for (size_t i = 0; i < len; i++) if (!dyn_arr_copy_item(out, recv, i, false)) { scr_dyn_release(out); return NULL; }
|
|
1397
1477
|
if (len > 1 && !dyn_arr_sort(out, cmp->kind == SCR_DYN_FUNC ? cmp : NULL)) {
|
|
1398
1478
|
scr_dyn_release(out);
|
|
1399
1479
|
return NULL;
|
|
@@ -1433,6 +1513,47 @@ static ScrDyn *scr_dyn_invoke_impl(
|
|
|
1433
1513
|
|
|
1434
1514
|
if (recv->kind == SCR_DYN_BYTES) {
|
|
1435
1515
|
ScrBytes *bytes = recv->v.bytes;
|
|
1516
|
+
if (bytes->is_data_view) {
|
|
1517
|
+
static const char *const kinds[] = { "Uint8", "Int8", "Uint16", "Int16", "Uint32", "Int32", "Float32", "Float64", "BigUint64", "BigInt64" };
|
|
1518
|
+
const bool get = !strncmp(method, "get", 3);
|
|
1519
|
+
const bool set = !strncmp(method, "set", 3);
|
|
1520
|
+
for (size_t kind = 0; (get || set) && kind < sizeof kinds / sizeof kinds[0]; kind++) {
|
|
1521
|
+
if (strcmp(method + 3, kinds[kind])) continue;
|
|
1522
|
+
double offset = 0;
|
|
1523
|
+
if (argc && !scr_dyn_number_coerce_js(args[0], &offset)) return NULL;
|
|
1524
|
+
/* ToIndex precedes value coercion; the view bounds check follows
|
|
1525
|
+
* it. Keep these stages distinct for observable valueOf calls. */
|
|
1526
|
+
offset = isnan(offset) ? 0 : trunc(offset);
|
|
1527
|
+
if (!(offset >= 0) || offset > 9007199254740991.0) {
|
|
1528
|
+
static const char message[] = "Offset is outside the bounds of the DataView";
|
|
1529
|
+
scr_throw_error_msg(SCR_ERR_RANGE, message, sizeof message - 1);
|
|
1530
|
+
return NULL;
|
|
1531
|
+
}
|
|
1532
|
+
const bool le = argc > (get ? 1 : 2) && scr_dyn_truthy(args[get ? 1 : 2]);
|
|
1533
|
+
if (get) {
|
|
1534
|
+
if (kind >= SCR_DV_BIGU64) {
|
|
1535
|
+
ScrBigInt *value = scr_bigint_dataview_get(bytes, offset, kind == SCR_DV_BIGI64, le);
|
|
1536
|
+
if (scr_exc_pending()) return NULL;
|
|
1537
|
+
ScrDyn *result = scr_dyn_new_bigint(value);
|
|
1538
|
+
scr_bigint_release(value);
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1541
|
+
double value = scr_dataview_get(bytes, offset, (ScrDataViewGet)kind, le);
|
|
1542
|
+
return scr_exc_pending() ? NULL : scr_dyn_new_num(value);
|
|
1543
|
+
}
|
|
1544
|
+
if (kind >= SCR_DV_BIGU64) {
|
|
1545
|
+
ScrBigInt *value = scr_dyn_bigint_coerce(argc > 1 ? args[1] : scr_dyn_undefined());
|
|
1546
|
+
if (scr_exc_pending()) return NULL;
|
|
1547
|
+
scr_bigint_dataview_set(bytes, offset, value, le);
|
|
1548
|
+
scr_bigint_release(value);
|
|
1549
|
+
} else {
|
|
1550
|
+
double value;
|
|
1551
|
+
if (!scr_dyn_number_coerce_js(argc > 1 ? args[1] : scr_dyn_undefined(), &value)) return NULL;
|
|
1552
|
+
scr_dataview_set(bytes, offset, value, (ScrDataViewGet)kind, le);
|
|
1553
|
+
}
|
|
1554
|
+
return scr_exc_pending() ? NULL : scr_dyn_retain(scr_dyn_undefined());
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1436
1557
|
size_t blen = bytes->len;
|
|
1437
1558
|
if (dyn_name_is(method, "at")) {
|
|
1438
1559
|
double iD = dyn_bytes_index_arg(args, argc, 0, 0);
|
|
@@ -1660,7 +1781,7 @@ ScrDyn *scr_dyn_array_prototype(void) {
|
|
|
1660
1781
|
}
|
|
1661
1782
|
|
|
1662
1783
|
/* Object.defineProperties over dyn values (see scr_runtime.h). */
|
|
1663
|
-
ScrDyn *
|
|
1784
|
+
static ScrDyn *scr_dyn_define_props_internal(ScrDyn *target, ScrDyn *descs, ScrDyn *protected_keys) {
|
|
1664
1785
|
/* Island-held operands ARE objects to Node — the non-object TypeError
|
|
1665
1786
|
* below would be a wrong claim. Loud fence (lane dyn-routing-ops). */
|
|
1666
1787
|
scr_dyn_isl_fence(target, "Object.defineProperties");
|
|
@@ -1733,6 +1854,15 @@ ScrDyn *scr_dyn_define_props(ScrDyn *target, ScrDyn *descs) {
|
|
|
1733
1854
|
ScrDyn *pair = pending->v.arr.items[i];
|
|
1734
1855
|
ScrDyn *key = pair->v.arr.items[0];
|
|
1735
1856
|
ScrDyn *descriptor = pair->v.arr.items[1];
|
|
1857
|
+
if (protected_keys) {
|
|
1858
|
+
for (size_t k = 0; k < protected_keys->v.arr.len; k++) {
|
|
1859
|
+
if (!scr_dyn_strict_eq(key, protected_keys->v.arr.items[k])) continue;
|
|
1860
|
+
static const char message[] = "Replacing compiled class prototype members has no native lowering [SC1090]";
|
|
1861
|
+
scr_throw_error_msg(SCR_ERR_ERROR, message, sizeof message - 1);
|
|
1862
|
+
scr_dyn_release(pending);
|
|
1863
|
+
return NULL;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1736
1866
|
ScrDyn *defined = scr_dyn_define_property(target, key, descriptor);
|
|
1737
1867
|
if (!defined) {
|
|
1738
1868
|
scr_dyn_release(pending);
|
|
@@ -1748,6 +1878,14 @@ fail:
|
|
|
1748
1878
|
return NULL;
|
|
1749
1879
|
}
|
|
1750
1880
|
|
|
1881
|
+
ScrDyn *scr_dyn_define_props(ScrDyn *target, ScrDyn *descs) {
|
|
1882
|
+
return scr_dyn_define_props_internal(target, descs, NULL);
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
ScrDyn *scr_dyn_define_prototype_props(ScrDyn *target, ScrDyn *descs, ScrDyn *protected_keys) {
|
|
1886
|
+
return scr_dyn_define_props_internal(target, descs, protected_keys);
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1751
1889
|
ScrDyn *scr_dyn_obj_create_with_properties(ScrDyn *prototype, ScrDyn *descriptors) {
|
|
1752
1890
|
ScrDyn *object = scr_dyn_obj_create(prototype);
|
|
1753
1891
|
if (!object) return NULL;
|
|
@@ -92,7 +92,11 @@
|
|
|
92
92
|
#include <stdlib.h>
|
|
93
93
|
#include <string.h>
|
|
94
94
|
|
|
95
|
+
#ifndef SCR_FETCH_SIGNAL_ONLY
|
|
95
96
|
#include <zlib.h>
|
|
97
|
+
#else
|
|
98
|
+
static void sf_signal_install(void);
|
|
99
|
+
#endif
|
|
96
100
|
|
|
97
101
|
/*
|
|
98
102
|
* The static tier is a small native Web-platform island of its own:
|
|
@@ -289,6 +293,7 @@ struct SfResponse {
|
|
|
289
293
|
bool null_body;
|
|
290
294
|
};
|
|
291
295
|
|
|
296
|
+
#ifndef SCR_FETCH_SIGNAL_ONLY
|
|
292
297
|
struct SfTransfer {
|
|
293
298
|
size_t rc; /* live registry + one per listener closure */
|
|
294
299
|
ScrPromise *promise; /* owned */
|
|
@@ -323,12 +328,15 @@ struct SfTransfer {
|
|
|
323
328
|
};
|
|
324
329
|
|
|
325
330
|
static SfTransfer *sf_live;
|
|
331
|
+
#endif
|
|
326
332
|
/* Weak registries: owners unlink themselves on destruction. They let the
|
|
327
333
|
* fetch teardown sever opaque native→dyn edges before final cycle collection,
|
|
328
334
|
* including otherwise-untraceable callback/reason→handle backedges. */
|
|
329
335
|
static SfSignal *sf_callback_signals;
|
|
330
336
|
static SfSignal *sf_reason_signals;
|
|
337
|
+
#ifndef SCR_FETCH_SIGNAL_ONLY
|
|
331
338
|
static SfStream *sf_callback_streams;
|
|
339
|
+
#endif
|
|
332
340
|
|
|
333
341
|
static void sf_oom(void) {
|
|
334
342
|
fputs("scriptc: out of memory\n", stderr);
|
|
@@ -484,6 +492,9 @@ static void sf_signal_drop_reason(SfSignal *s) {
|
|
|
484
492
|
}
|
|
485
493
|
|
|
486
494
|
static SfSignal *sf_signal_new(void) {
|
|
495
|
+
#ifdef SCR_FETCH_SIGNAL_ONLY
|
|
496
|
+
sf_signal_install();
|
|
497
|
+
#endif
|
|
487
498
|
SfSignal *s = calloc(1, sizeof *s);
|
|
488
499
|
if (!s) sf_oom();
|
|
489
500
|
s->rc = 1;
|
|
@@ -1340,6 +1351,8 @@ static bool sf_signal_set(void *ptr, const char *key, size_t len,
|
|
|
1340
1351
|
|
|
1341
1352
|
/* ── ReadableStream ──────────────────────────────────────────────── */
|
|
1342
1353
|
|
|
1354
|
+
#ifndef SCR_FETCH_SIGNAL_ONLY
|
|
1355
|
+
|
|
1343
1356
|
static void sf_stream_track_callbacks(SfStream *s) {
|
|
1344
1357
|
if (s->callbacks_tracked || (!s->pull_cb && !s->cancel_cb)) return;
|
|
1345
1358
|
s->callbacks_tracked = true;
|
|
@@ -5775,7 +5788,38 @@ void scr_fetch_install(void) {
|
|
|
5775
5788
|
scr_atexit(sf_teardown);
|
|
5776
5789
|
}
|
|
5777
5790
|
|
|
5778
|
-
#else
|
|
5791
|
+
#else /* SCR_FETCH_SIGNAL_ONLY */
|
|
5792
|
+
|
|
5793
|
+
static bool sf_no_set(void *ptr, const char *key, size_t len, const ScrDyn *value) {
|
|
5794
|
+
(void)ptr; (void)key; (void)len; (void)value;
|
|
5795
|
+
return false;
|
|
5796
|
+
}
|
|
5797
|
+
static const ScrDynHandleOps sf_signal_ops = {
|
|
5798
|
+
"AbortSignal", &sf_signal_retain_v, &sf_signal_release_v,
|
|
5799
|
+
&sf_signal_invoke, &sf_signal_get, &sf_signal_set, NULL };
|
|
5800
|
+
static const ScrDynHandleOps sf_abort_controller_ops = {
|
|
5801
|
+
"AbortController", &sf_signal_retain_v, &sf_signal_release_v,
|
|
5802
|
+
&sf_abort_controller_invoke, &sf_abort_controller_get, &sf_no_set, NULL };
|
|
5803
|
+
static const ScrDynHandleOps sf_event_ops = {
|
|
5804
|
+
"Event", &sf_event_retain_v, &sf_event_release_v,
|
|
5805
|
+
&sf_event_invoke, &sf_event_get, &sf_event_set, NULL };
|
|
5806
|
+
static void sf_signal_teardown(void) {
|
|
5807
|
+
while (sf_callback_signals) sf_signal_drop_callbacks(sf_callback_signals);
|
|
5808
|
+
while (sf_reason_signals) sf_signal_drop_reason(sf_reason_signals);
|
|
5809
|
+
}
|
|
5810
|
+
static void sf_signal_install(void) {
|
|
5811
|
+
static bool installed;
|
|
5812
|
+
if (installed) return;
|
|
5813
|
+
installed = true;
|
|
5814
|
+
scr_dyn_handle_install(SCR_DYNH_ABORT_SIGNAL, &sf_signal_ops);
|
|
5815
|
+
scr_dyn_handle_install(SCR_DYNH_ABORT_CONTROLLER, &sf_abort_controller_ops);
|
|
5816
|
+
scr_dyn_handle_install(SCR_DYNH_EVENT, &sf_event_ops);
|
|
5817
|
+
scr_atexit(sf_signal_teardown);
|
|
5818
|
+
}
|
|
5819
|
+
|
|
5820
|
+
#endif /* SCR_FETCH_SIGNAL_ONLY */
|
|
5821
|
+
|
|
5822
|
+
#else /* SCR_DYNAMIC */
|
|
5779
5823
|
|
|
5780
5824
|
#include "scr_runtime.h"
|
|
5781
5825
|
#include "scr_url_internal.h"
|
|
@@ -476,6 +476,37 @@ ScrPromise *scr_file_handle_close_promise(ScrFileHandle *h) {
|
|
|
476
476
|
return scr_promise_settled_void();
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
+
ScrPromise *scr_file_handle_sync_promise(ScrFileHandle *h) {
|
|
480
|
+
if (scr_file_handle_require_open(h)) scr_fs_fsync((double)h->fd);
|
|
481
|
+
return scr_promise_settled_void();
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
ScrPromise *scr_file_handle_datasync_promise(ScrFileHandle *h) {
|
|
485
|
+
if (scr_file_handle_require_open(h)) scr_fs_fdatasync((double)h->fd);
|
|
486
|
+
return scr_promise_settled_void();
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
ScrPromise *scr_file_handle_truncate_promise(ScrFileHandle *h, double length) {
|
|
490
|
+
if (scr_file_handle_require_open(h)) scr_fs_ftruncate((double)h->fd, length);
|
|
491
|
+
return scr_promise_settled_void();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
ScrPromise *scr_file_handle_chmod_promise(ScrFileHandle *h, double mode) {
|
|
495
|
+
if (scr_file_handle_require_open(h) && scr_file_handle_mode_valid(mode))
|
|
496
|
+
scr_fs_fchmod((double)h->fd, mode);
|
|
497
|
+
return scr_promise_settled_void();
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
double scr_file_handle_readv(ScrFileHandle *h, ScrArr *buffers, double position) {
|
|
501
|
+
if (!scr_file_handle_require_open(h)) return 0;
|
|
502
|
+
return scr_fs_readv_sync((double)h->fd, buffers, position);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
double scr_file_handle_writev(ScrFileHandle *h, ScrArr *buffers, double position) {
|
|
506
|
+
if (!scr_file_handle_require_open(h)) return 0;
|
|
507
|
+
return scr_fs_writev_sync((double)h->fd, buffers, position);
|
|
508
|
+
}
|
|
509
|
+
|
|
479
510
|
ScrPromise *scr_file_handle_read_file_promise(ScrFileHandle *h,
|
|
480
511
|
ScrStr *encoding) {
|
|
481
512
|
(void)encoding;
|