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 36d75f3
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 @@ -126,16 +126,30 @@ var Karma = function (socket, iframe, opener, navigator, location) {
}

this.result = function (result) {
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 (!startEmitted) {
socket.emit('start', {total: null})
startEmitted = true
}

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 36d75f3

Please sign in to comment.