seroval 0.10.4 → 0.11.1

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.
@@ -24,6 +24,7 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
24
24
  return Feature2;
25
25
  })(Feature || {});
26
26
  var ALL_ENABLED = 16383;
27
+ var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
27
28
 
28
29
  // src/core/constants.ts
29
30
  var SYMBOL_STRING = {
@@ -116,13 +117,6 @@ function deserializeConstant(node) {
116
117
  }
117
118
  }
118
119
 
119
- // src/core/assert.ts
120
- function assert(cond, error) {
121
- if (!cond) {
122
- throw error;
123
- }
124
- }
125
-
126
120
  // src/core/get-identifier.ts
127
121
  var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
128
122
  var REF_START_CHARS_LEN = REF_START_CHARS.length;
@@ -281,6 +275,13 @@ var INFINITY_NODE = createConstantNode(5 /* Infinity */);
281
275
  var NEG_INFINITY_NODE = createConstantNode(6 /* NegativeInfinity */);
282
276
  var NAN_NODE = createConstantNode(7 /* NaN */);
283
277
 
278
+ // src/core/assert.ts
279
+ function assert(cond, error) {
280
+ if (!cond) {
281
+ throw error;
282
+ }
283
+ }
284
+
284
285
  // src/core/keys.ts
285
286
  var REFERENCES_KEY = "__SEROVAL_REFS__";
286
287
  var GLOBAL_CONTEXT_API = "_$";
@@ -399,8 +400,7 @@ function createStringNode(value) {
399
400
  o: void 0
400
401
  };
401
402
  }
