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 Jun 3, 2016
1 parent ca95553 commit 544f7bb
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 @@ -125,17 +125,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 544f7bb

Please sign in to comment.