Index: test/mjsunit/mjsunit.js |
diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js |
index f08c29339ab788cc912ef185f651c028261f48e8..27f4d3942ad035fe9f743702381c7e6cff783737 100644 |
--- a/test/mjsunit/mjsunit.js |
+++ b/test/mjsunit/mjsunit.js |
@@ -113,14 +113,39 @@ var assertUnoptimized; |
(function () { // Scope for utility functions. |
+ var ObjectPrototypeToString = Object.prototype.toString; |
+ var NumberPrototypeValueOf = Number.prototype.valueOf; |
+ var BooleanPrototypeValueOf = Boolean.prototype.valueOf; |
+ var StringPrototypeValueOf = String.prototype.valueOf; |
+ var DatePrototypeValueOf = Date.prototype.valueOf; |
+ var RegExpPrototypeToString = RegExp.prototype.toString; |
+ var ArrayPrototypeMap = Array.prototype.map; |
+ var ArrayPrototypeJoin = Array.prototype.join; |
+ |
function classOf(object) { |
// Argument must not be null or undefined. |
- var string = Object.prototype.toString.call(object); |
+ var string = ObjectPrototypeToString.call(object); |
// String has format [object <ClassName>]. |
return string.substring(8, string.length - 1); |
} |
+ function ValueOf(value) { |
+ switch (classOf(value)) { |
+ case "Number": |
+ return NumberPrototypeValueOf.call(value); |
+ case "String": |
+ return StringPrototypeValueOf.call(value); |
+ case "Boolean": |
+ return BooleanPrototypeValueOf.call(value); |
+ case "Date": |
+ return DatePrototypeValueOf.call(value); |
+ default: |
+ return value; |
+ } |
+ } |
+ |
+ |
function PrettyPrint(value) { |
switch (typeof value) { |
case "string": |
@@ -137,19 +162,21 @@ var assertUnoptimized; |
if (value === null) return "null"; |
var objectClass = classOf(value); |
switch (objectClass) { |
- case "Number": |
- case "String": |
- case "Boolean": |
- case "Date": |
- return objectClass + "(" + PrettyPrint(value.valueOf()) + ")"; |
- case "RegExp": |
- return value.toString(); |
- case "Array": |
- return "[" + value.map(PrettyPrintArrayElement).join(",") + "]"; |
- case "Object": |
- break; |
- default: |
- return objectClass + "()"; |
+ case "Number": |
+ case "String": |
+ case "Boolean": |
+ case "Date": |
+ return objectClass + "(" + PrettyPrint(ValueOf(value)) + ")"; |
+ case "RegExp": |
+ return RegExpPrototypeToString.call(value); |
+ case "Array": |
+ var mapped = ArrayPrototypeMap.call(value, PrettyPrintArrayElement); |
+ var joined = ArrayPrototypeJoin.call(mapped, ","); |
+ return "[" + joined + "]"; |
+ case "Object": |
+ break; |
+ default: |
+ return objectClass + "()"; |
} |
// [[Class]] is "Object". |
var name = value.constructor.name; |
@@ -211,7 +238,8 @@ var assertUnoptimized; |
if (objectClass !== classOf(b)) return false; |
if (objectClass === "RegExp") { |
// For RegExp, just compare pattern and flags using its toString. |
- return (a.toString() === b.toString()); |
+ return RegExpPrototypeToString.call(a) === |
+ RegExpPrototypeToString.call(b); |
} |
// Functions are only identical to themselves. |
if (objectClass === "Function") return false; |
@@ -227,7 +255,7 @@ var assertUnoptimized; |
} |
if (objectClass === "String" || objectClass === "Number" || |
objectClass === "Boolean" || objectClass === "Date") { |
- if (a.valueOf() !== b.valueOf()) return false; |
+ if (ValueOf(a) !== ValueOf(b)) return false; |
} |
return deepObjectEquals(a, b); |
} |