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.
package/dist/index-bun.js CHANGED
@@ -40,6 +40,9 @@ function typeForRpc(value) {
40
40
  case AsyncFunction.prototype: return "function";
41
41
  case Array.prototype: return "array";
42
42
  case Date.prototype: return "date";
43
+ case RegExp.prototype: return "regexp";
44
+ case Set.prototype: return "set";
45
+ case Map.prototype: return "map";
43
46
  case Uint8Array.prototype:
44
47
  case BUFFER_PROTOTYPE:
45
48
  case ArrayBuffer.prototype:
@@ -90,7 +93,14 @@ let streamImpl = {
90
93
  };
91
94
  var StubHook = class {
92
95
  stream(path, args) {
93
- let pulled = this.call(path, args).pull();
96
+ let hook = this.call(path, args);
97
+ let pulled;
98
+ try {
99
+ pulled = hook.pull();
100
+ } catch (err) {
101
+ hook.dispose();
102
+ throw err;
103
+ }
94
104
  let promise;
95
105
  if (pulled instanceof Promise) promise = pulled.then((p) => {
96
106
  p.dispose();
@@ -109,9 +119,11 @@ var ErrorStubHook = class extends StubHook {
109
119
  this.error = error;
110
120
  }
111
121
  call(path, args) {
122
+ args.dispose();
112
123
  return this;
113
124
  }
114
125
  map(path, captures, instructions) {
126
+ for (let cap of captures) cap.dispose();
115
127
  return this;
116
128
  }
117
129
  get(path) {
@@ -235,7 +247,25 @@ var RpcStub$1 = class RpcStub$1 extends RpcTarget$1 {
235
247
  };
236
248
  var RpcPromise$1 = class extends RpcStub$1 {
237
249
  constructor(hook, pathIfPromise) {
238
- super(hook, pathIfPromise);
250
+ if (hook instanceof StubHook) super(hook, pathIfPromise ?? []);
251
+ else {
252
+ if (pathIfPromise !== void 0) throw new TypeError("RpcPromise constructor expected one argument, received two.");
253
+ let kind = typeForRpc(hook);
254
+ if (kind === "rpc-promise") {
255
+ let raw = unwrapStubAndPath(hook);
256
+ if (raw.pathIfPromise.length > 0) super(raw.hook, raw.pathIfPromise);
257
+ else {
258
+ let adopted = raw.hook;
259
+ raw.hook = DISPOSED_HOOK;
260
+ super(adopted, []);
261
+ }
262
+ } else if (kind === "rpc-thenable") super(TargetStubHook.create(hook, void 0), []);
263
+ else {
264
+ let promiseHook = new PromiseStubHook(Promise.resolve(hook).then((value) => new PayloadStubHook(RpcPayload.fromAppReturn(value))));
265
+ promiseHook.ignoreUnhandledRejections();
266
+ super(promiseHook, []);
267
+ }
268
+ }
239
269
  }
240
270
  then(onfulfilled, onrejected) {
241
271
  return pullPromise(this).then(...arguments);
@@ -276,6 +306,9 @@ async function pullPromise(promise) {
276
306
  if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
277
307
  return (await hook.pull()).deliverResolve();
278
308
  }
309
+ function mapKeyToPropertyName(key) {
310
+ return typeof key === "string" || typeof key === "number" ? key : { mapKey: key };
311
+ }
279
312
  var RpcPayload = class RpcPayload {
280
313
  value;
281
314
  source;
@@ -330,12 +363,13 @@ var RpcPayload = class RpcPayload {
330
363
  return TargetStubHook.create(target, parent);
331
364
  } else if (this.source === "return") {
332
365
  let hook = this.rpcTargets?.get(target);
333
- if (hook) if (dupStubs) return hook.dup();
334
- else {
335
- this.rpcTargets?.delete(target);
336
- return hook;
337
- }
338
- else {
366
+ if (hook) {
367
+ if (dupStubs) return hook.dup();
368
+ else {
369
+ this.rpcTargets?.delete(target);
370
+ return hook;
371
+ }
372
+ } else {
339
373
  hook = TargetStubHook.create(target, parent);
340
374
  if (dupStubs) {
341
375
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -349,12 +383,13 @@ var RpcPayload = class RpcPayload {
349
383
  if (this.source === "params") return streamImpl.createWritableStreamHook(stream);
350
384
  else if (this.source === "return") {
351
385
  let hook = this.rpcTargets?.get(stream);
352
- if (hook) if (dupStubs) return hook.dup();
353
- else {
354
- this.rpcTargets?.delete(stream);
355
- return hook;
356
- }
357
- else {
386
+ if (hook) {
387
+ if (dupStubs) return hook.dup();
388
+ else {
389
+ this.rpcTargets?.delete(stream);
390
+ return hook;
391
+ }
392
+ } else {
358
393
  hook = streamImpl.createWritableStreamHook(stream);
359
394
  if (dupStubs) {
360
395
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -368,12 +403,13 @@ var RpcPayload = class RpcPayload {
368
403
  if (this.source === "params") return streamImpl.createReadableStreamHook(stream);
369
404
  else if (this.source === "return") {
370
405
  let hook = this.rpcTargets?.get(stream);
371
- if (hook) if (dupStubs) return hook.dup();
372
- else {
373
- this.rpcTargets?.delete(stream);
374
- return hook;
375
- }
376
- else {
406
+ if (hook) {
407
+ if (dupStubs) return hook.dup();
408
+ else {
409
+ this.rpcTargets?.delete(stream);
410
+ return hook;
411
+ }
412
+ } else {
377
413
  hook = streamImpl.createReadableStreamHook(stream);
378
414
  if (dupStubs) {
379
415
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -381,7 +417,7 @@ var RpcPayload = class RpcPayload {
381
417
  return hook.dup();
382
418
  } else return hook;
383
419
  }
384
- } else throw new Error("owned payload shouldn't contain raw ReadableStreams");
420
+ } else return streamImpl.createReadableStreamHook(stream);
385
421
  }
386
422
  deepCopy(value, oldParent, property, parent, dupStubs, owner) {
387
423
  switch (typeForRpc(value)) {
@@ -392,6 +428,7 @@ var RpcPayload = class RpcPayload {
392
428
  case "bytes":
393
429
  case "blob":
394
430
  case "url":
431
+ case "regexp":
395
432
  case "error":
396
433
  case "undefined": return value;
397
434
  case "array": {
@@ -401,6 +438,35 @@ var RpcPayload = class RpcPayload {
401
438
  for (let i = 0; i < len; i++) result[i] = this.deepCopy(array[i], array, i, result, dupStubs, owner);
402
439
  return result;
403
440
  }
441
+ case "set": {
442
+ let set = value;
443
+ let elements = [...set];
444
+ for (let val of elements) {
445
+ let kind = typeForRpc(val);
446
+ 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.");
447
+ }
448
+ let result = /* @__PURE__ */ new Set();
449
+ let index = 0;
450
+ for (let val of elements) {
451
+ let copy = this.deepCopy(val, set, index++, result, dupStubs, owner);
452
+ result.add(copy);
453
+ }
454
+ return result;
455
+ }
456
+ case "map": {
457
+ let map = value;
458
+ let entries = [...map];
459
+ for (let [key] of entries) {
460
+ let kind = typeForRpc(key);
461
+ 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.");
462
+ }
463
+ let result = /* @__PURE__ */ new Map();
464
+ for (let [key, val] of entries) {
465
+ let keyCopy = this.deepCopy(key, map, -1, result, dupStubs, owner);
466
+ result.set(keyCopy, this.deepCopy(val, map, mapKeyToPropertyName(keyCopy), result, dupStubs, owner));
467
+ }
468
+ return result;
469
+ }
404
470
  case "object": {
405
471
  let result = {};
406
472
  let object = value;
@@ -458,8 +524,10 @@ var RpcPayload = class RpcPayload {
458
524
  case "readable": {
459
525
  let stream = value;
460
526
  let hook;
461
- if (owner) hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
462
- else hook = streamImpl.createReadableStreamHook(stream);
527
+ if (owner) {
528
+ if (owner.source === "owned") throw new Error("Can't copy a ReadableStream.");
529
+ hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
530
+ } else hook = streamImpl.createReadableStreamHook(stream);
463
531
  this.hooks.push(hook);
464
532
  return stream;
465
533
  }
@@ -485,6 +553,10 @@ var RpcPayload = class RpcPayload {
485
553
  try {
486
554
  this.value = this.deepCopy(this.value, void 0, "value", this, dupStubs, this);
487
555
  } catch (err) {
556
+ if (dupStubs) {
557
+ this.hooks.forEach((hook) => hook.dispose());
558
+ this.promises.forEach((promise) => promise.promise[Symbol.dispose]());
559
+ }
488
560
  this.hooks = void 0;
489
561
  this.promises = void 0;
490
562
  throw err;
@@ -498,7 +570,8 @@ var RpcPayload = class RpcPayload {
498
570
  this.ensureDeepCopied();
499
571
  if (this.value instanceof RpcPromise$1) RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
500
572
  else {
501
- parent[property] = this.value;
573
+ if (parent instanceof Map) parent.set(typeof property === "object" ? property.mapKey : property, this.value);
574
+ else parent[property] = this.value;
502
575
  for (let record of this.promises) RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
503
576
  }
504
577
  }
@@ -590,6 +663,7 @@ var RpcPayload = class RpcPayload {
590
663
  case "blob":
591
664
  case "date":
592
665
  case "url":
666
+ case "regexp":
593
667
  case "error":
594
668
  case "undefined": return;
595
669
  case "array": {
@@ -598,6 +672,19 @@ var RpcPayload = class RpcPayload {
598
672
  for (let i = 0; i < len; i++) this.disposeImpl(array[i], array);
599
673
  return;
600
674
  }
675
+ case "set": {
676
+ let set = value;
677
+ for (let element of set) this.disposeImpl(element, set);
678
+ return;
679
+ }
680
+ case "map": {
681
+ let map = value;
682
+ for (let [key, val] of map) {
683
+ this.disposeImpl(key, map);
684
+ this.disposeImpl(val, map);
685
+ }
686
+ return;
687
+ }
601
688
  case "object": {
602
689
  let object = value;
603
690
  for (let i in object) this.disposeImpl(object[i], object);
@@ -673,6 +760,7 @@ var RpcPayload = class RpcPayload {
673
760
  case "writable":
674
761
  case "readable":
675
762
  case "url":
763
+ case "regexp":
676
764
  case "headers":
677
765
  case "request":
678
766
  case "response": return;
@@ -682,6 +770,19 @@ var RpcPayload = class RpcPayload {
682
770
  for (let i = 0; i < len; i++) this.ignoreUnhandledRejectionsImpl(array[i]);
683
771
  return;
684
772
  }
773
+ case "set": {
774
+ let set = value;
775
+ for (let element of set) this.ignoreUnhandledRejectionsImpl(element);
776
+ return;
777
+ }
778
+ case "map": {
779
+ let map = value;
780
+ for (let [key, val] of map) {
781
+ this.ignoreUnhandledRejectionsImpl(key);
782
+ this.ignoreUnhandledRejectionsImpl(val);
783
+ }
784
+ return;
785
+ }
685
786
  case "object": {
686
787
  let object = value;
687
788
  for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
@@ -741,8 +842,11 @@ function followPath(value, parent, path, owner) {
741
842
  case "bytes":
742
843
  case "blob":
743
844
  case "date":
845
+ case "set":
846
+ case "map":
744
847
  case "error":
745
848
  case "url":
849
+ case "regexp":
746
850
  case "headers":
747
851
  case "request":
748
852
  case "response":
@@ -775,17 +879,23 @@ function followPath(value, parent, path, owner) {
775
879
  }
776
880
  var ValueStubHook = class extends StubHook {
777
881
  call(path, args) {
882
+ let followResult;
778
883
  try {
779
884
  let { value, owner } = this.getValue();
780
- let followResult = followPath(value, void 0, path, owner);
781
- if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
782
- if (typeof followResult.value != "function") throw new TypeError(`'${path.join(".")}' is not a function.`);
783
- return new PromiseStubHook(args.deliverCall(followResult.value, followResult.parent).then((payload) => {
784
- return new PayloadStubHook(payload);
785
- }));
885
+ followResult = followPath(value, void 0, path, owner);
786
886
  } catch (err) {
887
+ args.dispose();
787
888
  return new ErrorStubHook(err);
788
889
  }
890
+ if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
891
+ if (typeof followResult.value != "function") {
892
+ args.dispose();
893
+ return new ErrorStubHook(/* @__PURE__ */ new TypeError(`'${path.join(".")}' is not a function.`));
894
+ }
895
+ let promise = args.deliverCall(followResult.value, followResult.parent);
896
+ return new PromiseStubHook(promise.then((payload) => {
897
+ return new PayloadStubHook(payload);
898
+ }));
789
899
  }
790
900
  map(path, captures, instructions) {
791
901
  try {
@@ -806,7 +916,10 @@ var ValueStubHook = class extends StubHook {
806
916
  get(path) {
807
917
  try {
808
918
  let { value, owner } = this.getValue();
809
- if (path.length === 0 && owner === null) throw new Error("Can't dup an RpcTarget stub as a promise.");
919
+ if (path.length === 0 && owner === null) {
920
+ if (value instanceof Object && "then" in value) return this.dup();
921
+ throw new Error("Can't dup an RpcTarget stub as a promise.");
922
+ }
810
923
  let followResult = followPath(value, void 0, path, owner);
811
924
  if (followResult.hook) return followResult.hook.get(followResult.remainingPath);
812
925
  return new PayloadStubHook(RpcPayload.deepCopyFrom(followResult.value, followResult.parent, followResult.owner));
@@ -909,7 +1022,10 @@ var TargetStubHook = class TargetStubHook extends ValueStubHook {
909
1022
  this.target = void 0;
910
1023
  }
911
1024
  }
912
- onBroken(callback) {}
1025
+ onBroken(callback) {
1026
+ let target = this.target;
1027
+ if (target && "then" in target) Promise.resolve(target).then(() => {}, callback);
1028
+ }
913
1029
  };
914
1030
  var PromiseStubHook = class PromiseStubHook extends StubHook {
915
1031
  promise;
@@ -923,12 +1039,16 @@ var PromiseStubHook = class PromiseStubHook extends StubHook {
923
1039
  }
924
1040
  call(path, args) {
925
1041
  args.ensureDeepCopied();
926
- return new PromiseStubHook(this.promise.then((hook) => hook.call(path, args)));
1042
+ return new PromiseStubHook(this.promise.then((hook) => hook.call(path, args), (err) => {
1043
+ args.dispose();
1044
+ throw err;
1045
+ }));
927
1046
  }
928
1047
  stream(path, args) {
929
1048
  args.ensureDeepCopied();
930
- return { promise: this.promise.then((hook) => {
931
- return hook.stream(path, args).promise;
1049
+ return { promise: this.promise.then((hook) => hook.stream(path, args).promise, (err) => {
1050
+ args.dispose();
1051
+ throw err;
932
1052
  }) };
933
1053
  }
934
1054
  map(path, captures, instructions) {
@@ -955,10 +1075,7 @@ var PromiseStubHook = class PromiseStubHook extends StubHook {
955
1075
  }, (err) => {});
956
1076
  }
957
1077
  dispose() {
958
- if (this.resolution) this.resolution.dispose();
959
- else this.promise.then((hook) => {
960
- hook.dispose();
961
- }, (err) => {});
1078
+ this.promise.then((hook) => hook.dispose(), () => {});
962
1079
  }
963
1080
  onBroken(callback) {
964
1081
  if (this.resolution) this.resolution.onBroken(callback);
@@ -974,7 +1091,7 @@ const DEFAULT_MAX_DEPTH = 256;
974
1091
  const DEFAULT_LIMITS = {
975
1092
  maxBigIntDigits: 16384,
976
1093
  maxDepth: 256,
977
- maxMessageSize: 32 * 1024 * 1024
1094
+ maxMessageSize: 33554432
978
1095
  };
979
1096
  const NATIVE_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
980
1097
  const BYTE_CONTAINER_TYPE_NAMES = [
@@ -1036,9 +1153,7 @@ function swapByteOrder(bytes, elementSize) {
1036
1153
  case 4:
1037
1154
  view.setUint32(offset, view.getUint32(offset, false), true);
1038
1155
  break;
1039
- case 8:
1040
- view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1041
- break;
1156
+ case 8: view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1042
1157
  }
1043
1158
  }
1044
1159
  var NullExporter = class {
@@ -1123,6 +1238,30 @@ var Devaluator = class Devaluator {
1123
1238
  for (let i = 0; i < len; i++) result[i] = this.devaluateImpl(array[i], array, depth + 1);
1124
1239
  return [result];
1125
1240
  }
1241
+ case "set": {
1242
+ let set = value;
1243
+ let setElements = [...set];
1244
+ let elements = [];
1245
+ for (let element of setElements) switch (typeForRpc(element)) {
1246
+ case "blob": throw new TypeError("Cannot serialize a Blob as an element of a Set.");
1247
+ case "rpc-promise":
1248
+ 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.");
1249
+ }
1250
+ for (let element of setElements) elements.push(this.devaluateImpl(element, set, depth + 1));
1251
+ return ["set", elements];
1252
+ }
1253
+ case "map": {
1254
+ let map = value;
1255
+ let mapEntries = [...map];
1256
+ let entries = [];
1257
+ for (let [key] of mapEntries) switch (typeForRpc(key)) {
1258
+ case "blob": throw new TypeError("Cannot serialize a Blob as a key of a Map.");
1259
+ case "rpc-promise":
1260
+ 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.");
1261
+ }
1262
+ for (let [key, val] of mapEntries) entries.push([this.devaluateImpl(key, map, depth + 1), this.devaluateImpl(val, map, depth + 1)]);
1263
+ return ["map", entries];
1264
+ }
1126
1265
  case "bigint":
1127
1266
  if (this.encodingLevel === "structuredClonable") return value;
1128
1267
  return ["bigint", value.toString()];
@@ -1131,6 +1270,15 @@ var Devaluator = class Devaluator {
1131
1270
  const time = value.getTime();
1132
1271
  return ["date", Number.isNaN(time) ? null : time];
1133
1272
  }
1273
+ case "regexp": {
1274
+ if (this.encodingLevel === "structuredClonable") return value;
1275
+ let re = value;
1276
+ return re.flags ? [
1277
+ "regexp",
1278
+ re.source,
1279
+ re.flags
1280
+ ] : ["regexp", re.source];
1281
+ }
1134
1282
  case "bytes": {
1135
1283
  let alternateTypeName = BYTE_CONTAINER_TYPE_BY_PROTOTYPE.get(Object.getPrototypeOf(value));
1136
1284
  let bytes;
@@ -1145,11 +1293,14 @@ var Devaluator = class Devaluator {
1145
1293
  swapByteOrder(bytes, elementSize);
1146
1294
  }
1147
1295
  }
1148
- if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return alternateTypeName === void 0 ? ["bytes", bytes] : [
1149
- "bytes",
1150
- bytes,
1151
- alternateTypeName
1152
- ];
1296
+ if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") {
1297
+ if (bytes.byteLength !== bytes.buffer.byteLength) bytes = new Uint8Array(bytes);
1298
+ return alternateTypeName === void 0 ? ["bytes", bytes] : [
1299
+ "bytes",
1300
+ bytes,
1301
+ alternateTypeName
1302
+ ];
1303
+ }
1153
1304
  let b64;
1154
1305
  if (bytes.toBase64) b64 = bytes.toBase64({ omitPadding: true });
1155
1306
  else if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
@@ -1288,13 +1439,16 @@ var Devaluator = class Devaluator {
1288
1439
  if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
1289
1440
  let { hook, pathIfPromise } = unwrapStubAndPath(value);
1290
1441
  let importId = this.exporter.getImport(hook);
1291
- if (importId !== void 0) if (pathIfPromise) if (pathIfPromise.length > 0) return [
1292
- "pipeline",
1293
- importId,
1294
- pathIfPromise
1295
- ];
1296
- else return ["pipeline", importId];
1297
- else return ["import", importId];
1442
+ if (importId !== void 0) {
1443
+ if (pathIfPromise) {
1444
+ if (pathIfPromise.length > 0) return [
1445
+ "pipeline",
1446
+ importId,
1447
+ pathIfPromise
1448
+ ];
1449
+ else return ["pipeline", importId];
1450
+ } else return ["import", importId];
1451
+ }
1298
1452
  if (pathIfPromise) hook = hook.get(pathIfPromise);
1299
1453
  else hook = hook.dup();
1300
1454
  return this.devaluateHook(pathIfPromise ? "promise" : "export", hook);
@@ -1355,16 +1509,18 @@ var NullImporter = class {
1355
1509
  };
1356
1510
  const NULL_IMPORTER = new NullImporter();
1357
1511
  function fixBrokenRequestBody(request, body) {
1358
- return new RpcPromise$1(new PromiseStubHook(new Response(body).arrayBuffer().then((arrayBuffer) => {
1512
+ let promise = new Response(body).arrayBuffer().then((arrayBuffer) => {
1359
1513
  let bytes = new Uint8Array(arrayBuffer);
1360
1514
  let result = new Request(request, { body: bytes });
1361
1515
  return new PayloadStubHook(RpcPayload.fromAppReturn(result));
1362
- })), []);
1516
+ });
1517
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1363
1518
  }
1364
1519
  function streamToBlobPromise(stream, type) {
1365
- return new RpcPromise$1(new PromiseStubHook(streamToBlob(stream, type).then((blob) => {
1520
+ let promise = streamToBlob(stream, type).then((blob) => {
1366
1521
  return new PayloadStubHook(RpcPayload.fromAppReturn(blob));
1367
- })), []);
1522
+ });
1523
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1368
1524
  }
1369
1525
  var Evaluator = class Evaluator {
1370
1526
  importer;
@@ -1397,7 +1553,7 @@ var Evaluator = class Evaluator {
1397
1553
  let maxDepth = this.limits.maxDepth;
1398
1554
  if (depth >= maxDepth) throw new TypeError(`Deserialization exceeded maximum allowed message depth of ${maxDepth}.`);
1399
1555
  if (this.encodingLevel === "structuredClonable") {
1400
- if (value instanceof Date || typeof value === "bigint") return value;
1556
+ if (value instanceof Date || value instanceof RegExp || typeof value === "bigint") return value;
1401
1557
  }
1402
1558
  if (value instanceof Array) {
1403
1559
  if (value.length == 1 && value[0] instanceof Array) {
@@ -1417,18 +1573,48 @@ var Evaluator = class Evaluator {
1417
1573
  if (value[1] === null) return /* @__PURE__ */ new Date(NaN);
1418
1574
  if (typeof value[1] == "number") return new Date(value[1]);
1419
1575
  break;
1576
+ case "regexp":
1577
+ if (typeof value[1] === "string" && (value.length === 2 || value.length === 3 && typeof value[2] === "string")) return new RegExp(value[1], value[2]);
1578
+ break;
1579
+ case "set":
1580
+ if (value.length === 2 && value[1] instanceof Array) {
1581
+ let elements = value[1];
1582
+ let set = /* @__PURE__ */ new Set();
1583
+ for (let i = 0; i < elements.length; i++) {
1584
+ let copy = this.evaluateImpl(elements[i], set, i, depth + 1);
1585
+ if (copy instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as an element of a Set.");
1586
+ set.add(copy);
1587
+ }
1588
+ return set;
1589
+ }
1590
+ break;
1591
+ case "map":
1592
+ if (value.length === 2 && value[1] instanceof Array) {
1593
+ let entries = value[1];
1594
+ let map = /* @__PURE__ */ new Map();
1595
+ for (let i = 0; i < entries.length; i++) {
1596
+ let entry = entries[i];
1597
+ if (!(entry instanceof Array) || entry.length !== 2) throw new TypeError("Map entries must be serialized as key/value pairs.");
1598
+ let key = this.evaluateImpl(entry[0], map, i, depth + 1);
1599
+ if (key instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as a key of a Map.");
1600
+ map.set(key, this.evaluateImpl(entry[1], map, mapKeyToPropertyName(key), depth + 1));
1601
+ }
1602
+ return map;
1603
+ }
1604
+ break;
1420
1605
  case "bytes": {
1421
1606
  let bytes;
1422
1607
  if (value[1] instanceof Uint8Array) bytes = value[1];
1423
- else if (typeof value[1] == "string") if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1424
- else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1425
- else {
1426
- let bs = atob(value[1]);
1427
- let len = bs.length;
1428
- bytes = new Uint8Array(len);
1429
- for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1430
- }
1431
- else break;
1608
+ else if (typeof value[1] == "string") {
1609
+ if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1610
+ else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1611
+ else {
1612
+ let bs = atob(value[1]);
1613
+ let len = bs.length;
1614
+ bytes = new Uint8Array(len);
1615
+ for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1616
+ }
1617
+ } else break;
1432
1618
  if (value.length === 2) return bytes;
1433
1619
  if (typeof value[2] !== "string") throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`);
1434
1620
  if (!isValidByteContainerName(value[2])) {
@@ -1454,7 +1640,6 @@ var Evaluator = class Evaluator {
1454
1640
  case "BigUint64Array": return new BigUint64Array(buffer);
1455
1641
  case "Float32Array": return new Float32Array(buffer);
1456
1642
  case "Float64Array": return new Float64Array(buffer);
1457
- default:
1458
1643
  }
1459
1644
  }
1460
1645
  case "error":
@@ -1557,11 +1742,13 @@ var Evaluator = class Evaluator {
1557
1742
  return promise;
1558
1743
  } else {
1559
1744
  this.hooks.push(hook);
1560
- return new RpcPromise$1(hook, []);
1745
+ return new RpcStub$1(hook);
1561
1746
  }
1562
1747
  };
1563
- if (value.length == 2) if (isPromise) return addStub(hook.get([]));
1564
- else return addStub(hook.dup());
1748
+ if (value.length == 2) {
1749
+ if (isPromise) return addStub(hook.get([]));
1750
+ else return addStub(hook.dup());
1751
+ }
1565
1752
  let path = value[2];
1566
1753
  if (!(path instanceof Array)) break;
1567
1754
  if (!path.every((part) => {
@@ -1591,7 +1778,8 @@ var Evaluator = class Evaluator {
1591
1778
  }
1592
1779
  });
1593
1780
  let instructions = value[4];
1594
- let promise = new RpcPromise$1(hook.map(path, captures, instructions), []);
1781
+ let resultHook = hook.map(path, captures, instructions);
1782
+ let promise = new RpcPromise$1(resultHook, []);
1595
1783
  this.promises.push({
1596
1784
  promise,
1597
1785
  parent,
@@ -1601,18 +1789,21 @@ var Evaluator = class Evaluator {
1601
1789
  }
1602
1790
  case "export":
1603
1791
  case "promise":
1604
- if (typeof value[1] == "number") if (value[0] == "promise") {
1605
- let promise = new RpcPromise$1(this.importer.importPromise(value[1]), []);
1606
- this.promises.push({
1607
- parent,
1608
- property,
1609
- promise
1610
- });
1611
- return promise;
1612
- } else {
1613
- let hook = this.importer.importStub(value[1]);
1614
- this.hooks.push(hook);
1615
- return new RpcStub$1(hook);
1792
+ if (typeof value[1] == "number") {
1793
+ if (value[0] == "promise") {
1794
+ let hook = this.importer.importPromise(value[1]);
1795
+ let promise = new RpcPromise$1(hook, []);
1796
+ this.promises.push({
1797
+ parent,
1798
+ property,
1799
+ promise
1800
+ });
1801
+ return promise;
1802
+ } else {
1803
+ let hook = this.importer.importStub(value[1]);
1804
+ this.hooks.push(hook);
1805
+ return new RpcStub$1(hook);
1806
+ }
1616
1807
  }
1617
1808
  break;
1618
1809
  case "writable":
@@ -1623,14 +1814,12 @@ var Evaluator = class Evaluator {
1623
1814
  return stream;
1624
1815
  }
1625
1816
  break;
1626
- case "readable":
1627
- if (typeof value[1] == "number") {
1628
- let stream = this.importer.getPipeReadable(value[1]);
1629
- let hook = streamImpl.createReadableStreamHook(stream);
1630
- this.hooks.push(hook);
1631
- return stream;
1632
- }
1633
- break;
1817
+ case "readable": if (typeof value[1] == "number") {
1818
+ let stream = this.importer.getPipeReadable(value[1]);
1819
+ let hook = streamImpl.createReadableStreamHook(stream);
1820
+ this.hooks.push(hook);
1821
+ return stream;
1822
+ }
1634
1823
  }
1635
1824
  throw new TypeError(`unknown special value: ${JSON.stringify(value)}`);
1636
1825
  } else if (value instanceof Object) {
@@ -1675,6 +1864,7 @@ function estimateEncodedSize(value, seen, depth = 0) {
1675
1864
  if (value instanceof ArrayBuffer) return ESTIMATED_BINARY_OVERHEAD + value.byteLength;
1676
1865
  if (typeof Blob !== "undefined" && value instanceof Blob) return ESTIMATED_BINARY_OVERHEAD + value.size;
1677
1866
  if (value instanceof Date) return 16;
1867
+ if (value instanceof RegExp) return ESTIMATED_OBJECT_OVERHEAD + estimateStringSize(value.source) + estimateStringSize(value.flags);
1678
1868
  seen ??= /* @__PURE__ */ new WeakSet();
1679
1869
  if (seen.has(value)) return ESTIMATED_ENTRY_OVERHEAD;
1680
1870
  seen.add(value);
@@ -1698,10 +1888,11 @@ function estimateEncodedSize(value, seen, depth = 0) {
1698
1888
  var ImportTableEntry = class {
1699
1889
  session;
1700
1890
  importId;
1891
+ pulling;
1701
1892
  constructor(session, importId, pulling) {
1702
1893
  this.session = session;
1703
1894
  this.importId = importId;
1704
- if (pulling) this.activePull = Promise.withResolvers();
1895
+ this.pulling = pulling;
1705
1896
  }
1706
1897
  localRefcount = 0;
1707
1898
  remoteRefcount = 1;
@@ -1732,7 +1923,7 @@ var ImportTableEntry = class {
1732
1923
  }
1733
1924
  async awaitResolution() {
1734
1925
  if (!this.activePull) {
1735
- this.session.sendPull(this.importId);
1926
+ if (!this.pulling) this.session.sendPull(this.importId);
1736
1927
  this.activePull = Promise.withResolvers();
1737
1928
  }
1738
1929
  await this.activePull.promise;
@@ -1787,24 +1978,28 @@ var RpcImportHook = class RpcImportHook extends StubHook {
1787
1978
  if (this.entry) return this.entry;
1788
1979
  else throw new Error("This RpcImportHook was already disposed.");
1789
1980
  }
1981
+ getEntryTakingOwnership(disposeOwned) {
1982
+ try {
1983
+ return this.getEntry();
1984
+ } catch (err) {
1985
+ disposeOwned();
1986
+ throw err;
1987
+ }
1988
+ }
1790
1989
  call(path, args) {
1791
- let entry = this.getEntry();
1990
+ let entry = this.getEntryTakingOwnership(() => args.dispose());
1792
1991
  if (entry.resolution) return entry.resolution.call(path, args);
1793
1992
  else return entry.session.sendCall(entry.importId, path, args);
1794
1993
  }
1795
1994
  stream(path, args) {
1796
- let entry = this.getEntry();
1995
+ let entry = this.getEntryTakingOwnership(() => args.dispose());
1797
1996
  if (entry.resolution) return entry.resolution.stream(path, args);
1798
1997
  else return entry.session.sendStream(entry.importId, path, args);
1799
1998
  }
1800
1999
  map(path, captures, instructions) {
1801
- let entry;
1802
- try {
1803
- entry = this.getEntry();
1804
- } catch (err) {
2000
+ let entry = this.getEntryTakingOwnership(() => {
1805
2001
  for (let cap of captures) cap.dispose();
1806
- throw err;
1807
- }
2002
+ });
1808
2003
  if (entry.resolution) return entry.resolution.map(path, captures, instructions);
1809
2004
  else return entry.session.sendMap(entry.importId, path, captures, instructions);
1810
2005
  }
@@ -1958,6 +2153,7 @@ var RpcSessionImpl = class {
1958
2153
  let autoRelease = exp.autoRelease;
1959
2154
  ++this.pullCount;
1960
2155
  exp.pull = resolve().then((payload) => {
2156
+ if (this.exports[exportId] !== exp) return;
1961
2157
  let value = Devaluator.devaluate(payload.value, void 0, this, payload, this.encodingLevel);
1962
2158
  this.send([
1963
2159
  "resolve",
@@ -1966,6 +2162,7 @@ var RpcSessionImpl = class {
1966
2162
  ]);
1967
2163
  if (autoRelease) this.releaseExport(exportId, 1);
1968
2164
  }, (error) => {
2165
+ if (this.exports[exportId] !== exp) return;
1969
2166
  this.send([
1970
2167
  "reject",
1971
2168
  exportId,
@@ -1991,7 +2188,7 @@ var RpcSessionImpl = class {
1991
2188
  }
1992
2189
  }
1993
2190
  getImport(hook) {
1994
- if (hook instanceof RpcImportHook && hook.entry && hook.entry.session === this) return hook.entry.importId;
2191
+ if (hook instanceof RpcImportHook && hook.entry && hook.entry.session === this && !hook.entry.resolution) return hook.entry.importId;
1995
2192
  else return;
1996
2193
  }
1997
2194
  importStub(idx) {
@@ -2065,32 +2262,52 @@ var RpcSessionImpl = class {
2065
2262
  }
2066
2263
  }
2067
2264
  sendCall(id, path, args) {
2068
- if (this.abortReason) throw this.abortReason;
2265
+ if (this.abortReason) {
2266
+ args?.dispose();
2267
+ throw this.abortReason;
2268
+ }
2069
2269
  let value = [
2070
2270
  "pipeline",
2071
2271
  id,
2072
2272
  path
2073
2273
  ];
2074
2274
  if (args) {
2075
- let devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2275
+ let devalue;
2276
+ try {
2277
+ devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2278
+ } catch (err) {
2279
+ args.dispose();
2280
+ throw err;
2281
+ }
2076
2282
  value.push(devalue[0]);
2077
2283
  }
2078
2284
  this.send(["push", value]);
2285
+ args?.dispose();
2079
2286
  let entry = new ImportTableEntry(this, this.imports.length, false);
2080
2287
  this.imports.push(entry);
2081
2288
  return new RpcImportHook(true, entry);
2082
2289
  }
2083
2290
  sendStream(id, path, args) {
2084
- if (this.abortReason) throw this.abortReason;
2291
+ if (this.abortReason) {
2292
+ args.dispose();
2293
+ throw this.abortReason;
2294
+ }
2085
2295
  let value = [
2086
2296
  "pipeline",
2087
2297
  id,
2088
2298
  path
2089
2299
  ];
2090
- let devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2300
+ let devalue;
2301
+ try {
2302
+ devalue = Devaluator.devaluate(args.value, void 0, this, args, this.encodingLevel);
2303
+ } catch (err) {
2304
+ args.dispose();
2305
+ throw err;
2306
+ }
2091
2307
  value.push(devalue[0]);
2092
2308
  let msg = ["stream", value];
2093
2309
  let size = this.send(msg);
2310
+ args.dispose();
2094
2311
  if (size === void 0) size = estimateEncodedSize(msg);
2095
2312
  let importId = this.imports.length;
2096
2313
  let entry = new ImportTableEntry(this, importId, true);
@@ -2188,7 +2405,8 @@ var RpcSessionImpl = class {
2188
2405
  if (msg instanceof Array) switch (msg[0]) {
2189
2406
  case "push":
2190
2407
  if (msg.length > 1) {
2191
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2408
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2409
+ let hook = new PayloadStubHook(payload);
2192
2410
  hook.ignoreUnhandledRejections();
2193
2411
  this.exports.push({
2194
2412
  hook,
@@ -2199,7 +2417,8 @@ var RpcSessionImpl = class {
2199
2417
  break;
2200
2418
  case "stream":
2201
2419
  if (msg.length > 1) {
2202
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2420
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2421
+ let hook = new PayloadStubHook(payload);
2203
2422
  hook.ignoreUnhandledRejections();
2204
2423
  let exportId = this.exports.length;
2205
2424
  this.exports.push({
@@ -2234,13 +2453,14 @@ var RpcSessionImpl = class {
2234
2453
  let importId = msg[1];
2235
2454
  if (typeof importId == "number" && msg.length > 2) {
2236
2455
  let imp = this.imports[importId];
2237
- if (imp) if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2238
- else {
2239
- let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2240
- payload.dispose();
2241
- imp.resolve(new ErrorStubHook(payload.value));
2242
- }
2243
- else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2456
+ if (imp) {
2457
+ if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2458
+ else {
2459
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2460
+ payload.dispose();
2461
+ imp.resolve(new ErrorStubHook(payload.value));
2462
+ }
2463
+ } else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2244
2464
  continue;
2245
2465
  }
2246
2466
  break;
@@ -2312,7 +2532,8 @@ var RpcSession$1 = class {
2312
2532
  const MAX_CLOSE_REASON_BYTES = 123;
2313
2533
  function newWebSocketRpcSession$1(webSocket, localMain, options) {
2314
2534
  if (typeof webSocket === "string") webSocket = new WebSocket(webSocket);
2315
- return new RpcSession$1(new WebSocketTransport(webSocket), localMain, options).getRemoteMain();
2535
+ let transport = new WebSocketTransport(webSocket);
2536
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2316
2537
  }
2317
2538
  /**
2318
2539
  * For use in Cloudflare Workers: Construct an HTTP response that starts a WebSocket RPC session
@@ -2349,12 +2570,13 @@ var WebSocketTransport = class {
2349
2570
  });
2350
2571
  }
2351
2572
  webSocket.addEventListener("message", (event) => {
2352
- if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) if (this.#receiveResolver) {
2353
- this.#receiveResolver(event.data);
2354
- this.#receiveResolver = void 0;
2355
- this.#receiveRejecter = void 0;
2356
- } else this.#receiveQueue.push(event.data);
2357
- else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2573
+ if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) {
2574
+ if (this.#receiveResolver) {
2575
+ this.#receiveResolver(event.data);
2576
+ this.#receiveResolver = void 0;
2577
+ this.#receiveRejecter = void 0;
2578
+ } else this.#receiveQueue.push(event.data);
2579
+ } else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2358
2580
  });
2359
2581
  webSocket.addEventListener("close", (event) => {
2360
2582
  this.#receivedError(/* @__PURE__ */ new Error(`Peer closed WebSocket: ${event.code} ${event.reason}`));
@@ -2446,7 +2668,8 @@ function newHttpBatchRpcSession$1(urlOrRequest, options) {
2446
2668
  let body = await response.text();
2447
2669
  return body == "" ? [] : body.split("\n");
2448
2670
  };
2449
- return new RpcSession$1(new BatchClientTransport(sendBatch), void 0, options).getRemoteMain();
2671
+ let transport = new BatchClientTransport(sendBatch);
2672
+ return new RpcSession$1(transport, void 0, options).getRemoteMain();
2450
2673
  }
2451
2674
  var BatchServerTransport = class {
2452
2675
  constructor(batch) {
@@ -2489,7 +2712,8 @@ var BatchServerTransport = class {
2489
2712
  async function newHttpBatchRpcResponse(request, localMain, options) {
2490
2713
  if (request.method !== "POST") return new Response("This endpoint only accepts POST requests.", { status: 405 });
2491
2714
  let body = await request.text();
2492
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2715
+ let batch = body === "" ? [] : body.split("\n");
2716
+ let transport = new BatchServerTransport(batch);
2493
2717
  let rpc = new RpcSession$1(transport, localMain, options);
2494
2718
  await transport.whenAllReceived();
2495
2719
  await rpc.drain();
@@ -2519,7 +2743,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2519
2743
  });
2520
2744
  request.on("error", reject);
2521
2745
  });
2522
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2746
+ let batch = body === "" ? [] : body.split("\n");
2747
+ let transport = new BatchServerTransport(batch);
2523
2748
  let rpc = new RpcSession$1(transport, localMain, options);
2524
2749
  await transport.whenAllReceived();
2525
2750
  await rpc.drain();
@@ -2530,7 +2755,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2530
2755
  //#endregion
2531
2756
  //#region src/messageport.ts
2532
2757
  function newMessagePortRpcSession$1(port, localMain, options) {
2533
- return new RpcSession$1(new MessagePortTransport(port), localMain, options).getRemoteMain();
2758
+ let transport = new MessagePortTransport(port);
2759
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2534
2760
  }
2535
2761
  var MessagePortTransport = class {
2536
2762
  encodingLevel = "structuredClonable";
@@ -2718,9 +2944,11 @@ var MapVariableHook = class extends StubHook {
2718
2944
  else throwMapperBuilderUseError();
2719
2945
  }
2720
2946
  call(path, args) {
2947
+ args.dispose();
2721
2948
  throwMapperBuilderUseError();
2722
2949
  }
2723
2950
  map(path, captures, instructions) {
2951
+ for (let cap of captures) cap.dispose();
2724
2952
  throwMapperBuilderUseError();
2725
2953
  }
2726
2954
  pull() {
@@ -2778,7 +3006,8 @@ var MapApplicator = class {
2778
3006
  }
2779
3007
  };
2780
3008
  function applyMapToElement(input, parent, owner, captures, instructions) {
2781
- let mapper = new MapApplicator(captures, new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner)));
3009
+ let inputHook = new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner));
3010
+ let mapper = new MapApplicator(captures, inputHook);
2782
3011
  try {
2783
3012
  return mapper.apply(instructions);
2784
3013
  } finally {
@@ -2811,9 +3040,10 @@ mapImpl.applyMap = (input, parent, owner, captures, instructions) => {
2811
3040
  var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2812
3041
  state;
2813
3042
  static create(stream) {
3043
+ let writer = stream.getWriter();
2814
3044
  return new WritableStreamStubHook({
2815
3045
  refcount: 1,
2816
- writer: stream.getWriter(),
3046
+ writer,
2817
3047
  closed: false
2818
3048
  });
2819
3049
  }
@@ -2831,13 +3061,12 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2831
3061
  let state = this.getState();
2832
3062
  if (path.length !== 1 || typeof path[0] !== "string") throw new Error("WritableStream stub only supports direct method calls");
2833
3063
  const method = path[0];
2834
- if (method !== "write" && method !== "close" && method !== "abort") {
2835
- args.dispose();
2836
- throw new Error(`Unknown WritableStream method: ${method}`);
2837
- }
3064
+ if (method !== "write" && method !== "close" && method !== "abort") throw new Error(`Unknown WritableStream method: ${method}`);
2838
3065
  if (method === "close" || method === "abort") state.closed = true;
2839
- return new PromiseStubHook((method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer)).then((payload) => new PayloadStubHook(payload)));
3066
+ let promise = method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer);
3067
+ return new PromiseStubHook(promise.then((payload) => new PayloadStubHook(payload)));
2840
3068
  } catch (err) {
3069
+ args.dispose();
2841
3070
  return new ErrorStubHook(err);
2842
3071
  }
2843
3072
  }
@@ -2849,7 +3078,8 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2849
3078
  return new ErrorStubHook(/* @__PURE__ */ new Error("Cannot access properties on a WritableStream stub"));
2850
3079
  }
2851
3080
  dup() {
2852
- return new WritableStreamStubHook(this.getState(), this);
3081
+ let state = this.getState();
3082
+ return new WritableStreamStubHook(state, this);
2853
3083
  }
2854
3084
  pull() {
2855
3085
  return Promise.reject(/* @__PURE__ */ new Error("Cannot pull a WritableStream stub"));
@@ -2867,9 +3097,9 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2867
3097
  }
2868
3098
  onBroken(callback) {}
2869
3099
  };
2870
- const INITIAL_WINDOW = 256 * 1024;
2871
- const MAX_WINDOW = 1024 * 1024 * 1024;
2872
- const MIN_WINDOW = 64 * 1024;
3100
+ const INITIAL_WINDOW = 262144;
3101
+ const MAX_WINDOW = 1073741824;
3102
+ const MIN_WINDOW = 65536;
2873
3103
  const STARTUP_GROWTH_FACTOR = 2;
2874
3104
  const STEADY_GROWTH_FACTOR = 1.25;
2875
3105
  const DECAY_FACTOR = .9;