quickwin 3.0.1 → 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 (163) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/package.json +1 -3
  4. package/qwin-nowasm-x86.exe +0 -0
  5. package/qwin-nowasm.exe +0 -0
  6. package/qwin-x86.exe +0 -0
  7. package/qwin.exe +0 -0
  8. package/examples/PdfCanvas.js +0 -38
  9. package/examples/PdfCanvas.tsx +0 -54
  10. package/examples/execd/main.js +0 -23379
  11. package/examples/execd/tray.js +0 -192
  12. package/examples/execd/worker.js +0 -122
  13. package/examples/pdf_preview2.js +0 -398
  14. package/examples/pdf_preview2.ts +0 -353
  15. package/examples/pdf_viewer.js +0 -22515
  16. package/examples/pdf_viewer.tsx +0 -228
  17. package/examples/test_gallery.js +0 -18692
  18. package/examples/test_gallery.tsx +0 -291
  19. package/examples/test_react_lazy.js +0 -18560
  20. package/examples/test_react_lazy.tsx +0 -65
  21. package/examples/test_react_listbox.js +0 -18562
  22. package/examples/test_react_listbox.tsx +0 -73
  23. package/examples/test_root_window.js +0 -18532
  24. package/examples/test_root_window.tsx +0 -41
  25. package/examples/test_tab.js +0 -18563
  26. package/examples/test_tab.tsx +0 -77
  27. package/examples/tray_demo.js +0 -86
  28. package/examples/tray_demo.tsx +0 -89
  29. package/test/add.wasm +0 -0
  30. package/test/bench_ffi_callraw.js +0 -235
  31. package/test/bench_ffi_callraw.ts +0 -235
  32. package/test/bench_ffi_overhead.js +0 -139
  33. package/test/bench_ffi_overhead.ts +0 -141
  34. package/test/bench_sendmessage.js +0 -104
  35. package/test/bench_sendmessage.ts +0 -100
  36. package/test/bench_sendmessage_nonnull.js +0 -187
  37. package/test/bench_sendmessage_nonnull.ts +0 -188
  38. package/test/complex.wasm +0 -0
  39. package/test/complex_imports.wasm +0 -0
  40. package/test/debug/http_server_e2e.js +0 -31
  41. package/test/debug/minwasm.js +0 -52
  42. package/test/debug/mupdf_debug.js +0 -86
  43. package/test/debug/wasm.js +0 -122
  44. package/test/debug/wasm_export_debug.js +0 -54
  45. package/test/debug/wasm_names.js +0 -36
  46. package/test/example.pdf +0 -0
  47. package/test/global_imports.wasm +0 -0
  48. package/test/import_func.wasm +0 -0
  49. package/test/imports.wasm +0 -0
  50. package/test/mupdf-cdn.js +0 -40
  51. package/test/mupdf-cdn.ts +0 -43
  52. package/test/run.js +0 -111
  53. package/test/run.ts +0 -116
  54. package/test/sjlj.wasm +0 -0
  55. package/test/test_basic.js +0 -7
  56. package/test/test_basic.ts +0 -9
  57. package/test/test_basic_fetch.js +0 -63
  58. package/test/test_basic_fetch.ts +0 -59
  59. package/test/test_brotli.js +0 -48
  60. package/test/test_brotli.ts +0 -52
  61. package/test/test_fetch_cache.js +0 -169
  62. package/test/test_fetch_cache.ts +0 -187
  63. package/test/test_ffi.js +0 -157
  64. package/test/test_ffi.ts +0 -170
  65. package/test/test_ffi_abi.js +0 -290
  66. package/test/test_ffi_abi.ts +0 -274
  67. package/test/test_ffi_array.js +0 -116
  68. package/test/test_ffi_array.ts +0 -141
  69. package/test/test_ffi_bind.js +0 -656
  70. package/test/test_ffi_bind.ts +0 -670
  71. package/test/test_ffi_struct.js +0 -779
  72. package/test/test_ffi_struct.ts +0 -828
  73. package/test/test_ffi_struct_layout.js +0 -495
  74. package/test/test_ffi_struct_layout.ts +0 -543
  75. package/test/test_ffi_user32.js +0 -103
  76. package/test/test_ffi_user32.ts +0 -113
  77. package/test/test_ffi_windows.js +0 -172
  78. package/test/test_ffi_windows.ts +0 -187
  79. package/test/test_files.js +0 -102
  80. package/test/test_files.ts +0 -121
  81. package/test/test_frame_encoding.js +0 -128
  82. package/test/test_frame_encoding.ts +0 -132
  83. package/test/test_gdi_draw.js +0 -681
  84. package/test/test_gdi_draw.ts +0 -725
  85. package/test/test_helper.js +0 -91
  86. package/test/test_helper.ts +0 -88
  87. package/test/test_http_import.js +0 -96
  88. package/test/test_http_import.ts +0 -93
  89. package/test/test_http_server.js +0 -214
  90. package/test/test_http_server.ts +0 -211
  91. package/test/test_import_dir.js +0 -4
  92. package/test/test_import_dir.ts +0 -5
  93. package/test/test_ipv6.js +0 -134
  94. package/test/test_ipv6.ts +0 -130
  95. package/test/test_jsx.js +0 -1314
  96. package/test/test_meta_url.js +0 -3
  97. package/test/test_meta_url.ts +0 -4
  98. package/test/test_mupdf_render.js +0 -51
  99. package/test/test_mupdf_render.ts +0 -55
  100. package/test/test_mupdf_twice.js +0 -62
  101. package/test/test_mupdf_twice.ts +0 -65
  102. package/test/test_mupdf_wasm.js +0 -39
  103. package/test/test_mupdf_wasm.ts +0 -32
  104. package/test/test_net_event.js +0 -57
  105. package/test/test_net_event.ts +0 -56
  106. package/test/test_net_fetch.js +0 -384
  107. package/test/test_net_fetch.ts +0 -373
  108. package/test/test_net_websocket.js +0 -180
  109. package/test/test_net_websocket.ts +0 -164
  110. package/test/test_polyfill.js +0 -144
  111. package/test/test_polyfill.ts +0 -159
  112. package/test/test_printer.js +0 -137
  113. package/test/test_printer.ts +0 -148
  114. package/test/test_proc.js +0 -141
  115. package/test/test_proc.ts +0 -163
  116. package/test/test_react_complex.js +0 -18678
  117. package/test/test_react_counter.js +0 -18555
  118. package/test/test_react_flex.js +0 -18871
  119. package/test/test_react_hidden.js +0 -18560
  120. package/test/test_react_listview_link.js +0 -18590
  121. package/test/test_react_notify.js +0 -18797
  122. package/test/test_react_render.js +0 -18550
  123. package/test/test_registry.js +0 -74
  124. package/test/test_registry.ts +0 -95
  125. package/test/test_sysinfo.js +0 -122
  126. package/test/test_sysinfo.ts +0 -141
  127. package/test/test_url.js +0 -173
  128. package/test/test_url.ts +0 -183
  129. package/test/test_wasm_basic.js +0 -85
  130. package/test/test_wasm_basic.ts +0 -73
  131. package/test/test_wasm_import_global.js +0 -41
  132. package/test/test_wasm_import_global.ts +0 -45
  133. package/test/test_wasm_sjlj.js +0 -145
  134. package/test/test_wasm_sjlj.ts +0 -125
  135. package/test/test_wasm_types.js +0 -97
  136. package/test/test_wasm_types.ts +0 -124
  137. package/test/test_wolfssl_read.js +0 -203
  138. package/test/test_wolfssl_read.ts +0 -184
  139. package/test/test_worker.js +0 -21
  140. package/test/test_worker.ts +0 -24
  141. package/test/test_worker_concurrent.js +0 -45
  142. package/test/test_worker_concurrent.ts +0 -56
  143. package/test/test_worker_data_url.js +0 -46
  144. package/test/test_worker_data_url.ts +0 -51
  145. package/test/test_worker_fetch.js +0 -26
  146. package/test/test_worker_fetch.ts +0 -27
  147. package/test/test_worker_net.js +0 -69
  148. package/test/test_worker_net.ts +0 -66
  149. package/test/test_worker_wasm_concurrent.js +0 -44
  150. package/test/test_worker_wasm_concurrent.ts +0 -45
  151. package/test/types.wasm +0 -0
  152. package/test/worker_fetch.js +0 -13
  153. package/test/worker_fetch.ts +0 -13
  154. package/test/worker_helper.js +0 -1
  155. package/test/worker_helper.ts +0 -1
  156. package/test/worker_http.js +0 -18
  157. package/test/worker_http.ts +0 -20
  158. package/test/worker_import_lib.js +0 -12
  159. package/test/worker_import_lib.ts +0 -13
  160. package/test/worker_module.js +0 -16
  161. package/test/worker_module.ts +0 -17
  162. package/test/worker_wasm_concurrent.js +0 -22
  163. package/test/worker_wasm_concurrent.ts +0 -22
