@@ -625,174 +625,6 @@ export function arrayRemove(array, value) {
625
625
return index ;
626
626
}
627
627
628
- /**
629
- * Creates a deep copy of the source, which should be an object or an array.
630
- * - If no destination is supplied, a copy of the object or array is created.
631
- * - If a destination is provided, all of its elements (for arrays) or properties (for objects) are deleted,
632
- * and then all elements/properties from the source are copied to it.
633
- * - If the source is not an object or array (including null and undefined), the source is returned.
634
- * - If the source is identical to the destination, an exception will be thrown.
635
- *
636
- * @template T The type of the source and destination.
637
- * @param {T } source The source that will be used to make a copy. Can be any type, including primitives, null, and undefined.
638
- * @param {T } [destination] Destination into which the source is copied. If provided, must be of the same type as source.
639
- * @returns {T } A deep copy of the source.
640
- */
641
- export function copy ( source , destination , maxDepth ) {
642
- const stackSource = [ ] ;
643
- const stackDest = [ ] ;
644
- maxDepth = isValidObjectMaxDepth ( maxDepth ) ? maxDepth : NaN ;
645
-
646
- if ( destination ) {
647
- if ( isTypedArray ( destination ) || isArrayBuffer ( destination ) ) {
648
- throw ngMinErr (
649
- "cpta" ,
650
- "Can't copy! TypedArray destination cannot be mutated." ,
651
- ) ;
652
- }
653
- if ( source === destination ) {
654
- throw ngMinErr (
655
- "cpi" ,
656
- "Can't copy! Source and destination are identical." ,
657
- ) ;
658
- }
659
-
660
- // Empty the destination object
661
- if ( isArray ( destination ) ) {
662
- destination . length = 0 ;
663
- } else {
664
- forEach ( destination , ( value , key ) => {
665
- if ( key !== "$$hashKey" ) {
666
- delete destination [ key ] ;
667
- }
668
- } ) ;
669
- }
670
-
671
- stackSource . push ( source ) ;
672
- stackDest . push ( destination ) ;
673
- return copyRecurse ( source , destination , maxDepth ) ;
674
- }
675
-
676
- return copyElement ( source , maxDepth ) ;
677
-
678
- function copyRecurse ( source , destination , maxDepth ) {
679
- maxDepth -- ;
680
- if ( maxDepth < 0 ) {
681
- return "..." ;
682
- }
683
- const h = destination . $$hashKey ;
684
- let key ;
685
- if ( isArray ( source ) ) {
686
- for ( let i = 0 , ii = source . length ; i < ii ; i ++ ) {
687
- destination . push ( copyElement ( source [ i ] , maxDepth ) ) ;
688
- }
689
- } else if ( isBlankObject ( source ) ) {
690
- // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
691
- for ( key in source ) {
692
- destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
693
- }
694
- } else if ( source && typeof source . hasOwnProperty === "function" ) {
695
- // Slow path, which must rely on hasOwnProperty
696
- for ( key in source ) {
697
- if ( Object . prototype . hasOwnProperty . call ( source , key ) ) {
698
- destination [ key ] = copyElement ( source [ key ] , maxDepth ) ;
699
- }
700
- }
701
- }
702
- setHashKey ( destination , h ) ;
703
- return destination ;
704
- }
705
-
706
- function copyElement ( source , maxDepth ) {
707
- // Simple values
708
- if ( ! isObject ( source ) ) {
709
- return source ;
710
- }
711
-
712
- // Already copied values
713
- const index = stackSource . indexOf ( source ) ;
714
- if ( index !== - 1 ) {
715
- return stackDest [ index ] ;
716
- }
717
-
718
- if ( isWindow ( source ) || isScope ( source ) ) {
719
- throw ngMinErr (
720
- "cpws" ,
721
- "Can't copy! Making copies of Window or Scope instances is not supported." ,
722
- ) ;
723
- }
724
-
725
- let needsRecurse = false ;
726
- let destination = copyType ( source ) ;
727
-
728
- if ( destination === undefined ) {
729
- destination = isArray ( source )
730
- ? [ ]
731
- : Object . create ( Object . getPrototypeOf ( source ) ) ;
732
- needsRecurse = true ;
733
- }
734
-
735
- stackSource . push ( source ) ;
736
- stackDest . push ( destination ) ;
737
-
738
- return needsRecurse
739
- ? copyRecurse ( source , destination , maxDepth )
740
- : destination ;
741
- }
742
-
743
- function copyType ( source ) {
744
- switch ( toString . call ( source ) ) {
745
- case "[object Int8Array]" :
746
- case "[object Int16Array]" :
747
- case "[object Int32Array]" :
748
- case "[object Float32Array]" :
749
- case "[object Float64Array]" :
750
- case "[object Uint8Array]" :
751
- case "[object Uint8ClampedArray]" :
752
- case "[object Uint16Array]" :
753
- case "[object Uint32Array]" :
754
- return new source . constructor (
755
- copyElement ( source . buffer ) ,
756
- source . byteOffset ,
757
- source . length ,
758
- ) ;
759
-
760
- case "[object ArrayBuffer]" :
761
- // Support: IE10
762
- if ( ! source . slice ) {
763
- // If we're in this case we know the environment supports ArrayBuffer
764
- /* eslint-disable no-undef */
765
- const copied = new ArrayBuffer ( source . byteLength ) ;
766
- new Uint8Array ( copied ) . set ( new Uint8Array ( source ) ) ;
767
- /* eslint-enable */
768
- return copied ;
769
- }
770
- return source . slice ( 0 ) ;
771
-
772
- case "[object Boolean]" :
773
- case "[object Number]" :
774
- case "[object String]" :
775
- case "[object Date]" :
776
- return new source . constructor ( source . valueOf ( ) ) ;
777
-
778
- case "[object RegExp]" :
779
- const re = new RegExp (
780
- source . source ,
781
- source . toString ( ) . match ( / [ ^ / ] * $ / ) [ 0 ] ,
782
- ) ;
783
- re . lastIndex = source . lastIndex ;
784
- return re ;
785
-
786
- case "[object Blob]" :
787
- return new source . constructor ( [ source ] , { type : source . type } ) ;
788
- }
789
-
790
- if ( isFunction ( source . cloneNode ) ) {
791
- return source . cloneNode ( true ) ;
792
- }
793
- }
794
- }
795
-
796
628
export function simpleCompare ( a , b ) {
797
629
return a === b || ( a !== a && b !== b ) ;
798
630
}
@@ -1407,7 +1239,7 @@ export function minErr(module) {
1407
1239
const template = arguments [ 1 ] ;
1408
1240
let message = `[${ module ? `${ module } :` : "" } ${ code } ] ` ;
1409
1241
const templateArgs = sliceArgs ( arguments , 2 ) . map ( ( arg ) =>
1410
- toDebugString ( arg , minErrConfig . objectMaxDepth ) ,
1242
+ toDebugString ( arg ) ,
1411
1243
) ;
1412
1244
let paramPrefix ;
1413
1245
let i ;
@@ -1443,17 +1275,9 @@ export function minErr(module) {
1443
1275
} ;
1444
1276
}
1445
1277
1446
- export function serializeObject ( obj , maxDepth ) {
1278
+ export function serializeObject ( obj ) {
1447
1279
const seen = [ ] ;
1448
- let copyObj = obj ;
1449
- // There is no direct way to stringify object until reaching a specific depth
1450
- // and a very deep object can cause a performance issue, so we copy the object
1451
- // based on this specific depth and then stringify it.
1452
- if ( isValidObjectMaxDepth ( maxDepth ) ) {
1453
- // This file is also included in `angular-loader`, so `copy()` might not always be available in
1454
- // the closure. Therefore, it is lazily retrieved as `angular.copy()` when needed.
1455
- copyObj = copy ( obj , null , maxDepth ) ;
1456
- }
1280
+ let copyObj = structuredClone ( obj ) ;
1457
1281
return JSON . stringify ( copyObj , ( key , val ) => {
1458
1282
const replace = toJsonReplacer ( key , val ) ;
1459
1283
if ( isObject ( replace ) ) {
@@ -1465,15 +1289,15 @@ export function serializeObject(obj, maxDepth) {
1465
1289
} ) ;
1466
1290
}
1467
1291
1468
- export function toDebugString ( obj , maxDepth ) {
1292
+ export function toDebugString ( obj ) {
1469
1293
if ( typeof obj === "function" ) {
1470
1294
return obj . toString ( ) . replace ( / \{ [ \s \S ] * $ / , "" ) ;
1471
1295
}
1472
1296
if ( isUndefined ( obj ) ) {
1473
1297
return "undefined" ;
1474
1298
}
1475
1299
if ( typeof obj !== "string" ) {
1476
- return serializeObject ( obj , maxDepth ) ;
1300
+ return serializeObject ( obj ) ;
1477
1301
}
1478
1302
return obj ;
1479
1303
}
0 commit comments