seroval 1.7.6 → 1.7.7

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.
@@ -406,6 +406,30 @@ function getTypedArrayName(value) {
406
406
  if (!typedArrayNameGetter) typedArrayNameGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
407
407
  return typedArrayNameGetter.call(value);
408
408
  }
409
+ let typedArrayGetters;
410
+ let dataViewGetters;
411
+ function getAccessor(proto, key) {
412
+ return Object.getOwnPropertyDescriptor(proto, key).get;
413
+ }
414
+ function getViewGetters(proto, lengthKey) {
415
+ return {
416
+ buffer: getAccessor(proto, "buffer"),
417
+ byteOffset: getAccessor(proto, "byteOffset"),
418
+ byteLength: getAccessor(proto, "byteLength"),
419
+ length: getAccessor(proto, lengthKey)
420
+ };
421
+ }
422
+ function readArrayBufferView(value, isDataView) {
423
+ let getters;
424
+ if (isDataView) getters = dataViewGetters ?? (dataViewGetters = getViewGetters(DataView.prototype, "byteLength"));
425
+ else getters = typedArrayGetters ?? (typedArrayGetters = getViewGetters(Object.getPrototypeOf(Int8Array.prototype), "length"));
426
+ return {
427
+ buffer: getters.buffer.call(value),
428
+ byteOffset: getters.byteOffset.call(value),
429
+ byteLength: getters.byteLength.call(value),
430
+ length: getters.length.call(value)
431
+ };
432
+ }
409
433
  //#endregion
410
434
  //#region src/core/base-primitives.ts
