Skip to content

Commit e095411

Browse files
kostiadignifiedquire
authored andcommitted
fix(client): don't crash if receive array-like results
fixes #2061
1 parent 89a7a1c commit e095411

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

client/karma.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,32 @@ var Karma = function (socket, iframe, opener, navigator, location) {
118118
return false
119119
}
120120

121-
this.result = function (result) {
121+
this.result = function (originalResult) {
122+
var convertedResult = {}
123+
124+
// Convert all array-like objects to real arrays.
125+
for (var propertyName in originalResult) {
126+
if (originalResult.hasOwnProperty(propertyName)) {
127+
var propertyValue = originalResult[propertyName]
128+
129+
if (Object.prototype.toString.call(propertyValue) === '[object Array]') {
130+
convertedResult[propertyName] = Array.prototype.slice.call(propertyValue)
131+
} else {
132+
convertedResult[propertyName] = propertyValue
133+
}
134+
}
135+
}
136+
122137
if (!startEmitted) {
123138
socket.emit('start', {total: null})
124139
startEmitted = true
125140
}
126141

127142
if (resultsBufferLimit === 1) {
128-
return socket.emit('result', result)
143+
return socket.emit('result', convertedResult)
129144
}
130145

131-
resultsBuffer.push(result)
146+
resultsBuffer.push(convertedResult)
132147

133148
if (resultsBuffer.length === resultsBufferLimit) {
134149
socket.emit('result', resultsBuffer)

0 commit comments

Comments
 (0)