@scriptc/cli-darwin-arm64 0.2.1 → 0.2.3
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 +158 -31
- package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
- package/dist/lib/llvm/package.json +1 -1
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_events.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/default/scr_util_style.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_events.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_island.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_util_style.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic/scr_web.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/default/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/default/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/default/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/default/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_events.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/default/scr_util_style.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_array.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_assert.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_async_dyn.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_crypto_async.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_dyn_invoke.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_events.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_exception.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_file_handle.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_island.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_map.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_node_builtin.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_qs.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_symbol.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_url.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_url_params.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_util_compare.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_util_style.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic/scr_web.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
- package/dist/lib/runtime-darwin-arm64/package.json +1 -1
- package/dist/lib/runtime-darwin-arm64/runtime-pack.json +423 -297
- 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_array.c +5 -0
- package/dist/lib/runtime-sources/src/scr_assert.c +26 -0
- package/dist/lib/runtime-sources/src/scr_async.c +56 -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 +355 -51
- 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_events.c +9 -0
- package/dist/lib/runtime-sources/src/scr_exception.c +1 -0
- package/dist/lib/runtime-sources/src/scr_fetch.c +45 -1
- package/dist/lib/runtime-sources/src/scr_file_handle.c +42 -0
- package/dist/lib/runtime-sources/src/scr_island.c +2166 -786
- package/dist/lib/runtime-sources/src/scr_island_manifest.h +19 -13
- package/dist/lib/runtime-sources/src/scr_json.c +584 -54
- package/dist/lib/runtime-sources/src/scr_json.test.ts +1 -0
- package/dist/lib/runtime-sources/src/scr_lib.c +1192 -43
- package/dist/lib/runtime-sources/src/scr_map.c +8 -0
- package/dist/lib/runtime-sources/src/scr_node_builtin.c +78 -0
- package/dist/lib/runtime-sources/src/scr_qs.c +10 -0
- package/dist/lib/runtime-sources/src/scr_regex.c +107 -5
- package/dist/lib/runtime-sources/src/scr_runtime.h +136 -9
- package/dist/lib/runtime-sources/src/scr_symbol.c +5 -0
- package/dist/lib/runtime-sources/src/scr_system_errors.h +573 -0
- package/dist/lib/runtime-sources/src/scr_text_decoder_labels.h +12 -12
- package/dist/lib/runtime-sources/src/scr_url.c +547 -64
- package/dist/lib/runtime-sources/src/scr_url_internal.h +6 -0
- package/dist/lib/runtime-sources/src/scr_url_params.c +10 -0
- package/dist/lib/runtime-sources/src/scr_util_compare.c +222 -0
- package/dist/lib/runtime-sources/src/scr_util_style.c +337 -0
- package/dist/lib/runtime-sources/src/scr_web.c +849 -264
- package/package.json +1 -1
|
@@ -18,12 +18,18 @@ struct ScrUrl {
|
|
|
18
18
|
ScrStr *query; /* "" or "?..." */
|
|
19
19
|
ScrStr *fragment; /* "" or "#..." */
|
|
20
20
|
bool has_authority;
|
|
21
|
+
/* Node 24 preserves the /. serialization escape when a host setter
|
|
22
|
+
* enters port state from a host-less // path; pathname excludes it. */
|
|
23
|
+
bool host_path_escape;
|
|
21
24
|
/* The LIVE searchParams view (NULL until first read). NON-owning: the
|
|
22
25
|
* view retains its URL, so a URL with a live view never dies; the view
|
|
23
26
|
* clears this back-pointer when it releases. Every `u.searchParams`
|
|
24
27
|
* read answers the SAME view — Node's cached-object identity — and
|
|
25
28
|
* view mutations write back into `query` (sp_sync_owner). */
|
|
26
29
|
struct ScrSearchParams *sp_cache;
|
|
30
|
+
/* Installed by the optional params unit; setters can refresh a cached
|
|
31
|
+
* list without making params-free URL programs link that unit. */
|
|
32
|
+
void (*sp_reload)(struct ScrSearchParams *sp, ScrStr *query);
|
|
27
33
|
};
|
|
28
34
|
|
|
29
35
|
#endif /* SCR_URL_INTERNAL_H */
|
|
@@ -371,12 +371,22 @@ ScrSearchParams *scr_sp_with(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
|
|
|
371
371
|
return scr_sp_retain(sp);
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
static void sp_reload(ScrSearchParams *sp, ScrStr *query) {
|
|
375
|
+
for (size_t i = 0; i < sp->len; i++) {
|
|
376
|
+
scr_str_release(sp->names[i]);
|
|
377
|
+
scr_str_release(sp->vals[i]);
|
|
378
|
+
}
|
|
379
|
+
sp->len = 0;
|
|
380
|
+
if (query->len > 1) sp_parse_into(sp, query->data + 1, query->len - 1);
|
|
381
|
+
}
|
|
382
|
+
|
|
374
383
|
ScrSearchParams *scr_url_search_params(ScrUrl *u) {
|
|
375
384
|
if (u->sp_cache) return scr_sp_retain(u->sp_cache);
|
|
376
385
|
ScrSearchParams *sp = sp_alloc();
|
|
377
386
|
if (u->query->len > 1) sp_parse_into(sp, u->query->data + 1, u->query->len - 1);
|
|
378
387
|
sp->owner = scr_url_retain(u);
|
|
379
388
|
u->sp_cache = sp;
|
|
389
|
+
u->sp_reload = sp_reload;
|
|
380
390
|
return sp;
|
|
381
391
|
}
|
|
382
392
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#include "scr_runtime.h"
|
|
2
|
+
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
/* Node 24 strict comparison for values whose checked representation retains
|
|
6
|
+
* their observable shape. Never materialize an opaque native object as an
|
|
7
|
+
* ordinary record: doing so would discard its intrinsic brand/prototype. */
|
|
8
|
+
typedef struct ScrDeepFrame {
|
|
9
|
+
const ScrDyn *a, *b;
|
|
10
|
+
const struct ScrDeepFrame *parent;
|
|
11
|
+
} ScrDeepFrame;
|
|
12
|
+
|
|
13
|
+
static bool util_deep_refused(const char *kind) {
|
|
14
|
+
ScrJsonBuf message;
|
|
15
|
+
scr_jb_init(&message);
|
|
16
|
+
scr_jb_puts(&message, "util.isDeepStrictEqual over ");
|
|
17
|
+
scr_jb_puts(&message, kind);
|
|
18
|
+
scr_jb_puts(&message, " is not supported yet");
|
|
19
|
+
ScrStr *text = scr_jb_finish(&message);
|
|
20
|
+
scr_throw_error_msg_code(SCR_ERR_TYPE, text->data, text->len, "SC2020");
|
|
21
|
+
scr_str_release(text);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static bool util_deep_equal(const ScrDyn *, const ScrDyn *, bool, const ScrDeepFrame *);
|
|
26
|
+
|
|
27
|
+
static size_t util_deep_key_count(const ScrDyn *table) {
|
|
28
|
+
size_t count = 0;
|
|
29
|
+
if (table) for (size_t i = 0; i < table->v.obj.len; i++) count += table->v.obj.entries[i].enumerable;
|
|
30
|
+
return count;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static bool util_deep_same_keys(const ScrDyn *a, const ScrDyn *b) {
|
|
34
|
+
if (util_deep_key_count(a) != util_deep_key_count(b)) return false;
|
|
35
|
+
if (a) for (size_t i = 0; i < a->v.obj.len; i++) {
|
|
36
|
+
const ScrDynEntry *e = &a->v.obj.entries[i];
|
|
37
|
+
if (e->enumerable && (!b || !scr_dyn_obj_enumerable(b, e->key, e->key_len))) return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static ScrDyn *util_deep_constructor(const ScrDyn *value) {
|
|
43
|
+
for (const ScrDyn *p = value; p; p = p->prototype) {
|
|
44
|
+
const ScrDyn *table = p->kind == SCR_DYN_OBJ ? p : p->kind == SCR_DYN_ARR ? p->v.arr.properties : NULL;
|
|
45
|
+
if (table) for (size_t i = 0; i < table->v.obj.len; i++) {
|
|
46
|
+
const ScrDynEntry *e = &table->v.obj.entries[i];
|
|
47
|
+
if (e->key_len == 11 && !memcmp(e->key, "constructor", 11)) {
|
|
48
|
+
if (e->accessor) { util_deep_refused("native accessor properties"); return NULL; }
|
|
49
|
+
if (p == value && e->value->kind == SCR_DYN_FUNC) {
|
|
50
|
+
util_deep_refused("native own constructor functions"); return NULL;
|
|
51
|
+
}
|
|
52
|
+
return scr_dyn_retain(e->value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!p->prototype) {
|
|
56
|
+
if (p->null_proto) return scr_dyn_retain(scr_dyn_undefined());
|
|
57
|
+
// Object.prototype is an internal identity token here; general
|
|
58
|
+
// Object.prototype reflection retains its existing native boundary.
|
|
59
|
+
return p->kind == SCR_DYN_ARR ? scr_dyn_array_constructor() : scr_dyn_object_prototype();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return scr_dyn_retain(scr_dyn_undefined());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static ScrDyn *util_deep_tag(const ScrDyn *value) {
|
|
66
|
+
bool has_symbols = false;
|
|
67
|
+
for (const ScrDyn *p = value; p; p = p->prototype) has_symbols |= p->symbol_properties != NULL;
|
|
68
|
+
if (!has_symbols) return scr_dyn_retain(scr_dyn_undefined());
|
|
69
|
+
ScrStr *name = scr_str_new("toStringTag", 11);
|
|
70
|
+
ScrSym *symbol = scr_sym_well_known(name);
|
|
71
|
+
ScrDyn *key = scr_dyn_new_symbol(symbol);
|
|
72
|
+
scr_str_release(name); scr_sym_release(symbol);
|
|
73
|
+
for (const ScrDyn *p = value; p; p = p->prototype) {
|
|
74
|
+
const ScrDyn *keys = p->symbol_keys;
|
|
75
|
+
if (!keys) continue;
|
|
76
|
+
for (size_t i = 0; i < keys->v.arr.len; i++) {
|
|
77
|
+
if (!scr_dyn_same_value(keys->v.arr.items[i], key)) continue;
|
|
78
|
+
// General native getters retain an explicit boundary, including
|
|
79
|
+
// non-enumerable Symbol.toStringTag descriptors read by Node.
|
|
80
|
+
for (size_t j = 0; j < p->symbol_properties->v.obj.len; j++) {
|
|
81
|
+
if (p->symbol_properties->v.obj.entries[j].accessor) {
|
|
82
|
+
scr_dyn_release(key); util_deep_refused("native accessor properties"); return NULL;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
ScrDyn *result = scr_dyn_symbol_key_get(p, key, false);
|
|
86
|
+
scr_dyn_release(key);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
scr_dyn_release(key);
|
|
91
|
+
return scr_dyn_retain(scr_dyn_undefined());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static bool util_deep_properties(const ScrDyn *a, const ScrDyn *b, bool skip,
|
|
95
|
+
const ScrDeepFrame *frame) {
|
|
96
|
+
if (util_deep_key_count(a) != util_deep_key_count(b)) return false;
|
|
97
|
+
if (!a) return true;
|
|
98
|
+
for (size_t i = 0; i < a->v.obj.len; i++) {
|
|
99
|
+
const ScrDynEntry *x = &a->v.obj.entries[i];
|
|
100
|
+
if (!x->enumerable) continue;
|
|
101
|
+
const ScrDynEntry *y = NULL;
|
|
102
|
+
if (b) for (size_t j = 0; j < b->v.obj.len; j++) {
|
|
103
|
+
const ScrDynEntry *candidate = &b->v.obj.entries[j];
|
|
104
|
+
if (candidate->enumerable && candidate->key_len == x->key_len &&
|
|
105
|
+
!memcmp(candidate->key, x->key, x->key_len)) { y = candidate; break; }
|
|
106
|
+
}
|
|
107
|
+
if (!y) return false;
|
|
108
|
+
if (x->accessor || y->accessor) return util_deep_refused("native accessor properties");
|
|
109
|
+
// Materializing a cyclic typed child can refresh its ancestor table.
|
|
110
|
+
// Retain the values before that refresh replaces descriptor storage.
|
|
111
|
+
ScrDyn *xv = scr_dyn_retain(x->value), *yv = scr_dyn_retain(y->value);
|
|
112
|
+
bool same = util_deep_equal(xv, yv, skip, frame);
|
|
113
|
+
scr_dyn_release(xv); scr_dyn_release(yv);
|
|
114
|
+
if (!same) return false;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static bool util_deep_equal(const ScrDyn *a, const ScrDyn *b, bool skip,
|
|
120
|
+
const ScrDeepFrame *parent) {
|
|
121
|
+
if (scr_dyn_same_value(a, b)) return true;
|
|
122
|
+
if (a->kind == SCR_DYN_PROXY || b->kind == SCR_DYN_PROXY)
|
|
123
|
+
return util_deep_refused("native Proxy values");
|
|
124
|
+
if (a->kind == SCR_DYN_JSVAL || b->kind == SCR_DYN_JSVAL) {
|
|
125
|
+
scr_dyn_isl_fence(a->kind == SCR_DYN_JSVAL ? a : b, "util.isDeepStrictEqual");
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (a->kind == SCR_DYN_TYPED_REF || b->kind == SCR_DYN_TYPED_REF) {
|
|
129
|
+
const ScrDyn *inputs[] = { a, b };
|
|
130
|
+
for (size_t i = 0; i < 2; i++) {
|
|
131
|
+
const ScrDyn *v = inputs[i];
|
|
132
|
+
if (v->kind == SCR_DYN_TYPED_REF &&
|
|
133
|
+
strncmp(v->v.typed_ref.type_key, "record:", 7) &&
|
|
134
|
+
strncmp(v->v.typed_ref.type_key, "array<", 6))
|
|
135
|
+
return util_deep_refused("opaque native references");
|
|
136
|
+
}
|
|
137
|
+
ScrDyn *x = a->kind == SCR_DYN_TYPED_REF ? scr_dyn_typed_ref_materialize(a) : scr_dyn_retain((ScrDyn *)a);
|
|
138
|
+
ScrDyn *y = !scr_exc_pending() ? (b->kind == SCR_DYN_TYPED_REF ? scr_dyn_typed_ref_materialize(b) : scr_dyn_retain((ScrDyn *)b)) : NULL;
|
|
139
|
+
bool equal = !scr_exc_pending() && util_deep_equal(x, y, skip, parent);
|
|
140
|
+
scr_dyn_release(x); scr_dyn_release(y);
|
|
141
|
+
return equal;
|
|
142
|
+
}
|
|
143
|
+
if (a->kind == SCR_DYN_HANDLE || b->kind == SCR_DYN_HANDLE)
|
|
144
|
+
return util_deep_refused("native handles");
|
|
145
|
+
ScrError *error = scr_errdyn_err_of(a);
|
|
146
|
+
if (!error) error = scr_errdyn_err_of(b);
|
|
147
|
+
if (error) { scr_error_release(error); return util_deep_refused("native Error values"); }
|
|
148
|
+
if (a->kind != b->kind) return false;
|
|
149
|
+
if (a->kind != SCR_DYN_OBJ && a->kind != SCR_DYN_ARR && a->kind != SCR_DYN_BYTES) return false;
|
|
150
|
+
if (!skip) {
|
|
151
|
+
if (a->kind == SCR_DYN_BYTES) {
|
|
152
|
+
if (a->buffer != b->buffer || a->prototype != b->prototype) return false;
|
|
153
|
+
} else {
|
|
154
|
+
ScrDyn *x = util_deep_constructor(a);
|
|
155
|
+
ScrDyn *y = !scr_exc_pending() ? util_deep_constructor(b) : NULL;
|
|
156
|
+
const ScrDyn *table = a->kind == SCR_DYN_OBJ ? a : a->v.arr.properties;
|
|
157
|
+
bool inherited = !table || !scr_dyn_obj_get(table, "constructor", 11);
|
|
158
|
+
bool compare_constructor = !scr_exc_pending() && x->kind != SCR_DYN_UNDEF && inherited;
|
|
159
|
+
bool same = compare_constructor && scr_dyn_same_value(x, y);
|
|
160
|
+
scr_dyn_release(x); scr_dyn_release(y);
|
|
161
|
+
if (scr_exc_pending()) return false;
|
|
162
|
+
if (!compare_constructor) {
|
|
163
|
+
x = scr_dyn_get_prototype((ScrDyn *)a);
|
|
164
|
+
y = !scr_exc_pending() ? scr_dyn_get_prototype((ScrDyn *)b) : NULL;
|
|
165
|
+
same = !scr_exc_pending() && scr_dyn_same_value(x, y);
|
|
166
|
+
scr_dyn_release(x); scr_dyn_release(y);
|
|
167
|
+
}
|
|
168
|
+
if (!same) return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (a->kind != SCR_DYN_BYTES) {
|
|
172
|
+
ScrDyn *x = util_deep_tag(a);
|
|
173
|
+
ScrDyn *y = !scr_exc_pending() ? util_deep_tag(b) : NULL;
|
|
174
|
+
bool same = !scr_exc_pending() && scr_dyn_strict_eq(x, y);
|
|
175
|
+
if (!same && !scr_exc_pending() && a->kind == SCR_DYN_OBJ &&
|
|
176
|
+
(x->kind == SCR_DYN_UNDEF || y->kind == SCR_DYN_UNDEF)) {
|
|
177
|
+
const ScrDyn *tag = x->kind == SCR_DYN_UNDEF ? y : x;
|
|
178
|
+
same = tag->kind != SCR_DYN_STR || (tag->v.str->len == 6 && !memcmp(tag->v.str->data, "Object", 6));
|
|
179
|
+
}
|
|
180
|
+
scr_dyn_release(x); scr_dyn_release(y);
|
|
181
|
+
if (!same) return false;
|
|
182
|
+
}
|
|
183
|
+
if (a->kind == SCR_DYN_ARR && a->v.arr.len != b->v.arr.len) return false;
|
|
184
|
+
if (a->kind == SCR_DYN_BYTES) {
|
|
185
|
+
const ScrBytes *x = a->v.bytes, *y = b->v.bytes;
|
|
186
|
+
if (x->elem != y->elem || x->len != y->len) return false;
|
|
187
|
+
size_t length = x->len * scr_bytes_elem_size(x->elem);
|
|
188
|
+
if (length && memcmp(x->data, y->data, length)) return false;
|
|
189
|
+
}
|
|
190
|
+
const ScrDyn *props_a = a->kind == SCR_DYN_OBJ ? a : a->kind == SCR_DYN_ARR ? a->v.arr.properties : NULL;
|
|
191
|
+
const ScrDyn *props_b = b->kind == SCR_DYN_OBJ ? b : b->kind == SCR_DYN_ARR ? b->v.arr.properties : NULL;
|
|
192
|
+
if (!util_deep_same_keys(props_a, props_b) || !util_deep_same_keys(a->symbol_properties, b->symbol_properties)) return false;
|
|
193
|
+
/* Match Node 24's shallow pair fast path, then its ancestor-set cycle
|
|
194
|
+
* rule. These are path-local: repeated acyclic children remain structural. */
|
|
195
|
+
if (parent && !parent->parent) {
|
|
196
|
+
if (parent->a == a) return parent->b == b;
|
|
197
|
+
if (parent->b == b) return false;
|
|
198
|
+
} else if (parent) {
|
|
199
|
+
bool seen_a = false, seen_b = false;
|
|
200
|
+
for (const ScrDeepFrame *p = parent; p; p = p->parent) {
|
|
201
|
+
seen_a |= a == p->a || a == p->b;
|
|
202
|
+
seen_b |= b == p->a || b == p->b;
|
|
203
|
+
}
|
|
204
|
+
if (seen_a || seen_b) return seen_a && seen_b;
|
|
205
|
+
}
|
|
206
|
+
ScrDeepFrame frame = { a, b, parent };
|
|
207
|
+
if (a->kind == SCR_DYN_ARR) {
|
|
208
|
+
for (size_t i = 0; i < a->v.arr.len; i++) {
|
|
209
|
+
bool present = scr_dyn_arr_has_index(a, i);
|
|
210
|
+
if (present != scr_dyn_arr_has_index(b, i)) return false;
|
|
211
|
+
if (present && !util_deep_equal(a->v.arr.items[i], b->v.arr.items[i], skip, &frame)) return false;
|
|
212
|
+
}
|
|
213
|
+
if (!util_deep_properties(a->v.arr.properties, b->v.arr.properties, skip, &frame)) return false;
|
|
214
|
+
} else if (a->kind == SCR_DYN_OBJ) {
|
|
215
|
+
if (!util_deep_properties(a, b, skip, &frame)) return false;
|
|
216
|
+
}
|
|
217
|
+
return util_deep_properties(a->symbol_properties, b->symbol_properties, skip, &frame);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
bool scr_util_is_deep_strict_equal(const ScrDyn *a, const ScrDyn *b, const ScrDyn *skip) {
|
|
221
|
+
return util_deep_equal(a, b, scr_dyn_truthy(skip), NULL);
|
|
222
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
#include "scr_runtime.h"
|
|
2
|
+
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
|
|
7
|
+
/* Standard Node 24 inspect colors, including its non-enumerable aliases.
|
|
8
|
+
* Native inspect.colors mutation has no static surface. */
|
|
9
|
+
typedef struct ScrTextStyle { const char *name; unsigned open, close; } ScrTextStyle;
|
|
10
|
+
static const ScrTextStyle util_text_styles[] = {
|
|
11
|
+
{ "reset", 0, 0 },
|
|
12
|
+
{ "bold", 1, 22 },
|
|
13
|
+
{ "dim", 2, 22 },
|
|
14
|
+
{ "italic", 3, 23 },
|
|
15
|
+
{ "underline", 4, 24 },
|
|
16
|
+
{ "blink", 5, 25 },
|
|
17
|
+
{ "inverse", 7, 27 },
|
|
18
|
+
{ "hidden", 8, 28 },
|
|
19
|
+
{ "strikethrough", 9, 29 },
|
|
20
|
+
{ "doubleunderline", 21, 24 },
|
|
21
|
+
{ "black", 30, 39 },
|
|
22
|
+
{ "red", 31, 39 },
|
|
23
|
+
{ "green", 32, 39 },
|
|
24
|
+
{ "yellow", 33, 39 },
|
|
25
|
+
{ "blue", 34, 39 },
|
|
26
|
+
{ "magenta", 35, 39 },
|
|
27
|
+
{ "cyan", 36, 39 },
|
|
28
|
+
{ "white", 37, 39 },
|
|
29
|
+
{ "bgBlack", 40, 49 },
|
|
30
|
+
{ "bgRed", 41, 49 },
|
|
31
|
+
{ "bgGreen", 42, 49 },
|
|
32
|
+
{ "bgYellow", 43, 49 },
|
|
33
|
+
{ "bgBlue", 44, 49 },
|
|
34
|
+
{ "bgMagenta", 45, 49 },
|
|
35
|
+
{ "bgCyan", 46, 49 },
|
|
36
|
+
{ "bgWhite", 47, 49 },
|
|
37
|
+
{ "framed", 51, 54 },
|
|
38
|
+
{ "overlined", 53, 55 },
|
|
39
|
+
{ "gray", 90, 39 },
|
|
40
|
+
{ "redBright", 91, 39 },
|
|
41
|
+
{ "greenBright", 92, 39 },
|
|
42
|
+
{ "yellowBright", 93, 39 },
|
|
43
|
+
{ "blueBright", 94, 39 },
|
|
44
|
+
{ "magentaBright", 95, 39 },
|
|
45
|
+
{ "cyanBright", 96, 39 },
|
|
46
|
+
{ "whiteBright", 97, 39 },
|
|
47
|
+
{ "bgGray", 100, 49 },
|
|
48
|
+
{ "bgRedBright", 101, 49 },
|
|
49
|
+
{ "bgGreenBright", 102, 49 },
|
|
50
|
+
{ "bgYellowBright", 103, 49 },
|
|
51
|
+
{ "bgBlueBright", 104, 49 },
|
|
52
|
+
{ "bgMagentaBright", 105, 49 },
|
|
53
|
+
{ "bgCyanBright", 106, 49 },
|
|
54
|
+
{ "bgWhiteBright", 107, 49 },
|
|
55
|
+
{ "grey", 90, 39 },
|
|
56
|
+
{ "blackBright", 90, 39 },
|
|
57
|
+
{ "bgGrey", 100, 49 },
|
|
58
|
+
{ "bgBlackBright", 100, 49 },
|
|
59
|
+
{ "faint", 2, 22 },
|
|
60
|
+
{ "crossedout", 9, 29 },
|
|
61
|
+
{ "strikeThrough", 9, 29 },
|
|
62
|
+
{ "crossedOut", 9, 29 },
|
|
63
|
+
{ "conceal", 8, 28 },
|
|
64
|
+
{ "swapColors", 7, 27 },
|
|
65
|
+
{ "swapcolors", 7, 27 },
|
|
66
|
+
{ "doubleUnderline", 21, 24 },
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
static ScrDyn *util_style_view(const ScrDyn *value) {
|
|
70
|
+
return value->kind == SCR_DYN_TYPED_REF ? scr_dyn_typed_ref_materialize(value)
|
|
71
|
+
: scr_dyn_retain((ScrDyn *)value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static ScrDyn *util_style_member(const ScrDyn *value, const char *key) {
|
|
75
|
+
if (value->kind == SCR_DYN_UNDEF || value->kind == SCR_DYN_NULL)
|
|
76
|
+
return scr_dyn_retain(scr_dyn_undefined());
|
|
77
|
+
ScrDyn *view = util_style_view(value);
|
|
78
|
+
if (!view) return NULL;
|
|
79
|
+
ScrDyn *result = scr_dyn_obj_read(view, key, strlen(key));
|
|
80
|
+
scr_dyn_release(view);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static const ScrTextStyle *util_style_lookup(const ScrDyn *key) {
|
|
85
|
+
if (key->kind == SCR_DYN_SYMBOL) return NULL;
|
|
86
|
+
ScrStr *name = scr_dyn_string_constructor(key);
|
|
87
|
+
if (!name) return NULL;
|
|
88
|
+
const ScrTextStyle *result = NULL;
|
|
89
|
+
for (size_t i = 0; i < sizeof util_text_styles / sizeof util_text_styles[0]; i++) {
|
|
90
|
+
if (name->len == strlen(util_text_styles[i].name) &&
|
|
91
|
+
!memcmp(name->data, util_text_styles[i].name, name->len)) {
|
|
92
|
+
result = &util_text_styles[i]; break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
scr_str_release(name);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static bool util_style_none(const ScrDyn *key) {
|
|
100
|
+
return key->kind == SCR_DYN_STR && key->v.str->len == 4 &&
|
|
101
|
+
!memcmp(key->v.str->data, "none", 4);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static void util_style_invalid(const ScrDyn *key) {
|
|
105
|
+
ScrDyn *view = util_style_view(key);
|
|
106
|
+
if (!view) return;
|
|
107
|
+
ScrStr *shown = scr_insp_dyn(view, 0, 2);
|
|
108
|
+
scr_dyn_release(view);
|
|
109
|
+
if (!shown) return;
|
|
110
|
+
ScrJsonBuf message;
|
|
111
|
+
scr_jb_init(&message);
|
|
112
|
+
scr_jb_puts(&message, "The argument 'format' must be one of: ");
|
|
113
|
+
for (size_t i = 0; i < sizeof util_text_styles / sizeof util_text_styles[0]; i++) {
|
|
114
|
+
if (i) scr_jb_puts(&message, ", ");
|
|
115
|
+
scr_jb_putc(&message, '\'');
|
|
116
|
+
scr_jb_puts(&message, util_text_styles[i].name);
|
|
117
|
+
scr_jb_putc(&message, '\'');
|
|
118
|
+
}
|
|
119
|
+
scr_jb_puts(&message, ". Received ");
|
|
120
|
+
scr_jb_put_str(&message, shown);
|
|
121
|
+
ScrStr *text = scr_jb_finish(&message);
|
|
122
|
+
scr_throw_error_msg_code(SCR_ERR_TYPE, text->data, text->len, "ERR_INVALID_ARG_VALUE");
|
|
123
|
+
scr_str_release(text); scr_str_release(shown);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Reopen an outer style when a nested fragment closes it. Bold and dim
|
|
127
|
+
* share 22, so preserve that reset before restoring either attribute.
|
|
128
|
+
* A close at the very end is kept intact, matching Node's replacement. */
|
|
129
|
+
static void util_style_putn(ScrJsonBuf *buffer, const char *data, size_t length) {
|
|
130
|
+
for (size_t i = 0; i < length; i++) scr_jb_putc(buffer, data[i]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static ScrStr *util_style_replace(const ScrStr *text, const char *close,
|
|
134
|
+
const char *open, bool keep_close) {
|
|
135
|
+
size_t close_len = strlen(close), at = 0;
|
|
136
|
+
ScrJsonBuf result;
|
|
137
|
+
scr_jb_init(&result);
|
|
138
|
+
for (size_t i = 0; i + close_len < text->len;) {
|
|
139
|
+
if (!memcmp(text->data + i, close, close_len)) {
|
|
140
|
+
util_style_putn(&result, text->data + at, i - at);
|
|
141
|
+
if (keep_close) scr_jb_puts(&result, close);
|
|
142
|
+
scr_jb_puts(&result, open);
|
|
143
|
+
i += close_len; at = i;
|
|
144
|
+
} else i++;
|
|
145
|
+
}
|
|
146
|
+
util_style_putn(&result, text->data + at, text->len - at);
|
|
147
|
+
return scr_jb_finish(&result);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static bool util_style_env_nonempty(const char *name) {
|
|
151
|
+
const char *value = getenv(name);
|
|
152
|
+
return value && *value;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Node recognizes structural stream implementations as well as branded
|
|
156
|
+
* instances. Keep that valid shape outside the native stdio boundary. */
|
|
157
|
+
static bool util_style_custom_stream(const ScrDyn *stream) {
|
|
158
|
+
static const char *const keys[] = { "_readableState", "_writableState", "write", "on", "pipe", "pipeThrough", "getReader", "cancel", "getWriter", "abort" };
|
|
159
|
+
ScrDyn *members[sizeof keys / sizeof keys[0]] = {0};
|
|
160
|
+
bool result = false;
|
|
161
|
+
for (size_t i = 0; i < sizeof keys / sizeof keys[0]; i++) {
|
|
162
|
+
members[i] = util_style_member(stream, keys[i]);
|
|
163
|
+
if (!members[i] || scr_exc_pending()) goto done;
|
|
164
|
+
}
|
|
165
|
+
result = scr_dyn_truthy(members[0]) || scr_dyn_truthy(members[1]) ||
|
|
166
|
+
(members[3]->kind == SCR_DYN_FUNC && (members[2]->kind == SCR_DYN_FUNC || members[4]->kind == SCR_DYN_FUNC)) ||
|
|
167
|
+
(members[5]->kind == SCR_DYN_FUNC && members[6]->kind == SCR_DYN_FUNC && members[7]->kind == SCR_DYN_FUNC) ||
|
|
168
|
+
(members[8]->kind == SCR_DYN_FUNC && members[9]->kind == SCR_DYN_FUNC);
|
|
169
|
+
done:
|
|
170
|
+
for (size_t i = 0; i < sizeof keys / sizeof keys[0]; i++) scr_dyn_release(members[i]);
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* styleText only needs the color/no-color distinction, rather than the
|
|
175
|
+
* full 4/8/24-bit depth. Follow the ordering of Node 24 internal/tty. */
|
|
176
|
+
static bool util_style_terminal_colors(void) {
|
|
177
|
+
const char *force = getenv("FORCE_COLOR");
|
|
178
|
+
if (force) {
|
|
179
|
+
bool enabled = !strcmp(force, "") || !strcmp(force, "true") ||
|
|
180
|
+
!strcmp(force, "1") || !strcmp(force, "2") || !strcmp(force, "3");
|
|
181
|
+
static SCR_TL bool warned = false;
|
|
182
|
+
const char *disabled = util_style_env_nonempty("NO_COLOR") ? "NO_COLOR" :
|
|
183
|
+
util_style_env_nonempty("NODE_DISABLE_COLORS") ? "NODE_DISABLE_COLORS" : NULL;
|
|
184
|
+
if (enabled && disabled && !warned) {
|
|
185
|
+
ScrJsonBuf message;
|
|
186
|
+
scr_jb_init(&message);
|
|
187
|
+
scr_jb_puts(&message, "The '"); scr_jb_puts(&message, disabled);
|
|
188
|
+
scr_jb_puts(&message, "' env is ignored due to the 'FORCE_COLOR' env being set.");
|
|
189
|
+
ScrStr *text = scr_jb_finish(&message);
|
|
190
|
+
scr_emit_warning("Warning", NULL, text);
|
|
191
|
+
scr_str_release(text); warned = true;
|
|
192
|
+
}
|
|
193
|
+
return enabled;
|
|
194
|
+
}
|
|
195
|
+
const char *term = getenv("TERM");
|
|
196
|
+
if (util_style_env_nonempty("NO_COLOR") || util_style_env_nonempty("NODE_DISABLE_COLORS") ||
|
|
197
|
+
(term && !strcmp(term, "dumb"))) return false;
|
|
198
|
+
#ifdef _WIN32
|
|
199
|
+
return true;
|
|
200
|
+
#endif
|
|
201
|
+
if (util_style_env_nonempty("TMUX")) return true;
|
|
202
|
+
if (getenv("TF_BUILD") && getenv("AGENT_NAME")) return true;
|
|
203
|
+
if (getenv("CI")) {
|
|
204
|
+
static const char *const ci[] = { "APPVEYOR", "BUILDKITE", "CIRCLECI", "DRONE", "GITEA_ACTIONS", "GITHUB_ACTIONS", "GITLAB_CI", "TRAVIS" };
|
|
205
|
+
for (size_t i = 0; i < sizeof ci / sizeof ci[0]; i++) if (getenv(ci[i])) return true;
|
|
206
|
+
const char *name = getenv("CI_NAME");
|
|
207
|
+
return name && !strcmp(name, "codeship");
|
|
208
|
+
}
|
|
209
|
+
const char *teamcity = getenv("TEAMCITY_VERSION");
|
|
210
|
+
if (teamcity) {
|
|
211
|
+
const char *p = teamcity;
|
|
212
|
+
if (!strncmp(p, "9.", 2)) {
|
|
213
|
+
p += 2; while (*p == '0') p++;
|
|
214
|
+
if (*p < '1' || *p > '9') return false;
|
|
215
|
+
while (*p >= '0' && *p <= '9') p++;
|
|
216
|
+
return *p == '.';
|
|
217
|
+
}
|
|
218
|
+
while (*p >= '0' && *p <= '9') p++;
|
|
219
|
+
return p - teamcity >= 2 && *p == '.';
|
|
220
|
+
}
|
|
221
|
+
const char *program = getenv("TERM_PROGRAM");
|
|
222
|
+
if (program && (!strcmp(program, "iTerm.app") || !strcmp(program, "HyperTerm") ||
|
|
223
|
+
!strcmp(program, "MacTerm") || !strcmp(program, "Apple_Terminal"))) return true;
|
|
224
|
+
const char *colorterm = getenv("COLORTERM");
|
|
225
|
+
if (colorterm && (!strcmp(colorterm, "truecolor") || !strcmp(colorterm, "24bit"))) return true;
|
|
226
|
+
if (term) {
|
|
227
|
+
if (strstr(term, "truecolor") || !strncmp(term, "xterm-256", 9)) return true;
|
|
228
|
+
char *lower = malloc(strlen(term) + 1);
|
|
229
|
+
if (!lower) abort();
|
|
230
|
+
for (size_t i = 0; i <= strlen(term); i++) lower[i] = term[i] >= 'A' && term[i] <= 'Z' ? term[i] + ('a' - 'A') : term[i];
|
|
231
|
+
static const char *const terminals[] = { "eterm", "cons25", "console", "cygwin", "dtterm", "gnome", "hurd", "jfbterm", "konsole", "kterm", "mlterm", "mosh", "putty", "st", "rxvt-unicode-24bit", "terminator", "xterm-kitty" };
|
|
232
|
+
bool found = false;
|
|
233
|
+
for (size_t i = 0; i < sizeof terminals / sizeof terminals[0]; i++) found |= !strcmp(lower, terminals[i]);
|
|
234
|
+
found |= strstr(lower, "ansi") || strstr(lower, "color") || strstr(lower, "linux") || strstr(lower, "direct") ||
|
|
235
|
+
!strncmp(lower, "rxvt", 4) || !strncmp(lower, "screen", 6) || !strncmp(lower, "xterm", 5) ||
|
|
236
|
+
!strncmp(lower, "vt100", 5) || !strncmp(lower, "vt220", 5);
|
|
237
|
+
if (!strncmp(lower, "con", 3)) {
|
|
238
|
+
const char *p = lower + 3;
|
|
239
|
+
while (*p >= '0' && *p <= '9') p++;
|
|
240
|
+
if (*p == 'x' && p[1] >= '0' && p[1] <= '9') found = true;
|
|
241
|
+
}
|
|
242
|
+
free(lower);
|
|
243
|
+
if (found) return true;
|
|
244
|
+
}
|
|
245
|
+
return colorterm && *colorterm;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
ScrStr *scr_util_style_text(const ScrDyn *format, const ScrDyn *text, const ScrDyn *options) {
|
|
249
|
+
ScrDyn *validate = util_style_member(options, "validateStream");
|
|
250
|
+
if (!validate) return NULL;
|
|
251
|
+
if (validate->kind == SCR_DYN_UNDEF || validate->kind == SCR_DYN_NULL) {
|
|
252
|
+
scr_dyn_release(validate); validate = scr_dyn_new_bool(true);
|
|
253
|
+
}
|
|
254
|
+
const ScrTextStyle *fast = NULL;
|
|
255
|
+
if (!scr_dyn_truthy(validate) && format->kind == SCR_DYN_STR && text->kind == SCR_DYN_STR) {
|
|
256
|
+
if (util_style_none(format)) { scr_dyn_release(validate); return scr_str_retain(text->v.str); }
|
|
257
|
+
fast = util_style_lookup(format);
|
|
258
|
+
}
|
|
259
|
+
bool colorize = true;
|
|
260
|
+
ScrDyn *view = NULL, *stream = NULL;
|
|
261
|
+
ScrStr *result = NULL, *processed = NULL;
|
|
262
|
+
if (!fast) {
|
|
263
|
+
if (text->kind != SCR_DYN_STR) { scr_dyn_arg_type_fail("text", "of type string", text); goto done; }
|
|
264
|
+
view = util_style_view(options);
|
|
265
|
+
if (!view) goto done;
|
|
266
|
+
if (view->kind != SCR_DYN_UNDEF && view->kind != SCR_DYN_OBJ) {
|
|
267
|
+
scr_dyn_arg_type_fail("options", "of type object", view); goto done;
|
|
268
|
+
}
|
|
269
|
+
if (validate->kind != SCR_DYN_BOOL) {
|
|
270
|
+
scr_dyn_prop_type_fail("options.validateStream", "of type boolean", validate); goto done;
|
|
271
|
+
}
|
|
272
|
+
if (validate->v.b) {
|
|
273
|
+
stream = util_style_member(options, "stream");
|
|
274
|
+
if (!stream) goto done;
|
|
275
|
+
if (stream->kind == SCR_DYN_TYPED_REF && !strncmp(stream->v.typed_ref.type_key, "record:", 7)) {
|
|
276
|
+
ScrDyn *native = util_style_view(stream);
|
|
277
|
+
scr_dyn_release(stream); stream = native;
|
|
278
|
+
if (!stream) goto done;
|
|
279
|
+
}
|
|
280
|
+
double fd = 1;
|
|
281
|
+
if (stream->kind != SCR_DYN_UNDEF && stream->kind != SCR_DYN_NULL) {
|
|
282
|
+
if (stream->kind == SCR_DYN_HANDLE && stream->v.handle.tag == SCR_DYNH_STDIO) {
|
|
283
|
+
ScrStr *key = scr_str_new("fd", 2);
|
|
284
|
+
ScrDyn *value = scr_dyn_handle_key_get(stream, key);
|
|
285
|
+
scr_str_release(key);
|
|
286
|
+
if (!value) goto done;
|
|
287
|
+
fd = value->v.num; scr_dyn_release(value);
|
|
288
|
+
} else if (stream->kind == SCR_DYN_HANDLE || stream->kind == SCR_DYN_TYPED_REF ||
|
|
289
|
+
(stream->kind == SCR_DYN_OBJ && util_style_custom_stream(stream))) {
|
|
290
|
+
static const char message[] = "util.styleText over native custom streams is not supported yet";
|
|
291
|
+
scr_throw_error_msg_code(SCR_ERR_TYPE, message, sizeof message - 1, "SC2020"); goto done;
|
|
292
|
+
} else {
|
|
293
|
+
if (scr_exc_pending()) goto done;
|
|
294
|
+
scr_dyn_arg_type_fail("stream", "an instance of ReadableStream, WritableStream, or Stream", stream); goto done;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
colorize = getenv("FORCE_COLOR") ? util_style_terminal_colors() :
|
|
298
|
+
scr_process_is_tty(fd) && util_style_terminal_colors();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
scr_dyn_release(view); view = util_style_view(format);
|
|
302
|
+
if (!view) goto done;
|
|
303
|
+
processed = scr_str_retain(text->v.str);
|
|
304
|
+
ScrJsonBuf opens, closes;
|
|
305
|
+
scr_jb_init(&opens); scr_jb_init(&closes);
|
|
306
|
+
size_t count = view->kind == SCR_DYN_ARR ? view->v.arr.len : 1;
|
|
307
|
+
for (size_t i = 0; i < count; i++) {
|
|
308
|
+
const ScrDyn *key = view->kind == SCR_DYN_ARR ? view->v.arr.items[i] : view;
|
|
309
|
+
if (util_style_none(key)) continue;
|
|
310
|
+
const ScrTextStyle *style = util_style_lookup(key);
|
|
311
|
+
if (!style) {
|
|
312
|
+
if (!scr_exc_pending()) util_style_invalid(key);
|
|
313
|
+
scr_str_release(scr_jb_finish(&opens)); scr_str_release(scr_jb_finish(&closes)); goto done;
|
|
314
|
+
}
|
|
315
|
+
char open[16], close[16];
|
|
316
|
+
snprintf(open, sizeof open, "\x1b[%um", style->open);
|
|
317
|
+
snprintf(close, sizeof close, "\x1b[%um", style->close);
|
|
318
|
+
scr_jb_puts(&opens, open);
|
|
319
|
+
size_t n = strlen(close);
|
|
320
|
+
scr_jb_puts(&closes, close);
|
|
321
|
+
/* Prepend each closing sequence so the outer formats close last. */
|
|
322
|
+
memmove(closes.data + n, closes.data, closes.len - n);
|
|
323
|
+
memcpy(closes.data, close, n);
|
|
324
|
+
ScrStr *next = util_style_replace(processed, close, open, style->open == 1 || style->open == 2);
|
|
325
|
+
scr_str_release(processed); processed = next;
|
|
326
|
+
}
|
|
327
|
+
if (colorize) {
|
|
328
|
+
scr_jb_put_str(&opens, processed);
|
|
329
|
+
util_style_putn(&opens, closes.data, closes.len);
|
|
330
|
+
result = scr_jb_finish(&opens);
|
|
331
|
+
} else { scr_str_release(scr_jb_finish(&opens)); result = scr_str_retain(text->v.str); }
|
|
332
|
+
scr_str_release(scr_jb_finish(&closes));
|
|
333
|
+
done:
|
|
334
|
+
scr_dyn_release(validate); scr_dyn_release(view); scr_dyn_release(stream);
|
|
335
|
+
scr_str_release(processed);
|
|
336
|
+
return result;
|
|
337
|
+
}
|