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
@@ -1,74 +0,0 @@
1
- import * as os from 'os';
2
- import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js';
3
- import { RegCloseKey, RegCreateKeyEx, RegDeleteKey, RegOpenKeyEx, RegQueryValueEx, RegSetValueEx, } from '../lib/windows/advapi32.js';
4
- // 跨架构读指针宽句柄(ia32 4B / x64 8B)—— 照 test_ffi.ts 的 readPtr 先例
5
- function readPtr(dv, offset) {
6
- if (os.arch === 'ia32') {
7
- return dv.getUint32(offset, true);
8
- }
9
- const low = dv.getUint32(offset, true);
10
- const high = dv.getUint32(offset + 4, true);
11
- return low + high * 4294967296;
12
- }
13
- // REG_SZ 数据 = UTF-16LE 含结尾 NUL;读回按字节数截到 NUL
14
- function wbuf(s) {
15
- const p = new PtrArrayBuffer((s.length + 1) * 2);
16
- const dv = new DataView(p);
17
- for (let i = 0; i <= s.length; i++)
18
- dv.setUint16(i * 2, s.charCodeAt(i), true);
19
- return p;
20
- }
21
- function wstr(dv, bytes) {
22
- let out = '';
23
- for (let i = 0; i + 1 < bytes; i += 2) {
24
- const ch = dv.getUint16(i, true);
25
- if (!ch)
26
- break;
27
- out += String.fromCharCode(ch);
28
- }
29
- return out;
30
- }
31
- // 测试键:HKCU\Software\QuickWinTest(suite 结束时删除;中途 FAIL 会在下次 run 时复用)
32
- const KEY = 'Software\\QuickWinTest';
33
- const MSG = 'hello registry';
34
- export const suite = {
35
- name: 'registry',
36
- run: (t) => {
37
- t.section('RegCreateKeyEx: create test key under HKCU');
38
- const phk = new PtrArrayBuffer(8);
39
- // hKey 位双来源:预定义键常量(HKEY_CURRENT_USER = 0x80000001 的 i32 形)
40
- // 或真实句柄——裸 <>ptr 位收两者;符号/零扩展语义由本调用实测检验
41
- const rcCreate = RegCreateKeyEx(-2147483647 /* HKey.CURRENT_USER */, KEY, 0, NULL, 0, 983103 /* RegAccess.ALL_ACCESS */, NULL, phk, NULL);
42
- t.check('create key = ERROR_SUCCESS', 0, rcCreate);
43
- if (rcCreate !== 0)
44
- return; // 基座失败,后续无意义
45
- const hkey = readPtr(new DataView(phk), 0);
46
- t.checkTrue(`key handle non-null (${hkey})`, hkey !== 0);
47
- t.section('RegSetValueEx + RegQueryValueEx: REG_SZ roundtrip');
48
- const data = wbuf(MSG);
49
- t.check('set REG_SZ = ERROR_SUCCESS', 0, RegSetValueEx(hkey, 'greeting', 0, 1 /* RegType.SZ */, data, (MSG.length + 1) * 2));
50
- const pType = new PtrArrayBuffer(4);
51
- const pCb = new PtrArrayBuffer(4);
52
- const pData = new PtrArrayBuffer(64);
53
- new DataView(pCb).setUint32(0, 64, true); // 双向 lpcbData:入 = 缓冲大小须预写
54
- t.check('query = ERROR_SUCCESS', 0, RegQueryValueEx(hkey, 'greeting', NULL, pType, pData, pCb));
55
- t.check('type = REG_SZ', 1, new DataView(pType).getUint32(0, true));
56
- t.check('size = (len+1)*2', (MSG.length + 1) * 2, new DataView(pCb).getUint32(0, true));
57
- t.check('data roundtrip', MSG, wstr(new DataView(pData), (MSG.length + 1) * 2));
58
- t.section('RegQueryValueEx: size probe (lpData = NULL)');
59
- new DataView(pCb).setUint32(0, 0, true); // 预写 0:只查类型/尺寸
60
- t.check('probe = ERROR_SUCCESS', 0, RegQueryValueEx(hkey, 'greeting', NULL, NULL, NULL, pCb));
61
- t.check('probe size', (MSG.length + 1) * 2, new DataView(pCb).getUint32(0, true));
62
- t.section('RegOpenKeyEx: reopen + missings');
63
- const phk2 = new PtrArrayBuffer(8);
64
- t.check('reopen = ERROR_SUCCESS', 0, RegOpenKeyEx(-2147483647 /* HKey.CURRENT_USER */, KEY, 0, 131097 /* RegAccess.READ */, phk2));
65
- const hkey2 = readPtr(new DataView(phk2), 0);
66
- t.check('missing value → ERROR_FILE_NOT_FOUND', 2, RegQueryValueEx(hkey2, 'no-such-value', NULL, NULL, NULL, NULL));
67
- t.check('missing key → ERROR_FILE_NOT_FOUND', 2, RegOpenKeyEx(-2147483647 /* HKey.CURRENT_USER */, KEY + 'X', 0, 131097 /* RegAccess.READ */, new PtrArrayBuffer(8)));
68
- RegCloseKey(hkey2);
69
- t.section('RegDeleteKey + RegCloseKey: cleanup');
70
- t.check('delete key = ERROR_SUCCESS', 0, RegDeleteKey(-2147483647 /* HKey.CURRENT_USER */, KEY));
71
- t.check('close = ERROR_SUCCESS', 0, RegCloseKey(hkey));
72
- t.check('open deleted → ERROR_FILE_NOT_FOUND', 2, RegOpenKeyEx(-2147483647 /* HKey.CURRENT_USER */, KEY, 0, 131097 /* RegAccess.READ */, new PtrArrayBuffer(8)));
73
- },
74
- };
@@ -1,95 +0,0 @@
1
- import * as os from 'os'
2
- import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js'
3
- import {
4
- RegCloseKey, RegCreateKeyEx, RegDeleteKey, RegOpenKeyEx,
5
- RegQueryValueEx, RegSetValueEx,
6
- } from '../lib/windows/advapi32.js'
7
- import { Tester } from './test_helper.js'
8
- import { HKey, RegAccess, RegType } from '../constants'
9
-
10
- // 跨架构读指针宽句柄(ia32 4B / x64 8B)—— 照 test_ffi.ts 的 readPtr 先例
11
- function readPtr(dv: DataView, offset: number): number {
12
- if (os.arch === 'ia32') {
13
- return dv.getUint32(offset, true)
14
- }
15
- const low = dv.getUint32(offset, true)
16
- const high = dv.getUint32(offset + 4, true)
17
- return low + high * 4294967296
18
- }
19
-
20
- // REG_SZ 数据 = UTF-16LE 含结尾 NUL;读回按字节数截到 NUL
21
- function wbuf(s: string) {
22
- const p = new PtrArrayBuffer((s.length + 1) * 2)
23
- const dv = new DataView(p)
24
- for (let i = 0; i <= s.length; i++) dv.setUint16(i * 2, s.charCodeAt(i), true)
25
- return p
26
- }
27
- function wstr(dv: DataView, bytes: number): string {
28
- let out = ''
29
- for (let i = 0; i + 1 < bytes; i += 2) {
30
- const ch = dv.getUint16(i, true)
31
- if (!ch) break
32
- out += String.fromCharCode(ch)
33
- }
34
- return out
35
- }
36
-
37
- // 测试键:HKCU\Software\QuickWinTest(suite 结束时删除;中途 FAIL 会在下次 run 时复用)
38
- const KEY = 'Software\\QuickWinTest'
39
- const MSG = 'hello registry'
40
-
41
- export const suite = {
42
- name: 'registry',
43
- run: (t: Tester) => {
44
- t.section('RegCreateKeyEx: create test key under HKCU')
45
- const phk = new PtrArrayBuffer(8)
46
- // hKey 位双来源:预定义键常量(HKEY_CURRENT_USER = 0x80000001 的 i32 形)
47
- // 或真实句柄——裸 <>ptr 位收两者;符号/零扩展语义由本调用实测检验
48
- const rcCreate = RegCreateKeyEx(HKey.CURRENT_USER, KEY, 0, NULL, 0,
49
- RegAccess.ALL_ACCESS, NULL, phk, NULL)
50
- t.check('create key = ERROR_SUCCESS', 0, rcCreate)
51
- if (rcCreate !== 0) return // 基座失败,后续无意义
52
- const hkey = readPtr(new DataView(phk), 0)
53
- t.checkTrue(`key handle non-null (${hkey})`, hkey !== 0)
54
-
55
- t.section('RegSetValueEx + RegQueryValueEx: REG_SZ roundtrip')
56
- const data = wbuf(MSG)
57
- t.check('set REG_SZ = ERROR_SUCCESS', 0,
58
- RegSetValueEx(hkey, 'greeting', 0, RegType.SZ, data, (MSG.length + 1) * 2))
59
- const pType = new PtrArrayBuffer(4)
60
- const pCb = new PtrArrayBuffer(4)
61
- const pData = new PtrArrayBuffer(64)
62
- new DataView(pCb).setUint32(0, 64, true) // 双向 lpcbData:入 = 缓冲大小须预写
63
- t.check('query = ERROR_SUCCESS', 0,
64
- RegQueryValueEx(hkey, 'greeting', NULL, pType, pData, pCb))
65
- t.check('type = REG_SZ', 1, new DataView(pType).getUint32(0, true))
66
- t.check('size = (len+1)*2', (MSG.length + 1) * 2, new DataView(pCb).getUint32(0, true))
67
- t.check('data roundtrip', MSG, wstr(new DataView(pData), (MSG.length + 1) * 2))
68
-
69
- t.section('RegQueryValueEx: size probe (lpData = NULL)')
70
- new DataView(pCb).setUint32(0, 0, true) // 预写 0:只查类型/尺寸
71
- t.check('probe = ERROR_SUCCESS', 0,
72
- RegQueryValueEx(hkey, 'greeting', NULL, NULL, NULL, pCb))
73
- t.check('probe size', (MSG.length + 1) * 2, new DataView(pCb).getUint32(0, true))
74
-
75
- t.section('RegOpenKeyEx: reopen + missings')
76
- const phk2 = new PtrArrayBuffer(8)
77
- t.check('reopen = ERROR_SUCCESS', 0,
78
- RegOpenKeyEx(HKey.CURRENT_USER, KEY, 0, RegAccess.READ, phk2))
79
- const hkey2 = readPtr(new DataView(phk2), 0)
80
- t.check('missing value → ERROR_FILE_NOT_FOUND', 2,
81
- RegQueryValueEx(hkey2, 'no-such-value', NULL, NULL, NULL, NULL))
82
- t.check('missing key → ERROR_FILE_NOT_FOUND', 2,
83
- RegOpenKeyEx(HKey.CURRENT_USER, KEY + 'X', 0, RegAccess.READ,
84
- new PtrArrayBuffer(8)))
85
- RegCloseKey(hkey2)
86
-
87
- t.section('RegDeleteKey + RegCloseKey: cleanup')
88
- t.check('delete key = ERROR_SUCCESS', 0,
89
- RegDeleteKey(HKey.CURRENT_USER, KEY))
90
- t.check('close = ERROR_SUCCESS', 0, RegCloseKey(hkey))
91
- t.check('open deleted → ERROR_FILE_NOT_FOUND', 2,
92
- RegOpenKeyEx(HKey.CURRENT_USER, KEY, 0, RegAccess.READ,
93
- new PtrArrayBuffer(8)))
94
- },
95
- }
@@ -1,122 +0,0 @@
1
- import * as ffi from 'ffi';
2
- import * as os from 'os';
3
- import { WCHAR } from '../lib/ffi/bind.js';
4
- import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js';
5
- import { FormatMessage, GetCommandLineW, GetComputerName, GetEnvironmentVariable, GetLocalTime, GetModuleFileName, GetSystemDirectory, GetSystemTimeAsFileTime, GlobalAlloc, GlobalLock, GlobalUnlock, QueryPerformanceCounter, QueryPerformanceFrequency, RtlMoveMemory, Sleep, } from '../lib/windows/kernel32.js';
6
- import { CloseClipboard, EmptyClipboard, GetClipboardData, OpenClipboard, RegisterClipboardFormat, SetClipboardData, } from '../lib/windows/user32.js';
7
- import { GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue, } from '../lib/windows/version.js';
8
- import { SYSTEMTIME } from '../lib/windows/structs.js';
9
- // 进程内存跟进读:ffi 只有 readByte(无 DataView/写通道),u32 小端拼值 / 指针随位宽
10
- // (| 是有符号 32 位运算,>>> 0 归一无符号——0xFEEF04BD 类高位值否则读成负数)
11
- function readU32At(addr) {
12
- return (ffi.readByte(addr) | (ffi.readByte(addr + 1) << 8) |
13
- (ffi.readByte(addr + 2) << 16) | (ffi.readByte(addr + 3) << 24)) >>> 0;
14
- }
15
- function readPtr(dv, offset) {
16
- if (os.arch === 'ia32')
17
- return dv.getUint32(offset, true);
18
- return dv.getUint32(offset, true) + dv.getUint32(offset + 4, true) * 4294967296;
19
- }
20
- export const suite = {
21
- name: 'sysinfo',
22
- run: (t) => {
23
- t.section('QueryPerformanceCounter: frequency + monotonic');
24
- const freqB = new PtrArrayBuffer(8);
25
- t.checkTrue('QueryPerformanceFrequency ok', QueryPerformanceFrequency(freqB) !== 0);
26
- const freq = new DataView(freqB).getBigInt64(0, true);
27
- t.checkTrue(`frequency sane (${freq})`, freq > 0n);
28
- const c1 = new PtrArrayBuffer(8);
29
- const c2 = new PtrArrayBuffer(8);
30
- QueryPerformanceCounter(c1);
31
- QueryPerformanceCounter(c2);
32
- const v1 = new DataView(c1).getBigInt64(0, true);
33
- const v2 = new DataView(c2).getBigInt64(0, true);
34
- t.checkTrue(`counter monotonic (${v1} <= ${v2})`, v1 <= v2);
35
- t.section('Sleep: QPC-measured elapsed lands in interval');
36
- QueryPerformanceCounter(c1);
37
- Sleep(50);
38
- QueryPerformanceCounter(c2);
39
- const elapsedMs = Number((new DataView(c2).getBigInt64(0, true) -
40
- new DataView(c1).getBigInt64(0, true)) * 1000n / freq);
41
- t.checkTrue(`Sleep(50) -> ${elapsedMs}ms in [30, 3000)`, elapsedMs >= 30 && elapsedMs < 3000);
42
- t.section('GetLocalTime / GetSystemTimeAsFileTime');
43
- const st = SYSTEMTIME.alloc();
44
- GetLocalTime(st.ptr);
45
- const got = SYSTEMTIME.decode(st);
46
- t.checkTrue(`year sane (${got.wYear})`, got.wYear >= 2024 && got.wYear <= 2100);
47
- t.checkTrue(`month sane (${got.wMonth})`, got.wMonth >= 1 && got.wMonth <= 12);
48
- const ftB = new PtrArrayBuffer(8);
49
- GetSystemTimeAsFileTime(ftB);
50
- const ft = new DataView(ftB).getBigUint64(0, true);
51
- t.checkTrue(`FILETIME > 0 (${ft})`, ft > 0n);
52
- t.section('env / computer name / module path');
53
- const pathW = WCHAR.alloc(4096);
54
- const pathLen = GetEnvironmentVariable('PATH', pathW, 4096);
55
- t.checkTrue(`PATH non-empty (${pathLen} chars)`, pathLen > 0);
56
- const nameW = WCHAR.alloc(260);
57
- const nameLenB = new PtrArrayBuffer(4);
58
- new Uint32Array(nameLenB)[0] = 260;
59
- t.checkTrue('GetComputerName ok', GetComputerName(nameW, nameLenB) !== 0);
60
- const compName = WCHAR.decode(nameW);
61
- t.checkTrue(`computer name non-empty (${compName})`, compName.length > 0);
62
- const modW = WCHAR.alloc(520);
63
- const modLen = GetModuleFileName(NULL, modW, 520);
64
- const modPath = WCHAR.decode(modW);
65
- t.checkTrue(`exe path has qwin (${modLen > 0})`, /qwin/i.test(modPath));
66
- // 生产绑定的返回位 `<WCHAR>ptr!`:内建 WCHAR 自动解码 + `!` 非空担保(直接 string)
67
- const cmdLine = GetCommandLineW();
68
- t.checkTrue(`GetCommandLineW decodes to non-empty string (${cmdLine.length} chars)`, typeof cmdLine === 'string' && cmdLine.length > 0);
69
- t.section('FormatMessage: error 2 -> readable text');
70
- const msgW = WCHAR.alloc(512);
71
- const msgLen = FormatMessage(0x1200 /* FROM_SYSTEM | IGNORE_INSERTS */, NULL, 2 /* ERROR_FILE_NOT_FOUND */, 0, msgW, 512, NULL);
72
- // 语言无关断言(VM 中/英文系统都可过):错误 2 的系统文字必然 > 4 字符
73
- t.checkTrue(`error 2 message non-empty (${msgLen} chars)`, msgLen > 4);
74
- t.section('clipboard roundtrip: CF_UNICODETEXT (GlobalAlloc/RtlMoveMemory)');
75
- t.checkTrue('OpenClipboard', OpenClipboard(NULL) !== 0);
76
- t.checkTrue('EmptyClipboard', EmptyClipboard() !== 0);
77
- const clipText = 'QuickWin clip roundtrip 你好';
78
- const clipSrc = WCHAR.encode(clipText); // 自带 NUL 终止
79
- const hMem = GlobalAlloc(0x2 /* GMEM_MOVEABLE */, clipSrc.byteLength);
80
- t.checkTrue(`GlobalAlloc valid (${hMem})`, hMem !== 0);
81
- const clipDst = GlobalLock(hMem);
82
- t.checkTrue(`GlobalLock address (${clipDst})`, clipDst !== 0);
83
- RtlMoveMemory(clipDst, clipSrc, clipSrc.byteLength);
84
- GlobalUnlock(hMem);
85
- const setR = SetClipboardData(13 /* CF_UNICODETEXT */, hMem);
86
- t.checkTrue('SetClipboardData (ownership -> system)', setR !== 0);
87
- CloseClipboard();
88
- t.checkTrue('OpenClipboard (read back)', OpenClipboard(NULL) !== 0);
89
- const hRead = GetClipboardData(13);
90
- t.checkTrue('GetClipboardData handle', hRead !== 0);
91
- const pRead = hRead ? GlobalLock(hRead) : 0;
92
- const back = pRead ? WCHAR.decode(pRead) : '';
93
- if (pRead)
94
- GlobalUnlock(hRead);
95
- CloseClipboard();
96
- t.check('clip text roundtrip', clipText, back);
97
- t.checkTrue('RegisterClipboardFormat', RegisterClipboardFormat('QuickWinClipFmt') !== 0);
98
- t.section('version resource of kernel32.dll');
99
- const sysW = WCHAR.alloc(300);
100
- GetSystemDirectory(sysW, 300); // 尾不带反斜杠
101
- const k32Path = `${WCHAR.decode(sysW)}\\kernel32.dll`;
102
- const hB = new PtrArrayBuffer(4);
103
- const vSize = GetFileVersionInfoSize(k32Path, hB);
104
- t.checkTrue(`version size > 0 (${vSize})`, vSize > 0);
105
- if (vSize > 0) {
106
- const vHandle = new Uint32Array(hB)[0];
107
- const vBuf = new PtrArrayBuffer(vSize);
108
- t.checkTrue('GetFileVersionInfo', GetFileVersionInfo(k32Path, vHandle, vSize, vBuf) !== 0);
109
- const pBuf = new PtrArrayBuffer(8);
110
- const pLen = new PtrArrayBuffer(4);
111
- t.checkTrue('VerQueryValue root block', VerQueryValue(vBuf, '\\', pBuf, pLen) !== 0);
112
- const rootAddr = readPtr(new DataView(pBuf), 0);
113
- const rootLen = new Uint32Array(pLen)[0];
114
- t.checkTrue(`VS_FIXEDFILEINFO len >= 52 (${rootLen})`, rootLen >= 52);
115
- t.check('VS_FIXEDFILEINFO signature', 0xfeef04bd, readU32At(rootAddr));
116
- const fms = readU32At(rootAddr + 8);
117
- const fls = readU32At(rootAddr + 12);
118
- const ver = `${fms >>> 16}.${fms & 0xffff}.${fls >>> 16}.${fls & 0xffff}`;
119
- t.checkTrue(`file version sane (${ver})`, fms !== 0 || fls !== 0);
120
- }
121
- },
122
- };
@@ -1,141 +0,0 @@
1
- import * as ffi from 'ffi'
2
- import * as os from 'os'
3
- import { WCHAR } from '../lib/ffi/bind.js'
4
- import { NULL, PtrArrayBuffer, type Ptr } from '../lib/ffi/ctype.js'
5
- import {
6
- FormatMessage, GetCommandLineW, GetComputerName, GetEnvironmentVariable,
7
- GetLocalTime, GetModuleFileName, GetSystemDirectory, GetSystemTimeAsFileTime,
8
- GlobalAlloc, GlobalLock, GlobalUnlock, QueryPerformanceCounter,
9
- QueryPerformanceFrequency, RtlMoveMemory, Sleep,
10
- } from '../lib/windows/kernel32.js'
11
- import {
12
- CloseClipboard, EmptyClipboard, GetClipboardData, OpenClipboard,
13
- RegisterClipboardFormat, SetClipboardData,
14
- } from '../lib/windows/user32.js'
15
- import {
16
- GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue,
17
- } from '../lib/windows/version.js'
18
- import { SYSTEMTIME } from '../lib/windows/structs.js'
19
- import { Tester } from './test_helper.js'
20
-
21
- // 进程内存跟进读:ffi 只有 readByte(无 DataView/写通道),u32 小端拼值 / 指针随位宽
22
- // (| 是有符号 32 位运算,>>> 0 归一无符号——0xFEEF04BD 类高位值否则读成负数)
23
- function readU32At(addr: number): number {
24
- return (ffi.readByte(addr) | (ffi.readByte(addr + 1) << 8) |
25
- (ffi.readByte(addr + 2) << 16) | (ffi.readByte(addr + 3) << 24)) >>> 0
26
- }
27
- function readPtr(dv: DataView, offset: number): number {
28
- if (os.arch === 'ia32') return dv.getUint32(offset, true)
29
- return dv.getUint32(offset, true) + dv.getUint32(offset + 4, true) * 4294967296
30
- }
31
-
32
- export const suite = {
33
- name: 'sysinfo',
34
- run: (t: Tester) => {
35
- t.section('QueryPerformanceCounter: frequency + monotonic')
36
- const freqB = new PtrArrayBuffer(8)
37
- t.checkTrue('QueryPerformanceFrequency ok', QueryPerformanceFrequency(freqB) !== 0)
38
- const freq = new DataView(freqB).getBigInt64(0, true)
39
- t.checkTrue(`frequency sane (${freq})`, freq > 0n)
40
- const c1 = new PtrArrayBuffer(8)
41
- const c2 = new PtrArrayBuffer(8)
42
- QueryPerformanceCounter(c1)
43
- QueryPerformanceCounter(c2)
44
- const v1 = new DataView(c1).getBigInt64(0, true)
45
- const v2 = new DataView(c2).getBigInt64(0, true)
46
- t.checkTrue(`counter monotonic (${v1} <= ${v2})`, v1 <= v2)
47
-
48
- t.section('Sleep: QPC-measured elapsed lands in interval')
49
- QueryPerformanceCounter(c1)
50
- Sleep(50)
51
- QueryPerformanceCounter(c2)
52
- const elapsedMs = Number((new DataView(c2).getBigInt64(0, true) -
53
- new DataView(c1).getBigInt64(0, true)) * 1000n / freq)
54
- t.checkTrue(`Sleep(50) -> ${elapsedMs}ms in [30, 3000)`, elapsedMs >= 30 && elapsedMs < 3000)
55
-
56
- t.section('GetLocalTime / GetSystemTimeAsFileTime')
57
- const st = SYSTEMTIME.alloc()
58
- GetLocalTime(st.ptr)
59
- const got = SYSTEMTIME.decode(st)
60
- t.checkTrue(`year sane (${got.wYear})`, got.wYear >= 2024 && got.wYear <= 2100)
61
- t.checkTrue(`month sane (${got.wMonth})`, got.wMonth >= 1 && got.wMonth <= 12)
62
- const ftB = new PtrArrayBuffer(8)
63
- GetSystemTimeAsFileTime(ftB)
64
- const ft = new DataView(ftB).getBigUint64(0, true)
65
- t.checkTrue(`FILETIME > 0 (${ft})`, ft > 0n)
66
-
67
- t.section('env / computer name / module path')
68
- const pathW = WCHAR.alloc(4096)
69
- const pathLen = GetEnvironmentVariable('PATH', pathW, 4096)
70
- t.checkTrue(`PATH non-empty (${pathLen} chars)`, pathLen > 0)
71
- const nameW = WCHAR.alloc(260)
72
- const nameLenB = new PtrArrayBuffer(4)
73
- new Uint32Array(nameLenB)[0] = 260
74
- t.checkTrue('GetComputerName ok', GetComputerName(nameW, nameLenB) !== 0)
75
- const compName = WCHAR.decode(nameW)
76
- t.checkTrue(`computer name non-empty (${compName})`, compName.length > 0)
77
- const modW = WCHAR.alloc(520)
78
- const modLen = GetModuleFileName(NULL, modW, 520)
79
- const modPath = WCHAR.decode(modW)
80
- t.checkTrue(`exe path has qwin (${modLen > 0})`, /qwin/i.test(modPath))
81
- // 生产绑定的返回位 `<WCHAR>ptr!`:内建 WCHAR 自动解码 + `!` 非空担保(直接 string)
82
- const cmdLine = GetCommandLineW()
83
- t.checkTrue(`GetCommandLineW decodes to non-empty string (${cmdLine.length} chars)`,
84
- typeof cmdLine === 'string' && cmdLine.length > 0)
85
-
86
- t.section('FormatMessage: error 2 -> readable text')
87
- const msgW = WCHAR.alloc(512)
88
- const msgLen = FormatMessage(0x1200 /* FROM_SYSTEM | IGNORE_INSERTS */,
89
- NULL, 2 /* ERROR_FILE_NOT_FOUND */, 0, msgW, 512, NULL)
90
- // 语言无关断言(VM 中/英文系统都可过):错误 2 的系统文字必然 > 4 字符
91
- t.checkTrue(`error 2 message non-empty (${msgLen} chars)`, msgLen > 4)
92
-
93
- t.section('clipboard roundtrip: CF_UNICODETEXT (GlobalAlloc/RtlMoveMemory)')
94
- t.checkTrue('OpenClipboard', OpenClipboard(NULL) !== 0)
95
- t.checkTrue('EmptyClipboard', EmptyClipboard() !== 0)
96
- const clipText = 'QuickWin clip roundtrip 你好'
97
- const clipSrc = WCHAR.encode(clipText) // 自带 NUL 终止
98
- const hMem = GlobalAlloc(0x2 /* GMEM_MOVEABLE */, clipSrc.byteLength)
99
- t.checkTrue(`GlobalAlloc valid (${hMem})`, hMem !== 0)
100
- const clipDst = GlobalLock(hMem)
101
- t.checkTrue(`GlobalLock address (${clipDst})`, clipDst !== 0)
102
- RtlMoveMemory(clipDst, clipSrc, clipSrc.byteLength)
103
- GlobalUnlock(hMem)
104
- const setR = SetClipboardData(13 /* CF_UNICODETEXT */, hMem)
105
- t.checkTrue('SetClipboardData (ownership -> system)', setR !== 0)
106
- CloseClipboard()
107
- t.checkTrue('OpenClipboard (read back)', OpenClipboard(NULL) !== 0)
108
- const hRead = GetClipboardData(13)
109
- t.checkTrue('GetClipboardData handle', hRead !== 0)
110
- const pRead = hRead ? GlobalLock(hRead) : 0
111
- const back = pRead ? WCHAR.decode(pRead as Ptr<'WCHAR'>) : ''
112
- if (pRead) GlobalUnlock(hRead)
113
- CloseClipboard()
114
- t.check('clip text roundtrip', clipText, back)
115
- t.checkTrue('RegisterClipboardFormat', RegisterClipboardFormat('QuickWinClipFmt') !== 0)
116
-
117
- t.section('version resource of kernel32.dll')
118
- const sysW = WCHAR.alloc(300)
119
- GetSystemDirectory(sysW, 300) // 尾不带反斜杠
120
- const k32Path = `${WCHAR.decode(sysW)}\\kernel32.dll`
121
- const hB = new PtrArrayBuffer(4)
122
- const vSize = GetFileVersionInfoSize(k32Path, hB)
123
- t.checkTrue(`version size > 0 (${vSize})`, vSize > 0)
124
- if (vSize > 0) {
125
- const vHandle = new Uint32Array(hB)[0]!
126
- const vBuf = new PtrArrayBuffer(vSize)
127
- t.checkTrue('GetFileVersionInfo', GetFileVersionInfo(k32Path, vHandle, vSize, vBuf) !== 0)
128
- const pBuf = new PtrArrayBuffer(8)
129
- const pLen = new PtrArrayBuffer(4)
130
- t.checkTrue('VerQueryValue root block', VerQueryValue(vBuf, '\\', pBuf, pLen) !== 0)
131
- const rootAddr = readPtr(new DataView(pBuf), 0)
132
- const rootLen = new Uint32Array(pLen)[0]
133
- t.checkTrue(`VS_FIXEDFILEINFO len >= 52 (${rootLen})`, rootLen! >= 52)
134
- t.check('VS_FIXEDFILEINFO signature', 0xfeef04bd, readU32At(rootAddr))
135
- const fms = readU32At(rootAddr + 8)
136
- const fls = readU32At(rootAddr + 12)
137
- const ver = `${fms >>> 16}.${fms & 0xffff}.${fls >>> 16}.${fls & 0xffff}`
138
- t.checkTrue(`file version sane (${ver})`, fms !== 0 || fls !== 0)
139
- }
140
- },
141
- }
package/test/test_url.js DELETED
@@ -1,173 +0,0 @@
1
- import '../lib/url.js';
2
- export const suite = {
3
- name: 'url',
4
- run: (t) => {
5
- t.section('http parse');
6
- const u = new URL('http://example.com');
7
- t.check('href', 'http://example.com/', u.href);
8
- t.check('protocol', 'http:', u.protocol);
9
- t.check('hostname', 'example.com', u.hostname);
10
- t.check('port', '', u.port);
11
- t.check('pathname', '/', u.pathname);
12
- t.check('host', 'example.com', u.host);
13
- t.check('origin', 'http://example.com', u.origin);
14
- t.section('full http');
15
- const u2 = new URL('https://user:pass@host.com:443/path/to?q=1&r=2#frag');
16
- t.check('protocol', 'https:', u2.protocol);
17
- t.check('username', 'user', u2.username);
18
- t.check('password', 'pass', u2.password);
19
- t.check('hostname', 'host.com', u2.hostname);
20
- t.check('port', '443', u2.port);
21
- t.check('pathname', '/path/to', u2.pathname);
22
- t.check('search', '?q=1&r=2', u2.search);
23
- t.check('hash', '#frag', u2.hash);
24
- t.check('host', 'host.com:443', u2.host);
25
- t.section('query string params');
26
- t.check('get q', '1', u2.searchParams.get('q'));
27
- t.check('get r', '2', u2.searchParams.get('r'));
28
- t.check('has q', true, u2.searchParams.has('q'));
29
- t.check('has x', false, u2.searchParams.has('x'));
30
- t.section('relative resolution');
31
- const b = new URL('./add.wasm', 'http://example.com/base/');
32
- t.check('relative path', 'http://example.com/base/add.wasm', b.href);
33
- const b2 = new URL('../other', 'http://example.com/base/');
34
- t.check('up one dir', 'http://example.com/other', b2.href);
35
- const b3 = new URL('/abs', 'http://example.com/base/');
36
- t.check('absolute path', 'http://example.com/abs', b3.href);
37
- const b4 = new URL('//other.com:8080/path', 'http://example.com/base/');
38
- t.check('protocol-relative', 'http://other.com:8080/path', b4.href);
39
- t.section('file URL');
40
- const f = new URL('file:///C:/Users/test/file.js');
41
- t.check('protocol', 'file:', f.protocol);
42
- t.check('hostname', '', f.hostname);
43
- t.check('pathname', '/C:/Users/test/file.js', f.pathname);
44
- t.section('file relative resolution');
45
- const f2 = new URL('./add.wasm', 'file:///C:/Users/test/helper.js');
46
- t.check('file relative', 'file:///C:/Users/test/add.wasm', f2.href);
47
- const f3 = new URL('../other.wasm', 'file:///C:/Users/test/sub/helper.js');
48
- t.check('file up dir', 'file:///C:/Users/test/other.wasm', f3.href);
49
- t.section('URLSearchParams');
50
- const p = new URLSearchParams('a=1&b=2&a=3');
51
- t.check('get a', '1', p.get('a'));
52
- t.check('getAll a', 2, p.getAll('a').length);
53
- t.check('get b', '2', p.get('b'));
54
- t.check('has c', false, p.has('c'));
55
- t.check('size', 3, p.size);
56
- t.section('URLSearchParams set/append/delete');
57
- const p2 = new URLSearchParams();
58
- p2.append('key', 'val1');
59
- p2.append('key', 'val2');
60
- t.check('append 2', 2, p2.getAll('key').length);
61
- p2.set('key', 'new');
62
- t.check('set replaces', 1, p2.getAll('key').length);
63
- t.check('set value', 'new', p2.get('key'));
64
- p2.append('x', 'y');
65
- p2.delete('x');
66
- t.check('delete', false, p2.has('x'));
67
- t.section('URLSearchParams toString');
68
- const p3 = new URLSearchParams('q=hello&r=world');
69
- t.check('toString', 'q=hello&r=world', p3.toString());
70
- t.section('URLSearchParams iterator');
71
- const p4 = new URLSearchParams('a=1&b=2');
72
- const keys = [];
73
- for (const k of p4.keys())
74
- keys.push(k);
75
- t.check('keys', 'a,b', keys.join(','));
76
- t.section('URL toJSON');
77
- const j = new URL('http://example.com/path');
78
- t.check('toJSON', 'http://example.com/path', j.toJSON());
79
- t.section('URL toString');
80
- t.check('toString', 'http://example.com/path', j.toString());
81
- t.section('IPv6');
82
- const v6 = new URL('http://[::1]:8080/path');
83
- t.check('hostname', '::1', v6.hostname);
84
- t.check('port', '8080', v6.port);
85
- t.check('host', '[::1]:8080', v6.host);
86
- t.check('pathname', '/path', v6.pathname);
87
- const v6b = new URL('http://[2001:db8::1]/');
88
- t.check('IPv6 no port', '2001:db8::1', v6b.hostname);
89
- t.check('IPv6 host', '[2001:db8::1]', v6b.host);
90
- const v6c = new URL('http://[::1]:8080');
91
- t.check('IPv6 origin', 'http://[::1]:8080', v6c.origin);
92
- t.section('ws/wss');
93
- const ws = new URL('ws://example.com/socket');
94
- t.check('ws protocol', 'ws:', ws.protocol);
95
- t.check('ws hostname', 'example.com', ws.hostname);
96
- t.check('ws pathname', '/socket', ws.pathname);
97
- const wss = new URL('wss://secure.com:9090/chat');
98
- t.check('wss port', '9090', wss.port);
99
- t.section('relative fragment/query');
100
- const rf = new URL('#top', 'http://example.com/path');
101
- t.check('fragment-only', 'http://example.com/path#top', rf.href);
102
- const rq = new URL('?q=1', 'http://example.com/path');
103
- t.check('query-only', 'http://example.com/path?q=1', rq.href);
104
- const rqf = new URL('?a=1#hash', 'http://example.com/path');
105
- t.check('query+frag', 'http://example.com/path?a=1#hash', rqf.href);
106
- t.section('path normalization');
107
- const np1 = new URL('a/../../other', 'http://example.com/base/');
108
- t.check('multi up', 'http://example.com/other', np1.href);
109
- const np2 = new URL('/../other', 'http://example.com/base/');
110
- t.check('root up', 'http://example.com/other', np2.href);
111
- const np3 = new URL('.', 'http://example.com/base/');
112
- t.check('dot only', 'http://example.com/base', np3.href);
113
- const np4 = new URL('', 'http://example.com/base/');
114
- t.check('empty relative', 'http://example.com/base/', np4.href);
115
- t.section('IP address');
116
- const ip = new URL('http://127.0.0.1:8080/path');
117
- t.check('ip hostname', '127.0.0.1', ip.hostname);
118
- t.check('ip port', '8080', ip.port);
119
- t.section('URLSearchParams values/entries/forEach');
120
- const pv = new URLSearchParams('a=1&b=2');
121
- const vals = [];
122
- for (const v of pv.values())
123
- vals.push(v);
124
- t.check('values', '1,2', vals.join(','));
125
- const entries = [];
126
- for (const [k, v] of pv.entries())
127
- entries.push(k + '=' + v);
128
- t.check('entries', 'a=1,b=2', entries.join(','));
129
- let forEachStr = '';
130
- pv.forEach((v, k) => { forEachStr += k + '=' + v + '|'; });
131
- t.check('forEach', 'a=1|b=2|', forEachStr);
132
- const ps = new URLSearchParams('b=2&a=1&c=3');
133
- ps.sort();
134
- t.check('sort', 'a=1&b=2&c=3', ps.toString());
135
- t.section('URLSearchParams edge cases');
136
- const pe1 = new URLSearchParams('a=1&b');
137
- t.check('empty value', '', pe1.get('b'));
138
- const pe2 = new URLSearchParams('?a=1&b=2');
139
- t.check('leading ?', '1', pe2.get('a'));
140
- const pe3 = new URLSearchParams([['x', '10'], ['y', '20']]);
141
- t.check('array init', '10', pe3.get('x'));
142
- t.check('array init 2', '20', pe3.get('y'));
143
- t.check('array size', 2, pe3.size);
144
- t.section('encoded chars');
145
- const enc = new URL('http://example.com/hello%20world');
146
- t.check('encoded pathname', '/hello%20world', enc.pathname);
147
- const encq = new URL('http://example.com/path?q=a+b&r=%25');
148
- t.check('encoded query +→space', 'a b', encq.searchParams.get('q'));
149
- t.check('encoded query %25', '%', encq.searchParams.get('r'));
150
- t.section('null/undefined base');
151
- let threw = false;
152
- try {
153
- new URL('/path', null);
154
- }
155
- catch {
156
- threw = true;
157
- }
158
- t.check('null base throws', true, threw);
159
- threw = false;
160
- try {
161
- new URL('relative');
162
- }
163
- catch {
164
- threw = true;
165
- }
166
- t.check('no base throws', true, threw);
167
- t.section('data URL');
168
- const d = new URL('data:text/plain,hello');
169
- t.check('data protocol', 'data:', d.protocol);
170
- t.check('data hostname', '', d.hostname);
171
- t.check('data pathname', 'text/plain,hello', d.pathname);
172
- }
173
- };