Skip to content

Commit

Permalink
Helpers: Fix array check not working for components loaded by setSour…
Browse files Browse the repository at this point in the history
…ce()

When the array comes from another JS context, as is the case when
using eval() in ComponentLoader.setSource() isinstance Array returns
false even if it is a proper array.
  • Loading branch information
jonnor committed Sep 21, 2014
1 parent e77a55d commit e5344d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/Helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ StreamSender = require('./Streams').StreamSender
StreamReceiver = require('./Streams').StreamReceiver
InternalSocket = require './InternalSocket'

isArray = (obj) ->
return Array.isArray(obj) if Array.isArray
return Object.prototype.toString.call(arg) == '[object Array]'

# MapComponent maps a single inport to a single outport, forwarding all
# groups from in to out and calling `func` on each incoming packet
exports.MapComponent = (component, func, config) ->
Expand Down Expand Up @@ -74,10 +78,10 @@ exports.MapComponent = (component, func, config) ->
exports.WirePattern = (component, config, proc) ->
# In ports
inPorts = if 'in' of config then config.in else 'in'
inPorts = [ inPorts ] unless inPorts instanceof Array
inPorts = [ inPorts ] unless isArray inPorts
# Out ports
outPorts = if 'out' of config then config.out else 'out'
outPorts = [ outPorts ] unless outPorts instanceof Array
outPorts = [ outPorts ] unless isArray outPorts
# Error port
config.error = 'error' unless 'error' of config
# For async process
Expand Down

0 comments on commit e5344d9

Please sign in to comment.