quickwin 1.3.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.en.md +18 -24
  2. package/README.md +17 -23
  3. package/examples/PdfCanvas.js +8 -37
  4. package/examples/PdfCanvas.tsx +11 -41
  5. package/examples/exec_server.js +20155 -1420
  6. package/examples/exec_server.tsx +489 -0
  7. package/examples/exec_server_worker.js +383 -33
  8. package/examples/exec_server_worker.ts +408 -30
  9. package/examples/pdf_preview2.js +25 -82
  10. package/examples/pdf_preview2.ts +27 -84
  11. package/examples/pdf_viewer.js +1424 -1180
  12. package/examples/pdf_viewer.tsx +16 -67
  13. package/examples/setres.js +22 -47
  14. package/examples/setres.ts +23 -57
  15. package/examples/test_gallery.js +1418 -1075
  16. package/examples/test_react_lazy.js +1391 -1059
  17. package/examples/test_react_listbox.js +1390 -1058
  18. package/examples/test_root_window.js +1384 -1052
  19. package/examples/test_tab.js +1391 -1059
  20. package/lib/abort.js +70 -0
  21. package/lib/abort.ts +69 -0
  22. package/lib/certs.js +219 -0
  23. package/lib/certs.ts +229 -0
  24. package/lib/exec-log.js +15 -0
  25. package/lib/exec-log.ts +30 -0
  26. package/lib/fetch.js +88 -7
  27. package/lib/fetch.ts +73 -7
  28. package/lib/ffi/bind.js +441 -0
  29. package/lib/ffi/bind.ts +539 -0
  30. package/lib/ffi/ctype.js +194 -0
  31. package/lib/ffi/ctype.ts +369 -0
  32. package/lib/ffi/index.js +6 -0
  33. package/lib/ffi/index.ts +6 -0
  34. package/lib/ffi/struct.js +490 -0
  35. package/lib/ffi/struct.ts +753 -0
  36. package/lib/http-common.js +43 -5
  37. package/lib/http-common.ts +48 -6
  38. package/lib/http-server.js +187 -29
  39. package/lib/http-server.ts +177 -26
  40. package/lib/react-qw/components/DateTimePicker.js +18 -37
  41. package/lib/react-qw/components/Input.js +3 -10
  42. package/lib/react-qw/components/Link.js +6 -19
  43. package/lib/react-qw/components/ListView.js +50 -154
  44. package/lib/react-qw/components/PathPicker.js +28 -88
  45. package/lib/react-qw/components/ScrollView.js +15 -8
  46. package/lib/react-qw/components/Slider.js +2 -1
  47. package/lib/react-qw/components/Tab.js +6 -22
  48. package/lib/react-qw/components/Tooltip.js +10 -21
  49. package/lib/react-qw/components/TreeView.js +8 -31
  50. package/lib/react-qw/index.js +5 -3
  51. package/lib/react-qw/index.ts +8 -3
  52. package/lib/react-qw/nmhdr.js +3 -24
  53. package/lib/react-qw/nmhdr.ts +5 -30
  54. package/lib/react-qw/props.js +7 -2
  55. package/lib/react-qw/props.ts +7 -3
  56. package/lib/react-qw/reconciler.js +23 -13
  57. package/lib/react-qw/reconciler.ts +22 -13
  58. package/lib/text-measure.js +20 -23
  59. package/lib/text-measure.ts +22 -26
  60. package/lib/websocket.js +44 -4
  61. package/lib/websocket.ts +40 -4
  62. package/lib/windows/advapi32.js +53 -0
  63. package/lib/windows/advapi32.ts +64 -0
  64. package/lib/windows/comctl32.js +18 -0
  65. package/lib/windows/comctl32.ts +19 -0
  66. package/lib/windows/comdlg32.js +8 -0
  67. package/lib/windows/comdlg32.ts +10 -0
  68. package/lib/windows/gdi32.js +392 -0
  69. package/lib/windows/gdi32.ts +420 -0
  70. package/lib/windows/kernel32.js +262 -0
  71. package/lib/windows/kernel32.ts +291 -0
  72. package/lib/windows/msimg32.js +38 -0
  73. package/lib/windows/msimg32.ts +45 -0
  74. package/lib/windows/ntdll.js +9 -0
  75. package/lib/windows/ntdll.ts +11 -0
  76. package/lib/windows/ole32.js +7 -0
  77. package/lib/windows/ole32.ts +9 -0
  78. package/lib/windows/psapi.js +32 -0
  79. package/lib/windows/psapi.ts +37 -0
  80. package/lib/windows/shell32.js +13 -0
  81. package/lib/windows/shell32.ts +16 -0
  82. package/lib/windows/structs.js +519 -0
  83. package/lib/windows/structs.ts +566 -0
  84. package/lib/windows/user32.js +572 -0
  85. package/lib/windows/user32.ts +607 -0
  86. package/lib/windows/version.js +29 -0
  87. package/lib/windows/version.ts +35 -0
  88. package/lib/windows/winspool.js +71 -0
  89. package/lib/windows/winspool.ts +80 -0
  90. package/package.json +1 -1
  91. package/quickwin.d.ts +31 -40
  92. package/quickwin_const.d.ts +137 -0
  93. package/qwin-nowasm-x86.exe +0 -0
  94. package/qwin-nowasm.exe +0 -0
  95. package/qwin-x86.exe +0 -0
  96. package/qwin.exe +0 -0
  97. package/test/bench_ffi_callraw.js +236 -0
  98. package/test/bench_ffi_callraw.ts +236 -0
  99. package/test/bench_ffi_overhead.js +139 -0
  100. package/test/bench_ffi_overhead.ts +141 -0
  101. package/test/bench_sendmessage.js +104 -0
  102. package/test/bench_sendmessage.ts +100 -0
  103. package/test/bench_sendmessage_nonnull.js +187 -0
  104. package/test/bench_sendmessage_nonnull.ts +188 -0
  105. package/test/run.js +19 -4
  106. package/test/run.ts +20 -5
  107. package/test/test_basic_fetch.js +29 -0
  108. package/test/test_basic_fetch.ts +26 -0
  109. package/test/test_ffi.js +27 -45
  110. package/test/test_ffi.ts +35 -54
  111. package/test/test_ffi_abi.js +290 -0
  112. package/test/test_ffi_abi.ts +274 -0
  113. package/test/test_ffi_array.js +116 -0
  114. package/test/test_ffi_array.ts +141 -0
  115. package/test/test_ffi_bind.js +620 -8
  116. package/test/test_ffi_bind.ts +630 -8
  117. package/test/test_ffi_struct.js +632 -88
  118. package/test/test_ffi_struct.ts +666 -91
  119. package/test/test_ffi_struct_layout.js +495 -0
  120. package/test/test_ffi_struct_layout.ts +543 -0
  121. package/test/test_ffi_user32.js +103 -0
  122. package/test/test_ffi_user32.ts +113 -0
  123. package/test/test_ffi_windows.js +101 -0
  124. package/test/test_ffi_windows.ts +113 -0
  125. package/test/test_files.js +102 -0
  126. package/test/test_files.ts +121 -0
  127. package/test/test_gdi_draw.js +681 -0
  128. package/test/test_gdi_draw.ts +725 -0
  129. package/test/test_helper.js +8 -1
  130. package/test/test_helper.ts +9 -1
  131. package/test/test_http_import.js +18 -0
  132. package/test/test_http_import.ts +19 -0
  133. package/test/test_http_server.js +73 -1
  134. package/test/test_http_server.ts +75 -1
  135. package/test/test_ipv6.js +2 -2
  136. package/test/test_ipv6.ts +2 -2
  137. package/test/test_net_fetch.js +74 -11
  138. package/test/test_net_fetch.ts +73 -10
  139. package/test/test_net_websocket.js +1 -1
  140. package/test/test_net_websocket.ts +1 -1
  141. package/test/test_printer.js +137 -0
  142. package/test/test_printer.ts +148 -0
  143. package/test/test_proc.js +141 -0
  144. package/test/test_proc.ts +163 -0
  145. package/test/test_react_complex.js +1401 -1069
  146. package/test/test_react_counter.js +1391 -1059
  147. package/test/test_react_flex.js +1411 -1072
  148. package/test/test_react_hidden.js +1394 -1062
  149. package/test/test_react_listview_link.js +1391 -1059
  150. package/test/test_react_notify.js +18638 -0
  151. package/test/test_react_render.js +1391 -1059
  152. package/test/test_registry.js +74 -0
  153. package/test/test_registry.ts +95 -0
  154. package/test/test_sysinfo.js +122 -0
  155. package/test/test_sysinfo.ts +141 -0
  156. package/test/test_wolfssl_read.js +45 -43
  157. package/test/test_wolfssl_read.ts +42 -40
  158. package/test/test_worker_net.js +35 -17
  159. package/test/test_worker_net.ts +27 -15
  160. package/tsconfig.json +1 -1
  161. package/examples/exec_server.ts +0 -80
  162. package/lib/ffi-bind.js +0 -85
  163. package/lib/ffi-bind.ts +0 -170
  164. package/lib/ffi-struct.js +0 -224
  165. package/lib/ffi-struct.ts +0 -239
  166. package/lib/win-common-structs.js +0 -39
  167. package/lib/win-common-structs.ts +0 -41
