capnweb 0.10.0 → 0.11.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.
@@ -39,8 +39,9 @@ interface StubBase<T = unknown> extends Disposable {
39
39
  }
40
40
  type Stub<T extends RpcCompatible<T>> = T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
41
41
  type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; // This represents all the types that can be sent as-is over an RPC boundary
42
- type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<Uint8Array> | WritableStream<any> // Chunk type can be any RPC-compatible type
43
- | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
42
+ type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<any> // Chunk type can be any RPC-compatible type
43
+ | WritableStream<any> // Chunk type can be any RPC-compatible type
44
+ | URL | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
44
45
  // prettier-ignore
45
46
  type Stubify<T> = T extends Stubable ? Stub<T> : T extends Promise<infer U> ? Stubify<U> : T extends StubBase<any> ? T : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends [] ? [] : T extends [infer Head, ...infer Tail] ? [Stubify<Head>, ...Stubify<Tail>] : T extends readonly [] ? readonly [] : T extends readonly [infer Head, ...infer Tail] ? readonly [Stubify<Head>, ...Stubify<Tail>] : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T // When using "unknown" instead of "any", interfaces are not stubified.
46
47
  : T extends {
@@ -69,7 +70,13 @@ interface MapValuePlaceholder<T> {
69
70
  }
70
71
  type NonStubMembers<T> = Exclude<T, StubBase<any>>; // Utility type for adding `Disposable`s to `object` types only.
71
72
  // Note `unknown & T` is equivalent to `T`.
72
- type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for method return or property on an RPC interface.
73
+ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // The type behind the public `RpcPromise` (re-exported with its `RpcCompatible` constraint from
74
+ // index.ts). Defined here so that `Result`'s arms below resolve to the exact same alias
75
+ // instantiation: when both sides of an assignability check are the same alias applied to the
76
+ // same type arguments, the checker short-circuits on identity instead of recursing through the
77
+ // full structural comparison of these mutually-recursive types.
78
+ type RpcPromise$1<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> & StubBase<T> : Promise<Stubify<T> & MaybeDisposable<T>> & Provider<T> & StubBase<T>;
79
+ // Type for method return or property on an RPC interface.
73
80
  // - Stubable types are replaced by stubs.
74
81
  // - RpcCompatible types are passed by value, with stubable types replaced by stubs
75
82
  // and a top-level `Disposer`.
@@ -77,7 +84,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for m
77
84
  // Technically, we use custom thenables here, but they quack like `Promise`s.
78
85
  // Intersecting with `(Maybe)Provider` allows pipelining.
79
86
  // prettier-ignore
80
- type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? Promise<Stub<R>> & Provider<R> & StubBase<R> : R extends RpcCompatible<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & Provider<R> & StubBase<R> : never;
87
+ type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? RpcPromise$1<R> : R extends RpcCompatible<R> ? RpcPromise$1<R> : never;
81
88
  type IsAny<T> = 0 extends (1 & T) ? true : false;
82
89
  type UnknownResult = Promise<unknown> & Provider<unknown> & StubBase<unknown>; // Type for method or property on an RPC interface.
83
90
  // For methods, unwrap `Stub`s in parameters, and rewrite returns to be `Result`s.
@@ -321,7 +328,7 @@ declare const RpcStub: {
321
328
  * if you only intend to use the promise for pipelining and you never await it, then there's no
322
329
  * need to transmit the resolution!
323
330
  */
324
- type RpcPromise<T extends RpcCompatible<T>> = Stub<T> & Promise<Stubify<T>>;
331
+ type RpcPromise<T extends RpcCompatible<T>> = RpcPromise$1<T>;
325
332
  declare const RpcPromise: {};
326
333
  /**
327
334
  * Use to construct an `RpcSession` on top of a custom `RpcTransport`.
@@ -39,8 +39,9 @@ interface StubBase<T = unknown> extends Disposable {
39
39
  }
40
40
  type Stub<T extends RpcCompatible<T>> = T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
41
41
  type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; // This represents all the types that can be sent as-is over an RPC boundary
42
- type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<Uint8Array> | WritableStream<any> // Chunk type can be any RPC-compatible type
43
- | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
42
+ type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<any> // Chunk type can be any RPC-compatible type
43
+ | WritableStream<any> // Chunk type can be any RPC-compatible type
44
+ | URL | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
44
45
  // prettier-ignore
45
46
  type Stubify<T> = T extends Stubable ? Stub<T> : T extends Promise<infer U> ? Stubify<U> : T extends StubBase<any> ? T : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends [] ? [] : T extends [infer Head, ...infer Tail] ? [Stubify<Head>, ...Stubify<Tail>] : T extends readonly [] ? readonly [] : T extends readonly [infer Head, ...infer Tail] ? readonly [Stubify<Head>, ...Stubify<Tail>] : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T // When using "unknown" instead of "any", interfaces are not stubified.
46
47
  : T extends {
@@ -69,7 +70,13 @@ interface MapValuePlaceholder<T> {
69
70
  }
70
71
  type NonStubMembers<T> = Exclude<T, StubBase<any>>; // Utility type for adding `Disposable`s to `object` types only.
71
72
  // Note `unknown & T` is equivalent to `T`.
72
- type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for method return or property on an RPC interface.
73
+ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // The type behind the public `RpcPromise` (re-exported with its `RpcCompatible` constraint from
74
+ // index.ts). Defined here so that `Result`'s arms below resolve to the exact same alias
75
+ // instantiation: when both sides of an assignability check are the same alias applied to the
76
+ // same type arguments, the checker short-circuits on identity instead of recursing through the
77
+ // full structural comparison of these mutually-recursive types.
78
+ type RpcPromise$1<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> & StubBase<T> : Promise<Stubify<T> & MaybeDisposable<T>> & Provider<T> & StubBase<T>;
79
+ // Type for method return or property on an RPC interface.
73
80
  // - Stubable types are replaced by stubs.
74
81
  // - RpcCompatible types are passed by value, with stubable types replaced by stubs
75
82
  // and a top-level `Disposer`.
@@ -77,7 +84,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for m
77
84
  // Technically, we use custom thenables here, but they quack like `Promise`s.
78
85
  // Intersecting with `(Maybe)Provider` allows pipelining.
79
86
  // prettier-ignore
80
- type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? Promise<Stub<R>> & Provider<R> & StubBase<R> : R extends RpcCompatible<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & Provider<R> & StubBase<R> : never;
87
+ type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? RpcPromise$1<R> : R extends RpcCompatible<R> ? RpcPromise$1<R> : never;
81
88
  type IsAny<T> = 0 extends (1 & T) ? true : false;
82
89
  type UnknownResult = Promise<unknown> & Provider<unknown> & StubBase<unknown>; // Type for method or property on an RPC interface.
83
90
  // For methods, unwrap `Stub`s in parameters, and rewrite returns to be `Result`s.
@@ -321,7 +328,7 @@ declare const RpcStub: {
321
328
  * if you only intend to use the promise for pipelining and you never await it, then there's no
322
329
  * need to transmit the resolution!
323
330
  */
324
- type RpcPromise<T extends RpcCompatible<T>> = Stub<T> & Promise<Stubify<T>>;
331
+ type RpcPromise<T extends RpcCompatible<T>> = RpcPromise$1<T>;
325
332
  declare const RpcPromise: {};
326
333
  /**
327
334
  * Use to construct an `RpcSession` on top of a custom `RpcTransport`.
@@ -47,9 +47,22 @@ function typeForRpc(value) {
47
47
  case Array.prototype: return "array";
48
48
  case Date.prototype: return "date";
49
49
  case Uint8Array.prototype:
50
- case BUFFER_PROTOTYPE: return "bytes";
50
+ case BUFFER_PROTOTYPE:
51
+ case ArrayBuffer.prototype:
52
+ case DataView.prototype:
53
+ case Int8Array.prototype:
54
+ case Uint8ClampedArray.prototype:
55
+ case Int16Array.prototype:
56
+ case Uint16Array.prototype:
57
+ case Int32Array.prototype:
58
+ case Uint32Array.prototype:
59
+ case BigInt64Array.prototype:
60
+ case BigUint64Array.prototype:
61
+ case Float32Array.prototype:
62
+ case Float64Array.prototype: return "bytes";
51
63
  case WritableStream.prototype: return "writable";
52
64
  case ReadableStream.prototype: return "readable";
65
+ case URL.prototype: return "url";
53
66
  case Headers.prototype: return "headers";
54
67
  case Request.prototype: return "request";
55
68
  case Response.prototype: return "response";
@@ -384,6 +397,7 @@ var RpcPayload = class RpcPayload {
384
397
  case "date":
385
398
  case "bytes":
386
399
  case "blob":
400
+ case "url":
387
401
  case "error":
388
402
  case "undefined": return value;
389
403
  case "array": {
@@ -517,6 +531,30 @@ var RpcPayload = class RpcPayload {
517
531
  this.dispose();
518
532
  }
519
533
  }
534
+ async deliverStreamWrite(writer) {
535
+ try {
536
+ let promises = [];
537
+ this.deliverTo(this, "value", promises);
538
+ if (promises.length > 0) await Promise.all(promises);
539
+ let chunk = this.value[0];
540
+ if ((this.hooks.length > 0 || this.promises.length > 0) && chunk instanceof Object) {
541
+ if (!(Symbol.dispose in chunk)) Object.defineProperty(chunk, Symbol.dispose, {
542
+ value: () => this.dispose(),
543
+ writable: true,
544
+ enumerable: false,
545
+ configurable: true
546
+ });
547
+ await writer.write(chunk);
548
+ return RpcPayload.fromAppReturn(void 0);
549
+ }
550
+ await writer.write(chunk);
551
+ this.dispose();
552
+ return RpcPayload.fromAppReturn(void 0);
553
+ } catch (err) {
554
+ this.dispose();
555
+ throw err;
556
+ }
557
+ }
520
558
  async deliverResolve() {
521
559
  try {
522
560
  let promises = [];
@@ -557,6 +595,7 @@ var RpcPayload = class RpcPayload {
557
595
  case "bytes":
558
596
  case "blob":
559
597
  case "date":
598
+ case "url":
560
599
  case "error":
561
600
  case "undefined": return;
562
601
  case "array": {
@@ -639,6 +678,7 @@ var RpcPayload = class RpcPayload {
639
678
  case "rpc-target":
640
679
  case "writable":
641
680
  case "readable":
681
+ case "url":
642
682
  case "headers":
643
683
  case "request":
644
684
  case "response": return;
@@ -708,6 +748,7 @@ function followPath(value, parent, path, owner) {
708
748
  case "blob":
709
749
  case "date":
710
750
  case "error":
751
+ case "url":
711
752
  case "headers":
712
753
  case "request":
713
754
  case "response":
@@ -941,6 +982,71 @@ const DEFAULT_LIMITS = {
941
982
  maxDepth: 256,
942
983
  maxMessageSize: 32 * 1024 * 1024
943
984
  };
985
+ const NATIVE_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
986
+ const BYTE_CONTAINER_TYPE_NAMES = [
987
+ "ArrayBuffer",
988
+ "DataView",
989
+ "Int8Array",
990
+ "Uint8Array",
991
+ "Uint8ClampedArray",
992
+ "Int16Array",
993
+ "Uint16Array",
994
+ "Int32Array",
995
+ "Uint32Array",
996
+ "BigInt64Array",
997
+ "BigUint64Array",
998
+ "Float32Array",
999
+ "Float64Array"
1000
+ ];
1001
+ function isValidByteContainerName(value) {
1002
+ return BYTE_CONTAINER_TYPE_NAMES.includes(value);
1003
+ }
1004
+ const TYPED_ARRAY_ELEMENT_SIZE = {
1005
+ ArrayBuffer: void 0,
1006
+ DataView: void 0,
1007
+ Int8Array: void 0,
1008
+ Uint8Array: void 0,
1009
+ Uint8ClampedArray: void 0,
1010
+ Int16Array: 2,
1011
+ Uint16Array: 2,
1012
+ Int32Array: 4,
1013
+ Uint32Array: 4,
1014
+ BigInt64Array: 8,
1015
+ BigUint64Array: 8,
1016
+ Float32Array: 4,
1017
+ Float64Array: 8
1018
+ };
1019
+ const BYTE_CONTAINER_PROTOTYPES = {
1020
+ ArrayBuffer: ArrayBuffer.prototype,
1021
+ DataView: DataView.prototype,
1022
+ Int8Array: Int8Array.prototype,
1023
+ Uint8ClampedArray: Uint8ClampedArray.prototype,
1024
+ Int16Array: Int16Array.prototype,
1025
+ Uint16Array: Uint16Array.prototype,
1026
+ Int32Array: Int32Array.prototype,
1027
+ Uint32Array: Uint32Array.prototype,
1028
+ BigInt64Array: BigInt64Array.prototype,
1029
+ BigUint64Array: BigUint64Array.prototype,
1030
+ Float32Array: Float32Array.prototype,
1031
+ Float64Array: Float64Array.prototype
1032
+ };
1033
+ const BYTE_CONTAINER_TYPE_BY_PROTOTYPE = /* @__PURE__ */ new Map();
1034
+ for (let type of Object.keys(BYTE_CONTAINER_PROTOTYPES)) BYTE_CONTAINER_TYPE_BY_PROTOTYPE.set(BYTE_CONTAINER_PROTOTYPES[type], type);
1035
+ function swapByteOrder(bytes, elementSize) {
1036
+ if (elementSize !== 2 && elementSize !== 4 && elementSize !== 8) throw new RangeError(`Unsupported element size: ${elementSize}`);
1037
+ let view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1038
+ for (let offset = 0; offset < bytes.byteLength; offset += elementSize) switch (elementSize) {
1039
+ case 2:
1040
+ view.setUint16(offset, view.getUint16(offset, false), true);
1041
+ break;
1042
+ case 4:
1043
+ view.setUint32(offset, view.getUint32(offset, false), true);
1044
+ break;
1045
+ case 8:
1046
+ view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1047
+ break;
1048
+ }
1049
+ }
944
1050
  var NullExporter = class {
945
1051
  exportStub(stub) {
946
1052
  throw new Error("Cannot serialize RPC stubs without an RPC session.");
@@ -960,7 +1066,8 @@ async function streamToBlob(stream, type) {
960
1066
  let b = await new Response(stream).blob();
961
1067
  return b.type === type ? b : b.slice(0, b.size, type);
962
1068
  }
963
- const ERROR_TYPES = Object.assign(Object.create(null), {
1069
+ const ERROR_TYPES = {
1070
+ __proto__: null,
964
1071
  Error,
965
1072
  EvalError,
966
1073
  RangeError,
@@ -969,7 +1076,7 @@ const ERROR_TYPES = Object.assign(Object.create(null), {
969
1076
  TypeError,
970
1077
  URIError,
971
1078
  AggregateError
972
- });
1079
+ };
973
1080
  var Devaluator = class Devaluator {
974
1081
  exporter;
975
1082
  source;
@@ -1031,18 +1138,40 @@ var Devaluator = class Devaluator {
1031
1138
  return ["date", Number.isNaN(time) ? null : time];
1032
1139
  }
1033
1140
  case "bytes": {
1034
- let bytes = value;
1035
- if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return ["bytes", bytes];
1036
- if (bytes.toBase64) return ["bytes", bytes.toBase64({ omitPadding: true })];
1141
+ let alternateTypeName = BYTE_CONTAINER_TYPE_BY_PROTOTYPE.get(Object.getPrototypeOf(value));
1142
+ let bytes;
1143
+ if (alternateTypeName === "ArrayBuffer") bytes = new Uint8Array(value);
1144
+ else if (alternateTypeName === void 0) bytes = value;
1145
+ else {
1146
+ let view = value;
1147
+ bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
1148
+ let elementSize = TYPED_ARRAY_ELEMENT_SIZE[alternateTypeName];
1149
+ if (!NATIVE_LITTLE_ENDIAN && elementSize) {
1150
+ bytes = bytes.slice();
1151
+ swapByteOrder(bytes, elementSize);
1152
+ }
1153
+ }
1154
+ if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return alternateTypeName === void 0 ? ["bytes", bytes] : [
1155
+ "bytes",
1156
+ bytes,
1157
+ alternateTypeName
1158
+ ];
1037
1159
  let b64;
1038
- if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
1160
+ if (bytes.toBase64) b64 = bytes.toBase64({ omitPadding: true });
1161
+ else if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
1039
1162
  else {
1040
1163
  let binary = "";
1041
1164
  for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
1042
1165
  b64 = btoa(binary);
1043
1166
  }
1044
- return ["bytes", b64.replace(/=+$/, "")];
1167
+ b64 = b64.replace(/=+$/, "");
1168
+ return alternateTypeName === void 0 ? ["bytes", b64] : [
1169
+ "bytes",
1170
+ b64,
1171
+ alternateTypeName
1172
+ ];
1045
1173
  }
1174
+ case "url": return ["url", value.href];
1046
1175
  case "headers": return ["headers", [...value]];
1047
1176
  case "request": {
1048
1177
  let req = value;
@@ -1294,18 +1423,46 @@ var Evaluator = class Evaluator {
1294
1423
  if (value[1] === null) return /* @__PURE__ */ new Date(NaN);
1295
1424
  if (typeof value[1] == "number") return new Date(value[1]);
1296
1425
  break;
1297
- case "bytes":
1298
- if (value[1] instanceof Uint8Array) return value[1];
1299
- if (typeof value[1] == "string") if (typeof Buffer !== "undefined") return Buffer.from(value[1], "base64");
1300
- else if (Uint8Array.fromBase64) return Uint8Array.fromBase64(value[1]);
1426
+ case "bytes": {
1427
+ let bytes;
1428
+ if (value[1] instanceof Uint8Array) bytes = value[1];
1429
+ else if (typeof value[1] == "string") if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1430
+ else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1301
1431
  else {
1302
1432
  let bs = atob(value[1]);
1303
1433
  let len = bs.length;
1304
- let bytes = new Uint8Array(len);
1434
+ bytes = new Uint8Array(len);
1305
1435
  for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1306
- return bytes;
1307
1436
  }
1308
- break;
1437
+ else break;
1438
+ if (value.length === 2) return bytes;
1439
+ if (typeof value[2] !== "string") throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`);
1440
+ if (!isValidByteContainerName(value[2])) {
1441
+ let marker = value[2].slice(0, 64);
1442
+ throw new TypeError(`Unknown bytes type marker: ${marker}`);
1443
+ }
1444
+ let marker = value[2];
1445
+ let elementSize = TYPED_ARRAY_ELEMENT_SIZE[marker];
1446
+ if (elementSize !== void 0 && bytes.byteLength % elementSize !== 0) throw new TypeError(`Invalid byte length ${bytes.byteLength} for ${marker}; expected a multiple of ${elementSize}`);
1447
+ let buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
1448
+ if (!NATIVE_LITTLE_ENDIAN && elementSize !== void 0) swapByteOrder(new Uint8Array(buffer), elementSize);
1449
+ switch (marker) {
1450
+ case "ArrayBuffer": return buffer;
1451
+ case "DataView": return new DataView(buffer);
1452
+ case "Int8Array": return new Int8Array(buffer);
1453
+ case "Uint8Array": return new Uint8Array(buffer);
1454
+ case "Uint8ClampedArray": return new Uint8ClampedArray(buffer);
1455
+ case "Int16Array": return new Int16Array(buffer);
1456
+ case "Uint16Array": return new Uint16Array(buffer);
1457
+ case "Int32Array": return new Int32Array(buffer);
1458
+ case "Uint32Array": return new Uint32Array(buffer);
1459
+ case "BigInt64Array": return new BigInt64Array(buffer);
1460
+ case "BigUint64Array": return new BigUint64Array(buffer);
1461
+ case "Float32Array": return new Float32Array(buffer);
1462
+ case "Float64Array": return new Float64Array(buffer);
1463
+ default:
1464
+ }
1465
+ }
1309
1466
  case "error":
1310
1467
  if (value.length >= 3 && typeof value[1] === "string" && typeof value[2] === "string") {
1311
1468
  let cls = ERROR_TYPES[value[1]] || Error;
@@ -1334,6 +1491,9 @@ var Evaluator = class Evaluator {
1334
1491
  case "inf": return Infinity;
1335
1492
  case "-inf": return -Infinity;
1336
1493
  case "nan": return NaN;
1494
+ case "url":
1495
+ if (value.length === 2 && typeof value[1] === "string") return new URL(value[1]);
1496
+ break;
1337
1497
  case "headers":
1338
1498
  if (value.length === 2 && value[1] instanceof Array) return new Headers(value[1]);
1339
1499
  break;
@@ -1555,10 +1715,6 @@ var ImportTableEntry = class {
1555
1715
  resolution;
1556
1716
  onBrokenRegistrations;
1557
1717
  resolve(resolution) {
1558
- if (this.resolution) {
1559
- resolution.dispose();
1560
- return;
1561
- }
1562
1718
  if (this.localRefcount == 0) {
1563
1719
  resolution.dispose();
1564
1720
  return;
@@ -2158,6 +2314,8 @@ var RpcSession$1 = class {
2158
2314
 
2159
2315
  //#endregion
2160
2316
  //#region src/websocket.ts
2317
+ /** Close-frame reason max UTF-8 bytes: 125 payload − 2-byte status (RFC 6455 §5.5). */
2318
+ const MAX_CLOSE_REASON_BYTES = 123;
2161
2319
  function newWebSocketRpcSession$1(webSocket, localMain, options) {
2162
2320
  if (typeof webSocket === "string") webSocket = new WebSocket(webSocket);
2163
2321
  return new RpcSession$1(new WebSocketTransport(webSocket), localMain, options).getRemoteMain();
@@ -2252,6 +2410,7 @@ var WebSocketTransport = class {
2252
2410
 
2253
2411
  //#endregion
2254
2412
  //#region src/batch.ts
2413
+ const yieldToMacrotask = typeof setImmediate === "function" ? () => new Promise((resolve) => setImmediate(resolve)) : () => new Promise((resolve) => setTimeout(resolve, 0));
2255
2414
  var BatchClientTransport = class {
2256
2415
  constructor(sendBatch) {
2257
2416
  this.#promise = this.#scheduleBatch(sendBatch);
@@ -2273,7 +2432,7 @@ var BatchClientTransport = class {
2273
2432
  this.#aborted = reason;
2274
2433
  }
2275
2434
  async #scheduleBatch(sendBatch) {
2276
- await new Promise((resolve) => setTimeout(resolve, 0));
2435
+ await yieldToMacrotask();
2277
2436
  if (this.#aborted !== void 0) throw this.#aborted;
2278
2437
  let batch = this.#batchToSend;
2279
2438
  this.#batchToSend = null;
@@ -2683,8 +2842,7 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2683
2842
  throw new Error(`Unknown WritableStream method: ${method}`);
2684
2843
  }
2685
2844
  if (method === "close" || method === "abort") state.closed = true;
2686
- let func = state.writer[method];
2687
- return new PromiseStubHook(args.deliverCall(func, state.writer).then((payload) => new PayloadStubHook(payload)));
2845
+ return new PromiseStubHook((method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer)).then((payload) => new PayloadStubHook(payload)));
2688
2846
  } catch (err) {
2689
2847
  return new ErrorStubHook(err);
2690
2848
  }