@bytecodealliance/preview2-shim 0.16.4 → 0.16.5

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.
@@ -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: {
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.5",
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
  *