quickwin 3.0.0 → 3.0.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.
Files changed (253) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/lib/abort.d.ts +21 -0
  4. package/lib/assert.d.ts +2 -0
  5. package/lib/bitmap.d.ts +7 -0
  6. package/lib/cache-utils.d.ts +6 -0
  7. package/lib/certs.d.ts +1 -0
  8. package/lib/dpi.d.ts +9 -0
  9. package/lib/dumpRects.d.ts +2 -0
  10. package/lib/exec-log.d.ts +23 -0
  11. package/lib/fetch.d.ts +4 -0
  12. package/lib/ffi/bind.d.ts +70 -0
  13. package/lib/ffi/ctype.d.ts +117 -0
  14. package/lib/ffi/index.d.ts +2 -0
  15. package/lib/ffi/struct.d.ts +174 -0
  16. package/lib/http-common.d.ts +143 -0
  17. package/lib/http-server.d.ts +59 -0
  18. package/lib/polyfill.d.ts +22 -0
  19. package/lib/react-qw/components/Button.d.ts +9 -0
  20. package/lib/react-qw/components/CheckBox.d.ts +11 -0
  21. package/lib/react-qw/components/ComboBox.d.ts +11 -0
  22. package/lib/react-qw/components/DateTimePicker.d.ts +15 -0
  23. package/lib/react-qw/components/Input.d.ts +15 -0
  24. package/lib/react-qw/components/Link.d.ts +12 -0
  25. package/lib/react-qw/components/ListBox.d.ts +13 -0
  26. package/lib/react-qw/components/ListView.d.ts +37 -0
  27. package/lib/react-qw/components/PathPicker.d.ts +23 -0
  28. package/lib/react-qw/components/ProgressBar.d.ts +9 -0
  29. package/lib/react-qw/components/RadioButton.d.ts +11 -0
  30. package/lib/react-qw/components/ScrollView.d.ts +9 -0
  31. package/lib/react-qw/components/Slider.d.ts +12 -0
  32. package/lib/react-qw/components/Tab.d.ts +14 -0
  33. package/lib/react-qw/components/Tooltip.d.ts +7 -0
  34. package/lib/react-qw/components/TreeView.d.ts +18 -0
  35. package/lib/react-qw/components/index.d.ts +16 -0
  36. package/lib/react-qw/index.d.ts +24 -0
  37. package/lib/react-qw/layout.d.ts +29 -0
  38. package/lib/react-qw/nmhdr.d.ts +1 -0
  39. package/lib/react-qw/props.d.ts +2 -0
  40. package/lib/react-qw/reconciler.d.ts +21 -0
  41. package/lib/stream.d.ts +20 -0
  42. package/lib/text-codec.d.ts +39 -0
  43. package/lib/text-measure.d.ts +14 -0
  44. package/lib/url.d.ts +54 -0
  45. package/lib/websocket.d.ts +73 -0
  46. package/lib/windows/{advapi32.ts → advapi32.d.ts} +6 -21
  47. package/lib/windows/comctl32.d.ts +14 -0
  48. package/lib/windows/comdlg32.d.ts +4 -0
  49. package/lib/windows/{gdi32.ts → gdi32.d.ts} +161 -98
  50. package/lib/windows/{kernel32.ts → kernel32.d.ts} +138 -115
  51. package/lib/windows/{msimg32.ts → msimg32.d.ts} +11 -14
  52. package/lib/windows/ntdll.d.ts +5 -0
  53. package/lib/windows/ole32.d.ts +3 -0
  54. package/lib/windows/{psapi.ts → psapi.d.ts} +9 -18
  55. package/lib/windows/{shell32.ts → shell32.d.ts} +25 -24
  56. package/lib/windows/structs.d.ts +3141 -0
  57. package/lib/windows/{user32.ts → user32.d.ts} +196 -193
  58. package/lib/windows/version.d.ts +27 -0
  59. package/lib/windows/{winspool.ts → winspool.d.ts} +18 -32
  60. package/package.json +15 -8
  61. package/qwin-nowasm-x86.exe +0 -0
  62. package/qwin-nowasm.exe +0 -0
  63. package/qwin-x86.exe +0 -0
  64. package/qwin.exe +0 -0
  65. package/examples/PdfCanvas.js +0 -38
  66. package/examples/PdfCanvas.tsx +0 -54
  67. package/examples/execd/main.js +0 -23379
  68. package/examples/execd/tray.js +0 -192
  69. package/examples/execd/worker.js +0 -122
  70. package/examples/pdf_preview2.js +0 -398
  71. package/examples/pdf_preview2.ts +0 -353
  72. package/examples/pdf_viewer.js +0 -22515
  73. package/examples/pdf_viewer.tsx +0 -228
  74. package/examples/test_gallery.js +0 -18692
  75. package/examples/test_gallery.tsx +0 -291
  76. package/examples/test_react_lazy.js +0 -18560
  77. package/examples/test_react_lazy.tsx +0 -65
  78. package/examples/test_react_listbox.js +0 -18562
  79. package/examples/test_react_listbox.tsx +0 -73
  80. package/examples/test_root_window.js +0 -18532
  81. package/examples/test_root_window.tsx +0 -41
  82. package/examples/test_tab.js +0 -18563
  83. package/examples/test_tab.tsx +0 -77
  84. package/examples/tray_demo.js +0 -86
  85. package/examples/tray_demo.tsx +0 -89
  86. package/lib/abort.ts +0 -69
  87. package/lib/assert.ts +0 -7
  88. package/lib/bitmap.ts +0 -39
  89. package/lib/cache-utils.ts +0 -40
  90. package/lib/certs.ts +0 -258
  91. package/lib/dpi.ts +0 -31
  92. package/lib/dumpRects.ts +0 -34
  93. package/lib/exec-log.ts +0 -30
  94. package/lib/fetch.ts +0 -589
  95. package/lib/ffi/bind.ts +0 -540
  96. package/lib/ffi/ctype.ts +0 -371
  97. package/lib/ffi/index.ts +0 -6
  98. package/lib/ffi/struct.ts +0 -780
  99. package/lib/http-common.ts +0 -441
  100. package/lib/http-server.ts +0 -604
  101. package/lib/polyfill.ts +0 -171
  102. package/lib/react-qw/components/index.ts +0 -17
  103. package/lib/react-qw/index.ts +0 -96
  104. package/lib/react-qw/layout.ts +0 -111
  105. package/lib/react-qw/nmhdr.ts +0 -7
  106. package/lib/react-qw/props.ts +0 -41
  107. package/lib/react-qw/reconciler.ts +0 -379
  108. package/lib/stream.ts +0 -22
  109. package/lib/text-codec.ts +0 -171
  110. package/lib/text-measure.ts +0 -44
  111. package/lib/url.ts +0 -201
  112. package/lib/websocket.ts +0 -600
  113. package/lib/windows/comctl32.ts +0 -20
  114. package/lib/windows/comdlg32.ts +0 -10
  115. package/lib/windows/ntdll.ts +0 -11
  116. package/lib/windows/ole32.ts +0 -9
  117. package/lib/windows/structs.ts +0 -807
  118. package/lib/windows/version.ts +0 -35
  119. package/test/add.wasm +0 -0
  120. package/test/bench_ffi_callraw.js +0 -235
  121. package/test/bench_ffi_callraw.ts +0 -235
  122. package/test/bench_ffi_overhead.js +0 -139
  123. package/test/bench_ffi_overhead.ts +0 -141
  124. package/test/bench_sendmessage.js +0 -104
  125. package/test/bench_sendmessage.ts +0 -100
  126. package/test/bench_sendmessage_nonnull.js +0 -187
  127. package/test/bench_sendmessage_nonnull.ts +0 -188
  128. package/test/complex.wasm +0 -0
  129. package/test/complex_imports.wasm +0 -0
  130. package/test/debug/http_server_e2e.js +0 -31
  131. package/test/debug/minwasm.js +0 -52
  132. package/test/debug/mupdf_debug.js +0 -86
  133. package/test/debug/wasm.js +0 -122
  134. package/test/debug/wasm_export_debug.js +0 -54
  135. package/test/debug/wasm_names.js +0 -36
  136. package/test/example.pdf +0 -0
  137. package/test/global_imports.wasm +0 -0
  138. package/test/import_func.wasm +0 -0
  139. package/test/imports.wasm +0 -0
  140. package/test/mupdf-cdn.js +0 -40
  141. package/test/mupdf-cdn.ts +0 -43
  142. package/test/run.js +0 -111
  143. package/test/run.ts +0 -116
  144. package/test/sjlj.wasm +0 -0
  145. package/test/test_basic.js +0 -7
  146. package/test/test_basic.ts +0 -9
  147. package/test/test_basic_fetch.js +0 -63
  148. package/test/test_basic_fetch.ts +0 -59
  149. package/test/test_brotli.js +0 -48
  150. package/test/test_brotli.ts +0 -52
  151. package/test/test_fetch_cache.js +0 -169
  152. package/test/test_fetch_cache.ts +0 -187
  153. package/test/test_ffi.js +0 -157
  154. package/test/test_ffi.ts +0 -170
  155. package/test/test_ffi_abi.js +0 -290
  156. package/test/test_ffi_abi.ts +0 -274
  157. package/test/test_ffi_array.js +0 -116
  158. package/test/test_ffi_array.ts +0 -141
  159. package/test/test_ffi_bind.js +0 -656
  160. package/test/test_ffi_bind.ts +0 -670
  161. package/test/test_ffi_struct.js +0 -779
  162. package/test/test_ffi_struct.ts +0 -828
  163. package/test/test_ffi_struct_layout.js +0 -495
  164. package/test/test_ffi_struct_layout.ts +0 -543
  165. package/test/test_ffi_user32.js +0 -103
  166. package/test/test_ffi_user32.ts +0 -113
  167. package/test/test_ffi_windows.js +0 -172
  168. package/test/test_ffi_windows.ts +0 -187
  169. package/test/test_files.js +0 -102
  170. package/test/test_files.ts +0 -121
  171. package/test/test_frame_encoding.js +0 -128
  172. package/test/test_frame_encoding.ts +0 -132
  173. package/test/test_gdi_draw.js +0 -681
  174. package/test/test_gdi_draw.ts +0 -725
  175. package/test/test_helper.js +0 -91
  176. package/test/test_helper.ts +0 -88
  177. package/test/test_http_import.js +0 -96
  178. package/test/test_http_import.ts +0 -93
  179. package/test/test_http_server.js +0 -214
  180. package/test/test_http_server.ts +0 -211
  181. package/test/test_import_dir.js +0 -4
  182. package/test/test_import_dir.ts +0 -5
  183. package/test/test_ipv6.js +0 -134
  184. package/test/test_ipv6.ts +0 -130
  185. package/test/test_jsx.js +0 -1314
  186. package/test/test_meta_url.js +0 -3
  187. package/test/test_meta_url.ts +0 -4
  188. package/test/test_mupdf_render.js +0 -51
  189. package/test/test_mupdf_render.ts +0 -55
  190. package/test/test_mupdf_twice.js +0 -62
  191. package/test/test_mupdf_twice.ts +0 -65
  192. package/test/test_mupdf_wasm.js +0 -39
  193. package/test/test_mupdf_wasm.ts +0 -32
  194. package/test/test_net_event.js +0 -57
  195. package/test/test_net_event.ts +0 -56
  196. package/test/test_net_fetch.js +0 -384
  197. package/test/test_net_fetch.ts +0 -373
  198. package/test/test_net_websocket.js +0 -180
  199. package/test/test_net_websocket.ts +0 -164
  200. package/test/test_polyfill.js +0 -144
  201. package/test/test_polyfill.ts +0 -159
  202. package/test/test_printer.js +0 -137
  203. package/test/test_printer.ts +0 -148
  204. package/test/test_proc.js +0 -141
  205. package/test/test_proc.ts +0 -163
  206. package/test/test_react_complex.js +0 -18678
  207. package/test/test_react_counter.js +0 -18555
  208. package/test/test_react_flex.js +0 -18871
  209. package/test/test_react_hidden.js +0 -18560
  210. package/test/test_react_listview_link.js +0 -18590
  211. package/test/test_react_notify.js +0 -18797
  212. package/test/test_react_render.js +0 -18550
  213. package/test/test_registry.js +0 -74
  214. package/test/test_registry.ts +0 -95
  215. package/test/test_sysinfo.js +0 -122
  216. package/test/test_sysinfo.ts +0 -141
  217. package/test/test_url.js +0 -173
  218. package/test/test_url.ts +0 -183
  219. package/test/test_wasm_basic.js +0 -85
  220. package/test/test_wasm_basic.ts +0 -73
  221. package/test/test_wasm_import_global.js +0 -41
  222. package/test/test_wasm_import_global.ts +0 -45
  223. package/test/test_wasm_sjlj.js +0 -145
  224. package/test/test_wasm_sjlj.ts +0 -125
  225. package/test/test_wasm_types.js +0 -97
  226. package/test/test_wasm_types.ts +0 -124
  227. package/test/test_wolfssl_read.js +0 -203
  228. package/test/test_wolfssl_read.ts +0 -184
  229. package/test/test_worker.js +0 -21
  230. package/test/test_worker.ts +0 -24
  231. package/test/test_worker_concurrent.js +0 -45
  232. package/test/test_worker_concurrent.ts +0 -56
  233. package/test/test_worker_data_url.js +0 -46
  234. package/test/test_worker_data_url.ts +0 -51
  235. package/test/test_worker_fetch.js +0 -26
  236. package/test/test_worker_fetch.ts +0 -27
  237. package/test/test_worker_net.js +0 -69
  238. package/test/test_worker_net.ts +0 -66
  239. package/test/test_worker_wasm_concurrent.js +0 -44
  240. package/test/test_worker_wasm_concurrent.ts +0 -45
  241. package/test/types.wasm +0 -0
  242. package/test/worker_fetch.js +0 -13
  243. package/test/worker_fetch.ts +0 -13
  244. package/test/worker_helper.js +0 -1
  245. package/test/worker_helper.ts +0 -1
  246. package/test/worker_http.js +0 -18
  247. package/test/worker_http.ts +0 -20
  248. package/test/worker_import_lib.js +0 -12
  249. package/test/worker_import_lib.ts +0 -13
  250. package/test/worker_module.js +0 -16
  251. package/test/worker_module.ts +0 -17
  252. package/test/worker_wasm_concurrent.js +0 -22
  253. package/test/worker_wasm_concurrent.ts +0 -22
