@zappdev/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/README.md +55 -0
  2. package/dist/zapp-cli.js +9471 -0
  3. package/native/src/app/app.zc +490 -0
  4. package/native/src/event/event.zc +24 -0
  5. package/native/src/event/events.zc +70 -0
  6. package/native/src/platform/darwin/backend.zc +923 -0
  7. package/native/src/platform/darwin/backend_bootstrap.zc +9 -0
  8. package/native/src/platform/darwin/bootstrap.zc +9 -0
  9. package/native/src/platform/darwin/engine_jsc.zc +86 -0
  10. package/native/src/platform/darwin/engine_qjs.zc +92 -0
  11. package/native/src/platform/darwin/platform.zc +156 -0
  12. package/native/src/platform/darwin/webview.zc +550 -0
  13. package/native/src/platform/darwin/webview_bootstrap.zc +9 -0
  14. package/native/src/platform/darwin/window.zc +1223 -0
  15. package/native/src/platform/darwin/worker/common.zc +223 -0
  16. package/native/src/platform/darwin/worker/core/base64_core.zc +29 -0
  17. package/native/src/platform/darwin/worker/core/crypto_core.zc +19 -0
  18. package/native/src/platform/darwin/worker/core/encoding_core.zc +32 -0
  19. package/native/src/platform/darwin/worker/core/fetch_core.zc +145 -0
  20. package/native/src/platform/darwin/worker/core/url_core.zc +69 -0
  21. package/native/src/platform/darwin/worker/core/websocket_core.zc +179 -0
  22. package/native/src/platform/darwin/worker/dispatch.zc +55 -0
  23. package/native/src/platform/darwin/worker/jsc/base64_jsc.zc +39 -0
  24. package/native/src/platform/darwin/worker/jsc/crypto_jsc.zc +49 -0
  25. package/native/src/platform/darwin/worker/jsc/encoding_jsc.zc +86 -0
  26. package/native/src/platform/darwin/worker/jsc/fetch_jsc.zc +149 -0
  27. package/native/src/platform/darwin/worker/jsc/url_jsc.zc +54 -0
  28. package/native/src/platform/darwin/worker/jsc/websocket_jsc.zc +127 -0
  29. package/native/src/platform/darwin/worker/jsc.zc +670 -0
  30. package/native/src/platform/darwin/worker/mod.zc +30 -0
  31. package/native/src/platform/darwin/worker/qjs/fetch_qjs.zc +233 -0
  32. package/native/src/platform/darwin/worker/qjs/qjs_macros.zc +23 -0
  33. package/native/src/platform/darwin/worker/qjs/websocket_qjs.zc +223 -0
  34. package/native/src/platform/darwin/worker/qjs.zc +1053 -0
  35. package/native/src/platform/darwin/worker/timers.zc +149 -0
  36. package/native/src/platform/darwin/worker/timers_qjs.zc +209 -0
  37. package/native/src/platform/platform.zc +64 -0
  38. package/native/src/platform/shared/log.zc +156 -0
  39. package/native/src/platform/shared/worker/qjs/base64_qjs.zc +38 -0
  40. package/native/src/platform/shared/worker/qjs/crypto_qjs.zc +44 -0
  41. package/native/src/platform/shared/worker/qjs/encoding_qjs.zc +95 -0
  42. package/native/src/platform/shared/worker/qjs/url_qjs.zc +65 -0
  43. package/native/src/platform/shared/worker_registry.zc +206 -0
  44. package/native/src/platform/window.zc +446 -0
  45. package/native/src/platform/windows/backend.zc +452 -0
  46. package/native/src/platform/windows/backend_bootstrap.zc +9 -0
  47. package/native/src/platform/windows/bootstrap.zc +9 -0
  48. package/native/src/platform/windows/engine_qjs.zc +60 -0
  49. package/native/src/platform/windows/platform.zc +387 -0
  50. package/native/src/platform/windows/webview.zc +1175 -0
  51. package/native/src/platform/windows/webview_bootstrap.zc +9 -0
  52. package/native/src/platform/windows/window.zc +1271 -0
  53. package/native/src/platform/windows/worker/common.zc +409 -0
  54. package/native/src/platform/windows/worker/core/base64_core.zc +52 -0
  55. package/native/src/platform/windows/worker/core/crypto_core.zc +34 -0
  56. package/native/src/platform/windows/worker/core/encoding_core.zc +60 -0
  57. package/native/src/platform/windows/worker/core/fetch_core.zc +274 -0
  58. package/native/src/platform/windows/worker/core/url_core.zc +216 -0
  59. package/native/src/platform/windows/worker/core/websocket_core.zc +343 -0
  60. package/native/src/platform/windows/worker/dispatch.zc +34 -0
  61. package/native/src/platform/windows/worker/mod.zc +46 -0
  62. package/native/src/platform/windows/worker/qjs/fetch_qjs.zc +255 -0
  63. package/native/src/platform/windows/worker/qjs/websocket_qjs.zc +263 -0
  64. package/native/src/platform/windows/worker/qjs.zc +1049 -0
  65. package/native/src/platform/windows/worker/timers_qjs.zc +288 -0
  66. package/native/src/platform/worker.zc +8 -0
  67. package/native/src/service/service.zc +228 -0
  68. package/native/vendor/quickjs-ng/.gitattributes +4 -0
  69. package/native/vendor/quickjs-ng/.github/dependabot.yml +7 -0
  70. package/native/vendor/quickjs-ng/.github/workflows/ci.yml +812 -0
  71. package/native/vendor/quickjs-ng/.github/workflows/docs.yml +49 -0
  72. package/native/vendor/quickjs-ng/.github/workflows/release.yml +162 -0
  73. package/native/vendor/quickjs-ng/.github/workflows/test-docs.yml +23 -0
  74. package/native/vendor/quickjs-ng/.github/workflows/tsan.yml +32 -0
  75. package/native/vendor/quickjs-ng/.github/workflows/valgrind.yml +33 -0
  76. package/native/vendor/quickjs-ng/.gitmodules +5 -0
  77. package/native/vendor/quickjs-ng/CMakeLists.txt +553 -0
  78. package/native/vendor/quickjs-ng/LICENSE +24 -0
  79. package/native/vendor/quickjs-ng/Makefile +149 -0
  80. package/native/vendor/quickjs-ng/amalgam.js +53 -0
  81. package/native/vendor/quickjs-ng/api-test.c +927 -0
  82. package/native/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
  83. package/native/vendor/quickjs-ng/builtin-array-fromasync.js +36 -0
  84. package/native/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
  85. package/native/vendor/quickjs-ng/builtin-iterator-zip-keyed.js +194 -0
  86. package/native/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
  87. package/native/vendor/quickjs-ng/builtin-iterator-zip.js +210 -0
  88. package/native/vendor/quickjs-ng/ctest.c +17 -0
  89. package/native/vendor/quickjs-ng/cutils.h +2013 -0
  90. package/native/vendor/quickjs-ng/cxxtest.cc +2 -0
  91. package/native/vendor/quickjs-ng/dtoa.c +1619 -0
  92. package/native/vendor/quickjs-ng/dtoa.h +87 -0
  93. package/native/vendor/quickjs-ng/examples/fib.c +67 -0
  94. package/native/vendor/quickjs-ng/examples/fib_module.js +10 -0
  95. package/native/vendor/quickjs-ng/examples/hello.js +1 -0
  96. package/native/vendor/quickjs-ng/examples/hello_module.js +6 -0
  97. package/native/vendor/quickjs-ng/examples/meson.build +17 -0
  98. package/native/vendor/quickjs-ng/examples/pi_bigint.js +118 -0
  99. package/native/vendor/quickjs-ng/examples/point.c +154 -0
  100. package/native/vendor/quickjs-ng/examples/test_fib.js +8 -0
  101. package/native/vendor/quickjs-ng/examples/test_point.js +43 -0
  102. package/native/vendor/quickjs-ng/fuzz.c +51 -0
  103. package/native/vendor/quickjs-ng/gen/function_source.c +81 -0
  104. package/native/vendor/quickjs-ng/gen/hello.c +53 -0
  105. package/native/vendor/quickjs-ng/gen/hello_module.c +106 -0
  106. package/native/vendor/quickjs-ng/gen/repl.c +3053 -0
  107. package/native/vendor/quickjs-ng/gen/standalone.c +324 -0
  108. package/native/vendor/quickjs-ng/gen/test_fib.c +81 -0
  109. package/native/vendor/quickjs-ng/libregexp-opcode.h +58 -0
  110. package/native/vendor/quickjs-ng/libregexp.c +2687 -0
  111. package/native/vendor/quickjs-ng/libregexp.h +98 -0
  112. package/native/vendor/quickjs-ng/libunicode-table.h +4707 -0
  113. package/native/vendor/quickjs-ng/libunicode.c +1746 -0
  114. package/native/vendor/quickjs-ng/libunicode.h +126 -0
  115. package/native/vendor/quickjs-ng/list.h +107 -0
  116. package/native/vendor/quickjs-ng/lre-test.c +73 -0
  117. package/native/vendor/quickjs-ng/meson.build +684 -0
  118. package/native/vendor/quickjs-ng/meson_options.txt +6 -0
  119. package/native/vendor/quickjs-ng/qjs-wasi-reactor.c +208 -0
  120. package/native/vendor/quickjs-ng/qjs.c +748 -0
  121. package/native/vendor/quickjs-ng/qjsc.c +673 -0
  122. package/native/vendor/quickjs-ng/quickjs-atom.h +267 -0
  123. package/native/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
  124. package/native/vendor/quickjs-ng/quickjs-libc.c +4986 -0
  125. package/native/vendor/quickjs-ng/quickjs-libc.h +79 -0
  126. package/native/vendor/quickjs-ng/quickjs-opcode.h +369 -0
  127. package/native/vendor/quickjs-ng/quickjs.c +60259 -0
  128. package/native/vendor/quickjs-ng/quickjs.h +1419 -0
  129. package/native/vendor/quickjs-ng/repl.js +1927 -0
  130. package/native/vendor/quickjs-ng/run-test262.c +2417 -0
  131. package/native/vendor/quickjs-ng/standalone.js +129 -0
  132. package/native/vendor/quickjs-ng/tests/assert.js +49 -0
  133. package/native/vendor/quickjs-ng/tests/bug1221.js +16 -0
  134. package/native/vendor/quickjs-ng/tests/bug1296.js +12 -0
  135. package/native/vendor/quickjs-ng/tests/bug1297.js +22 -0
  136. package/native/vendor/quickjs-ng/tests/bug1301.js +21 -0
  137. package/native/vendor/quickjs-ng/tests/bug1302.js +24 -0
  138. package/native/vendor/quickjs-ng/tests/bug1305.js +26 -0
  139. package/native/vendor/quickjs-ng/tests/bug1318.js +54 -0
  140. package/native/vendor/quickjs-ng/tests/bug1352.js +8 -0
  141. package/native/vendor/quickjs-ng/tests/bug1354.js +6 -0
  142. package/native/vendor/quickjs-ng/tests/bug1355.js +58 -0
  143. package/native/vendor/quickjs-ng/tests/bug1368.js +9 -0
  144. package/native/vendor/quickjs-ng/tests/bug39/1.js +6 -0
  145. package/native/vendor/quickjs-ng/tests/bug39/2.js +6 -0
  146. package/native/vendor/quickjs-ng/tests/bug39/3.js +7 -0
  147. package/native/vendor/quickjs-ng/tests/bug488-upstream.js +7 -0
  148. package/native/vendor/quickjs-ng/tests/bug633/0.js +7 -0
  149. package/native/vendor/quickjs-ng/tests/bug633/1.js +4 -0
  150. package/native/vendor/quickjs-ng/tests/bug633/2.js +4 -0
  151. package/native/vendor/quickjs-ng/tests/bug633/3.js +4 -0
  152. package/native/vendor/quickjs-ng/tests/bug645/0.js +4 -0
  153. package/native/vendor/quickjs-ng/tests/bug645/1.js +9 -0
  154. package/native/vendor/quickjs-ng/tests/bug645/2.js +7 -0
  155. package/native/vendor/quickjs-ng/tests/bug648.js +13 -0
  156. package/native/vendor/quickjs-ng/tests/bug652.js +4 -0
  157. package/native/vendor/quickjs-ng/tests/bug741.js +19 -0
  158. package/native/vendor/quickjs-ng/tests/bug775.js +7 -0
  159. package/native/vendor/quickjs-ng/tests/bug776.js +7 -0
  160. package/native/vendor/quickjs-ng/tests/bug832.js +2 -0
  161. package/native/vendor/quickjs-ng/tests/bug858.js +26 -0
  162. package/native/vendor/quickjs-ng/tests/bug904.js +6 -0
  163. package/native/vendor/quickjs-ng/tests/bug988.js +7 -0
  164. package/native/vendor/quickjs-ng/tests/bug999.js +3 -0
  165. package/native/vendor/quickjs-ng/tests/destructured-export.js +8 -0
  166. package/native/vendor/quickjs-ng/tests/detect_module/0.js +1 -0
  167. package/native/vendor/quickjs-ng/tests/detect_module/1.js +2 -0
  168. package/native/vendor/quickjs-ng/tests/detect_module/2.js +1 -0
  169. package/native/vendor/quickjs-ng/tests/detect_module/3.js +8 -0
  170. package/native/vendor/quickjs-ng/tests/detect_module/4.js +3 -0
  171. package/native/vendor/quickjs-ng/tests/empty.js +0 -0
  172. package/native/vendor/quickjs-ng/tests/fixture_cyclic_import.js +2 -0
  173. package/native/vendor/quickjs-ng/tests/fixture_string_exports.js +12 -0
  174. package/native/vendor/quickjs-ng/tests/function_source.js +14 -0
  175. package/native/vendor/quickjs-ng/tests/microbench.js +1267 -0
  176. package/native/vendor/quickjs-ng/tests/null_or_undefined.js +38 -0
  177. package/native/vendor/quickjs-ng/tests/str-pad-leak.js +5 -0
  178. package/native/vendor/quickjs-ng/tests/test_bigint.js +107 -0
  179. package/native/vendor/quickjs-ng/tests/test_bjson.js +366 -0
  180. package/native/vendor/quickjs-ng/tests/test_builtin.js +1314 -0
  181. package/native/vendor/quickjs-ng/tests/test_closure.js +220 -0
  182. package/native/vendor/quickjs-ng/tests/test_cyclic_import.js +12 -0
  183. package/native/vendor/quickjs-ng/tests/test_domexception.js +35 -0
  184. package/native/vendor/quickjs-ng/tests/test_language.js +755 -0
  185. package/native/vendor/quickjs-ng/tests/test_loop.js +367 -0
  186. package/native/vendor/quickjs-ng/tests/test_queue_microtask.js +39 -0
  187. package/native/vendor/quickjs-ng/tests/test_std.js +340 -0
  188. package/native/vendor/quickjs-ng/tests/test_string_exports.js +25 -0
  189. package/native/vendor/quickjs-ng/tests/test_worker.js +43 -0
  190. package/native/vendor/quickjs-ng/tests/test_worker_module.js +30 -0
  191. package/native/vendor/quickjs-ng/tests.conf +14 -0
  192. package/native/vendor/quickjs-ng/unicode_download.sh +19 -0
  193. package/native/vendor/quickjs-ng/unicode_gen.c +3108 -0
  194. package/native/vendor/quickjs-ng/unicode_gen_def.h +310 -0
  195. package/native/vendor/quickjs-ng/update-version.sh +32 -0
  196. package/native/vendor/webview2/include/WebView2.h +60636 -0
  197. package/native/vendor/webview2/include/WebView2EnvironmentOptions.h +406 -0
  198. package/package.json +33 -0
  199. package/src/backend.ts +139 -0
  200. package/src/build-config.ts +87 -0
  201. package/src/build.ts +276 -0
  202. package/src/common.ts +195 -0
  203. package/src/config.ts +89 -0
  204. package/src/dev.ts +164 -0
  205. package/src/generate.ts +200 -0
  206. package/src/icons.ts +116 -0
  207. package/src/init.ts +190 -0
  208. package/src/package.ts +150 -0
  209. package/src/zapp-cli.ts +263 -0
