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.
@@ -63,6 +63,7 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
63
63
  return Feature2;
64
64
  })(Feature || {});
65
65
  var ALL_ENABLED = 16383;
66
+ var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
66
67
 
67
68
  // src/core/constants.ts
68
69
  var SYMBOL_STRING = {
@@ -155,13 +156,6 @@ function deserializeConstant(node) {
155
156
  }
156
157
  }
157
158
 
158
- // src/core/assert.ts
159
- function assert(cond, error) {
160
- if (!cond) {
161
- throw error;
162
- }
163
- }
164
-
165
159
  // src/core/get-identifier.ts
166
160
  var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
167
161
  var REF_START_CHARS_LEN = REF_START_CHARS.length;
@@ -320,6 +314,13 @@ var INFINITY_NODE = createConstantNode(5 /* Infinity */);
320
314
  var NEG_INFINITY_NODE = createConstantNode(6 /* NegativeInfinity */);
321
315
  var NAN_NODE = createConstantNode(7 /* NaN */);
322
316
 
317
+ // src/core/assert.ts
318
+ function assert(cond, error) {
319
+ if (!cond) {
320
+ throw error;
321
+ }
322
+ }
323
+
323
324
  // src/core/keys.ts
324
325
  var REFERENCES_KEY = "__SEROVAL_REFS__";
325
326
  var GLOBAL_CONTEXT_API = "_$";
@@ -438,8 +439,7 @@ function createStringNode(value) {
438
439
  o: void 0
439
440
  };
440
441
  }