@@ -0,0 +1,290 @@
1
+ import * as std from 'std';
2
+ import * as win from 'win';
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 && !!win.GetProcAddress(dll, name);
33
+ }
34
+ export const suite = {
35
+ name: 'ffi-abi',
36
+ run: (t) => {
37
+ const k32 = win.LoadLibrary('kernel32.dll');
38
+ const usr = win.LoadLibrary('user32.dll');
39
+ const gdi = win.LoadLibrary('gdi32.dll');
40
+ const crt = win.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
+ };
@@ -0,0 +1,274 @@
1
+ import * as std from 'std'
2
+ import * as win from 'win'
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
+ import { Tester } from './test_helper.js'
9
+
10
+ // ABI 边界回归:覆盖 REMOVE_LIBFFI_PLAN.md §4.2 的维度,全部用真实 Win32/CRT
11
+ // 函数(不新增测试专用导出)。缺函数的平台记 SKIP 而非 FAIL,避免环境差异误报。
12
+ //
13
+ // 维度 → 用例:
14
+ // 参数个数 0/1/3/4/5/6/8/12:GetTickCount/fabs/memcpy/GetLocaleInfoA/
15
+ // SetRect/CompareStringW/WideCharToMultiByte/SetDIBitsToDevice
16
+ // 整浮混合:ldexp(f64,i32)、frexp(f64,ptr)、modf(f64,ptr)
17
+ // 前 4 全整数(RCX-R9):GetLocaleInfoA 的 4 个参数
18
+ // 负数返回 i32/i16/i8:lstrcmpW;i64:InterlockedIncrement64
19
+ // 窄整型负值传参:abs(i8/i16/u8/u16)
20
+ // 大 64 位传参:InterlockedExchange64
21
+ // 指针 NULL:GetDC(NULL)、IsWindow(NULL);null/undefined 不是指针合法值,应拒绝
22
+
23
+ function readAscii(buf: ArrayBuffer, len: number): string {
24
+ const dv = new DataView(buf)
25
+ let s = ''
26
+ for (let i = 0; i < len; i++) {
27
+ const c = dv.getUint8(i)
28
+ if (c === 0) break
29
+ s += String.fromCharCode(c)
30
+ }
31
+ return s
32
+ }
33
+
34
+ function has(dll: win.HMODULE | null, name: string): boolean {
35
+ return !!dll && !!win.GetProcAddress(dll, name)
36
+ }
37
+
38
+ export const suite = {
39
+ name: 'ffi-abi',
40
+ run: (t: Tester) => {
41
+ const k32 = win.LoadLibrary('kernel32.dll')
42
+ const usr = win.LoadLibrary('user32.dll')
43
+ const gdi = win.LoadLibrary('gdi32.dll')
44
+ const crt = win.LoadLibrary('msvcrt.dll')
45
+
46
+ t.section('param count 0 ( -> u32)')
47
+ if (has(k32, 'GetTickCount')) {
48
+ const getTickCount = bind('kernel32.dll', 'GetTickCount', ' -> u32')
49
+ const tc = getTickCount()
50
+ t.checkTrue('GetTickCount() > 0', tc > 0)
51
+ } else t.skipCase('GetTickCount missing')
52
+
53
+ t.section('param count 1 (f64 -> f64)')
54
+ if (has(crt, 'fabs')) {
55
+ const fabs = bind('msvcrt.dll', 'fabs', 'f64 -> f64')
56
+ t.check('fabs(-3.5)', 3.5, fabs(-3.5))
57
+ } else t.skipCase('fabs missing')
58
+
59
+ t.section('param count 3 (<BYTE>ptr <BYTE>ptr u32 -> ptr)')
60
+ if (has(crt, 'memcpy')) {
61
+ const memcpy = bind('msvcrt.dll', 'memcpy', '<BYTE>ptr <BYTE>ptr u32 -> <>ptr')
62
+ const srcB = new PtrArrayBuffer(8)
63
+ const src = new Uint8Array(srcB)
64
+ src.set([1, 2, 3, 4, 5, 6, 7, 8])
65
+ const dstB = new PtrArrayBuffer(8)
66
+ const dst = new Uint8Array(dstB)
67
+ const r = memcpy(dstB, srcB, 8)
68
+ const rd = Array.from(dst).join(',')
69
+ t.check('memcpy copied bytes', '1,2,3,4,5,6,7,8', rd)
70
+ t.checkTrue('memcpy returns dest ptr', typeof r === 'number' && r !== 0)
71
+ } else t.skipCase('memcpy missing')
72
+
73
+ t.section('param count 4 + all-int-regs (u32 u32 <BYTE>ptr i32 -> i32)')
74
+ if (has(k32, 'GetLocaleInfoA')) {
75
+ const getLocaleInfoA = bind('kernel32.dll', 'GetLocaleInfoA', 'u32 u32 <BYTE>ptr i32 -> i32')
76
+ const buf = new PtrArrayBuffer(64)
77
+ const n = getLocaleInfoA(0x0409, 0x00001001 /* LOCALE_SENGLANGUAGE */, buf, 64)
78
+ if (n > 0) {
79
+ const s = readAscii(buf, n)
80
+ std.printf(' GetLocaleInfoA(0x0409, LOCALE_SENGLANGUAGE) = "%s" (%d)\n', s, n)
81
+ t.check('en-US language name', 'English', s)
82
+ } else t.skipCase('en-US locale unavailable')
83
+ } else t.skipCase('GetLocaleInfoA missing')
84
+
85
+ t.section('param count 5 (<BYTE>ptr i32 i32 i32 i32 -> i32)')
86
+ if (has(usr, 'SetRect')) {
87
+ const setRect = bind('user32.dll', 'SetRect', '<BYTE>ptr i32 i32 i32 i32 -> i32')
88
+ const rc = new PtrArrayBuffer(16)
89
+ const ok = setRect(rc, 1, 2, 30, 40)
90
+ const dv = new DataView(rc)
91
+ t.checkTrue('SetRect returns nonzero', ok !== 0)
92
+ t.check('SetRect left', 1, dv.getInt32(0, true))
93
+ t.check('SetRect top', 2, dv.getInt32(4, true))
94
+ t.check('SetRect right', 30, dv.getInt32(8, true))
95
+ t.check('SetRect bottom', 40, dv.getInt32(12, true))
96
+ } else t.skipCase('SetRect missing')
97
+
98
+ t.section('param count 6 (u32 u32 <WCHAR>ptr i32 <WCHAR>ptr i32 -> i32)')
99
+ if (has(k32, 'CompareStringW')) {
100
+ const compareStringW = bind('kernel32.dll', 'CompareStringW', 'u32 u32 <WCHAR>ptr i32 <WCHAR>ptr i32 -> i32')
101
+ const r = compareStringW(0x0400 /* LOCALE_USER_DEFAULT */, 0, 'abc', -1, 'abd', -1)
102
+ t.check('CompareStringW("abc","abd") = CSTR_LESS_THAN', 1, r)
103
+ } else t.skipCase('CompareStringW missing')
104
+
105
+ t.section('param count 8 (u32 u32 <WCHAR>ptr i32 <BYTE>ptr i32 <>ptr <>ptr -> i32)')
106
+ if (has(k32, 'WideCharToMultiByte')) {
107
+ const wideCharToMultiByte = bind('kernel32.dll', 'WideCharToMultiByte', 'u32 u32 <WCHAR>ptr i32 <BYTE>ptr i32 <>ptr <>ptr -> i32')
108
+ const out = new PtrArrayBuffer(16)
109
+ // 显式给长度(cchWideChar=2)避免 -1 空终止语义下返回值是否含 '\0' 的版本差异。
110
+ const n = wideCharToMultiByte(0 /* CP_ACP */, 0, 'AB', 2, out, 16, NULL, NULL)
111
+ t.check('WideCharToMultiByte char count', 2, n)
112
+ t.check('converted byte 0 = A', 65, new DataView(out).getUint8(0))
113
+ t.check('converted byte 1 = B', 66, new DataView(out).getUint8(1))
114
+ } else t.skipCase('WideCharToMultiByte missing')
115
+
116
+ t.section('param count 12 (SetDIBitsToDevice on memory DC)')
117
+ if (has(gdi, 'SetDIBitsToDevice') && has(gdi, 'CreateCompatibleDC') && has(gdi, 'DeleteDC')) {
118
+ const createCompatibleDC = bind('gdi32.dll', 'CreateCompatibleDC', '<>ptr -> <>ptr')
119
+ const deleteDC = bind('gdi32.dll', 'DeleteDC', '<>ptr -> i32')
120
+ const setDIBitsToDevice = bind('gdi32.dll', 'SetDIBitsToDevice',
121
+ '<>ptr i32 i32 u32 u32 i32 i32 u32 u32 <BYTE>ptr <BYTE>ptr u32 -> i32')
122
+ const hdc = createCompatibleDC(0)
123
+ if (hdc) {
124
+ const bmi = new PtrArrayBuffer(40)
125
+ const bdv = new DataView(bmi)
126
+ bdv.setUint32(0, 40, true) // biSize
127
+ bdv.setInt32(4, 1, true) // biWidth
128
+ bdv.setInt32(8, 1, true) // biHeight (bottom-up)
129
+ bdv.setUint16(12, 1, true) // biPlanes
130
+ bdv.setUint16(14, 32, true) // biBitCount
131
+ bdv.setUint32(16, 0, true) // biCompression = BI_RGB
132
+ const bits = new PtrArrayBuffer(4)
133
+ const lines = setDIBitsToDevice(hdc, 0, 0, 1, 1, 0, 0, 0, 1, bits, bmi, 0 /* DIB_RGB_COLORS */)
134
+ t.check('SetDIBitsToDevice scanlines copied', 1, lines)
135
+ deleteDC(hdc)
136
+ } else t.skipCase('CreateCompatibleDC returned NULL')
137
+ } else t.skipCase('SetDIBitsToDevice/CreateCompatibleDC missing')
138
+
139
+ t.section('int/float mix: f64 i32 -> f64')
140
+ if (has(crt, 'ldexp')) {
141
+ const ldexp = bind('msvcrt.dll', 'ldexp', 'f64 i32 -> f64')
142
+ t.check('ldexp(1.5, 3)', 12.0, ldexp(1.5, 3))
143
+ } else t.skipCase('ldexp missing')
144
+
145
+ t.section('int/float mix: f64 <BYTE>ptr -> f64')
146
+ if (has(crt, 'frexp')) {
147
+ const frexp = bind('msvcrt.dll', 'frexp', 'f64 <BYTE>ptr -> f64')
148
+ const e = new PtrArrayBuffer(4)
149
+ const m = frexp(12.0, e)
150
+ t.check('frexp(12).mantissa', 0.75, m)
151
+ t.check('frexp(12).exponent', 4, new DataView(e).getInt32(0, true))
152
+ } else t.skipCase('frexp missing')
153
+ if (has(crt, 'modf')) {
154
+ const modf = bind('msvcrt.dll', 'modf', 'f64 <BYTE>ptr -> f64')
155
+ const ip = new PtrArrayBuffer(8)
156
+ const frac = modf(3.75, ip)
157
+ t.check('modf(3.75).frac', 0.75, frac)
158
+ t.check('modf(3.75).int', 3.0, new DataView(ip).getFloat64(0, true))
159
+ } else t.skipCase('modf missing')
160
+
161
+ t.section('narrow signed args (msvcrt!abs)')
162
+ if (has(crt, 'abs')) {
163
+ const absI8 = bind('msvcrt.dll', 'abs', 'i8 -> i32')
164
+ const absU8 = bind('msvcrt.dll', 'abs', 'u8 -> i32')
165
+ const absI16 = bind('msvcrt.dll', 'abs', 'i16 -> i32')
166
+ const absU16 = bind('msvcrt.dll', 'abs', 'u16 -> i32')
167
+ t.check('abs(i8 -128)', 128, absI8(-128))
168
+ t.check('abs(i8 -5)', 5, absI8(-5))
169
+ t.check('abs(u8 200)', 200, absU8(200))
170
+ t.check('abs(i16 -300)', 300, absI16(-300))
171
+ t.check('abs(u16 60000)', 60000, absU16(60000))
172
+ } else t.skipCase('abs missing')
173
+
174
+ t.section('negative return i32/i16/i8 (lstrcmpW)')
175
+ if (has(k32, 'lstrcmpW')) {
176
+ const cmpI32 = bind('kernel32.dll', 'lstrcmpW', '<WCHAR>ptr <WCHAR>ptr -> i32')
177
+ const cmpI16 = bind('kernel32.dll', 'lstrcmpW', '<WCHAR>ptr <WCHAR>ptr -> i16')
178
+ const cmpI8 = bind('kernel32.dll', 'lstrcmpW', '<WCHAR>ptr <WCHAR>ptr -> i8')
179
+ t.checkTrue('lstrcmpW i32 < 0', cmpI32('a', 'b') < 0)
180
+ t.checkTrue('lstrcmpW i16 < 0', cmpI16('a', 'b') < 0)
181
+ t.checkTrue('lstrcmpW i8 < 0', cmpI8('a', 'b') < 0)
182
+ } else t.skipCase('lstrcmpW missing')
183
+
184
+ t.section('negative return i64 (InterlockedIncrement64)')
185
+ if (has(k32, 'InterlockedExchange64') && has(k32, 'InterlockedIncrement64')) {
186
+ const exchange64 = bind('kernel32.dll', 'InterlockedExchange64', '<BYTE>ptr i64 -> i64')
187
+ const increment64 = bind('kernel32.dll', 'InterlockedIncrement64', '<BYTE>ptr -> i64')
188
+ const cell = new PtrArrayBuffer(8)
189
+ exchange64(cell, -2n)
190
+ t.check('InterlockedIncrement64(-2)', -1n, increment64(cell))
191
+ } else t.skipCase('Interlocked*64 missing')
192
+
193
+ t.section('64-bit arg transport (InterlockedExchange64)')
194
+ if (has(k32, 'InterlockedExchange64')) {
195
+ const exchange64 = bind('kernel32.dll', 'InterlockedExchange64', '<BYTE>ptr i64 -> i64')
196
+ const cell = new PtrArrayBuffer(8)
197
+ const prev0 = exchange64(cell, 4294967297n) // 2^32+1:超过 32 位
198
+ const prev1 = exchange64(cell, -1n) // 64 位全 1
199
+ const prev2 = exchange64(cell, 0n)
200
+ t.check('exchange empty cell returns 0', 0n, prev0)
201
+ t.check('exchange returns 2^32+1', 4294967297n, prev1)
202
+ t.check('exchange returns -1', -1n, prev2)
203
+ } else t.skipCase('InterlockedExchange64 missing')
204
+
205
+ t.section('ptr NULL/undefined')
206
+ if (has(usr, 'GetDC') && has(usr, 'IsWindow')) {
207
+ const getDC = bind('user32.dll', 'GetDC', '<>ptr -> <>ptr')
208
+ const isWindow = bind('user32.dll', 'IsWindow', '<>ptr -> i32')
209
+ t.checkTrue('GetDC(NULL) non-null', !!getDC(NULL))
210
+ // undefined / null 不是指针合法值(指针只收 NULL 或有效地址),必须拒绝而非静默当 0。
211
+ let errUndef = ''
212
+ try {
213
+ (getDC as unknown as (v: unknown) => number)(undefined)
214
+ } catch (e) {
215
+ errUndef = String(e)
216
+ }
217
+ t.checkTrue('GetDC(undefined) rejected', errUndef.includes('undefined'))
218
+ t.check('IsWindow(NULL) = FALSE', 0, isWindow(NULL))
219
+ } else t.skipCase('GetDC/IsWindow missing')
220
+
221
+ t.section('by-value struct arg: <POINT> (slot value, not a pointer)')
222
+ if (has(usr, 'PtInRect') && has(usr, 'WindowFromPoint') && has(usr, 'ChildWindowFromPointEx')) {
223
+ // PtInRect(rect, pt):RECT 按指针、POINT 按值(x64 位置寄存器 / ia32 压 8 字节上栈)。
224
+ // 非对称矩形 {0,0,10,100} —— 若 x/y 在打包中交换,(99,5) 与 (5,99) 的判定会互换,
225
+ // 本段即可抓出「槽内是地址而非值」「字段顺序/位置错」两类 ABI 错误。
226
+ const ptInRect = bind('user32.dll', 'PtInRect', '<RECT>ptr <POINT> -> i32', { RECT, POINT })
227
+ const rectOut = RECT.alloc()
228
+ const rdv = new DataView(rectOut)
229
+ rdv.setInt32(8, 10, true) // right(left/top = 0,零填充)
230
+ rdv.setInt32(12, 100, true) // bottom
231
+ t.check('PtInRect inside (5,5)', 1, ptInRect(rectOut.ptr, { x: 5, y: 5 }))
232
+ t.check('PtInRect inside (5,99)', 1, ptInRect(rectOut.ptr, { x: 5, y: 99 }))
233
+ t.check('PtInRect outside (99,5) — swap-sensitive', 0, ptInRect(rectOut.ptr, { x: 99, y: 5 }))
234
+ t.check('PtInRect outside x=10 (right edge exclusive)', 0, ptInRect(rectOut.ptr, { x: 10, y: 5 }))
235
+
236
+ // 位置 1(首参即结构):WindowFromPoint(POINT) → 屏内必非 NULL
237
+ const getSystemMetrics = bind('user32.dll', 'GetSystemMetrics', 'i32 -> i32')
238
+ const cx = getSystemMetrics(0) // SM_CXSCREEN
239
+ const cy = getSystemMetrics(1) // SM_CYSCREEN
240
+ const windowFromPoint = bind('user32.dll', 'WindowFromPoint', '<POINT> -> <>ptr', { POINT })
241
+ t.checkTrue('WindowFromPoint(screen center) non-null', !!windowFromPoint({ x: cx >> 1, y: cy >> 1 }))
242
+
243
+ // 位置 2 + 其后参数推移(POINT 之后还有 UINT flags —— 槽宽算错会把 flags 读错位)
244
+ const childFromPointEx = bind('user32.dll', 'ChildWindowFromPointEx', '<>ptr <POINT> u32 -> <>ptr', { POINT })
245
+ const getDesktopWindow = bind('user32.dll', 'GetDesktopWindow', ' -> <>ptr')
246
+ const desk = getDesktopWindow()
247
+ t.checkTrue('ChildWindowFromPointEx inside → non-null', !!childFromPointEx(desk, { x: 1, y: 1 }, 0 /* CWP_ALL */))
248
+ t.check('ChildWindowFromPointEx outside → NULL', 0, childFromPointEx(desk, { x: cx + 100, y: cy + 100 }, 0 /* CWP_ALL */))
249
+ } else t.skipCase('PtInRect/WindowFromPoint/ChildWindowFromPointEx missing')
250
+
251
+ t.section('by-value struct >8B / odd size: x64 by-reference (caller temp)')
252
+ if (os.arch === 'x64' && has(crt, 'memcpy')) {
253
+ // MS x64:size ∉ {1,2,4,8} 的聚合体按引用传 —— 槽内是指向 caller 分配的
254
+ // 16 字节对齐临时副本的指针(单参数永不跨寄存器)。memcpy 第 2 参语义即
255
+ // 「源地址」,借它白盒验证整条 by-ref 路径:若槽内不是合法副本地址、或
256
+ // 字节未写进副本,拷回内容必错。ia32 按值恒把字节压栈(callee 读地址会
257
+ // 拿到垃圾值),故本段 x64 限定;ia32 侧由上面真实 API 段覆盖栈上传值。
258
+ const BYVAL12 = struct('BYVAL12', { a: 'u32', b: 'u32', c: 'u32' })
259
+ const BYVAL3 = struct('BYVAL3', { p: 'u8', q: 'u8', r: 'u8' })
260
+ const cp12 = bind('msvcrt.dll', 'memcpy', '<BYTE>ptr <BYVAL12> u32 -> <>ptr', { BYVAL12 })
261
+ const cp3 = bind('msvcrt.dll', 'memcpy', '<BYTE>ptr <BYVAL3> u32 -> <>ptr', { BYVAL3 })
262
+ const d12 = new PtrArrayBuffer(12)
263
+ cp12(d12, { a: 1, b: 0x11223344, c: 0x7fffffff }, 12)
264
+ const dv12 = new DataView(d12)
265
+ t.check('12B (>8B) by-ref word 0', 1, dv12.getUint32(0, true))
266
+ t.check('12B (>8B) by-ref word 1', 0x11223344, dv12.getUint32(4, true))
267
+ t.check('12B (>8B) by-ref word 2', 0x7fffffff, dv12.getUint32(8, true))
268
+ const d3 = new PtrArrayBuffer(3)
269
+ cp3(d3, { p: 0xaa, q: 0xbb, r: 0xcc }, 3)
270
+ t.check('3B (odd size) by-ref bytes', 'AA,BB,CC',
271
+ Array.from(new Uint8Array(d3)).map(x => x.toString(16).toUpperCase()).join(','))
272
+ } else t.skipCase('by-ref path: x64-only whitebox (ia32 pushes value bytes verbatim)')
273
+ },
274
+ }