quickwin 1.1.3 → 1.1.4

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "quickwin",
4
- "version": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "description": "QuickJS Win32 runtime — GUI, networking, WASM, FFI, and more",
6
6
  "bin": {
7
7
  "quickwin": "qwin.exe",
package/quickwin.d.ts CHANGED
@@ -340,8 +340,8 @@ declare module "os" {
340
340
  static parent: Worker;
341
341
  }
342
342
 
343
- /** Return a string representing the platform: `"linux"`, `"darwin"`, `"win32"` or `"js"`. */
344
- const platform: string;
343
+ /** Process architecture (pointer width): `"x64"` or `"ia32"`. */
344
+ const arch: string;
345
345
  }
346
346
 
347
347
  declare module "sock" {
Binary file
package/qwin-nowasm.exe CHANGED
Binary file
package/qwin-x86.exe CHANGED
Binary file
package/qwin.exe CHANGED
Binary file
package/test/test_ffi.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import * as std from 'std';
2
2
  import * as win from 'win';
3
3
  import * as ffi from 'ffi';
4
+ import * as os from 'os';
5
+ const MAX_WCHARS = 4096;
4
6
  function decodeWideAtPtr(ptr) {
5
7
  if (!ptr)
6
8
  return '';
7
9
  const chars = [];
8
10
  let pos = ptr;
9
- while (true) {
11
+ while (chars.length < MAX_WCHARS) {
10
12
  const low = ffi.readByte(pos);
11
13
  const high = ffi.readByte(pos + 1);
12
14
  const ch = low + high * 256;
@@ -18,6 +20,9 @@ function decodeWideAtPtr(ptr) {
18
20
  return String.fromCharCode(...chars);
19
21
  }
20
22
  function readPtr(dv, offset) {
23
+ if (os.arch === 'ia32') {
24
+ return dv.getUint32(offset, true);
25
+ }
21
26
  const low = dv.getUint32(offset, true);
22
27
  const high = dv.getUint32(offset + 4, true);
23
28
  return low + high * 4294967296;
@@ -122,15 +127,25 @@ export const suite = {
122
127
  std.printf(' printers found: %d\n', returnedBuf[0]);
123
128
  if (returnedBuf[0] > 0) {
124
129
  const dv = new DataView(printerBuf);
125
- const structSize = 136;
130
+ // PRINTER_INFO_2W layout (MinGW verified):
131
+ // x64: sizeof=136 name=8 port=24 drv=32 comment=40 location=48 status=124
132
+ // ia32: sizeof=84 name=4 port=12 drv=16 comment=20 location=24 status=72
133
+ const ia32 = os.arch === 'ia32';
134
+ const structSize = ia32 ? 84 : 136;
135
+ const offName = ia32 ? 4 : 8;
136
+ const offPort = ia32 ? 12 : 24;
137
+ const offDrv = ia32 ? 16 : 32;
138
+ const offComment = ia32 ? 20 : 40;
139
+ const offLocation = ia32 ? 24 : 48;
140
+ const offStatus = ia32 ? 72 : 124;
126
141
  for (let i = 0; i < returnedBuf[0] && i < 20; i++) {
127
142
  const off = i * structSize;
128
- const name = decodeWideAtPtr(readPtr(dv, off + 8));
129
- const port = decodeWideAtPtr(readPtr(dv, off + 24));
130
- const driver = decodeWideAtPtr(readPtr(dv, off + 32));
131
- const location = decodeWideAtPtr(readPtr(dv, off + 48));
132
- const comment = decodeWideAtPtr(readPtr(dv, off + 40));
133
- const status = dv.getUint32(off + 124, true);
143
+ const name = decodeWideAtPtr(readPtr(dv, off + offName));
144
+ const port = decodeWideAtPtr(readPtr(dv, off + offPort));
145
+ const driver = decodeWideAtPtr(readPtr(dv, off + offDrv));
146
+ const location = decodeWideAtPtr(readPtr(dv, off + offLocation));
147
+ const comment = decodeWideAtPtr(readPtr(dv, off + offComment));
148
+ const status = dv.getUint32(off + offStatus, true);
134
149
  std.printf(' [%d] %s\n', i + 1, name);
135
150
  std.printf(' port: %s\n', port);
136
151
  std.printf(' driver: %s\n', driver);
package/test/test_ffi.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  import * as std from 'std'
2
2
  import * as win from 'win'
3
3
  import * as ffi from 'ffi'
4
+ import * as os from 'os'
4
5
  import { Tester } from './test_helper.js'
5
6
 
7
+ const MAX_WCHARS = 4096
8
+
6
9
  function decodeWideAtPtr(ptr: number): string {
7
10
  if (!ptr) return ''
8
11
  const chars: number[] = []
9
12
  let pos = ptr
10
- while (true) {
13
+ while (chars.length < MAX_WCHARS) {
11
14
  const low = ffi.readByte(pos)
12
15
  const high = ffi.readByte(pos + 1)
13
16
  const ch = low + high * 256
@@ -19,6 +22,9 @@ function decodeWideAtPtr(ptr: number): string {
19
22
  }
20
23
 
21
24
  function readPtr(dv: DataView, offset: number): number {
25
+ if (os.arch === 'ia32') {
26
+ return dv.getUint32(offset, true)
27
+ }
22
28
  const low = dv.getUint32(offset, true)
23
29
  const high = dv.getUint32(offset + 4, true)
24
30
  return low + high * 4294967296
@@ -136,16 +142,26 @@ export const suite = {
136
142
 
137
143
  if (returnedBuf[0]! > 0) {
138
144
  const dv = new DataView(printerBuf)
139
- const structSize = 136
145
+ // PRINTER_INFO_2W layout (MinGW verified):
146
+ // x64: sizeof=136 name=8 port=24 drv=32 comment=40 location=48 status=124
147
+ // ia32: sizeof=84 name=4 port=12 drv=16 comment=20 location=24 status=72
148
+ const ia32 = os.arch === 'ia32'
149
+ const structSize = ia32 ? 84 : 136
150
+ const offName = ia32 ? 4 : 8
151
+ const offPort = ia32 ? 12 : 24
152
+ const offDrv = ia32 ? 16 : 32
153
+ const offComment = ia32 ? 20 : 40
154
+ const offLocation = ia32 ? 24 : 48
155
+ const offStatus = ia32 ? 72 : 124
140
156
 
141
157
  for (let i = 0; i < returnedBuf[0]! && i < 20; i++) {
142
158
  const off = i * structSize
143
- const name = decodeWideAtPtr(readPtr(dv, off + 8))
144
- const port = decodeWideAtPtr(readPtr(dv, off + 24))
145
- const driver = decodeWideAtPtr(readPtr(dv, off + 32))
146
- const location = decodeWideAtPtr(readPtr(dv, off + 48))
147
- const comment = decodeWideAtPtr(readPtr(dv, off + 40))
148
- const status = dv.getUint32(off + 124, true)
159
+ const name = decodeWideAtPtr(readPtr(dv, off + offName))
160
+ const port = decodeWideAtPtr(readPtr(dv, off + offPort))
161
+ const driver = decodeWideAtPtr(readPtr(dv, off + offDrv))
162
+ const location = decodeWideAtPtr(readPtr(dv, off + offLocation))
163
+ const comment = decodeWideAtPtr(readPtr(dv, off + offComment))
164
+ const status = dv.getUint32(off + offStatus, true)
149
165
  std.printf(' [%d] %s\n', i + 1, name)
150
166
  std.printf(' port: %s\n', port)
151
167
  std.printf(' driver: %s\n', driver)