@bytecodealliance/preview2-shim 0.17.9 → 0.18.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.
@@ -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" };
@@ -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),
@@ -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
- const tableEntries = this.#table.get(lowercased);
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.17.9",
3
+ "version": "0.18.0",
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": "^24.43.1"
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": "npm run 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
+ }