capnweb 0.11.1 → 0.13.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,9 @@ function typeForRpc(value) {
46
46
  case AsyncFunction.prototype: return "function";
47
47
  case Array.prototype: return "array";
48
48
  case Date.prototype: return "date";
49
+ case RegExp.prototype: return "regexp";
50
+ case Set.prototype: return "set";
51
+ case Map.prototype: return "map";
49
52
  case Uint8Array.prototype:
50
53
  case BUFFER_PROTOTYPE:
51
54
  case ArrayBuffer.prototype:
@@ -96,7 +99,14 @@ let streamImpl = {
96
99
  };
97
100
  var StubHook = class {
98
101
  stream(path, args) {
99
- let pulled = this.call(path, args).pull();
102
+ let hook = this.call(path, args);
103
+ let pulled;
104
+ try {
105
+ pulled = hook.pull();
106
+ } catch (err) {
107
+ hook.dispose();
108
+ throw err;
109
+ }
100
110
  let promise;
101
111
  if (pulled instanceof Promise) promise = pulled.then((p) => {
102
112
  p.dispose();
@@ -115,9 +125,11 @@ var ErrorStubHook = class extends StubHook {
115
125
  this.error = error;
116
126
  }
117
127
  call(path, args) {
128
+ args.dispose();
118
129
  return this;
119
130
  }
120
131
  map(path, captures, instructions) {
132
+ for (let cap of captures) cap.dispose();
121
133
  return this;
122
134
  }
123
135
  get(path) {
@@ -241,7 +253,25 @@ var RpcStub$1 = class RpcStub$1 extends RpcTarget$1 {
241
253
  };
242
254
  var RpcPromise$1 = class extends RpcStub$1 {
243
255
  constructor(hook, pathIfPromise) {
244
- super(hook, pathIfPromise);
256
+ if (hook instanceof StubHook) super(hook, pathIfPromise ?? []);
257
+ else {
258
+ if (pathIfPromise !== void 0) throw new TypeError("RpcPromise constructor expected one argument, received two.");
259
+ let kind = typeForRpc(hook);
260
+ if (kind === "rpc-promise") {
261
+ let raw = unwrapStubAndPath(hook);
262
+ if (raw.pathIfPromise.length > 0) super(raw.hook, raw.pathIfPromise);
263
+ else {
264
+ let adopted = raw.hook;
265
+ raw.hook = DISPOSED_HOOK;
266
+ super(adopted, []);
267
+ }
268
+ } else if (kind === "rpc-thenable") super(TargetStubHook.create(hook, void 0), []);
269
+ else {
270
+ let promiseHook = new PromiseStubHook(Promise.resolve(hook).then((value) => new PayloadStubHook(RpcPayload.fromAppReturn(value))));
271
+ promiseHook.ignoreUnhandledRejections();
272
+ super(promiseHook, []);
273
+ }
274
+ }
245
275
  }
246
276
  then(onfulfilled, onrejected) {
247
277
  return pullPromise(this).then(...arguments);
@@ -282,6 +312,9 @@ async function pullPromise(promise) {
282
312
  if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
283
313
  return (await hook.pull()).deliverResolve();
284
314
  }
315
+ function mapKeyToPropertyName(key) {
316
+ return typeof key === "string" || typeof key === "number" ? key : { mapKey: key };
317
+ }
285
318
  var RpcPayload = class RpcPayload {
286
319
  value;
287
320
  source;
@@ -336,12 +369,13 @@ var RpcPayload = class RpcPayload {
336
369
  return TargetStubHook.create(target, parent);
337
370
  } else if (this.source === "return") {
338
371
  let hook = this.rpcTargets?.get(target);
339
- if (hook) if (dupStubs) return hook.dup();
340
- else {
341
- this.rpcTargets?.delete(target);
342
- return hook;
343
- }
344
- else {
372
+ if (hook) {
373
+ if (dupStubs) return hook.dup();
374
+ else {
375
+ this.rpcTargets?.delete(target);
376
+ return hook;
377
+ }
378
+ } else {
345
379
  hook = TargetStubHook.create(target, parent);
346
380
  if (dupStubs) {
347
381
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -355,12 +389,13 @@ var RpcPayload = class RpcPayload {
355
389
  if (this.source === "params") return streamImpl.createWritableStreamHook(stream);
356
390
  else if (this.source === "return") {
357
391
  let hook = this.rpcTargets?.get(stream);
358
- if (hook) if (dupStubs) return hook.dup();
359
- else {
360
- this.rpcTargets?.delete(stream);
361
- return hook;
362
- }
363
- else {
392
+ if (hook) {
393
+ if (dupStubs) return hook.dup();
394
+ else {
395
+ this.rpcTargets?.delete(stream);
396
+ return hook;
397
+ }
398
+ } else {
364
399
  hook = streamImpl.createWritableStreamHook(stream);
365
400
  if (dupStubs) {
366
401
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -374,12 +409,13 @@ var RpcPayload = class RpcPayload {
374
409
  if (this.source === "params") return streamImpl.createReadableStreamHook(stream);
375
410
  else if (this.source === "return") {
376
411
  let hook = this.rpcTargets?.get(stream);
377
- if (hook) if (dupStubs) return hook.dup();
378
- else {
379
- this.rpcTargets?.delete(stream);
380
- return hook;
381
- }
382
- else {
412
+ if (hook) {
413
+ if (dupStubs) return hook.dup();
414
+ else {
415
+ this.rpcTargets?.delete(stream);
416
+ return hook;
417
+ }
418
+ } else {
383
419
  hook = streamImpl.createReadableStreamHook(stream);
384
420
  if (dupStubs) {
385
421
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -387,7 +423,7 @@ var RpcPayload = class RpcPayload {
387
423
  return hook.dup();
388
424
  } else return hook;
389
425
  }
390
- } else throw new Error("owned payload shouldn't contain raw ReadableStreams");
426
+ } else return streamImpl.createReadableStreamHook(stream);
391
427
  }
392
428
  deepCopy(value, oldParent, property, parent, dupStubs, owner) {
393
429
  switch (typeForRpc(value)) {
@@ -398,6 +434,7 @@ var RpcPayload = class RpcPayload {
398
434
  case "bytes":
399
435
  case "blob":
400
436
  case "url":
437
+ case "regexp":
401
438
  case "error":
402
439
  case "undefined": return value;
403
440
  case "array": {
@@ -407,6 +444,35 @@ var RpcPayload = class RpcPayload {
407
444
  for (let i = 0; i < len; i++) result[i] = this.deepCopy(array[i], array, i, result, dupStubs, owner);
408
445
  return result;
409
446
  }
447
+ case "set": {
448
+ let set = value;
449
+ let elements = [...set];
450
+ for (let val of elements) {
451
+ let kind = typeForRpc(val);
452
+ 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.");
453
+ }
454
+ let result = /* @__PURE__ */ new Set();
455
+ let index = 0;
456
+ for (let val of elements) {
457
+ let copy = this.deepCopy(val, set, index++, result, dupStubs, owner);
458
+ result.add(copy);
459
+ }
460
+ return result;
461
+ }
462
+ case "map": {
463
+ let map = value;
464
+ let entries = [...map];
465
+ for (let [key] of entries) {
466
+ let kind = typeForRpc(key);
467
+ 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.");
468
+ }
469
+ let result = /* @__PURE__ */ new Map();
470
+ for (let [key, val] of entries) {
471
+ let keyCopy = this.deepCopy(key, map, -1, result, dupStubs, owner);
472
+ result.set(keyCopy, this.deepCopy(val, map, mapKeyToPropertyName(keyCopy), result, dupStubs, owner));
473
+ }
474
+ return result;
475
+ }
410
476
  case "object": {
411
477
  let result = {};
412
478
  let object = value;
@@ -464,8 +530,10 @@ var RpcPayload = class RpcPayload {
464
530
  case "readable": {
465
531
  let stream = value;
466
532
  let hook;
467
- if (owner) hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
468
- else hook = streamImpl.createReadableStreamHook(stream);
533
+ if (owner) {
534
+ if (owner.source === "owned") throw new Error("Can't copy a ReadableStream.");
535
+ hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
536
+ } else hook = streamImpl.createReadableStreamHook(stream);
469
537
  this.hooks.push(hook);
470
538
  return stream;
471
539
  }
@@ -491,6 +559,10 @@ var RpcPayload = class RpcPayload {
491
559
  try {
492
560
  this.value = this.deepCopy(this.value, void 0, "value", this, dupStubs, this);
493
561
  } catch (err) {
562
+ if (dupStubs) {
563
+ this.hooks.forEach((hook) => hook.dispose());
564
+ this.promises.forEach((promise) => promise.promise[Symbol.dispose]());
565
+ }
494
566
  this.hooks = void 0;
495
567
  this.promises = void 0;
496
568
  throw err;
@@ -504,7 +576,8 @@ var RpcPayload = class RpcPayload {
504
576
  this.ensureDeepCopied();
505
577
  if (this.value instanceof RpcPromise$1) RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
506
578
  else {
507
- parent[property] = this.value;
579
+ if (parent instanceof Map) parent.set(typeof property === "object" ? property.mapKey : property, this.value);
580
+ else parent[property] = this.value;
508
581
  for (let record of this.promises) RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
509
582
  }
510
583
  }
@@ -596,6 +669,7 @@ var RpcPayload = class RpcPayload {
596
669
  case "blob":
597
670
  case "date":
598
671
  case "url":
672
+ case "regexp":
599
673
  case "error":
600
674
  case "undefined": return;
601
675
  case "array": {
@@ -604,6 +678,19 @@ var RpcPayload = class RpcPayload {
604
678
  for (let i = 0; i < len; i++) this.disposeImpl(array[i], array);
605
679
  return;
606
680
  }
681
+ case "set": {
682
+ let set = value;
683
+ for (let element of set) this.disposeImpl(element, set);
684
+ return;
685
+ }
686
+ case "map": {
687
+ let map = value;
688
+ for (let [key, val] of map) {
689
+ this.disposeImpl(key, map);
690
+ this.disposeImpl(val, map);
691
+ }
692
+ return;
693
+ }
607
694
  case "object": {
608
695
  let object = value;
609
696
  for (let i in object) this.disposeImpl(object[i], object);
@@ -679,6 +766,7 @@ var RpcPayload = class RpcPayload {
679
766
  case "writable":
680
767
  case "readable":
681
768
  case "url":
769
+ case "regexp":
682
770
  case "headers":
683
771
  case "request":
684
772
  case "response": return;
@@ -688,6 +776,19 @@ var RpcPayload = class RpcPayload {
688
776
  for (let i = 0; i < len; i++) this.ignoreUnhandledRejectionsImpl(array[i]);
689
777
  return;
690
778
  }
779
+ case "set": {
780
+ let set = value;
781
+ for (let element of set) this.ignoreUnhandledRejectionsImpl(element);
782
+ return;
783
+ }
784
+ case "map": {
785
+ let map = value;
786
+ for (let [key, val] of map) {
787
+ this.ignoreUnhandledRejectionsImpl(key);
788
+ this.ignoreUnhandledRejectionsImpl(val);
789
+ }
790
+ return;
791
+ }
691
792
  case "object": {
692
793
  let object = value;
693
794
  for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
@@ -747,8 +848,11 @@ function followPath(value, parent, path, owner) {
747
848
  case "bytes":
748
849
  case "blob":
749
850
  case "date":
851
+ case "set":
852
+ case "map":
750
853
  case "error":
751
854
  case "url":
855
+ case "regexp":
752
856
  case "headers":
753
857
  case "request":
754
858
  case "response":
@@ -781,17 +885,23 @@ function followPath(value, parent, path, owner) {
781
885
  }
782
886
  var ValueStubHook = class extends StubHook {
783
887
  call(path, args) {
888
+ let followResult;
784
889
  try {
785
890
  let { value, owner } = this.getValue();
786
- let followResult = followPath(value, void 0, path, owner);
787
- if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
788
- if (typeof followResult.value != "function") throw new TypeError(`'${path.join(".")}' is not a function.`);
789
- return new PromiseStubHook(args.deliverCall(followResult.value, followResult.parent).then((payload) => {
790
- return new PayloadStubHook(payload);
791
- }));
891
+ followResult = followPath(value, void 0, path, owner);
792
892
  } catch (err) {
893
+ args.dispose();
793
894
  return new ErrorStubHook(err);
794
895
  }
896
+ if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
897
+ if (typeof followResult.value != "function") {
898
+ args.dispose();
899
+ return new ErrorStubHook(/* @__PURE__ */ new TypeError(`'${path.join(".")}' is not a function.`));
900
+ }
901
+ let promise = args.deliverCall(followResult.value, followResult.parent);
902
+ return new PromiseStubHook(promise.then((payload) => {
903
+ return new PayloadStubHook(payload);
904
+ }));
795
905
  }
796
906
  map(path, captures, instructions) {
797
907
  try {
@@ -812,7 +922,10 @@ var ValueStubHook = class extends StubHook {
812
922
  get(path) {
813
923
  try {
814
924
  let { value, owner } = this.getValue();
815
- if (path.length === 0 && owner === null) throw new Error("Can't dup an RpcTarget stub as a promise.");
925
+ if (path.length === 0 && owner === null) {
926
+ if (value instanceof Object && "then" in value) return this.dup();
927
+ throw new Error("Can't dup an RpcTarget stub as a promise.");
928
+ }
816
929
  let followResult = followPath(value, void 0, path, owner);
817
930
  if (followResult.hook) return followResult.hook.get(followResult.remainingPath);
818
931
  return new PayloadStubHook(RpcPayload.deepCopyFrom(followResult.value, followResult.parent, followResult.owner));
@@ -915,7 +1028,10 @@ var TargetStubHook = class TargetStubHook extends ValueStubHook {
915
1028
  this.target = void 0;
916
1029
  }
917
1030
  }
918
- onBroken(callback) {}
1031
+ onBroken(callback) {
1032
+ let target = this.target;
1033
+ if (target && "then" in target) Promise.resolve(target).then(() => {}, callback);
1034
+ }
919
1035
  };
920
1036
  var PromiseStubHook = class PromiseStubHook extends StubHook {
921
1037
  promise;
@@ -929,12 +1045,16 @@ var PromiseStubHook = class PromiseStubHook extends StubHook {
929
1045
  }
930
1046
  call(path, args) {
931
1047
  args.ensureDeepCopied();
932
- return new PromiseStubHook(this.promise.then((hook) => hook.call(path, args)));
1048
+ return new PromiseStubHook(this.promise.then((hook) => hook.call(path, args), (err) => {
1049
+ args.dispose();
1050
+ throw err;
1051
+ }));
933
1052
  }
934
1053
  stream(path, args) {
935
1054
  args.ensureDeepCopied();
936
- return { promise: this.promise.then((hook) => {
937
- return hook.stream(path, args).promise;
1055
+ return { promise: this.promise.then((hook) => hook.stream(path, args).promise, (err) => {
1056
+ args.dispose();
1057
+ throw err;
938
1058
  }) };
939
1059
  }
940
1060
  map(path, captures, instructions) {
@@ -961,10 +1081,7 @@ var PromiseStubHook = class PromiseStubHook extends StubHook {
961
1081
  }, (err) => {});
962
1082
  }
963
1083
  dispose() {
964
- if (this.resolution) this.resolution.dispose();
965
- else this.promise.then((hook) => {
966
- hook.dispose();
967
- }, (err) => {});
1084
+ this.promise.then((hook) => hook.dispose(), () => {});
968
1085
  }
969
1086
  onBroken(callback) {
970
1087
  if (this.resolution) this.resolution.onBroken(callback);
@@ -980,7 +1097,7 @@ const DEFAULT_MAX_DEPTH = 256;
980
1097
  const DEFAULT_LIMITS = {
981
1098
  maxBigIntDigits: 16384,
982
1099
  maxDepth: 256,
983
- maxMessageSize: 32 * 1024 * 1024
1100
+ maxMessageSize: 33554432
984
1101
  };
985
1102
  const NATIVE_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
986
1103
  const BYTE_CONTAINER_TYPE_NAMES = [
@@ -1042,9 +1159,7 @@ function swapByteOrder(bytes, elementSize) {
1042
1159
  case 4:
1043
1160
  view.setUint32(offset, view.getUint32(offset, false), true);
1044
1161
  break;
1045
- case 8:
1046
- view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1047
- break;
1162
+ case 8: view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1048
1163
  }
1049
1164
  }
1050
1165
  var NullExporter = class {
@@ -1129,6 +1244,30 @@ var Devaluator = class Devaluator {
1129
1244
  for (let i = 0; i < len; i++) result[i] = this.devaluateImpl(array[i], array, depth + 1);
1130
1245
  return [result];
1131
1246
  }
1247
+ case "set": {
1248
+ let set = value;
1249
+ let setElements = [...set];
1250
+ let elements = [];
1251
+ for (let element of setElements) switch (typeForRpc(element)) {
1252
+ case "blob": throw new TypeError("Cannot serialize a Blob as an element of a Set.");
1253
+ case "rpc-promise":
1254
+ 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.");
1255
+ }
1256
+ for (let element of setElements) elements.push(this.devaluateImpl(element, set, depth + 1));
1257
+ return ["set", elements];
1258
+ }
1259
+ case "map": {
1260
+ let map = value;
1261
+ let mapEntries = [...map];
1262
+ let entries = [];
1263
+ for (let [key] of mapEntries) switch (typeForRpc(key)) {
1264
+ case "blob": throw new TypeError("Cannot serialize a Blob as a key of a Map.");
1265
+ case "rpc-promise":
1266
+ 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.");
1267
+ }
1268
+ for (let [key, val] of mapEntries) entries.push([this.devaluateImpl(key, map, depth + 1), this.devaluateImpl(val, map, depth + 1)]);
1269
+ return ["map", entries];
1270
+ }
1132
1271
  case "bigint":
1133
1272
  if (this.encodingLevel === "structuredClonable") return value;
1134
1273
  return ["bigint", value.toString()];
@@ -1137,6 +1276,15 @@ var Devaluator = class Devaluator {
1137
1276
  const time = value.getTime();
1138
1277
  return ["date", Number.isNaN(time) ? null : time];
1139
1278
  }
1279
+ case "regexp": {
1280
+ if (this.encodingLevel === "structuredClonable") return value;
1281
+ let re = value;
1282
+ return re.flags ? [
1283
+ "regexp",
1284
+ re.source,
1285
+ re.flags
1286
+ ] : ["regexp", re.source];
1287
+ }
1140
1288
  case "bytes": {
1141
1289
  let alternateTypeName = BYTE_CONTAINER_TYPE_BY_PROTOTYPE.get(Object.getPrototypeOf(value));
1142
1290
  let bytes;
@@ -1151,11 +1299,14 @@ var Devaluator = class Devaluator {
1151
1299
  swapByteOrder(bytes, elementSize);
1152
1300
  }
1153
1301
  }
1154
- if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return alternateTypeName === void 0 ? ["bytes", bytes] : [
1155
- "bytes",
1156
- bytes,
1157
- alternateTypeName
1158
- ];
1302
+ if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") {
1303
+ if (bytes.byteLength !== bytes.buffer.byteLength) bytes = new Uint8Array(bytes);
1304
+ return alternateTypeName === void 0 ? ["bytes", bytes] : [
1305
+ "bytes",
1306
+ bytes,
1307
+ alternateTypeName
1308
+ ];
1309
+ }
1159
1310
  let b64;
1160
1311
  if (bytes.toBase64) b64 = bytes.toBase64({ omitPadding: true });
1161
1312
  else if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
@@ -1294,13 +1445,16 @@ var Devaluator = class Devaluator {
1294
1445
  if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
1295
1446
  let { hook, pathIfPromise } = unwrapStubAndPath(value);
1296
1447
  let importId = this.exporter.getImport(hook);
1297
- if (importId !== void 0) if (pathIfPromise) if (pathIfPromise.length > 0) return [
1298
- "pipeline",
1299
- importId,
1300
- pathIfPromise
1301
- ];
1302
- else return ["pipeline", importId];
1303
- else return ["import", importId];
1448
+ if (importId !== void 0) {
1449
+ if (pathIfPromise) {
1450
+ if (pathIfPromise.length > 0) return [
1451
+ "pipeline",
1452
+ importId,
1453
+ pathIfPromise
1454
+ ];
1455
+ else return ["pipeline", importId];
1456
+ } else return ["import", importId];
1457
+ }
1304
1458
  if (pathIfPromise) hook = hook.get(pathIfPromise);
1305
1459
  else hook = hook.dup();
1306
1460
  return this.devaluateHook(pathIfPromise ? "promise" : "export", hook);
@@ -1361,16 +1515,18 @@ var NullImporter = class {
1361
1515
  };
1362
1516
  const NULL_IMPORTER = new NullImporter();
1363
1517
  function fixBrokenRequestBody(request, body) {
1364
- return new RpcPromise$1(new PromiseStubHook(new Response(body).arrayBuffer().then((arrayBuffer) => {
1518
+ let promise = new Response(body).arrayBuffer().then((arrayBuffer) => {
1365
1519
  let bytes = new Uint8Array(arrayBuffer);
1366
1520
  let result = new Request(request, { body: bytes });
1367
1521
  return new PayloadStubHook(RpcPayload.fromAppReturn(result));
1368
- })), []);
1522
+ });
1523
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1369
1524
  }
1370
1525
  function streamToBlobPromise(stream, type) {
1371
- return new RpcPromise$1(new PromiseStubHook(streamToBlob(stream, type).then((blob) => {
1526
+ let promise = streamToBlob(stream, type).then((blob) => {
1372
1527
  return new PayloadStubHook(RpcPayload.fromAppReturn(blob));
1373
- })), []);
1528
+ });
1529
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1374
1530
  }
1375
1531
  var Evaluator = class Evaluator {
1376
1532
  importer;
@@ -1403,7 +1559,7 @@ var Evaluator = class Evaluator {
1403
1559
  let maxDepth = this.limits.maxDepth;
1404
1560
  if (depth >= maxDepth) throw new TypeError(`Deserialization exceeded maximum allowed message depth of ${maxDepth}.`);
1405
1561
  if (this.encodingLevel === "structuredClonable") {
1406
- if (value instanceof Date || typeof value === "bigint") return value;
1562
+ if (value instanceof Date || value instanceof RegExp || typeof value === "bigint") return value;
1407
1563
  }
1408
1564
  if (value instanceof Array) {
1409
1565
  if (value.length == 1 && value[0] instanceof Array) {
@@ -1423,18 +1579,48 @@ var Evaluator = class Evaluator {
1423
1579
  if (value[1] === null) return /* @__PURE__ */ new Date(NaN);
1424
1580
  if (typeof value[1] == "number") return new Date(value[1]);
1425
1581
  break;
1582
+ case "regexp":
1583
+ if (typeof value[1] === "string" && (value.length === 2 || value.length === 3 && typeof value[2] === "string")) return new RegExp(value[1], value[2]);
1584
+ break;
1585
+ case "set":
1586
+ if (value.length === 2 && value[1] instanceof Array) {
1587
+ let elements = value[1];
1588
+ let set = /* @__PURE__ */ new Set();
1589
+ for (let i = 0; i < elements.length; i++) {
1590
+ let copy = this.evaluateImpl(elements[i], set, i, depth + 1);
1591
+ if (copy instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as an element of a Set.");
1592
+ set.add(copy);
1593
+ }
1594
+ return set;
1595
+ }
1596
+ break;
1597
+ case "map":
1598
+ if (value.length === 2 && value[1] instanceof Array) {
1599
+ let entries = value[1];
1600
+ let map = /* @__PURE__ */ new Map();
1601
+ for (let i = 0; i < entries.length; i++) {
1602
+ let entry = entries[i];
1603
+ if (!(entry instanceof Array) || entry.length !== 2) throw new TypeError("Map entries must be serialized as key/value pairs.");
1604
+ let key = this.evaluateImpl(entry[0], map, i, depth + 1);
1605
+ if (key instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as a key of a Map.");
1606
+ map.set(key, this.evaluateImpl(entry[1], map, mapKeyToPropertyName(key), depth + 1));
1607
+ }
1608
+ return map;
1609
+ }
1610
+ break;
1426
1611
  case "bytes": {
1427
1612
  let bytes;
1428
1613
  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]);
1431
- else {
1432
- let bs = atob(value[1]);
1433
- let len = bs.length;
1434
- bytes = new Uint8Array(len);
1435
- for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1436
- }
1437
- else break;
1614
+ else if (typeof value[1] == "string") {
1615
+ if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1616
+ else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1617
+ else {
1618
+ let bs = atob(value[1]);
1619
+ let len = bs.length;
1620
+ bytes = new Uint8Array(len);
1621
+ for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1622
+ }
1623
+ } else break;
1438
1624
  if (value.length === 2) return bytes;
1439
1625
  if (typeof value[2] !== "string") throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`);
1440
1626
  if (!isValidByteContainerName(value[2])) {
@@ -1460,7 +1646,6 @@ var Evaluator = class Evaluator {
1460
1646
  case "BigUint64Array": return new BigUint64Array(buffer);
1461
1647
  case "Float32Array": return new Float32Array(buffer);
1462
1648
  case "Float64Array": return new Float64Array(buffer);
1463
- default:
1464
1649
  }
1465
1650
  }
1466
1651
  case "error":
@@ -1563,11 +1748,13 @@ var Evaluator = class Evaluator {
1563
1748
  return promise;
1564
1749
  } else {
1565
1750
  this.hooks.push(hook);
1566
- return new RpcPromise$1(hook, []);
1751
+ return new RpcStub$1(hook);
1567
1752
  }
1568
1753
  };
1569
- if (value.length == 2) if (isPromise) return addStub(hook.get([]));
1570
- else return addStub(hook.dup());
1754
+ if (value.length == 2) {
1755
+ if (isPromise) return addStub(hook.get([]));
1756
+ else return addStub(hook.dup());
1757
+ }
1571
1758
  let path = value[2];
1572
1759
  if (!(path instanceof Array)) break;
1573
1760
  if (!path.every((part) => {
@@ -1597,7 +1784,8 @@ var Evaluator = class Evaluator {
1597
1784
  }
1598
1785
  });
1599
1786
  let instructions = value[4];
1600
- let promise = new RpcPromise$1(hook.map(path, captures, instructions), []);
1787
+ let resultHook = hook.map(path, captures, instructions);
1788
+ let promise = new RpcPromise$1(resultHook, []);
1601
1789
  this.promises.push({
1602
1790
  promise,
1603
1791
  parent,
@@ -1607,18 +1795,21 @@ var Evaluator = class Evaluator {
1607
1795
  }
1608
1796
  case "export":
1609
1797
  case "promise":
1610
- if (typeof value[1] == "number") if (value[0] == "promise") {
1611
- let promise = new RpcPromise$1(this.importer.importPromise(value[1]), []);
1612
- this.promises.push({
1613
- parent,
1614
- property,
1615
- promise
1616
- });
1617
- return promise;
1618
- } else {
1619
- let hook = this.importer.importStub(value[1]);
1620
- this.hooks.push(hook);
1621
- return new RpcStub$1(hook);
1798
+ if (typeof value[1] == "number") {
1799
+ if (value[0] == "promise") {
1800
+ let hook = this.importer.importPromise(value[1]);
1801
+ let promise = new RpcPromise$1(hook, []);
1802
+ this.promises.push({
1803
+ parent,
1804
+ property,
1805
+ promise
1806
+ });
1807
+ return promise;
1808
+ } else {
1809
+ let hook = this.importer.importStub(value[1]);
1810
+ this.hooks.push(hook);
1811
+ return new RpcStub$1(hook);
1812
+ }
1622
1813
  }
1623
1814
  break;
1624
1815
  case "writable":
@@ -1629,14 +1820,12 @@ var Evaluator = class Evaluator {
1629
1820
  return stream;
1630
1821
  }
1631
1822
  break;
1632
- case "readable":
1633
- if (typeof value[1] == "number") {
1634
- let stream = this.importer.getPipeReadable(value[1]);
1635
- let hook = streamImpl.createReadableStreamHook(stream);
1636
- this.hooks.push(hook);
1637
- return stream;
1638
- }
1639
- break;
1823
+ case "readable": if (typeof value[1] == "number") {
1824
+ let stream = this.importer.getPipeReadable(value[1]);
1825
+ let hook = streamImpl.createReadableStreamHook(stream);
1826
+ this.hooks.push(hook);
1827
+ return stream;
1828
+ }
1640
1829
  }
1641
1830
  throw new TypeError(`unknown special value: ${JSON.stringify(value)}`);
1642
1831
  } else if (value instanceof Object) {
@@ -1681,6 +1870,7 @@ function estimateEncodedSize(value, seen, depth = 0) {
1681
1870
  if (value instanceof ArrayBuffer) return ESTIMATED_BINARY_OVERHEAD + value.byteLength;
1682
1871
  if (typeof Blob !== "undefined" && value instanceof Blob) return ESTIMATED_BINARY_OVERHEAD + value.size;
1683
1872
  if (value instanceof Date) return 16;
1873
+ if (value instanceof RegExp) return ESTIMATED_OBJECT_OVERHEAD + estimateStringSize(value.source) + estimateStringSize(value.flags);
1684
1874
  seen ??= /* @__PURE__ */ new WeakSet();
1685
1875
  if (seen.has(value)) return ESTIMATED_ENTRY_OVERHEAD;
1686
1876
  seen.add(value);
@@ -1704,10 +1894,11 @@ function estimateEncodedSize(value, seen, depth = 0) {
1704
1894
  var ImportTableEntry = class {
1705
1895
  session;
1706
1896
  importId;
1897
+ pulling;
1707
1898
  constructor(session, importId, pulling) {
1708
1899
  this.session = session;
1709
1900
  this.importId = importId;
1710
- if (pulling) this.activePull = Promise.withResolvers();
1901
+ this.pulling = pulling;
1711
1902
  }
1712
1903
  localRefcount = 0;
1713
1904
  remoteRefcount = 1;
@@ -1738,7 +1929,7 @@ var ImportTableEntry = class {
1738
1929
  }
1739
1930
  async awaitResolution() {
1740
1931
  if (!this.activePull) {
1741
- this.session.sendPull(this.importId);
1932
+ if (!this.pulling) this.session.sendPull(this.importId);
1742
1933
  this.activePull = Promise.withResolvers();
1743
1934
  }
1744
1935
  await this.activePull.promise;
@@ -1793,24 +1984,28 @@ var RpcImportHook = class RpcImportHook extends StubHook {
1793
1984
  if (this.entry) return this.entry;
1794
1985
  else throw new Error("This RpcImportHook was already disposed.");
1795
1986
  }
1987
+ getEntryTakingOwnership(disposeOwned) {
1988
+ try {
1989
+ return this.getEntry();
1990
+ } catch (err) {
1991
+ disposeOwned();
1992
+ throw err;
1993
+ }
1994
+ }
1796
1995
  call(path, args) {
1797
- let entry = this.getEntry();
1996
+ let entry = this.getEntryTakingOwnership(() => args.dispose());
1798
1997
  if (entry.resolution) return entry.resolution.call(path, args);
1799
1998
  else return entry.session.sendCall(entry.importId, path, args);
1800
1999
  }
1801
2000
  stream(path, args) {
1802
- let entry = this.getEntry();
2001
+ let entry = this.getEntryTakingOwnership(() => args.dispose());
1803
2002
  if (entry.resolution) return entry.resolution.stream(path, args);
1804
2003
  else return entry.session.sendStream(entry.importId, path, args);
1805
2004
  }
1806
2005
  map(path, captures, instructions) {
1807
- let entry;
1808
- try {
1809
- entry = this.getEntry();
1810
- } catch (err) {
2006
+ let entry = this.getEntryTakingOwnership(() => {
1811
2007
  for (let cap of captures) cap.dispose();
1812
- throw err;
1813
- }
2008
+ });
1814
2009
  if (entry.resolution) return entry.resolution.map(path, captures, instructions);
1815
2010
  else return entry.session.sendMap(entry.importId, path, captures, instructions);
1816
2011
  }
@@ -1964,6 +2159,7 @@ var RpcSessionImpl = class {
1964
2159
  let autoRelease = exp.autoRelease;
1965
2160
  ++this.pullCount;
1966
2161
  exp.pull = resolve().then((payload) => {
2162
+ if (this.exports[exportId] !== exp) return;
1967
2163
  let value = Devaluator.devaluate(payload.value, void 0, this, payload, this.encodingLevel);
1968
2164
  this.send([
1969
2165
  "resolve",
@@ -1972,6 +2168,7 @@ var RpcSessionImpl = class {
1972
2168
  ]);
1973
2169
  if (autoRelease) this.releaseExport(exportId, 1);
1974
2170
  }, (error) => {
2171
+ if (this.exports[exportId] !== exp) return;
1975
2172
  this.send([
1976
2173
  "reject",
1977
2174
  exportId,
@@ -1997,7 +2194,7 @@ var RpcSessionImpl = class {
1997
2194
  }
1998
2195
  }
1999
2196
  getImport(hook) {
2000
- if (hook instanceof RpcImportHook && hook.entry && hook.entry.session === this) return hook.entry.importId;
2197
+ if (hook instanceof RpcImportHook && hook.entry && hook.entry.session === this && !hook.entry.resolution) return hook.entry.importId;
2001
2198
  else return;
2002
2199
  }
2003
2200
  importStub(idx) {
@@ -2071,32 +2268,52 @@ var RpcSessionImpl = class {
2071
2268
  }
2072
2269
  }
2073
2270
  sendCall(id, path, args) {
2074
- if (this.abortReason) throw this.abortReason;
2271
+ if (this.abortReason) {
2272
+ args?.dispose();
2273
+ throw this.abortReason;
2274
+ }
2075
2275
  let value = [
2076
2276
  "pipeline",
2077
2277
  id,
2078
2278
  path
2079
2279
  ];
2080
2280
  if (args) {
2081
- let devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2281
+ let devalue;
2282
+ try {
2283
+ devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2284
+ } catch (err) {
2285
+ args.dispose();
2286
+ throw err;
2287
+ }
2082
2288
  value.push(devalue[0]);
2083
2289
  }
2084
2290
  this.send(["push", value]);
2291
+ args?.dispose();
2085
2292
  let entry = new ImportTableEntry(this, this.imports.length, false);
2086
2293
  this.imports.push(entry);
2087
2294
  return new RpcImportHook(true, entry);
2088
2295
  }
2089
2296
  sendStream(id, path, args) {
2090
- if (this.abortReason) throw this.abortReason;
2297
+ if (this.abortReason) {
2298
+ args.dispose();
2299
+ throw this.abortReason;
2300
+ }
2091
2301
  let value = [
2092
2302
  "pipeline",
2093
2303
  id,
2094
2304
  path
2095
2305
  ];
2096
- let devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2306
+ let devalue;
2307
+ try {
2308
+ devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2309
+ } catch (err) {
2310
+ args.dispose();
2311
+ throw err;
2312
+ }
2097
2313
  value.push(devalue[0]);
2098
2314
  let msg = ["stream", value];
2099
2315
  let size = this.send(msg);
2316
+ args.dispose();
2100
2317
  if (size === void 0) size = estimateEncodedSize(msg);
2101
2318
  let importId = this.imports.length;
2102
2319
  let entry = new ImportTableEntry(this, importId, true);
@@ -2194,7 +2411,8 @@ var RpcSessionImpl = class {
2194
2411
  if (msg instanceof Array) switch (msg[0]) {
2195
2412
  case "push":
2196
2413
  if (msg.length > 1) {
2197
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2414
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2415
+ let hook = new PayloadStubHook(payload);
2198
2416
  hook.ignoreUnhandledRejections();
2199
2417
  this.exports.push({
2200
2418
  hook,
@@ -2205,7 +2423,8 @@ var RpcSessionImpl = class {
2205
2423
  break;
2206
2424
  case "stream":
2207
2425
  if (msg.length > 1) {
2208
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2426
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2427
+ let hook = new PayloadStubHook(payload);
2209
2428
  hook.ignoreUnhandledRejections();
2210
2429
  let exportId = this.exports.length;
2211
2430
  this.exports.push({
@@ -2240,13 +2459,14 @@ var RpcSessionImpl = class {
2240
2459
  let importId = msg[1];
2241
2460
  if (typeof importId == "number" && msg.length > 2) {
2242
2461
  let imp = this.imports[importId];
2243
- if (imp) if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2244
- else {
2245
- let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2246
- payload.dispose();
2247
- imp.resolve(new ErrorStubHook(payload.value));
2248
- }
2249
- else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2462
+ if (imp) {
2463
+ if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2464
+ else {
2465
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2466
+ payload.dispose();
2467
+ imp.resolve(new ErrorStubHook(payload.value));
2468
+ }
2469
+ } else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2250
2470
  continue;
2251
2471
  }
2252
2472
  break;
@@ -2318,7 +2538,8 @@ var RpcSession$1 = class {
2318
2538
  const MAX_CLOSE_REASON_BYTES = 123;
2319
2539
  function newWebSocketRpcSession$1(webSocket, localMain, options) {
2320
2540
  if (typeof webSocket === "string") webSocket = new WebSocket(webSocket);
2321
- return new RpcSession$1(new WebSocketTransport(webSocket), localMain, options).getRemoteMain();
2541
+ let transport = new WebSocketTransport(webSocket);
2542
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2322
2543
  }
2323
2544
  /**
2324
2545
  * For use in Cloudflare Workers: Construct an HTTP response that starts a WebSocket RPC session
@@ -2355,12 +2576,13 @@ var WebSocketTransport = class {
2355
2576
  });
2356
2577
  }
2357
2578
  webSocket.addEventListener("message", (event) => {
2358
- if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) if (this.#receiveResolver) {
2359
- this.#receiveResolver(event.data);
2360
- this.#receiveResolver = void 0;
2361
- this.#receiveRejecter = void 0;
2362
- } else this.#receiveQueue.push(event.data);
2363
- else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2579
+ if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) {
2580
+ if (this.#receiveResolver) {
2581
+ this.#receiveResolver(event.data);
2582
+ this.#receiveResolver = void 0;
2583
+ this.#receiveRejecter = void 0;
2584
+ } else this.#receiveQueue.push(event.data);
2585
+ } else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2364
2586
  });
2365
2587
  webSocket.addEventListener("close", (event) => {
2366
2588
  this.#receivedError(/* @__PURE__ */ new Error(`Peer closed WebSocket: ${event.code} ${event.reason}`));
@@ -2452,7 +2674,8 @@ function newHttpBatchRpcSession$1(urlOrRequest, options) {
2452
2674
  let body = await response.text();
2453
2675
  return body == "" ? [] : body.split("\n");
2454
2676
  };
2455
- return new RpcSession$1(new BatchClientTransport(sendBatch), void 0, options).getRemoteMain();
2677
+ let transport = new BatchClientTransport(sendBatch);
2678
+ return new RpcSession$1(transport, void 0, options).getRemoteMain();
2456
2679
  }
2457
2680
  var BatchServerTransport = class {
2458
2681
  constructor(batch) {
@@ -2495,7 +2718,8 @@ var BatchServerTransport = class {
2495
2718
  async function newHttpBatchRpcResponse(request, localMain, options) {
2496
2719
  if (request.method !== "POST") return new Response("This endpoint only accepts POST requests.", { status: 405 });
2497
2720
  let body = await request.text();
2498
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2721
+ let batch = body === "" ? [] : body.split("\n");
2722
+ let transport = new BatchServerTransport(batch);
2499
2723
  let rpc = new RpcSession$1(transport, localMain, options);
2500
2724
  await transport.whenAllReceived();
2501
2725
  await rpc.drain();
@@ -2525,7 +2749,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2525
2749
  });
2526
2750
  request.on("error", reject);
2527
2751
  });
2528
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2752
+ let batch = body === "" ? [] : body.split("\n");
2753
+ let transport = new BatchServerTransport(batch);
2529
2754
  let rpc = new RpcSession$1(transport, localMain, options);
2530
2755
  await transport.whenAllReceived();
2531
2756
  await rpc.drain();
@@ -2536,7 +2761,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2536
2761
  //#endregion
2537
2762
  //#region src/messageport.ts
2538
2763
  function newMessagePortRpcSession$1(port, localMain, options) {
2539
- return new RpcSession$1(new MessagePortTransport(port), localMain, options).getRemoteMain();
2764
+ let transport = new MessagePortTransport(port);
2765
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2540
2766
  }
2541
2767
  var MessagePortTransport = class {
2542
2768
  encodingLevel = "structuredClonable";
@@ -2724,9 +2950,11 @@ var MapVariableHook = class extends StubHook {
2724
2950
  else throwMapperBuilderUseError();
2725
2951
  }
2726
2952
  call(path, args) {
2953
+ args.dispose();
2727
2954
  throwMapperBuilderUseError();
2728
2955
  }
2729
2956
  map(path, captures, instructions) {
2957
+ for (let cap of captures) cap.dispose();
2730
2958
  throwMapperBuilderUseError();
2731
2959
  }
2732
2960
  pull() {
@@ -2784,7 +3012,8 @@ var MapApplicator = class {
2784
3012
  }
2785
3013
  };
2786
3014
  function applyMapToElement(input, parent, owner, captures, instructions) {
2787
- let mapper = new MapApplicator(captures, new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner)));
3015
+ let inputHook = new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner));
3016
+ let mapper = new MapApplicator(captures, inputHook);
2788
3017
  try {
2789
3018
  return mapper.apply(instructions);
2790
3019
  } finally {
@@ -2817,9 +3046,10 @@ mapImpl.applyMap = (input, parent, owner, captures, instructions) => {
2817
3046
  var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2818
3047
  state;
2819
3048
  static create(stream) {
3049
+ let writer = stream.getWriter();
2820
3050
  return new WritableStreamStubHook({
2821
3051
  refcount: 1,
2822
- writer: stream.getWriter(),
3052
+ writer,
2823
3053
  closed: false
2824
3054
  });
2825
3055
  }
@@ -2837,13 +3067,12 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2837
3067
  let state = this.getState();
2838
3068
  if (path.length !== 1 || typeof path[0] !== "string") throw new Error("WritableStream stub only supports direct method calls");
2839
3069
  const method = path[0];
2840
- if (method !== "write" && method !== "close" && method !== "abort") {
2841
- args.dispose();
2842
- throw new Error(`Unknown WritableStream method: ${method}`);
2843
- }
3070
+ if (method !== "write" && method !== "close" && method !== "abort") throw new Error(`Unknown WritableStream method: ${method}`);
2844
3071
  if (method === "close" || method === "abort") state.closed = true;
2845
- return new PromiseStubHook((method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer)).then((payload) => new PayloadStubHook(payload)));
3072
+ let promise = method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer);
3073
+ return new PromiseStubHook(promise.then((payload) => new PayloadStubHook(payload)));
2846
3074
  } catch (err) {
3075
+ args.dispose();
2847
3076
  return new ErrorStubHook(err);
2848
3077
  }
2849
3078
  }
@@ -2855,7 +3084,8 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2855
3084
  return new ErrorStubHook(/* @__PURE__ */ new Error("Cannot access properties on a WritableStream stub"));
2856
3085
  }
2857
3086
  dup() {
2858
- return new WritableStreamStubHook(this.getState(), this);
3087
+ let state = this.getState();
3088
+ return new WritableStreamStubHook(state, this);
2859
3089
  }
2860
3090
  pull() {
2861
3091
  return Promise.reject(/* @__PURE__ */ new Error("Cannot pull a WritableStream stub"));
@@ -2873,9 +3103,9 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2873
3103
  }
2874
3104
  onBroken(callback) {}
2875
3105
  };
2876
- const INITIAL_WINDOW = 256 * 1024;
2877
- const MAX_WINDOW = 1024 * 1024 * 1024;
2878
- const MIN_WINDOW = 64 * 1024;
3106
+ const INITIAL_WINDOW = 262144;
3107
+ const MAX_WINDOW = 1073741824;
3108
+ const MIN_WINDOW = 65536;
2879
3109
  const STARTUP_GROWTH_FACTOR = 2;
2880
3110
  const STEADY_GROWTH_FACTOR = 1.25;
2881
3111
  const DECAY_FACTOR = .9;