File tree Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,51 @@ function toObject(val) {
11
11
return Object ( val ) ;
12
12
}
13
13
14
- module . exports = Object . assign || function ( target , source ) {
14
+ function shouldUseNative ( ) {
15
+ try {
16
+ if ( ! Object . assign ) {
17
+ return false ;
18
+ }
19
+
20
+ // Detect buggy property enumeration order in older V8 versions.
21
+
22
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4118
23
+ var test1 = new String ( 'abc' ) ; // eslint-disable-line
24
+ test1 [ 5 ] = 'de' ;
25
+ if ( Object . getOwnPropertyNames ( test1 ) [ 0 ] === '5' ) {
26
+ return false ;
27
+ }
28
+
29
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
30
+ var test2 = { } ;
31
+ for ( var i = 0 ; i < 10 ; i ++ ) {
32
+ test2 [ '_' + String . fromCharCode ( i ) ] = i ;
33
+ }
34
+ var order2 = Object . getOwnPropertyNames ( test2 ) . map ( function ( n ) {
35
+ return test2 [ n ] ;
36
+ } ) ;
37
+ if ( order2 . join ( '' ) !== '0123456789' ) {
38
+ return false ;
39
+ }
40
+
41
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
42
+ var test3 = { } ;
43
+ 'abcdefghijklmnopqrst' . split ( '' ) . forEach ( function ( letter ) {
44
+ test3 [ letter ] = letter ;
45
+ } ) ;
46
+ if ( Object . keys ( Object . assign ( { } , test3 ) ) . join ( '' ) !==
47
+ 'abcdefghijklmnopqrst' ) {
48
+ return false ;
49
+ }
50
+
51
+ return true ;
52
+ } catch ( e ) {
53
+ // We don't expect any of the above to throw, but better to be safe.
54
+ return false ;
55
+ }
56
+ }
57
+
58
+ module . exports = shouldUseNative ( ) ? Object . assign : function ( target , source ) {
15
59
var from ;
16
60
var to = toObject ( target ) ;
17
61
var symbols ;
You can’t perform that action at this time.
0 commit comments