Skip to content

Commit

Permalink
account for IE7/IE8 String constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Sep 23, 2016
1 parent aea24cb commit 6ac4568
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var indexOf = exports.indexOf = function(arr, obj, start) {
* @param {Object} val Initial value.
* @return {*}
*/
exports.reduce = function(arr, fn, val) {
var reduce = exports.reduce = function(arr, fn, val) {
var rval = val;

for (var i = 0, l = arr.length; i < l; i++) {
Expand Down Expand Up @@ -313,7 +313,7 @@ exports.trim = function(str) {
* @return {Object}
*/
exports.parseQuery = function(qs) {
return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair) {
return reduce(qs.replace('?', '').split('&'), function(obj, pair) {
var i = pair.indexOf('=');
var key = pair.slice(0, i);
var val = pair.slice(++i);
Expand Down Expand Up @@ -449,9 +449,19 @@ exports.stringify = function(value) {
.replace(/,(\n|$)/g, '$1');
}

for (var prop in value) {
if (Object.prototype.hasOwnProperty.call(value, prop)) {
return jsonStringify(exports.canonicalize(value, null, typeHint), 2).replace(/,(\n|$)/g, '$1');
// IE7/IE8 has a bizarre String constructor; needs to be coerced
// into an array and back again.
var obj = value;
if (typeof value === 'string' && typeHint === 'object') {
obj = Array.prototype.slice.apply(value);
}
for (var prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
var result = jsonStringify(exports.canonicalize(obj, null, typeHint), 2).replace(/,(\n|$)/g, '$1');
return obj === value ? result : reduce(obj, function(acc, char, idx) {
acc[idx] = char;
return acc;
}, {});
}
}

Expand Down Expand Up @@ -750,7 +760,7 @@ exports.stackTraceFilter = function() {
return function(stack) {
stack = stack.split('\n');

stack = exports.reduce(stack, function(list, line) {
stack = reduce(stack, function(list, line) {
if (isMochaInternal(line)) {
return list;
}
Expand Down

0 comments on commit 6ac4568

Please sign in to comment.