@bytecodealliance/preview2-shim 0.16.4 → 0.16.6

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.
@@ -198,7 +198,7 @@ class Descriptor {
198
198
  }
199
199
 
200
200
  statAt(_pathFlags, path) {
201
- const entry = getChildEntry(this.#entry, path);
201
+ const entry = getChildEntry(this.#entry, path, { create: false, directory: false });
202
202
  let type = 'unknown', size = BigInt(0);
203
203
  if (entry.source) {
204
204
  type = 'regular-file';
@@ -167,6 +167,7 @@ class InputStream {
167
167
  #streamType;
168
168
  #finalizer;
169
169
  read(len) {
170
+ process._rawDebug('read', len);
170
171
  return streamIoErrorCall(
171
172
  INPUT_STREAM_READ | this.#streamType,
172
173
  this.#id,
@@ -31,6 +31,8 @@ import {
31
31
  } from "./worker-sockets.js";
32
32
  import { Socket, Server } from "node:net";
33
33
 
34
+ const winOrMac = process.platform === 'win32' || process.platform === 'darwin';
35
+
34
36
  /**
35
37
  * @typedef {import("../../types/interfaces/wasi-sockets-network.js").IpSocketAddress} IpSocketAddress
36
38
  * @typedef {import("../../../types/interfaces/wasi-sockets-tcp.js").IpAddressFamily} IpAddressFamily
@@ -45,7 +47,7 @@ import { Socket, Server } from "node:net";
45
47
  * @typedef {{
46
48
  * state: number,
47
49
  * future: number | null,
48
- * socket: TcpSocket | null,
50
+ * tcpSocket: TcpSocket | null,
49
51
  * listenBacklogSize: number,
50
52
  * handle: TCP,
51
53
  * pendingAccepts: PendingAccept[],
@@ -68,6 +70,7 @@ export function createTcpSocket() {
68
70
  tcpSockets.set(++tcpSocketCnt, {
69
71
  state: SOCKET_STATE_INIT,
70
72
  future: null,
73
+ tcpSocket: null,
71
74
  listenBacklogSize: 128,
72
75
  handle,
73
76
  pendingAccepts: [],
@@ -217,6 +220,7 @@ export function socketTcpAccept(id) {
217
220
  tcpSockets.set(++tcpSocketCnt, {
218
221
  state: SOCKET_STATE_CONNECTION,
219
222
  future: null,
223
+ tcpSocket: accept.tcpSocket,
220
224
  listenBacklogSize: 128,
221
225
  handle: accept.tcpSocket._handle,
222
226
  pendingAccepts: [],
@@ -265,8 +269,12 @@ export function socketTcpShutdown(id, shutdownType) {
265
269
  const socket = tcpSockets.get(id);
266
270
  if (socket.state !== SOCKET_STATE_CONNECTION) throw "invalid-state";
267
271
  // Node.js only supports a write shutdown, which is triggered on end
268
- if (shutdownType === "send" || shutdownType === "both")
269
- socket.tcpSocket.end();
272
+ if (shutdownType === "send" || shutdownType === "both") {
273
+ if (winOrMac && socket.tcpSocket.destroySoon)
274
+ socket.tcpSocket.destroySoon();
275
+ else
276
+ socket.tcpSocket.destroy();
277
+ }
270
278
  }
271
279
 
272
280
  export function socketTcpSetKeepAlive(id, { keepAlive, keepAliveIdleTime }) {
@@ -583,7 +583,7 @@ function handle(call, id, payload) {
583
583
  Math.min(stream.stream.readableLength, Number(payload))
584
584
  );
585
585
  if (res) return res;
586
- if (stream.stream.readableEnded) return { tag: "closed" };
586
+ if (stream.stream.readableEnded) throw { tag: "closed" };
587
587
  return new Uint8Array();
588
588
  }
589
589
  case INPUT_STREAM_BLOCKING_READ: {
@@ -352,7 +352,7 @@ class Descriptor {
352
352
  let isSymlink = false;
353
353
  try {
354
354
  isSymlink = lstatSync(fullPath).isSymbolicLink();
355
- } catch (e) {
355
+ } catch {
356
356
  //
357
357
  }
358
358
  if (isSymlink) throw openFlags.directory ? "not-directory" : "loop";
@@ -361,7 +361,7 @@ class Descriptor {
361
361
  let isFile = false;
362
362
  try {
363
363
  isFile = !statSync(fullPath).isDirectory();
364
- } catch (e) {
364
+ } catch {
365
365
  //
366
366
  }
367
367
  if (isFile) throw "not-directory";
@@ -430,7 +430,7 @@ class Descriptor {
430
430
  let isDir = false;
431
431
  try {
432
432
  isDir = statSync(fullPath).isDirectory();
433
- } catch (_) {
433
+ } catch {
434
434
  //
435
435
  }
436
436
  if (!isDir) throw isWindows ? "no-entry" : "not-directory";
@@ -449,7 +449,7 @@ class Descriptor {
449
449
  let isDir = false;
450
450
  try {
451
451
  isDir = statSync(fullPath).isDirectory();
452
- } catch (e) {
452
+ } catch {
453
453
  //
454
454
  }
455
455
  throw isDir ? (isWindows ? "access" : (isMac ? "not-permitted" : "is-directory")) : "not-directory";
@@ -540,7 +540,7 @@ class Fields {
540
540
  }
541
541
  try {
542
542
  validateHeaderValue(name, new TextDecoder().decode(value));
543
- } catch (e) {
543
+ } catch {
544
544
  throw { tag: "invalid-syntax" };
545
545
  }
546
546
  const lowercased = name.toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.16.4",
3
+ "version": "0.16.6",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
6
6
  "type": "module",
@@ -9,11 +9,11 @@ export namespace WasiCliEnvironment {
9
9
  * in the component model, this import function should return the same
10
10
  * values each time it is called.
11
11
  */
12
- export function getEnvironment(): [string, string][];
12
+ export function getEnvironment(): Array<[string, string]>;
13
13
  /**
14
14
  * Get the POSIX-style arguments to the program.
15
15
  */
16
- export function getArguments(): string[];
16
+ export function getArguments(): Array<string>;
17
17
  /**
18
18
  * Return a path that programs should use as their initial current working
19
19
  * directory, interpreting `.` as shorthand for this.
@@ -2,7 +2,7 @@ export namespace WasiFilesystemPreopens {
2
2
  /**
3
3
  * Return the set of preopened directories, and their path.
4
4
  */
5
- export function getDirectories(): [Descriptor, string][];
5
+ export function getDirectories(): Array<[Descriptor, string]>;
6
6
  }
7
7
  import type { Descriptor } from './wasi-filesystem-types.js';
8
8
  export { Descriptor };
@@ -324,14 +324,14 @@ export class Fields {
324
324
  * An error result will be returned if any header or value was
325
325
  * syntactically invalid, or if a header was forbidden.
326
326
  */
327
- static fromList(entries: [FieldKey, FieldValue][]): Fields;
327
+ static fromList(entries: Array<[FieldKey, FieldValue]>): Fields;
328
328
  /**
329
329
  * Get all of the values corresponding to a key. If the key is not present
330
330
  * in this `fields`, an empty list is returned. However, if the key is
331
331
  * present but empty, this is represented by a list with one or more
332
332
  * empty field-values present.
333
333
  */
334
- get(name: FieldKey): FieldValue[];
334
+ get(name: FieldKey): Array<FieldValue>;
335
335
  /**
336
336
  * Returns `true` when the key is present in this `fields`. If the key is
337
337
  * syntactically invalid, `false` is returned.
@@ -343,7 +343,7 @@ export class Fields {
343
343
  *
344
344
  * Fails with `header-error.immutable` if the `fields` are immutable.
345
345
  */
346
- set(name: FieldKey, value: FieldValue[]): void;
346
+ set(name: FieldKey, value: Array<FieldValue>): void;
347
347
  /**
348
348
  * Delete all values for a key. Does nothing if no values for the key
349
349
  * exist.
@@ -366,7 +366,7 @@ export class Fields {
366
366
  * which have multiple values are represented by multiple entries in this
367
367
  * list with the same key.
368
368
  */
369
- entries(): [FieldKey, FieldValue][];
369
+ entries(): Array<[FieldKey, FieldValue]>;
370
370
  /**
371
371
  * Make a deep copy of the Fields. Equivelant in behavior to calling the
372
372
  * `fields` constructor on the return value of `entries`. The resulting
@@ -20,7 +20,7 @@ export namespace WasiIoPoll {
20
20
  * the pollables has an error, it is indicated by marking the source as
21
21
  * being reaedy for I/O.
22
22
  */
23
- export function poll(in_: Pollable[]): Uint32Array;
23
+ export function poll(in_: Array<Pollable>): Uint32Array;
24
24
  }
25
25
 
26
26
  export class Pollable {
@@ -78,7 +78,7 @@ export class IncomingDatagramStream {
78
78
  * - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
79
79
  * - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
80
80
  */
81
- receive(maxResults: bigint): IncomingDatagram[];
81
+ receive(maxResults: bigint): Array<IncomingDatagram>;
82
82
  /**
83
83
  * Create a `pollable` which will resolve once the stream is ready to receive again.
84
84
  *
@@ -139,7 +139,7 @@ export class OutgoingDatagramStream {
139
139
  * - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
140
140
  * - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
141
141
  */
142
- send(datagrams: OutgoingDatagram[]): bigint;
142
+ send(datagrams: Array<OutgoingDatagram>): bigint;
143
143
  /**
144
144
  * Create a `pollable` which will resolve once the stream is ready to send again.
145
145
  *