| Index: test/mjsunit/mjsunit.js
|
| diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js
|
| index 320e8d15d360e23daa3e88ff257b35b628c49080..2c52a31e604451065363bc1fc90d1452a7b20427 100644
|
| --- a/test/mjsunit/mjsunit.js
|
| +++ b/test/mjsunit/mjsunit.js
|
| @@ -51,6 +51,25 @@ function fail(expected, found, name_opt) {
|
| }
|
|
|
|
|
| +function deepObjectEquals(a, b) {
|
| + var aProps = [];
|
| + for (var key in a)
|
| + aProps.push(key);
|
| + var bProps = [];
|
| + for (var key in b)
|
| + bProps.push(key);
|
| + aProps.sort();
|
| + bProps.sort();
|
| + if (!deepEquals(aProps, bProps))
|
| + return false;
|
| + for (var i = 0; i < aProps.length; i++) {
|
| + if (!deepEquals(a[aProps[i]], b[aProps[i]]))
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +
|
| function deepEquals(a, b) {
|
| if (a == b) return true;
|
| if (typeof a == "number" && typeof b == "number" && isNaN(a) && isNaN(b)) {
|
| @@ -73,8 +92,9 @@ function deepEquals(a, b) {
|
| }
|
| }
|
| return true;
|
| + } else {
|
| + return deepObjectEquals(a, b);
|
| }
|
| - return false;
|
| }
|
|
|
|
|
| @@ -130,12 +150,20 @@ function assertNotNull(value, name_opt) {
|
| }
|
|
|
|
|
| -function assertThrows(code) {
|
| +function assertThrows(code, type_opt, cause_opt) {
|
| var threwException = true;
|
| try {
|
| - eval(code);
|
| + if (typeof code == 'function') {
|
| + code();
|
| + } else {
|
| + eval(code);
|
| + }
|
| threwException = false;
|
| } catch (e) {
|
| + if (typeof type_opt == 'function')
|
| + assertInstanceof(e, type_opt);
|
| + if (arguments.length >= 3)
|
| + assertEquals(e.type, cause_opt);
|
| // Do nothing.
|
| }
|
| if (!threwException) assertTrue(false, "did not throw exception");
|
|
|