411
435
  function createNumberNode(value) {
@@ -426,12 +450,14 @@ function createBigIntNode(current) {
426
450
  function createIndexedValueNode(id) {
427
451
  return createSerovalNode(4, id);
428
452
  }
453
+ const getDateTime = Date.prototype.getTime;
454
+ const getDateISOString = Date.prototype.toISOString;
429
455
  function createDateNode(id, current) {
430
- const timestamp = current.valueOf();
431
- return createSerovalNode(5, id, timestamp === timestamp ? current.toISOString() : "");
456
+ const timestamp = getDateTime.call(current);
457
+ return createSerovalNode(5, id, timestamp === timestamp ? getDateISOString.call(current) : "");
432
458
  }
433
- function createTemporalNode(id, type, current) {
434
- return createSerovalNode(36, id, current.toString(), type);
459
+ function createTemporalNode(id, type, temporalClass, current) {
460
+ return createSerovalNode(36, id, temporalClass.prototype.toString.call(current), type);
435
461
  }
436
462
  const getRegExpSource = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get;
437
463
  const getRegExpFlags = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
@@ -454,11 +480,11 @@ function createBoxedNode(id, boxed) {
454
480
  return createSerovalNode(21, id, void 0, void 0, void 0, void 0, void 0, void 0, boxed);
455
481
  }
456
482
  const MAX_TYPED_ARRAY_LENGTH = 1e6;
457
- function createViewNode(type, id, current, buffer) {
483
+ function createViewNode(type, id, current, view, buffer) {
458
484
  const isDataView = type === 20;
459
- const size = isDataView ? current.byteLength : current.length;
485
+ const size = view.length;
460
486
  if (size > MAX_TYPED_ARRAY_LENGTH) throw new SerovalUnsupportedTypeError(current);
461
- return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, current.byteOffset, void 0, size);
487
+ return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, view.byteOffset, void 0, size);
462
488
  }
463
489
  function createErrorNode(type, id, current, options) {
464
490
  return createSerovalNode(type, id, getErrorConstructor(current), void 0, serializeString(current.message), options);
@@ -480,8 +506,9 @@ function createSequenceNode(id, sequence, throwAt, doneAt) {
480
506
  }
481
507
  //#endregion
482
508
  //#region src/core/live-stream.ts
509
+ const BRAND = /* @__PURE__ */ Symbol("LiveStream");
483
510
  function isLiveStream(value) {
484
- return value instanceof LiveStream;
511
+ return value != null && value[BRAND] === true;
485
512
  }
486
513
  /**
487
514
  * A single-consumer stream for incremental serialization. Unlike
@@ -489,11 +516,12 @@ function isLiveStream(value) {
489
516
  * producer operation that sent it settles only when the consumer accepts it.
490
517
  *
491
518
  * An internal class rather than a tagged POJO: identity is checked with
492
- * `instanceof`, which untrusted input cannot forge. The class is exported
519
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
493
520
  * because bundlers cannot drop an unexported top-level class.
494
521
  */
495
522
  var LiveStream = class {
496
523
  constructor(options) {
524
+ this[BRAND] = true;
497
525
  this.consumed = false;
498
526
  this.closed = false;
499
527
  this.cancelled = false;
@@ -1295,12 +1323,12 @@ function getTemporalType(currentClass) {
1295
1323
  }
1296
1324
  }
1297
1325
  function getObjectClass(current) {
1298
- const currentClass = current.constructor;
1299
- if (typeof currentClass !== "function") {
1300
- const proto = Object.getPrototypeOf(current);
1301
- return proto === null ? void 0 : proto.constructor;
1302
- }
1303
- return currentClass;
1326
+ const proto = Object.getPrototypeOf(current);
1327
+ if (proto === null) return void 0;
1328
+ if (proto === Object.prototype) return Object;
1329
+ const currentClass = proto.constructor;
1330
+ if (typeof currentClass !== "function" || currentClass === Object || currentClass.prototype === proto) return currentClass;
1331
+ return proto;
1304
1332
  }
1305
1333
  /**
1306
1334
  * Decides how an object is parsed. Shared by the sync, stream and async
@@ -1364,10 +1392,14 @@ function createMapNode(id, sentinel, k, v) {
1364
1392
  function createPromiseConstructorNode(ctx, id, resolver) {
1365
1393
  return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1));
1366
1394
  }
1367
- function getArrayBufferView(ctx, current) {
1368
- if (!ctx.compactArrayBufferViews) return current;
1369
- const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
1370
- return new (current instanceof DataView ? DataView : getTypedArrayConstructor(getTypedArrayName(current)))(buffer);
1395
+ function getArrayBufferView(ctx, view) {
1396
+ if (!ctx.compactArrayBufferViews) return view;
1397
+ return {
1398
+ buffer: new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer,
1399
+ byteOffset: 0,
1400
+ byteLength: view.byteLength,
1401
+ length: view.length
1402
+ };
1371
1403
  }
1372
1404
  function createArrayBufferNode(ctx, id, current) {
1373
1405
  return createSerovalNode(19, id, encodeArrayBuffer(current), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5));
@@ -1428,8 +1460,8 @@ async function parseBoxed$1(ctx, depth, id, current) {
1428
1460
  return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
1429
1461
  }
1430
1462
  async function parseView$1(ctx, depth, type, id, current) {
1431
- current = getArrayBufferView(ctx.base, current);
1432
- return createViewNode(type, id, current, await parseAsync(ctx, depth, current.buffer));
1463
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
1464
+ return createViewNode(type, id, current, view, await parseAsync(ctx, depth, view.buffer));
1433
1465
  }
1434
1466
  async function parseError$1(ctx, depth, type, id, current) {
1435
1467
  const options = getErrorOptions(current, ctx.base.features);
@@ -1586,7 +1618,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
1586
1618
  case 12: return parseSet$1(ctx, depth, id, current);
1587
1619
  case 13: return parsePromise$1(ctx, depth, id, current);
1588
1620
  case 14: return createRegExpNode(id, current);
1589
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
1621
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
1590
1622
  case 16: return parsePlainObject$1(ctx, depth, id, current, !!currentClass);
1591
1623
  default: throw new SerovalUnsupportedTypeError(current);
1592
1624
  }
@@ -2422,10 +2454,10 @@ function serializeNullConstructor(ctx, node) {
2422
2454
  return serializeDictionary(ctx, node, NULL_CONSTRUCTOR);
2423
2455
  }
2424
2456
  function serializeDate(node) {
2425
- return "new Date(\"" + node.s + "\")";
2457
+ return "new Date(\"" + serializeString(node.s) + "\")";
2426
2458
  }
2427
2459
  function serializeTemporal(ctx, node) {
2428
- if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + node.s + "\")";
2460
+ if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + serializeString(node.s) + "\")";
2429
2461
  throw new SerovalUnsupportedNodeError(node);
2430
2462
  }
2431
2463
  function serializeRegExp(ctx, node) {
@@ -2539,7 +2571,7 @@ function serializeArrayBuffer(ctx, node) {
2539
2571
  return getConstructor(ctx, node.f) + "(\"" + node.s + "\")";
2540
2572
  }
2541
2573
  function serializeView(ctx, node) {
2542
- return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + node.b + "," + node.l + ")";
2574
+ return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + +node.b + "," + +node.l + ")";
2543
2575
  }
2544
2576
  function serializeAggregateError(ctx, node) {
2545
2577
  const id = node.i;
@@ -2658,7 +2690,7 @@ function serializeSequence(ctx, node) {
2658
2690
  result += (item && result && ",") + item;
2659
2691
  }
2660
2692
  ctx.base.stack.pop();
2661
- if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + node.s + ",d:" + node.l + "}";
2693
+ if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + +node.s + ",d:" + +node.l + "}";
2662
2694
  }
2663
2695
  return "{__SEROVAL_SEQUENCE__:!0,v:[],t:-1,d:0}";
2664
2696
  }
@@ -2831,8 +2863,8 @@ function parseBoxed(ctx, depth, id, current) {
2831
2863
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2832
2864
  }
2833
2865
  function parseView(ctx, depth, type, id, current) {
2834
- current = getArrayBufferView(ctx.base, current);
2835
- return createViewNode(type, id, current, parseSOS(ctx, depth, current.buffer));
2866
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
2867
+ return createViewNode(type, id, current, view, parseSOS(ctx, depth, view.buffer));
2836
2868
  }
2837
2869
  function parseError(ctx, depth, type, id, current) {
2838
2870
  const options = getErrorOptions(current, ctx.base.features);
@@ -2923,14 +2955,15 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
2923
2955
  case 12: return parseSet(ctx, depth, id, current);
2924
2956
  case 13: return parsePromise(ctx, depth, id, current);
2925
2957
  case 14: return createRegExpNode(id, current);
2926
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
2958
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
2927
2959
  case 16: return parsePlainObject(ctx, depth, id, current, !!currentClass);
2928
2960
  default: throw new SerovalUnsupportedTypeError(current);
2929
2961
  }
2930
2962
  }
2931
2963
  function parseObject(ctx, depth, id, current) {
2932
2964
  if (Array.isArray(current)) return parseArray(ctx, depth, id, current);
2933
- if (isStream(current)) return isLiveStream(current) ? parseLiveStream(ctx, depth, id, current) : parseStream(ctx, depth, id, current);
2965
+ if (isLiveStream(current)) return parseLiveStream(ctx, depth, id, current);
2966
+ if (current instanceof Stream) return parseStream(ctx, depth, id, current);
2934
2967
  if (isSequence(current)) return parseSequence(ctx, depth, id, current);
2935
2968
  const currentClass = getObjectClass(current);
2936
2969
  if (currentClass === OpaqueReference) return parseSOS(ctx, depth, current.replacement);
@@ -483,6 +483,7 @@ interface LiveStreamSink<T> {
483
483
  interface LiveStreamOptions {
484
484
  onCancel?: (reason: unknown) => void;
485
485
  }
486
+ declare const BRAND: unique symbol;
486
487
  export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
487
488
  /**
488
489
  * A single-consumer stream for incremental serialization. Unlike
@@ -490,10 +491,11 @@ export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
490
491
  * producer operation that sent it settles only when the consumer accepts it.
491
492
  *
492
493
  * An internal class rather than a tagged POJO: identity is checked with
493
- * `instanceof`, which untrusted input cannot forge. The class is exported
494
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
494
495
  * because bundlers cannot drop an unexported top-level class.
495
496
  */
496
497
  export declare class LiveStream<T> {
498
+ private readonly [BRAND];
497
499
  private pending;
498
500
  private waiting;
499
501
  private consumed;
@@ -483,6 +483,7 @@ interface LiveStreamSink<T> {
483
483
  interface LiveStreamOptions {
484
484
  onCancel?: (reason: unknown) => void;
485
485
  }
486
+ declare const BRAND: unique symbol;
486
487
  export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
487
488
  /**
488
489
  * A single-consumer stream for incremental serialization. Unlike
@@ -490,10 +491,11 @@ export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
490
491
  * producer operation that sent it settles only when the consumer accepts it.
491
492
  *
492
493
  * An internal class rather than a tagged POJO: identity is checked with
493
- * `instanceof`, which untrusted input cannot forge. The class is exported
494
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
494
495
  * because bundlers cannot drop an unexported top-level class.
495
496
  */
496
497
  export declare class LiveStream<T> {
498
+ private readonly [BRAND];
497
499
  private pending;
498
500
  private waiting;
499
501
  private consumed;
package/dist/dev/index.js CHANGED
@@ -405,6 +405,30 @@ function getTypedArrayName(value) {
405
405
  if (!typedArrayNameGetter) typedArrayNameGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
406
406
  return typedArrayNameGetter.call(value);
407
407
  }
408
+ let typedArrayGetters;
409
+ let dataViewGetters;
410
+ function getAccessor(proto, key) {
411
+ return Object.getOwnPropertyDescriptor(proto, key).get;
412
+ }
413
+ function getViewGetters(proto, lengthKey) {
414
+ return {
415
+ buffer: getAccessor(proto, "buffer"),
416
+ byteOffset: getAccessor(proto, "byteOffset"),
417
+ byteLength: getAccessor(proto, "byteLength"),
418
+ length: getAccessor(proto, lengthKey)
419
+ };
420
+ }
421
+ function readArrayBufferView(value, isDataView) {
422
+ let getters;
423
+ if (isDataView) getters = dataViewGetters ?? (dataViewGetters = getViewGetters(DataView.prototype, "byteLength"));
424
+ else getters = typedArrayGetters ?? (typedArrayGetters = getViewGetters(Object.getPrototypeOf(Int8Array.prototype), "length"));
425
+ return {
426
+ buffer: getters.buffer.call(value),
427
+ byteOffset: getters.byteOffset.call(value),
428
+ byteLength: getters.byteLength.call(value),
429
+ length: getters.length.call(value)
430
+ };
431
+ }
408
432
  //#endregion
409
433
  //#region src/core/base-primitives.ts
410
434
  function createNumberNode(value) {
@@ -425,12 +449,14 @@ function createBigIntNode(current) {
425
449
  function createIndexedValueNode(id) {
426
450
  return createSerovalNode(4, id);
427
451
  }
452
+ const getDateTime = Date.prototype.getTime;
453
+ const getDateISOString = Date.prototype.toISOString;
428
454
  function createDateNode(id, current) {
429
- const timestamp = current.valueOf();
430
- return createSerovalNode(5, id, timestamp === timestamp ? current.toISOString() : "");
455
+ const timestamp = getDateTime.call(current);
456
+ return createSerovalNode(5, id, timestamp === timestamp ? getDateISOString.call(current) : "");
431
457
  }
432
- function createTemporalNode(id, type, current) {
433
- return createSerovalNode(36, id, current.toString(), type);
458
+ function createTemporalNode(id, type, temporalClass, current) {
459
+ return createSerovalNode(36, id, temporalClass.prototype.toString.call(current), type);
434
460
  }
435
461
  const getRegExpSource = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get;
436
462
  const getRegExpFlags = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
@@ -453,11 +479,11 @@ function createBoxedNode(id, boxed) {
453
479
  return createSerovalNode(21, id, void 0, void 0, void 0, void 0, void 0, void 0, boxed);
454
480
  }
455
481
  const MAX_TYPED_ARRAY_LENGTH = 1e6;
456
- function createViewNode(type, id, current, buffer) {
482
+ function createViewNode(type, id, current, view, buffer) {
457
483
  const isDataView = type === 20;
458
- const size = isDataView ? current.byteLength : current.length;
484
+ const size = view.length;
459
485
  if (size > MAX_TYPED_ARRAY_LENGTH) throw new SerovalUnsupportedTypeError(current);
460
- return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, current.byteOffset, void 0, size);
486
+ return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, view.byteOffset, void 0, size);
461
487
  }
462
488
  function createErrorNode(type, id, current, options) {
463
489
  return createSerovalNode(type, id, getErrorConstructor(current), void 0, serializeString(current.message), options);
@@ -479,8 +505,9 @@ function createSequenceNode(id, sequence, throwAt, doneAt) {
479
505
  }
480
506
  //#endregion
481
507
  //#region src/core/live-stream.ts
508
+ const BRAND = /* @__PURE__ */ Symbol("LiveStream");
482
509
  function isLiveStream(value) {
483
- return value instanceof LiveStream;
510
+ return value != null && value[BRAND] === true;
484
511
  }
485
512
  /**
486
513
  * A single-consumer stream for incremental serialization. Unlike
@@ -488,11 +515,12 @@ function isLiveStream(value) {
488
515
  * producer operation that sent it settles only when the consumer accepts it.
489
516
  *
490
517
  * An internal class rather than a tagged POJO: identity is checked with
491
- * `instanceof`, which untrusted input cannot forge. The class is exported
518
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
492
519
  * because bundlers cannot drop an unexported top-level class.
493
520
  */
494
521
  var LiveStream = class {
495
522
  constructor(options) {
523
+ this[BRAND] = true;
496
524
  this.consumed = false;
497
525
  this.closed = false;
498
526
  this.cancelled = false;
@@ -1294,12 +1322,12 @@ function getTemporalType(currentClass) {
1294
1322
  }
1295
1323
  }
1296
1324
  function getObjectClass(current) {
1297
- const currentClass = current.constructor;
1298
- if (typeof currentClass !== "function") {
1299
- const proto = Object.getPrototypeOf(current);
1300
- return proto === null ? void 0 : proto.constructor;
1301
- }
1302
- return currentClass;
1325
+ const proto = Object.getPrototypeOf(current);
1326
+ if (proto === null) return void 0;
1327
+ if (proto === Object.prototype) return Object;
1328
+ const currentClass = proto.constructor;
1329
+ if (typeof currentClass !== "function" || currentClass === Object || currentClass.prototype === proto) return currentClass;
1330
+ return proto;
1303
1331
  }
1304
1332
  /**
1305
1333
  * Decides how an object is parsed. Shared by the sync, stream and async
@@ -1363,10 +1391,14 @@ function createMapNode(id, sentinel, k, v) {
1363
1391
  function createPromiseConstructorNode(ctx, id, resolver) {
1364
1392
  return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1));
1365
1393
  }
1366
- function getArrayBufferView(ctx, current) {
1367
- if (!ctx.compactArrayBufferViews) return current;
1368
- const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
1369
- return new (current instanceof DataView ? DataView : getTypedArrayConstructor(getTypedArrayName(current)))(buffer);
1394
+ function getArrayBufferView(ctx, view) {
1395
+ if (!ctx.compactArrayBufferViews) return view;
1396
+ return {
1397
+ buffer: new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer,
1398
+ byteOffset: 0,
1399
+ byteLength: view.byteLength,
1400
+ length: view.length
1401
+ };
1370
1402
  }
1371
1403
  function createArrayBufferNode(ctx, id, current) {
1372
1404
  return createSerovalNode(19, id, encodeArrayBuffer(current), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5));
@@ -1427,8 +1459,8 @@ async function parseBoxed$1(ctx, depth, id, current) {
1427
1459
  return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
1428
1460
  }
1429
1461
  async function parseView$1(ctx, depth, type, id, current) {
1430
- current = getArrayBufferView(ctx.base, current);
1431
- return createViewNode(type, id, current, await parseAsync(ctx, depth, current.buffer));
1462
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
1463
+ return createViewNode(type, id, current, view, await parseAsync(ctx, depth, view.buffer));
1432
1464
  }
1433
1465
  async function parseError$1(ctx, depth, type, id, current) {
1434
1466
  const options = getErrorOptions(current, ctx.base.features);
@@ -1585,7 +1617,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
1585
1617
  case 12: return parseSet$1(ctx, depth, id, current);
1586
1618
  case 13: return parsePromise$1(ctx, depth, id, current);
1587
1619
  case 14: return createRegExpNode(id, current);
1588
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
1620
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
1589
1621
  case 16: return parsePlainObject$1(ctx, depth, id, current, !!currentClass);
1590
1622
  default: throw new SerovalUnsupportedTypeError(current);
1591
1623
  }
@@ -2421,10 +2453,10 @@ function serializeNullConstructor(ctx, node) {
2421
2453
  return serializeDictionary(ctx, node, NULL_CONSTRUCTOR);
2422
2454
  }
2423
2455
  function serializeDate(node) {
2424
- return "new Date(\"" + node.s + "\")";
2456
+ return "new Date(\"" + serializeString(node.s) + "\")";
2425
2457
  }
2426
2458
  function serializeTemporal(ctx, node) {
2427
- if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + node.s + "\")";
2459
+ if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + serializeString(node.s) + "\")";
2428
2460
  throw new SerovalUnsupportedNodeError(node);
2429
2461
  }
2430
2462
  function serializeRegExp(ctx, node) {
@@ -2538,7 +2570,7 @@ function serializeArrayBuffer(ctx, node) {
2538
2570
  return getConstructor(ctx, node.f) + "(\"" + node.s + "\")";
2539
2571
  }
2540
2572
  function serializeView(ctx, node) {
2541
- return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + node.b + "," + node.l + ")";
2573
+ return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + +node.b + "," + +node.l + ")";
2542
2574
  }
2543
2575
  function serializeAggregateError(ctx, node) {
2544
2576
  const id = node.i;
@@ -2657,7 +2689,7 @@ function serializeSequence(ctx, node) {
2657
2689
  result += (item && result && ",") + item;
2658
2690
  }
2659
2691
  ctx.base.stack.pop();
2660
- if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + node.s + ",d:" + node.l + "}";
2692
+ if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + +node.s + ",d:" + +node.l + "}";
2661
2693
  }
2662
2694
  return "{__SEROVAL_SEQUENCE__:!0,v:[],t:-1,d:0}";
2663
2695
  }
@@ -2830,8 +2862,8 @@ function parseBoxed(ctx, depth, id, current) {
2830
2862
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2831
2863
  }
2832
2864
  function parseView(ctx, depth, type, id, current) {
2833
- current = getArrayBufferView(ctx.base, current);
2834
- return createViewNode(type, id, current, parseSOS(ctx, depth, current.buffer));
2865
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
2866
+ return createViewNode(type, id, current, view, parseSOS(ctx, depth, view.buffer));
2835
2867
  }
2836
2868
  function parseError(ctx, depth, type, id, current) {
2837
2869
  const options = getErrorOptions(current, ctx.base.features);
@@ -2922,14 +2954,15 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
2922
2954
  case 12: return parseSet(ctx, depth, id, current);
2923
2955
  case 13: return parsePromise(ctx, depth, id, current);
2924
2956
  case 14: return createRegExpNode(id, current);
2925
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
2957
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
2926
2958
  case 16: return parsePlainObject(ctx, depth, id, current, !!currentClass);
2927
2959
  default: throw new SerovalUnsupportedTypeError(current);
2928
2960
  }
2929
2961
  }
2930
2962
  function parseObject(ctx, depth, id, current) {
2931
2963
  if (Array.isArray(current)) return parseArray(ctx, depth, id, current);
2932
- if (isStream(current)) return isLiveStream(current) ? parseLiveStream(ctx, depth, id, current) : parseStream(ctx, depth, id, current);
2964
+ if (isLiveStream(current)) return parseLiveStream(ctx, depth, id, current);
2965
+ if (current instanceof Stream) return parseStream(ctx, depth, id, current);
2933
2966
  if (isSequence(current)) return parseSequence(ctx, depth, id, current);
2934
2967
  const currentClass = getObjectClass(current);
2935
2968
  if (currentClass === OpaqueReference) return parseSOS(ctx, depth, current.replacement);
package/dist/index.cjs CHANGED
@@ -390,6 +390,30 @@ function getTypedArrayName(value) {
390
390
  if (!typedArrayNameGetter) typedArrayNameGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
391
391
  return typedArrayNameGetter.call(value);
392
392
  }
393
+ let typedArrayGetters;
394
+ let dataViewGetters;
395
+ function getAccessor(proto, key) {
396
+ return Object.getOwnPropertyDescriptor(proto, key).get;
397
+ }
398
+ function getViewGetters(proto, lengthKey) {
399
+ return {
400
+ buffer: getAccessor(proto, "buffer"),
401
+ byteOffset: getAccessor(proto, "byteOffset"),
402
+ byteLength: getAccessor(proto, "byteLength"),
403
+ length: getAccessor(proto, lengthKey)
404
+ };
405
+ }
406
+ function readArrayBufferView(value, isDataView) {
407
+ let getters;
408
+ if (isDataView) getters = dataViewGetters ?? (dataViewGetters = getViewGetters(DataView.prototype, "byteLength"));
409
+ else getters = typedArrayGetters ?? (typedArrayGetters = getViewGetters(Object.getPrototypeOf(Int8Array.prototype), "length"));
410
+ return {
411
+ buffer: getters.buffer.call(value),
412
+ byteOffset: getters.byteOffset.call(value),
413
+ byteLength: getters.byteLength.call(value),
414
+ length: getters.length.call(value)
415
+ };
416
+ }
393
417
  //#endregion
394
418
  //#region src/core/base-primitives.ts
395
419
  function createNumberNode(value) {
@@ -410,12 +434,14 @@ function createBigIntNode(current) {
410
434
  function createIndexedValueNode(id) {
411
435
  return createSerovalNode(4, id);
412
436
  }
437
+ const getDateTime = Date.prototype.getTime;
438
+ const getDateISOString = Date.prototype.toISOString;
413
439
  function createDateNode(id, current) {
414
- const timestamp = current.valueOf();
415
- return createSerovalNode(5, id, timestamp === timestamp ? current.toISOString() : "");
440
+ const timestamp = getDateTime.call(current);
441
+ return createSerovalNode(5, id, timestamp === timestamp ? getDateISOString.call(current) : "");
416
442
  }
417
- function createTemporalNode(id, type, current) {
418
- return createSerovalNode(36, id, current.toString(), type);
443
+ function createTemporalNode(id, type, temporalClass, current) {
444
+ return createSerovalNode(36, id, temporalClass.prototype.toString.call(current), type);
419
445
  }
420
446
  const getRegExpSource = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get;
421
447
  const getRegExpFlags = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
@@ -438,11 +464,11 @@ function createBoxedNode(id, boxed) {
438
464
  return createSerovalNode(21, id, void 0, void 0, void 0, void 0, void 0, void 0, boxed);
439
465
  }
440
466
  const MAX_TYPED_ARRAY_LENGTH = 1e6;
441
- function createViewNode(type, id, current, buffer) {
467
+ function createViewNode(type, id, current, view, buffer) {
442
468
  const isDataView = type === 20;
443
- const size = isDataView ? current.byteLength : current.length;
469
+ const size = view.length;
444
470
  if (size > MAX_TYPED_ARRAY_LENGTH) throw new SerovalUnsupportedTypeError(current);
445
- return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, current.byteOffset, void 0, size);
471
+ return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, view.byteOffset, void 0, size);
446
472
  }
447
473
  function createErrorNode(type, id, current, options) {
448
474
  return createSerovalNode(type, id, getErrorConstructor(current), void 0, serializeString(current.message), options);
@@ -464,8 +490,9 @@ function createSequenceNode(id, sequence, throwAt, doneAt) {
464
490
  }
465
491
  //#endregion
466
492
  //#region src/core/live-stream.ts
493
+ const BRAND = /* @__PURE__ */ Symbol("LiveStream");
467
494
  function isLiveStream(value) {
468
- return value instanceof LiveStream;
495
+ return value != null && value[BRAND] === true;
469
496
  }
470
497
  /**
471
498
  * A single-consumer stream for incremental serialization. Unlike
@@ -473,11 +500,12 @@ function isLiveStream(value) {
473
500
  * producer operation that sent it settles only when the consumer accepts it.
474
501
  *
475
502
  * An internal class rather than a tagged POJO: identity is checked with
476
- * `instanceof`, which untrusted input cannot forge. The class is exported
503
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
477
504
  * because bundlers cannot drop an unexported top-level class.
478
505
  */
479
506
  var LiveStream = class {
480
507
  constructor(options) {
508
+ this[BRAND] = true;
481
509
  this.consumed = false;
482
510
  this.closed = false;
483
511
  this.cancelled = false;
@@ -1279,12 +1307,12 @@ function getTemporalType(currentClass) {
1279
1307
  }
1280
1308
  }
1281
1309
  function getObjectClass(current) {
1282
- const currentClass = current.constructor;
1283
- if (typeof currentClass !== "function") {
1284
- const proto = Object.getPrototypeOf(current);
1285
- return proto === null ? void 0 : proto.constructor;
1286
- }
1287
- return currentClass;
1310
+ const proto = Object.getPrototypeOf(current);
1311
+ if (proto === null) return void 0;
1312
+ if (proto === Object.prototype) return Object;
1313
+ const currentClass = proto.constructor;
1314
+ if (typeof currentClass !== "function" || currentClass === Object || currentClass.prototype === proto) return currentClass;
1315
+ return proto;
1288
1316
  }
1289
1317
  /**
1290
1318
  * Decides how an object is parsed. Shared by the sync, stream and async
@@ -1348,10 +1376,14 @@ function createMapNode(id, sentinel, k, v) {
1348
1376
  function createPromiseConstructorNode(ctx, id, resolver) {
1349
1377
  return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1));
1350
1378
  }
1351
- function getArrayBufferView(ctx, current) {
1352
- if (!ctx.compactArrayBufferViews) return current;
1353
- const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
1354
- return new (current instanceof DataView ? DataView : getTypedArrayConstructor(getTypedArrayName(current)))(buffer);
1379
+ function getArrayBufferView(ctx, view) {
1380
+ if (!ctx.compactArrayBufferViews) return view;
1381
+ return {
1382
+ buffer: new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer,
1383
+ byteOffset: 0,
1384
+ byteLength: view.byteLength,
1385
+ length: view.length
1386
+ };
1355
1387
  }
1356
1388
  function createArrayBufferNode(ctx, id, current) {
1357
1389
  return createSerovalNode(19, id, encodeArrayBuffer(current), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5));
@@ -1412,8 +1444,8 @@ async function parseBoxed$1(ctx, depth, id, current) {
1412
1444
  return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
1413
1445
  }
1414
1446
  async function parseView$1(ctx, depth, type, id, current) {
1415
- current = getArrayBufferView(ctx.base, current);
1416
- return createViewNode(type, id, current, await parseAsync(ctx, depth, current.buffer));
1447
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
1448
+ return createViewNode(type, id, current, view, await parseAsync(ctx, depth, view.buffer));
1417
1449
  }
1418
1450
  async function parseError$1(ctx, depth, type, id, current) {
1419
1451
  const options = getErrorOptions(current, ctx.base.features);
@@ -1570,7 +1602,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
1570
1602
  case 12: return parseSet$1(ctx, depth, id, current);
1571
1603
  case 13: return parsePromise$1(ctx, depth, id, current);
1572
1604
  case 14: return createRegExpNode(id, current);
1573
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
1605
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
1574
1606
  case 16: return parsePlainObject$1(ctx, depth, id, current, !!currentClass);
1575
1607
  default: throw new SerovalUnsupportedTypeError(current);
1576
1608
  }
@@ -2406,10 +2438,10 @@ function serializeNullConstructor(ctx, node) {
2406
2438
  return serializeDictionary(ctx, node, NULL_CONSTRUCTOR);
2407
2439
  }
2408
2440
  function serializeDate(node) {
2409
- return "new Date(\"" + node.s + "\")";
2441
+ return "new Date(\"" + serializeString(node.s) + "\")";
2410
2442
  }
2411
2443
  function serializeTemporal(ctx, node) {
2412
- if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + node.s + "\")";
2444
+ if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + serializeString(node.s) + "\")";
2413
2445
  throw new SerovalUnsupportedNodeError(node);
2414
2446
  }
2415
2447
  function serializeRegExp(ctx, node) {
@@ -2523,7 +2555,7 @@ function serializeArrayBuffer(ctx, node) {
2523
2555
  return getConstructor(ctx, node.f) + "(\"" + node.s + "\")";
2524
2556
  }
2525
2557
  function serializeView(ctx, node) {
2526
- return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + node.b + "," + node.l + ")";
2558
+ return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + +node.b + "," + +node.l + ")";
2527
2559
  }
2528
2560
  function serializeAggregateError(ctx, node) {
2529
2561
  const id = node.i;
@@ -2642,7 +2674,7 @@ function serializeSequence(ctx, node) {
2642
2674
  result += (item && result && ",") + item;
2643
2675
  }
2644
2676
  ctx.base.stack.pop();
2645
- if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + node.s + ",d:" + node.l + "}";
2677
+ if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + +node.s + ",d:" + +node.l + "}";
2646
2678
  }
2647
2679
  return "{__SEROVAL_SEQUENCE__:!0,v:[],t:-1,d:0}";
2648
2680
  }
@@ -2815,8 +2847,8 @@ function parseBoxed(ctx, depth, id, current) {
2815
2847
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2816
2848
  }
2817
2849
  function parseView(ctx, depth, type, id, current) {
2818
- current = getArrayBufferView(ctx.base, current);
2819
- return createViewNode(type, id, current, parseSOS(ctx, depth, current.buffer));
2850
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
2851
+ return createViewNode(type, id, current, view, parseSOS(ctx, depth, view.buffer));
2820
2852
  }
2821
2853
  function parseError(ctx, depth, type, id, current) {
2822
2854
  const options = getErrorOptions(current, ctx.base.features);
@@ -2907,14 +2939,15 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
2907
2939
  case 12: return parseSet(ctx, depth, id, current);
2908
2940
  case 13: return parsePromise(ctx, depth, id, current);
2909
2941
  case 14: return createRegExpNode(id, current);
2910
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
2942
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
2911
2943
  case 16: return parsePlainObject(ctx, depth, id, current, !!currentClass);
2912
2944
  default: throw new SerovalUnsupportedTypeError(current);
2913
2945
  }
2914
2946
  }
2915
2947
  function parseObject(ctx, depth, id, current) {
2916
2948
  if (Array.isArray(current)) return parseArray(ctx, depth, id, current);
2917
- if (isStream(current)) return isLiveStream(current) ? parseLiveStream(ctx, depth, id, current) : parseStream(ctx, depth, id, current);
2949
+ if (isLiveStream(current)) return parseLiveStream(ctx, depth, id, current);
2950
+ if (current instanceof Stream) return parseStream(ctx, depth, id, current);
2918
2951
  if (isSequence(current)) return parseSequence(ctx, depth, id, current);
2919
2952
  const currentClass = getObjectClass(current);
2920
2953
  if (currentClass === OpaqueReference) return parseSOS(ctx, depth, current.replacement);
package/dist/index.d.cts CHANGED
@@ -483,6 +483,7 @@ interface LiveStreamSink<T> {
483
483
  interface LiveStreamOptions {
484
484
  onCancel?: (reason: unknown) => void;
485
485
  }
486
+ declare const BRAND: unique symbol;
486
487
  export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
487
488
  /**
488
489
  * A single-consumer stream for incremental serialization. Unlike
@@ -490,10 +491,11 @@ export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
490
491
  * producer operation that sent it settles only when the consumer accepts it.
491
492
  *
492
493
  * An internal class rather than a tagged POJO: identity is checked with
493
- * `instanceof`, which untrusted input cannot forge. The class is exported
494
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
494
495
  * because bundlers cannot drop an unexported top-level class.
495
496
  */
496
497
  export declare class LiveStream<T> {
498
+ private readonly [BRAND];
497
499
  private pending;
498
500
  private waiting;
499
501
  private consumed;
package/dist/index.d.ts CHANGED
@@ -483,6 +483,7 @@ interface LiveStreamSink<T> {
483
483
  interface LiveStreamOptions {
484
484
  onCancel?: (reason: unknown) => void;
485
485
  }
486
+ declare const BRAND: unique symbol;
486
487
  export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
487
488
  /**
488
489
  * A single-consumer stream for incremental serialization. Unlike
@@ -490,10 +491,11 @@ export declare function isLiveStream<T>(value: unknown): value is LiveStream<T>;
490
491
  * producer operation that sent it settles only when the consumer accepts it.
491
492
  *
492
493
  * An internal class rather than a tagged POJO: identity is checked with
493
- * `instanceof`, which untrusted input cannot forge. The class is exported
494
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
494
495
  * because bundlers cannot drop an unexported top-level class.
495
496
  */
496
497
  export declare class LiveStream<T> {
498
+ private readonly [BRAND];
497
499
  private pending;
498
500
  private waiting;
499
501
  private consumed;
package/dist/index.js CHANGED
@@ -389,6 +389,30 @@ function getTypedArrayName(value) {
389
389
  if (!typedArrayNameGetter) typedArrayNameGetter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), Symbol.toStringTag).get;
390
390
  return typedArrayNameGetter.call(value);
391
391
  }
392
+ let typedArrayGetters;
393
+ let dataViewGetters;
394
+ function getAccessor(proto, key) {
395
+ return Object.getOwnPropertyDescriptor(proto, key).get;
396
+ }
397
+ function getViewGetters(proto, lengthKey) {
398
+ return {
399
+ buffer: getAccessor(proto, "buffer"),
400
+ byteOffset: getAccessor(proto, "byteOffset"),
401
+ byteLength: getAccessor(proto, "byteLength"),
402
+ length: getAccessor(proto, lengthKey)
403
+ };
404
+ }
405
+ function readArrayBufferView(value, isDataView) {
406
+ let getters;
407
+ if (isDataView) getters = dataViewGetters ?? (dataViewGetters = getViewGetters(DataView.prototype, "byteLength"));
408
+ else getters = typedArrayGetters ?? (typedArrayGetters = getViewGetters(Object.getPrototypeOf(Int8Array.prototype), "length"));
409
+ return {
410
+ buffer: getters.buffer.call(value),
411
+ byteOffset: getters.byteOffset.call(value),
412
+ byteLength: getters.byteLength.call(value),
413
+ length: getters.length.call(value)
414
+ };
415
+ }
392
416
  //#endregion
393
417
  //#region src/core/base-primitives.ts
394
418
  function createNumberNode(value) {
@@ -409,12 +433,14 @@ function createBigIntNode(current) {
409
433
  function createIndexedValueNode(id) {
410
434
  return createSerovalNode(4, id);
411
435
  }
436
+ const getDateTime = Date.prototype.getTime;
437
+ const getDateISOString = Date.prototype.toISOString;
412
438
  function createDateNode(id, current) {
413
- const timestamp = current.valueOf();
414
- return createSerovalNode(5, id, timestamp === timestamp ? current.toISOString() : "");
439
+ const timestamp = getDateTime.call(current);
440
+ return createSerovalNode(5, id, timestamp === timestamp ? getDateISOString.call(current) : "");
415
441
  }
416
- function createTemporalNode(id, type, current) {
417
- return createSerovalNode(36, id, current.toString(), type);
442
+ function createTemporalNode(id, type, temporalClass, current) {
443
+ return createSerovalNode(36, id, temporalClass.prototype.toString.call(current), type);
418
444
  }
419
445
  const getRegExpSource = Object.getOwnPropertyDescriptor(RegExp.prototype, "source").get;
420
446
  const getRegExpFlags = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
@@ -437,11 +463,11 @@ function createBoxedNode(id, boxed) {
437
463
  return createSerovalNode(21, id, void 0, void 0, void 0, void 0, void 0, void 0, boxed);
438
464
  }
439
465
  const MAX_TYPED_ARRAY_LENGTH = 1e6;
440
- function createViewNode(type, id, current, buffer) {
466
+ function createViewNode(type, id, current, view, buffer) {
441
467
  const isDataView = type === 20;
442
- const size = isDataView ? current.byteLength : current.length;
468
+ const size = view.length;
443
469
  if (size > MAX_TYPED_ARRAY_LENGTH) throw new SerovalUnsupportedTypeError(current);
444
- return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, current.byteOffset, void 0, size);
470
+ return createSerovalNode(type, id, void 0, isDataView ? void 0 : getTypedArrayName(current), void 0, void 0, void 0, void 0, buffer, view.byteOffset, void 0, size);
445
471
  }
446
472
  function createErrorNode(type, id, current, options) {
447
473
  return createSerovalNode(type, id, getErrorConstructor(current), void 0, serializeString(current.message), options);
@@ -463,8 +489,9 @@ function createSequenceNode(id, sequence, throwAt, doneAt) {
463
489
  }
464
490
  //#endregion
465
491
  //#region src/core/live-stream.ts
492
+ const BRAND = /* @__PURE__ */ Symbol("LiveStream");
466
493
  function isLiveStream(value) {
467
- return value instanceof LiveStream;
494
+ return value != null && value[BRAND] === true;
468
495
  }
469
496
  /**
470
497
  * A single-consumer stream for incremental serialization. Unlike
@@ -472,11 +499,12 @@ function isLiveStream(value) {
472
499
  * producer operation that sent it settles only when the consumer accepts it.
473
500
  *
474
501
  * An internal class rather than a tagged POJO: identity is checked with
475
- * `instanceof`, which untrusted input cannot forge. The class is exported
502
+ * `isLiveStream`, which untrusted input cannot forge. The class is exported
476
503
  * because bundlers cannot drop an unexported top-level class.
477
504
  */
478
505
  var LiveStream = class {
479
506
  constructor(options) {
507
+ this[BRAND] = true;
480
508
  this.consumed = false;
481
509
  this.closed = false;
482
510
  this.cancelled = false;
@@ -1278,12 +1306,12 @@ function getTemporalType(currentClass) {
1278
1306
  }
1279
1307
  }
1280
1308
  function getObjectClass(current) {
1281
- const currentClass = current.constructor;
1282
- if (typeof currentClass !== "function") {
1283
- const proto = Object.getPrototypeOf(current);
1284
- return proto === null ? void 0 : proto.constructor;
1285
- }
1286
- return currentClass;
1309
+ const proto = Object.getPrototypeOf(current);
1310
+ if (proto === null) return void 0;
1311
+ if (proto === Object.prototype) return Object;
1312
+ const currentClass = proto.constructor;
1313
+ if (typeof currentClass !== "function" || currentClass === Object || currentClass.prototype === proto) return currentClass;
1314
+ return proto;
1287
1315
  }
1288
1316
  /**
1289
1317
  * Decides how an object is parsed. Shared by the sync, stream and async
@@ -1347,10 +1375,14 @@ function createMapNode(id, sentinel, k, v) {
1347
1375
  function createPromiseConstructorNode(ctx, id, resolver) {
1348
1376
  return createSerovalNode(22, id, resolver, void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 1));
1349
1377
  }
1350
- function getArrayBufferView(ctx, current) {
1351
- if (!ctx.compactArrayBufferViews) return current;
1352
- const buffer = new Uint8Array(current.buffer, current.byteOffset, current.byteLength).slice().buffer;
1353
- return new (current instanceof DataView ? DataView : getTypedArrayConstructor(getTypedArrayName(current)))(buffer);
1378
+ function getArrayBufferView(ctx, view) {
1379
+ if (!ctx.compactArrayBufferViews) return view;
1380
+ return {
1381
+ buffer: new Uint8Array(view.buffer, view.byteOffset, view.byteLength).slice().buffer,
1382
+ byteOffset: 0,
1383
+ byteLength: view.byteLength,
1384
+ length: view.length
1385
+ };
1354
1386
  }
1355
1387
  function createArrayBufferNode(ctx, id, current) {
1356
1388
  return createSerovalNode(19, id, encodeArrayBuffer(current), void 0, void 0, void 0, void 0, void 0, parseSpecialReference(ctx, 5));
@@ -1411,8 +1443,8 @@ async function parseBoxed$1(ctx, depth, id, current) {
1411
1443
  return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
1412
1444
  }
1413
1445
  async function parseView$1(ctx, depth, type, id, current) {
1414
- current = getArrayBufferView(ctx.base, current);
1415
- return createViewNode(type, id, current, await parseAsync(ctx, depth, current.buffer));
1446
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
1447
+ return createViewNode(type, id, current, view, await parseAsync(ctx, depth, view.buffer));
1416
1448
  }
1417
1449
  async function parseError$1(ctx, depth, type, id, current) {
1418
1450
  const options = getErrorOptions(current, ctx.base.features);
@@ -1569,7 +1601,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
1569
1601
  case 12: return parseSet$1(ctx, depth, id, current);
1570
1602
  case 13: return parsePromise$1(ctx, depth, id, current);
1571
1603
  case 14: return createRegExpNode(id, current);
1572
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
1604
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
1573
1605
  case 16: return parsePlainObject$1(ctx, depth, id, current, !!currentClass);
1574
1606
  default: throw new SerovalUnsupportedTypeError(current);
1575
1607
  }
@@ -2405,10 +2437,10 @@ function serializeNullConstructor(ctx, node) {
2405
2437
  return serializeDictionary(ctx, node, NULL_CONSTRUCTOR);
2406
2438
  }
2407
2439
  function serializeDate(node) {
2408
- return "new Date(\"" + node.s + "\")";
2440
+ return "new Date(\"" + serializeString(node.s) + "\")";
2409
2441
  }
2410
2442
  function serializeTemporal(ctx, node) {
2411
- if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + node.s + "\")";
2443
+ if (ctx.base.features & 64) return "Temporal." + TEMPORAL_TYPE_NAME[node.c] + ".from(\"" + serializeString(node.s) + "\")";
2412
2444
  throw new SerovalUnsupportedNodeError(node);
2413
2445
  }
2414
2446
  function serializeRegExp(ctx, node) {
@@ -2522,7 +2554,7 @@ function serializeArrayBuffer(ctx, node) {
2522
2554
  return getConstructor(ctx, node.f) + "(\"" + node.s + "\")";
2523
2555
  }
2524
2556
  function serializeView(ctx, node) {
2525
- return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + node.b + "," + node.l + ")";
2557
+ return "new " + (node.t === 20 ? "DataView" : node.c) + "(" + serialize$1(ctx, node.f) + "," + +node.b + "," + +node.l + ")";
2526
2558
  }
2527
2559
  function serializeAggregateError(ctx, node) {
2528
2560
  const id = node.i;
@@ -2641,7 +2673,7 @@ function serializeSequence(ctx, node) {
2641
2673
  result += (item && result && ",") + item;
2642
2674
  }
2643
2675
  ctx.base.stack.pop();
2644
- if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + node.s + ",d:" + node.l + "}";
2676
+ if (result) return "{__SEROVAL_SEQUENCE__:!0,v:[" + result + "],t:" + +node.s + ",d:" + +node.l + "}";
2645
2677
  }
2646
2678
  return "{__SEROVAL_SEQUENCE__:!0,v:[],t:-1,d:0}";
2647
2679
  }
@@ -2814,8 +2846,8 @@ function parseBoxed(ctx, depth, id, current) {
2814
2846
  return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
2815
2847
  }
2816
2848
  function parseView(ctx, depth, type, id, current) {
2817
- current = getArrayBufferView(ctx.base, current);
2818
- return createViewNode(type, id, current, parseSOS(ctx, depth, current.buffer));
2849
+ const view = getArrayBufferView(ctx.base, readArrayBufferView(current, type === 20));
2850
+ return createViewNode(type, id, current, view, parseSOS(ctx, depth, view.buffer));
2819
2851
  }
2820
2852
  function parseError(ctx, depth, type, id, current) {
2821
2853
  const options = getErrorOptions(current, ctx.base.features);
@@ -2906,14 +2938,15 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
2906
2938
  case 12: return parseSet(ctx, depth, id, current);
2907
2939
  case 13: return parsePromise(ctx, depth, id, current);
2908
2940
  case 14: return createRegExpNode(id, current);
2909
- case 15: return createTemporalNode(id, getTemporalType(currentClass), current);
2941
+ case 15: return createTemporalNode(id, getTemporalType(currentClass), currentClass, current);
2910
2942
  case 16: return parsePlainObject(ctx, depth, id, current, !!currentClass);
2911
2943
  default: throw new SerovalUnsupportedTypeError(current);
2912
2944
  }
2913
2945
  }
2914
2946
  function parseObject(ctx, depth, id, current) {
2915
2947
  if (Array.isArray(current)) return parseArray(ctx, depth, id, current);
2916
- if (isStream(current)) return isLiveStream(current) ? parseLiveStream(ctx, depth, id, current) : parseStream(ctx, depth, id, current);
2948
+ if (isLiveStream(current)) return parseLiveStream(ctx, depth, id, current);
2949
+ if (current instanceof Stream) return parseStream(ctx, depth, id, current);
2917
2950
  if (isSequence(current)) return parseSequence(ctx, depth, id, current);
2918
2951
  const currentClass = getObjectClass(current);
2919
2952
  if (currentClass === OpaqueReference) return parseSOS(ctx, depth, current.replacement);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seroval",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "1.7.6",
5
+ "version": "1.7.7",
6
6
  "files": [
7
7
  "dist"
8
8
  ],