Chromium Code Reviews| Index: test/mjsunit/mjsunit.js |
| diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js |
| index 436bdc8184957fcf3a85f50f77d2a110a9980096..c4ae03843a8aebc74d72638664cf7362e73415bb 100644 |
| --- a/test/mjsunit/mjsunit.js |
| +++ b/test/mjsunit/mjsunit.js |
| @@ -31,16 +31,25 @@ function MjsUnitAssertionError(message) { |
| this.stack = new Error("").stack; |
| } |
| -MjsUnitAssertionError.prototype.toString = function () { |
| - return this.message; |
| -} |
| - |
| /* |
| * This file is included in all mini jsunit test cases. The test |
| * framework expects lines that signal failed tests to start with |
| * the f-word and ignore all other lines. |
| */ |
| + |
| +MjsUnitAssertionError.prototype.toString = function () { |
| + return this.message; |
| +}; |
| + |
| + |
| +function classOf(object) { |
| + var string = Object.prototype.toString.call(object); |
| + // String has format [object <ClassName>]. |
| + return string.substring(8, string.length - 1); |
| +} |
| + |
| + |
| function MjsUnitToString(value) { |
| switch (typeof value) { |
| case "string": |
| @@ -54,8 +63,7 @@ function MjsUnitToString(value) { |
| return String(value); |
| case "object": |
| if (value === null) return "null"; |
| - var clazz = Object.prototype.toString.call(value); |
| - clazz = clazz.substring(8, clazz.length - 1); |
| + var clazz = classOf(value); |
|
William Hesse
2011/04/14 08:13:03
object_class? Better than a misspelling.
|
| switch (clazz) { |
| case "Number": |
| case "String": |
| @@ -102,11 +110,13 @@ function fail(expected, found, name_opt) { |
| function deepObjectEquals(a, b) { |
| var aProps = []; |
| - for (var key in a) |
| + for (var key in a) { |
| aProps.push(key); |
| + } |
| var bProps = []; |
| - for (var key in b) |
| + for (key in b) { |
| bProps.push(key); |
| + } |
| aProps.sort(); |
| bProps.sort(); |
| if (!deepEquals(aProps, bProps)) |
| @@ -129,14 +139,16 @@ function deepEquals(a, b) { |
| return true; |
| } |
| if (a == null || b == null) return false; |
| - if (a.constructor === RegExp || b.constructor === RegExp) { |
| - return (a.constructor === b.constructor) && (a.toString() === b.toString()); |
| + var aClass = classOf(a); |
| + var bClass = classOf(b); |
| + if (aClass === "RegExp" || bClass === "RegExp") { |
| + return (aClass === bClass) && (a.toString() === b.toString()); |
| } |
| if ((typeof a) !== 'object' || (typeof b) !== 'object' || |
| (a === null) || (b === null)) |
| return false; |
| - if (a.constructor === Array) { |
| - if (b.constructor !== Array) |
| + if (aClass === "Array") { |
| + if (bClass !== "Array") |
| return false; |
|
William Hesse
2011/04/14 08:13:03
What about if a is an Object and b is an Array?
{0
|
| if (a.length != b.length) |
| return false; |