@scriptc/cli-darwin-arm64 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-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_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_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_url.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_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_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_url.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_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_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_regex.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/text-decoder-legacy/scr_bytes.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_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_regex.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/text-decoder-legacy/scr_bytes.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_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_regex.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/text-decoder-legacy/scr_bytes.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_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_regex.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/text-decoder-legacy/scr_bytes.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_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_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_url.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_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_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_url.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 +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
|
@@ -62,43 +62,77 @@ static const char web_prelude[] =
|
|
|
62
62
|
" * (host.setTimer/host.clearTimer) — REF'd like Node's (an armed\n"
|
|
63
63
|
" * timer keeps the process alive), FIFO-ordered against static\n"
|
|
64
64
|
" * timers on one heap, Node's <1ms clamp. Returns a Timeout-shaped\n"
|
|
65
|
-
" * object
|
|
66
|
-
" *
|
|
67
|
-
"
|
|
68
|
-
" * approximation). */\n"
|
|
65
|
+
" * object with real ref/unref/refresh/close operations. Immediates\n"
|
|
66
|
+
" * use the native check queue, independently of timer ids. */\n"
|
|
67
|
+
" const timers = new Map();\n"
|
|
69
68
|
" class Timeout {\n"
|
|
70
|
-
" constructor(fn, delay, repeat) {\n"
|
|
69
|
+
" constructor(fn, delay, args, repeat) {\n"
|
|
71
70
|
" this._fn = fn;\n"
|
|
72
71
|
" this._delay = delay;\n"
|
|
72
|
+
" this._args = args;\n"
|
|
73
73
|
" this._repeat = repeat;\n"
|
|
74
|
-
" this.
|
|
74
|
+
" this._reffed = true;\n"
|
|
75
|
+
" this._closed = false;\n"
|
|
76
|
+
" this._callback = () => {\n"
|
|
77
|
+
" if (!this._repeat) { this._destroyed = true; timers.delete(this._id); }\n"
|
|
78
|
+
" this._fn.apply(this, this._args);\n"
|
|
79
|
+
" };\n"
|
|
80
|
+
" this._arm();\n"
|
|
75
81
|
" }\n"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
82
|
+
" _arm() {\n"
|
|
83
|
+
" this._destroyed = false;\n"
|
|
84
|
+
" this._id = host.setTimer(this._callback, this._delay, this._repeat, false);\n"
|
|
85
|
+
" timers.set(this._id, this);\n"
|
|
86
|
+
" if (!this._reffed) host.refTimer(this._id, false, false);\n"
|
|
87
|
+
" }\n"
|
|
88
|
+
" ref() { this._reffed = true; host.refTimer(this._id, true, false); return this; }\n"
|
|
89
|
+
" unref() { this._reffed = false; host.refTimer(this._id, false, false); return this; }\n"
|
|
90
|
+
" hasRef() { return this._reffed; }\n"
|
|
79
91
|
" refresh() {\n"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
92
|
+
" if (this._closed) return this;\n"
|
|
93
|
+
" if (this._destroyed) this._arm();\n"
|
|
94
|
+
" else host.refreshTimer(this._id);\n"
|
|
82
95
|
" return this;\n"
|
|
83
96
|
" }\n"
|
|
84
|
-
" close() { host.clearTimer(this._id); return this; }\n"
|
|
97
|
+
" close() { this._closed = true; this._destroyed = true; timers.delete(this._id); host.clearTimer(this._id, false); return this; }\n"
|
|
98
|
+
" [Symbol.dispose]() { this.close(); }\n"
|
|
85
99
|
" [Symbol.toPrimitive]() { return this._id; }\n"
|
|
86
100
|
" }\n"
|
|
87
101
|
" const mkTimer = (fn, ms, args, repeat) => {\n"
|
|
88
102
|
" if (typeof fn !== 'function') {\n"
|
|
89
103
|
" throw new TypeError('The \"callback\" argument must be of type function. Received type ' + typeof fn);\n"
|
|
90
104
|
" }\n"
|
|
91
|
-
"
|
|
92
|
-
" return new Timeout(cb, Number(ms), repeat);\n"
|
|
105
|
+
" return new Timeout(fn, Number(ms), args, repeat);\n"
|
|
93
106
|
" };\n"
|
|
94
107
|
" g.setTimeout = (fn, ms, ...args) => mkTimer(fn, ms, args, false);\n"
|
|
95
108
|
" g.setInterval = (fn, ms, ...args) => mkTimer(fn, ms, args, true);\n"
|
|
96
109
|
" g.clearTimeout = (t) => {\n"
|
|
97
110
|
" if (t === undefined || t === null) return;\n"
|
|
98
111
|
" const id = typeof t === 'number' ? t : Number(t);\n"
|
|
99
|
-
" if (Number.isFinite(id))
|
|
112
|
+
" if (Number.isFinite(id)) {\n"
|
|
113
|
+
" const timer = timers.get(id);\n"
|
|
114
|
+
" if (timer) timer.close(); else host.clearTimer(id, false);\n"
|
|
115
|
+
" }\n"
|
|
100
116
|
" };\n"
|
|
101
117
|
" g.clearInterval = g.clearTimeout;\n"
|
|
118
|
+
" class Immediate {\n"
|
|
119
|
+
" constructor(fn, args) {\n"
|
|
120
|
+
" this._reffed = true; this._destroyed = false;\n"
|
|
121
|
+
" this._id = host.setTimer(() => {\n"
|
|
122
|
+
" this._destroyed = true; this._reffed = false; fn.apply(this, args);\n"
|
|
123
|
+
" }, 0, false, true);\n"
|
|
124
|
+
" }\n"
|
|
125
|
+
" ref() { if (!this._destroyed) { this._reffed = true; host.refTimer(this._id, true, true); } return this; }\n"
|
|
126
|
+
" unref() { if (!this._destroyed) { this._reffed = false; host.refTimer(this._id, false, true); } return this; }\n"
|
|
127
|
+
" hasRef() { return this._reffed; }\n"
|
|
128
|
+
" _close() { this._destroyed = true; this._reffed = false; host.clearTimer(this._id, true); }\n"
|
|
129
|
+
" [Symbol.dispose]() { this._close(); }\n"
|
|
130
|
+
" }\n"
|
|
131
|
+
" g.setImmediate = (fn, ...args) => {\n"
|
|
132
|
+
" if (typeof fn !== 'function') throw new TypeError('The \"callback\" argument must be of type function. Received type ' + typeof fn);\n"
|
|
133
|
+
" return new Immediate(fn, args);\n"
|
|
134
|
+
" };\n"
|
|
135
|
+
" g.clearImmediate = (immediate) => { if (immediate instanceof Immediate) immediate._close(); };\n"
|
|
102
136
|
"\n"
|
|
103
137
|
" class ReadableStream {\n"
|
|
104
138
|
" constructor(source, _strategy) {\n"
|
|
@@ -503,8 +537,41 @@ static const char web_prelude[] =
|
|
|
503
537
|
" g.TransformStream = TransformStream;\n"
|
|
504
538
|
"\n"
|
|
505
539
|
"\n"
|
|
540
|
+
" const textEncoders = new WeakSet();\n"
|
|
506
541
|
" class TextEncoder {\n"
|
|
542
|
+
" constructor() { textEncoders.add(this); }\n"
|
|
507
543
|
" get encoding() { return 'utf-8'; }\n"
|
|
544
|
+
" encodeInto(src, dest) {\n"
|
|
545
|
+
" const fail = (name, expected, value) => {\n"
|
|
546
|
+
" let received;\n"
|
|
547
|
+
" if (value === null || value === undefined) received = String(value);\n"
|
|
548
|
+
" else if (typeof value === 'object' || typeof value === 'function') received = 'an instance of ' + (value.constructor && value.constructor.name || 'Object');\n"
|
|
549
|
+
" else if (typeof value === 'string') received = \"type string ('\" + value + \"')\";\n"
|
|
550
|
+
" else received = 'type ' + typeof value + ' (' + String(value) + (typeof value === 'bigint' ? 'n' : '') + ')';\n"
|
|
551
|
+
" const error = new TypeError('The \"' + name + '\" argument must be ' + expected + '. Received ' + received);\n"
|
|
552
|
+
" error.code = 'ERR_INVALID_ARG_TYPE'; throw error;\n"
|
|
553
|
+
" };\n"
|
|
554
|
+
" if (!textEncoders.has(this)) { const error = new TypeError('Value of \"this\" must be of type TextEncoder'); error.code = 'ERR_INVALID_THIS'; throw error; }\n"
|
|
555
|
+
" if (typeof src !== 'string') fail('src', 'of type string', src);\n"
|
|
556
|
+
" if (!(dest instanceof Uint8Array)) fail('dest', 'an instance of Uint8Array', dest);\n"
|
|
557
|
+
" let read = 0, written = 0;\n"
|
|
558
|
+
" while (read < src.length) {\n"
|
|
559
|
+
" let cp = src.charCodeAt(read), units = 1;\n"
|
|
560
|
+
" if (cp >= 0xd800 && cp <= 0xdbff) {\n"
|
|
561
|
+
" const low = src.charCodeAt(read + 1);\n"
|
|
562
|
+
" if (low >= 0xdc00 && low <= 0xdfff) { cp = 0x10000 + ((cp - 0xd800) << 10) + low - 0xdc00; units = 2; }\n"
|
|
563
|
+
" else cp = 0xfffd;\n"
|
|
564
|
+
" } else if (cp >= 0xdc00 && cp <= 0xdfff) cp = 0xfffd;\n"
|
|
565
|
+
" const size = cp < 0x80 ? 1 : cp < 0x800 ? 2 : cp < 0x10000 ? 3 : 4;\n"
|
|
566
|
+
" if (written + size > dest.length) break;\n"
|
|
567
|
+
" if (size === 1) dest[written++] = cp;\n"
|
|
568
|
+
" else if (size === 2) { dest[written++] = 0xc0 | (cp >> 6); dest[written++] = 0x80 | (cp & 63); }\n"
|
|
569
|
+
" else if (size === 3) { dest[written++] = 0xe0 | (cp >> 12); dest[written++] = 0x80 | ((cp >> 6) & 63); dest[written++] = 0x80 | (cp & 63); }\n"
|
|
570
|
+
" else { dest[written++] = 0xf0 | (cp >> 18); dest[written++] = 0x80 | ((cp >> 12) & 63); dest[written++] = 0x80 | ((cp >> 6) & 63); dest[written++] = 0x80 | (cp & 63); }\n"
|
|
571
|
+
" read += units;\n"
|
|
572
|
+
" }\n"
|
|
573
|
+
" return { read, written };\n"
|
|
574
|
+
" }\n"
|
|
508
575
|
" encode(input) {\n"
|
|
509
576
|
" const s = input === undefined ? '' : String(input);\n"
|
|
510
577
|
" const bytes = [];\n"
|
|
@@ -891,13 +958,14 @@ static const char web_prelude[] =
|
|
|
891
958
|
" const once = !!(options !== null && typeof options === 'object' && options.once);\n"
|
|
892
959
|
" const list = this._et[t] || (this._et[t] = []);\n"
|
|
893
960
|
" for (const e of list) { if (e.listener === listener) return; }\n"
|
|
894
|
-
"
|
|
961
|
+
" const resistant = !!(options && options[Symbol.for('scriptc.events.resistStopPropagation')]);\n"
|
|
962
|
+
" list.push({ listener, once, resistant });\n"
|
|
895
963
|
" }\n"
|
|
896
964
|
" removeEventListener(type, listener) {\n"
|
|
897
965
|
" const list = this._et[String(type)];\n"
|
|
898
966
|
" if (!list) return;\n"
|
|
899
967
|
" const i = list.findIndex((e) => e.listener === listener);\n"
|
|
900
|
-
" if (i >= 0) list.splice(i, 1);\n"
|
|
968
|
+
" if (i >= 0) list.splice(i, 1)[0].removed = true;\n"
|
|
901
969
|
" }\n"
|
|
902
970
|
" dispatchEvent(event) {\n"
|
|
903
971
|
" if (!(event instanceof Event)) throw new TypeError('The \"event\" argument must be an instance of Event.');\n"
|
|
@@ -907,7 +975,8 @@ static const char web_prelude[] =
|
|
|
907
975
|
" const list = this._et[event.type];\n"
|
|
908
976
|
" if (list) {\n"
|
|
909
977
|
" for (const e of [...list]) {\n"
|
|
910
|
-
" if (
|
|
978
|
+
" if (e.removed) continue;\n"
|
|
979
|
+
" if (event._stopImmediate && !e.resistant) continue;\n"
|
|
911
980
|
" if (e.once) this.removeEventListener(event.type, e.listener);\n"
|
|
912
981
|
" if (typeof e.listener === 'function') e.listener.call(this, event);\n"
|
|
913
982
|
" else if (e.listener !== null && typeof e.listener.handleEvent === 'function') e.listener.handleEvent(event);\n"
|
|
@@ -1054,13 +1123,16 @@ static const char web_prelude[] =
|
|
|
1054
1123
|
" if (s._aborted) return;\n"
|
|
1055
1124
|
" s._aborted = true;\n"
|
|
1056
1125
|
" s._reason = reason === undefined ? mkAbortError() : reason;\n"
|
|
1057
|
-
" const ev =
|
|
1126
|
+
" const ev = new Event('abort');\n"
|
|
1127
|
+
" ev.target = s; ev.currentTarget = s; ev.eventPhase = Event.AT_TARGET; ev.isTrusted = true;\n"
|
|
1058
1128
|
" let firstErr;\n"
|
|
1059
1129
|
" let threw = false;\n"
|
|
1060
1130
|
" if (s._onabort !== null) {\n"
|
|
1061
1131
|
" try { s._onabort.call(s, ev); } catch (e) { firstErr = e; threw = true; }\n"
|
|
1062
1132
|
" }\n"
|
|
1063
1133
|
" for (const l of s._listeners.slice()) {\n"
|
|
1134
|
+
" if (l.removed) continue;\n"
|
|
1135
|
+
" if (ev._stopImmediate && !l.resistant) continue;\n"
|
|
1064
1136
|
" if (l.once) s.removeEventListener('abort', l.fn);\n"
|
|
1065
1137
|
" try { l.fn.call(s, ev); } catch (e) { if (!threw) { firstErr = e; threw = true; } }\n"
|
|
1066
1138
|
" }\n"
|
|
@@ -1076,13 +1148,15 @@ static const char web_prelude[] =
|
|
|
1076
1148
|
" throwIfAborted() { if (this._aborted) throw this._reason; }\n"
|
|
1077
1149
|
" addEventListener(type, fn, options) {\n"
|
|
1078
1150
|
" if (String(type) !== 'abort' || typeof fn !== 'function') return;\n"
|
|
1151
|
+
" if (this._listeners.some(l => l.fn === fn)) return;\n"
|
|
1079
1152
|
" const once = options !== undefined && options !== null && !!options.once;\n"
|
|
1080
|
-
"
|
|
1153
|
+
" const resistant = !!(options && options[Symbol.for('scriptc.events.resistStopPropagation')]);\n"
|
|
1154
|
+
" this._listeners.push({ fn, once, resistant });\n"
|
|
1081
1155
|
" }\n"
|
|
1082
1156
|
" removeEventListener(type, fn) {\n"
|
|
1083
1157
|
" if (String(type) !== 'abort') return;\n"
|
|
1084
1158
|
" const i = this._listeners.findIndex((l) => l.fn === fn);\n"
|
|
1085
|
-
" if (i >= 0) this._listeners.splice(i, 1);\n"
|
|
1159
|
+
" if (i >= 0) this._listeners.splice(i, 1)[0].removed = true;\n"
|
|
1086
1160
|
" }\n"
|
|
1087
1161
|
" static abort(reason) {\n"
|
|
1088
1162
|
" const s = mkSignal();\n"
|
|
@@ -1633,7 +1707,6 @@ static void web_timer_fire_cb(ScrClosure *env) {
|
|
|
1633
1707
|
static JSValue web_host_set_timer(JSContext *ctx, JSValueConst this_val,
|
|
1634
1708
|
int argc, JSValueConst *argv) {
|
|
1635
1709
|
(void)this_val;
|
|
1636
|
-
(void)argc;
|
|
1637
1710
|
double ms = 0;
|
|
1638
1711
|
if (JS_ToFloat64(ctx, &ms, argv[1])) return JS_EXCEPTION;
|
|
1639
1712
|
bool repeat = JS_ToBool(ctx, argv[2]) > 0;
|
|
@@ -1649,17 +1722,45 @@ static JSValue web_host_set_timer(JSContext *ctx, JSValueConst this_val,
|
|
|
1649
1722
|
scr_box_set_ref(box, h); /* the box owns the +1 */
|
|
1650
1723
|
ScrClosure *cb = scr_closure_new((void *)web_timer_fire_cb, 1);
|
|
1651
1724
|
cb->caps[0] = box;
|
|
1652
|
-
|
|
1725
|
+
bool immediate = argc > 3 && JS_ToBool(ctx, argv[3]) > 0;
|
|
1726
|
+
double id = immediate ? scr_set_immediate(cb)
|
|
1727
|
+
: repeat ? scr_set_interval(cb, ms) : scr_set_timeout_handle(cb, ms);
|
|
1653
1728
|
return JS_NewFloat64(ctx, id);
|
|
1654
1729
|
}
|
|
1655
1730
|
|
|
1656
1731
|
static JSValue web_host_clear_timer(JSContext *ctx, JSValueConst this_val,
|
|
1657
1732
|
int argc, JSValueConst *argv) {
|
|
1658
1733
|
(void)this_val;
|
|
1734
|
+
double id = 0;
|
|
1735
|
+
if (JS_ToFloat64(ctx, &id, argv[0])) return JS_EXCEPTION;
|
|
1736
|
+
if (argc > 1 && JS_ToBool(ctx, argv[1]) > 0) scr_clear_immediate(id);
|
|
1737
|
+
else scr_clear_interval(id);
|
|
1738
|
+
return JS_UNDEFINED;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
static JSValue web_host_ref_timer(JSContext *ctx, JSValueConst this_val,
|
|
1742
|
+
int argc, JSValueConst *argv) {
|
|
1743
|
+
(void)this_val;
|
|
1744
|
+
(void)argc;
|
|
1745
|
+
double id = 0;
|
|
1746
|
+
if (JS_ToFloat64(ctx, &id, argv[0])) return JS_EXCEPTION;
|
|
1747
|
+
bool reffed = JS_ToBool(ctx, argv[1]) > 0;
|
|
1748
|
+
bool immediate = JS_ToBool(ctx, argv[2]) > 0;
|
|
1749
|
+
if (immediate) {
|
|
1750
|
+
if (reffed) scr_immediate_ref(id); else scr_immediate_unref(id);
|
|
1751
|
+
} else {
|
|
1752
|
+
if (reffed) scr_timer_ref(id); else scr_timer_unref(id);
|
|
1753
|
+
}
|
|
1754
|
+
return JS_UNDEFINED;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
static JSValue web_host_refresh_timer(JSContext *ctx, JSValueConst this_val,
|
|
1758
|
+
int argc, JSValueConst *argv) {
|
|
1759
|
+
(void)this_val;
|
|
1659
1760
|
(void)argc;
|
|
1660
1761
|
double id = 0;
|
|
1661
1762
|
if (JS_ToFloat64(ctx, &id, argv[0])) return JS_EXCEPTION;
|
|
1662
|
-
|
|
1763
|
+
scr_timer_refresh(id);
|
|
1663
1764
|
return JS_UNDEFINED;
|
|
1664
1765
|
}
|
|
1665
1766
|
|
|
@@ -1837,8 +1938,10 @@ void scr_island_web_boot(void *jsctx) {
|
|
|
1837
1938
|
JS_SetPropertyStr(ctx, host, "write", JS_NewCFunction(ctx, web_host_write, "write", 2));
|
|
1838
1939
|
JS_SetPropertyStr(ctx, host, "tzname", JS_NewCFunction(ctx, web_host_tzname, "tzname", 1));
|
|
1839
1940
|
JS_SetPropertyStr(ctx, host, "timer", JS_NewCFunction(ctx, web_host_timer, "timer", 2));
|
|
1840
|
-
JS_SetPropertyStr(ctx, host, "setTimer", JS_NewCFunction(ctx, web_host_set_timer, "setTimer",
|
|
1841
|
-
JS_SetPropertyStr(ctx, host, "clearTimer", JS_NewCFunction(ctx, web_host_clear_timer, "clearTimer",
|
|
1941
|
+
JS_SetPropertyStr(ctx, host, "setTimer", JS_NewCFunction(ctx, web_host_set_timer, "setTimer", 4));
|
|
1942
|
+
JS_SetPropertyStr(ctx, host, "clearTimer", JS_NewCFunction(ctx, web_host_clear_timer, "clearTimer", 2));
|
|
1943
|
+
JS_SetPropertyStr(ctx, host, "refTimer", JS_NewCFunction(ctx, web_host_ref_timer, "refTimer", 3));
|
|
1944
|
+
JS_SetPropertyStr(ctx, host, "refreshTimer", JS_NewCFunction(ctx, web_host_refresh_timer, "refreshTimer", 1));
|
|
1842
1945
|
JSValue r = JS_Call(ctx, fn, JS_UNDEFINED, 1, (JSValueConst *)&host);
|
|
1843
1946
|
JS_FreeValue(ctx, host);
|
|
1844
1947
|
JS_FreeValue(ctx, fn);
|