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
fixes #2061
  • Loading branch information
kostia authored and dignifiedquire committed Feb 19, 2017
1 parent 89a7a1c commit e095411
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,32 @@ var Karma = function (socket, iframe, opener, navigator, location) {
return false
}

this.result = function (result) {
this.result = function (originalResult) {
var convertedResult = {}

// Convert all array-like objects to real arrays.
for (var propertyName in originalResult) {
if (originalResult.hasOwnProperty(propertyName)) {
var propertyValue = originalResult[propertyName]

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

if (!startEmitted) {
socket.emit('start', {total: null})
startEmitted = true
}

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

resultsBuffer.push(result)
resultsBuffer.push(convertedResult)

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

0 comments on commit e095411

Please sign in to comment.