1- /* eslint-disable es/no-map -- safe */
2- /* eslint-disable es/no-set -- safe */
3- 'use const' ;
4- var isSymbol = require ( './is-symbol' ) ;
5- var toObject = require ( './to-object' ) ;
6- var getOwnPropertyNames = require ( './object-get-own-property-names' ) ;
7- var classof = require ( './classof' ) ;
1+ 'use strict' ;
2+ var isSymbol = require ( '../internals/is-symbol' ) ;
3+ var getOwnPropertyNames = require ( '../internals/object-get-own-property-names' ) ;
4+ var classof = require ( '../internals/classof' ) ;
5+ var getBuiltin = require ( '../internals/get-built-in' ) ;
6+ var isObject = require ( '../internals/is-object' ) ;
7+ var has = require ( '../internals/has' ) ;
8+
9+ var Set = getBuiltin ( 'Set' ) ;
10+ var Map = getBuiltin ( 'Map' ) ;
811
912function createDataCloneError ( message ) {
1013 if ( typeof DOMException === 'function' ) {
@@ -21,18 +24,19 @@ function createDataCloneError(message) {
2124 */
2225module . exports = function structuredCloneInternal ( weakmap , value ) {
2326 if ( isSymbol ( value ) ) throw createDataCloneError ( 'Symbols are not cloneable' ) ;
24- if ( typeof value !== 'function' && typeof value !== 'object' ) return value ;
27+ if ( ! isObject ( value ) ) return value ;
2528 if ( value === null ) return null ;
2629 if ( weakmap . has ( value ) ) return weakmap . get ( value ) ; // effectively preserves circular references
2730
2831 var cloned , i , deep ;
32+ var type = classof ( value ) ;
2933
30- switch ( classof ( value ) ) {
34+ switch ( type ) {
3135 case 'Boolean' :
3236 case 'BigInt' :
3337 case 'Number' :
3438 case 'String' :
35- cloned = toObject ( value . valueOf ( ) ) ;
39+ cloned = Object ( value . valueOf ( ) ) ;
3640 break ;
3741 case 'Date' :
3842 cloned = new Date ( value . valueOf ( ) ) ;
@@ -67,12 +71,12 @@ module.exports = function structuredCloneInternal(weakmap, value) {
6771 deep = true ;
6872 break ;
6973 default :
70- throw createDataCloneError ( 'Uncloneable type: ' + classof ( value ) ) ;
74+ throw createDataCloneError ( 'Uncloneable type: ' + type ) ;
7175 }
7276
7377 weakmap . set ( value , cloned ) ;
7478
75- if ( deep ) switch ( classof ( value ) ) {
79+ if ( deep ) switch ( type ) {
7680 case 'Map' :
7781 value . forEach ( function ( v , k ) {
7882 cloned . set ( structuredCloneInternal ( weakmap , k ) , structuredCloneInternal ( weakmap , v ) ) ;
@@ -86,14 +90,13 @@ module.exports = function structuredCloneInternal(weakmap, value) {
8690 case 'Error' :
8791 // Attempt to clone the stack.
8892 if (
89- ! Object . prototype . hasOwnProperty . call ( value , 'stack' ) && // Chrome, Safari
90- ! Object . prototype . hasOwnProperty . call ( Error . prototype , 'stack' ) // Firefox
93+ ! has ( value , 'stack' ) && // Chrome, Safari
94+ ! has ( Error . prototype , 'stack' ) // Firefox
9195 ) break ;
9296 try {
9397 cloned . stack = structuredCloneInternal ( weakmap , value . stack ) ;
94- } catch ( error ) {
95- if ( classof ( error ) === 'TypeError' ) return cloned ; // Stack cloning not avaliable.
96- throw error ; // Unexpected error while cloning.
98+ } catch ( _ ) {
99+ return cloned ; // Stack cloning not avaliable.
97100 }
98101 break ;
99102 case 'Array' :
0 commit comments