Skip to content

Commit

Permalink
fix(client): don't crash if receive array-like results.
Browse files Browse the repository at this point in the history
  • Loading branch information
kostia committed Sep 15, 2016
1 parent ca95553 commit e7c0755
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,25 @@ var Karma = function (socket, iframe, opener, navigator, location) {
startEmitted = true
}

var fixedResult = {}

for (var propertyName in result) {
if (result.hasOwnProperty(propertyName)) {
var propertyValue = result[propertyName]

if (Object.prototype.toString.call(propertyValue) === '[object Array]') {
fixedResult[propertyName] = Array.prototype.slice.call(propertyValue)
} else {
fixedResult[propertyName] = propertyValue
}
}
}

if (resultsBufferLimit === 1) {
return socket.emit('result', result)
return socket.emit('result', fixedResult)
}

resultsBuffer.push(result)
resultsBuffer.push(fixedResult)

if (resultsBuffer.length === resultsBufferLimit) {
socket.emit('result', resultsBuffer)
Expand Down

0 comments on commit e7c0755

Please sign in to comment.