capnweb 0.0.0-6664f94 → 0.0.0-66ed2fd

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.
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/symbols.ts
4
3
  let WORKERS_MODULE_SYMBOL = Symbol("workers-module");
5
4
 
@@ -42,6 +41,9 @@ function typeForRpc(value) {
42
41
  case AsyncFunction.prototype: return "function";
43
42
  case Array.prototype: return "array";
44
43
  case Date.prototype: return "date";
44
+ case RegExp.prototype: return "regexp";
45
+ case Set.prototype: return "set";
46
+ case Map.prototype: return "map";
45
47
  case Uint8Array.prototype:
46
48
  case BUFFER_PROTOTYPE:
47
49
  case ArrayBuffer.prototype:
@@ -58,6 +60,7 @@ function typeForRpc(value) {
58
60
  case Float64Array.prototype: return "bytes";
59
61
  case WritableStream.prototype: return "writable";
60
62
  case ReadableStream.prototype: return "readable";
63
+ case URL.prototype: return "url";
61
64
  case Headers.prototype: return "headers";
62
65
  case Request.prototype: return "request";
63
66
  case Response.prototype: return "response";
@@ -91,7 +94,14 @@ let streamImpl = {
91
94
  };
92
95
  var StubHook = class {
93
96
  stream(path, args) {
94
- let pulled = this.call(path, args).pull();
97
+ let hook = this.call(path, args);
98
+ let pulled;
99
+ try {
100
+ pulled = hook.pull();
101
+ } catch (err) {
102
+ hook.dispose();
103
+ throw err;
104
+ }
95
105
  let promise;
96
106
  if (pulled instanceof Promise) promise = pulled.then((p) => {
97
107
  p.dispose();
@@ -110,9 +120,11 @@ var ErrorStubHook = class extends StubHook {
110
120
  this.error = error;
111
121
  }
112
122
  call(path, args) {
123
+ args.dispose();
113
124
  return this;
114
125
  }
115
126
  map(path, captures, instructions) {
127
+ for (let cap of captures) cap.dispose();
116
128
  return this;
117
129
  }
118
130
  get(path) {
@@ -236,7 +248,25 @@ var RpcStub$1 = class RpcStub$1 extends RpcTarget$1 {
236
248
  };
237
249
  var RpcPromise$1 = class extends RpcStub$1 {
238
250
  constructor(hook, pathIfPromise) {
239
- super(hook, pathIfPromise);
251
+ if (hook instanceof StubHook) super(hook, pathIfPromise ?? []);
252
+ else {
253
+ if (pathIfPromise !== void 0) throw new TypeError("RpcPromise constructor expected one argument, received two.");
254
+ let kind = typeForRpc(hook);
255
+ if (kind === "rpc-promise") {
256
+ let raw = unwrapStubAndPath(hook);
257
+ if (raw.pathIfPromise.length > 0) super(raw.hook, raw.pathIfPromise);
258
+ else {
259
+ let adopted = raw.hook;
260
+ raw.hook = DISPOSED_HOOK;
261
+ super(adopted, []);
262
+ }
263
+ } else if (kind === "rpc-thenable") super(TargetStubHook.create(hook, void 0), []);
264
+ else {
265
+ let promiseHook = new PromiseStubHook(Promise.resolve(hook).then((value) => new PayloadStubHook(RpcPayload.fromAppReturn(value))));
266
+ promiseHook.ignoreUnhandledRejections();
267
+ super(promiseHook, []);
268
+ }
269
+ }
240
270
  }
241
271
  then(onfulfilled, onrejected) {
242
272
  return pullPromise(this).then(...arguments);
@@ -277,6 +307,9 @@ async function pullPromise(promise) {
277
307
  if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
278
308
  return (await hook.pull()).deliverResolve();
279
309
  }
310
+ function mapKeyToPropertyName(key) {
311
+ return typeof key === "string" || typeof key === "number" ? key : { mapKey: key };
312
+ }
280
313
  var RpcPayload = class RpcPayload {
281
314
  value;
282
315
  source;
@@ -331,12 +364,13 @@ var RpcPayload = class RpcPayload {
331
364
  return TargetStubHook.create(target, parent);
332
365
  } else if (this.source === "return") {
333
366
  let hook = this.rpcTargets?.get(target);
334
- if (hook) if (dupStubs) return hook.dup();
335
- else {
336
- this.rpcTargets?.delete(target);
337
- return hook;
338
- }
339
- else {
367
+ if (hook) {
368
+ if (dupStubs) return hook.dup();
369
+ else {
370
+ this.rpcTargets?.delete(target);
371
+ return hook;
372
+ }
373
+ } else {
340
374
  hook = TargetStubHook.create(target, parent);
341
375
  if (dupStubs) {
342
376
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -350,12 +384,13 @@ var RpcPayload = class RpcPayload {
350
384
  if (this.source === "params") return streamImpl.createWritableStreamHook(stream);
351
385
  else if (this.source === "return") {
352
386
  let hook = this.rpcTargets?.get(stream);
353
- if (hook) if (dupStubs) return hook.dup();
354
- else {
355
- this.rpcTargets?.delete(stream);
356
- return hook;
357
- }
358
- else {
387
+ if (hook) {
388
+ if (dupStubs) return hook.dup();
389
+ else {
390
+ this.rpcTargets?.delete(stream);
391
+ return hook;
392
+ }
393
+ } else {
359
394
  hook = streamImpl.createWritableStreamHook(stream);
360
395
  if (dupStubs) {
361
396
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -369,12 +404,13 @@ var RpcPayload = class RpcPayload {
369
404
  if (this.source === "params") return streamImpl.createReadableStreamHook(stream);
370
405
  else if (this.source === "return") {
371
406
  let hook = this.rpcTargets?.get(stream);
372
- if (hook) if (dupStubs) return hook.dup();
373
- else {
374
- this.rpcTargets?.delete(stream);
375
- return hook;
376
- }
377
- else {
407
+ if (hook) {
408
+ if (dupStubs) return hook.dup();
409
+ else {
410
+ this.rpcTargets?.delete(stream);
411
+ return hook;
412
+ }
413
+ } else {
378
414
  hook = streamImpl.createReadableStreamHook(stream);
379
415
  if (dupStubs) {
380
416
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -382,7 +418,7 @@ var RpcPayload = class RpcPayload {
382
418
  return hook.dup();
383
419
  } else return hook;
384
420
  }
385
- } else throw new Error("owned payload shouldn't contain raw ReadableStreams");
421
+ } else return streamImpl.createReadableStreamHook(stream);
386
422
  }
387
423
  deepCopy(value, oldParent, property, parent, dupStubs, owner) {
388
424
  switch (typeForRpc(value)) {
@@ -392,6 +428,8 @@ var RpcPayload = class RpcPayload {
392
428
  case "date":
393
429
  case "bytes":
394
430
  case "blob":
431
+ case "url":
432
+ case "regexp":
395
433
  case "error":
396
434
  case "undefined": return value;
397
435
  case "array": {
@@ -401,6 +439,35 @@ var RpcPayload = class RpcPayload {
401
439
  for (let i = 0; i < len; i++) result[i] = this.deepCopy(array[i], array, i, result, dupStubs, owner);
402
440
  return result;
403
441
  }
442
+ case "set": {
443
+ let set = value;
444
+ let elements = [...set];
445
+ for (let val of elements) {
446
+ let kind = typeForRpc(val);
447
+ if (kind === "rpc-promise" || kind === "rpc-thenable") throw new TypeError("Cannot pass a promise as an element of a Set. Await the value before adding it to the Set.");
448
+ }
449
+ let result = /* @__PURE__ */ new Set();
450
+ let index = 0;
451
+ for (let val of elements) {
452
+ let copy = this.deepCopy(val, set, index++, result, dupStubs, owner);
453
+ result.add(copy);
454
+ }
455
+ return result;
456
+ }
457
+ case "map": {
458
+ let map = value;
459
+ let entries = [...map];
460
+ for (let [key] of entries) {
461
+ let kind = typeForRpc(key);
462
+ if (kind === "rpc-promise" || kind === "rpc-thenable") throw new TypeError("Cannot pass a promise as a key of a Map. Await the value before using it as a key.");
463
+ }
464
+ let result = /* @__PURE__ */ new Map();
465
+ for (let [key, val] of entries) {
466
+ let keyCopy = this.deepCopy(key, map, -1, result, dupStubs, owner);
467
+ result.set(keyCopy, this.deepCopy(val, map, mapKeyToPropertyName(keyCopy), result, dupStubs, owner));
468
+ }
469
+ return result;
470
+ }
404
471
  case "object": {
405
472
  let result = {};
406
473
  let object = value;
@@ -458,8 +525,10 @@ var RpcPayload = class RpcPayload {
458
525
  case "readable": {
459
526
  let stream = value;
460
527
  let hook;
461
- if (owner) hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
462
- else hook = streamImpl.createReadableStreamHook(stream);
528
+ if (owner) {
529
+ if (owner.source === "owned") throw new Error("Can't copy a ReadableStream.");
530
+ hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
531
+ } else hook = streamImpl.createReadableStreamHook(stream);
463
532
  this.hooks.push(hook);
464
533
  return stream;
465
534
  }
@@ -485,6 +554,10 @@ var RpcPayload = class RpcPayload {
485
554
  try {
486
555
  this.value = this.deepCopy(this.value, void 0, "value", this, dupStubs, this);
487
556
  } catch (err) {
557
+ if (dupStubs) {
558
+ this.hooks.forEach((hook) => hook.dispose());
559
+ this.promises.forEach((promise) => promise.promise[Symbol.dispose]());
560
+ }
488
561
  this.hooks = void 0;
489
562
  this.promises = void 0;
490
563
  throw err;
@@ -498,7 +571,8 @@ var RpcPayload = class RpcPayload {
498
571
  this.ensureDeepCopied();
499
572
  if (this.value instanceof RpcPromise$1) RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
500
573
  else {
501
- parent[property] = this.value;
574
+ if (parent instanceof Map) parent.set(typeof property === "object" ? property.mapKey : property, this.value);
575
+ else parent[property] = this.value;
502
576
  for (let record of this.promises) RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
503
577
  }
504
578
  }
@@ -589,6 +663,8 @@ var RpcPayload = class RpcPayload {
589
663
  case "bytes":
590
664
  case "blob":
591
665
  case "date":
666
+ case "url":
667
+ case "regexp":
592
668
  case "error":
593
669
  case "undefined": return;
594
670
  case "array": {
@@ -597,6 +673,19 @@ var RpcPayload = class RpcPayload {
597
673
  for (let i = 0; i < len; i++) this.disposeImpl(array[i], array);
598
674
  return;
599
675
  }
676
+ case "set": {
677
+ let set = value;
678
+ for (let element of set) this.disposeImpl(element, set);
679
+ return;
680
+ }
681
+ case "map": {
682
+ let map = value;
683
+ for (let [key, val] of map) {
684
+ this.disposeImpl(key, map);
685
+ this.disposeImpl(val, map);
686
+ }
687
+ return;
688
+ }
600
689
  case "object": {
601
690
  let object = value;
602
691
  for (let i in object) this.disposeImpl(object[i], object);
@@ -671,6 +760,8 @@ var RpcPayload = class RpcPayload {
671
760
  case "rpc-target":
672
761
  case "writable":
673
762
  case "readable":
763
+ case "url":
764
+ case "regexp":
674
765
  case "headers":
675
766
  case "request":
676
767
  case "response": return;
@@ -680,6 +771,19 @@ var RpcPayload = class RpcPayload {
680
771
  for (let i = 0; i < len; i++) this.ignoreUnhandledRejectionsImpl(array[i]);
681
772
  return;
682
773
  }
774
+ case "set": {
775
+ let set = value;
776
+ for (let element of set) this.ignoreUnhandledRejectionsImpl(element);
777
+ return;
778
+ }
779
+ case "map": {
780
+ let map = value;
781
+ for (let [key, val] of map) {
782
+ this.ignoreUnhandledRejectionsImpl(key);
783
+ this.ignoreUnhandledRejectionsImpl(val);
784
+ }
785
+ return;
786
+ }
683
787
  case "object": {
684
788
  let object = value;
685
789
  for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
@@ -739,7 +843,11 @@ function followPath(value, parent, path, owner) {
739
843
  case "bytes":
740
844
  case "blob":
741
845
  case "date":
846
+ case "set":
847
+ case "map":
742
848
  case "error":
849
+ case "url":
850
+ case "regexp":
743
851
  case "headers":
744
852
  case "request":
745
853
  case "response":
@@ -772,17 +880,23 @@ function followPath(value, parent, path, owner) {
772
880
  }
773
881
  var ValueStubHook = class extends StubHook {
774
882
  call(path, args) {
883
+ let followResult;
775
884
  try {
776
885
  let { value, owner } = this.getValue();
777
- let followResult = followPath(value, void 0, path, owner);
778
- if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
779
- if (typeof followResult.value != "function") throw new TypeError(`'${path.join(".")}' is not a function.`);
780
- return new PromiseStubHook(args.deliverCall(followResult.value, followResult.parent).then((payload) => {
781
- return new PayloadStubHook(payload);
782
- }));
886
+ followResult = followPath(value, void 0, path, owner);
783
887
  } catch (err) {
888
+ args.dispose();
784
889
  return new ErrorStubHook(err);
785
890
  }
891
+ if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
892
+ if (typeof followResult.value != "function") {
893
+ args.dispose();
894
+ return new ErrorStubHook(/* @__PURE__ */ new TypeError(`'${path.join(".")}' is not a function.`));
895
+ }
896
+ let promise = args.deliverCall(followResult.value, followResult.parent);
897
+ return new PromiseStubHook(promise.then((payload) => {
898
+ return new PayloadStubHook(payload);
899
+ }));
786
900
  }
787
901
  map(path, captures, instructions) {
788
902
  try {
@@ -803,7 +917,10 @@ var ValueStubHook = class extends StubHook {
803
917
  get(path) {
804
918
  try {
805
919
  let { value, owner } = this.getValue();
806
- if (path.length === 0 && owner === null) throw new Error("Can't dup an RpcTarget stub as a promise.");
920
+ if (path.length === 0 && owner === null) {
921
+ if (value instanceof Object && "then" in value) return this.dup();
922
+ throw new Error("Can't dup an RpcTarget stub as a promise.");
923
+ }
807
924
  let followResult = followPath(value, void 0, path, owner);
808
925
  if (followResult.hook) return followResult.hook.get(followResult.remainingPath);
809
926
  return new PayloadStubHook(RpcPayload.deepCopyFrom(followResult.value, followResult.parent, followResult.owner));
@@ -906,7 +1023,10 @@ var TargetStubHook = class TargetStubHook extends ValueStubHook {
906
1023
  this.target = void 0;
907
1024
  }
908
1025
  }
909
- onBroken(callback) {}
1026
+ onBroken(callback) {
1027
+ let target = this.target;
1028
+ if (target && "then" in target) Promise.resolve(target).then(() => {}, callback);
1029
+ }
910
1030
  };
911
1031
  var PromiseStubHook = class PromiseStubHook extends StubHook {
912
1032
  promise;
@@ -920,12 +1040,16 @@ var PromiseStubHook = class PromiseStubHook extends StubHook {
920
1040
  }
921
1041
  call(path, args) {
922
1042
  args.ensureDeepCopied();
923
- return new PromiseStubHook(this.promise.then((hook) => hook.call(path, args)));
1043
+ return new PromiseStubHook(this.promise.then((hook) => hook.call(path, args), (err) => {
1044
+ args.dispose();
1045
+ throw err;
1046
+ }));
924
1047
  }
925
1048
  stream(path, args) {
926
1049
  args.ensureDeepCopied();
927
- return { promise: this.promise.then((hook) => {
928
- return hook.stream(path, args).promise;
1050
+ return { promise: this.promise.then((hook) => hook.stream(path, args).promise, (err) => {
1051
+ args.dispose();
1052
+ throw err;
929
1053
  }) };
930
1054
  }
931
1055
  map(path, captures, instructions) {
@@ -952,10 +1076,7 @@ var PromiseStubHook = class PromiseStubHook extends StubHook {
952
1076
  }, (err) => {});
953
1077
  }
954
1078
  dispose() {
955
- if (this.resolution) this.resolution.dispose();
956
- else this.promise.then((hook) => {
957
- hook.dispose();
958
- }, (err) => {});
1079
+ this.promise.then((hook) => hook.dispose(), () => {});
959
1080
  }
960
1081
  onBroken(callback) {
961
1082
  if (this.resolution) this.resolution.onBroken(callback);
@@ -971,7 +1092,7 @@ const DEFAULT_MAX_DEPTH = 256;
971
1092
  const DEFAULT_LIMITS = {
972
1093
  maxBigIntDigits: 16384,
973
1094
  maxDepth: 256,
974
- maxMessageSize: 32 * 1024 * 1024
1095
+ maxMessageSize: 33554432
975
1096
  };
976
1097
  const NATIVE_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
977
1098
  const BYTE_CONTAINER_TYPE_NAMES = [
@@ -1033,9 +1154,7 @@ function swapByteOrder(bytes, elementSize) {
1033
1154
  case 4:
1034
1155
  view.setUint32(offset, view.getUint32(offset, false), true);
1035
1156
  break;
1036
- case 8:
1037
- view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1038
- break;
1157
+ case 8: view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1039
1158
  }
1040
1159
  }
1041
1160
  var NullExporter = class {
@@ -1120,6 +1239,30 @@ var Devaluator = class Devaluator {
1120
1239
  for (let i = 0; i < len; i++) result[i] = this.devaluateImpl(array[i], array, depth + 1);
1121
1240
  return [result];
1122
1241
  }
1242
+ case "set": {
1243
+ let set = value;
1244
+ let setElements = [...set];
1245
+ let elements = [];
1246
+ for (let element of setElements) switch (typeForRpc(element)) {
1247
+ case "blob": throw new TypeError("Cannot serialize a Blob as an element of a Set.");
1248
+ case "rpc-promise":
1249
+ case "rpc-thenable": throw new TypeError("Cannot serialize a promise as an element of a Set. Await the value before adding it to the Set.");
1250
+ }
1251
+ for (let element of setElements) elements.push(this.devaluateImpl(element, set, depth + 1));
1252
+ return ["set", elements];
1253
+ }
1254
+ case "map": {
1255
+ let map = value;
1256
+ let mapEntries = [...map];
1257
+ let entries = [];
1258
+ for (let [key] of mapEntries) switch (typeForRpc(key)) {
1259
+ case "blob": throw new TypeError("Cannot serialize a Blob as a key of a Map.");
1260
+ case "rpc-promise":
1261
+ case "rpc-thenable": throw new TypeError("Cannot serialize a promise as a key of a Map. Await the value before using it as a key.");
1262
+ }
1263
+ for (let [key, val] of mapEntries) entries.push([this.devaluateImpl(key, map, depth + 1), this.devaluateImpl(val, map, depth + 1)]);
1264
+ return ["map", entries];
1265
+ }
1123
1266
  case "bigint":
1124
1267
  if (this.encodingLevel === "structuredClonable") return value;
1125
1268
  return ["bigint", value.toString()];
@@ -1128,6 +1271,15 @@ var Devaluator = class Devaluator {
1128
1271
  const time = value.getTime();
1129
1272
  return ["date", Number.isNaN(time) ? null : time];
1130
1273
  }
1274
+ case "regexp": {
1275
+ if (this.encodingLevel === "structuredClonable") return value;
1276
+ let re = value;
1277
+ return re.flags ? [
1278
+ "regexp",
1279
+ re.source,
1280
+ re.flags
1281
+ ] : ["regexp", re.source];
1282
+ }
1131
1283
  case "bytes": {
1132
1284
  let alternateTypeName = BYTE_CONTAINER_TYPE_BY_PROTOTYPE.get(Object.getPrototypeOf(value));
1133
1285
  let bytes;
@@ -1142,11 +1294,14 @@ var Devaluator = class Devaluator {
1142
1294
  swapByteOrder(bytes, elementSize);
1143
1295
  }
1144
1296
  }
1145
- if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return alternateTypeName === void 0 ? ["bytes", bytes] : [
1146
- "bytes",
1147
- bytes,
1148
- alternateTypeName
1149
- ];
1297
+ if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") {
1298
+ if (bytes.byteLength !== bytes.buffer.byteLength) bytes = new Uint8Array(bytes);
1299
+ return alternateTypeName === void 0 ? ["bytes", bytes] : [
1300
+ "bytes",
1301
+ bytes,
1302
+ alternateTypeName
1303
+ ];
1304
+ }
1150
1305
  let b64;
1151
1306
  if (bytes.toBase64) b64 = bytes.toBase64({ omitPadding: true });
1152
1307
  else if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
@@ -1162,6 +1317,7 @@ var Devaluator = class Devaluator {
1162
1317
  alternateTypeName
1163
1318
  ];
1164
1319
  }
1320
+ case "url": return ["url", value.href];
1165
1321
  case "headers": return ["headers", [...value]];
1166
1322
  case "request": {
1167
1323
  let req = value;
@@ -1284,13 +1440,16 @@ var Devaluator = class Devaluator {
1284
1440
  if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
1285
1441
  let { hook, pathIfPromise } = unwrapStubAndPath(value);
1286
1442
  let importId = this.exporter.getImport(hook);
1287
- if (importId !== void 0) if (pathIfPromise) if (pathIfPromise.length > 0) return [
1288
- "pipeline",
1289
- importId,
1290
- pathIfPromise
1291
- ];
1292
- else return ["pipeline", importId];
1293
- else return ["import", importId];
1443
+ if (importId !== void 0) {
1444
+ if (pathIfPromise) {
1445
+ if (pathIfPromise.length > 0) return [
1446
+ "pipeline",
1447
+ importId,
1448
+ pathIfPromise
1449
+ ];
1450
+ else return ["pipeline", importId];
1451
+ } else return ["import", importId];
1452
+ }
1294
1453
  if (pathIfPromise) hook = hook.get(pathIfPromise);
1295
1454
  else hook = hook.dup();
1296
1455
  return this.devaluateHook(pathIfPromise ? "promise" : "export", hook);
@@ -1351,16 +1510,18 @@ var NullImporter = class {
1351
1510
  };
1352
1511
  const NULL_IMPORTER = new NullImporter();
1353
1512
  function fixBrokenRequestBody(request, body) {
1354
- return new RpcPromise$1(new PromiseStubHook(new Response(body).arrayBuffer().then((arrayBuffer) => {
1513
+ let promise = new Response(body).arrayBuffer().then((arrayBuffer) => {
1355
1514
  let bytes = new Uint8Array(arrayBuffer);
1356
1515
  let result = new Request(request, { body: bytes });
1357
1516
  return new PayloadStubHook(RpcPayload.fromAppReturn(result));
1358
- })), []);
1517
+ });
1518
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1359
1519
  }
1360
1520
  function streamToBlobPromise(stream, type) {
1361
- return new RpcPromise$1(new PromiseStubHook(streamToBlob(stream, type).then((blob) => {
1521
+ let promise = streamToBlob(stream, type).then((blob) => {
1362
1522
  return new PayloadStubHook(RpcPayload.fromAppReturn(blob));
1363
- })), []);
1523
+ });
1524
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1364
1525
  }
1365
1526
  var Evaluator = class Evaluator {
1366
1527
  importer;
@@ -1393,7 +1554,7 @@ var Evaluator = class Evaluator {
1393
1554
  let maxDepth = this.limits.maxDepth;
1394
1555
  if (depth >= maxDepth) throw new TypeError(`Deserialization exceeded maximum allowed message depth of ${maxDepth}.`);
1395
1556
  if (this.encodingLevel === "structuredClonable") {
1396
- if (value instanceof Date || typeof value === "bigint") return value;
1557
+ if (value instanceof Date || value instanceof RegExp || typeof value === "bigint") return value;
1397
1558
  }
1398
1559
  if (value instanceof Array) {
1399
1560
  if (value.length == 1 && value[0] instanceof Array) {
@@ -1413,18 +1574,48 @@ var Evaluator = class Evaluator {
1413
1574
  if (value[1] === null) return /* @__PURE__ */ new Date(NaN);
1414
1575
  if (typeof value[1] == "number") return new Date(value[1]);
1415
1576
  break;
1577
+ case "regexp":
1578
+ if (typeof value[1] === "string" && (value.length === 2 || value.length === 3 && typeof value[2] === "string")) return new RegExp(value[1], value[2]);
1579
+ break;
1580
+ case "set":
1581
+ if (value.length === 2 && value[1] instanceof Array) {
1582
+ let elements = value[1];
1583
+ let set = /* @__PURE__ */ new Set();
1584
+ for (let i = 0; i < elements.length; i++) {
1585
+ let copy = this.evaluateImpl(elements[i], set, i, depth + 1);
1586
+ if (copy instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as an element of a Set.");
1587
+ set.add(copy);
1588
+ }
1589
+ return set;
1590
+ }
1591
+ break;
1592
+ case "map":
1593
+ if (value.length === 2 && value[1] instanceof Array) {
1594
+ let entries = value[1];
1595
+ let map = /* @__PURE__ */ new Map();
1596
+ for (let i = 0; i < entries.length; i++) {
1597
+ let entry = entries[i];
1598
+ if (!(entry instanceof Array) || entry.length !== 2) throw new TypeError("Map entries must be serialized as key/value pairs.");
1599
+ let key = this.evaluateImpl(entry[0], map, i, depth + 1);
1600
+ if (key instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as a key of a Map.");
1601
+ map.set(key, this.evaluateImpl(entry[1], map, mapKeyToPropertyName(key), depth + 1));
1602
+ }
1603
+ return map;
1604
+ }
1605
+ break;
1416
1606
  case "bytes": {
1417
1607
  let bytes;
1418
1608
  if (value[1] instanceof Uint8Array) bytes = value[1];
1419
- else if (typeof value[1] == "string") if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1420
- else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1421
- else {
1422
- let bs = atob(value[1]);
1423
- let len = bs.length;
1424
- bytes = new Uint8Array(len);
1425
- for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1426
- }
1427
- else break;
1609
+ else if (typeof value[1] == "string") {
1610
+ if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1611
+ else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1612
+ else {
1613
+ let bs = atob(value[1]);
1614
+ let len = bs.length;
1615
+ bytes = new Uint8Array(len);
1616
+ for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1617
+ }
1618
+ } else break;
1428
1619
  if (value.length === 2) return bytes;
1429
1620
  if (typeof value[2] !== "string") throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`);
1430
1621
  if (!isValidByteContainerName(value[2])) {
@@ -1450,7 +1641,6 @@ var Evaluator = class Evaluator {
1450
1641
  case "BigUint64Array": return new BigUint64Array(buffer);
1451
1642
  case "Float32Array": return new Float32Array(buffer);
1452
1643
  case "Float64Array": return new Float64Array(buffer);
1453
- default:
1454
1644
  }
1455
1645
  }
1456
1646
  case "error":
@@ -1481,6 +1671,9 @@ var Evaluator = class Evaluator {
1481
1671
  case "inf": return Infinity;
1482
1672
  case "-inf": return -Infinity;
1483
1673
  case "nan": return NaN;
1674
+ case "url":
1675
+ if (value.length === 2 && typeof value[1] === "string") return new URL(value[1]);
1676
+ break;
1484
1677
  case "headers":
1485
1678
  if (value.length === 2 && value[1] instanceof Array) return new Headers(value[1]);
1486
1679
  break;
@@ -1550,11 +1743,13 @@ var Evaluator = class Evaluator {
1550
1743
  return promise;
1551
1744
  } else {
1552
1745
  this.hooks.push(hook);
1553
- return new RpcPromise$1(hook, []);
1746
+ return new RpcStub$1(hook);
1554
1747
  }
1555
1748
  };
1556
- if (value.length == 2) if (isPromise) return addStub(hook.get([]));
1557
- else return addStub(hook.dup());
1749
+ if (value.length == 2) {
1750
+ if (isPromise) return addStub(hook.get([]));
1751
+ else return addStub(hook.dup());
1752
+ }
1558
1753
  let path = value[2];
1559
1754
  if (!(path instanceof Array)) break;
1560
1755
  if (!path.every((part) => {
@@ -1584,7 +1779,8 @@ var Evaluator = class Evaluator {
1584
1779
  }
1585
1780
  });
1586
1781
  let instructions = value[4];
1587
- let promise = new RpcPromise$1(hook.map(path, captures, instructions), []);
1782
+ let resultHook = hook.map(path, captures, instructions);
1783
+ let promise = new RpcPromise$1(resultHook, []);
1588
1784
  this.promises.push({
1589
1785
  promise,
1590
1786
  parent,
@@ -1594,18 +1790,21 @@ var Evaluator = class Evaluator {
1594
1790
  }
1595
1791
  case "export":
1596
1792
  case "promise":
1597
- if (typeof value[1] == "number") if (value[0] == "promise") {
1598
- let promise = new RpcPromise$1(this.importer.importPromise(value[1]), []);
1599
- this.promises.push({
1600
- parent,
1601
- property,
1602
- promise
1603
- });
1604
- return promise;
1605
- } else {
1606
- let hook = this.importer.importStub(value[1]);
1607
- this.hooks.push(hook);
1608
- return new RpcStub$1(hook);
1793
+ if (typeof value[1] == "number") {
1794
+ if (value[0] == "promise") {
1795
+ let hook = this.importer.importPromise(value[1]);
1796
+ let promise = new RpcPromise$1(hook, []);
1797
+ this.promises.push({
1798
+ parent,
1799
+ property,
1800
+ promise
1801
+ });
1802
+ return promise;
1803
+ } else {
1804
+ let hook = this.importer.importStub(value[1]);
1805
+ this.hooks.push(hook);
1806
+ return new RpcStub$1(hook);
1807
+ }
1609
1808
  }
1610
1809
  break;
1611
1810
  case "writable":
@@ -1616,14 +1815,12 @@ var Evaluator = class Evaluator {
1616
1815
  return stream;
1617
1816
  }
1618
1817
  break;
1619
- case "readable":
1620
- if (typeof value[1] == "number") {
1621
- let stream = this.importer.getPipeReadable(value[1]);
1622
- let hook = streamImpl.createReadableStreamHook(stream);
1623
- this.hooks.push(hook);
1624
- return stream;
1625
- }
1626
- break;
1818
+ case "readable": if (typeof value[1] == "number") {
1819
+ let stream = this.importer.getPipeReadable(value[1]);
1820
+ let hook = streamImpl.createReadableStreamHook(stream);
1821
+ this.hooks.push(hook);
1822
+ return stream;
1823
+ }
1627
1824
  }
1628
1825
  throw new TypeError(`unknown special value: ${JSON.stringify(value)}`);
1629
1826
  } else if (value instanceof Object) {
@@ -1668,6 +1865,7 @@ function estimateEncodedSize(value, seen, depth = 0) {
1668
1865
  if (value instanceof ArrayBuffer) return ESTIMATED_BINARY_OVERHEAD + value.byteLength;
1669
1866
  if (typeof Blob !== "undefined" && value instanceof Blob) return ESTIMATED_BINARY_OVERHEAD + value.size;
1670
1867
  if (value instanceof Date) return 16;
1868
+ if (value instanceof RegExp) return ESTIMATED_OBJECT_OVERHEAD + estimateStringSize(value.source) + estimateStringSize(value.flags);
1671
1869
  seen ??= /* @__PURE__ */ new WeakSet();
1672
1870
  if (seen.has(value)) return ESTIMATED_ENTRY_OVERHEAD;
1673
1871
  seen.add(value);
@@ -1780,24 +1978,28 @@ var RpcImportHook = class RpcImportHook extends StubHook {
1780
1978
  if (this.entry) return this.entry;
1781
1979
  else throw new Error("This RpcImportHook was already disposed.");
1782
1980
  }
1981
+ getEntryTakingOwnership(disposeOwned) {
1982
+ try {
1983
+ return this.getEntry();
1984
+ } catch (err) {
1985
+ disposeOwned();
1986
+ throw err;
1987
+ }
1988
+ }
1783
1989
  call(path, args) {
1784
- let entry = this.getEntry();
1990
+ let entry = this.getEntryTakingOwnership(() => args.dispose());
1785
1991
  if (entry.resolution) return entry.resolution.call(path, args);
1786
1992
  else return entry.session.sendCall(entry.importId, path, args);
1787
1993
  }
1788
1994
  stream(path, args) {
1789
- let entry = this.getEntry();
1995
+ let entry = this.getEntryTakingOwnership(() => args.dispose());
1790
1996
  if (entry.resolution) return entry.resolution.stream(path, args);
1791
1997
  else return entry.session.sendStream(entry.importId, path, args);
1792
1998
  }
1793
1999
  map(path, captures, instructions) {
1794
- let entry;
1795
- try {
1796
- entry = this.getEntry();
1797
- } catch (err) {
2000
+ let entry = this.getEntryTakingOwnership(() => {
1798
2001
  for (let cap of captures) cap.dispose();
1799
- throw err;
1800
- }
2002
+ });
1801
2003
  if (entry.resolution) return entry.resolution.map(path, captures, instructions);
1802
2004
  else return entry.session.sendMap(entry.importId, path, captures, instructions);
1803
2005
  }
@@ -1984,7 +2186,7 @@ var RpcSessionImpl = class {
1984
2186
  }
1985
2187
  }
1986
2188
  getImport(hook) {
1987
- if (hook instanceof RpcImportHook && hook.entry && hook.entry.session === this) return hook.entry.importId;
2189
+ if (hook instanceof RpcImportHook && hook.entry && hook.entry.session === this && !hook.entry.resolution) return hook.entry.importId;
1988
2190
  else return;
1989
2191
  }
1990
2192
  importStub(idx) {
@@ -2058,14 +2260,23 @@ var RpcSessionImpl = class {
2058
2260
  }
2059
2261
  }
2060
2262
  sendCall(id, path, args) {
2061
- if (this.abortReason) throw this.abortReason;
2263
+ if (this.abortReason) {
2264
+ args?.dispose();
2265
+ throw this.abortReason;
2266
+ }
2062
2267
  let value = [
2063
2268
  "pipeline",
2064
2269
  id,
2065
2270
  path
2066
2271
  ];
2067
2272
  if (args) {
2068
- let devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2273
+ let devalue;
2274
+ try {
2275
+ devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2276
+ } catch (err) {
2277
+ args.dispose();
2278
+ throw err;
2279
+ }
2069
2280
  value.push(devalue[0]);
2070
2281
  }
2071
2282
  this.send(["push", value]);
@@ -2074,13 +2285,22 @@ var RpcSessionImpl = class {
2074
2285
  return new RpcImportHook(true, entry);
2075
2286
  }
2076
2287
  sendStream(id, path, args) {
2077
- if (this.abortReason) throw this.abortReason;
2288
+ if (this.abortReason) {
2289
+ args.dispose();
2290
+ throw this.abortReason;
2291
+ }
2078
2292
  let value = [
2079
2293
  "pipeline",
2080
2294
  id,
2081
2295
  path
2082
2296
  ];
2083
- let devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2297
+ let devalue;
2298
+ try {
2299
+ devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2300
+ } catch (err) {
2301
+ args.dispose();
2302
+ throw err;
2303
+ }
2084
2304
  value.push(devalue[0]);
2085
2305
  let msg = ["stream", value];
2086
2306
  let size = this.send(msg);
@@ -2181,7 +2401,8 @@ var RpcSessionImpl = class {
2181
2401
  if (msg instanceof Array) switch (msg[0]) {
2182
2402
  case "push":
2183
2403
  if (msg.length > 1) {
2184
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2404
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2405
+ let hook = new PayloadStubHook(payload);
2185
2406
  hook.ignoreUnhandledRejections();
2186
2407
  this.exports.push({
2187
2408
  hook,
@@ -2192,7 +2413,8 @@ var RpcSessionImpl = class {
2192
2413
  break;
2193
2414
  case "stream":
2194
2415
  if (msg.length > 1) {
2195
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2416
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2417
+ let hook = new PayloadStubHook(payload);
2196
2418
  hook.ignoreUnhandledRejections();
2197
2419
  let exportId = this.exports.length;
2198
2420
  this.exports.push({
@@ -2227,13 +2449,14 @@ var RpcSessionImpl = class {
2227
2449
  let importId = msg[1];
2228
2450
  if (typeof importId == "number" && msg.length > 2) {
2229
2451
  let imp = this.imports[importId];
2230
- if (imp) if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2231
- else {
2232
- let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2233
- payload.dispose();
2234
- imp.resolve(new ErrorStubHook(payload.value));
2235
- }
2236
- else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2452
+ if (imp) {
2453
+ if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2454
+ else {
2455
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2456
+ payload.dispose();
2457
+ imp.resolve(new ErrorStubHook(payload.value));
2458
+ }
2459
+ } else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2237
2460
  continue;
2238
2461
  }
2239
2462
  break;
@@ -2301,11 +2524,12 @@ var RpcSession$1 = class {
2301
2524
 
2302
2525
  //#endregion
2303
2526
  //#region src/websocket.ts
2304
- /** Close-frame reason max UTF-8 bytes: 125 payload − 2-byte status (RFC 6455 §5.5). */
2527
+ /** Close-frame reason max UTF-8 bytes: 125 payload - 2-byte status (RFC 6455 section 5.5). */
2305
2528
  const MAX_CLOSE_REASON_BYTES = 123;
2306
2529
  function newWebSocketRpcSession$1(webSocket, localMain, options) {
2307
2530
  if (typeof webSocket === "string") webSocket = new WebSocket(webSocket);
2308
- return new RpcSession$1(new WebSocketTransport(webSocket), localMain, options).getRemoteMain();
2531
+ let transport = new WebSocketTransport(webSocket);
2532
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2309
2533
  }
2310
2534
  /**
2311
2535
  * For use in Cloudflare Workers: Construct an HTTP response that starts a WebSocket RPC session
@@ -2342,12 +2566,13 @@ var WebSocketTransport = class {
2342
2566
  });
2343
2567
  }
2344
2568
  webSocket.addEventListener("message", (event) => {
2345
- if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) if (this.#receiveResolver) {
2346
- this.#receiveResolver(event.data);
2347
- this.#receiveResolver = void 0;
2348
- this.#receiveRejecter = void 0;
2349
- } else this.#receiveQueue.push(event.data);
2350
- else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2569
+ if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) {
2570
+ if (this.#receiveResolver) {
2571
+ this.#receiveResolver(event.data);
2572
+ this.#receiveResolver = void 0;
2573
+ this.#receiveRejecter = void 0;
2574
+ } else this.#receiveQueue.push(event.data);
2575
+ } else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2351
2576
  });
2352
2577
  webSocket.addEventListener("close", (event) => {
2353
2578
  this.#receivedError(/* @__PURE__ */ new Error(`Peer closed WebSocket: ${event.code} ${event.reason}`));
@@ -2439,7 +2664,8 @@ function newHttpBatchRpcSession$1(urlOrRequest, options) {
2439
2664
  let body = await response.text();
2440
2665
  return body == "" ? [] : body.split("\n");
2441
2666
  };
2442
- return new RpcSession$1(new BatchClientTransport(sendBatch), void 0, options).getRemoteMain();
2667
+ let transport = new BatchClientTransport(sendBatch);
2668
+ return new RpcSession$1(transport, void 0, options).getRemoteMain();
2443
2669
  }
2444
2670
  var BatchServerTransport = class {
2445
2671
  constructor(batch) {
@@ -2482,7 +2708,8 @@ var BatchServerTransport = class {
2482
2708
  async function newHttpBatchRpcResponse(request, localMain, options) {
2483
2709
  if (request.method !== "POST") return new Response("This endpoint only accepts POST requests.", { status: 405 });
2484
2710
  let body = await request.text();
2485
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2711
+ let batch = body === "" ? [] : body.split("\n");
2712
+ let transport = new BatchServerTransport(batch);
2486
2713
  let rpc = new RpcSession$1(transport, localMain, options);
2487
2714
  await transport.whenAllReceived();
2488
2715
  await rpc.drain();
@@ -2512,7 +2739,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2512
2739
  });
2513
2740
  request.on("error", reject);
2514
2741
  });
2515
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2742
+ let batch = body === "" ? [] : body.split("\n");
2743
+ let transport = new BatchServerTransport(batch);
2516
2744
  let rpc = new RpcSession$1(transport, localMain, options);
2517
2745
  await transport.whenAllReceived();
2518
2746
  await rpc.drain();
@@ -2523,7 +2751,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2523
2751
  //#endregion
2524
2752
  //#region src/messageport.ts
2525
2753
  function newMessagePortRpcSession$1(port, localMain, options) {
2526
- return new RpcSession$1(new MessagePortTransport(port), localMain, options).getRemoteMain();
2754
+ let transport = new MessagePortTransport(port);
2755
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2527
2756
  }
2528
2757
  var MessagePortTransport = class {
2529
2758
  encodingLevel = "structuredClonable";
@@ -2711,9 +2940,11 @@ var MapVariableHook = class extends StubHook {
2711
2940
  else throwMapperBuilderUseError();
2712
2941
  }
2713
2942
  call(path, args) {
2943
+ args.dispose();
2714
2944
  throwMapperBuilderUseError();
2715
2945
  }
2716
2946
  map(path, captures, instructions) {
2947
+ for (let cap of captures) cap.dispose();
2717
2948
  throwMapperBuilderUseError();
2718
2949
  }
2719
2950
  pull() {
@@ -2771,7 +3002,8 @@ var MapApplicator = class {
2771
3002
  }
2772
3003
  };
2773
3004
  function applyMapToElement(input, parent, owner, captures, instructions) {
2774
- let mapper = new MapApplicator(captures, new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner)));
3005
+ let inputHook = new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner));
3006
+ let mapper = new MapApplicator(captures, inputHook);
2775
3007
  try {
2776
3008
  return mapper.apply(instructions);
2777
3009
  } finally {
@@ -2804,9 +3036,10 @@ mapImpl.applyMap = (input, parent, owner, captures, instructions) => {
2804
3036
  var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2805
3037
  state;
2806
3038
  static create(stream) {
3039
+ let writer = stream.getWriter();
2807
3040
  return new WritableStreamStubHook({
2808
3041
  refcount: 1,
2809
- writer: stream.getWriter(),
3042
+ writer,
2810
3043
  closed: false
2811
3044
  });
2812
3045
  }
@@ -2824,13 +3057,12 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2824
3057
  let state = this.getState();
2825
3058
  if (path.length !== 1 || typeof path[0] !== "string") throw new Error("WritableStream stub only supports direct method calls");
2826
3059
  const method = path[0];
2827
- if (method !== "write" && method !== "close" && method !== "abort") {
2828
- args.dispose();
2829
- throw new Error(`Unknown WritableStream method: ${method}`);
2830
- }
3060
+ if (method !== "write" && method !== "close" && method !== "abort") throw new Error(`Unknown WritableStream method: ${method}`);
2831
3061
  if (method === "close" || method === "abort") state.closed = true;
2832
- return new PromiseStubHook((method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer)).then((payload) => new PayloadStubHook(payload)));
3062
+ let promise = method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer);
3063
+ return new PromiseStubHook(promise.then((payload) => new PayloadStubHook(payload)));
2833
3064
  } catch (err) {
3065
+ args.dispose();
2834
3066
  return new ErrorStubHook(err);
2835
3067
  }
2836
3068
  }
@@ -2842,7 +3074,8 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2842
3074
  return new ErrorStubHook(/* @__PURE__ */ new Error("Cannot access properties on a WritableStream stub"));
2843
3075
  }
2844
3076
  dup() {
2845
- return new WritableStreamStubHook(this.getState(), this);
3077
+ let state = this.getState();
3078
+ return new WritableStreamStubHook(state, this);
2846
3079
  }
2847
3080
  pull() {
2848
3081
  return Promise.reject(/* @__PURE__ */ new Error("Cannot pull a WritableStream stub"));
@@ -2860,9 +3093,9 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2860
3093
  }
2861
3094
  onBroken(callback) {}
2862
3095
  };
2863
- const INITIAL_WINDOW = 256 * 1024;
2864
- const MAX_WINDOW = 1024 * 1024 * 1024;
2865
- const MIN_WINDOW = 64 * 1024;
3096
+ const INITIAL_WINDOW = 262144;
3097
+ const MAX_WINDOW = 1073741824;
3098
+ const MIN_WINDOW = 65536;
2866
3099
  const STARTUP_GROWTH_FACTOR = 2;
2867
3100
  const STEADY_GROWTH_FACTOR = 1.25;
2868
3101
  const DECAY_FACTOR = .9;