package/test/test_url.ts DELETED
@@ -1,183 +0,0 @@
1
- import { Tester } from './test_helper.js'
2
- import '../lib/url.js'
3
-
4
- export const suite = {
5
- name: 'url',
6
- run: (t: Tester) => {
7
- t.section('http parse')
8
- const u = new URL('http://example.com')
9
- t.check('href', 'http://example.com/', u.href)
10
- t.check('protocol', 'http:', u.protocol)
11
- t.check('hostname', 'example.com', u.hostname)
12
- t.check('port', '', u.port)
13
- t.check('pathname', '/', u.pathname)
14
- t.check('host', 'example.com', u.host)
15
- t.check('origin', 'http://example.com', u.origin)
16
-
17
- t.section('full http')
18
- const u2 = new URL('https://user:pass@host.com:443/path/to?q=1&r=2#frag')
19
- t.check('protocol', 'https:', u2.protocol)
20
- t.check('username', 'user', u2.username)
21
- t.check('password', 'pass', u2.password)
22
- t.check('hostname', 'host.com', u2.hostname)
23
- t.check('port', '443', u2.port)
24
- t.check('pathname', '/path/to', u2.pathname)
25
- t.check('search', '?q=1&r=2', u2.search)
26
- t.check('hash', '#frag', u2.hash)
27
- t.check('host', 'host.com:443', u2.host)
28
-
29
- t.section('query string params')
30
- t.check('get q', '1', u2.searchParams.get('q'))
31
- t.check('get r', '2', u2.searchParams.get('r'))
32
- t.check('has q', true, u2.searchParams.has('q'))
33
- t.check('has x', false, u2.searchParams.has('x'))
34
-
35
- t.section('relative resolution')
36
- const b = new URL('./add.wasm', 'http://example.com/base/')
37
- t.check('relative path', 'http://example.com/base/add.wasm', b.href)
38
- const b2 = new URL('../other', 'http://example.com/base/')
39
- t.check('up one dir', 'http://example.com/other', b2.href)
40
- const b3 = new URL('/abs', 'http://example.com/base/')
41
- t.check('absolute path', 'http://example.com/abs', b3.href)
42
- const b4 = new URL('//other.com:8080/path', 'http://example.com/base/')
43
- t.check('protocol-relative', 'http://other.com:8080/path', b4.href)
44
-
45
- t.section('file URL')
46
- const f = new URL('file:///C:/Users/test/file.js')
47
- t.check('protocol', 'file:', f.protocol)
48
- t.check('hostname', '', f.hostname)
49
- t.check('pathname', '/C:/Users/test/file.js', f.pathname)
50
-
51
- t.section('file relative resolution')
52
- const f2 = new URL('./add.wasm', 'file:///C:/Users/test/helper.js')
53
- t.check('file relative', 'file:///C:/Users/test/add.wasm', f2.href)
54
- const f3 = new URL('../other.wasm', 'file:///C:/Users/test/sub/helper.js')
55
- t.check('file up dir', 'file:///C:/Users/test/other.wasm', f3.href)
56
-
57
- t.section('URLSearchParams')
58
- const p = new URLSearchParams('a=1&b=2&a=3')
59
- t.check('get a', '1', p.get('a'))
60
- t.check('getAll a', 2, p.getAll('a').length)
61
- t.check('get b', '2', p.get('b'))
62
- t.check('has c', false, p.has('c'))
63
- t.check('size', 3, p.size)
64
-
65
- t.section('URLSearchParams set/append/delete')
66
- const p2 = new URLSearchParams()
67
- p2.append('key', 'val1')
68
- p2.append('key', 'val2')
69
- t.check('append 2', 2, p2.getAll('key').length)
70
- p2.set('key', 'new')
71
- t.check('set replaces', 1, p2.getAll('key').length)
72
- t.check('set value', 'new', p2.get('key'))
73
- p2.append('x', 'y')
74
- p2.delete('x')
75
- t.check('delete', false, p2.has('x'))
76
-
77
- t.section('URLSearchParams toString')
78
- const p3 = new URLSearchParams('q=hello&r=world')
79
- t.check('toString', 'q=hello&r=world', p3.toString())
80
-
81
- t.section('URLSearchParams iterator')
82
- const p4 = new URLSearchParams('a=1&b=2')
83
- const keys: string[] = []
84
- for (const k of p4.keys()) keys.push(k)
85
- t.check('keys', 'a,b', keys.join(','))
86
-
87
- t.section('URL toJSON')
88
- const j = new URL('http://example.com/path')
89
- t.check('toJSON', 'http://example.com/path', j.toJSON())
90
-
91
- t.section('URL toString')
92
- t.check('toString', 'http://example.com/path', j.toString())
93
-
94
- t.section('IPv6')
95
- const v6 = new URL('http://[::1]:8080/path')
96
- t.check('hostname', '::1', v6.hostname)
97
- t.check('port', '8080', v6.port)
98
- t.check('host', '[::1]:8080', v6.host)
99
- t.check('pathname', '/path', v6.pathname)
100
- const v6b = new URL('http://[2001:db8::1]/')
101
- t.check('IPv6 no port', '2001:db8::1', v6b.hostname)
102
- t.check('IPv6 host', '[2001:db8::1]', v6b.host)
103
- const v6c = new URL('http://[::1]:8080')
104
- t.check('IPv6 origin', 'http://[::1]:8080', v6c.origin)
105
-
106
- t.section('ws/wss')
107
- const ws = new URL('ws://example.com/socket')
108
- t.check('ws protocol', 'ws:', ws.protocol)
109
- t.check('ws hostname', 'example.com', ws.hostname)
110
- t.check('ws pathname', '/socket', ws.pathname)
111
- const wss = new URL('wss://secure.com:9090/chat')
112
- t.check('wss port', '9090', wss.port)
113
-
114
- t.section('relative fragment/query')
115
- const rf = new URL('#top', 'http://example.com/path')
116
- t.check('fragment-only', 'http://example.com/path#top', rf.href)
117
- const rq = new URL('?q=1', 'http://example.com/path')
118
- t.check('query-only', 'http://example.com/path?q=1', rq.href)
119
- const rqf = new URL('?a=1#hash', 'http://example.com/path')
120
- t.check('query+frag', 'http://example.com/path?a=1#hash', rqf.href)
121
-
122
- t.section('path normalization')
123
- const np1 = new URL('a/../../other', 'http://example.com/base/')
124
- t.check('multi up', 'http://example.com/other', np1.href)
125
- const np2 = new URL('/../other', 'http://example.com/base/')
126
- t.check('root up', 'http://example.com/other', np2.href)
127
- const np3 = new URL('.', 'http://example.com/base/')
128
- t.check('dot only', 'http://example.com/base', np3.href)
129
- const np4 = new URL('', 'http://example.com/base/')
130
- t.check('empty relative', 'http://example.com/base/', np4.href)
131
-
132
- t.section('IP address')
133
- const ip = new URL('http://127.0.0.1:8080/path')
134
- t.check('ip hostname', '127.0.0.1', ip.hostname)
135
- t.check('ip port', '8080', ip.port)
136
-
137
- t.section('URLSearchParams values/entries/forEach')
138
- const pv = new URLSearchParams('a=1&b=2')
139
- const vals: string[] = []
140
- for (const v of pv.values()) vals.push(v)
141
- t.check('values', '1,2', vals.join(','))
142
- const entries: string[] = []
143
- for (const [k, v] of pv.entries()) entries.push(k + '=' + v)
144
- t.check('entries', 'a=1,b=2', entries.join(','))
145
- let forEachStr = ''
146
- pv.forEach((v, k) => { forEachStr += k + '=' + v + '|' })
147
- t.check('forEach', 'a=1|b=2|', forEachStr)
148
- const ps = new URLSearchParams('b=2&a=1&c=3')
149
- ps.sort()
150
- t.check('sort', 'a=1&b=2&c=3', ps.toString())
151
-
152
- t.section('URLSearchParams edge cases')
153
- const pe1 = new URLSearchParams('a=1&b')
154
- t.check('empty value', '', pe1.get('b'))
155
- const pe2 = new URLSearchParams('?a=1&b=2')
156
- t.check('leading ?', '1', pe2.get('a'))
157
- const pe3 = new URLSearchParams([['x', '10'], ['y', '20']] as any)
158
- t.check('array init', '10', pe3.get('x'))
159
- t.check('array init 2', '20', pe3.get('y'))
160
- t.check('array size', 2, pe3.size)
161
-
162
- t.section('encoded chars')
163
- const enc = new URL('http://example.com/hello%20world')
164
- t.check('encoded pathname', '/hello%20world', enc.pathname)
165
- const encq = new URL('http://example.com/path?q=a+b&r=%25')
166
- t.check('encoded query +→space', 'a b', encq.searchParams.get('q'))
167
- t.check('encoded query %25', '%', encq.searchParams.get('r'))
168
-
169
- t.section('null/undefined base')
170
- let threw = false
171
- try { new URL('/path', null as any) } catch { threw = true }
172
- t.check('null base throws', true, threw)
173
- threw = false
174
- try { new URL('relative') } catch { threw = true }
175
- t.check('no base throws', true, threw)
176
-
177
- t.section('data URL')
178
- const d = new URL('data:text/plain,hello')
179
- t.check('data protocol', 'data:', d.protocol)
180
- t.check('data hostname', '', d.hostname)
181
- t.check('data pathname', 'text/plain,hello', d.pathname)
182
- }
183
- }
@@ -1,85 +0,0 @@
1
- import { readWasmFile } from './test_helper.js';
2
- export const suite = {
3
- name: 'wasm-basic',
4
- run: (t) => {
5
- t.section('validate');
6
- t.check('empty buffer', false, WebAssembly.validate(new Uint8Array([]).buffer));
7
- t.check('invalid bytes', false, WebAssembly.validate(new Uint8Array([1, 2, 3]).buffer));
8
- const wasmBuf = readWasmFile('./add.wasm');
9
- if (!wasmBuf) {
10
- t.fail++;
11
- return;
12
- }
13
- t.check('valid add.wasm', true, WebAssembly.validate(wasmBuf));
14
- t.section('Module');
15
- var mod = null;
16
- try {
17
- mod = new WebAssembly.Module(wasmBuf);
18
- t.check('Module constructor', true, mod instanceof WebAssembly.Module);
19
- }
20
- catch (e) {
21
- t.fail++;
22
- }
23
- t.section('Module.exports');
24
- if (mod) {
25
- try {
26
- const exps = WebAssembly.Module.exports(mod);
27
- t.check('exports count', 1, exps.length);
28
- t.check('export name', 'add', exps[0].name);
29
- t.check('export kind', 'function', exps[0].kind);
30
- }
31
- catch (e) {
32
- t.fail++;
33
- }
34
- }
35
- t.section('Instance (add.wasm)');
36
- if (mod) {
37
- try {
38
- const inst = new WebAssembly.Instance(mod);
39
- const iExp = inst.exports;
40
- t.check('Instance created', true, inst instanceof WebAssembly.Instance);
41
- t.check('add(1, 2)', 3, iExp.add(1, 2));
42
- t.check('add(10, 20)', 30, iExp.add(10, 20));
43
- t.check('add(-5, 3)', -2, iExp.add(-5, 3));
44
- }
45
- catch (e) {
46
- t.fail++;
47
- }
48
- }
49
- t.section('complex.wasm');
50
- const complexBuf = readWasmFile('./complex.wasm');
51
- if (complexBuf) {
52
- try {
53
- const cmod = new WebAssembly.Module(complexBuf);
54
- const cinst = new WebAssembly.Instance(cmod);
55
- const cExp = cinst.exports;
56
- t.check('add(3, 4)', 7, cExp.add(3, 4));
57
- t.check('sub(10, 3)', 7, cExp.sub(10, 3));
58
- t.check('mul(6, 7)', 42, cExp.mul(6, 7));
59
- t.check('factorial(0)', 1, cExp.factorial(0));
60
- t.check('factorial(5)', 120, cExp.factorial(5));
61
- t.check('factorial(10)', 3628800, cExp.factorial(10));
62
- }
63
- catch (e) {
64
- t.fail++;
65
- }
66
- }
67
- t.section('import function');
68
- const importFuncBuf = readWasmFile('./import_func.wasm');
69
- if (importFuncBuf) {
70
- try {
71
- const ifmod = new WebAssembly.Module(importFuncBuf);
72
- const ifinst = new WebAssembly.Instance(ifmod, {
73
- env: { imported_add: (a, b) => a + b }
74
- });
75
- const ifExp = ifinst.exports;
76
- t.check('add_via_import(3, 4)', 7, ifExp.add_via_import(3, 4));
77
- t.check('add_via_import(10, 20)', 30, ifExp.add_via_import(10, 20));
78
- t.check('add_via_import(-5, 3)', -2, ifExp.add_via_import(-5, 3));
79
- }
80
- catch (e) {
81
- t.fail++;
82
- }
83
- }
84
- }
85
- };
@@ -1,73 +0,0 @@
1
- import { Tester, readWasmFile } from './test_helper.js'
2
-
3
- export const suite = {
4
- name: 'wasm-basic',
5
- run: (t: Tester) => {
6
- t.section('validate')
7
- t.check('empty buffer', false, WebAssembly.validate(new Uint8Array([]).buffer))
8
- t.check('invalid bytes', false, WebAssembly.validate(new Uint8Array([1, 2, 3]).buffer))
9
- const wasmBuf = readWasmFile('./add.wasm')
10
- if (!wasmBuf) { t.fail++; return }
11
- t.check('valid add.wasm', true, WebAssembly.validate(wasmBuf))
12
-
13
- t.section('Module')
14
- var mod: WebAssembly.Module | null = null
15
- try {
16
- mod = new WebAssembly.Module(wasmBuf)
17
- t.check('Module constructor', true, mod instanceof WebAssembly.Module)
18
- } catch (e) { t.fail++ }
19
-
20
- t.section('Module.exports')
21
- if (mod) {
22
- try {
23
- const exps = WebAssembly.Module.exports(mod)
24
- t.check('exports count', 1, exps.length)
25
- t.check('export name', 'add', exps[0]!.name)
26
- t.check('export kind', 'function', exps[0]!.kind)
27
- } catch (e) { t.fail++ }
28
- }
29
-
30
- t.section('Instance (add.wasm)')
31
- if (mod) {
32
- try {
33
- const inst = new WebAssembly.Instance<{ add: (a: number, b: number) => number }>(mod)
34
- const iExp = inst.exports
35
- t.check('Instance created', true, inst instanceof WebAssembly.Instance)
36
- t.check('add(1, 2)', 3, iExp.add(1, 2))
37
- t.check('add(10, 20)', 30, iExp.add(10, 20))
38
- t.check('add(-5, 3)', -2, iExp.add(-5, 3))
39
- } catch (e) { t.fail++ }
40
- }
41
-
42
- t.section('complex.wasm')
43
- const complexBuf = readWasmFile('./complex.wasm')
44
- if (complexBuf) {
45
- try {
46
- const cmod = new WebAssembly.Module(complexBuf)
47
- const cinst = new WebAssembly.Instance<{ add: (a: number, b: number) => number; sub: (a: number, b: number) => number; mul: (a: number, b: number) => number; factorial: (n: number) => number }>(cmod)
48
- const cExp = cinst.exports
49
- t.check('add(3, 4)', 7, cExp.add(3, 4))
50
- t.check('sub(10, 3)', 7, cExp.sub(10, 3))
51
- t.check('mul(6, 7)', 42, cExp.mul(6, 7))
52
- t.check('factorial(0)', 1, cExp.factorial(0))
53
- t.check('factorial(5)', 120, cExp.factorial(5))
54
- t.check('factorial(10)', 3628800, cExp.factorial(10))
55
- } catch (e) { t.fail++ }
56
- }
57
-
58
- t.section('import function')
59
- const importFuncBuf = readWasmFile('./import_func.wasm')
60
- if (importFuncBuf) {
61
- try {
62
- const ifmod = new WebAssembly.Module(importFuncBuf)
63
- const ifinst = new WebAssembly.Instance<{ add_via_import: (a: number, b: number) => number }>(ifmod, {
64
- env: { imported_add: (a: number, b: number) => a + b }
65
- })
66
- const ifExp = ifinst.exports
67
- t.check('add_via_import(3, 4)', 7, ifExp.add_via_import(3, 4))
68
- t.check('add_via_import(10, 20)', 30, ifExp.add_via_import(10, 20))
69
- t.check('add_via_import(-5, 3)', -2, ifExp.add_via_import(-5, 3))
70
- } catch (e) { t.fail++ }
71
- }
72
- }
73
- }
@@ -1,41 +0,0 @@
1
- import { readWasmFile } from './test_helper.js';
2
- export const suite = {
3
- name: 'wasm-import-global',
4
- run: (t) => {
5
- const giBuf = readWasmFile('./global_imports.wasm');
6
- if (!giBuf) {
7
- t.fail++;
8
- return;
9
- }
10
- const giMod = new WebAssembly.Module(giBuf);
11
- t.section('import globals');
12
- var giInst;
13
- try {
14
- giInst = new WebAssembly.Instance(giMod, {
15
- env: {
16
- offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 42),
17
- factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 3.14),
18
- log: function (_x) { }
19
- }
20
- });
21
- }
22
- catch (e) {
23
- t.fail++;
24
- return;
25
- }
26
- t.check('get_offset()', 42, giInst.exports.get_offset());
27
- t.check('compute(10)', 31.4, giInst.exports.compute(10));
28
- t.check('run(8)', 50, giInst.exports.run(8));
29
- t.section('second instance');
30
- var giInst2 = new WebAssembly.Instance(giMod, {
31
- env: {
32
- offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 100),
33
- factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 2.0),
34
- log: function (_x) { }
35
- }
36
- });
37
- t.check('instance2 get_offset()', 100, giInst2.exports.get_offset());
38
- t.check('instance2 compute(5)', 10, giInst2.exports.compute(5));
39
- t.check('instance1 still get_offset()', 42, giInst.exports.get_offset());
40
- }
41
- };
@@ -1,45 +0,0 @@
1
- import { Tester, readWasmFile } from './test_helper.js'
2
-
3
- type GlobalImportsExports = {
4
- get_offset: () => number
5
- compute: (x: number) => number
6
- run: (x: number) => number
7
- }
8
-
9
- export const suite = {
10
- name: 'wasm-import-global',
11
- run: (t: Tester) => {
12
- const giBuf = readWasmFile('./global_imports.wasm')
13
- if (!giBuf) { t.fail++; return }
14
- const giMod = new WebAssembly.Module(giBuf)
15
-
16
- t.section('import globals')
17
- var giInst: WebAssembly.Instance<GlobalImportsExports>
18
- try {
19
- giInst = new WebAssembly.Instance<GlobalImportsExports>(giMod, {
20
- env: {
21
- offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 42),
22
- factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 3.14),
23
- log: function (_x: number) { /* noop */ }
24
- }
25
- })
26
- } catch (e) {
27
- t.fail++; return
28
- }
29
- t.check('get_offset()', 42, giInst.exports.get_offset())
30
- t.check('compute(10)', 31.4, giInst.exports.compute(10))
31
- t.check('run(8)', 50, giInst.exports.run(8))
32
-
33
- t.section('second instance')
34
- var giInst2 = new WebAssembly.Instance<GlobalImportsExports>(giMod, {
35
- env: {
36
- offset: new WebAssembly.Global({ value: 'i32', mutable: false }, 100),
37
- factor: new WebAssembly.Global({ value: 'f64', mutable: false }, 2.0),
38
- log: function (_x: number) { /* noop */ }
39
- }
40
- })
41
- t.check('instance2 get_offset()', 100, giInst2.exports.get_offset())
42
- t.check('instance2 compute(5)', 10, giInst2.exports.compute(5))
43
- t.check('instance1 still get_offset()', 42, giInst.exports.get_offset())
44
- }
45
- }
@@ -1,145 +0,0 @@
1
- import { readWasmFile } from './test_helper.js';
2
- class EmscriptenEH {
3
- }
4
- class EmscriptenSjLj extends EmscriptenEH {
5
- }
6
- export const suite = {
7
- name: 'wasm-sjlj',
8
- run: (t) => {
9
- ;
10
- globalThis.EmscriptenEH = EmscriptenEH;
11
- globalThis.EmscriptenSjLj = EmscriptenSjLj;
12
- const buf = readWasmFile('./sjlj.wasm');
13
- if (!buf) {
14
- t.fail++;
15
- return;
16
- }
17
- t.section('Module');
18
- var mod = null;
19
- try {
20
- mod = new WebAssembly.Module(buf);
21
- t.check('Module created', true, mod instanceof WebAssembly.Module);
22
- }
23
- catch (e) {
24
- t.fail++;
25
- return;
26
- }
27
- t.section('Instance with SjLj imports');
28
- var inst = null;
29
- var threwBit = 0;
30
- function getWasmTableEntry(index) {
31
- const table = inst.exports['__indirect_function_table'];
32
- const fn = table.get(index);
33
- return fn;
34
- }
35
- function _setThrew(val, _v) {
36
- if (threwBit === 0) {
37
- threwBit = val;
38
- }
39
- }
40
- function invoke_ii(index, a1) {
41
- try {
42
- return getWasmTableEntry(index)(a1);
43
- }
44
- catch (e) {
45
- if (!(e instanceof EmscriptenEH))
46
- throw e;
47
- _setThrew(1, 0);
48
- return 0;
49
- }
50
- }
51
- try {
52
- inst = new WebAssembly.Instance(mod, {
53
- env: {
54
- throw_longjmp: () => { throw new EmscriptenSjLj; },
55
- invoke_ii: invoke_ii,
56
- }
57
- });
58
- t.check('Instance created', true, inst instanceof WebAssembly.Instance);
59
- }
60
- catch (e) {
61
- t.fail++;
62
- return;
63
- }
64
- t.section('identity (no throw)');
65
- try {
66
- threwBit = 0;
67
- const result = inst.exports.identity(42);
68
- t.check('identity(42) = 42', 42, result);
69
- }
70
- catch (e) {
71
- t.fail++;
72
- }
73
- t.section('invoke_ii with no-throw function');
74
- try {
75
- threwBit = 0;
76
- const result = inst.exports.test_no_throw();
77
- t.check('test_no_throw() returns 10', 10, result);
78
- t.check('threwBit is 0', 0, threwBit);
79
- }
80
- catch (e) {
81
- t.fail++;
82
- }
83
- t.section('invoke_ii with throwing function');
84
- try {
85
- threwBit = 0;
86
- const result = inst.exports.test_throw();
87
- t.check('test_throw() detects threwBit', true, result !== 0);
88
- t.check('threwBit is set', true, threwBit !== 0);
89
- }
90
- catch (e) {
91
- t.fail++;
92
- }
93
- t.section('nested invoke (invoke_ii calls invoke_ii)');
94
- try {
95
- threwBit = 0;
96
- const result = inst.exports.test_nested_invoke();
97
- t.check('test_nested_invoke() detects threwBit', true, result !== 0);
98
- t.check('threwBit is set', true, threwBit !== 0);
99
- }
100
- catch (e) {
101
- t.fail++;
102
- }
103
- t.section('setjmp_test pattern');
104
- try {
105
- threwBit = 0;
106
- const result = inst.exports.setjmp_test(0);
107
- t.check('setjmp_test detects throw', -1, result);
108
- t.check('threwBit is set', true, threwBit !== 0);
109
- }
110
- catch (e) {
111
- t.fail++;
112
- }
113
- t.section('setjmp/longjmp: a(x) normal path');
114
- try {
115
- threwBit = 0;
116
- const result = inst.exports.a(5);
117
- t.check('a(5) returns 10 (b returns x*2)', 10, result);
118
- t.check('threwBit is 0', 0, threwBit);
119
- }
120
- catch (e) {
121
- t.fail++;
122
- }
123
- t.section('setjmp/longjmp: a(x) longjmp path');
124
- try {
125
- threwBit = 0;
126
- const result = inst.exports.a(-1);
127
- t.check('a(-1) returns -1 (longjmp caught)', -1, result);
128
- t.check('threwBit is set', true, threwBit !== 0);
129
- }
130
- catch (e) {
131
- t.fail++;
132
- }
133
- t.section('EmscriptenSjLj instanceof check');
134
- try {
135
- const exc = new EmscriptenSjLj();
136
- t.check('instanceof EmscriptenEH', true, exc instanceof EmscriptenEH);
137
- t.check('instanceof EmscriptenSjLj', true, exc instanceof EmscriptenSjLj);
138
- const regularErr = new Error('test');
139
- t.check('Error not instanceof EmscriptenEH', false, regularErr instanceof EmscriptenEH);
140
- }
141
- catch (e) {
142
- t.fail++;
143
- }
144
- }
145
- };