@bytecodealliance/preview2-shim 0.17.9 → 0.18.1
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/filesystem.js +19 -1
- package/lib/browser/http.js +13 -0
- package/lib/io/worker-sockets.js +1 -1
- package/lib/nodejs/http.js +18 -3
- package/package.json +9 -9
|
@@ -43,6 +43,22 @@ const timeZero = {
|
|
|
43
43
|
nanoseconds: 0,
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/** Coerce the given object to a safe integer */
|
|
47
|
+
function coerceToSafeIntegerNumber(obj) {
|
|
48
|
+
let n;
|
|
49
|
+
if (typeof obj === "number") {
|
|
50
|
+
n = obj;
|
|
51
|
+
} else if (typeof obj == "bigint") {
|
|
52
|
+
n = Number(obj);
|
|
53
|
+
} else {
|
|
54
|
+
throw new TypeError(`unexpected non-numeric type: ${obj}`);
|
|
55
|
+
}
|
|
56
|
+
if (n > Number.MAX_SAFE_INTEGER) {
|
|
57
|
+
throw new TypeError(`excessively large number: ${n}`);
|
|
58
|
+
}
|
|
59
|
+
return n;
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
function getChildEntry(parentEntry, subpath, openFlags) {
|
|
47
63
|
if (subpath === "." && _rootPreopen && descriptorGetEntry(_rootPreopen[0]) === parentEntry) {
|
|
48
64
|
subpath = _getCwd();
|
|
@@ -188,7 +204,9 @@ class Descriptor {
|
|
|
188
204
|
|
|
189
205
|
read(length, offset) {
|
|
190
206
|
const source = getSource(this.#entry);
|
|
191
|
-
|
|
207
|
+
const off = coerceToSafeIntegerNumber(offset);
|
|
208
|
+
const len = coerceToSafeIntegerNumber(length);
|
|
209
|
+
return [source.slice(off, off + len), off + len >= source.byteLength];
|
|
192
210
|
}
|
|
193
211
|
|
|
194
212
|
write(buffer, offset) {
|
package/lib/browser/http.js
CHANGED
|
@@ -46,6 +46,19 @@ class Fields {
|
|
|
46
46
|
return tableEntries.map(([, v]) => v);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* WIT spec (https://github.com/WebAssembly/WASI/blob/91bb44c3c3a9b1e09187db23c85fa844d1fd6b15/proposals/http/wit/types.wit#L215-L223):
|
|
51
|
+
*
|
|
52
|
+
* > Set all of the values for a name. Clears any existing values for that
|
|
53
|
+
* > name, if they have been set.
|
|
54
|
+
* >
|
|
55
|
+
* > Fails with `header-error.immutable` if the `fields` are immutable.
|
|
56
|
+
* >
|
|
57
|
+
* > Fails with `header-error.invalid-syntax` if the `field-name` or any of
|
|
58
|
+
* > the `field-value`s are syntactically invalid.
|
|
59
|
+
*
|
|
60
|
+
* The existing-branch splice/reuse is an allocation optimization — values are cleared, not retained.
|
|
61
|
+
*/
|
|
49
62
|
set(name, values) {
|
|
50
63
|
if (this.#immutable) {
|
|
51
64
|
throw { tag: "immutable" };
|
package/lib/io/worker-sockets.js
CHANGED
|
@@ -87,7 +87,7 @@ export function socketResolveAddress(name) {
|
|
|
87
87
|
return lookup(name, dnsLookupOptions).then(
|
|
88
88
|
(addresses) => {
|
|
89
89
|
return addresses.map(({ address, family }) => {
|
|
90
|
-
[
|
|
90
|
+
return [
|
|
91
91
|
{
|
|
92
92
|
tag: "ipv" + family,
|
|
93
93
|
val: (family === 4 ? ipv4ToTuple : ipv6ToTuple)(address),
|
package/lib/nodejs/http.js
CHANGED
|
@@ -499,6 +499,19 @@ class Fields {
|
|
|
499
499
|
}
|
|
500
500
|
return tableEntries.map(([, v]) => v);
|
|
501
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* WIT spec (https://github.com/WebAssembly/WASI/blob/91bb44c3c3a9b1e09187db23c85fa844d1fd6b15/proposals/http/wit/types.wit#L215-L223):
|
|
504
|
+
*
|
|
505
|
+
* > Set all of the values for a name. Clears any existing values for that
|
|
506
|
+
* > name, if they have been set.
|
|
507
|
+
* >
|
|
508
|
+
* > Fails with `header-error.immutable` if the `fields` are immutable.
|
|
509
|
+
* >
|
|
510
|
+
* > Fails with `header-error.invalid-syntax` if the `field-name` or any of
|
|
511
|
+
* > the `field-value`s are syntactically invalid.
|
|
512
|
+
*
|
|
513
|
+
* The existing-branch splice/reuse is an allocation optimization — values are cleared, not retained.
|
|
514
|
+
*/
|
|
502
515
|
set(name, values) {
|
|
503
516
|
if (this.#immutable) {
|
|
504
517
|
throw { tag: "immutable" };
|
|
@@ -514,17 +527,19 @@ class Fields {
|
|
|
514
527
|
} catch {
|
|
515
528
|
throw { tag: "invalid-syntax" };
|
|
516
529
|
}
|
|
517
|
-
throw { tag: "invalid-syntax" };
|
|
518
530
|
}
|
|
519
531
|
const lowercased = name.toLowerCase();
|
|
520
532
|
if (_forbiddenHeaders.has(lowercased)) {
|
|
521
533
|
throw { tag: "forbidden" };
|
|
522
534
|
}
|
|
523
|
-
|
|
535
|
+
let tableEntries = this.#table.get(lowercased);
|
|
524
536
|
if (tableEntries) {
|
|
525
537
|
this.#entries = this.#entries.filter((entry) => !tableEntries.includes(entry));
|
|
538
|
+
tableEntries.splice(0, tableEntries.length);
|
|
539
|
+
} else {
|
|
540
|
+
this.#table.set(lowercased, []);
|
|
541
|
+
tableEntries = this.#table.get(lowercased);
|
|
526
542
|
}
|
|
527
|
-
tableEntries.splice(0, tableEntries.length);
|
|
528
543
|
for (const value of values) {
|
|
529
544
|
const entry = [name, value];
|
|
530
545
|
this.#entries.push(entry);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/preview2-shim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "WASI Preview2 shim for JS environments",
|
|
5
5
|
"homepage": "https://github.com/bytecodealliance/jco#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
"default": "./lib/common/instantiation.js"
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@bytecodealliance/componentize-js": "0.21.0",
|
|
53
|
+
"@bytecodealliance/jco": "1.15.2",
|
|
54
|
+
"mime": "^4.0.7",
|
|
55
|
+
"puppeteer": "^25.1.0"
|
|
56
|
+
},
|
|
51
57
|
"scripts": {
|
|
52
58
|
"types:check": "tsc --noEmit",
|
|
53
59
|
"fmt": "oxfmt",
|
|
54
60
|
"fmt:check": "oxfmt --check",
|
|
55
61
|
"lint": "oxlint",
|
|
56
|
-
"lint:fix": "
|
|
62
|
+
"lint:fix": "oxlint --fix",
|
|
57
63
|
"test": "vitest run -c test/vitest.ts"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@bytecodealliance/componentize-js": "0.19.3",
|
|
61
|
-
"@bytecodealliance/jco": "1.15.2",
|
|
62
|
-
"mime": "^4.0.7",
|
|
63
|
-
"puppeteer": "^24.16.2"
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
}
|