@bytecodealliance/preview2-shim 0.16.7 → 0.17.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.
- package/lib/browser/cli.js +9 -2
- package/lib/browser/filesystem.js +1 -1
- package/lib/io/worker-socket-tcp.js +5 -8
- package/package.json +1 -1
- package/types/interfaces/wasi-clocks-monotonic-clock.d.ts +3 -4
- package/types/interfaces/wasi-filesystem-types.d.ts +1 -1
- package/types/interfaces/wasi-http-types.d.ts +30 -23
- package/types/interfaces/wasi-io-poll.d.ts +4 -3
- package/types/interfaces/wasi-io-streams.d.ts +2 -2
- package/types/interfaces/wasi-sockets-tcp.d.ts +4 -4
package/lib/browser/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ const { InputStream, OutputStream } = streams;
|
|
|
4
4
|
|
|
5
5
|
const symbolDispose = Symbol.dispose ?? Symbol.for('dispose');
|
|
6
6
|
|
|
7
|
-
let _env = [], _args = [], _cwd =
|
|
7
|
+
let _env = [], _args = [], _cwd = "/";
|
|
8
8
|
export function _setEnv (envObj) {
|
|
9
9
|
_env = Object.entries(envObj);
|
|
10
10
|
}
|
|
@@ -75,6 +75,10 @@ const stdinStream = new InputStream({
|
|
|
75
75
|
let textDecoder = new TextDecoder();
|
|
76
76
|
const stdoutStream = new OutputStream({
|
|
77
77
|
write (contents) {
|
|
78
|
+
if (contents[contents.length - 1] == 10) {
|
|
79
|
+
// console.log already appends a new line
|
|
80
|
+
contents = contents.subarray(0, contents.length - 1);
|
|
81
|
+
}
|
|
78
82
|
console.log(textDecoder.decode(contents));
|
|
79
83
|
},
|
|
80
84
|
blockingFlush () {
|
|
@@ -84,10 +88,13 @@ const stdoutStream = new OutputStream({
|
|
|
84
88
|
});
|
|
85
89
|
const stderrStream = new OutputStream({
|
|
86
90
|
write (contents) {
|
|
91
|
+
if (contents[contents.length - 1] == 10) {
|
|
92
|
+
// console.error already appends a new line
|
|
93
|
+
contents = contents.subarray(0, contents.length - 1);
|
|
94
|
+
}
|
|
87
95
|
console.error(textDecoder.decode(contents));
|
|
88
96
|
},
|
|
89
97
|
blockingFlush () {
|
|
90
|
-
|
|
91
98
|
},
|
|
92
99
|
[symbolDispose] () {
|
|
93
100
|
|
|
@@ -265,16 +265,13 @@ export function socketTcpGetRemoteAddress(id) {
|
|
|
265
265
|
return ipSocketAddress(out.family.toLowerCase(), out.address, out.port);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
export function socketTcpShutdown(id,
|
|
268
|
+
export function socketTcpShutdown(id, _shutdownType) {
|
|
269
269
|
const socket = tcpSockets.get(id);
|
|
270
270
|
if (socket.state !== SOCKET_STATE_CONNECTION) throw "invalid-state";
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
else
|
|
276
|
-
socket.tcpSocket.destroy();
|
|
277
|
-
}
|
|
271
|
+
if (winOrMac && socket.tcpSocket.destroySoon)
|
|
272
|
+
socket.tcpSocket.destroySoon();
|
|
273
|
+
else
|
|
274
|
+
socket.tcpSocket.destroy();
|
|
278
275
|
}
|
|
279
276
|
|
|
280
277
|
export function socketTcpSetKeepAlive(id, { keepAlive, keepAliveIdleTime }) {
|
package/package.json
CHANGED
|
@@ -13,13 +13,12 @@ export namespace WasiClocksMonotonicClock {
|
|
|
13
13
|
export function resolution(): Duration;
|
|
14
14
|
/**
|
|
15
15
|
* Create a `pollable` which will resolve once the specified instant
|
|
16
|
-
*
|
|
16
|
+
* has occurred.
|
|
17
17
|
*/
|
|
18
18
|
export function subscribeInstant(when: Instant): Pollable;
|
|
19
19
|
/**
|
|
20
|
-
* Create a `pollable`
|
|
21
|
-
* elapsed
|
|
22
|
-
* occured.
|
|
20
|
+
* Create a `pollable` that will resolve after the specified duration has
|
|
21
|
+
* elapsed from the time this function is invoked.
|
|
23
22
|
*/
|
|
24
23
|
export function subscribeDuration(when: Duration): Pollable;
|
|
25
24
|
}
|
|
@@ -95,7 +95,7 @@ export interface DescriptorFlags {
|
|
|
95
95
|
*/
|
|
96
96
|
dataIntegritySync?: boolean,
|
|
97
97
|
/**
|
|
98
|
-
* Requests that reads be performed at the same level of
|
|
98
|
+
* Requests that reads be performed at the same level of integrity
|
|
99
99
|
* requested for writes. This is similar to `O_RSYNC` in POSIX.
|
|
100
100
|
*
|
|
101
101
|
* The precise semantics of this operation have not yet been defined for
|
|
@@ -317,19 +317,17 @@ export class Fields {
|
|
|
317
317
|
* list with the same key.
|
|
318
318
|
*
|
|
319
319
|
* The tuple is a pair of the field key, represented as a string, and
|
|
320
|
-
* Value, represented as a list of bytes.
|
|
321
|
-
* and values are valid UTF-8 strings. However, values are not always
|
|
322
|
-
* well-formed, so they are represented as a raw list of bytes.
|
|
320
|
+
* Value, represented as a list of bytes.
|
|
323
321
|
*
|
|
324
|
-
* An error result will be returned if any
|
|
325
|
-
* syntactically invalid, or if a
|
|
322
|
+
* An error result will be returned if any `field-key` or `field-value` is
|
|
323
|
+
* syntactically invalid, or if a field is forbidden.
|
|
326
324
|
*/
|
|
327
325
|
static fromList(entries: Array<[FieldKey, FieldValue]>): Fields;
|
|
328
326
|
/**
|
|
329
327
|
* Get all of the values corresponding to a key. If the key is not present
|
|
330
|
-
* in this `fields
|
|
331
|
-
* present but empty, this is represented by a list
|
|
332
|
-
* empty field-values present.
|
|
328
|
+
* in this `fields` or is syntactically invalid, an empty list is returned.
|
|
329
|
+
* However, if the key is present but empty, this is represented by a list
|
|
330
|
+
* with one or more empty field-values present.
|
|
333
331
|
*/
|
|
334
332
|
get(name: FieldKey): Array<FieldValue>;
|
|
335
333
|
/**
|
|
@@ -342,6 +340,9 @@ export class Fields {
|
|
|
342
340
|
* key, if they have been set.
|
|
343
341
|
*
|
|
344
342
|
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
343
|
+
*
|
|
344
|
+
* Fails with `header-error.invalid-syntax` if the `field-key` or any of
|
|
345
|
+
* the `field-value`s are syntactically invalid.
|
|
345
346
|
*/
|
|
346
347
|
set(name: FieldKey, value: Array<FieldValue>): void;
|
|
347
348
|
/**
|
|
@@ -349,6 +350,9 @@ export class Fields {
|
|
|
349
350
|
* exist.
|
|
350
351
|
*
|
|
351
352
|
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
353
|
+
*
|
|
354
|
+
* Fails with `header-error.invalid-syntax` if the `field-key` is
|
|
355
|
+
* syntactically invalid.
|
|
352
356
|
*/
|
|
353
357
|
'delete'(name: FieldKey): void;
|
|
354
358
|
/**
|
|
@@ -356,6 +360,9 @@ export class Fields {
|
|
|
356
360
|
* values for that key.
|
|
357
361
|
*
|
|
358
362
|
* Fails with `header-error.immutable` if the `fields` are immutable.
|
|
363
|
+
*
|
|
364
|
+
* Fails with `header-error.invalid-syntax` if the `field-key` or
|
|
365
|
+
* `field-value` are syntactically invalid.
|
|
359
366
|
*/
|
|
360
367
|
append(name: FieldKey, value: FieldValue): void;
|
|
361
368
|
/**
|
|
@@ -368,7 +375,7 @@ export class Fields {
|
|
|
368
375
|
*/
|
|
369
376
|
entries(): Array<[FieldKey, FieldValue]>;
|
|
370
377
|
/**
|
|
371
|
-
* Make a deep copy of the Fields.
|
|
378
|
+
* Make a deep copy of the Fields. Equivalent in behavior to calling the
|
|
372
379
|
* `fields` constructor on the return value of `entries`. The resulting
|
|
373
380
|
* `fields` is mutable.
|
|
374
381
|
*/
|
|
@@ -378,7 +385,7 @@ export class Fields {
|
|
|
378
385
|
export class FutureIncomingResponse {
|
|
379
386
|
/**
|
|
380
387
|
* Returns a pollable which becomes ready when either the Response has
|
|
381
|
-
* been received, or an error has
|
|
388
|
+
* been received, or an error has occurred. When this pollable is ready,
|
|
382
389
|
* the `get` method will return `some`.
|
|
383
390
|
*/
|
|
384
391
|
subscribe(): Pollable;
|
|
@@ -393,8 +400,8 @@ export class FutureIncomingResponse {
|
|
|
393
400
|
* is `some`, and error on subsequent calls.
|
|
394
401
|
*
|
|
395
402
|
* The inner `result` represents that either the incoming HTTP Response
|
|
396
|
-
* status and headers have
|
|
397
|
-
*
|
|
403
|
+
* status and headers have received successfully, or that an error
|
|
404
|
+
* occurred. Errors may also occur while consuming the response body,
|
|
398
405
|
* but those will be reported by the `incoming-body` and its
|
|
399
406
|
* `output-stream` child.
|
|
400
407
|
*/
|
|
@@ -404,12 +411,12 @@ export class FutureIncomingResponse {
|
|
|
404
411
|
export class FutureTrailers {
|
|
405
412
|
/**
|
|
406
413
|
* Returns a pollable which becomes ready when either the trailers have
|
|
407
|
-
* been received, or an error has
|
|
414
|
+
* been received, or an error has occurred. When this pollable is ready,
|
|
408
415
|
* the `get` method will return `some`.
|
|
409
416
|
*/
|
|
410
417
|
subscribe(): Pollable;
|
|
411
418
|
/**
|
|
412
|
-
* Returns the contents of the trailers, or an error which
|
|
419
|
+
* Returns the contents of the trailers, or an error which occurred,
|
|
413
420
|
* once the future is ready.
|
|
414
421
|
*
|
|
415
422
|
* The outer `option` represents future readiness. Users can wait on this
|
|
@@ -421,7 +428,7 @@ export class FutureTrailers {
|
|
|
421
428
|
*
|
|
422
429
|
* The inner `result` represents that either the HTTP Request or Response
|
|
423
430
|
* body, as well as any trailers, were received successfully, or that an
|
|
424
|
-
* error
|
|
431
|
+
* error occurred receiving them. The optional `trailers` indicates whether
|
|
425
432
|
* or not trailers were present in the body.
|
|
426
433
|
*
|
|
427
434
|
* When some `trailers` are returned by this method, the `trailers`
|
|
@@ -472,7 +479,7 @@ export class IncomingRequest {
|
|
|
472
479
|
*/
|
|
473
480
|
scheme(): Scheme | undefined;
|
|
474
481
|
/**
|
|
475
|
-
* Returns the authority
|
|
482
|
+
* Returns the authority of the Request's target URI, if present.
|
|
476
483
|
*/
|
|
477
484
|
authority(): string | undefined;
|
|
478
485
|
/**
|
|
@@ -597,16 +604,16 @@ export class OutgoingRequest {
|
|
|
597
604
|
*/
|
|
598
605
|
setScheme(scheme: Scheme | undefined): void;
|
|
599
606
|
/**
|
|
600
|
-
* Get the
|
|
601
|
-
* with Related Schemes which do not require an
|
|
607
|
+
* Get the authority of the Request's target URI. A value of `none` may be used
|
|
608
|
+
* with Related Schemes which do not require an authority. The HTTP and
|
|
602
609
|
* HTTPS schemes always require an authority.
|
|
603
610
|
*/
|
|
604
611
|
authority(): string | undefined;
|
|
605
612
|
/**
|
|
606
|
-
* Set the
|
|
607
|
-
* with Related Schemes which do not require an
|
|
613
|
+
* Set the authority of the Request's target URI. A value of `none` may be used
|
|
614
|
+
* with Related Schemes which do not require an authority. The HTTP and
|
|
608
615
|
* HTTPS schemes always require an authority. Fails if the string given is
|
|
609
|
-
* not a syntactically valid
|
|
616
|
+
* not a syntactically valid URI authority.
|
|
610
617
|
*/
|
|
611
618
|
setAuthority(authority: string | undefined): void;
|
|
612
619
|
/**
|
|
@@ -616,7 +623,7 @@ export class OutgoingRequest {
|
|
|
616
623
|
* `delete` operations will fail with `header-error.immutable`.
|
|
617
624
|
*
|
|
618
625
|
* This headers resource is a child: it must be dropped before the parent
|
|
619
|
-
* `outgoing-request` is dropped, or its ownership is
|
|
626
|
+
* `outgoing-request` is dropped, or its ownership is transferred to
|
|
620
627
|
* another component by e.g. `outgoing-handler.handle`.
|
|
621
628
|
*/
|
|
622
629
|
headers(): Headers;
|
|
@@ -647,7 +654,7 @@ export class OutgoingResponse {
|
|
|
647
654
|
* `delete` operations will fail with `header-error.immutable`.
|
|
648
655
|
*
|
|
649
656
|
* This headers resource is a child: it must be dropped before the parent
|
|
650
|
-
* `outgoing-request` is dropped, or its ownership is
|
|
657
|
+
* `outgoing-request` is dropped, or its ownership is transferred to
|
|
651
658
|
* another component by e.g. `outgoing-handler.handle`.
|
|
652
659
|
*/
|
|
653
660
|
headers(): Headers;
|
|
@@ -9,8 +9,9 @@ export namespace WasiIoPoll {
|
|
|
9
9
|
* The result `list<u32>` contains one or more indices of handles in the
|
|
10
10
|
* argument list that is ready for I/O.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* This function traps if either:
|
|
13
|
+
* - the list is empty, or:
|
|
14
|
+
* - the list contains more elements than can be indexed with a `u32` value.
|
|
14
15
|
*
|
|
15
16
|
* A timeout can be implemented by adding a pollable from the
|
|
16
17
|
* wasi-clocks API to the list.
|
|
@@ -18,7 +19,7 @@ export namespace WasiIoPoll {
|
|
|
18
19
|
* This function does not return a `result`; polling in itself does not
|
|
19
20
|
* do any I/O so it doesn't fail. If any of the I/O sources identified by
|
|
20
21
|
* the pollables has an error, it is indicated by marking the source as
|
|
21
|
-
* being
|
|
22
|
+
* being ready for I/O.
|
|
22
23
|
*/
|
|
23
24
|
export function poll(in_: Array<Pollable>): Uint32Array;
|
|
24
25
|
}
|
|
@@ -162,7 +162,7 @@ export class OutputStream {
|
|
|
162
162
|
blockingFlush(): void;
|
|
163
163
|
/**
|
|
164
164
|
* Create a `pollable` which will resolve once the output-stream
|
|
165
|
-
* is ready for more writing, or an error has
|
|
165
|
+
* is ready for more writing, or an error has occurred. When this
|
|
166
166
|
* pollable is ready, `check-write` will return `ok(n)` with n>0, or an
|
|
167
167
|
* error.
|
|
168
168
|
*
|
|
@@ -212,7 +212,7 @@ export class OutputStream {
|
|
|
212
212
|
/**
|
|
213
213
|
* Read from one stream and write to another.
|
|
214
214
|
*
|
|
215
|
-
* The behavior of splice is
|
|
215
|
+
* The behavior of splice is equivalent to:
|
|
216
216
|
* 1. calling `check-write` on the `output-stream`
|
|
217
217
|
* 2. calling `read` on the `input-stream` with the smaller of the
|
|
218
218
|
* `check-write` permitted length and the `len` provided to `splice`
|
|
@@ -79,7 +79,7 @@ export class TcpSocket {
|
|
|
79
79
|
* Connect to a remote endpoint.
|
|
80
80
|
*
|
|
81
81
|
* On success:
|
|
82
|
-
* - the socket is transitioned into the `
|
|
82
|
+
* - the socket is transitioned into the `connected` state.
|
|
83
83
|
* - a pair of streams is returned that can be used to read & write to the connection
|
|
84
84
|
*
|
|
85
85
|
* After a failed connection attempt, the socket will be in the `closed`
|
|
@@ -329,8 +329,8 @@ export class TcpSocket {
|
|
|
329
329
|
* `subscribe` only has to be called once per socket and can then be
|
|
330
330
|
* (re)used for the remainder of the socket's lifetime.
|
|
331
331
|
*
|
|
332
|
-
* See <https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md#
|
|
333
|
-
* for
|
|
332
|
+
* See <https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md#pollable-readiness>
|
|
333
|
+
* for more information.
|
|
334
334
|
*
|
|
335
335
|
* Note: this function is here for WASI Preview2 only.
|
|
336
336
|
* It's planned to be removed when `future` is natively supported in Preview3.
|
|
@@ -347,7 +347,7 @@ export class TcpSocket {
|
|
|
347
347
|
* associated with this socket will be closed and a FIN packet will be sent.
|
|
348
348
|
* - `both`: Same effect as `receive` & `send` combined.
|
|
349
349
|
*
|
|
350
|
-
* This function is idempotent
|
|
350
|
+
* This function is idempotent; shutting down a direction more than once
|
|
351
351
|
* has no effect and returns `ok`.
|
|
352
352
|
*
|
|
353
353
|
* The shutdown function does not close (drop) the socket.
|