@@ -0,0 +1,340 @@
1
+ import * as std from "qjs:std";
2
+ import * as os from "qjs:os";
3
+ import { assert } from "./assert.js";
4
+
5
+ const isWin = os.platform === 'win32';
6
+ const isCygwin = os.platform === 'cygwin';
7
+
8
+
9
+ function test_printf()
10
+ {
11
+ assert(std.sprintf("a=%d s=%s", 123, "abc"), "a=123 s=abc");
12
+ assert(std.sprintf("%010d", 123), "0000000123");
13
+ assert(std.sprintf("%x", -2), "fffffffe");
14
+ assert(std.sprintf("%lx", -2), "fffffffffffffffe");
15
+ assert(std.sprintf("%10.1f", 2.1), " 2.1");
16
+ assert(std.sprintf("%*.*f", 10, 2, -2.13), " -2.13");
17
+ assert(std.sprintf("%#lx", 0x7fffffffffffffffn), "0x7fffffffffffffff");
18
+ }
19
+
20
+ function test_file1()
21
+ {
22
+ var f, len, str, size, buf, ret, i, str1, ab;
23
+
24
+ f = std.tmpfile();
25
+ str = "hello world\n";
26
+ f.puts(str);
27
+
28
+ f.seek(0, std.SEEK_SET);
29
+ ab = f.readAsArrayBuffer();
30
+ assert([...new Uint8Array(ab)], str.split("").map(c => c.charCodeAt(0)));
31
+
32
+ f.seek(0, std.SEEK_SET);
33
+ str1 = f.readAsString();
34
+ assert(str1, str);
35
+
36
+ f.seek(0, std.SEEK_END);
37
+ size = f.tell();
38
+ assert(size, str.length);
39
+
40
+ f.seek(0, std.SEEK_SET);
41
+
42
+ buf = new Uint8Array(size);
43
+ ret = f.read(buf.buffer, 0, size);
44
+ assert(ret, size);
45
+ for(i = 0; i < size; i++)
46
+ assert(buf[i], str.charCodeAt(i));
47
+
48
+ f.close();
49
+ }
50
+
51
+ function test_file2()
52
+ {
53
+ var f, str, i, size;
54
+ f = std.tmpfile();
55
+ str = "hello world\n";
56
+ size = str.length;
57
+ for(i = 0; i < size; i++)
58
+ f.putByte(str.charCodeAt(i));
59
+ f.seek(0, std.SEEK_SET);
60
+ for(i = 0; i < size; i++) {
61
+ assert(str.charCodeAt(i), f.getByte());
62
+ }
63
+ assert(f.getByte(), -1);
64
+ f.close();
65
+ }
66
+
67
+ function test_getline()
68
+ {
69
+ var f, line, line_count, lines, i;
70
+
71
+ lines = ["hello world", "line 1", "line 2" ];
72
+ f = std.tmpfile();
73
+ for(i = 0; i < lines.length; i++) {
74
+ f.puts(lines[i], "\n");
75
+ }
76
+
77
+ f.seek(0, std.SEEK_SET);
78
+ assert(!f.eof());
79
+ line_count = 0;
80
+ for(;;) {
81
+ line = f.getline();
82
+ if (line === null)
83
+ break;
84
+ assert(line, lines[line_count]);
85
+ line_count++;
86
+ }
87
+ assert(f.eof());
88
+ assert(line_count, lines.length);
89
+
90
+ f.close();
91
+ }
92
+
93
+ function test_popen()
94
+ {
95
+ var str, f, fname = "tmp_file.txt";
96
+ var ta, content = "hello world";
97
+ var cmd = isWin ? "type" : "cat";
98
+
99
+ ta = new Uint8Array([...content].map(c => c.charCodeAt(0)));
100
+ std.writeFile(fname, ta);
101
+ assert(std.loadFile(fname), content);
102
+ std.writeFile(fname, ta.buffer);
103
+ assert(std.loadFile(fname), content);
104
+ std.writeFile(fname, content);
105
+ assert(std.loadFile(fname), content);
106
+
107
+ // popen pipe is unidirectional so mode should
108
+ // be either read or write but not both
109
+ let caught = false;
110
+ try {
111
+ std.popen(cmd, "rw");
112
+ } catch (e) {
113
+ assert(/invalid file mode/.test(e.message));
114
+ caught = true;
115
+ }
116
+ assert(caught);
117
+
118
+ /* execute shell command */
119
+ f = std.popen(cmd + " " + fname, "r");
120
+ str = f.readAsString();
121
+ f.close();
122
+
123
+ assert(str, content);
124
+
125
+ os.remove(fname);
126
+ }
127
+
128
+ function test_os()
129
+ {
130
+ var fd, fpath, fname, fdir, buf, buf2, i, files, err, fdate, st, link_path;
131
+
132
+ // XXX(bnoordhuis) disabled because stdio is not a tty on CI
133
+ //assert(os.isatty(0));
134
+
135
+ fdir = "test_tmp_dir";
136
+ fname = "tmp_file.txt";
137
+ fpath = fdir + "/" + fname;
138
+ link_path = fdir + "/test_link";
139
+
140
+ os.remove(link_path);
141
+ os.remove(fpath);
142
+ os.remove(fdir);
143
+
144
+ err = os.mkdir(fdir, 0o755);
145
+ assert(err, 0);
146
+
147
+ fd = os.open(fpath, os.O_RDWR | os.O_CREAT | os.O_TRUNC);
148
+ assert(fd >= 0);
149
+
150
+ buf = new Uint8Array(10);
151
+ for(i = 0; i < buf.length; i++)
152
+ buf[i] = i;
153
+ assert(os.write(fd, buf.buffer, 0, buf.length), buf.length);
154
+
155
+ assert(os.seek(fd, 0, std.SEEK_SET), 0);
156
+ buf2 = new Uint8Array(buf.length);
157
+ assert(os.read(fd, buf2.buffer, 0, buf2.length), buf2.length);
158
+
159
+ for(i = 0; i < buf.length; i++)
160
+ assert(buf[i] == buf2[i]);
161
+
162
+ if (typeof BigInt !== "undefined") {
163
+ assert(os.seek(fd, BigInt(6), std.SEEK_SET), BigInt(6));
164
+ assert(os.read(fd, buf2.buffer, 0, 1), 1);
165
+ assert(buf[6] == buf2[0]);
166
+ }
167
+
168
+ assert(os.close(fd), 0);
169
+
170
+ [files, err] = os.readdir(fdir);
171
+ assert(err, 0);
172
+ assert(files.length >= 3);
173
+ assert(files.includes(fname));
174
+ assert(files.includes("."));
175
+ assert(files.includes(".."));
176
+
177
+ fdate = 10000;
178
+
179
+ err = os.utimes(fpath, fdate, fdate);
180
+ assert(err, 0);
181
+
182
+ [st, err] = os.stat(fpath);
183
+ assert(err, 0);
184
+ assert(st.mode & os.S_IFMT, os.S_IFREG);
185
+ assert(st.mtime, fdate);
186
+
187
+ if (!isWin) {
188
+ err = os.symlink(fname, link_path);
189
+ assert(err, 0);
190
+
191
+ [st, err] = os.lstat(link_path);
192
+ assert(err, 0);
193
+ assert(st.mode & os.S_IFMT, os.S_IFLNK);
194
+
195
+ [buf, err] = os.readlink(link_path);
196
+ assert(err, 0);
197
+ assert(buf, fname);
198
+
199
+ assert(os.remove(link_path) === 0);
200
+ }
201
+
202
+ [buf, err] = os.getcwd();
203
+ assert(err, 0);
204
+
205
+ [buf2, err] = os.realpath(".");
206
+ assert(err, 0);
207
+
208
+ assert(buf, buf2);
209
+
210
+ assert(os.remove(fpath) === 0);
211
+
212
+ fd = os.open(fpath, os.O_RDONLY);
213
+ assert(fd < 0);
214
+
215
+ assert(os.remove(fdir) === 0);
216
+
217
+ if (!isWin) {
218
+ [fdir, err] = os.mkdtemp();
219
+ assert(err, 0);
220
+ assert(fdir.startsWith("tmp"));
221
+ assert(fdir.length, 9);
222
+
223
+ [fpath, fd] = os.mkstemp(`${fdir}/XXXXXX`);
224
+ assert(fdir.startsWith(`${fdir}`));
225
+ assert(fd >= 0);
226
+
227
+ const f = std.fdopen(fd, "w+");
228
+ f.write("xyzzy");
229
+ f.flush();
230
+ const b = new Uint8Array(5);
231
+ f.seek(0, std.SEEK_SET);
232
+ assert(5, f.read(b.buffer));
233
+ const s = [...b].map(c => String.fromCharCode(c)).join("");
234
+ assert(s, "xyzzy");
235
+ f.seek(0, std.SEEK_SET);
236
+ assert(0, f.read(b.buffer, 5, 42));
237
+ f.close();
238
+
239
+ assert(os.remove(fpath), 0);
240
+ assert(os.remove(fdir), 0);
241
+ }
242
+ }
243
+
244
+ function test_os_exec()
245
+ {
246
+ var ret, fds, pid, f, status;
247
+
248
+ ret = os.exec(["true"]);
249
+ assert(ret, 0);
250
+
251
+ ret = os.exec(["/bin/sh", "-c", "exit 1"], { usePath: false });
252
+ assert(ret, 1);
253
+
254
+ fds = os.pipe();
255
+ pid = os.exec(["sh", "-c", "echo $FOO"], {
256
+ stdout: fds[1],
257
+ block: false,
258
+ env: { FOO: "hello" },
259
+ } );
260
+ assert(pid >= 0);
261
+ os.close(fds[1]); /* close the write end (as it is only in the child) */
262
+ f = std.fdopen(fds[0], "r");
263
+ assert(f.getline(), "hello");
264
+ assert(f.getline(), null);
265
+ f.close();
266
+ [ret, status] = os.waitpid(pid, 0);
267
+ assert(ret, pid);
268
+ assert(status & 0x7f, 0); /* exited */
269
+ assert(status >> 8, 0); /* exit code */
270
+
271
+ pid = os.exec(["cat"], { block: false } );
272
+ assert(pid >= 0);
273
+ os.kill(pid, os.SIGTERM);
274
+ [ret, status] = os.waitpid(pid, 0);
275
+ assert(ret, pid);
276
+ // Flaky on cygwin for unclear reasons, see
277
+ // https://github.com/quickjs-ng/quickjs/issues/184
278
+ if (!isCygwin) {
279
+ assert(status & 0x7f, os.SIGTERM);
280
+ }
281
+ }
282
+
283
+ function test_interval()
284
+ {
285
+ var t = os.setInterval(f, 1);
286
+ function f() {
287
+ if (++f.count === 3) os.clearInterval(t);
288
+ }
289
+ f.count = 0;
290
+ }
291
+
292
+ function test_timeout()
293
+ {
294
+ var th, i;
295
+
296
+ /* just test that a timer can be inserted and removed */
297
+ th = [];
298
+ for(i = 0; i < 3; i++)
299
+ th[i] = os.setTimeout(function () { }, 1000);
300
+ for(i = 0; i < 3; i++)
301
+ os.clearTimeout(th[i]);
302
+ }
303
+
304
+ function test_timeout_order()
305
+ {
306
+ var s = "";
307
+ os.setTimeout(a, 0);
308
+ os.setTimeout(b, 100);
309
+ os.setTimeout(d, 700);
310
+ function a() { s += "a"; os.setTimeout(c, 300); }
311
+ function b() { s += "b"; }
312
+ function c() { s += "c"; }
313
+ function d() { assert(s, "abc"); } // not "acb"
314
+ }
315
+
316
+ function test_stdio_close()
317
+ {
318
+ for (const f of [std.in, std.out, std.err]) {
319
+ let caught = false;
320
+ try {
321
+ f.close();
322
+ } catch (e) {
323
+ assert(/cannot close stdio/.test(e.message));
324
+ caught = true;
325
+ }
326
+ assert(caught);
327
+ }
328
+ }
329
+
330
+ test_printf();
331
+ test_file1();
332
+ test_file2();
333
+ test_getline();
334
+ test_popen();
335
+ test_os();
336
+ !isWin && test_os_exec();
337
+ test_interval();
338
+ test_timeout();
339
+ test_timeout_order();
340
+ test_stdio_close();
@@ -0,0 +1,25 @@
1
+ // Test ES2020 string export/import names
2
+ import { assert } from "./assert.js";
3
+ import * as mod from "./fixture_string_exports.js";
4
+
5
+ // Test string import names
6
+ import { "string-export-1" as str1 } from "./fixture_string_exports.js";
7
+ import { "string-export-2" as str2 } from "./fixture_string_exports.js";
8
+ import { "string-name" as strMixed } from "./fixture_string_exports.js";
9
+
10
+ // Test regular imports still work
11
+ import { regularExport, normalName } from "./fixture_string_exports.js";
12
+
13
+ // Verify values
14
+ assert(str1, "value-1");
15
+ assert(str2, "value-2");
16
+ assert(strMixed, "mixed-value");
17
+ assert(regularExport, "regular");
18
+ assert(normalName, "mixed-value");
19
+
20
+ // Verify module namespace has string-named exports
21
+ assert(mod["string-export-1"], "value-1");
22
+ assert(mod["string-export-2"], "value-2");
23
+ assert(mod["string-name"], "mixed-value");
24
+ assert(mod.regularExport, "regular");
25
+ assert(mod.normalName, "mixed-value");
@@ -0,0 +1,43 @@
1
+ import * as os from "qjs:os";
2
+ import { assert } from "./assert.js";
3
+
4
+ var worker;
5
+
6
+ function test_worker()
7
+ {
8
+ var counter;
9
+
10
+ worker = new os.Worker("./test_worker_module.js");
11
+
12
+ counter = 0;
13
+ worker.onmessage = function (e) {
14
+ var ev = e.data;
15
+ // print("recv", JSON.stringify(ev));
16
+ switch(ev.type) {
17
+ case "num":
18
+ assert(ev.num, counter);
19
+ counter++;
20
+ if (counter == 10) {
21
+ /* test SharedArrayBuffer modification */
22
+ let sab = new SharedArrayBuffer(10);
23
+ let buf = new Uint8Array(sab);
24
+ worker.postMessage({ type: "sab", buf: buf });
25
+ }
26
+ break;
27
+ case "sab_done":
28
+ {
29
+ let buf = ev.buf;
30
+ /* check that the SharedArrayBuffer was modified */
31
+ assert(buf[2], 10);
32
+ worker.postMessage({ type: "abort" });
33
+ }
34
+ break;
35
+ case "done":
36
+ /* terminate */
37
+ worker.onmessage = null;
38
+ break;
39
+ }
40
+ };
41
+ }
42
+
43
+ test_worker();
@@ -0,0 +1,30 @@
1
+ /* Worker code for test_worker.js */
2
+ import * as os from "qjs:os";
3
+
4
+ var parent = os.Worker.parent;
5
+
6
+ function handle_msg(e) {
7
+ var ev = e.data;
8
+ // print("child_recv", JSON.stringify(ev));
9
+ switch(ev.type) {
10
+ case "abort":
11
+ parent.postMessage({ type: "done" });
12
+ break;
13
+ case "sab":
14
+ /* modify the SharedArrayBuffer */
15
+ ev.buf[2] = 10;
16
+ parent.postMessage({ type: "sab_done", buf: ev.buf });
17
+ break;
18
+ }
19
+ }
20
+
21
+ function worker_main() {
22
+ var i;
23
+
24
+ parent.onmessage = handle_msg;
25
+ for(i = 0; i < 10; i++) {
26
+ parent.postMessage({ type: "num", num: i });
27
+ }
28
+ }
29
+
30
+ worker_main();
@@ -0,0 +1,14 @@
1
+ [config]
2
+ local=yes
3
+ verbose=yes
4
+ testdir=tests
5
+
6
+ [features]
7
+ skip-if-tcc=!tcc
8
+
9
+ [exclude]
10
+ tests/empty.js
11
+ tests/fixture_cyclic_import.js
12
+ tests/microbench.js
13
+ tests/test_worker_module.js
14
+ tests/fixture_string_exports.js
@@ -0,0 +1,19 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ url="https://www.unicode.org/Public/17.0.0/ucd"
5
+ emoji_url="${url}/emoji/emoji-data.txt"
6
+
7
+ files="CaseFolding.txt DerivedNormalizationProps.txt PropList.txt \
8
+ SpecialCasing.txt CompositionExclusions.txt ScriptExtensions.txt \
9
+ UnicodeData.txt DerivedCoreProperties.txt NormalizationTest.txt Scripts.txt \
10
+ PropertyValueAliases.txt"
11
+
12
+ mkdir -p unicode
13
+
14
+ for f in $files; do
15
+ g="${url}/${f}"
16
+ wget $g -O unicode/$f
17
+ done
18
+
19
+ wget $emoji_url -O unicode/emoji-data.txt