seroval 0.10.4 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 = "_$";
@@ -530,7 +531,6 @@ function serializeArrayBuffer(ctx, current) {
530
531
  return createArrayBufferNode(id, current);
531
532
  }
532
533
  function createTypedArrayNode(ctx, id, current) {
533
- assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
534
534
  return {
535
535
  t: 15 /* TypedArray */,
536
536
  i: id,
@@ -546,12 +546,7 @@ function createTypedArrayNode(ctx, id, current) {
546
546
  o: void 0
547
547
  };
548
548
  }
549
- var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
550
549
  function createBigIntTypedArrayNode(ctx, id, current) {
551
- assert(
552
- (ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
553
- new UnsupportedTypeError(current)
554
- );
555
550
  return {
556
551
  t: 16 /* BigIntTypedArray */,
557
552
  i: id,
@@ -778,8 +773,7 @@ async function createFileNode(ctx, id, current) {
778
773
  }
779
774
 
780
775
  // src/core/web-api.ts
781
- function createURLNode(ctx, id, current) {
782
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
776
+ function createURLNode(id, current) {
783
777
  return {
784
778
  t: 18 /* URL */,
785
779
  i: id,
@@ -795,8 +789,7 @@ function createURLNode(ctx, id, current) {
795
789
  o: void 0
796
790
  };
797
791
  }
798
- function createURLSearchParamsNode(ctx, id, current) {
799
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
792
+ function createURLSearchParamsNode(id, current) {
800
793
  return {
801
794
  t: 19 /* URLSearchParams */,
802
795
  i: id,
@@ -812,6 +805,22 @@ function createURLSearchParamsNode(ctx, id, current) {
812
805
  o: void 0
813
806
  };
814
807
  }
808
+ function createDOMExceptionNode(id, current) {
809
+ return {
810
+ t: 39 /* DOMException */,
811
+ i: id,
812
+ s: serializeString(current.message),
813
+ l: void 0,
814
+ c: serializeString(current.name),
815
+ m: void 0,
816
+ p: void 0,
817
+ e: void 0,
818
+ a: void 0,
819
+ f: void 0,
820
+ b: void 0,
821
+ o: void 0
822
+ };
823
+ }
815
824
 
816
825
  // src/core/promise-to-result.ts
817
826
  async function promiseToResult(current) {
@@ -822,6 +831,45 @@ async function promiseToResult(current) {
822
831
  }
823
832
  }
824
833
 
834
+ // src/core/constructors.ts
835
+ function createRequestOptions(current, body) {
836
+ return {
837
+ body,
838
+ cache: current.cache,
839
+ credentials: current.credentials,
840
+ headers: current.headers,
841
+ integrity: current.integrity,
842
+ keepalive: current.keepalive,
843
+ method: current.method,
844
+ mode: current.mode,
845
+ redirect: current.redirect,
846
+ referrer: current.referrer,
847
+ referrerPolicy: current.referrerPolicy
848
+ };
849
+ }
850
+ function createResponseOptions(current) {
851
+ return {
852
+ headers: current.headers,
853
+ status: current.status,
854
+ statusText: current.statusText
855
+ };
856
+ }
857
+ function createEventOptions(current) {
858
+ return {
859
+ bubbles: current.bubbles,
860
+ cancelable: current.cancelable,
861
+ composed: current.composed
862
+ };
863
+ }
864
+ function createCustomEventOptions(current) {
865
+ return {
866
+ detail: current.detail,
867
+ bubbles: current.bubbles,
868
+ cancelable: current.cancelable,
869
+ composed: current.composed
870
+ };
871
+ }
872
+
825
873
  // src/core/tree/async.ts
826
874
  async function generateNodeList(ctx, current) {
827
875
  const size = current.length;
@@ -862,7 +910,6 @@ async function generateArrayNode(ctx, id, current) {
862
910
  };
863
911
  }
864
912
  async function generateMapNode(ctx, id, current) {
865
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
866
913
  const len = current.size;
867
914
  const keyNodes = new Array(len);
868
915
  const valueNodes = new Array(len);
@@ -901,7 +948,6 @@ async function generateMapNode(ctx, id, current) {
901
948
  };
902
949
  }
903
950
  async function generateSetNode(ctx, id, current) {
904
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
905
951
  const len = current.size;
906
952
  const nodes = new Array(len);
907
953
  const deferred = new Array(len);
@@ -1013,7 +1059,6 @@ async function generatePlainProperties(ctx, properties) {
1013
1059
  };
1014
1060
  }
1015
1061
  async function generatePromiseNode(ctx, id, current) {
1016
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
1017
1062
  const [status, result] = await promiseToResult(current);
1018
1063
  return {
1019
1064
  t: 12 /* Promise */,
@@ -1083,7 +1128,6 @@ async function generateErrorNode(ctx, id, current) {
1083
1128
  };
1084
1129
  }
1085
1130
  async function generateHeadersNode(ctx, id, current) {
1086
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
1087
1131
  const items = {};
1088
1132
  current.forEach((value, key) => {
1089
1133
  items[key] = value;
@@ -1104,7 +1148,6 @@ async function generateHeadersNode(ctx, id, current) {
1104
1148
  };
1105
1149
  }
1106
1150
  async function generateFormDataNode(ctx, id, current) {
1107
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
1108
1151
  const items = {};
1109
1152
  current.forEach((value, key) => {
1110
1153
  items[key] = value;
@@ -1140,6 +1183,76 @@ async function generateBoxedNode(ctx, id, current) {
1140
1183
  o: void 0
1141
1184
  };
1142
1185
  }
1186
+ async function generateRequestNode(ctx, id, current) {
1187
+ return {
1188
+ t: 35 /* Request */,
1189
+ i: id,
1190
+ s: serializeString(current.url),
1191
+ l: void 0,
1192
+ c: void 0,
1193
+ m: void 0,
1194
+ p: void 0,
1195
+ e: void 0,
1196
+ f: await parseObject(
1197
+ ctx,
1198
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
1199
+ ),
1200
+ a: void 0,
1201
+ b: void 0,
1202
+ o: void 0
1203
+ };
1204
+ }
1205
+ async function generateResponseNode(ctx, id, current) {
1206
+ return {
1207
+ t: 36 /* Response */,
1208
+ i: id,
1209
+ s: void 0,
1210
+ l: void 0,
1211
+ c: void 0,
1212
+ m: void 0,
1213
+ p: void 0,
1214
+ e: void 0,
1215
+ f: void 0,
1216
+ a: [
1217
+ current.body ? serializeArrayBuffer(ctx, await current.clone().arrayBuffer()) : NULL_NODE,
1218
+ await parseObject(ctx, createResponseOptions(current))
1219
+ ],
1220
+ b: void 0,
1221
+ o: void 0
1222
+ };
1223
+ }
1224
+ async function generateEventNode(ctx, id, current) {
1225
+ return {
1226
+ t: 37 /* Event */,
1227
+ i: id,
1228
+ s: serializeString(current.type),
1229
+ l: void 0,
1230
+ c: void 0,
1231
+ m: void 0,
1232
+ p: void 0,
1233
+ e: void 0,
1234
+ a: void 0,
1235
+ f: await parseObject(ctx, createEventOptions(current)),
1236
+ b: void 0,
1237
+ o: void 0
1238
+ };
1239
+ }
1240
+ async function generateCustomEventNode(ctx, id, current) {
1241
+ return {
1242
+ t: 38 /* CustomEvent */,
1243
+ i: id,
1244
+ s: serializeString(current.type),
1245
+ l: void 0,
1246
+ c: void 0,
1247
+ m: void 0,
1248
+ p: void 0,
1249
+ e: void 0,
1250
+ a: void 0,
1251
+ f: await parseObject(ctx, createCustomEventOptions(current)),
1252
+ b: void 0,
1253
+ o: void 0
1254
+ };
1255
+ }
1143
1256
  async function parseObject(ctx, current) {
1144
1257
  if (!current) {
1145
1258
  return NULL_NODE;
@@ -1154,49 +1267,17 @@ async function parseObject(ctx, current) {
1154
1267
  if (Array.isArray(current)) {
1155
1268
  return generateArrayNode(ctx, id, current);
1156
1269
  }
1157
- switch (current.constructor) {
1270
+ const currentClass = current.constructor;
1271
+ switch (currentClass) {
1158
1272
  case Number:
1159
1273
  case Boolean:
1160
1274
  case String:
1161
1275
  case BigInt:
1162
- case Function:
1163
- case Symbol:
1164
1276
  return generateBoxedNode(ctx, id, current);
1165
1277
  case Date:
1166
1278
  return createDateNode(id, current);
1167
1279
  case RegExp:
1168
1280
  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
1281
  case Object:
1201
1282
  return generateObjectNode(
1202
1283
  ctx,
@@ -1211,11 +1292,6 @@ async function parseObject(ctx, current) {
1211
1292
  current,
1212
1293
  true
1213
1294
  );
1214
- case AggregateError:
1215
- if (ctx.features & 1 /* AggregateError */) {
1216
- return generateAggregateErrorNode(ctx, id, current);
1217
- }
1218
- return generateErrorNode(ctx, id, current);
1219
1295
  case Error:
1220
1296
  case EvalError:
1221
1297
  case RangeError:
@@ -1224,40 +1300,100 @@ async function parseObject(ctx, current) {
1224
1300
  case TypeError:
1225
1301
  case URIError:
1226
1302
  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
1303
  default:
1240
1304
  break;
1241
1305
  }
1242
- if (current instanceof AggregateError) {
1243
- if (ctx.features & 1 /* AggregateError */) {
1244
- return generateAggregateErrorNode(ctx, id, current);
1306
+ if (ctx.features & 2048 /* TypedArray */) {
1307
+ switch (currentClass) {
1308
+ case ArrayBuffer:
1309
+ return createArrayBufferNode(id, current);
1310
+ case Int8Array:
1311
+ case Int16Array:
1312
+ case Int32Array:
1313
+ case Uint8Array:
1314
+ case Uint16Array:
1315
+ case Uint32Array:
1316
+ case Uint8ClampedArray:
1317
+ case Float32Array:
1318
+ case Float64Array:
1319
+ return createTypedArrayNode(ctx, id, current);
1320
+ case DataView:
1321
+ return createDataViewNode(ctx, id, current);
1322
+ default:
1323
+ break;
1245
1324
  }
1246
- return generateErrorNode(ctx, id, current);
1247
1325
  }
1248
- if (current instanceof Error) {
1249
- return generateErrorNode(ctx, id, current);
1326
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
1327
+ switch (currentClass) {
1328
+ case BigInt64Array:
1329
+ case BigUint64Array:
1330
+ return createBigIntTypedArrayNode(ctx, id, current);
1331
+ default:
1332
+ break;
1333
+ }
1334
+ }
1335
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
1336
+ return generateMapNode(
1337
+ ctx,
1338
+ id,
1339
+ current
1340
+ );
1341
+ }
1342
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
1343
+ return generateSetNode(
1344
+ ctx,
1345
+ id,
1346
+ current
1347
+ );
1250
1348
  }
1251
- if (current instanceof Promise) {
1349
+ if (ctx.features & 8192 /* WebAPI */) {
1350
+ switch (currentClass) {
1351
+ case URL:
1352
+ return createURLNode(id, current);
1353
+ case URLSearchParams:
1354
+ return createURLSearchParamsNode(id, current);
1355
+ case Blob:
1356
+ return createBlobNode(ctx, id, current);
1357
+ case File:
1358
+ return createFileNode(ctx, id, current);
1359
+ case Headers:
1360
+ return generateHeadersNode(ctx, id, current);
1361
+ case FormData:
1362
+ return generateFormDataNode(ctx, id, current);
1363
+ case Request:
1364
+ return generateRequestNode(ctx, id, current);
1365
+ case Response:
1366
+ return generateResponseNode(ctx, id, current);
1367
+ case Event:
1368
+ return generateEventNode(ctx, id, current);
1369
+ case CustomEvent:
1370
+ return generateCustomEventNode(ctx, id, current);
1371
+ case DOMException:
1372
+ return createDOMExceptionNode(id, current);
1373
+ default:
1374
+ break;
1375
+ }
1376
+ }
1377
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
1378
+ return generateAggregateErrorNode(ctx, id, current);
1379
+ }
1380
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
1252
1381
  return generatePromiseNode(ctx, id, current);
1253
1382
  }
1254
- if (Symbol.iterator in current) {
1255
- return generateObjectNode(ctx, id, current, !!current.constructor);
1383
+ if (current instanceof Error) {
1384
+ return generateErrorNode(ctx, id, current);
1385
+ }
1386
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
1387
+ return generateObjectNode(ctx, id, current, !!currentClass);
1256
1388
  }
1257
1389
  throw new UnsupportedTypeError(current);
1258
1390
  }
1259
1391
  async function parseAsync(ctx, current) {
1260
- switch (typeof current) {
1392
+ const t = typeof current;
1393
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
1394
+ return createBigIntNode(ctx, current);
1395
+ }
1396
+ switch (t) {
1261
1397
  case "boolean":
1262
1398
  return current ? TRUE_NODE : FALSE_NODE;
1263
1399
  case "undefined":
@@ -1266,8 +1402,6 @@ async function parseAsync(ctx, current) {
1266
1402
  return createStringNode(current);
1267
1403
  case "number":
1268
1404
  return createNumberNode(current);
1269
- case "bigint":
1270
- return createBigIntNode(ctx, current);
1271
1405
  case "object":
1272
1406
  return parseObject(ctx, current);
1273
1407
  case "symbol":
@@ -1508,6 +1642,53 @@ function deserializeBoxed(ctx, node) {
1508
1642
  Object(deserializeTree(ctx, node.f))
1509
1643
  );
1510
1644
  }
1645
+ function deserializeRequest(ctx, node) {
1646
+ return assignIndexedValue(
1647
+ ctx,
1648
+ node.i,
1649
+ new Request(deserializeString(node.s), deserializeTree(ctx, node.f))
1650
+ );
1651
+ }
1652
+ function deserializeResponse(ctx, node) {
1653
+ return assignIndexedValue(
1654
+ ctx,
1655
+ node.i,
1656
+ new Response(
1657
+ deserializeTree(ctx, node.a[0]),
1658
+ deserializeTree(ctx, node.a[1])
1659
+ )
1660
+ );
1661
+ }
1662
+ function deserializeEvent(ctx, node) {
1663
+ return assignIndexedValue(
1664
+ ctx,
1665
+ node.i,
1666
+ new Event(
1667
+ deserializeString(node.s),
1668
+ deserializeTree(ctx, node.f)
1669
+ )
1670
+ );
1671
+ }
1672
+ function deserializeCustomEvent(ctx, node) {
1673
+ return assignIndexedValue(
1674
+ ctx,
1675
+ node.i,
1676
+ new CustomEvent(
1677
+ deserializeString(node.s),
1678
+ deserializeTree(ctx, node.f)
1679
+ )
1680
+ );
1681
+ }
1682
+ function deserializeDOMException(ctx, node) {
1683
+ return assignIndexedValue(
1684
+ ctx,
1685
+ node.i,
1686
+ new DOMException(
1687
+ deserializeString(node.s),
1688
+ deserializeString(node.c)
1689
+ )
1690
+ );
1691
+ }
1511
1692
  function deserializeTree(ctx, node) {
1512
1693
  switch (node.t) {
1513
1694
  case 2 /* Constant */:
@@ -1564,6 +1745,16 @@ function deserializeTree(ctx, node) {
1564
1745
  return deserializeFormData(ctx, node);
1565
1746
  case 27 /* Boxed */:
1566
1747
  return deserializeBoxed(ctx, node);
1748
+ case 35 /* Request */:
1749
+ return deserializeRequest(ctx, node);
1750
+ case 36 /* Response */:
1751
+ return deserializeResponse(ctx, node);
1752
+ case 37 /* Event */:
1753
+ return deserializeEvent(ctx, node);
1754
+ case 38 /* CustomEvent */:
1755
+ return deserializeCustomEvent(ctx, node);
1756
+ case 39 /* DOMException */:
1757
+ return deserializeDOMException(ctx, node);
1567
1758
  default:
1568
1759
  throw new Error("invariant");
1569
1760
  }
@@ -2138,6 +2329,33 @@ function serializeBoxed(ctx, node) {
2138
2329
  function serializeWKSymbol(ctx, node) {
2139
2330
  return assignIndexedValue2(ctx, node.i, SYMBOL_STRING[node.s]);
2140
2331
  }
2332
+ function serializeRequest(ctx, node) {
2333
+ return assignIndexedValue2(ctx, node.i, 'new Request("' + node.s + '",' + serializeTree(ctx, node.f) + ")");
2334
+ }
2335
+ function serializeResponse(ctx, node) {
2336
+ return assignIndexedValue2(ctx, node.i, "new Response(" + serializeTree(ctx, node.a[0]) + "," + serializeTree(ctx, node.a[1]) + ")");
2337
+ }
2338
+ function serializeEvent(ctx, node) {
2339
+ return assignIndexedValue2(
2340
+ ctx,
2341
+ node.i,
2342
+ 'new Event("' + node.s + '",' + serializeTree(ctx, node.f) + ")"
2343
+ );
2344
+ }
2345
+ function serializeCustomEvent(ctx, node) {
2346
+ return assignIndexedValue2(
2347
+ ctx,
2348
+ node.i,
2349
+ 'new CustomEvent("' + node.s + '",' + serializeTree(ctx, node.f) + ")"
2350
+ );
2351
+ }
2352
+ function serializeDOMException(ctx, node) {
2353
+ return assignIndexedValue2(
2354
+ ctx,
2355
+ node.i,
2356
+ 'new DOMException("' + node.s + '","' + node.c + '")'
2357
+ );
2358
+ }
2141
2359
  function serializeTree(ctx, node) {
2142
2360
  switch (node.t) {
2143
2361
  case 0 /* Number */:
@@ -2195,6 +2413,16 @@ function serializeTree(ctx, node) {
2195
2413
  return serializeFormData(ctx, node);
2196
2414
  case 27 /* Boxed */:
2197
2415
  return serializeBoxed(ctx, node);
2416
+ case 35 /* Request */:
2417
+ return serializeRequest(ctx, node);
2418
+ case 36 /* Response */:
2419
+ return serializeResponse(ctx, node);
2420
+ case 37 /* Event */:
2421
+ return serializeEvent(ctx, node);
2422
+ case 38 /* CustomEvent */:
2423
+ return serializeCustomEvent(ctx, node);
2424
+ case 39 /* DOMException */:
2425
+ return serializeDOMException(ctx, node);
2198
2426
  default:
2199
2427
  throw new Error("invariant");
2200
2428
  }
@@ -2240,7 +2468,6 @@ function generateArrayNode2(ctx, id, current) {
2240
2468
  };
2241
2469
  }
2242
2470
  function generateMapNode2(ctx, id, current) {
2243
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
2244
2471
  const len = current.size;
2245
2472
  const keyNodes = new Array(len);
2246
2473
  const valueNodes = new Array(len);
@@ -2279,7 +2506,6 @@ function generateMapNode2(ctx, id, current) {
2279
2506
  };
2280
2507
  }
2281
2508
  function generateSetNode2(ctx, id, current) {
2282
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
2283
2509
  const len = current.size;
2284
2510
  const nodes = new Array(len);
2285
2511
  const deferred = new Array(len);
@@ -2440,7 +2666,6 @@ function generateErrorNode2(ctx, id, current) {
2440
2666
  };
2441
2667
  }
2442
2668
  function generateHeadersNode2(ctx, id, current) {
2443
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2444
2669
  const items = {};
2445
2670
  current.forEach((value, key) => {
2446
2671
  items[key] = value;
@@ -2461,7 +2686,6 @@ function generateHeadersNode2(ctx, id, current) {
2461
2686
  };
2462
2687
  }
2463
2688
  function generateFormDataNode2(ctx, id, current) {
2464
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
2465
2689
  const items = {};
2466
2690
  current.forEach((value, key) => {
2467
2691
  items[key] = value;
@@ -2497,6 +2721,38 @@ function generateBoxedNode2(ctx, id, current) {
2497
2721
  o: void 0
2498
2722
  };
2499
2723
  }
2724
+ function generateEventNode2(ctx, id, current) {
2725
+ return {
2726
+ t: 37 /* Event */,
2727
+ i: id,
2728
+ s: serializeString(current.type),
2729
+ l: void 0,
2730
+ c: void 0,
2731
+ m: void 0,
2732
+ p: void 0,
2733
+ e: void 0,
2734
+ a: void 0,
2735
+ f: parseObject2(ctx, createEventOptions(current)),
2736
+ b: void 0,
2737
+ o: void 0
2738
+ };
2739
+ }
2740
+ function generateCustomEventNode2(ctx, id, current) {
2741
+ return {
2742
+ t: 38 /* CustomEvent */,
2743
+ i: id,
2744
+ s: serializeString(current.type),
2745
+ l: void 0,
2746
+ c: void 0,
2747
+ m: void 0,
2748
+ p: void 0,
2749
+ e: void 0,
2750
+ a: void 0,
2751
+ f: parseObject2(ctx, createCustomEventOptions(current)),
2752
+ b: void 0,
2753
+ o: void 0
2754
+ };
2755
+ }
2500
2756
  function parseObject2(ctx, current) {
2501
2757
  if (!current) {
2502
2758
  return NULL_NODE;
@@ -2511,39 +2767,17 @@ function parseObject2(ctx, current) {
2511
2767
  if (Array.isArray(current)) {
2512
2768
  return generateArrayNode2(ctx, id, current);
2513
2769
  }
2514
- switch (current.constructor) {
2770
+ const currentClass = current.constructor;
2771
+ switch (currentClass) {
2515
2772
  case Number:
2516
2773
  case Boolean:
2517
2774
  case String:
2518
2775
  case BigInt:
2519
- case Function:
2520
- case Symbol:
2521
2776
  return generateBoxedNode2(ctx, id, current);
2522
2777
  case Date:
2523
2778
  return createDateNode(id, current);
2524
2779
  case RegExp:
2525
2780
  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
2781
  case Object:
2548
2782
  return generateObjectNode2(
2549
2783
  ctx,
@@ -2558,11 +2792,6 @@ function parseObject2(ctx, current) {
2558
2792
  current,
2559
2793
  true
2560
2794
  );
2561
- case AggregateError:
2562
- if (ctx.features & 1 /* AggregateError */) {
2563
- return generateAggregateErrorNode2(ctx, id, current);
2564
- }
2565
- return generateErrorNode2(ctx, id, current);
2566
2795
  case Error:
2567
2796
  case EvalError:
2568
2797
  case RangeError:
@@ -2571,33 +2800,81 @@ function parseObject2(ctx, current) {
2571
2800
  case TypeError:
2572
2801
  case URIError:
2573
2802
  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
2803
  default:
2583
2804
  break;
2584
2805
  }
2585
- if (current instanceof AggregateError) {
2586
- if (ctx.features & 1 /* AggregateError */) {
2587
- return generateAggregateErrorNode2(ctx, id, current);
2806
+ if (ctx.features & 2048 /* TypedArray */) {
2807
+ switch (currentClass) {
2808
+ case ArrayBuffer:
2809
+ return createArrayBufferNode(id, current);
2810
+ case Int8Array:
2811
+ case Int16Array:
2812
+ case Int32Array:
2813
+ case Uint8Array:
2814
+ case Uint16Array:
2815
+ case Uint32Array:
2816
+ case Uint8ClampedArray:
2817
+ case Float32Array:
2818
+ case Float64Array:
2819
+ return createTypedArrayNode(ctx, id, current);
2820
+ case DataView:
2821
+ return createDataViewNode(ctx, id, current);
2822
+ default:
2823
+ break;
2824
+ }
2825
+ }
2826
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
2827
+ switch (currentClass) {
2828
+ case BigInt64Array:
2829
+ case BigUint64Array:
2830
+ return createBigIntTypedArrayNode(ctx, id, current);
2831
+ default:
2832
+ break;
2588
2833
  }
2589
- return generateErrorNode2(ctx, id, current);
2834
+ }
2835
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
2836
+ return generateMapNode2(ctx, id, current);
2837
+ }
2838
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
2839
+ return generateSetNode2(ctx, id, current);
2840
+ }
2841
+ if (ctx.features & 8192 /* WebAPI */) {
2842
+ switch (currentClass) {
2843
+ case URL:
2844
+ return createURLNode(id, current);
2845
+ case URLSearchParams:
2846
+ return createURLSearchParamsNode(id, current);
2847
+ case Headers:
2848
+ return generateHeadersNode2(ctx, id, current);
2849
+ case FormData:
2850
+ return generateFormDataNode2(ctx, id, current);
2851
+ case Event:
2852
+ return generateEventNode2(ctx, id, current);
2853
+ case CustomEvent:
2854
+ return generateCustomEventNode2(ctx, id, current);
2855
+ case DOMException:
2856
+ return createDOMExceptionNode(id, current);
2857
+ default:
2858
+ break;
2859
+ }
2860
+ }
2861
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
2862
+ return generateAggregateErrorNode2(ctx, id, current);
2590
2863
  }
2591
2864
  if (current instanceof Error) {
2592
2865
  return generateErrorNode2(ctx, id, current);
2593
2866
  }
2594
- if (Symbol.iterator in current) {
2595
- return generateObjectNode2(ctx, id, current, !!current.constructor);
2867
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
2868
+ return generateObjectNode2(ctx, id, current, !!currentClass);
2596
2869
  }
2597
2870
  throw new UnsupportedTypeError(current);
2598
2871
  }
2599
2872
  function parseSync(ctx, current) {
2600
- switch (typeof current) {
2873
+ const t = typeof current;
2874
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
2875
+ return createBigIntNode(ctx, current);
2876
+ }
2877
+ switch (t) {
2601
2878
  case "boolean":
2602
2879
  return current ? TRUE_NODE : FALSE_NODE;
2603
2880
  case "undefined":
@@ -2606,8 +2883,6 @@ function parseSync(ctx, current) {
2606
2883
  return createStringNode(current);
2607
2884
  case "number":
2608
2885
  return createNumberNode(current);
2609
- case "bigint":
2610
- return createBigIntNode(ctx, current);
2611
2886
  case "object":
2612
2887
  return parseObject2(ctx, current);
2613
2888
  case "symbol":
@@ -2919,7 +3194,6 @@ async function generateArrayNode3(ctx, id, current) {
2919
3194
  };
2920
3195
  }
2921
3196
  async function generateMapNode3(ctx, id, current) {
2922
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
2923
3197
  const len = current.size;
2924
3198
  const keyNodes = new Array(len);
2925
3199
  const valueNodes = new Array(len);
@@ -2958,7 +3232,6 @@ async function generateMapNode3(ctx, id, current) {
2958
3232
  };
2959
3233
  }
2960
3234
  async function generateSetNode3(ctx, id, current) {
2961
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
2962
3235
  const len = current.size;
2963
3236
  const nodes = new Array(len);
2964
3237
  const deferred = new Array(len);
@@ -3070,7 +3343,6 @@ async function generatePlainProperties3(ctx, properties) {
3070
3343
  };
3071
3344
  }
3072
3345
  async function generatePromiseNode2(ctx, id, current) {
3073
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
3074
3346
  const [status, result] = await promiseToResult(current);
3075
3347
  return {
3076
3348
  t: 12 /* Promise */,
@@ -3140,7 +3412,6 @@ async function generateErrorNode3(ctx, id, current) {
3140
3412
  };
3141
3413
  }
3142
3414
  async function generateHeadersNode3(ctx, id, current) {
3143
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3144
3415
  const items = {};
3145
3416
  current.forEach((value, key) => {
3146
3417
  items[key] = value;
@@ -3161,7 +3432,6 @@ async function generateHeadersNode3(ctx, id, current) {
3161
3432
  };
3162
3433
  }
3163
3434
  async function generateFormDataNode3(ctx, id, current) {
3164
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
3165
3435
  const items = {};
3166
3436
  current.forEach((value, key) => {
3167
3437
  items[key] = value;
@@ -3197,6 +3467,76 @@ async function generateBoxedNode3(ctx, id, current) {
3197
3467
  o: void 0
3198
3468
  };
3199
3469
  }
3470
+ async function generateRequestNode2(ctx, id, current) {
3471
+ return {
3472
+ t: 35 /* Request */,
3473
+ i: id,
3474
+ s: serializeString(current.url),
3475
+ l: void 0,
3476
+ c: void 0,
3477
+ m: void 0,
3478
+ p: void 0,
3479
+ e: void 0,
3480
+ f: await parseObject3(
3481
+ ctx,
3482
+ createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
3483
+ ),
3484
+ a: void 0,
3485
+ b: void 0,
3486
+ o: void 0
3487
+ };
3488
+ }
3489
+ async function generateResponseNode2(ctx, id, current) {
3490
+ return {
3491
+ t: 36 /* Response */,
3492
+ i: id,
3493
+ s: void 0,
3494
+ l: void 0,
3495
+ c: void 0,
3496
+ m: void 0,
3497
+ p: void 0,
3498
+ e: void 0,
3499
+ f: void 0,
3500
+ a: [
3501
+ current.body ? serializeArrayBuffer3(ctx, await current.clone().arrayBuffer()) : NULL_NODE,
3502
+ await parseObject3(ctx, createResponseOptions(current))
3503
+ ],
3504
+ b: void 0,
3505
+ o: void 0
3506
+ };
3507
+ }
3508
+ async function generateEventNode3(ctx, id, current) {
3509
+ return {
3510
+ t: 37 /* Event */,
3511
+ i: id,
3512
+ s: serializeString(current.type),
3513
+ l: void 0,
3514
+ c: void 0,
3515
+ m: void 0,
3516
+ p: void 0,
3517
+ e: void 0,
3518
+ a: void 0,
3519
+ f: await parseObject3(ctx, createEventOptions(current)),
3520
+ b: void 0,
3521
+ o: void 0
3522
+ };
3523
+ }
3524
+ async function generateCustomEventNode3(ctx, id, current) {
3525
+ return {
3526
+ t: 38 /* CustomEvent */,
3527
+ i: id,
3528
+ s: serializeString(current.type),
3529
+ l: void 0,
3530
+ c: void 0,
3531
+ m: void 0,
3532
+ p: void 0,
3533
+ e: void 0,
3534
+ a: void 0,
3535
+ f: await parseObject3(ctx, createCustomEventOptions(current)),
3536
+ b: void 0,
3537
+ o: void 0
3538
+ };
3539
+ }
3200
3540
  async function parseObject3(ctx, current) {
3201
3541
  if (!current) {
3202
3542
  return NULL_NODE;
@@ -3213,49 +3553,17 @@ async function parseObject3(ctx, current) {
3213
3553
  if (Array.isArray(current)) {
3214
3554
  return generateArrayNode3(ctx, id, current);
3215
3555
  }
3216
- switch (current.constructor) {
3556
+ const currentClass = current.constructor;
3557
+ switch (currentClass) {
3217
3558
  case Number:
3218
3559
  case Boolean:
3219
3560
  case String:
3220
3561
  case BigInt:
3221
- case Function:
3222
- case Symbol:
3223
3562
  return generateBoxedNode3(ctx, id, current);
3224
3563
  case Date:
3225
3564
  return createDateNode(id, current);
3226
3565
  case RegExp:
3227
3566
  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
3567
  case Object:
3260
3568
  return generateObjectNode3(
3261
3569
  ctx,
@@ -3270,11 +3578,6 @@ async function parseObject3(ctx, current) {
3270
3578
  current,
3271
3579
  true
3272
3580
  );
3273
- case AggregateError:
3274
- if (ctx.features & 1 /* AggregateError */) {
3275
- return generateAggregateErrorNode3(ctx, id, current);
3276
- }
3277
- return generateErrorNode3(ctx, id, current);
3278
3581
  case Error:
3279
3582
  case EvalError:
3280
3583
  case RangeError:
@@ -3283,40 +3586,100 @@ async function parseObject3(ctx, current) {
3283
3586
  case TypeError:
3284
3587
  case URIError:
3285
3588
  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
3589
  default:
3299
3590
  break;
3300
3591
  }
3301
- if (current instanceof AggregateError) {
3302
- if (ctx.features & 1 /* AggregateError */) {
3303
- return generateAggregateErrorNode3(ctx, id, current);
3592
+ if (ctx.features & 2048 /* TypedArray */) {
3593
+ switch (currentClass) {
3594
+ case ArrayBuffer:
3595
+ return createArrayBufferNode(id, current);
3596
+ case Int8Array:
3597
+ case Int16Array:
3598
+ case Int32Array:
3599
+ case Uint8Array:
3600
+ case Uint16Array:
3601
+ case Uint32Array:
3602
+ case Uint8ClampedArray:
3603
+ case Float32Array:
3604
+ case Float64Array:
3605
+ return createTypedArrayNode2(ctx, id, current);
3606
+ case DataView:
3607
+ return createDataViewNode2(ctx, id, current);
3608
+ default:
3609
+ break;
3304
3610
  }
3305
- return generateErrorNode3(ctx, id, current);
3306
3611
  }
3307
- if (current instanceof Error) {
3308
- return generateErrorNode3(ctx, id, current);
3612
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
3613
+ switch (currentClass) {
3614
+ case BigInt64Array:
3615
+ case BigUint64Array:
3616
+ return createBigIntTypedArrayNode2(ctx, id, current);
3617
+ default:
3618
+ break;
3619
+ }
3620
+ }
3621
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
3622
+ return generateMapNode3(
3623
+ ctx,
3624
+ id,
3625
+ current
3626
+ );
3309
3627
  }
3310
- if (current instanceof Promise) {
3628
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
3629
+ return generateSetNode3(
3630
+ ctx,
3631
+ id,
3632
+ current
3633
+ );
3634
+ }
3635
+ if (ctx.features & 8192 /* WebAPI */) {
3636
+ switch (currentClass) {
3637
+ case URL:
3638
+ return createURLNode(id, current);
3639
+ case URLSearchParams:
3640
+ return createURLSearchParamsNode(id, current);
3641
+ case Blob:
3642
+ return createBlobNode2(ctx, id, current);
3643
+ case File:
3644
+ return createFileNode2(ctx, id, current);
3645
+ case Headers:
3646
+ return generateHeadersNode3(ctx, id, current);
3647
+ case FormData:
3648
+ return generateFormDataNode3(ctx, id, current);
3649
+ case Request:
3650
+ return generateRequestNode2(ctx, id, current);
3651
+ case Response:
3652
+ return generateResponseNode2(ctx, id, current);
3653
+ case Event:
3654
+ return generateEventNode3(ctx, id, current);
3655
+ case CustomEvent:
3656
+ return generateCustomEventNode3(ctx, id, current);
3657
+ case DOMException:
3658
+ return createDOMExceptionNode(id, current);
3659
+ default:
3660
+ break;
3661
+ }
3662
+ }
3663
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
3664
+ return generateAggregateErrorNode3(ctx, id, current);
3665
+ }
3666
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
3311
3667
  return generatePromiseNode2(ctx, id, current);
3312
3668
  }
3313
- if (Symbol.iterator in current) {
3314
- return generateObjectNode3(ctx, id, current, !!current.constructor);
3669
+ if (current instanceof Error) {
3670
+ return generateErrorNode3(ctx, id, current);
3671
+ }
3672
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
3673
+ return generateObjectNode3(ctx, id, current, !!currentClass);
3315
3674
  }
3316
3675
  throw new UnsupportedTypeError(current);
3317
3676
  }
3318
3677
  async function crossParseAsync(ctx, current) {
3319
- switch (typeof current) {
3678
+ const t = typeof current;
3679
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
3680
+ return createBigIntNode(ctx, current);
3681
+ }
3682
+ switch (t) {
3320
3683
  case "boolean":
3321
3684
  return current ? TRUE_NODE : FALSE_NODE;
3322
3685
  case "undefined":
@@ -3325,8 +3688,6 @@ async function crossParseAsync(ctx, current) {
3325
3688
  return createStringNode(current);
3326
3689
  case "number":
3327
3690
  return createNumberNode(current);
3328
- case "bigint":
3329
- return createBigIntNode(ctx, current);
3330
3691
  case "object":
3331
3692
  return parseObject3(ctx, current);
3332
3693
  case "symbol":
@@ -3806,6 +4167,33 @@ function serializeReadableStreamError(ctx, node) {
3806
4167
  function serializeReadableStreamConstructor(node) {
3807
4168
  return assignIndexedValue3(node.i, GLOBAL_CONTEXT_API + "." + GLOBAL_CONTEXT_STREAM_CONSTRUCTOR + "()");
3808
4169
  }
4170
+ function serializeRequest2(ctx, node) {
4171
+ return assignIndexedValue3(node.i, 'new Request("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")");
4172
+ }
4173
+ function serializeResponse2(ctx, node) {
4174
+ return assignIndexedValue3(
4175
+ node.i,
4176
+ "new Response(" + crossSerializeTree(ctx, node.a[0]) + "," + crossSerializeTree(ctx, node.a[1]) + ")"
4177
+ );
4178
+ }
4179
+ function serializeEvent2(ctx, node) {
4180
+ return assignIndexedValue3(
4181
+ node.i,
4182
+ 'new Event("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")"
4183
+ );
4184
+ }
4185
+ function serializeCustomEvent2(ctx, node) {
4186
+ return assignIndexedValue3(
4187
+ node.i,
4188
+ 'new CustomEvent("' + node.s + '",' + crossSerializeTree(ctx, node.f) + ")"
4189
+ );
4190
+ }
4191
+ function serializeDOMException2(node) {
4192
+ return assignIndexedValue3(
4193
+ node.i,
4194
+ 'new DOMException("' + node.s + '","' + node.c + '")'
4195
+ );
4196
+ }
3809
4197
  function crossSerializeTree(ctx, node) {
3810
4198
  switch (node.t) {
3811
4199
  case 0 /* Number */:
@@ -3877,6 +4265,16 @@ function crossSerializeTree(ctx, node) {
3877
4265
  return serializeReadableStreamEnqueue(ctx, node);
3878
4266
  case 34 /* ReadableStreamError */:
3879
4267
  return serializeReadableStreamError(ctx, node);
4268
+ case 35 /* Request */:
4269
+ return serializeRequest2(ctx, node);
4270
+ case 36 /* Response */:
4271
+ return serializeResponse2(ctx, node);
4272
+ case 37 /* Event */:
4273
+ return serializeEvent2(ctx, node);
4274
+ case 38 /* CustomEvent */:
4275
+ return serializeCustomEvent2(ctx, node);
4276
+ case 39 /* DOMException */:
4277
+ return serializeDOMException2(node);
3880
4278
  default:
3881
4279
  throw new Error("invariant");
3882
4280
  }
@@ -3922,7 +4320,6 @@ function generateArrayNode4(ctx, id, current) {
3922
4320
  };
3923
4321
  }
3924
4322
  function generateMapNode4(ctx, id, current) {
3925
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
3926
4323
  const len = current.size;
3927
4324
  const keyNodes = new Array(len);
3928
4325
  const valueNodes = new Array(len);
@@ -3961,7 +4358,6 @@ function generateMapNode4(ctx, id, current) {
3961
4358
  };
3962
4359
  }
3963
4360
  function generateSetNode4(ctx, id, current) {
3964
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
3965
4361
  const len = current.size;
3966
4362
  const nodes = new Array(len);
3967
4363
  const deferred = new Array(len);
@@ -4073,7 +4469,6 @@ function generatePlainProperties4(ctx, properties) {
4073
4469
  };
4074
4470
  }
4075
4471
  function generatePromiseNode3(ctx, id, current) {
4076
- assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
4077
4472
  current.then(
4078
4473
  (data) => {
4079
4474
  if (ctx.alive) {
@@ -4183,7 +4578,6 @@ function generateErrorNode4(ctx, id, current) {
4183
4578
  };
4184
4579
  }
4185
4580
  function generateHeadersNode4(ctx, id, current) {
4186
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4187
4581
  const items = {};
4188
4582
  current.forEach((value, key) => {
4189
4583
  items[key] = value;
@@ -4204,7 +4598,6 @@ function generateHeadersNode4(ctx, id, current) {
4204
4598
  };
4205
4599
  }
4206
4600
  function generateFormDataNode4(ctx, id, current) {
4207
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4208
4601
  const items = {};
4209
4602
  current.forEach((value, key) => {
4210
4603
  items[key] = value;
@@ -4241,7 +4634,6 @@ function generateBoxedNode4(ctx, id, current) {
4241
4634
  };
4242
4635
  }
4243
4636
  function generateReadableStreamNode(ctx, id, current) {
4244
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4245
4637
  const reader = current.getReader();
4246
4638
  pushPendingState(ctx);
4247
4639
  function push() {
@@ -4320,6 +4712,76 @@ function generateReadableStreamNode(ctx, id, current) {
4320
4712
  o: void 0
4321
4713
  };
4322
4714
  }
4715
+ function generateRequestNode3(ctx, id, current) {
4716
+ return {
4717
+ t: 35 /* Request */,
4718
+ i: id,
4719
+ s: serializeString(current.url),
4720
+ l: void 0,
4721
+ c: void 0,
4722
+ m: void 0,
4723
+ p: void 0,
4724
+ e: void 0,
4725
+ f: parseObject4(
4726
+ ctx,
4727
+ createRequestOptions(current, current.clone().body)
4728
+ ),
4729
+ a: void 0,
4730
+ b: void 0,
4731
+ o: void 0
4732
+ };
4733
+ }
4734
+ function generateResponseNode3(ctx, id, current) {
4735
+ return {
4736
+ t: 36 /* Response */,
4737
+ i: id,
4738
+ s: void 0,
4739
+ l: void 0,
4740
+ c: void 0,
4741
+ m: void 0,
4742
+ p: void 0,
4743
+ e: void 0,
4744
+ f: void 0,
4745
+ a: [
4746
+ current.body ? parseObject4(ctx, current.clone().body) : NULL_NODE,
4747
+ parseObject4(ctx, createResponseOptions(current))
4748
+ ],
4749
+ b: void 0,
4750
+ o: void 0
4751
+ };
4752
+ }
4753
+ function generateEventNode4(ctx, id, current) {
4754
+ return {
4755
+ t: 37 /* Event */,
4756
+ i: id,
4757
+ s: serializeString(current.type),
4758
+ l: void 0,
4759
+ c: void 0,
4760
+ m: void 0,
4761
+ p: void 0,
4762
+ e: void 0,
4763
+ a: void 0,
4764
+ f: parseObject4(ctx, createEventOptions(current)),
4765
+ b: void 0,
4766
+ o: void 0
4767
+ };
4768
+ }
4769
+ function generateCustomEventNode4(ctx, id, current) {
4770
+ return {
4771
+ t: 38 /* CustomEvent */,
4772
+ i: id,
4773
+ s: serializeString(current.type),
4774
+ l: void 0,
4775
+ c: void 0,
4776
+ m: void 0,
4777
+ p: void 0,
4778
+ e: void 0,
4779
+ a: void 0,
4780
+ f: parseObject4(ctx, createCustomEventOptions(current)),
4781
+ b: void 0,
4782
+ o: void 0
4783
+ };
4784
+ }
4323
4785
  function parseObject4(ctx, current) {
4324
4786
  if (!current) {
4325
4787
  return NULL_NODE;
@@ -4336,7 +4798,8 @@ function parseObject4(ctx, current) {
4336
4798
  if (Array.isArray(current)) {
4337
4799
  return generateArrayNode4(ctx, id, current);
4338
4800
  }
4339
- switch (current.constructor) {
4801
+ const currentClass = current.constructor;
4802
+ switch (currentClass) {
4340
4803
  case Number:
4341
4804
  case Boolean:
4342
4805
  case String:
@@ -4348,37 +4811,6 @@ function parseObject4(ctx, current) {
4348
4811
  return createDateNode(id, current);
4349
4812
  case RegExp:
4350
4813
  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
4814
  case Object:
4383
4815
  return generateObjectNode4(
4384
4816
  ctx,
@@ -4393,11 +4825,6 @@ function parseObject4(ctx, current) {
4393
4825
  current,
4394
4826
  true
4395
4827
  );
4396
- case AggregateError:
4397
- if (ctx.features & 1 /* AggregateError */) {
4398
- return generateAggregateErrorNode4(ctx, id, current);
4399
- }
4400
- return generateErrorNode4(ctx, id, current);
4401
4828
  case Error:
4402
4829
  case EvalError:
4403
4830
  case RangeError:
@@ -4406,38 +4833,90 @@ function parseObject4(ctx, current) {
4406
4833
  case TypeError:
4407
4834
  case URIError:
4408
4835
  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
4836
  default:
4420
4837
  break;
4421
4838
  }
4422
- if (current instanceof AggregateError) {
4423
- if (ctx.features & 1 /* AggregateError */) {
4424
- return generateAggregateErrorNode4(ctx, id, current);
4839
+ if (ctx.features & 2048 /* TypedArray */) {
4840
+ switch (currentClass) {
4841
+ case ArrayBuffer:
4842
+ return createArrayBufferNode(id, current);
4843
+ case Int8Array:
4844
+ case Int16Array:
4845
+ case Int32Array:
4846
+ case Uint8Array:
4847
+ case Uint16Array:
4848
+ case Uint32Array:
4849
+ case Uint8ClampedArray:
4850
+ case Float32Array:
4851
+ case Float64Array:
4852
+ return createTypedArrayNode2(ctx, id, current);
4853
+ case DataView:
4854
+ return createDataViewNode2(ctx, id, current);
4855
+ default:
4856
+ break;
4425
4857
  }
4426
- return generateErrorNode4(ctx, id, current);
4427
4858
  }
4428
- if (current instanceof Error) {
4429
- return generateErrorNode4(ctx, id, current);
4859
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
4860
+ switch (currentClass) {
4861
+ case BigInt64Array:
4862
+ case BigUint64Array:
4863
+ return createBigIntTypedArrayNode2(ctx, id, current);
4864
+ default:
4865
+ break;
4866
+ }
4867
+ }
4868
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
4869
+ return generateMapNode4(ctx, id, current);
4870
+ }
4871
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
4872
+ return generateSetNode4(ctx, id, current);
4873
+ }
4874
+ if (ctx.features & 8192 /* WebAPI */) {
4875
+ switch (currentClass) {
4876
+ case URL:
4877
+ return createURLNode(id, current);
4878
+ case URLSearchParams:
4879
+ return createURLSearchParamsNode(id, current);
4880
+ case Headers:
4881
+ return generateHeadersNode4(ctx, id, current);
4882
+ case FormData:
4883
+ return generateFormDataNode4(ctx, id, current);
4884
+ case ReadableStream:
4885
+ return generateReadableStreamNode(ctx, id, current);
4886
+ case Request:
4887
+ return generateRequestNode3(ctx, id, current);
4888
+ case Response:
4889
+ return generateResponseNode3(ctx, id, current);
4890
+ case Event:
4891
+ return generateEventNode4(ctx, id, current);
4892
+ case CustomEvent:
4893
+ return generateCustomEventNode4(ctx, id, current);
4894
+ case DOMException:
4895
+ return createDOMExceptionNode(id, current);
4896
+ default:
4897
+ break;
4898
+ }
4899
+ }
4900
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
4901
+ return generateAggregateErrorNode4(ctx, id, current);
4430
4902
  }
4431
- if (current instanceof Promise) {
4903
+ if (ctx.features & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
4432
4904
  return generatePromiseNode3(ctx, id, current);
4433
4905
  }
4434
- if (Symbol.iterator in current) {
4435
- return generateObjectNode4(ctx, id, current, !!current.constructor);
4906
+ if (current instanceof Error) {
4907
+ return generateErrorNode4(ctx, id, current);
4908
+ }
4909
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
4910
+ return generateObjectNode4(ctx, id, current, !!currentClass);
4436
4911
  }
4437
4912
  throw new UnsupportedTypeError(current);
4438
4913
  }
4439
4914
  function crossParseStream(ctx, current) {
4440
- switch (typeof current) {
4915
+ const t = typeof current;
4916
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
4917
+ return createBigIntNode(ctx, current);
4918
+ }
4919
+ switch (t) {
4441
4920
  case "boolean":
4442
4921
  return current ? TRUE_NODE : FALSE_NODE;
4443
4922
  case "undefined":
@@ -4446,8 +4925,6 @@ function crossParseStream(ctx, current) {
4446
4925
  return createStringNode(current);
4447
4926
  case "number":
4448
4927
  return createNumberNode(current);
4449
- case "bigint":
4450
- return createBigIntNode(ctx, current);
4451
4928
  case "object":
4452
4929
  return parseObject4(ctx, current);
4453
4930
  case "symbol":
@@ -4499,7 +4976,6 @@ function generateArrayNode5(ctx, id, current) {
4499
4976
  };
4500
4977
  }
4501
4978
  function generateMapNode5(ctx, id, current) {
4502
- assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
4503
4979
  const len = current.size;
4504
4980
  const keyNodes = new Array(len);
4505
4981
  const valueNodes = new Array(len);
@@ -4538,7 +5014,6 @@ function generateMapNode5(ctx, id, current) {
4538
5014
  };
4539
5015
  }
4540
5016
  function generateSetNode5(ctx, id, current) {
4541
- assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
4542
5017
  const len = current.size;
4543
5018
  const nodes = new Array(len);
4544
5019
  const deferred = new Array(len);
@@ -4698,7 +5173,6 @@ function generateErrorNode5(ctx, id, current) {
4698
5173
  };
4699
5174
  }
4700
5175
  function generateHeadersNode5(ctx, id, current) {
4701
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4702
5176
  const items = {};
4703
5177
  current.forEach((value, key) => {
4704
5178
  items[key] = value;
@@ -4719,7 +5193,6 @@ function generateHeadersNode5(ctx, id, current) {
4719
5193
  };
4720
5194
  }
4721
5195
  function generateFormDataNode5(ctx, id, current) {
4722
- assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
4723
5196
  const items = {};
4724
5197
  current.forEach((value, key) => {
4725
5198
  items[key] = value;
@@ -4755,6 +5228,38 @@ function generateBoxedNode5(ctx, id, current) {
4755
5228
  o: void 0
4756
5229
  };
4757
5230
  }
5231
+ function generateEventNode5(ctx, id, current) {
5232
+ return {
5233
+ t: 37 /* Event */,
5234
+ i: id,
5235
+ s: serializeString(current.type),
5236
+ l: void 0,
5237
+ c: void 0,
5238
+ m: void 0,
5239
+ p: void 0,
5240
+ e: void 0,
5241
+ a: void 0,
5242
+ f: parseObject5(ctx, createEventOptions(current)),
5243
+ b: void 0,
5244
+ o: void 0
5245
+ };
5246
+ }
5247
+ function generateCustomEventNode5(ctx, id, current) {
5248
+ return {
5249
+ t: 38 /* CustomEvent */,
5250
+ i: id,
5251
+ s: serializeString(current.type),
5252
+ l: void 0,
5253
+ c: void 0,
5254
+ m: void 0,
5255
+ p: void 0,
5256
+ e: void 0,
5257
+ a: void 0,
5258
+ f: parseObject5(ctx, createCustomEventOptions(current)),
5259
+ b: void 0,
5260
+ o: void 0
5261
+ };
5262
+ }
4758
5263
  function parseObject5(ctx, current) {
4759
5264
  if (!current) {
4760
5265
  return NULL_NODE;
@@ -4771,39 +5276,17 @@ function parseObject5(ctx, current) {
4771
5276
  if (Array.isArray(current)) {
4772
5277
  return generateArrayNode5(ctx, id, current);
4773
5278
  }
4774
- switch (current.constructor) {
5279
+ const currentClass = current.constructor;
5280
+ switch (currentClass) {
4775
5281
  case Number:
4776
5282
  case Boolean:
4777
5283
  case String:
4778
5284
  case BigInt:
4779
- case Function:
4780
- case Symbol:
4781
5285
  return generateBoxedNode5(ctx, id, current);
4782
5286
  case Date:
4783
5287
  return createDateNode(id, current);
4784
5288
  case RegExp:
4785
5289
  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
5290
  case Object:
4808
5291
  return generateObjectNode5(
4809
5292
  ctx,
@@ -4818,11 +5301,6 @@ function parseObject5(ctx, current) {
4818
5301
  current,
4819
5302
  true
4820
5303
  );
4821
- case AggregateError:
4822
- if (ctx.features & 1 /* AggregateError */) {
4823
- return generateAggregateErrorNode5(ctx, id, current);
4824
- }
4825
- return generateErrorNode5(ctx, id, current);
4826
5304
  case Error:
4827
5305
  case EvalError:
4828
5306
  case RangeError:
@@ -4831,33 +5309,81 @@ function parseObject5(ctx, current) {
4831
5309
  case TypeError:
4832
5310
  case URIError:
4833
5311
  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
5312
  default:
4843
5313
  break;
4844
5314
  }
4845
- if (current instanceof AggregateError) {
4846
- if (ctx.features & 1 /* AggregateError */) {
4847
- return generateAggregateErrorNode5(ctx, id, current);
5315
+ if (ctx.features & 2048 /* TypedArray */) {
5316
+ switch (currentClass) {
5317
+ case ArrayBuffer:
5318
+ return createArrayBufferNode(id, current);
5319
+ case Int8Array:
5320
+ case Int16Array:
5321
+ case Int32Array:
5322
+ case Uint8Array:
5323
+ case Uint16Array:
5324
+ case Uint32Array:
5325
+ case Uint8ClampedArray:
5326
+ case Float32Array:
5327
+ case Float64Array:
5328
+ return createTypedArrayNode2(ctx, id, current);
5329
+ case DataView:
5330
+ return createDataViewNode2(ctx, id, current);
5331
+ default:
5332
+ break;
4848
5333
  }
4849
- return generateErrorNode5(ctx, id, current);
5334
+ }
5335
+ if ((ctx.features & BIGINT_FLAG) === BIGINT_FLAG) {
5336
+ switch (currentClass) {
5337
+ case BigInt64Array:
5338
+ case BigUint64Array:
5339
+ return createBigIntTypedArrayNode2(ctx, id, current);
5340
+ default:
5341
+ break;
5342
+ }
5343
+ }
5344
+ if (ctx.features & 32 /* Map */ && currentClass === Map) {
5345
+ return generateMapNode5(ctx, id, current);
5346
+ }
5347
+ if (ctx.features & 512 /* Set */ && currentClass === Set) {
5348
+ return generateSetNode5(ctx, id, current);
5349
+ }
5350
+ if (ctx.features & 8192 /* WebAPI */) {
5351
+ switch (currentClass) {
5352
+ case URL:
5353
+ return createURLNode(id, current);
5354
+ case URLSearchParams:
5355
+ return createURLSearchParamsNode(id, current);
5356
+ case Headers:
5357
+ return generateHeadersNode5(ctx, id, current);
5358
+ case FormData:
5359
+ return generateFormDataNode5(ctx, id, current);
5360
+ case Event:
5361
+ return generateEventNode5(ctx, id, current);
5362
+ case CustomEvent:
5363
+ return generateCustomEventNode5(ctx, id, current);
5364
+ case DOMException:
5365
+ return createDOMExceptionNode(id, current);
5366
+ default:
5367
+ break;
5368
+ }
5369
+ }
5370
+ if (ctx.features & 1 /* AggregateError */ && (currentClass === AggregateError || current instanceof AggregateError)) {
5371
+ return generateAggregateErrorNode5(ctx, id, current);
4850
5372
  }
4851
5373
  if (current instanceof Error) {
4852
5374
  return generateErrorNode5(ctx, id, current);
4853
5375
  }
4854
- if (Symbol.iterator in current) {
4855
- return generateObjectNode5(ctx, id, current, !!current.constructor);
5376
+ if (ctx.features & 1024 /* Symbol */ && Symbol.iterator in current) {
5377
+ return generateObjectNode5(ctx, id, current, !!currentClass);
4856
5378
  }
4857
5379
  throw new UnsupportedTypeError(current);
4858
5380
  }
4859
5381
  function crossParseSync(ctx, current) {
4860
- switch (typeof current) {
5382
+ const t = typeof current;
5383
+ if (ctx.features & 8 /* BigInt */ && t === "bigint") {
5384
+ return createBigIntNode(ctx, current);
5385
+ }
5386
+ switch (t) {
4861
5387
  case "boolean":
4862
5388
  return current ? TRUE_NODE : FALSE_NODE;
4863
5389
  case "undefined":
@@ -4866,8 +5392,6 @@ function crossParseSync(ctx, current) {
4866
5392
  return createStringNode(current);
4867
5393
  case "number":
4868
5394
  return createNumberNode(current);
4869
- case "bigint":
4870
- return createBigIntNode(ctx, current);
4871
5395
  case "object":
4872
5396
  return parseObject5(ctx, current);
4873
5397
  case "symbol":