402
- function createBigIntNode(ctx, current) {
403
- assert(ctx.features & 8 /* BigInt */, new UnsupportedTypeError(current));
403
+ function createBigIntNode(current) {
404
404
  return {
405
405
  t: 3 /* BigInt */,
406
406
  i: void 0,
@@ -486,8 +486,7 @@ function createArrayBufferNode(id, current) {
486
486
  o: void 0
487
487
  };
488
488
  }
489
- function createWKSymbolNode(ctx, id, current) {
490
- assert(ctx.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
489
+ function createWKSymbolNode(id, current) {
491
490
  assert(current in INV_SYMBOL_REF, new Error("Only well-known symbols are supported."));
492
491
  return {
493
492
  t: 17 /* WKSymbol */,
@@ -530,7 +529,6 @@ function serializeArrayBuffer(ctx, current) {
530
529
  return createArrayBufferNode(id, current);
531
530
  }
532
531
  function createTypedArrayNode(ctx, id, current) {
533
- assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
534
532
  return {
535
533
  t: 15 /* TypedArray */,
536
534
  i: id,
@@ -546,12 +544,7 @@ function createTypedArrayNode(ctx, id, current) {
546
544
  o: void 0
547
545
  };
548
546
  }
549
- var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
550
547
  function createBigIntTypedArrayNode(ctx, id, current) {
551
- assert(
552
- (ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
553
- new UnsupportedTypeError(current)
554
- );
555
548
  return {
556
549
  t: 16 /* BigIntTypedArray */,
557
550
  i: id,
@@ -591,7 +584,7 @@ function createSymbolNode(ctx, current) {
591
584
  if (hasReferenceID(current)) {
592
585
  return createReferenceNode(id, current);
593
586
  }
594
- return createWKSymbolNode(ctx, id, current);
587
+ return createWKSymbolNode(id, current);
595
588
  }
596
589
  function createFunctionNode(ctx, current) {
597
590
  assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
@@ -743,7 +736,6 @@ function getObjectFlag(obj) {
743
736
 
744
737
  // src/core/tree/web-api.ts
745
738
  async function createBlobNode(ctx, id, current) {
746
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
747
739
  return {
748
740
  t: 23 /* Blob */,
749
741
  i: id,
@@ -760,7 +752,6 @@ async function createBlobNode(ctx, id, current) {
760
752
  };
761
753
  }
762
754
  async function createFileNode(ctx, id, current) {
763
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
764
755
  return {
765
756
  t: 24 /* File */,
766
757
  i: id,
@@ -778,8 +769,7 @@ async function createFileNode(ctx, id, current) {
778
769
  }
779
770
 
780
771
  // src/core/web-api.ts
781
- function createURLNode(ctx, id, current) {
782
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
772
+ function createURLNode(id, current) {
783
773
  return {
784
774
  t: 18 /* URL */,
785
775
  i: id,
@@ -795,8 +785,7 @@ function createURLNode(ctx, id, current) {
795
785
  o: void 0
796
786
  };
797
787
  }
798
- function createURLSearchParamsNode(ctx, id, current) {
799
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
788
+ function createURLSearchParamsNode(id, current) {
800
789
  return {
801
790
  t: 19 /* URLSearchParams */,
802
791
  i: id,
@@ -812,6 +801,22 @@ function createURLSearchParamsNode(ctx, id, current) {
812
801
  o: void 0
813
802
  };
814
803
  }
804
+ function createDOMExceptionNode(id, current) {
805
+ return {
806
+ t: 39 /* DOMException */,
807
+ i: id,
808
+ s: serializeString(current.message),
809
+ l: void 0,
810
+ c: serializeString(current.name),
811
+ m: void 0,
812
+ p: void 0,
813
+ e: void 0,
814
+ a: void 0,
815
+ f: void 0,
816
+ b: void 0,
817
+ o: void 0
818
+ };
819
+ }
815
820
 
816
821
  // src/core/promise-to-result.ts
817
822
  async function promiseToResult(current) {
@@ -822,6 +827,45 @@ async function promiseToResult(current) {
822
827
  }
823
828
  }
824
829
 
830
+ // src/core/constructors.ts
831
+ function createRequestOptions(current, body) {
832
+ return {
833
+ body,
834
+ cache: current.cache,
835
+ credentials: current.credentials,
836
+ headers: current.headers,
837
+ integrity: current.integrity,
838
+ keepalive: current.keepalive,
839
+ method: current.method,
840
+ mode: current.mode,
841
+ redirect: current.redirect,
842
+ referrer: current.referrer,
843
+ referrerPolicy: current.referrerPolicy
844
+ };
845
+ }
846
+ function createResponseOptions(current) {
847
+ return {
848
+ headers: current.headers,
849
+ status: current.status,
850
+ statusText: current.statusText
851
+ };
852
+ }
853
+ function createEventOptions(current) {
854
+ return {
855
+ bubbles: current.bubbles,
856
+ cancelable: current.cancelable,
857
+ composed: current.composed
858
+ };
859
+ }
860
+ function createCustomEventOptions(current) {
861
+ return {
862
+ detail: current.detail,
863
+ bubbles: current.bubbles,
864
+ cancelable: current.cancelable,
865
+ composed: current.composed
866
+ };
867
+ }
868
+
825
869
  // src/core/tree/async.ts
826
870
  async function generateNodeList(ctx, current) {
827
871
  const size = current.length;
@@ -862,7 +906,6 @@ async function generateArrayNode(ctx, id, current) {
862
906
  };
863
907
  }
864
908
  async function generateMapNode(ctx, id, current) {
865
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
866
909
  const len = current.size;
867
910
  const keyNodes = new Array(len);
868
911
  const valueNodes = new Array(len);
@@ -901,7 +944,6 @@ async function generateMapNode(ctx, id, current) {
901
944
  };
902
945
  }
903
946
  async function generateSetNode(ctx, id, current) {
904
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
905
947
  const len = current.size;
906
948
  const nodes = new Array(len);
907
949
  const deferred = new Array(len);
@@ -1013,7 +1055,6 @@ async function generatePlainProperties(ctx, properties) {
1013
1055
  };
1014
1056
  }
1015
1057
  async function generatePromiseNode(ctx, id, current) {
1016
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
1017
1058
  const [status, result] = await promiseToResult(current);
1018
1059
  return {
1019
1060
  t: 12 /* Promise */,
@@ -1083,7 +1124,6 @@ async function generateErrorNode(ctx, id, current) {
1083
1124
  };
1084
1125
  }
1085
1126
  async function generateHeadersNode(ctx, id, current) {
1086
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
1087
1127
  const items = {};
1088
1128
  current.forEach((value, key) => {
1089
1129
  items[key] = value;
@@ -1104,7 +1144,6 @@ async function generateHeadersNode(ctx, id, current) {
1104
1144
  };
1105
1145
  }
1106
1146
  async function generateFormDataNode(ctx, id, current) {
1107
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
1108
1147
  const items = {};
1109
1148
  current.forEach((value, key) => {
1110
1149
  items[key] = value;
@@ -1140,6 +1179,76 @@ async function generateBoxedNode(ctx, id, current) {
1140
1179
  o: void 0
1141
1180
  };
1142
1181
  }
1182
+ async function generateRequestNode(ctx, id, current) {
1183
+ return {
1184
+ t: 35 /* Request */,
1185
+ i: id,
1186
+ s: serializeString(current.url),
1187
+ l: void 0,
1188
+ c: void 0,
1189
+ m: void 0,
1190
+ p: void 0,
1191
+ e: void 0,
1192
+ f: await parseObject(
1193
+ ctx,
1194
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
1195
+ ),
1196
+ a: void 0,
1197
+ b: void 0,
1198
+ o: void 0
1199
+ };
1200
+ }
1201
+ async function generateResponseNode(ctx, id, current) {
1202
+ return {
1203
+ t: 36 /* Response */,
1204
+ i: id,
1205
+ s: void 0,
1206
+ l: void 0,
1207
+ c: void 0,
1208
+ m: void 0,
1209
+ p: void 0,
1210
+ e: void 0,
1211
+ f: void 0,
1212
+ a: [
1213
+ current.body ? serializeArrayBuffer(ctx, await current.clone().arrayBuffer()) : NULL_NODE,
1214
+ await parseObject(ctx, createResponseOptions(current))
1215
+ ],
1216
+ b: void 0,
1217
+ o: void 0
1218
+ };
1219
+ }
1220
+ async function generateEventNode(ctx, id, current) {
1221
+ return {
1222
+ t: 37 /* Event */,
1223
+ i: id,
1224
+ s: serializeString(current.type),
1225
+ l: void 0,
1226
+ c: void 0,
1227
+ m: void 0,
1228
+ p: void 0,
1229
+ e: void 0,
1230
+ a: void 0,
1231
+ f: await parseObject(ctx, createEventOptions(current)),
1232
+ b: void 0,
1233
+ o: void 0
1234
+ };
1235
+ }
1236
+ async function generateCustomEventNode(ctx, id, current) {
1237
+ return {
1238
+ t: 38 /* CustomEvent */,
1239
+ i: id,
1240
+ s: serializeString(current.type),
1241
+ l: void 0,
1242
+ c: void 0,
1243
+ m: void 0,
1244
+ p: void 0,
1245
+ e: void 0,
1246
+ a: void 0,
1247
+ f: await parseObject(ctx, createCustomEventOptions(current)),
1248
+ b: void 0,
1249
+ o: void 0
1250
+ };
1251
+ }
1143
1252
  async function parseObject(ctx, current) {
1144
1253
  if (!current) {
1145
1254
  return NULL_NODE;
@@ -1154,49 +1263,17 @@ async function parseObject(ctx, current) {
1154
1263
  if (Array.isArray(current)) {
1155
1264
  return generateArrayNode(ctx, id, current);
1156
1265
  }
1157
- switch (current.constructor) {
1266
+ const currentClass = current.constructor;
1267
+ switch (currentClass) {
1158
1268
  case Number:
1159
1269
  case Boolean:
1160
1270
  case String:
1161
1271
  case BigInt:
1162
- case Function:
1163
- case Symbol:
1164
1272
  return generateBoxedNode(ctx, id, current);
1165
1273
  case Date:
1166
1274
  return createDateNode(id, current);
1167
1275
  case RegExp:
1168
1276
  return createRegExpNode(id, current);
1169
- case Promise:
1170
- return generatePromiseNode(ctx, id, current);
1171
- case ArrayBuffer:
1172
- return createArrayBufferNode(id, current);
1173
- case Int8Array:
1174
- case Int16Array:
1175
- case Int32Array:
1176
- case Uint8Array:
1177
- case Uint16Array:
1178
- case Uint32Array:
1179
- case Uint8ClampedArray:
1180
- case Float32Array:
1181
- case Float64Array:
1182
- return createTypedArrayNode(ctx, id, current);
1183
- case BigInt64Array:
1184
- case BigUint64Array:
1185
- return createBigIntTypedArrayNode(ctx, id, current);
1186
- case DataView:
1187
- return createDataViewNode(ctx, id, current);
1188
- case Map:
1189
- return generateMapNode(
1190
- ctx,
1191
- id,
1192
- current
1193
- );
1194
- case Set:
1195
- return generateSetNode(
1196
- ctx,
1197
- id,
1198
- current
1199
- );
1200
1277
  case Object:
1201
1278
  return generateObjectNode(
1202
1279
  ctx,
@@ -1211,11 +1288,6 @@ async function parseObject(ctx, current) {
1211
1288
  current,
1212
1289
  true
1213
1290
  );
1214
- case AggregateError:
1215
- if (ctx.features & 1 /* AggregateError */) {
1216
- return generateAggregateErrorNode(ctx, id, current);
1217
- }
1218
- return generateErrorNode(ctx, id, current);
1219
1291
  case Error:
1220
1292
  case EvalError:
1221
1293
  case RangeError:
@@ -1224,40 +1296,100 @@ async function parseObject(ctx, current) {
1224
1296
  case TypeError:
1225
1297
  case URIError:
1226
1298
  return generateErrorNode(ctx, id, current);
1227
- case URL:
1228
- return createURLNode(ctx, id, current);
1229
- case URLSearchParams:
1230
- return createURLSearchParamsNode(ctx, id, current);
1231
- case Blob:
1232
- return createBlobNode(ctx, id, current);
1233
- case File:
1234
- return createFileNode(ctx, id, current);
1235
- case Headers:
1236
- return generateHeadersNode(ctx, id, current);
1237
- case FormData:
1238
- return generateFormDataNode(ctx, id, current);
1239
1299
  default:
1240
1300
  break;
1241
1301
  }
1242
- if (current instanceof AggregateError) {
1243
- if (ctx.features & 1 /* AggregateError */) {
1244
- return generateAggregateErrorNode(ctx, id, current);
1302
+ if (ctx.features & 2048 /* TypedArray */) {
1303
+ switch (currentClass) {
1304
+ case ArrayBuffer:
1305
+ return createArrayBufferNode(id, current);
1306
+ case Int8Array:
1307
+ case Int16Array:
1308
+ case Int32Array:
1309
+ case Uint8Array:
1310
+ case Uint16Array:
1311
+ case Uint32Array:
1312
+ case Uint8ClampedArray:
1313
+ case Float32Array:
1314
+ case Float64Array:
1315
+ return createTypedArrayNode(ctx, id, current);
1316
+ case DataView:
1317
+ return createDataViewNode(ctx, id, current);
1318
+ default:
1319
+ break;
1245
1320
  }
1246
- return generateErrorNode(ctx, id, current);
1247
1321
  }
1248
- if (current instanceof Error) {
1249
- return generateErrorNode(ctx, id, current);
1322
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
1323
+ switch (currentClass) {
1324
+ case BigInt64Array:
1325
+ case BigUint64Array:
1326
+ return createBigIntTypedArrayNode(ctx, id, current);
1327
+ default:
1328
+ break;
1329
+ }
1330
+ }
1331
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
1332
+ return generateMapNode(
1333
+ ctx,
1334
+ id,
1335
+ current
1336
+ );
1337
+ }
1338
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
1339
+ return generateSetNode(
1340
+ ctx,
1341
+ id,
1342
+ current
1343
+ );
1344
+ }
1345
+ if (ctx.features & 8192 /* WebAPI */) {
1346
+ switch (currentClass) {
1347
+ case URL:
1348
+ return createURLNode(id, current);
1349
+ case URLSearchParams:
1350
+ return createURLSearchParamsNode(id, current);
1351
+ case Blob:
1352
+ return createBlobNode(ctx, id, current);
1353
+ case File:
1354
+ return createFileNode(ctx, id, current);
1355
+ case Headers:
1356
+ return generateHeadersNode(ctx, id, current);
1357
+ case FormData:
1358
+ return generateFormDataNode(ctx, id, current);
1359
+ case Request:
1360
+ return generateRequestNode(ctx, id, current);
1361
+ case Response:
1362
+ return generateResponseNode(ctx, id, current);
1363
+ case Event:
1364
+ return generateEventNode(ctx, id, current);
1365
+ case CustomEvent:
1366
+ return generateCustomEventNode(ctx, id, current);
1367
+ case DOMException:
1368
+ return createDOMExceptionNode(id, current);
1369
+ default:
1370
+ break;
1371
+ }
1372
+ }
1373
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
1374
+ return generateAggregateErrorNode(ctx, id, current);
1250
1375
  }
1251
- if (current instanceof Promise) {
1376
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
1252
1377
  return generatePromiseNode(ctx, id, current);
1253
1378
  }
1254
- if (Symbol.iterator in current) {
1255
- return generateObjectNode(ctx, id, current, !!current.constructor);
1379
+ if (current instanceof Error) {
1380
+ return generateErrorNode(ctx, id, current);
1381
+ }
1382
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
1383
+ return generateObjectNode(ctx, id, current, !!currentClass);
1256
1384
  }
1257
1385
  throw new UnsupportedTypeError(current);
1258
1386
  }
1259
1387
  async function parseAsync(ctx, current) {
1260
- switch (typeof current) {
1388
+ const t = typeof current;
1389
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
1390
+ return createBigIntNode(current);
1391
+ }
1392
+ switch (t) {
1261
1393
  case "boolean":
1262
1394
  return current ? TRUE_NODE : FALSE_NODE;
1263
1395
  case "undefined":
@@ -1266,8 +1398,6 @@ async function parseAsync(ctx, current) {
1266
1398
  return createStringNode(current);
1267
1399
  case "number":
1268
1400
  return createNumberNode(current);
1269
- case "bigint":
1270
- return createBigIntNode(ctx, current);
1271
1401
  case "object":
1272
1402
  return parseObject(ctx, current);
1273
1403
  case "symbol":
@@ -1508,6 +1638,53 @@ function deserializeBoxed(ctx, node) {
1508
1638
  Object(deserializeTree(ctx, node.f))
1509
1639
  );
1510
1640
  }
1641
+ function deserializeRequest(ctx, node) {
1642
+ return assignIndexedValue(
1643
+ ctx,
1644
+ node.i,
1645
+ new Request(deserializeString(node.s), deserializeTree(ctx, node.f))
1646
+ );
1647
+ }
1648
+ function deserializeResponse(ctx, node) {
1649
+ return assignIndexedValue(
1650
+ ctx,
1651
+ node.i,
1652
+ new Response(
1653
+ deserializeTree(ctx, node.a[0]),
1654
+ deserializeTree(ctx, node.a[1])
1655
+ )
1656
+ );
1657
+ }
1658
+ function deserializeEvent(ctx, node) {
1659
+ return assignIndexedValue(
1660
+ ctx,
1661
+ node.i,
1662
+ new Event(
1663
+ deserializeString(node.s),
1664
+ deserializeTree(ctx, node.f)
1665
+ )
1666
+ );
1667
+ }
1668
+ function deserializeCustomEvent(ctx, node) {
1669
+ return assignIndexedValue(
1670
+ ctx,
1671
+ node.i,
1672
+ new CustomEvent(
1673
+ deserializeString(node.s),
1674
+ deserializeTree(ctx, node.f)
1675
+ )
1676
+ );
1677
+ }
1678
+ function deserializeDOMException(ctx, node) {
1679
+ return assignIndexedValue(
1680
+ ctx,
1681
+ node.i,
1682
+ new DOMException(
1683
+ deserializeString(node.s),
1684
+ deserializeString(node.c)
1685
+ )
1686
+ );
1687
+ }
1511
1688
  function deserializeTree(ctx, node) {
1512
1689
  switch (node.t) {
1513
1690
  case 2 /* Constant */:
@@ -1564,6 +1741,16 @@ function deserializeTree(ctx, node) {
1564
1741
  return deserializeFormData(ctx, node);
1565
1742
  case 27 /* Boxed */:
1566
1743
  return deserializeBoxed(ctx, node);
1744
+ case 35 /* Request */:
1745
+ return deserializeRequest(ctx, node);
1746
+ case 36 /* Response */:
1747
+ return deserializeResponse(ctx, node);
1748
+ case 37 /* Event */:
1749
+ return deserializeEvent(ctx, node);
1750
+ case 38 /* CustomEvent */:
1751
+ return deserializeCustomEvent(ctx, node);
1752
+ case 39 /* DOMException */:
1753
+ return deserializeDOMException(ctx, node);
1567
1754
  default:
1568
1755
  throw new Error("invariant");
1569
1756
  }
@@ -2138,6 +2325,33 @@ function serializeBoxed(ctx, node) {
2138
2325
  function serializeWKSymbol(ctx, node) {
2139
2326
  return assignIndexedValue2(ctx, node.i, SYMBOL_STRING[node.s]);
2140
2327
  }
2328
+ function serializeRequest(ctx, node) {
2329
+ return assignIndexedValue2(ctx, node.i, 'new Request("' + node.s + '",' + serializeTree(ctx, node.f) + ")");
2330
+ }
2331
+ function serializeResponse(ctx, node) {
2332
+ return assignIndexedValue2(ctx, node.i, "new Response(" + serializeTree(ctx, node.a[0]) + "," + serializeTree(ctx, node.a[1]) + ")");
2333
+ }
2334
+ function serializeEvent(ctx, node) {
2335
+ return assignIndexedValue2(
2336
+ ctx,
2337
+ node.i,
2338
+ 'new Event("' + node.s + '",' + serializeTree(ctx, node.f) + ")"
2339
+ );
2340
+ }
2341
+ function serializeCustomEvent(ctx, node) {
2342
+ return assignIndexedValue2(
2343
+ ctx,
2344
+ node.i,
2345
+ 'new CustomEvent("' + node.s + '",' + serializeTree(ctx, node.f) + ")"
2346
+ );
2347
+ }
2348
+ function serializeDOMException(ctx, node) {
2349
+ return assignIndexedValue2(
2350
+ ctx,
2351
+ node.i,
2352
+ 'new DOMException("' + node.s + '","' + node.c + '")'
2353
+ );
2354
+ }
2141
2355
  function serializeTree(ctx, node) {
2142
2356
  switch (node.t) {
2143
2357
  case 0 /* Number */:
@@ -2195,6 +2409,16 @@ function serializeTree(ctx, node) {
2195
2409
  return serializeFormData(ctx, node);
2196
2410
  case 27 /* Boxed */:
2197
2411
  return serializeBoxed(ctx, node);
2412
+ case 35 /* Request */:
2413
+ return serializeRequest(ctx, node);
2414
+ case 36 /* Response */:
2415
+ return serializeResponse(ctx, node);
2416
+ case 37 /* Event */:
2417
+ return serializeEvent(ctx, node);
2418
+ case 38 /* CustomEvent */:
2419
+ return serializeCustomEvent(ctx, node);
2420
+ case 39 /* DOMException */:
2421
+ return serializeDOMException(ctx, node);
2198
2422
  default:
2199
2423
  throw new Error("invariant");
2200
2424
  }
@@ -2240,7 +2464,6 @@ function generateArrayNode2(ctx, id, current) {
2240
2464
  };
2241
2465
  }
2242
2466
  function generateMapNode2(ctx, id, current) {
2243
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
2244
2467
  const len = current.size;
2245
2468
  const keyNodes = new Array(len);
2246
2469
  const valueNodes = new Array(len);
@@ -2279,7 +2502,6 @@ function generateMapNode2(ctx, id, current) {
2279
2502
  };
2280
2503
  }
2281
2504
  function generateSetNode2(ctx, id, current) {
2282
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
2283
2505
  const len = current.size;
2284
2506
  const nodes = new Array(len);
2285
2507
  const deferred = new Array(len);
@@ -2440,7 +2662,6 @@ function generateErrorNode2(ctx, id, current) {
2440
2662
  };
2441
2663
  }
2442
2664
  function generateHeadersNode2(ctx, id, current) {
2443
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2444
2665
  const items = {};
2445
2666
  current.forEach((value, key) => {
2446
2667
  items[key] = value;
@@ -2461,7 +2682,6 @@ function generateHeadersNode2(ctx, id, current) {
2461
2682
  };
2462
2683
  }
2463
2684
  function generateFormDataNode2(ctx, id, current) {
2464
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2465
2685
  const items = {};
2466
2686
  current.forEach((value, key) => {
2467
2687
  items[key] = value;
@@ -2497,6 +2717,38 @@ function generateBoxedNode2(ctx, id, current) {
2497
2717
  o: void 0
2498
2718
  };
2499
2719
  }
2720
+ function generateEventNode2(ctx, id, current) {
2721
+ return {
2722
+ t: 37 /* Event */,
2723
+ i: id,
2724
+ s: serializeString(current.type),
2725
+ l: void 0,
2726
+ c: void 0,
2727
+ m: void 0,
2728
+ p: void 0,
2729
+ e: void 0,
2730
+ a: void 0,
2731
+ f: parseObject2(ctx, createEventOptions(current)),
2732
+ b: void 0,
2733
+ o: void 0
2734
+ };
2735
+ }
2736
+ function generateCustomEventNode2(ctx, id, current) {
2737
+ return {
2738
+ t: 38 /* CustomEvent */,
2739
+ i: id,
2740
+ s: serializeString(current.type),
2741
+ l: void 0,
2742
+ c: void 0,
2743
+ m: void 0,
2744
+ p: void 0,
2745
+ e: void 0,
2746
+ a: void 0,
2747
+ f: parseObject2(ctx, createCustomEventOptions(current)),
2748
+ b: void 0,
2749
+ o: void 0
2750
+ };
2751
+ }
2500
2752
  function parseObject2(ctx, current) {
2501
2753
  if (!current) {
2502
2754
  return NULL_NODE;
@@ -2511,39 +2763,17 @@ function parseObject2(ctx, current) {
2511
2763
  if (Array.isArray(current)) {
2512
2764
  return generateArrayNode2(ctx, id, current);
2513
2765
  }
2514
- switch (current.constructor) {
2766
+ const currentClass = current.constructor;
2767
+ switch (currentClass) {
2515
2768
  case Number:
2516
2769
  case Boolean:
2517
2770
  case String:
2518
2771
  case BigInt:
2519
- case Function:
2520
- case Symbol:
2521
2772
  return generateBoxedNode2(ctx, id, current);
2522
2773
  case Date:
2523
2774
  return createDateNode(id, current);
2524
2775
  case RegExp:
2525
2776
  return createRegExpNode(id, current);
2526
- case ArrayBuffer:
2527
- return createArrayBufferNode(id, current);
2528
- case Int8Array:
2529
- case Int16Array:
2530
- case Int32Array:
2531
- case Uint8Array:
2532
- case Uint16Array:
2533
- case Uint32Array:
2534
- case Uint8ClampedArray:
2535
- case Float32Array:
2536
- case Float64Array:
2537
- return createTypedArrayNode(ctx, id, current);
2538
- case BigInt64Array:
2539
- case BigUint64Array:
2540
- return createBigIntTypedArrayNode(ctx, id, current);
2541
- case DataView:
2542
- return createDataViewNode(ctx, id, current);
2543
- case Map:
2544
- return generateMapNode2(ctx, id, current);
2545
- case Set:
2546
- return generateSetNode2(ctx, id, current);
2547
2777
  case Object:
2548
2778
  return generateObjectNode2(
2549
2779
  ctx,
@@ -2558,11 +2788,6 @@ function parseObject2(ctx, current) {
2558
2788
  current,
2559
2789
  true
2560
2790
  );
2561
- case AggregateError:
2562
- if (ctx.features & 1 /* AggregateError */) {
2563
- return generateAggregateErrorNode2(ctx, id, current);
2564
- }
2565
- return generateErrorNode2(ctx, id, current);
2566
2791
  case Error:
2567
2792
  case EvalError:
2568
2793
  case RangeError:
@@ -2571,33 +2796,81 @@ function parseObject2(ctx, current) {
2571
2796
  case TypeError:
2572
2797
  case URIError:
2573
2798
  return generateErrorNode2(ctx, id, current);
2574
- case URL:
2575
- return createURLNode(ctx, id, current);
2576
- case URLSearchParams:
2577
- return createURLSearchParamsNode(ctx, id, current);
2578
- case Headers:
2579
- return generateHeadersNode2(ctx, id, current);
2580
- case FormData:
2581
- return generateFormDataNode2(ctx, id, current);
2582
2799
  default:
2583
2800
  break;
2584
2801
  }
2585
- if (current instanceof AggregateError) {
2586
- if (ctx.features & 1 /* AggregateError */) {
2587
- return generateAggregateErrorNode2(ctx, id, current);
2802
+ if (ctx.features & 2048 /* TypedArray */) {
2803
+ switch (currentClass) {
2804
+ case ArrayBuffer:
2805
+ return createArrayBufferNode(id, current);
2806
+ case Int8Array:
2807
+ case Int16Array:
2808
+ case Int32Array:
2809
+ case Uint8Array:
2810
+ case Uint16Array:
2811
+ case Uint32Array:
2812
+ case Uint8ClampedArray:
2813
+ case Float32Array:
2814
+ case Float64Array:
2815
+ return createTypedArrayNode(ctx, id, current);
2816
+ case DataView:
2817
+ return createDataViewNode(ctx, id, current);
2818
+ default:
2819
+ break;
2820
+ }
2821
+ }
2822
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
2823
+ switch (currentClass) {
2824
+ case BigInt64Array:
2825
+ case BigUint64Array:
2826
+ return createBigIntTypedArrayNode(ctx, id, current);
2827
+ default:
2828
+ break;
2588
2829
  }
2589
- return generateErrorNode2(ctx, id, current);
2830
+ }
2831
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
2832
+ return generateMapNode2(ctx, id, current);
2833
+ }
2834
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
2835
+ return generateSetNode2(ctx, id, current);
2836
+ }
2837
+ if (ctx.features & 8192 /* WebAPI */) {
2838
+ switch (currentClass) {
2839
+ case URL:
2840
+ return createURLNode(id, current);
2841
+ case URLSearchParams:
2842
+ return createURLSearchParamsNode(id, current);
2843
+ case Headers:
2844
+ return generateHeadersNode2(ctx, id, current);
2845
+ case FormData:
2846
+ return generateFormDataNode2(ctx, id, current);
2847
+ case Event:
2848
+ return generateEventNode2(ctx, id, current);
2849
+ case CustomEvent:
2850
+ return generateCustomEventNode2(ctx, id, current);
2851
+ case DOMException:
2852
+ return createDOMExceptionNode(id, current);
2853
+ default:
2854
+ break;
2855
+ }
2856
+ }
2857
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
2858
+ return generateAggregateErrorNode2(ctx, id, current);
2590
2859
  }
2591
2860
  if (current instanceof Error) {
2592
2861
  return generateErrorNode2(ctx, id, current);
2593
2862
  }
2594
- if (Symbol.iterator in current) {
2595
- return generateObjectNode2(ctx, id, current, !!current.constructor);
2863
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
2864
+ return generateObjectNode2(ctx, id, current, !!currentClass);
2596
2865
  }
2597
2866
  throw new UnsupportedTypeError(current);
2598
2867
  }
2599
2868
  function parseSync(ctx, current) {
2600
- switch (typeof current) {
2869
+ const t = typeof current;
2870
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
2871
+ return createBigIntNode(current);
2872
+ }
2873
+ switch (t) {
2601
2874
  case "boolean":
2602
2875
  return current ? TRUE_NODE : FALSE_NODE;
2603
2876
  case "undefined":
@@ -2606,8 +2879,6 @@ function parseSync(ctx, current) {
2606
2879
  return createStringNode(current);
2607
2880
  case "number":
2608
2881
  return createNumberNode(current);
2609
- case "bigint":
2610
- return createBigIntNode(ctx, current);
2611
2882
  case "object":
2612
2883
  return parseObject2(ctx, current);
2613
2884
  case "symbol":
@@ -2767,7 +3038,6 @@ function serializeArrayBuffer3(ctx, current) {
2767
3038
  return createArrayBufferNode(newID, current);
2768
3039
  }
2769
3040
  function createTypedArrayNode2(ctx, id, current) {
2770
- assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
2771
3041
  return {
2772
3042
  t: 15 /* TypedArray */,
2773
3043
  i: id,
@@ -2830,7 +3100,7 @@ function createSymbolNode2(ctx, current) {
2830
3100
  if (hasReferenceID(current)) {
2831
3101
  return createReferenceNode(newID, current);
2832
3102
  }
2833
- return createWKSymbolNode(ctx, newID, current);
3103
+ return createWKSymbolNode(newID, current);
2834
3104
  }
2835
3105
  function createFunctionNode2(ctx, current) {
2836
3106
  assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
@@ -2845,7 +3115,6 @@ function createFunctionNode2(ctx, current) {
2845
3115
 
2846
3116
  // src/core/cross/web-api.ts
2847
3117
  async function createBlobNode2(ctx, id, current) {
2848
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2849
3118
  return {
2850
3119
  t: 23 /* Blob */,
2851
3120
  i: id,
@@ -2862,7 +3131,6 @@ async function createBlobNode2(ctx, id, current) {
2862
3131
  };
2863
3132
  }
2864
3133
  async function createFileNode2(ctx, id, current) {
2865
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2866
3134
  return {
2867
3135
  t: 24 /* File */,
2868
3136
  i: id,
@@ -2919,7 +3187,6 @@ async function generateArrayNode3(ctx, id, current) {
2919
3187
  };
2920
3188
  }
2921
3189
  async function generateMapNode3(ctx, id, current) {
2922
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
2923
3190
  const len = current.size;
2924
3191
  const keyNodes = new Array(len);
2925
3192
  const valueNodes = new Array(len);
@@ -2958,7 +3225,6 @@ async function generateMapNode3(ctx, id, current) {
2958
3225
  };
2959
3226
  }
2960
3227
  async function generateSetNode3(ctx, id, current) {
2961
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
2962
3228
  const len = current.size;
2963
3229
  const nodes = new Array(len);
2964
3230
  const deferred = new Array(len);
@@ -3070,7 +3336,6 @@ async function generatePlainProperties3(ctx, properties) {
3070
3336
  };
3071
3337
  }
3072
3338
  async function generatePromiseNode2(ctx, id, current) {
3073
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
3074
3339
  const [status, result] = await promiseToResult(current);
3075
3340
  return {
3076
3341
  t: 12 /* Promise */,
@@ -3140,7 +3405,6 @@ async function generateErrorNode3(ctx, id, current) {
3140
3405
  };
3141
3406
  }
3142
3407
  async function generateHeadersNode3(ctx, id, current) {
3143
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3144
3408
  const items = {};
3145
3409
  current.forEach((value, key) => {
3146
3410
  items[key] = value;
@@ -3161,7 +3425,6 @@ async function generateHeadersNode3(ctx, id, current) {
3161
3425
  };
3162
3426
  }
3163
3427
  async function generateFormDataNode3(ctx, id, current) {
3164
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3165
3428
  const items = {};
3166
3429
  current.forEach((value, key) => {
3167
3430
  items[key] = value;
@@ -3197,6 +3460,76 @@ async function generateBoxedNode3(ctx, id, current) {
3197
3460
  o: void 0
3198
3461
  };
3199
3462
  }
3463
+ async function generateRequestNode2(ctx, id, current) {
3464
+ return {
3465
+ t: 35 /* Request */,
3466
+ i: id,
3467
+ s: serializeString(current.url),
3468
+ l: void 0,
3469
+ c: void 0,
3470
+ m: void 0,
3471
+ p: void 0,
3472
+ e: void 0,
3473
+ f: await parseObject3(
3474
+ ctx,
3475
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
3476
+ ),
3477
+ a: void 0,
3478
+ b: void 0,
3479
+ o: void 0
3480
+ };
3481
+ }
3482
+ async function generateResponseNode2(ctx, id, current) {
3483
+ return {
3484
+ t: 36 /* Response */,
3485
+ i: id,
3486
+ s: void 0,
3487
+ l: void 0,
3488
+ c: void 0,
3489
+ m: void 0,
3490
+ p: void 0,
3491
+ e: void 0,
3492
+ f: void 0,
3493
+ a: [
3494
+ current.body ? serializeArrayBuffer3(ctx, await current.clone().arrayBuffer()) : NULL_NODE,
3495
+ await parseObject3(ctx, createResponseOptions(current))
3496
+ ],
3497
+ b: void 0,
3498
+ o: void 0
3499
+ };
3500
+ }
3501
+ async function generateEventNode3(ctx, id, current) {
3502
+ return {
3503
+ t: 37 /* Event */,
3504
+ i: id,
3505
+ s: serializeString(current.type),
3506
+ l: void 0,
3507
+ c: void 0,
3508
+ m: void 0,
3509
+ p: void 0,
3510
+ e: void 0,
3511
+ a: void 0,
3512
+ f: await parseObject3(ctx, createEventOptions(current)),
3513
+ b: void 0,
3514
+ o: void 0
3515
+ };
3516
+ }
3517
+ async function generateCustomEventNode3(ctx, id, current) {
3518
+ return {
3519
+ t: 38 /* CustomEvent */,
3520
+ i: id,
3521
+ s: serializeString(current.type),
3522
+ l: void 0,
3523
+ c: void 0,
3524
+ m: void 0,
3525
+ p: void 0,
3526
+ e: void 0,
3527
+ a: void 0,
3528
+ f: await parseObject3(ctx, createCustomEventOptions(current)),
3529
+ b: void 0,
3530
+ o: void 0
3531
+ };
3532
+ }
3200
3533
  async function parseObject3(ctx, current) {
3201
3534
  if (!current) {
3202
3535
  return NULL_NODE;
@@ -3213,49 +3546,17 @@ async function parseObject3(ctx, current) {
3213
3546
  if (Array.isArray(current)) {
3214
3547
  return generateArrayNode3(ctx, id, current);
3215
3548
  }
3216
- switch (current.constructor) {
3549
+ const currentClass = current.constructor;
3550
+ switch (currentClass) {
3217
3551
  case Number:
3218
3552
  case Boolean:
3219
3553
  case String:
3220
3554
  case BigInt:
3221
- case Function:
3222
- case Symbol:
3223
3555
  return generateBoxedNode3(ctx, id, current);
3224
3556
  case Date:
3225
3557
  return createDateNode(id, current);
3226
3558
  case RegExp:
3227
3559
  return createRegExpNode(id, current);
3228
- case Promise:
3229
- return generatePromiseNode2(ctx, id, current);
3230
- case ArrayBuffer:
3231
- return createArrayBufferNode(id, current);
3232
- case Int8Array:
3233
- case Int16Array:
3234
- case Int32Array:
3235
- case Uint8Array:
3236
- case Uint16Array:
3237
- case Uint32Array:
3238
- case Uint8ClampedArray:
3239
- case Float32Array:
3240
- case Float64Array:
3241
- return createTypedArrayNode2(ctx, id, current);
3242
- case BigInt64Array:
3243
- case BigUint64Array:
3244
- return createBigIntTypedArrayNode2(ctx, id, current);
3245
- case DataView:
3246
- return createDataViewNode2(ctx, id, current);
3247
- case Map:
3248
- return generateMapNode3(
3249
- ctx,
3250
- id,
3251
- current
3252
- );
3253
- case Set:
3254
- return generateSetNode3(
3255
- ctx,
3256
- id,
3257
- current
3258
- );
3259
3560
  case Object:
3260
3561
  return generateObjectNode3(
3261
3562
  ctx,
@@ -3270,11 +3571,6 @@ async function parseObject3(ctx, current) {
3270
3571
  current,
3271
3572
  true
3272
3573
  );
3273
- case AggregateError:
3274
- if (ctx.features & 1 /* AggregateError */) {
3275
- return generateAggregateErrorNode3(ctx, id, current);
3276
- }
3277
- return generateErrorNode3(ctx, id, current);
3278
3574
  case Error:
3279
3575
  case EvalError:
3280
3576
  case RangeError:
@@ -3283,40 +3579,100 @@ async function parseObject3(ctx, current) {
3283
3579
  case TypeError:
3284
3580
  case URIError:
3285
3581
  return generateErrorNode3(ctx, id, current);
3286
- case URL:
3287
- return createURLNode(ctx, id, current);
3288
- case URLSearchParams:
3289
- return createURLSearchParamsNode(ctx, id, current);
3290
- case Blob:
3291
- return createBlobNode2(ctx, id, current);
3292
- case File:
3293
- return createFileNode2(ctx, id, current);
3294
- case Headers:
3295
- return generateHeadersNode3(ctx, id, current);
3296
- case FormData:
3297
- return generateFormDataNode3(ctx, id, current);
3298
3582
  default:
3299
3583
  break;
3300
3584
  }
3301
- if (current instanceof AggregateError) {
3302
- if (ctx.features & 1 /* AggregateError */) {
3303
- return generateAggregateErrorNode3(ctx, id, current);
3585
+ if (ctx.features & 2048 /* TypedArray */) {
3586
+ switch (currentClass) {
3587
+ case ArrayBuffer:
3588
+ return createArrayBufferNode(id, current);
3589
+ case Int8Array:
3590
+ case Int16Array:
3591
+ case Int32Array:
3592
+ case Uint8Array:
3593
+ case Uint16Array:
3594
+ case Uint32Array:
3595
+ case Uint8ClampedArray:
3596
+ case Float32Array:
3597
+ case Float64Array:
3598
+ return createTypedArrayNode2(ctx, id, current);
3599
+ case DataView:
3600
+ return createDataViewNode2(ctx, id, current);
3601
+ default:
3602
+ break;
3304
3603
  }
3305
- return generateErrorNode3(ctx, id, current);
3306
3604
  }
3307
- if (current instanceof Error) {
3308
- return generateErrorNode3(ctx, id, current);
3605
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
3606
+ switch (currentClass) {
3607
+ case BigInt64Array:
3608
+ case BigUint64Array:
3609
+ return createBigIntTypedArrayNode2(ctx, id, current);
3610
+ default:
3611
+ break;
3612
+ }
3613
+ }
3614
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
3615
+ return generateMapNode3(
3616
+ ctx,
3617
+ id,
3618
+ current
3619
+ );
3620
+ }
3621
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
3622
+ return generateSetNode3(
3623
+ ctx,
3624
+ id,
3625
+ current
3626
+ );
3627
+ }
3628
+ if (ctx.features & 8192 /* WebAPI */) {
3629
+ switch (currentClass) {
3630
+ case URL:
3631
+ return createURLNode(id, current);
3632
+ case URLSearchParams:
3633
+ return createURLSearchParamsNode(id, current);
3634
+ case Blob:
3635
+ return createBlobNode2(ctx, id, current);
3636
+ case File:
3637
+ return createFileNode2(ctx, id, current);
3638
+ case Headers:
3639
+ return generateHeadersNode3(ctx, id, current);
3640
+ case FormData:
3641
+ return generateFormDataNode3(ctx, id, current);
3642
+ case Request:
3643
+ return generateRequestNode2(ctx, id, current);
3644
+ case Response:
3645
+ return generateResponseNode2(ctx, id, current);
3646
+ case Event:
3647
+ return generateEventNode3(ctx, id, current);
3648
+ case CustomEvent:
3649
+ return generateCustomEventNode3(ctx, id, current);
3650
+ case DOMException:
3651
+ return createDOMExceptionNode(id, current);
3652
+ default:
3653
+ break;
3654
+ }
3655
+ }
3656
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
3657
+ return generateAggregateErrorNode3(ctx, id, current);
3309
3658
  }
3310
- if (current instanceof Promise) {
3659
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
3311
3660
  return generatePromiseNode2(ctx, id, current);
3312
3661
  }
3313
- if (Symbol.iterator in current) {
3314
- return generateObjectNode3(ctx, id, current, !!current.constructor);
3662
+ if (current instanceof Error) {
3663
+ return generateErrorNode3(ctx, id, current);
3664
+ }
3665
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
3666
+ return generateObjectNode3(ctx, id, current, !!currentClass);
3315
3667
  }
3316
3668
  throw new UnsupportedTypeError(current);
3317
3669
  }
3318
3670
  async function crossParseAsync(ctx, current) {
3319
- switch (typeof current) {
3671
+ const t = typeof current;
3672
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
3673
+ return createBigIntNode(current);
3674
+ }
3675
+ switch (t) {
3320
3676
  case "boolean":
3321
3677
  return current ? TRUE_NODE : FALSE_NODE;
3322
3678
  case "undefined":
@@ -3325,8 +3681,6 @@ async function crossParseAsync(ctx, current) {
3325
3681
  return createStringNode(current);
3326
3682
  case "number":
3327
3683
  return createNumberNode(current);
3328
- case "bigint":
3329
- return createBigIntNode(ctx, current);
3330
3684
  case "object":
3331
3685
  return parseObject3(ctx, current);
3332
3686
  case "symbol":
@@ -3806,6 +4160,33 @@ function serializeReadableStreamError(ctx, node) {
3806
4160
  function serializeReadableStreamConstructor(node) {
3807
4161
  return assignIndexedValue3(node.i, GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_CONSTRUCTOR + "()");
3808
4162
  }
4163
+ function serializeRequest2(ctx, node) {
4164
+ return assignIndexedValue3(node.i, 'new Request("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")");
4165
+ }
4166
+ function serializeResponse2(ctx, node) {
4167
+ return assignIndexedValue3(
4168
+ node.i,
4169
+ "new Response(" + crossSerializeTree(ctx, node.a[0]) + "," + crossSerializeTree(ctx, node.a[1]) + ")"
4170
+ );
4171
+ }
4172
+ function serializeEvent2(ctx, node) {
4173
+ return assignIndexedValue3(
4174
+ node.i,
4175
+ 'new Event("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")"
4176
+ );
4177
+ }
4178
+ function serializeCustomEvent2(ctx, node) {
4179
+ return assignIndexedValue3(
4180
+ node.i,
4181
+ 'new CustomEvent("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")"
4182
+ );
4183
+ }
4184
+ function serializeDOMException2(node) {
4185
+ return assignIndexedValue3(
4186
+ node.i,
4187
+ 'new DOMException("' + node.s + '","' + node.c + '")'
4188
+ );
4189
+ }
3809
4190
  function crossSerializeTree(ctx, node) {
3810
4191
  switch (node.t) {
3811
4192
  case 0 /* Number */:
@@ -3877,6 +4258,16 @@ function crossSerializeTree(ctx, node) {
3877
4258
  return serializeReadableStreamEnqueue(ctx, node);
3878
4259
  case 34 /* ReadableStreamError */:
3879
4260
  return serializeReadableStreamError(ctx, node);
4261
+ case 35 /* Request */:
4262
+ return serializeRequest2(ctx, node);
4263
+ case 36 /* Response */:
4264
+ return serializeResponse2(ctx, node);
4265
+ case 37 /* Event */:
4266
+ return serializeEvent2(ctx, node);
4267
+ case 38 /* CustomEvent */:
4268
+ return serializeCustomEvent2(ctx, node);
4269
+ case 39 /* DOMException */:
4270
+ return serializeDOMException2(node);
3880
4271
  default:
3881
4272
  throw new Error("invariant");
3882
4273
  }
@@ -3922,7 +4313,6 @@ function generateArrayNode4(ctx, id, current) {
3922
4313
  };
3923
4314
  }
3924
4315
  function generateMapNode4(ctx, id, current) {
3925
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
3926
4316
  const len = current.size;
3927
4317
  const keyNodes = new Array(len);
3928
4318
  const valueNodes = new Array(len);
@@ -3961,7 +4351,6 @@ function generateMapNode4(ctx, id, current) {
3961
4351
  };
3962
4352
  }
3963
4353
  function generateSetNode4(ctx, id, current) {
3964
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
3965
4354
  const len = current.size;
3966
4355
  const nodes = new Array(len);
3967
4356
  const deferred = new Array(len);
@@ -4073,7 +4462,6 @@ function generatePlainProperties4(ctx, properties) {
4073
4462
  };
4074
4463
  }
4075
4464
  function generatePromiseNode3(ctx, id, current) {
4076
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
4077
4465
  current.then(
4078
4466
  (data) => {
4079
4467
  if (ctx.alive) {
@@ -4183,7 +4571,6 @@ function generateErrorNode4(ctx, id, current) {
4183
4571
  };
4184
4572
  }
4185
4573
  function generateHeadersNode4(ctx, id, current) {
4186
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4187
4574
  const items = {};
4188
4575
  current.forEach((value, key) => {
4189
4576
  items[key] = value;
@@ -4204,7 +4591,6 @@ function generateHeadersNode4(ctx, id, current) {
4204
4591
  };
4205
4592
  }
4206
4593
  function generateFormDataNode4(ctx, id, current) {
4207
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4208
4594
  const items = {};
4209
4595
  current.forEach((value, key) => {
4210
4596
  items[key] = value;
@@ -4241,7 +4627,6 @@ function generateBoxedNode4(ctx, id, current) {
4241
4627
  };
4242
4628
  }
4243
4629
  function generateReadableStreamNode(ctx, id, current) {
4244
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4245
4630
  const reader = current.getReader();
4246
4631
  pushPendingState(ctx);
4247
4632
  function push() {
@@ -4320,6 +4705,76 @@ function generateReadableStreamNode(ctx, id, current) {
4320
4705
  o: void 0
4321
4706
  };
4322
4707
  }
4708
+ function generateRequestNode3(ctx, id, current) {
4709
+ return {
4710
+ t: 35 /* Request */,
4711
+ i: id,
4712
+ s: serializeString(current.url),
4713
+ l: void 0,
4714
+ c: void 0,
4715
+ m: void 0,
4716
+ p: void 0,
4717
+ e: void 0,
4718
+ f: parseObject4(
4719
+ ctx,
4720
+ createRequestOptions(current, current.clone().body)
4721
+ ),
4722
+ a: void 0,
4723
+ b: void 0,
4724
+ o: void 0
4725
+ };
4726
+ }
4727
+ function generateResponseNode3(ctx, id, current) {
4728
+ return {
4729
+ t: 36 /* Response */,
4730
+ i: id,
4731
+ s: void 0,
4732
+ l: void 0,
4733
+ c: void 0,
4734
+ m: void 0,
4735
+ p: void 0,
4736
+ e: void 0,
4737
+ f: void 0,
4738
+ a: [
4739
+ current.body ? parseObject4(ctx, current.clone().body) : NULL_NODE,
4740
+ parseObject4(ctx, createResponseOptions(current))
4741
+ ],
4742
+ b: void 0,
4743
+ o: void 0
4744
+ };
4745
+ }
4746
+ function generateEventNode4(ctx, id, current) {
4747
+ return {
4748
+ t: 37 /* Event */,
4749
+ i: id,
4750
+ s: serializeString(current.type),
4751
+ l: void 0,
4752
+ c: void 0,
4753
+ m: void 0,
4754
+ p: void 0,
4755
+ e: void 0,
4756
+ a: void 0,
4757
+ f: parseObject4(ctx, createEventOptions(current)),
4758
+ b: void 0,
4759
+ o: void 0
4760
+ };
4761
+ }
4762
+ function generateCustomEventNode4(ctx, id, current) {
4763
+ return {
4764
+ t: 38 /* CustomEvent */,
4765
+ i: id,
4766
+ s: serializeString(current.type),
4767
+ l: void 0,
4768
+ c: void 0,
4769
+ m: void 0,
4770
+ p: void 0,
4771
+ e: void 0,
4772
+ a: void 0,
4773
+ f: parseObject4(ctx, createCustomEventOptions(current)),
4774
+ b: void 0,
4775
+ o: void 0
4776
+ };
4777
+ }
4323
4778
  function parseObject4(ctx, current) {
4324
4779
  if (!current) {
4325
4780
  return NULL_NODE;
@@ -4336,7 +4791,8 @@ function parseObject4(ctx, current) {
4336
4791
  if (Array.isArray(current)) {
4337
4792
  return generateArrayNode4(ctx, id, current);
4338
4793
  }
4339
- switch (current.constructor) {
4794
+ const currentClass = current.constructor;
4795
+ switch (currentClass) {
4340
4796
  case Number:
4341
4797
  case Boolean:
4342
4798
  case String:
@@ -4348,37 +4804,6 @@ function parseObject4(ctx, current) {
4348
4804
  return createDateNode(id, current);
4349
4805
  case RegExp:
4350
4806
  return createRegExpNode(id, current);
4351
- case Promise:
4352
- return generatePromiseNode3(ctx, id, current);
4353
- case ArrayBuffer:
4354
- return createArrayBufferNode(id, current);
4355
- case Int8Array:
4356
- case Int16Array:
4357
- case Int32Array:
4358
- case Uint8Array:
4359
- case Uint16Array:
4360
- case Uint32Array:
4361
- case Uint8ClampedArray:
4362
- case Float32Array:
4363
- case Float64Array:
4364
- return createTypedArrayNode2(ctx, id, current);
4365
- case BigInt64Array:
4366
- case BigUint64Array:
4367
- return createBigIntTypedArrayNode2(ctx, id, current);
4368
- case DataView:
4369
- return createDataViewNode2(ctx, id, current);
4370
- case Map:
4371
- return generateMapNode4(
4372
- ctx,
4373
- id,
4374
- current
4375
- );
4376
- case Set:
4377
- return generateSetNode4(
4378
- ctx,
4379
- id,
4380
- current
4381
- );
4382
4807
  case Object:
4383
4808
  return generateObjectNode4(
4384
4809
  ctx,
@@ -4393,11 +4818,6 @@ function parseObject4(ctx, current) {
4393
4818
  current,
4394
4819
  true
4395
4820
  );
4396
- case AggregateError:
4397
- if (ctx.features & 1 /* AggregateError */) {
4398
- return generateAggregateErrorNode4(ctx, id, current);
4399
- }
4400
- return generateErrorNode4(ctx, id, current);
4401
4821
  case Error:
4402
4822
  case EvalError:
4403
4823
  case RangeError:
@@ -4406,38 +4826,90 @@ function parseObject4(ctx, current) {
4406
4826
  case TypeError:
4407
4827
  case URIError:
4408
4828
  return generateErrorNode4(ctx, id, current);
4409
- case URL:
4410
- return createURLNode(ctx, id, current);
4411
- case URLSearchParams:
4412
- return createURLSearchParamsNode(ctx, id, current);
4413
- case Headers:
4414
- return generateHeadersNode4(ctx, id, current);
4415
- case FormData:
4416
- return generateFormDataNode4(ctx, id, current);
4417
- case ReadableStream:
4418
- return generateReadableStreamNode(ctx, id, current);
4419
4829
  default:
4420
4830
  break;
4421
4831
  }
4422
- if (current instanceof AggregateError) {
4423
- if (ctx.features & 1 /* AggregateError */) {
4424
- return generateAggregateErrorNode4(ctx, id, current);
4832
+ if (ctx.features & 2048 /* TypedArray */) {
4833
+ switch (currentClass) {
4834
+ case ArrayBuffer:
4835
+ return createArrayBufferNode(id, current);
4836
+ case Int8Array:
4837
+ case Int16Array:
4838
+ case Int32Array:
4839
+ case Uint8Array:
4840
+ case Uint16Array:
4841
+ case Uint32Array:
4842
+ case Uint8ClampedArray:
4843
+ case Float32Array:
4844
+ case Float64Array:
4845
+ return createTypedArrayNode2(ctx, id, current);
4846
+ case DataView:
4847
+ return createDataViewNode2(ctx, id, current);
4848
+ default:
4849
+ break;
4425
4850
  }
4426
- return generateErrorNode4(ctx, id, current);
4427
4851
  }
4428
- if (current instanceof Error) {
4429
- return generateErrorNode4(ctx, id, current);
4852
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
4853
+ switch (currentClass) {
4854
+ case BigInt64Array:
4855
+ case BigUint64Array:
4856
+ return createBigIntTypedArrayNode2(ctx, id, current);
4857
+ default:
4858
+ break;
4859
+ }
4430
4860
  }
4431
- if (current instanceof Promise) {
4861
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
4862
+ return generateMapNode4(ctx, id, current);
4863
+ }
4864
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
4865
+ return generateSetNode4(ctx, id, current);
4866
+ }
4867
+ if (ctx.features & 8192 /* WebAPI */) {
4868
+ switch (currentClass) {
4869
+ case URL:
4870
+ return createURLNode(id, current);
4871
+ case URLSearchParams:
4872
+ return createURLSearchParamsNode(id, current);
4873
+ case Headers:
4874
+ return generateHeadersNode4(ctx, id, current);
4875
+ case FormData:
4876
+ return generateFormDataNode4(ctx, id, current);
4877
+ case ReadableStream:
4878
+ return generateReadableStreamNode(ctx, id, current);
4879
+ case Request:
4880
+ return generateRequestNode3(ctx, id, current);
4881
+ case Response:
4882
+ return generateResponseNode3(ctx, id, current);
4883
+ case Event:
4884
+ return generateEventNode4(ctx, id, current);
4885
+ case CustomEvent:
4886
+ return generateCustomEventNode4(ctx, id, current);
4887
+ case DOMException:
4888
+ return createDOMExceptionNode(id, current);
4889
+ default:
4890
+ break;
4891
+ }
4892
+ }
4893
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
4894
+ return generateAggregateErrorNode4(ctx, id, current);
4895
+ }
4896
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
4432
4897
  return generatePromiseNode3(ctx, id, current);
4433
4898
  }
4434
- if (Symbol.iterator in current) {
4435
- return generateObjectNode4(ctx, id, current, !!current.constructor);
4899
+ if (current instanceof Error) {
4900
+ return generateErrorNode4(ctx, id, current);
4901
+ }
4902
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
4903
+ return generateObjectNode4(ctx, id, current, !!currentClass);
4436
4904
  }
4437
4905
  throw new UnsupportedTypeError(current);
4438
4906
  }
4439
4907
  function crossParseStream(ctx, current) {
4440
- switch (typeof current) {
4908
+ const t = typeof current;
4909
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
4910
+ return createBigIntNode(current);
4911
+ }
4912
+ switch (t) {
4441
4913
  case "boolean":
4442
4914
  return current ? TRUE_NODE : FALSE_NODE;
4443
4915
  case "undefined":
@@ -4446,8 +4918,6 @@ function crossParseStream(ctx, current) {
4446
4918
  return createStringNode(current);
4447
4919
  case "number":
4448
4920
  return createNumberNode(current);
4449
- case "bigint":
4450
- return createBigIntNode(ctx, current);
4451
4921
  case "object":
4452
4922
  return parseObject4(ctx, current);
4453
4923
  case "symbol":
@@ -4499,7 +4969,6 @@ function generateArrayNode5(ctx, id, current) {
4499
4969
  };
4500
4970
  }
4501
4971
  function generateMapNode5(ctx, id, current) {
4502
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
4503
4972
  const len = current.size;
4504
4973
  const keyNodes = new Array(len);
4505
4974
  const valueNodes = new Array(len);
@@ -4538,7 +5007,6 @@ function generateMapNode5(ctx, id, current) {
4538
5007
  };
4539
5008
  }
4540
5009
  function generateSetNode5(ctx, id, current) {
4541
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
4542
5010
  const len = current.size;
4543
5011
  const nodes = new Array(len);
4544
5012
  const deferred = new Array(len);
@@ -4698,7 +5166,6 @@ function generateErrorNode5(ctx, id, current) {
4698
5166
  };
4699
5167
  }
4700
5168
  function generateHeadersNode5(ctx, id, current) {
4701
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4702
5169
  const items = {};
4703
5170
  current.forEach((value, key) => {
4704
5171
  items[key] = value;
@@ -4719,7 +5186,6 @@ function generateHeadersNode5(ctx, id, current) {
4719
5186
  };
4720
5187
  }
4721
5188
  function generateFormDataNode5(ctx, id, current) {
4722
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4723
5189
  const items = {};
4724
5190
  current.forEach((value, key) => {
4725
5191
  items[key] = value;
@@ -4755,6 +5221,38 @@ function generateBoxedNode5(ctx, id, current) {
4755
5221
  o: void 0
4756
5222
  };
4757
5223
  }
5224
+ function generateEventNode5(ctx, id, current) {
5225
+ return {
5226
+ t: 37 /* Event */,
5227
+ i: id,
5228
+ s: serializeString(current.type),
5229
+ l: void 0,
5230
+ c: void 0,
5231
+ m: void 0,
5232
+ p: void 0,
5233
+ e: void 0,
5234
+ a: void 0,
5235
+ f: parseObject5(ctx, createEventOptions(current)),
5236
+ b: void 0,
5237
+ o: void 0
5238
+ };
5239
+ }
5240
+ function generateCustomEventNode5(ctx, id, current) {
5241
+ return {
5242
+ t: 38 /* CustomEvent */,
5243
+ i: id,
5244
+ s: serializeString(current.type),
5245
+ l: void 0,
5246
+ c: void 0,
5247
+ m: void 0,
5248
+ p: void 0,
5249
+ e: void 0,
5250
+ a: void 0,
5251
+ f: parseObject5(ctx, createCustomEventOptions(current)),
5252
+ b: void 0,
5253
+ o: void 0
5254
+ };
5255
+ }
4758
5256
  function parseObject5(ctx, current) {
4759
5257
  if (!current) {
4760
5258
  return NULL_NODE;
@@ -4771,39 +5269,17 @@ function parseObject5(ctx, current) {
4771
5269
  if (Array.isArray(current)) {
4772
5270
  return generateArrayNode5(ctx, id, current);
4773
5271
  }
4774
- switch (current.constructor) {
5272
+ const currentClass = current.constructor;
5273
+ switch (currentClass) {
4775
5274
  case Number:
4776
5275
  case Boolean:
4777
5276
  case String:
4778
5277
  case BigInt:
4779
- case Function:
4780
- case Symbol:
4781
5278
  return generateBoxedNode5(ctx, id, current);
4782
5279
  case Date:
4783
5280
  return createDateNode(id, current);
4784
5281
  case RegExp:
4785
5282
  return createRegExpNode(id, current);
4786
- case ArrayBuffer:
4787
- return createArrayBufferNode(id, current);
4788
- case Int8Array:
4789
- case Int16Array:
4790
- case Int32Array:
4791
- case Uint8Array:
4792
- case Uint16Array:
4793
- case Uint32Array:
4794
- case Uint8ClampedArray:
4795
- case Float32Array:
4796
- case Float64Array:
4797
- return createTypedArrayNode2(ctx, id, current);
4798
- case BigInt64Array:
4799
- case BigUint64Array:
4800
- return createBigIntTypedArrayNode2(ctx, id, current);
4801
- case DataView:
4802
- return createDataViewNode2(ctx, id, current);
4803
- case Map:
4804
- return generateMapNode5(ctx, id, current);
4805
- case Set:
4806
- return generateSetNode5(ctx, id, current);
4807
5283
  case Object:
4808
5284
  return generateObjectNode5(
4809
5285
  ctx,
@@ -4818,11 +5294,6 @@ function parseObject5(ctx, current) {
4818
5294
  current,
4819
5295
  true
4820
5296
  );
4821
- case AggregateError:
4822
- if (ctx.features & 1 /* AggregateError */) {
4823
- return generateAggregateErrorNode5(ctx, id, current);
4824
- }
4825
- return generateErrorNode5(ctx, id, current);
4826
5297
  case Error:
4827
5298
  case EvalError:
4828
5299
  case RangeError:
@@ -4831,33 +5302,81 @@ function parseObject5(ctx, current) {
4831
5302
  case TypeError:
4832
5303
  case URIError:
4833
5304
  return generateErrorNode5(ctx, id, current);
4834
- case URL:
4835
- return createURLNode(ctx, id, current);
4836
- case URLSearchParams:
4837
- return createURLSearchParamsNode(ctx, id, current);
4838
- case Headers:
4839
- return generateHeadersNode5(ctx, id, current);
4840
- case FormData:
4841
- return generateFormDataNode5(ctx, id, current);
4842
5305
  default:
4843
5306
  break;
4844
5307
  }
4845
- if (current instanceof AggregateError) {
4846
- if (ctx.features & 1 /* AggregateError */) {
4847
- return generateAggregateErrorNode5(ctx, id, current);
5308
+ if (ctx.features & 2048 /* TypedArray */) {
5309
+ switch (currentClass) {
5310
+ case ArrayBuffer:
5311
+ return createArrayBufferNode(id, current);
5312
+ case Int8Array:
5313
+ case Int16Array:
5314
+ case Int32Array:
5315
+ case Uint8Array:
5316
+ case Uint16Array:
5317
+ case Uint32Array:
5318
+ case Uint8ClampedArray:
5319
+ case Float32Array:
5320
+ case Float64Array:
5321
+ return createTypedArrayNode2(ctx, id, current);
5322
+ case DataView:
5323
+ return createDataViewNode2(ctx, id, current);
5324
+ default:
5325
+ break;
4848
5326
  }
4849
- return generateErrorNode5(ctx, id, current);
5327
+ }
5328
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
5329
+ switch (currentClass) {
5330
+ case BigInt64Array:
5331
+ case BigUint64Array:
5332
+ return createBigIntTypedArrayNode2(ctx, id, current);
5333
+ default:
5334
+ break;
5335
+ }
5336
+ }
5337
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
5338
+ return generateMapNode5(ctx, id, current);
5339
+ }
5340
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
5341
+ return generateSetNode5(ctx, id, current);
5342
+ }
5343
+ if (ctx.features & 8192 /* WebAPI */) {
5344
+ switch (currentClass) {
5345
+ case URL:
5346
+ return createURLNode(id, current);
5347
+ case URLSearchParams:
5348
+ return createURLSearchParamsNode(id, current);
5349
+ case Headers:
5350
+ return generateHeadersNode5(ctx, id, current);
5351
+ case FormData:
5352
+ return generateFormDataNode5(ctx, id, current);
5353
+ case Event:
5354
+ return generateEventNode5(ctx, id, current);
5355
+ case CustomEvent:
5356
+ return generateCustomEventNode5(ctx, id, current);
5357
+ case DOMException:
5358
+ return createDOMExceptionNode(id, current);
5359
+ default:
5360
+ break;
5361
+ }
5362
+ }
5363
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
5364
+ return generateAggregateErrorNode5(ctx, id, current);
4850
5365
  }
4851
5366
  if (current instanceof Error) {
4852
5367
  return generateErrorNode5(ctx, id, current);
4853
5368
  }
4854
- if (Symbol.iterator in current) {
4855
- return generateObjectNode5(ctx, id, current, !!current.constructor);
5369
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
5370
+ return generateObjectNode5(ctx, id, current, !!currentClass);
4856
5371
  }
4857
5372
  throw new UnsupportedTypeError(current);
4858
5373
  }
4859
5374
  function crossParseSync(ctx, current) {
4860
- switch (typeof current) {
5375
+ const t = typeof current;
5376
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
5377
+ return createBigIntNode(current);
5378
+ }
5379
+ switch (t) {
4861
5380
  case "boolean":
4862
5381
  return current ? TRUE_NODE : FALSE_NODE;
4863
5382
  case "undefined":
@@ -4866,8 +5385,6 @@ function crossParseSync(ctx, current) {
4866
5385
  return createStringNode(current);
4867
5386
  case "number":
4868
5387
  return createNumberNode(current);
4869
- case "bigint":
4870
- return createBigIntNode(ctx, current);
4871
5388
  case "object":
4872
5389
  return parseObject5(ctx, current);
4873
5390
  case "symbol":