lib/renderer/api/remote.js
function wrapArgs (args, visited = new Set()) {
  const valueToMeta = (value) => {
    // Check for circular reference.
    if (visited.has(value)) {
      return {
        type: 'value',
        value: null
      }
    }

    if (Array.isArray(value)) {
      visited.add(value)
      const meta = {
        type: 'array',
        value: wrapArgs(value, visited)
      }
      visited.delete(value)
      return meta
    } else if (bufferUtils.isBuffer(value)) {
      return {
        type: 'buffer',
        value: bufferUtils.bufferToMeta(value)
      }
    } else if (value instanceof Date) {
      return {
        type: 'date',
        value: value.getTime()
      }
    } else if ((value != null) && typeof value === 'object') {
      if (isPromise(value)) {
        return {
          type: 'promise',
          then: valueToMeta(function (onFulfilled, onRejected) {
            value.then(onFulfilled, onRejected)
          })
        }
      } else if (v8Util.getHiddenValue(value, 'atomId')) {
        return {
          type: 'remote-object',
          id: v8Util.getHiddenValue(value, 'atomId')
        }
      }

      const meta = {
        type: 'object',
        name: value.constructor ? value.constructor.name : '',
        members: []
      }
      visited.add(value)
      for (const prop in value) {
        meta.members.push({
          name: prop,
          value: valueToMeta(value[prop])
        })
      }
      visited.delete(value)
      return meta
    } else if (typeof value === 'function' && v8Util.getHiddenValue(value, 'returnValue')) {
      return {
        type: 'function-with-return-value',
        value: valueToMeta(value())
      }
    } else if (typeof value === 'function') {
      return {
        type: 'function',
        id: callbacksRegistry.add(value),
        location: v8Util.getHiddenValue(value, 'location'),
        length: value.length
      }
    } else {
      return {
        type: 'value',
        value: value
      }
    }
  }
  return args.map(valueToMeta)
}
function wrapArgs (args, visited = new Set()) {
  const valueToMeta = (value) => {
    // Check for circular reference.
    if (visited.has(value)) {
      return {
        type: 'value',
        value: null
      }
    }

    if (Array.isArray(value)) {
      visited.add(value)
      const meta = {
        type: 'array',
        value: wrapArgs(value, visited)
      }
      visited.delete(value)
      return meta
    } else if (bufferUtils.isBuffer(value)) {
      return {
        type: 'buffer',
        value: bufferUtils.bufferToMeta(value)
      }
    } else if (value instanceof Date) {
      return {
        type: 'date',
        value: value.getTime()
      }
    } else if ((value != null) && typeof value === 'object') {
      if (isPromise(value)) {
        return {
          type: 'promise',
          then: valueToMeta(function (onFulfilled, onRejected) {
            value.then(onFulfilled, onRejected)
          })
        }
      } else if (v8Util.getHiddenValue(value, 'atomId')) {
        return {
          type: 'remote-object',
          id: v8Util.getHiddenValue(value, 'atomId')
        }
      }

      const meta = {
        type: 'object',
        name: value.constructor ? value.constructor.name : '',
        members: []
      }
      visited.add(value)
      for (const prop in value) {
        meta.members.push({
          name: prop,
          value: valueToMeta(value[prop])
        })
      }
      visited.delete(value)
      return meta
    } else if (typeof value === 'function' && v8Util.getHiddenValue(value, 'returnValue')) {
      return {
        type: 'function-with-return-value',
        value: valueToMeta(value())
      }
    } else if (typeof value === 'function') {
      return {
        type: 'function',
        id: callbacksRegistry.add(value),
        location: v8Util.getHiddenValue(value, 'location'),
        length: value.length
      }
    } else {
      return {
        type: 'value',
        value: value
      }
    }
  }
  return args.map(valueToMeta)
}
function wrapArgs ( args , visited = new Set ( ) ) { const valueToMeta = ( value ) => { // Check for circular reference. if ( visited . has ( value ) ) { return { type : 'value' , value : null } } if ( Array . isArray ( value ) ) { visited . add ( value ) const meta = { type : 'array' , value : wrapArgs ( value , visited ) } visited . delete ( value ) return meta } else if ( bufferUtils . isBuffer ( value ) ) { return { type : 'buffer' , value : bufferUtils . bufferToMeta ( value ) } } else if ( value instanceof Date ) { return { type : 'date' , value : value . getTime ( ) } } else if ( ( value != null ) && typeof value === 'object' ) { if ( isPromise ( value ) ) { return { type : 'promise' , then : valueToMeta ( function ( onFulfilled , onRejected ) { value . then ( onFulfilled , onRejected ) } ) } } else if ( v8Util . getHiddenValue ( value , 'atomId' ) ) { return { type : 'remote-object' , id : v8Util . getHiddenValue ( value , 'atomId' ) } } const meta = { type : 'object' , name : value . constructor ? value . constructor . name : '' , members : [ ] } visited . add ( value ) for ( const prop in value ) { meta . members . push ( { name : prop , value : valueToMeta ( value [ prop ] ) } ) } visited . delete ( value ) return meta } else if ( typeof value === 'function' && v8Util . getHiddenValue ( value , 'returnValue' ) ) { return { type : 'function-with-return-value' , value : valueToMeta ( value ( ) ) } } else if ( typeof value === 'function' ) { return { type : 'function' , id : callbacksRegistry . add ( value ) , location : v8Util . getHiddenValue ( value , 'location' ) , length : value . length } } else { return { type : 'value' , value : value } } } return args . map ( valueToMeta ) }
Convert the arguments object into an array of meta data.
Convert the arguments object into an array of meta data .