package/test/test_ffi.ts DELETED
@@ -1,170 +0,0 @@
1
- import * as std from 'std'
2
- import * as ffi from 'ffi'
3
- import * as os from 'os'
4
- import { bind, bindLib } from '../lib/ffi/bind.js'
5
- import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js'
6
- import { Tester } from './test_helper.js'
7
-
8
- const MAX_WCHARS = 4096
9
-
10
- function decodeWideAtPtr(ptr: number): string {
11
- if (!ptr) return ''
12
- const chars: number[] = []
13
- let pos = ptr
14
- while (chars.length < MAX_WCHARS) {
15
- const low = ffi.readByte(pos)
16
- const high = ffi.readByte(pos + 1)
17
- const ch = low + high * 256
18
- if (ch === 0) break
19
- chars.push(ch)
20
- pos += 2
21
- }
22
- return String.fromCharCode(...chars)
23
- }
24
-
25
- function readPtr(dv: DataView, offset: number): number {
26
- if (os.arch === 'ia32') {
27
- return dv.getUint32(offset, true)
28
- }
29
- const low = dv.getUint32(offset, true)
30
- const high = dv.getUint32(offset + 4, true)
31
- return low + high * 4294967296
32
- }
33
-
34
- const STATUS_FLAGS: [number, string][] = [
35
- [0x00000001, 'PAUSED'],
36
- [0x00000002, 'ERROR'],
37
- [0x00000004, 'PENDING_DELETION'],
38
- [0x00000008, 'PAPER_JAM'],
39
- [0x00000010, 'PAPER_OUT'],
40
- [0x00000020, 'MANUAL_FEED'],
41
- [0x00000040, 'PAPER_PROBLEM'],
42
- [0x00000080, 'OFFLINE'],
43
- [0x00000100, 'IO_ACTIVE'],
44
- [0x00000200, 'BUSY'],
45
- [0x00000400, 'PRINTING'],
46
- [0x00000800, 'OUTPUT_BIN_FULL'],
47
- [0x00001000, 'NOT_AVAILABLE'],
48
- [0x00002000, 'WAITING'],
49
- [0x00004000, 'PROCESSING'],
50
- [0x00008000, 'INITIALIZING'],
51
- [0x00010000, 'WARMING_UP'],
52
- [0x00020000, 'TONER_LOW'],
53
- [0x00040000, 'NO_TONER'],
54
- [0x00080000, 'PAGE_PUNT'],
55
- [0x00100000, 'USER_INTERVENTION'],
56
- [0x00200000, 'OUT_OF_MEMORY'],
57
- [0x00400000, 'DOOR_OPEN'],
58
- [0x00800000, 'SERVER_UNKNOWN'],
59
- [0x01000000, 'POWER_SAVE'],
60
- [0x02000000, 'SERVER_OFFLINE'],
61
- [0x04000000, 'DRIVER_UPDATE'],
62
- ];
63
-
64
- function formatStatus(status: number): string {
65
- if (status === 0) return 'OK'
66
- const parts: string[] = []
67
- for (const [flag, name] of STATUS_FLAGS) {
68
- if (status & flag) parts.push(name)
69
- }
70
- return parts.join('|') || 'UNKNOWN'
71
- }
72
-
73
- export const suite = {
74
- name: 'ffi',
75
- run: (t: Tester) => {
76
- t.section('EnumPrinters')
77
- const hWinspool = ffi.LoadLibrary('winspool.drv')
78
- t.checkTrue('LoadLibrary("winspool.drv") succeeds', !!hWinspool)
79
- if (!hWinspool) return
80
-
81
- const enumPrinters = ffi.GetProcAddress(hWinspool, 'EnumPrintersW')
82
- t.checkTrue('GetProcAddress("EnumPrintersW") succeeds', !!enumPrinters)
83
- if (!enumPrinters) return
84
-
85
- const { EnumPrintersW: EnumPrinters } = bindLib('winspool.drv', {
86
- EnumPrintersW: 'u32 <>ptr u32 <BYTE>ptr u32 <BYTE>ptr <BYTE>ptr -> i32',
87
- })
88
-
89
- const flags = 0x06
90
- const level = 2
91
- const neededB = new PtrArrayBuffer(4)
92
- const neededBuf = new Uint32Array(neededB)
93
- const returnedB = new PtrArrayBuffer(4)
94
- const returnedBuf = new Uint32Array(returnedB)
95
-
96
- const ret1 = EnumPrinters(flags, NULL, level, NULL, 0, neededB, returnedB)
97
- std.printf(' first call: ret=%d needed=%d returned=%d\n', ret1, neededBuf[0], returnedBuf[0])
98
- if (neededBuf[0]! > 0) {
99
- t.checkTrue('pcbNeeded > 0', neededBuf[0]! > 0)
100
- } else {
101
- // 无打印机环境(CI VM)EnumPrinters 的 pcbNeeded 为 0,属环境差异非缺陷,
102
- // 记 SKIP 而非 FAIL,CI 无需再对 ffi 用例做失败容忍。
103
- t.skipCase('pcbNeeded > 0 (no printers on this VM)')
104
- return
105
- }
106
-
107
- const printerBuf = new PtrArrayBuffer(neededBuf[0]!)
108
- const ret2 = EnumPrinters(
109
- flags,
110
- NULL,
111
- level,
112
- printerBuf,
113
- neededBuf[0]!,
114
- neededB,
115
- returnedB
116
- )
117
- t.checkTrue('EnumPrinters succeeds', ret2 !== 0)
118
- if (ret2 === 0) return
119
-
120
- std.printf(' printers found: %d\n', returnedBuf[0])
121
-
122
- if (returnedBuf[0]! > 0) {
123
- const dv = new DataView(printerBuf)
124
- // PRINTER_INFO_2W layout (MinGW verified):
125
- // x64: sizeof=136 name=8 port=24 drv=32 comment=40 location=48 status=124
126
- // ia32: sizeof=84 name=4 port=12 drv=16 comment=20 location=24 status=72
127
- const ia32 = os.arch === 'ia32'
128
- const structSize = ia32 ? 84 : 136
129
- const offName = ia32 ? 4 : 8
130
- const offPort = ia32 ? 12 : 24
131
- const offDrv = ia32 ? 16 : 32
132
- const offComment = ia32 ? 20 : 40
133
- const offLocation = ia32 ? 24 : 48
134
- const offStatus = ia32 ? 72 : 124
135
-
136
- for (let i = 0; i < returnedBuf[0]! && i < 20; i++) {
137
- const off = i * structSize
138
- const name = decodeWideAtPtr(readPtr(dv, off + offName))
139
- const port = decodeWideAtPtr(readPtr(dv, off + offPort))
140
- const driver = decodeWideAtPtr(readPtr(dv, off + offDrv))
141
- const location = decodeWideAtPtr(readPtr(dv, off + offLocation))
142
- const comment = decodeWideAtPtr(readPtr(dv, off + offComment))
143
- const status = dv.getUint32(off + offStatus, true)
144
- std.printf(' [%d] %s\n', i + 1, name)
145
- std.printf(' port: %s\n', port)
146
- std.printf(' driver: %s\n', driver)
147
- if (location) std.printf(' location: %s\n', location)
148
- if (comment) std.printf(' comment: %s\n', comment)
149
- std.printf(' status: 0x%08X (%s)\n', status, formatStatus(status))
150
- }
151
- } else {
152
- std.printf(' no printers installed (skip)\n')
153
- }
154
-
155
- t.section('PTR accepts raw number handles (XP 32-bit fix)')
156
- const hUser32 = ffi.LoadLibrary('user32.dll')
157
- t.checkTrue('LoadLibrary("user32.dll") succeeds', !!hUser32)
158
- if (hUser32) {
159
- const getDC = ffi.GetProcAddress(hUser32, 'GetDC')
160
- t.checkTrue('GetProcAddress("GetDC") succeeds', !!getDC)
161
- if (getDC) {
162
- const GetDC = bind('user32.dll', 'GetDC', '<>ptr -> <>ptr')
163
- const screenDc = GetDC(0)
164
- t.checkTrue('PTR slot takes number (NULL hwnd) and returns a DC handle', screenDc !== 0)
165
- const bogus = GetDC(0x12345678)
166
- t.checkTrue('PTR slot takes non-zero number without throwing', bogus === 0)
167
- }
168
- }
169
- }
170
- }
@@ -1,290 +0,0 @@
1
- import * as std from 'std';
2
- import * as ffi from 'ffi';
3
- import * as os from 'os';
4
- import { bind } from '../lib/ffi/bind.js';
5
- import { struct } from '../lib/ffi/struct.js';
6
- import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js';
7
- import { POINT, RECT } from '../lib/windows/structs.js';
8
- // ABI 边界回归:覆盖 REMOVE_LIBFFI_PLAN.md §4.2 的维度,全部用真实 Win32/CRT
9
- // 函数(不新增测试专用导出)。缺函数的平台记 SKIP 而非 FAIL,避免环境差异误报。
10
- //
11
- // 维度 → 用例:
12
- // 参数个数 0/1/3/4/5/6/8/12:GetTickCount/fabs/memcpy/GetLocaleInfoA/
13
- // SetRect/CompareStringW/WideCharToMultiByte/SetDIBitsToDevice
14
- // 整浮混合:ldexp(f64,i32)、frexp(f64,ptr)、modf(f64,ptr)
15
- // 前 4 全整数(RCX-R9):GetLocaleInfoA 的 4 个参数
16
- // 负数返回 i32/i16/i8:lstrcmpW;i64:InterlockedIncrement64
17
- // 窄整型负值传参:abs(i8/i16/u8/u16)
18
- // 大 64 位传参:InterlockedExchange64
19
- // 指针 NULL:GetDC(NULL)、IsWindow(NULL);null/undefined 不是指针合法值,应拒绝
20
- function readAscii(buf, len) {
21
- const dv = new DataView(buf);
22
- let s = '';
23
- for (let i = 0; i < len; i++) {
24
- const c = dv.getUint8(i);
25
- if (c === 0)
26
- break;
27
- s += String.fromCharCode(c);
28
- }
29
- return s;
30
- }
31
- function has(dll, name) {
32
- return !!dll && !!ffi.GetProcAddress(dll, name);
33
- }
34
- export const suite = {
35
- name: 'ffi-abi',
36
- run: (t) => {
37
- const k32 = ffi.LoadLibrary('kernel32.dll');
38
- const usr = ffi.LoadLibrary('user32.dll');
39
- const gdi = ffi.LoadLibrary('gdi32.dll');
40
- const crt = ffi.LoadLibrary('msvcrt.dll');
41
- t.section('param count 0 ( -> u32)');
42
- if (has(k32, 'GetTickCount')) {
43
- const getTickCount = bind('kernel32.dll', 'GetTickCount', ' -> u32');
44
- const tc = getTickCount();
45
- t.checkTrue('GetTickCount() > 0', tc > 0);
46
- }
47
- else
48
- t.skipCase('GetTickCount missing');
49
- t.section('param count 1 (f64 -> f64)');
50
- if (has(crt, 'fabs')) {
51
- const fabs = bind('msvcrt.dll', 'fabs', 'f64 -> f64');
52
- t.check('fabs(-3.5)', 3.5, fabs(-3.5));
53
- }
54
- else
55
- t.skipCase('fabs missing');
56
- t.section('param count 3 (<BYTE>ptr <BYTE>ptr u32 -> ptr)');
57
- if (has(crt, 'memcpy')) {
58
- const memcpy = bind('msvcrt.dll', 'memcpy', '<BYTE>ptr <BYTE>ptr u32 -> <>ptr');
59
- const srcB = new PtrArrayBuffer(8);
60
- const src = new Uint8Array(srcB);
61
- src.set([1, 2, 3, 4, 5, 6, 7, 8]);
62
- const dstB = new PtrArrayBuffer(8);
63
- const dst = new Uint8Array(dstB);
64
- const r = memcpy(dstB, srcB, 8);
65
- const rd = Array.from(dst).join(',');
66
- t.check('memcpy copied bytes', '1,2,3,4,5,6,7,8', rd);
67
- t.checkTrue('memcpy returns dest ptr', typeof r === 'number' && r !== 0);
68
- }
69
- else
70
- t.skipCase('memcpy missing');
71
- t.section('param count 4 + all-int-regs (u32 u32 <BYTE>ptr i32 -> i32)');
72
- if (has(k32, 'GetLocaleInfoA')) {
73
- const getLocaleInfoA = bind('kernel32.dll', 'GetLocaleInfoA', 'u32 u32 <BYTE>ptr i32 -> i32');
74
- const buf = new PtrArrayBuffer(64);
75
- const n = getLocaleInfoA(0x0409, 0x00001001 /* LOCALE_SENGLANGUAGE */, buf, 64);
76
- if (n > 0) {
77
- const s = readAscii(buf, n);
78
- std.printf(' GetLocaleInfoA(0x0409, LOCALE_SENGLANGUAGE) = "%s" (%d)\n', s, n);
79
- t.check('en-US language name', 'English', s);
80
- }
81
- else
82
- t.skipCase('en-US locale unavailable');
83
- }
84
- else
85
- t.skipCase('GetLocaleInfoA missing');
86
- t.section('param count 5 (<BYTE>ptr i32 i32 i32 i32 -> i32)');
87
- if (has(usr, 'SetRect')) {
88
- const setRect = bind('user32.dll', 'SetRect', '<BYTE>ptr i32 i32 i32 i32 -> i32');
89
- const rc = new PtrArrayBuffer(16);
90
- const ok = setRect(rc, 1, 2, 30, 40);
91
- const dv = new DataView(rc);
92
- t.checkTrue('SetRect returns nonzero', ok !== 0);
93
- t.check('SetRect left', 1, dv.getInt32(0, true));
94
- t.check('SetRect top', 2, dv.getInt32(4, true));
95
- t.check('SetRect right', 30, dv.getInt32(8, true));
96
- t.check('SetRect bottom', 40, dv.getInt32(12, true));
97
- }
98
- else
99
- t.skipCase('SetRect missing');
100
- t.section('param count 6 (u32 u32 <WCHAR>ptr i32 <WCHAR>ptr i32 -> i32)');
101
- if (has(k32, 'CompareStringW')) {
102
- const compareStringW = bind('kernel32.dll', 'CompareStringW', 'u32 u32 <WCHAR>ptr i32 <WCHAR>ptr i32 -> i32');
103
- const r = compareStringW(0x0400 /* LOCALE_USER_DEFAULT */, 0, 'abc', -1, 'abd', -1);
104
- t.check('CompareStringW("abc","abd") = CSTR_LESS_THAN', 1, r);
105
- }
106
- else
107
- t.skipCase('CompareStringW missing');
108
- t.section('param count 8 (u32 u32 <WCHAR>ptr i32 <BYTE>ptr i32 <>ptr <>ptr -> i32)');
109
- if (has(k32, 'WideCharToMultiByte')) {
110
- const wideCharToMultiByte = bind('kernel32.dll', 'WideCharToMultiByte', 'u32 u32 <WCHAR>ptr i32 <BYTE>ptr i32 <>ptr <>ptr -> i32');
111
- const out = new PtrArrayBuffer(16);
112
- // 显式给长度(cchWideChar=2)避免 -1 空终止语义下返回值是否含 '\0' 的版本差异。
113
- const n = wideCharToMultiByte(0 /* CP_ACP */, 0, 'AB', 2, out, 16, NULL, NULL);
114
- t.check('WideCharToMultiByte char count', 2, n);
115
- t.check('converted byte 0 = A', 65, new DataView(out).getUint8(0));
116
- t.check('converted byte 1 = B', 66, new DataView(out).getUint8(1));
117
- }
118
- else
119
- t.skipCase('WideCharToMultiByte missing');
120
- t.section('param count 12 (SetDIBitsToDevice on memory DC)');
121
- if (has(gdi, 'SetDIBitsToDevice') && has(gdi, 'CreateCompatibleDC') && has(gdi, 'DeleteDC')) {
122
- const createCompatibleDC = bind('gdi32.dll', 'CreateCompatibleDC', '<>ptr -> <>ptr');
123
- const deleteDC = bind('gdi32.dll', 'DeleteDC', '<>ptr -> i32');
124
- const setDIBitsToDevice = bind('gdi32.dll', 'SetDIBitsToDevice', '<>ptr i32 i32 u32 u32 i32 i32 u32 u32 <BYTE>ptr <BYTE>ptr u32 -> i32');
125
- const hdc = createCompatibleDC(0);
126
- if (hdc) {
127
- const bmi = new PtrArrayBuffer(40);
128
- const bdv = new DataView(bmi);
129
- bdv.setUint32(0, 40, true); // biSize
130
- bdv.setInt32(4, 1, true); // biWidth
131
- bdv.setInt32(8, 1, true); // biHeight (bottom-up)
132
- bdv.setUint16(12, 1, true); // biPlanes
133
- bdv.setUint16(14, 32, true); // biBitCount
134
- bdv.setUint32(16, 0, true); // biCompression = BI_RGB
135
- const bits = new PtrArrayBuffer(4);
136
- const lines = setDIBitsToDevice(hdc, 0, 0, 1, 1, 0, 0, 0, 1, bits, bmi, 0 /* DIB_RGB_COLORS */);
137
- t.check('SetDIBitsToDevice scanlines copied', 1, lines);
138
- deleteDC(hdc);
139
- }
140
- else
141
- t.skipCase('CreateCompatibleDC returned NULL');
142
- }
143
- else
144
- t.skipCase('SetDIBitsToDevice/CreateCompatibleDC missing');
145
- t.section('int/float mix: f64 i32 -> f64');
146
- if (has(crt, 'ldexp')) {
147
- const ldexp = bind('msvcrt.dll', 'ldexp', 'f64 i32 -> f64');
148
- t.check('ldexp(1.5, 3)', 12.0, ldexp(1.5, 3));
149
- }
150
- else
151
- t.skipCase('ldexp missing');
152
- t.section('int/float mix: f64 <BYTE>ptr -> f64');
153
- if (has(crt, 'frexp')) {
154
- const frexp = bind('msvcrt.dll', 'frexp', 'f64 <BYTE>ptr -> f64');
155
- const e = new PtrArrayBuffer(4);
156
- const m = frexp(12.0, e);
157
- t.check('frexp(12).mantissa', 0.75, m);
158
- t.check('frexp(12).exponent', 4, new DataView(e).getInt32(0, true));
159
- }
160
- else
161
- t.skipCase('frexp missing');
162
- if (has(crt, 'modf')) {
163
- const modf = bind('msvcrt.dll', 'modf', 'f64 <BYTE>ptr -> f64');
164
- const ip = new PtrArrayBuffer(8);
165
- const frac = modf(3.75, ip);
166
- t.check('modf(3.75).frac', 0.75, frac);
167
- t.check('modf(3.75).int', 3.0, new DataView(ip).getFloat64(0, true));
168
- }
169
- else
170
- t.skipCase('modf missing');
171
- t.section('narrow signed args (msvcrt!abs)');
172
- if (has(crt, 'abs')) {
173
- const absI8 = bind('msvcrt.dll', 'abs', 'i8 -> i32');
174
- const absU8 = bind('msvcrt.dll', 'abs', 'u8 -> i32');
175
- const absI16 = bind('msvcrt.dll', 'abs', 'i16 -> i32');
176
- const absU16 = bind('msvcrt.dll', 'abs', 'u16 -> i32');
177
- t.check('abs(i8 -128)', 128, absI8(-128));
178
- t.check('abs(i8 -5)', 5, absI8(-5));
179
- t.check('abs(u8 200)', 200, absU8(200));
180
- t.check('abs(i16 -300)', 300, absI16(-300));
181
- t.check('abs(u16 60000)', 60000, absU16(60000));
182
- }
183
- else
184
- t.skipCase('abs missing');
185
- t.section('negative return i32/i16/i8 (lstrcmpW)');
186
- if (has(k32, 'lstrcmpW')) {
187
- const cmpI32 = bind('kernel32.dll', 'lstrcmpW', '<WCHAR>ptr <WCHAR>ptr -> i32');
188
- const cmpI16 = bind('kernel32.dll', 'lstrcmpW', '<WCHAR>ptr <WCHAR>ptr -> i16');
189
- const cmpI8 = bind('kernel32.dll', 'lstrcmpW', '<WCHAR>ptr <WCHAR>ptr -> i8');
190
- t.checkTrue('lstrcmpW i32 < 0', cmpI32('a', 'b') < 0);
191
- t.checkTrue('lstrcmpW i16 < 0', cmpI16('a', 'b') < 0);
192
- t.checkTrue('lstrcmpW i8 < 0', cmpI8('a', 'b') < 0);
193
- }
194
- else
195
- t.skipCase('lstrcmpW missing');
196
- t.section('negative return i64 (InterlockedIncrement64)');
197
- if (has(k32, 'InterlockedExchange64') && has(k32, 'InterlockedIncrement64')) {
198
- const exchange64 = bind('kernel32.dll', 'InterlockedExchange64', '<BYTE>ptr i64 -> i64');
199
- const increment64 = bind('kernel32.dll', 'InterlockedIncrement64', '<BYTE>ptr -> i64');
200
- const cell = new PtrArrayBuffer(8);
201
- exchange64(cell, -2n);
202
- t.check('InterlockedIncrement64(-2)', -1n, increment64(cell));
203
- }
204
- else
205
- t.skipCase('Interlocked*64 missing');
206
- t.section('64-bit arg transport (InterlockedExchange64)');
207
- if (has(k32, 'InterlockedExchange64')) {
208
- const exchange64 = bind('kernel32.dll', 'InterlockedExchange64', '<BYTE>ptr i64 -> i64');
209
- const cell = new PtrArrayBuffer(8);
210
- const prev0 = exchange64(cell, 4294967297n); // 2^32+1:超过 32 位
211
- const prev1 = exchange64(cell, -1n); // 64 位全 1
212
- const prev2 = exchange64(cell, 0n);
213
- t.check('exchange empty cell returns 0', 0n, prev0);
214
- t.check('exchange returns 2^32+1', 4294967297n, prev1);
215
- t.check('exchange returns -1', -1n, prev2);
216
- }
217
- else
218
- t.skipCase('InterlockedExchange64 missing');
219
- t.section('ptr NULL/undefined');
220
- if (has(usr, 'GetDC') && has(usr, 'IsWindow')) {
221
- const getDC = bind('user32.dll', 'GetDC', '<>ptr -> <>ptr');
222
- const isWindow = bind('user32.dll', 'IsWindow', '<>ptr -> i32');
223
- t.checkTrue('GetDC(NULL) non-null', !!getDC(NULL));
224
- // undefined / null 不是指针合法值(指针只收 NULL 或有效地址),必须拒绝而非静默当 0。
225
- let errUndef = '';
226
- try {
227
- getDC(undefined);
228
- }
229
- catch (e) {
230
- errUndef = String(e);
231
- }
232
- t.checkTrue('GetDC(undefined) rejected', errUndef.includes('undefined'));
233
- t.check('IsWindow(NULL) = FALSE', 0, isWindow(NULL));
234
- }
235
- else
236
- t.skipCase('GetDC/IsWindow missing');
237
- t.section('by-value struct arg: <POINT> (slot value, not a pointer)');
238
- if (has(usr, 'PtInRect') && has(usr, 'WindowFromPoint') && has(usr, 'ChildWindowFromPointEx')) {
239
- // PtInRect(rect, pt):RECT 按指针、POINT 按值(x64 位置寄存器 / ia32 压 8 字节上栈)。
240
- // 非对称矩形 {0,0,10,100} —— 若 x/y 在打包中交换,(99,5) 与 (5,99) 的判定会互换,
241
- // 本段即可抓出「槽内是地址而非值」「字段顺序/位置错」两类 ABI 错误。
242
- const ptInRect = bind('user32.dll', 'PtInRect', '<RECT>ptr <POINT> -> i32', { RECT, POINT });
243
- const rectOut = RECT.alloc();
244
- const rdv = new DataView(rectOut);
245
- rdv.setInt32(8, 10, true); // right(left/top = 0,零填充)
246
- rdv.setInt32(12, 100, true); // bottom
247
- t.check('PtInRect inside (5,5)', 1, ptInRect(rectOut.ptr, { x: 5, y: 5 }));
248
- t.check('PtInRect inside (5,99)', 1, ptInRect(rectOut.ptr, { x: 5, y: 99 }));
249
- t.check('PtInRect outside (99,5) — swap-sensitive', 0, ptInRect(rectOut.ptr, { x: 99, y: 5 }));
250
- t.check('PtInRect outside x=10 (right edge exclusive)', 0, ptInRect(rectOut.ptr, { x: 10, y: 5 }));
251
- // 位置 1(首参即结构):WindowFromPoint(POINT) → 屏内必非 NULL
252
- const getSystemMetrics = bind('user32.dll', 'GetSystemMetrics', 'i32 -> i32');
253
- const cx = getSystemMetrics(0); // SM_CXSCREEN
254
- const cy = getSystemMetrics(1); // SM_CYSCREEN
255
- const windowFromPoint = bind('user32.dll', 'WindowFromPoint', '<POINT> -> <>ptr', { POINT });
256
- t.checkTrue('WindowFromPoint(screen center) non-null', !!windowFromPoint({ x: cx >> 1, y: cy >> 1 }));
257
- // 位置 2 + 其后参数推移(POINT 之后还有 UINT flags —— 槽宽算错会把 flags 读错位)
258
- const childFromPointEx = bind('user32.dll', 'ChildWindowFromPointEx', '<>ptr <POINT> u32 -> <>ptr', { POINT });
259
- const getDesktopWindow = bind('user32.dll', 'GetDesktopWindow', ' -> <>ptr');
260
- const desk = getDesktopWindow();
261
- t.checkTrue('ChildWindowFromPointEx inside → non-null', !!childFromPointEx(desk, { x: 1, y: 1 }, 0 /* CWP_ALL */));
262
- t.check('ChildWindowFromPointEx outside → NULL', 0, childFromPointEx(desk, { x: cx + 100, y: cy + 100 }, 0 /* CWP_ALL */));
263
- }
264
- else
265
- t.skipCase('PtInRect/WindowFromPoint/ChildWindowFromPointEx missing');
266
- t.section('by-value struct >8B / odd size: x64 by-reference (caller temp)');
267
- if (os.arch === 'x64' && has(crt, 'memcpy')) {
268
- // MS x64:size ∉ {1,2,4,8} 的聚合体按引用传 —— 槽内是指向 caller 分配的
269
- // 16 字节对齐临时副本的指针(单参数永不跨寄存器)。memcpy 第 2 参语义即
270
- // 「源地址」,借它白盒验证整条 by-ref 路径:若槽内不是合法副本地址、或
271
- // 字节未写进副本,拷回内容必错。ia32 按值恒把字节压栈(callee 读地址会
272
- // 拿到垃圾值),故本段 x64 限定;ia32 侧由上面真实 API 段覆盖栈上传值。
273
- const BYVAL12 = struct('BYVAL12', { a: 'u32', b: 'u32', c: 'u32' });
274
- const BYVAL3 = struct('BYVAL3', { p: 'u8', q: 'u8', r: 'u8' });
275
- const cp12 = bind('msvcrt.dll', 'memcpy', '<BYTE>ptr <BYVAL12> u32 -> <>ptr', { BYVAL12 });
276
- const cp3 = bind('msvcrt.dll', 'memcpy', '<BYTE>ptr <BYVAL3> u32 -> <>ptr', { BYVAL3 });
277
- const d12 = new PtrArrayBuffer(12);
278
- cp12(d12, { a: 1, b: 0x11223344, c: 0x7fffffff }, 12);
279
- const dv12 = new DataView(d12);
280
- t.check('12B (>8B) by-ref word 0', 1, dv12.getUint32(0, true));
281
- t.check('12B (>8B) by-ref word 1', 0x11223344, dv12.getUint32(4, true));
282
- t.check('12B (>8B) by-ref word 2', 0x7fffffff, dv12.getUint32(8, true));
283
- const d3 = new PtrArrayBuffer(3);
284
- cp3(d3, { p: 0xaa, q: 0xbb, r: 0xcc }, 3);
285
- t.check('3B (odd size) by-ref bytes', 'AA,BB,CC', Array.from(new Uint8Array(d3)).map(x => x.toString(16).toUpperCase()).join(','));
286
- }
287
- else
288
- t.skipCase('by-ref path: x64-only whitebox (ia32 pushes value bytes verbatim)');
289
- },
290
- };