441
- function createBigIntNode(ctx, current) {
442
- assert(ctx.features & 8 /* BigInt */, new UnsupportedTypeError(current));
442
+ function createBigIntNode(current) {
443
443
  return {
444
444
  t: 3 /* BigInt */,
445
445
  i: void 0,
@@ -525,8 +525,7 @@ function createArrayBufferNode(id, current) {
525
525
  o: void 0
526
526
  };
527
527
  }
528
- function createWKSymbolNode(ctx, id, current) {
529
- assert(ctx.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
528
+ function createWKSymbolNode(id, current) {
530
529
  assert(current in INV_SYMBOL_REF, new Error("Only well-known symbols are supported."));
531
530
  return {
532
531
  t: 17 /* WKSymbol */,
@@ -569,7 +568,6 @@ function serializeArrayBuffer(ctx, current) {
569
568
  return createArrayBufferNode(id, current);
570
569
  }
571
570
  function createTypedArrayNode(ctx, id, current) {
572
- assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
573
571
  return {
574
572
  t: 15 /* TypedArray */,
575
573
  i: id,
@@ -585,12 +583,7 @@ function createTypedArrayNode(ctx, id, current) {
585
583
  o: void 0
586
584
  };
587
585
  }
588
- var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
589
586
  function createBigIntTypedArrayNode(ctx, id, current) {
590
- assert(
591
- (ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
592
- new UnsupportedTypeError(current)
593
- );
594
587
  return {
595
588
  t: 16 /* BigIntTypedArray */,
596
589
  i: id,
@@ -630,7 +623,7 @@ function createSymbolNode(ctx, current) {
630
623
  if (hasReferenceID(current)) {
631
624
  return createReferenceNode(id, current);
632
625
  }
633
- return createWKSymbolNode(ctx, id, current);
626
+ return createWKSymbolNode(id, current);
634
627
  }
635
628
  function createFunctionNode(ctx, current) {
636
629
  assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
@@ -782,7 +775,6 @@ function getObjectFlag(obj) {
782
775
 
783
776
  // src/core/tree/web-api.ts
784
777
  async function createBlobNode(ctx, id, current) {
785
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
786
778
  return {
787
779
  t: 23 /* Blob */,
788
780
  i: id,
@@ -799,7 +791,6 @@ async function createBlobNode(ctx, id, current) {
799
791
  };
800
792
  }
801
793
  async function createFileNode(ctx, id, current) {
802
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
803
794
  return {
804
795
  t: 24 /* File */,
805
796
  i: id,
@@ -817,8 +808,7 @@ async function createFileNode(ctx, id, current) {
817
808
  }
818
809
 
819
810
  // src/core/web-api.ts
820
- function createURLNode(ctx, id, current) {
821
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
811
+ function createURLNode(id, current) {
822
812
  return {
823
813
  t: 18 /* URL */,
824
814
  i: id,
@@ -834,8 +824,7 @@ function createURLNode(ctx, id, current) {
834
824
  o: void 0
835
825
  };
836
826
  }
837
- function createURLSearchParamsNode(ctx, id, current) {
838
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
827
+ function createURLSearchParamsNode(id, current) {
839
828
  return {
840
829
  t: 19 /* URLSearchParams */,
841
830
  i: id,
@@ -851,6 +840,22 @@ function createURLSearchParamsNode(ctx, id, current) {
851
840
  o: void 0
852
841
  };
853
842
  }
843
+ function createDOMExceptionNode(id, current) {
844
+ return {
845
+ t: 39 /* DOMException */,
846
+ i: id,
847
+ s: serializeString(current.message),
848
+ l: void 0,
849
+ c: serializeString(current.name),
850
+ m: void 0,
851
+ p: void 0,
852
+ e: void 0,
853
+ a: void 0,
854
+ f: void 0,
855
+ b: void 0,
856
+ o: void 0
857
+ };
858
+ }
854
859
 
855
860
  // src/core/promise-to-result.ts
856
861
  async function promiseToResult(current) {
@@ -861,6 +866,45 @@ async function promiseToResult(current) {
861
866
  }
862
867
  }
863
868
 
869
+ // src/core/constructors.ts
870
+ function createRequestOptions(current, body) {
871
+ return {
872
+ body,
873
+ cache: current.cache,
874
+ credentials: current.credentials,
875
+ headers: current.headers,
876
+ integrity: current.integrity,
877
+ keepalive: current.keepalive,
878
+ method: current.method,
879
+ mode: current.mode,
880
+ redirect: current.redirect,
881
+ referrer: current.referrer,
882
+ referrerPolicy: current.referrerPolicy
883
+ };
884
+ }
885
+ function createResponseOptions(current) {
886
+ return {
887
+ headers: current.headers,
888
+ status: current.status,
889
+ statusText: current.statusText
890
+ };
891
+ }
892
+ function createEventOptions(current) {
893
+ return {
894
+ bubbles: current.bubbles,
895
+ cancelable: current.cancelable,
896
+ composed: current.composed
897
+ };
898
+ }
899
+ function createCustomEventOptions(current) {
900
+ return {
901
+ detail: current.detail,
902
+ bubbles: current.bubbles,
903
+ cancelable: current.cancelable,
904
+ composed: current.composed
905
+ };
906
+ }
907
+
864
908
  // src/core/tree/async.ts
865
909
  async function generateNodeList(ctx, current) {
866
910
  const size = current.length;
@@ -901,7 +945,6 @@ async function generateArrayNode(ctx, id, current) {
901
945
  };
902
946
  }
903
947
  async function generateMapNode(ctx, id, current) {
904
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
905
948
  const len = current.size;
906
949
  const keyNodes = new Array(len);
907
950
  const valueNodes = new Array(len);
@@ -940,7 +983,6 @@ async function generateMapNode(ctx, id, current) {
940
983
  };
941
984
  }
942
985
  async function generateSetNode(ctx, id, current) {
943
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
944
986
  const len = current.size;
945
987
  const nodes = new Array(len);
946
988
  const deferred = new Array(len);
@@ -1052,7 +1094,6 @@ async function generatePlainProperties(ctx, properties) {
1052
1094
  };
1053
1095
  }
1054
1096
  async function generatePromiseNode(ctx, id, current) {
1055
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
1056
1097
  const [status, result] = await promiseToResult(current);
1057
1098
  return {
1058
1099
  t: 12 /* Promise */,
@@ -1122,7 +1163,6 @@ async function generateErrorNode(ctx, id, current) {
1122
1163
  };
1123
1164
  }
1124
1165
  async function generateHeadersNode(ctx, id, current) {
1125
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
1126
1166
  const items = {};
1127
1167
  current.forEach((value, key) => {
1128
1168
  items[key] = value;
@@ -1143,7 +1183,6 @@ async function generateHeadersNode(ctx, id, current) {
1143
1183
  };
1144
1184
  }
1145
1185
  async function generateFormDataNode(ctx, id, current) {
1146
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
1147
1186
  const items = {};
1148
1187
  current.forEach((value, key) => {
1149
1188
  items[key] = value;
@@ -1179,6 +1218,76 @@ async function generateBoxedNode(ctx, id, current) {
1179
1218
  o: void 0
1180
1219
  };
1181
1220
  }
1221
+ async function generateRequestNode(ctx, id, current) {
1222
+ return {
1223
+ t: 35 /* Request */,
1224
+ i: id,
1225
+ s: serializeString(current.url),
1226
+ l: void 0,
1227
+ c: void 0,
1228
+ m: void 0,
1229
+ p: void 0,
1230
+ e: void 0,
1231
+ f: await parseObject(
1232
+ ctx,
1233
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
1234
+ ),
1235
+ a: void 0,
1236
+ b: void 0,
1237
+ o: void 0
1238
+ };
1239
+ }
1240
+ async function generateResponseNode(ctx, id, current) {
1241
+ return {
1242
+ t: 36 /* Response */,
1243
+ i: id,
1244
+ s: void 0,
1245
+ l: void 0,
1246
+ c: void 0,
1247
+ m: void 0,
1248
+ p: void 0,
1249
+ e: void 0,
1250
+ f: void 0,
1251
+ a: [
1252
+ current.body ? serializeArrayBuffer(ctx, await current.clone().arrayBuffer()) : NULL_NODE,
1253
+ await parseObject(ctx, createResponseOptions(current))
1254
+ ],
1255
+ b: void 0,
1256
+ o: void 0
1257
+ };
1258
+ }
1259
+ async function generateEventNode(ctx, id, current) {
1260
+ return {
1261
+ t: 37 /* Event */,
1262
+ i: id,
1263
+ s: serializeString(current.type),
1264
+ l: void 0,
1265
+ c: void 0,
1266
+ m: void 0,
1267
+ p: void 0,
1268
+ e: void 0,
1269
+ a: void 0,
1270
+ f: await parseObject(ctx, createEventOptions(current)),
1271
+ b: void 0,
1272
+ o: void 0
1273
+ };
1274
+ }
1275
+ async function generateCustomEventNode(ctx, id, current) {
1276
+ return {
1277
+ t: 38 /* CustomEvent */,
1278
+ i: id,
1279
+ s: serializeString(current.type),
1280
+ l: void 0,
1281
+ c: void 0,
1282
+ m: void 0,
1283
+ p: void 0,
1284
+ e: void 0,
1285
+ a: void 0,
1286
+ f: await parseObject(ctx, createCustomEventOptions(current)),
1287
+ b: void 0,
1288
+ o: void 0
1289
+ };
1290
+ }
1182
1291
  async function parseObject(ctx, current) {
1183
1292
  if (!current) {
1184
1293
  return NULL_NODE;
@@ -1193,49 +1302,17 @@ async function parseObject(ctx, current) {
1193
1302
  if (Array.isArray(current)) {
1194
1303
  return generateArrayNode(ctx, id, current);
1195
1304
  }
1196
- switch (current.constructor) {
1305
+ const currentClass = current.constructor;
1306
+ switch (currentClass) {
1197
1307
  case Number:
1198
1308
  case Boolean:
1199
1309
  case String:
1200
1310
  case BigInt:
1201
- case Function:
1202
- case Symbol:
1203
1311
  return generateBoxedNode(ctx, id, current);
1204
1312
  case Date:
1205
1313
  return createDateNode(id, current);
1206
1314
  case RegExp:
1207
1315
  return createRegExpNode(id, current);
1208
- case Promise:
1209
- return generatePromiseNode(ctx, id, current);
1210
- case ArrayBuffer:
1211
- return createArrayBufferNode(id, current);
1212
- case Int8Array:
1213
- case Int16Array:
1214
- case Int32Array:
1215
- case Uint8Array:
1216
- case Uint16Array:
1217
- case Uint32Array:
1218
- case Uint8ClampedArray:
1219
- case Float32Array:
1220
- case Float64Array:
1221
- return createTypedArrayNode(ctx, id, current);
1222
- case BigInt64Array:
1223
- case BigUint64Array:
1224
- return createBigIntTypedArrayNode(ctx, id, current);
1225
- case DataView:
1226
- return createDataViewNode(ctx, id, current);
1227
- case Map:
1228
- return generateMapNode(
1229
- ctx,
1230
- id,
1231
- current
1232
- );
1233
- case Set:
1234
- return generateSetNode(
1235
- ctx,
1236
- id,
1237
- current
1238
- );
1239
1316
  case Object:
1240
1317
  return generateObjectNode(
1241
1318
  ctx,
@@ -1250,11 +1327,6 @@ async function parseObject(ctx, current) {
1250
1327
  current,
1251
1328
  true
1252
1329
  );
1253
- case AggregateError:
1254
- if (ctx.features & 1 /* AggregateError */) {
1255
- return generateAggregateErrorNode(ctx, id, current);
1256
- }
1257
- return generateErrorNode(ctx, id, current);
1258
1330
  case Error:
1259
1331
  case EvalError:
1260
1332
  case RangeError:
@@ -1263,40 +1335,100 @@ async function parseObject(ctx, current) {
1263
1335
  case TypeError:
1264
1336
  case URIError:
1265
1337
  return generateErrorNode(ctx, id, current);
1266
- case URL:
1267
- return createURLNode(ctx, id, current);
1268
- case URLSearchParams:
1269
- return createURLSearchParamsNode(ctx, id, current);
1270
- case Blob:
1271
- return createBlobNode(ctx, id, current);
1272
- case File:
1273
- return createFileNode(ctx, id, current);
1274
- case Headers:
1275
- return generateHeadersNode(ctx, id, current);
1276
- case FormData:
1277
- return generateFormDataNode(ctx, id, current);
1278
1338
  default:
1279
1339
  break;
1280
1340
  }
1281
- if (current instanceof AggregateError) {
1282
- if (ctx.features & 1 /* AggregateError */) {
1283
- return generateAggregateErrorNode(ctx, id, current);
1341
+ if (ctx.features & 2048 /* TypedArray */) {
1342
+ switch (currentClass) {
1343
+ case ArrayBuffer:
1344
+ return createArrayBufferNode(id, current);
1345
+ case Int8Array:
1346
+ case Int16Array:
1347
+ case Int32Array:
1348
+ case Uint8Array:
1349
+ case Uint16Array:
1350
+ case Uint32Array:
1351
+ case Uint8ClampedArray:
1352
+ case Float32Array:
1353
+ case Float64Array:
1354
+ return createTypedArrayNode(ctx, id, current);
1355
+ case DataView:
1356
+ return createDataViewNode(ctx, id, current);
1357
+ default:
1358
+ break;
1284
1359
  }
1285
- return generateErrorNode(ctx, id, current);
1286
1360
  }
1287
- if (current instanceof Error) {
1288
- return generateErrorNode(ctx, id, current);
1361
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
1362
+ switch (currentClass) {
1363
+ case BigInt64Array:
1364
+ case BigUint64Array:
1365
+ return createBigIntTypedArrayNode(ctx, id, current);
1366
+ default:
1367
+ break;
1368
+ }
1369
+ }
1370
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
1371
+ return generateMapNode(
1372
+ ctx,
1373
+ id,
1374
+ current
1375
+ );
1376
+ }
1377
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
1378
+ return generateSetNode(
1379
+ ctx,
1380
+ id,
1381
+ current
1382
+ );
1383
+ }
1384
+ if (ctx.features & 8192 /* WebAPI */) {
1385
+ switch (currentClass) {
1386
+ case URL:
1387
+ return createURLNode(id, current);
1388
+ case URLSearchParams:
1389
+ return createURLSearchParamsNode(id, current);
1390
+ case Blob:
1391
+ return createBlobNode(ctx, id, current);
1392
+ case File:
1393
+ return createFileNode(ctx, id, current);
1394
+ case Headers:
1395
+ return generateHeadersNode(ctx, id, current);
1396
+ case FormData:
1397
+ return generateFormDataNode(ctx, id, current);
1398
+ case Request:
1399
+ return generateRequestNode(ctx, id, current);
1400
+ case Response:
1401
+ return generateResponseNode(ctx, id, current);
1402
+ case Event:
1403
+ return generateEventNode(ctx, id, current);
1404
+ case CustomEvent:
1405
+ return generateCustomEventNode(ctx, id, current);
1406
+ case DOMException:
1407
+ return createDOMExceptionNode(id, current);
1408
+ default:
1409
+ break;
1410
+ }
1411
+ }
1412
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
1413
+ return generateAggregateErrorNode(ctx, id, current);
1289
1414
  }
1290
- if (current instanceof Promise) {
1415
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
1291
1416
  return generatePromiseNode(ctx, id, current);
1292
1417
  }
1293
- if (Symbol.iterator in current) {
1294
- return generateObjectNode(ctx, id, current, !!current.constructor);
1418
+ if (current instanceof Error) {
1419
+ return generateErrorNode(ctx, id, current);
1420
+ }
1421
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
1422
+ return generateObjectNode(ctx, id, current, !!currentClass);
1295
1423
  }
1296
1424
  throw new UnsupportedTypeError(current);
1297
1425
  }
1298
1426
  async function parseAsync(ctx, current) {
1299
- switch (typeof current) {
1427
+ const t = typeof current;
1428
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
1429
+ return createBigIntNode(current);
1430
+ }
1431
+ switch (t) {
1300
1432
  case "boolean":
1301
1433
  return current ? TRUE_NODE : FALSE_NODE;
1302
1434
  case "undefined":
@@ -1305,8 +1437,6 @@ async function parseAsync(ctx, current) {
1305
1437
  return createStringNode(current);
1306
1438
  case "number":
1307
1439
  return createNumberNode(current);
1308
- case "bigint":
1309
- return createBigIntNode(ctx, current);
1310
1440
  case "object":
1311
1441
  return parseObject(ctx, current);
1312
1442
  case "symbol":
@@ -1547,6 +1677,53 @@ function deserializeBoxed(ctx, node) {
1547
1677
  Object(deserializeTree(ctx, node.f))
1548
1678
  );
1549
1679
  }
1680
+ function deserializeRequest(ctx, node) {
1681
+ return assignIndexedValue(
1682
+ ctx,
1683
+ node.i,
1684
+ new Request(deserializeString(node.s), deserializeTree(ctx, node.f))
1685
+ );
1686
+ }
1687
+ function deserializeResponse(ctx, node) {
1688
+ return assignIndexedValue(
1689
+ ctx,
1690
+ node.i,
1691
+ new Response(
1692
+ deserializeTree(ctx, node.a[0]),
1693
+ deserializeTree(ctx, node.a[1])
1694
+ )
1695
+ );
1696
+ }
1697
+ function deserializeEvent(ctx, node) {
1698
+ return assignIndexedValue(
1699
+ ctx,
1700
+ node.i,
1701
+ new Event(
1702
+ deserializeString(node.s),
1703
+ deserializeTree(ctx, node.f)
1704
+ )
1705
+ );
1706
+ }
1707
+ function deserializeCustomEvent(ctx, node) {
1708
+ return assignIndexedValue(
1709
+ ctx,
1710
+ node.i,
1711
+ new CustomEvent(
1712
+ deserializeString(node.s),
1713
+ deserializeTree(ctx, node.f)
1714
+ )
1715
+ );
1716
+ }
1717
+ function deserializeDOMException(ctx, node) {
1718
+ return assignIndexedValue(
1719
+ ctx,
1720
+ node.i,
1721
+ new DOMException(
1722
+ deserializeString(node.s),
1723
+ deserializeString(node.c)
1724
+ )
1725
+ );
1726
+ }
1550
1727
  function deserializeTree(ctx, node) {
1551
1728
  switch (node.t) {
1552
1729
  case 2 /* Constant */:
@@ -1603,6 +1780,16 @@ function deserializeTree(ctx, node) {
1603
1780
  return deserializeFormData(ctx, node);
1604
1781
  case 27 /* Boxed */:
1605
1782
  return deserializeBoxed(ctx, node);
1783
+ case 35 /* Request */:
1784
+ return deserializeRequest(ctx, node);
1785
+ case 36 /* Response */:
1786
+ return deserializeResponse(ctx, node);
1787
+ case 37 /* Event */:
1788
+ return deserializeEvent(ctx, node);
1789
+ case 38 /* CustomEvent */:
1790
+ return deserializeCustomEvent(ctx, node);
1791
+ case 39 /* DOMException */:
1792
+ return deserializeDOMException(ctx, node);
1606
1793
  default:
1607
1794
  throw new Error("invariant");
1608
1795
  }
@@ -2177,6 +2364,33 @@ function serializeBoxed(ctx, node) {
2177
2364
  function serializeWKSymbol(ctx, node) {
2178
2365
  return assignIndexedValue2(ctx, node.i, SYMBOL_STRING[node.s]);
2179
2366
  }
2367
+ function serializeRequest(ctx, node) {
2368
+ return assignIndexedValue2(ctx, node.i, 'new Request("' + node.s + '",' + serializeTree(ctx, node.f) + ")");
2369
+ }
2370
+ function serializeResponse(ctx, node) {
2371
+ return assignIndexedValue2(ctx, node.i, "new Response(" + serializeTree(ctx, node.a[0]) + "," + serializeTree(ctx, node.a[1]) + ")");
2372
+ }
2373
+ function serializeEvent(ctx, node) {
2374
+ return assignIndexedValue2(
2375
+ ctx,
2376
+ node.i,
2377
+ 'new Event("' + node.s + '",' + serializeTree(ctx, node.f) + ")"
2378
+ );
2379
+ }
2380
+ function serializeCustomEvent(ctx, node) {
2381
+ return assignIndexedValue2(
2382
+ ctx,
2383
+ node.i,
2384
+ 'new CustomEvent("' + node.s + '",' + serializeTree(ctx, node.f) + ")"
2385
+ );
2386
+ }
2387
+ function serializeDOMException(ctx, node) {
2388
+ return assignIndexedValue2(
2389
+ ctx,
2390
+ node.i,
2391
+ 'new DOMException("' + node.s + '","' + node.c + '")'
2392
+ );
2393
+ }
2180
2394
  function serializeTree(ctx, node) {
2181
2395
  switch (node.t) {
2182
2396
  case 0 /* Number */:
@@ -2234,6 +2448,16 @@ function serializeTree(ctx, node) {
2234
2448
  return serializeFormData(ctx, node);
2235
2449
  case 27 /* Boxed */:
2236
2450
  return serializeBoxed(ctx, node);
2451
+ case 35 /* Request */:
2452
+ return serializeRequest(ctx, node);
2453
+ case 36 /* Response */:
2454
+ return serializeResponse(ctx, node);
2455
+ case 37 /* Event */:
2456
+ return serializeEvent(ctx, node);
2457
+ case 38 /* CustomEvent */:
2458
+ return serializeCustomEvent(ctx, node);
2459
+ case 39 /* DOMException */:
2460
+ return serializeDOMException(ctx, node);
2237
2461
  default:
2238
2462
  throw new Error("invariant");
2239
2463
  }
@@ -2279,7 +2503,6 @@ function generateArrayNode2(ctx, id, current) {
2279
2503
  };
2280
2504
  }
2281
2505
  function generateMapNode2(ctx, id, current) {
2282
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
2283
2506
  const len = current.size;
2284
2507
  const keyNodes = new Array(len);
2285
2508
  const valueNodes = new Array(len);
@@ -2318,7 +2541,6 @@ function generateMapNode2(ctx, id, current) {
2318
2541
  };
2319
2542
  }
2320
2543
  function generateSetNode2(ctx, id, current) {
2321
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
2322
2544
  const len = current.size;
2323
2545
  const nodes = new Array(len);
2324
2546
  const deferred = new Array(len);
@@ -2479,7 +2701,6 @@ function generateErrorNode2(ctx, id, current) {
2479
2701
  };
2480
2702
  }
2481
2703
  function generateHeadersNode2(ctx, id, current) {
2482
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2483
2704
  const items = {};
2484
2705
  current.forEach((value, key) => {
2485
2706
  items[key] = value;
@@ -2500,7 +2721,6 @@ function generateHeadersNode2(ctx, id, current) {
2500
2721
  };
2501
2722
  }
2502
2723
  function generateFormDataNode2(ctx, id, current) {
2503
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2504
2724
  const items = {};
2505
2725
  current.forEach((value, key) => {
2506
2726
  items[key] = value;
@@ -2536,6 +2756,38 @@ function generateBoxedNode2(ctx, id, current) {
2536
2756
  o: void 0
2537
2757
  };
2538
2758
  }
2759
+ function generateEventNode2(ctx, id, current) {
2760
+ return {
2761
+ t: 37 /* Event */,
2762
+ i: id,
2763
+ s: serializeString(current.type),
2764
+ l: void 0,
2765
+ c: void 0,
2766
+ m: void 0,
2767
+ p: void 0,
2768
+ e: void 0,
2769
+ a: void 0,
2770
+ f: parseObject2(ctx, createEventOptions(current)),
2771
+ b: void 0,
2772
+ o: void 0
2773
+ };
2774
+ }
2775
+ function generateCustomEventNode2(ctx, id, current) {
2776
+ return {
2777
+ t: 38 /* CustomEvent */,
2778
+ i: id,
2779
+ s: serializeString(current.type),
2780
+ l: void 0,
2781
+ c: void 0,
2782
+ m: void 0,
2783
+ p: void 0,
2784
+ e: void 0,
2785
+ a: void 0,
2786
+ f: parseObject2(ctx, createCustomEventOptions(current)),
2787
+ b: void 0,
2788
+ o: void 0
2789
+ };
2790
+ }
2539
2791
  function parseObject2(ctx, current) {
2540
2792
  if (!current) {
2541
2793
  return NULL_NODE;
@@ -2550,39 +2802,17 @@ function parseObject2(ctx, current) {
2550
2802
  if (Array.isArray(current)) {
2551
2803
  return generateArrayNode2(ctx, id, current);
2552
2804
  }
2553
- switch (current.constructor) {
2805
+ const currentClass = current.constructor;
2806
+ switch (currentClass) {
2554
2807
  case Number:
2555
2808
  case Boolean:
2556
2809
  case String:
2557
2810
  case BigInt:
2558
- case Function:
2559
- case Symbol:
2560
2811
  return generateBoxedNode2(ctx, id, current);
2561
2812
  case Date:
2562
2813
  return createDateNode(id, current);
2563
2814
  case RegExp:
2564
2815
  return createRegExpNode(id, current);
2565
- case ArrayBuffer:
2566
- return createArrayBufferNode(id, current);
2567
- case Int8Array:
2568
- case Int16Array:
2569
- case Int32Array:
2570
- case Uint8Array:
2571
- case Uint16Array:
2572
- case Uint32Array:
2573
- case Uint8ClampedArray:
2574
- case Float32Array:
2575
- case Float64Array:
2576
- return createTypedArrayNode(ctx, id, current);
2577
- case BigInt64Array:
2578
- case BigUint64Array:
2579
- return createBigIntTypedArrayNode(ctx, id, current);
2580
- case DataView:
2581
- return createDataViewNode(ctx, id, current);
2582
- case Map:
2583
- return generateMapNode2(ctx, id, current);
2584
- case Set:
2585
- return generateSetNode2(ctx, id, current);
2586
2816
  case Object:
2587
2817
  return generateObjectNode2(
2588
2818
  ctx,
@@ -2597,11 +2827,6 @@ function parseObject2(ctx, current) {
2597
2827
  current,
2598
2828
  true
2599
2829
  );
2600
- case AggregateError:
2601
- if (ctx.features & 1 /* AggregateError */) {
2602
- return generateAggregateErrorNode2(ctx, id, current);
2603
- }
2604
- return generateErrorNode2(ctx, id, current);
2605
2830
  case Error:
2606
2831
  case EvalError:
2607
2832
  case RangeError:
@@ -2610,33 +2835,81 @@ function parseObject2(ctx, current) {
2610
2835
  case TypeError:
2611
2836
  case URIError:
2612
2837
  return generateErrorNode2(ctx, id, current);
2613
- case URL:
2614
- return createURLNode(ctx, id, current);
2615
- case URLSearchParams:
2616
- return createURLSearchParamsNode(ctx, id, current);
2617
- case Headers:
2618
- return generateHeadersNode2(ctx, id, current);
2619
- case FormData:
2620
- return generateFormDataNode2(ctx, id, current);
2621
2838
  default:
2622
2839
  break;
2623
2840
  }
2624
- if (current instanceof AggregateError) {
2625
- if (ctx.features & 1 /* AggregateError */) {
2626
- return generateAggregateErrorNode2(ctx, id, current);
2841
+ if (ctx.features & 2048 /* TypedArray */) {
2842
+ switch (currentClass) {
2843
+ case ArrayBuffer:
2844
+ return createArrayBufferNode(id, current);
2845
+ case Int8Array:
2846
+ case Int16Array:
2847
+ case Int32Array:
2848
+ case Uint8Array:
2849
+ case Uint16Array:
2850
+ case Uint32Array:
2851
+ case Uint8ClampedArray:
2852
+ case Float32Array:
2853
+ case Float64Array:
2854
+ return createTypedArrayNode(ctx, id, current);
2855
+ case DataView:
2856
+ return createDataViewNode(ctx, id, current);
2857
+ default:
2858
+ break;
2859
+ }
2860
+ }
2861
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
2862
+ switch (currentClass) {
2863
+ case BigInt64Array:
2864
+ case BigUint64Array:
2865
+ return createBigIntTypedArrayNode(ctx, id, current);
2866
+ default:
2867
+ break;
2627
2868
  }
2628
- return generateErrorNode2(ctx, id, current);
2869
+ }
2870
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
2871
+ return generateMapNode2(ctx, id, current);
2872
+ }
2873
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
2874
+ return generateSetNode2(ctx, id, current);
2875
+ }
2876
+ if (ctx.features & 8192 /* WebAPI */) {
2877
+ switch (currentClass) {
2878
+ case URL:
2879
+ return createURLNode(id, current);
2880
+ case URLSearchParams:
2881
+ return createURLSearchParamsNode(id, current);
2882
+ case Headers:
2883
+ return generateHeadersNode2(ctx, id, current);
2884
+ case FormData:
2885
+ return generateFormDataNode2(ctx, id, current);
2886
+ case Event:
2887
+ return generateEventNode2(ctx, id, current);
2888
+ case CustomEvent:
2889
+ return generateCustomEventNode2(ctx, id, current);
2890
+ case DOMException:
2891
+ return createDOMExceptionNode(id, current);
2892
+ default:
2893
+ break;
2894
+ }
2895
+ }
2896
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
2897
+ return generateAggregateErrorNode2(ctx, id, current);
2629
2898
  }
2630
2899
  if (current instanceof Error) {
2631
2900
  return generateErrorNode2(ctx, id, current);
2632
2901
  }
2633
- if (Symbol.iterator in current) {
2634
- return generateObjectNode2(ctx, id, current, !!current.constructor);
2902
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
2903
+ return generateObjectNode2(ctx, id, current, !!currentClass);
2635
2904
  }
2636
2905
  throw new UnsupportedTypeError(current);
2637
2906
  }
2638
2907
  function parseSync(ctx, current) {
2639
- switch (typeof current) {
2908
+ const t = typeof current;
2909
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
2910
+ return createBigIntNode(current);
2911
+ }
2912
+ switch (t) {
2640
2913
  case "boolean":
2641
2914
  return current ? TRUE_NODE : FALSE_NODE;
2642
2915
  case "undefined":
@@ -2645,8 +2918,6 @@ function parseSync(ctx, current) {
2645
2918
  return createStringNode(current);
2646
2919
  case "number":
2647
2920
  return createNumberNode(current);
2648
- case "bigint":
2649
- return createBigIntNode(ctx, current);
2650
2921
  case "object":
2651
2922
  return parseObject2(ctx, current);
2652
2923
  case "symbol":
@@ -2806,7 +3077,6 @@ function serializeArrayBuffer3(ctx, current) {
2806
3077
  return createArrayBufferNode(newID, current);
2807
3078
  }
2808
3079
  function createTypedArrayNode2(ctx, id, current) {
2809
- assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
2810
3080
  return {
2811
3081
  t: 15 /* TypedArray */,
2812
3082
  i: id,
@@ -2869,7 +3139,7 @@ function createSymbolNode2(ctx, current) {
2869
3139
  if (hasReferenceID(current)) {
2870
3140
  return createReferenceNode(newID, current);
2871
3141
  }
2872
- return createWKSymbolNode(ctx, newID, current);
3142
+ return createWKSymbolNode(newID, current);
2873
3143
  }
2874
3144
  function createFunctionNode2(ctx, current) {
2875
3145
  assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
@@ -2884,7 +3154,6 @@ function createFunctionNode2(ctx, current) {
2884
3154
 
2885
3155
  // src/core/cross/web-api.ts
2886
3156
  async function createBlobNode2(ctx, id, current) {
2887
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2888
3157
  return {
2889
3158
  t: 23 /* Blob */,
2890
3159
  i: id,
@@ -2901,7 +3170,6 @@ async function createBlobNode2(ctx, id, current) {
2901
3170
  };
2902
3171
  }
2903
3172
  async function createFileNode2(ctx, id, current) {
2904
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2905
3173
  return {
2906
3174
  t: 24 /* File */,
2907
3175
  i: id,
@@ -2958,7 +3226,6 @@ async function generateArrayNode3(ctx, id, current) {
2958
3226
  };
2959
3227
  }
2960
3228
  async function generateMapNode3(ctx, id, current) {
2961
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
2962
3229
  const len = current.size;
2963
3230
  const keyNodes = new Array(len);
2964
3231
  const valueNodes = new Array(len);
@@ -2997,7 +3264,6 @@ async function generateMapNode3(ctx, id, current) {
2997
3264
  };
2998
3265
  }
2999
3266
  async function generateSetNode3(ctx, id, current) {
3000
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
3001
3267
  const len = current.size;
3002
3268
  const nodes = new Array(len);
3003
3269
  const deferred = new Array(len);
@@ -3109,7 +3375,6 @@ async function generatePlainProperties3(ctx, properties) {
3109
3375
  };
3110
3376
  }
3111
3377
  async function generatePromiseNode2(ctx, id, current) {
3112
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
3113
3378
  const [status, result] = await promiseToResult(current);
3114
3379
  return {
3115
3380
  t: 12 /* Promise */,
@@ -3179,7 +3444,6 @@ async function generateErrorNode3(ctx, id, current) {
3179
3444
  };
3180
3445
  }
3181
3446
  async function generateHeadersNode3(ctx, id, current) {
3182
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3183
3447
  const items = {};
3184
3448
  current.forEach((value, key) => {
3185
3449
  items[key] = value;
@@ -3200,7 +3464,6 @@ async function generateHeadersNode3(ctx, id, current) {
3200
3464
  };
3201
3465
  }
3202
3466
  async function generateFormDataNode3(ctx, id, current) {
3203
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3204
3467
  const items = {};
3205
3468
  current.forEach((value, key) => {
3206
3469
  items[key] = value;
@@ -3236,6 +3499,76 @@ async function generateBoxedNode3(ctx, id, current) {
3236
3499
  o: void 0
3237
3500
  };
3238
3501
  }
3502
+ async function generateRequestNode2(ctx, id, current) {
3503
+ return {
3504
+ t: 35 /* Request */,
3505
+ i: id,
3506
+ s: serializeString(current.url),
3507
+ l: void 0,
3508
+ c: void 0,
3509
+ m: void 0,
3510
+ p: void 0,
3511
+ e: void 0,
3512
+ f: await parseObject3(
3513
+ ctx,
3514
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
3515
+ ),
3516
+ a: void 0,
3517
+ b: void 0,
3518
+ o: void 0
3519
+ };
3520
+ }
3521
+ async function generateResponseNode2(ctx, id, current) {
3522
+ return {
3523
+ t: 36 /* Response */,
3524
+ i: id,
3525
+ s: void 0,
3526
+ l: void 0,
3527
+ c: void 0,
3528
+ m: void 0,
3529
+ p: void 0,
3530
+ e: void 0,
3531
+ f: void 0,
3532
+ a: [
3533
+ current.body ? serializeArrayBuffer3(ctx, await current.clone().arrayBuffer()) : NULL_NODE,
3534
+ await parseObject3(ctx, createResponseOptions(current))
3535
+ ],
3536
+ b: void 0,
3537
+ o: void 0
3538
+ };
3539
+ }
3540
+ async function generateEventNode3(ctx, id, current) {
3541
+ return {
3542
+ t: 37 /* Event */,
3543
+ i: id,
3544
+ s: serializeString(current.type),
3545
+ l: void 0,
3546
+ c: void 0,
3547
+ m: void 0,
3548
+ p: void 0,
3549
+ e: void 0,
3550
+ a: void 0,
3551
+ f: await parseObject3(ctx, createEventOptions(current)),
3552
+ b: void 0,
3553
+ o: void 0
3554
+ };
3555
+ }
3556
+ async function generateCustomEventNode3(ctx, id, current) {
3557
+ return {
3558
+ t: 38 /* CustomEvent */,
3559
+ i: id,
3560
+ s: serializeString(current.type),
3561
+ l: void 0,
3562
+ c: void 0,
3563
+ m: void 0,
3564
+ p: void 0,
3565
+ e: void 0,
3566
+ a: void 0,
3567
+ f: await parseObject3(ctx, createCustomEventOptions(current)),
3568
+ b: void 0,
3569
+ o: void 0
3570
+ };
3571
+ }
3239
3572
  async function parseObject3(ctx, current) {
3240
3573
  if (!current) {
3241
3574
  return NULL_NODE;
@@ -3252,49 +3585,17 @@ async function parseObject3(ctx, current) {
3252
3585
  if (Array.isArray(current)) {
3253
3586
  return generateArrayNode3(ctx, id, current);
3254
3587
  }
3255
- switch (current.constructor) {
3588
+ const currentClass = current.constructor;
3589
+ switch (currentClass) {
3256
3590
  case Number:
3257
3591
  case Boolean:
3258
3592
  case String:
3259
3593
  case BigInt:
3260
- case Function:
3261
- case Symbol:
3262
3594
  return generateBoxedNode3(ctx, id, current);
3263
3595
  case Date:
3264
3596
  return createDateNode(id, current);
3265
3597
  case RegExp:
3266
3598
  return createRegExpNode(id, current);
3267
- case Promise:
3268
- return generatePromiseNode2(ctx, id, current);
3269
- case ArrayBuffer:
3270
- return createArrayBufferNode(id, current);
3271
- case Int8Array:
3272
- case Int16Array:
3273
- case Int32Array:
3274
- case Uint8Array:
3275
- case Uint16Array:
3276
- case Uint32Array:
3277
- case Uint8ClampedArray:
3278
- case Float32Array:
3279
- case Float64Array:
3280
- return createTypedArrayNode2(ctx, id, current);
3281
- case BigInt64Array:
3282
- case BigUint64Array:
3283
- return createBigIntTypedArrayNode2(ctx, id, current);
3284
- case DataView:
3285
- return createDataViewNode2(ctx, id, current);
3286
- case Map:
3287
- return generateMapNode3(
3288
- ctx,
3289
- id,
3290
- current
3291
- );
3292
- case Set:
3293
- return generateSetNode3(
3294
- ctx,
3295
- id,
3296
- current
3297
- );
3298
3599
  case Object:
3299
3600
  return generateObjectNode3(
3300
3601
  ctx,
@@ -3309,11 +3610,6 @@ async function parseObject3(ctx, current) {
3309
3610
  current,
3310
3611
  true
3311
3612
  );
3312
- case AggregateError:
3313
- if (ctx.features & 1 /* AggregateError */) {
3314
- return generateAggregateErrorNode3(ctx, id, current);
3315
- }
3316
- return generateErrorNode3(ctx, id, current);
3317
3613
  case Error:
3318
3614
  case EvalError:
3319
3615
  case RangeError:
@@ -3322,40 +3618,100 @@ async function parseObject3(ctx, current) {
3322
3618
  case TypeError:
3323
3619
  case URIError:
3324
3620
  return generateErrorNode3(ctx, id, current);
3325
- case URL:
3326
- return createURLNode(ctx, id, current);
3327
- case URLSearchParams:
3328
- return createURLSearchParamsNode(ctx, id, current);
3329
- case Blob:
3330
- return createBlobNode2(ctx, id, current);
3331
- case File:
3332
- return createFileNode2(ctx, id, current);
3333
- case Headers:
3334
- return generateHeadersNode3(ctx, id, current);
3335
- case FormData:
3336
- return generateFormDataNode3(ctx, id, current);
3337
3621
  default:
3338
3622
  break;
3339
3623
  }
3340
- if (current instanceof AggregateError) {
3341
- if (ctx.features & 1 /* AggregateError */) {
3342
- return generateAggregateErrorNode3(ctx, id, current);
3624
+ if (ctx.features & 2048 /* TypedArray */) {
3625
+ switch (currentClass) {
3626
+ case ArrayBuffer:
3627
+ return createArrayBufferNode(id, current);
3628
+ case Int8Array:
3629
+ case Int16Array:
3630
+ case Int32Array:
3631
+ case Uint8Array:
3632
+ case Uint16Array:
3633
+ case Uint32Array:
3634
+ case Uint8ClampedArray:
3635
+ case Float32Array:
3636
+ case Float64Array:
3637
+ return createTypedArrayNode2(ctx, id, current);
3638
+ case DataView:
3639
+ return createDataViewNode2(ctx, id, current);
3640
+ default:
3641
+ break;
3343
3642
  }
3344
- return generateErrorNode3(ctx, id, current);
3345
3643
  }
3346
- if (current instanceof Error) {
3347
- return generateErrorNode3(ctx, id, current);
3644
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
3645
+ switch (currentClass) {
3646
+ case BigInt64Array:
3647
+ case BigUint64Array:
3648
+ return createBigIntTypedArrayNode2(ctx, id, current);
3649
+ default:
3650
+ break;
3651
+ }
3652
+ }
3653
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
3654
+ return generateMapNode3(
3655
+ ctx,
3656
+ id,
3657
+ current
3658
+ );
3659
+ }
3660
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
3661
+ return generateSetNode3(
3662
+ ctx,
3663
+ id,
3664
+ current
3665
+ );
3666
+ }
3667
+ if (ctx.features & 8192 /* WebAPI */) {
3668
+ switch (currentClass) {
3669
+ case URL:
3670
+ return createURLNode(id, current);
3671
+ case URLSearchParams:
3672
+ return createURLSearchParamsNode(id, current);
3673
+ case Blob:
3674
+ return createBlobNode2(ctx, id, current);
3675
+ case File:
3676
+ return createFileNode2(ctx, id, current);
3677
+ case Headers:
3678
+ return generateHeadersNode3(ctx, id, current);
3679
+ case FormData:
3680
+ return generateFormDataNode3(ctx, id, current);
3681
+ case Request:
3682
+ return generateRequestNode2(ctx, id, current);
3683
+ case Response:
3684
+ return generateResponseNode2(ctx, id, current);
3685
+ case Event:
3686
+ return generateEventNode3(ctx, id, current);
3687
+ case CustomEvent:
3688
+ return generateCustomEventNode3(ctx, id, current);
3689
+ case DOMException:
3690
+ return createDOMExceptionNode(id, current);
3691
+ default:
3692
+ break;
3693
+ }
3694
+ }
3695
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
3696
+ return generateAggregateErrorNode3(ctx, id, current);
3348
3697
  }
3349
- if (current instanceof Promise) {
3698
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
3350
3699
  return generatePromiseNode2(ctx, id, current);
3351
3700
  }
3352
- if (Symbol.iterator in current) {
3353
- return generateObjectNode3(ctx, id, current, !!current.constructor);
3701
+ if (current instanceof Error) {
3702
+ return generateErrorNode3(ctx, id, current);
3703
+ }
3704
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
3705
+ return generateObjectNode3(ctx, id, current, !!currentClass);
3354
3706
  }
3355
3707
  throw new UnsupportedTypeError(current);
3356
3708
  }
3357
3709
  async function crossParseAsync(ctx, current) {
3358
- switch (typeof current) {
3710
+ const t = typeof current;
3711
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
3712
+ return createBigIntNode(current);
3713
+ }
3714
+ switch (t) {
3359
3715
  case "boolean":
3360
3716
  return current ? TRUE_NODE : FALSE_NODE;
3361
3717
  case "undefined":
@@ -3364,8 +3720,6 @@ async function crossParseAsync(ctx, current) {
3364
3720
  return createStringNode(current);
3365
3721
  case "number":
3366
3722
  return createNumberNode(current);
3367
- case "bigint":
3368
- return createBigIntNode(ctx, current);
3369
3723
  case "object":
3370
3724
  return parseObject3(ctx, current);
3371
3725
  case "symbol":
@@ -3845,6 +4199,33 @@ function serializeReadableStreamError(ctx, node) {
3845
4199
  function serializeReadableStreamConstructor(node) {
3846
4200
  return assignIndexedValue3(node.i, GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_CONSTRUCTOR + "()");
3847
4201
  }
4202
+ function serializeRequest2(ctx, node) {
4203
+ return assignIndexedValue3(node.i, 'new Request("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")");
4204
+ }
4205
+ function serializeResponse2(ctx, node) {
4206
+ return assignIndexedValue3(
4207
+ node.i,
4208
+ "new Response(" + crossSerializeTree(ctx, node.a[0]) + "," + crossSerializeTree(ctx, node.a[1]) + ")"
4209
+ );
4210
+ }
4211
+ function serializeEvent2(ctx, node) {
4212
+ return assignIndexedValue3(
4213
+ node.i,
4214
+ 'new Event("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")"
4215
+ );
4216
+ }
4217
+ function serializeCustomEvent2(ctx, node) {
4218
+ return assignIndexedValue3(
4219
+ node.i,
4220
+ 'new CustomEvent("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")"
4221
+ );
4222
+ }
4223
+ function serializeDOMException2(node) {
4224
+ return assignIndexedValue3(
4225
+ node.i,
4226
+ 'new DOMException("' + node.s + '","' + node.c + '")'
4227
+ );
4228
+ }
3848
4229
  function crossSerializeTree(ctx, node) {
3849
4230
  switch (node.t) {
3850
4231
  case 0 /* Number */:
@@ -3916,6 +4297,16 @@ function crossSerializeTree(ctx, node) {
3916
4297
  return serializeReadableStreamEnqueue(ctx, node);
3917
4298
  case 34 /* ReadableStreamError */:
3918
4299
  return serializeReadableStreamError(ctx, node);
4300
+ case 35 /* Request */:
4301
+ return serializeRequest2(ctx, node);
4302
+ case 36 /* Response */:
4303
+ return serializeResponse2(ctx, node);
4304
+ case 37 /* Event */:
4305
+ return serializeEvent2(ctx, node);
4306
+ case 38 /* CustomEvent */:
4307
+ return serializeCustomEvent2(ctx, node);
4308
+ case 39 /* DOMException */:
4309
+ return serializeDOMException2(node);
3919
4310
  default:
3920
4311
  throw new Error("invariant");
3921
4312
  }
@@ -3961,7 +4352,6 @@ function generateArrayNode4(ctx, id, current) {
3961
4352
  };
3962
4353
  }
3963
4354
  function generateMapNode4(ctx, id, current) {
3964
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
3965
4355
  const len = current.size;
3966
4356
  const keyNodes = new Array(len);
3967
4357
  const valueNodes = new Array(len);
@@ -4000,7 +4390,6 @@ function generateMapNode4(ctx, id, current) {
4000
4390
  };
4001
4391
  }
4002
4392
  function generateSetNode4(ctx, id, current) {
4003
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
4004
4393
  const len = current.size;
4005
4394
  const nodes = new Array(len);
4006
4395
  const deferred = new Array(len);
@@ -4112,7 +4501,6 @@ function generatePlainProperties4(ctx, properties) {
4112
4501
  };
4113
4502
  }
4114
4503
  function generatePromiseNode3(ctx, id, current) {
4115
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
4116
4504
  current.then(
4117
4505
  (data) => {
4118
4506
  if (ctx.alive) {
@@ -4222,7 +4610,6 @@ function generateErrorNode4(ctx, id, current) {
4222
4610
  };
4223
4611
  }
4224
4612
  function generateHeadersNode4(ctx, id, current) {
4225
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4226
4613
  const items = {};
4227
4614
  current.forEach((value, key) => {
4228
4615
  items[key] = value;
@@ -4243,7 +4630,6 @@ function generateHeadersNode4(ctx, id, current) {
4243
4630
  };
4244
4631
  }
4245
4632
  function generateFormDataNode4(ctx, id, current) {
4246
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4247
4633
  const items = {};
4248
4634
  current.forEach((value, key) => {
4249
4635
  items[key] = value;
@@ -4280,7 +4666,6 @@ function generateBoxedNode4(ctx, id, current) {
4280
4666
  };
4281
4667
  }
4282
4668
  function generateReadableStreamNode(ctx, id, current) {
4283
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4284
4669
  const reader = current.getReader();
4285
4670
  pushPendingState(ctx);
4286
4671
  function push() {
@@ -4359,6 +4744,76 @@ function generateReadableStreamNode(ctx, id, current) {
4359
4744
  o: void 0
4360
4745
  };
4361
4746
  }
4747
+ function generateRequestNode3(ctx, id, current) {
4748
+ return {
4749
+ t: 35 /* Request */,
4750
+ i: id,
4751
+ s: serializeString(current.url),
4752
+ l: void 0,
4753
+ c: void 0,
4754
+ m: void 0,
4755
+ p: void 0,
4756
+ e: void 0,
4757
+ f: parseObject4(
4758
+ ctx,
4759
+ createRequestOptions(current, current.clone().body)
4760
+ ),
4761
+ a: void 0,
4762
+ b: void 0,
4763
+ o: void 0
4764
+ };
4765
+ }
4766
+ function generateResponseNode3(ctx, id, current) {
4767
+ return {
4768
+ t: 36 /* Response */,
4769
+ i: id,
4770
+ s: void 0,
4771
+ l: void 0,
4772
+ c: void 0,
4773
+ m: void 0,
4774
+ p: void 0,
4775
+ e: void 0,
4776
+ f: void 0,
4777
+ a: [
4778
+ current.body ? parseObject4(ctx, current.clone().body) : NULL_NODE,
4779
+ parseObject4(ctx, createResponseOptions(current))
4780
+ ],
4781
+ b: void 0,
4782
+ o: void 0
4783
+ };
4784
+ }
4785
+ function generateEventNode4(ctx, id, current) {
4786
+ return {
4787
+ t: 37 /* Event */,
4788
+ i: id,
4789
+ s: serializeString(current.type),
4790
+ l: void 0,
4791
+ c: void 0,
4792
+ m: void 0,
4793
+ p: void 0,
4794
+ e: void 0,
4795
+ a: void 0,
4796
+ f: parseObject4(ctx, createEventOptions(current)),
4797
+ b: void 0,
4798
+ o: void 0
4799
+ };
4800
+ }
4801
+ function generateCustomEventNode4(ctx, id, current) {
4802
+ return {
4803
+ t: 38 /* CustomEvent */,
4804
+ i: id,
4805
+ s: serializeString(current.type),
4806
+ l: void 0,
4807
+ c: void 0,
4808
+ m: void 0,
4809
+ p: void 0,
4810
+ e: void 0,
4811
+ a: void 0,
4812
+ f: parseObject4(ctx, createCustomEventOptions(current)),
4813
+ b: void 0,
4814
+ o: void 0
4815
+ };
4816
+ }
4362
4817
  function parseObject4(ctx, current) {
4363
4818
  if (!current) {
4364
4819
  return NULL_NODE;
@@ -4375,7 +4830,8 @@ function parseObject4(ctx, current) {
4375
4830
  if (Array.isArray(current)) {
4376
4831
  return generateArrayNode4(ctx, id, current);
4377
4832
  }
4378
- switch (current.constructor) {
4833
+ const currentClass = current.constructor;
4834
+ switch (currentClass) {
4379
4835
  case Number:
4380
4836
  case Boolean:
4381
4837
  case String:
@@ -4387,37 +4843,6 @@ function parseObject4(ctx, current) {
4387
4843
  return createDateNode(id, current);
4388
4844
  case RegExp:
4389
4845
  return createRegExpNode(id, current);
4390
- case Promise:
4391
- return generatePromiseNode3(ctx, id, current);
4392
- case ArrayBuffer:
4393
- return createArrayBufferNode(id, current);
4394
- case Int8Array:
4395
- case Int16Array:
4396
- case Int32Array:
4397
- case Uint8Array:
4398
- case Uint16Array:
4399
- case Uint32Array:
4400
- case Uint8ClampedArray:
4401
- case Float32Array:
4402
- case Float64Array:
4403
- return createTypedArrayNode2(ctx, id, current);
4404
- case BigInt64Array:
4405
- case BigUint64Array:
4406
- return createBigIntTypedArrayNode2(ctx, id, current);
4407
- case DataView:
4408
- return createDataViewNode2(ctx, id, current);
4409
- case Map:
4410
- return generateMapNode4(
4411
- ctx,
4412
- id,
4413
- current
4414
- );
4415
- case Set:
4416
- return generateSetNode4(
4417
- ctx,
4418
- id,
4419
- current
4420
- );
4421
4846
  case Object:
4422
4847
  return generateObjectNode4(
4423
4848
  ctx,
@@ -4432,11 +4857,6 @@ function parseObject4(ctx, current) {
4432
4857
  current,
4433
4858
  true
4434
4859
  );
4435
- case AggregateError:
4436
- if (ctx.features & 1 /* AggregateError */) {
4437
- return generateAggregateErrorNode4(ctx, id, current);
4438
- }
4439
- return generateErrorNode4(ctx, id, current);
4440
4860
  case Error:
4441
4861
  case EvalError:
4442
4862
  case RangeError:
@@ -4445,38 +4865,90 @@ function parseObject4(ctx, current) {
4445
4865
  case TypeError:
4446
4866
  case URIError:
4447
4867
  return generateErrorNode4(ctx, id, current);
4448
- case URL:
4449
- return createURLNode(ctx, id, current);
4450
- case URLSearchParams:
4451
- return createURLSearchParamsNode(ctx, id, current);
4452
- case Headers:
4453
- return generateHeadersNode4(ctx, id, current);
4454
- case FormData:
4455
- return generateFormDataNode4(ctx, id, current);
4456
- case ReadableStream:
4457
- return generateReadableStreamNode(ctx, id, current);
4458
4868
  default:
4459
4869
  break;
4460
4870
  }
4461
- if (current instanceof AggregateError) {
4462
- if (ctx.features & 1 /* AggregateError */) {
4463
- return generateAggregateErrorNode4(ctx, id, current);
4871
+ if (ctx.features & 2048 /* TypedArray */) {
4872
+ switch (currentClass) {
4873
+ case ArrayBuffer:
4874
+ return createArrayBufferNode(id, current);
4875
+ case Int8Array:
4876
+ case Int16Array:
4877
+ case Int32Array:
4878
+ case Uint8Array:
4879
+ case Uint16Array:
4880
+ case Uint32Array:
4881
+ case Uint8ClampedArray:
4882
+ case Float32Array:
4883
+ case Float64Array:
4884
+ return createTypedArrayNode2(ctx, id, current);
4885
+ case DataView:
4886
+ return createDataViewNode2(ctx, id, current);
4887
+ default:
4888
+ break;
4464
4889
  }
4465
- return generateErrorNode4(ctx, id, current);
4466
4890
  }
4467
- if (current instanceof Error) {
4468
- return generateErrorNode4(ctx, id, current);
4891
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
4892
+ switch (currentClass) {
4893
+ case BigInt64Array:
4894
+ case BigUint64Array:
4895
+ return createBigIntTypedArrayNode2(ctx, id, current);
4896
+ default:
4897
+ break;
4898
+ }
4469
4899
  }
4470
- if (current instanceof Promise) {
4900
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
4901
+ return generateMapNode4(ctx, id, current);
4902
+ }
4903
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
4904
+ return generateSetNode4(ctx, id, current);
4905
+ }
4906
+ if (ctx.features & 8192 /* WebAPI */) {
4907
+ switch (currentClass) {
4908
+ case URL:
4909
+ return createURLNode(id, current);
4910
+ case URLSearchParams:
4911
+ return createURLSearchParamsNode(id, current);
4912
+ case Headers:
4913
+ return generateHeadersNode4(ctx, id, current);
4914
+ case FormData:
4915
+ return generateFormDataNode4(ctx, id, current);
4916
+ case ReadableStream:
4917
+ return generateReadableStreamNode(ctx, id, current);
4918
+ case Request:
4919
+ return generateRequestNode3(ctx, id, current);
4920
+ case Response:
4921
+ return generateResponseNode3(ctx, id, current);
4922
+ case Event:
4923
+ return generateEventNode4(ctx, id, current);
4924
+ case CustomEvent:
4925
+ return generateCustomEventNode4(ctx, id, current);
4926
+ case DOMException:
4927
+ return createDOMExceptionNode(id, current);
4928
+ default:
4929
+ break;
4930
+ }
4931
+ }
4932
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
4933
+ return generateAggregateErrorNode4(ctx, id, current);
4934
+ }
4935
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
4471
4936
  return generatePromiseNode3(ctx, id, current);
4472
4937
  }
4473
- if (Symbol.iterator in current) {
4474
- return generateObjectNode4(ctx, id, current, !!current.constructor);
4938
+ if (current instanceof Error) {
4939
+ return generateErrorNode4(ctx, id, current);
4940
+ }
4941
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
4942
+ return generateObjectNode4(ctx, id, current, !!currentClass);
4475
4943
  }
4476
4944
  throw new UnsupportedTypeError(current);
4477
4945
  }
4478
4946
  function crossParseStream(ctx, current) {
4479
- switch (typeof current) {
4947
+ const t = typeof current;
4948
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
4949
+ return createBigIntNode(current);
4950
+ }
4951
+ switch (t) {
4480
4952
  case "boolean":
4481
4953
  return current ? TRUE_NODE : FALSE_NODE;
4482
4954
  case "undefined":
@@ -4485,8 +4957,6 @@ function crossParseStream(ctx, current) {
4485
4957
  return createStringNode(current);
4486
4958
  case "number":
4487
4959
  return createNumberNode(current);
4488
- case "bigint":
4489
- return createBigIntNode(ctx, current);
4490
4960
  case "object":
4491
4961
  return parseObject4(ctx, current);
4492
4962
  case "symbol":
@@ -4538,7 +5008,6 @@ function generateArrayNode5(ctx, id, current) {
4538
5008
  };
4539
5009
  }
4540
5010
  function generateMapNode5(ctx, id, current) {
4541
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
4542
5011
  const len = current.size;
4543
5012
  const keyNodes = new Array(len);
4544
5013
  const valueNodes = new Array(len);
@@ -4577,7 +5046,6 @@ function generateMapNode5(ctx, id, current) {
4577
5046
  };
4578
5047
  }
4579
5048
  function generateSetNode5(ctx, id, current) {
4580
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
4581
5049
  const len = current.size;
4582
5050
  const nodes = new Array(len);
4583
5051
  const deferred = new Array(len);
@@ -4737,7 +5205,6 @@ function generateErrorNode5(ctx, id, current) {
4737
5205
  };
4738
5206
  }
4739
5207
  function generateHeadersNode5(ctx, id, current) {
4740
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4741
5208
  const items = {};
4742
5209
  current.forEach((value, key) => {
4743
5210
  items[key] = value;
@@ -4758,7 +5225,6 @@ function generateHeadersNode5(ctx, id, current) {
4758
5225
  };
4759
5226
  }
4760
5227
  function generateFormDataNode5(ctx, id, current) {
4761
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4762
5228
  const items = {};
4763
5229
  current.forEach((value, key) => {
4764
5230
  items[key] = value;
@@ -4794,6 +5260,38 @@ function generateBoxedNode5(ctx, id, current) {
4794
5260
  o: void 0
4795
5261
  };
4796
5262
  }
5263
+ function generateEventNode5(ctx, id, current) {
5264
+ return {
5265
+ t: 37 /* Event */,
5266
+ i: id,
5267
+ s: serializeString(current.type),
5268
+ l: void 0,
5269
+ c: void 0,
5270
+ m: void 0,
5271
+ p: void 0,
5272
+ e: void 0,
5273
+ a: void 0,
5274
+ f: parseObject5(ctx, createEventOptions(current)),
5275
+ b: void 0,
5276
+ o: void 0
5277
+ };
5278
+ }
5279
+ function generateCustomEventNode5(ctx, id, current) {
5280
+ return {
5281
+ t: 38 /* CustomEvent */,
5282
+ i: id,
5283
+ s: serializeString(current.type),
5284
+ l: void 0,
5285
+ c: void 0,
5286
+ m: void 0,
5287
+ p: void 0,
5288
+ e: void 0,
5289
+ a: void 0,
5290
+ f: parseObject5(ctx, createCustomEventOptions(current)),
5291
+ b: void 0,
5292
+ o: void 0
5293
+ };
5294
+ }
4797
5295
  function parseObject5(ctx, current) {
4798
5296
  if (!current) {
4799
5297
  return NULL_NODE;
@@ -4810,39 +5308,17 @@ function parseObject5(ctx, current) {
4810
5308
  if (Array.isArray(current)) {
4811
5309
  return generateArrayNode5(ctx, id, current);
4812
5310
  }
4813
- switch (current.constructor) {
5311
+ const currentClass = current.constructor;
5312
+ switch (currentClass) {
4814
5313
  case Number:
4815
5314
  case Boolean:
4816
5315
  case String:
4817
5316
  case BigInt:
4818
- case Function:
4819
- case Symbol:
4820
5317
  return generateBoxedNode5(ctx, id, current);
4821
5318
  case Date:
4822
5319
  return createDateNode(id, current);
4823
5320
  case RegExp:
4824
5321
  return createRegExpNode(id, current);
4825
- case ArrayBuffer:
4826
- return createArrayBufferNode(id, current);
4827
- case Int8Array:
4828
- case Int16Array:
4829
- case Int32Array:
4830
- case Uint8Array:
4831
- case Uint16Array:
4832
- case Uint32Array:
4833
- case Uint8ClampedArray:
4834
- case Float32Array:
4835
- case Float64Array:
4836
- return createTypedArrayNode2(ctx, id, current);
4837
- case BigInt64Array:
4838
- case BigUint64Array:
4839
- return createBigIntTypedArrayNode2(ctx, id, current);
4840
- case DataView:
4841
- return createDataViewNode2(ctx, id, current);
4842
- case Map:
4843
- return generateMapNode5(ctx, id, current);
4844
- case Set:
4845
- return generateSetNode5(ctx, id, current);
4846
5322
  case Object:
4847
5323
  return generateObjectNode5(
4848
5324
  ctx,
@@ -4857,11 +5333,6 @@ function parseObject5(ctx, current) {
4857
5333
  current,
4858
5334
  true
4859
5335
  );
4860
- case AggregateError:
4861
- if (ctx.features & 1 /* AggregateError */) {
4862
- return generateAggregateErrorNode5(ctx, id, current);
4863
- }
4864
- return generateErrorNode5(ctx, id, current);
4865
5336
  case Error:
4866
5337
  case EvalError:
4867
5338
  case RangeError:
@@ -4870,33 +5341,81 @@ function parseObject5(ctx, current) {
4870
5341
  case TypeError:
4871
5342
  case URIError:
4872
5343
  return generateErrorNode5(ctx, id, current);
4873
- case URL:
4874
- return createURLNode(ctx, id, current);
4875
- case URLSearchParams:
4876
- return createURLSearchParamsNode(ctx, id, current);
4877
- case Headers:
4878
- return generateHeadersNode5(ctx, id, current);
4879
- case FormData:
4880
- return generateFormDataNode5(ctx, id, current);
4881
5344
  default:
4882
5345
  break;
4883
5346
  }
4884
- if (current instanceof AggregateError) {
4885
- if (ctx.features & 1 /* AggregateError */) {
4886
- return generateAggregateErrorNode5(ctx, id, current);
5347
+ if (ctx.features & 2048 /* TypedArray */) {
5348
+ switch (currentClass) {
5349
+ case ArrayBuffer:
5350
+ return createArrayBufferNode(id, current);
5351
+ case Int8Array:
5352
+ case Int16Array:
5353
+ case Int32Array:
5354
+ case Uint8Array:
5355
+ case Uint16Array:
5356
+ case Uint32Array:
5357
+ case Uint8ClampedArray:
5358
+ case Float32Array:
5359
+ case Float64Array:
5360
+ return createTypedArrayNode2(ctx, id, current);
5361
+ case DataView:
5362
+ return createDataViewNode2(ctx, id, current);
5363
+ default:
5364
+ break;
4887
5365
  }
4888
- return generateErrorNode5(ctx, id, current);
5366
+ }
5367
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
5368
+ switch (currentClass) {
5369
+ case BigInt64Array:
5370
+ case BigUint64Array:
5371
+ return createBigIntTypedArrayNode2(ctx, id, current);
5372
+ default:
5373
+ break;
5374
+ }
5375
+ }
5376
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
5377
+ return generateMapNode5(ctx, id, current);
5378
+ }
5379
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
5380
+ return generateSetNode5(ctx, id, current);
5381
+ }
5382
+ if (ctx.features & 8192 /* WebAPI */) {
5383
+ switch (currentClass) {
5384
+ case URL:
5385
+ return createURLNode(id, current);
5386
+ case URLSearchParams:
5387
+ return createURLSearchParamsNode(id, current);
5388
+ case Headers:
5389
+ return generateHeadersNode5(ctx, id, current);
5390
+ case FormData:
5391
+ return generateFormDataNode5(ctx, id, current);
5392
+ case Event:
5393
+ return generateEventNode5(ctx, id, current);
5394
+ case CustomEvent:
5395
+ return generateCustomEventNode5(ctx, id, current);
5396
+ case DOMException:
5397
+ return createDOMExceptionNode(id, current);
5398
+ default:
5399
+ break;
5400
+ }
5401
+ }
5402
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
5403
+ return generateAggregateErrorNode5(ctx, id, current);
4889
5404
  }
4890
5405
  if (current instanceof Error) {
4891
5406
  return generateErrorNode5(ctx, id, current);
4892
5407
  }
4893
- if (Symbol.iterator in current) {
4894
- return generateObjectNode5(ctx, id, current, !!current.constructor);
5408
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
5409
+ return generateObjectNode5(ctx, id, current, !!currentClass);
4895
5410
  }
4896
5411
  throw new UnsupportedTypeError(current);
4897
5412
  }
4898
5413
  function crossParseSync(ctx, current) {
4899
- switch (typeof current) {
5414
+ const t = typeof current;
5415
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
5416
+ return createBigIntNode(current);
5417
+ }
5418
+ switch (t) {
4900
5419
  case "boolean":
4901
5420
  return current ? TRUE_NODE : FALSE_NODE;
4902
5421
  case "undefined":
@@ -4905,8 +5424,6 @@ function crossParseSync(ctx, current) {
4905
5424
  return createStringNode(current);
4906
5425
  case "number":
4907
5426
  return createNumberNode(current);
4908
- case "bigint":
4909
- return createBigIntNode(ctx, current);
4910
5427
  case "object":
4911
5428
  return parseObject5(ctx, current);
4912
5429
  case "symbol":