Commit 7aec228d authored by lrn@chromium.org's avatar lrn@chromium.org

Cleanup of mjsunit.js code and make assertEquals more strict.

Encapsulate the helper functions in mjsunit.js.
Now only exposes the exception class and the assertXXX functions.

Make assertEquals use === instead of ==.
This prevents a lot of possiblefalse positives in tests, and avoids
having to do assertTrue(expected === actual) when you need it.

Fixed some tests that were either buggy or assuming == test.

Review URL: http://codereview.chromium.org/6869007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7628 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dab8f48e
......@@ -33,43 +33,43 @@ function f1(a) {
return a;
}
assertTrue(this === f0.apply(), "1-0");
assertSame(this, f0.apply(), "1-0");
assertTrue(this === f0.apply(this), "2a");
assertTrue(this === f0.apply(this, new Array(1)), "2b");
assertTrue(this === f0.apply(this, new Array(2)), "2c");
assertTrue(this === f0.apply(this, new Array(4242)), "2d");
assertSame(this, f0.apply(this), "2a");
assertSame(this, f0.apply(this, new Array(1)), "2b");
assertSame(this, f0.apply(this, new Array(2)), "2c");
assertSame(this, f0.apply(this, new Array(4242)), "2d");
assertTrue(this === f0.apply(null), "3a");
assertTrue(this === f0.apply(null, new Array(1)), "3b");
assertTrue(this === f0.apply(null, new Array(2)), "3c");
assertTrue(this === f0.apply(this, new Array(4242)), "3d");
assertSame(this, f0.apply(null), "3a");
assertSame(this, f0.apply(null, new Array(1)), "3b");
assertSame(this, f0.apply(null, new Array(2)), "3c");
assertSame(this, f0.apply(this, new Array(4242)), "3d");
assertTrue(this === f0.apply(void 0), "4a");
assertTrue(this === f0.apply(void 0, new Array(1)), "4b");
assertTrue(this === f0.apply(void 0, new Array(2)), "4c");
assertSame(this, f0.apply(void 0), "4a");
assertSame(this, f0.apply(void 0, new Array(1)), "4b");
assertSame(this, f0.apply(void 0, new Array(2)), "4c");
assertTrue(void 0 === f1.apply(), "1-1");
assertEquals(void 0, f1.apply(), "1-1");
assertTrue(void 0 === f1.apply(this), "5a");
assertTrue(void 0 === f1.apply(this, new Array(1)), "5b");
assertTrue(void 0 === f1.apply(this, new Array(2)), "5c");
assertTrue(void 0 === f1.apply(this, new Array(4242)), "5d");
assertTrue(42 === f1.apply(this, new Array(42, 43)), "5e");
assertEquals(void 0, f1.apply(this), "5a");
assertEquals(void 0, f1.apply(this, new Array(1)), "5b");
assertEquals(void 0, f1.apply(this, new Array(2)), "5c");
assertEquals(void 0, f1.apply(this, new Array(4242)), "5d");
assertEquals(42, f1.apply(this, new Array(42, 43)), "5e");
assertEquals("foo", f1.apply(this, new Array("foo", "bar", "baz", "bo")), "5f");
assertTrue(void 0 === f1.apply(null), "6a");
assertTrue(void 0 === f1.apply(null, new Array(1)), "6b");
assertTrue(void 0 === f1.apply(null, new Array(2)), "6c");
assertTrue(void 0 === f1.apply(null, new Array(4242)), "6d");
assertTrue(42 === f1.apply(null, new Array(42, 43)), "6e");
assertEquals(void 0, f1.apply(null), "6a");
assertEquals(void 0, f1.apply(null, new Array(1)), "6b");
assertEquals(void 0, f1.apply(null, new Array(2)), "6c");
assertEquals(void 0, f1.apply(null, new Array(4242)), "6d");
assertEquals(42, f1.apply(null, new Array(42, 43)), "6e");
assertEquals("foo", f1.apply(null, new Array("foo", "bar", "baz", "bo")), "6f");
assertTrue(void 0 === f1.apply(void 0), "7a");
assertTrue(void 0 === f1.apply(void 0, new Array(1)), "7b");
assertTrue(void 0 === f1.apply(void 0, new Array(2)), "7c");
assertTrue(void 0 === f1.apply(void 0, new Array(4242)), "7d");
assertTrue(42 === f1.apply(void 0, new Array(42, 43)), "7e");
assertEquals(void 0, f1.apply(void 0), "7a");
assertEquals(void 0, f1.apply(void 0, new Array(1)), "7b");
assertEquals(void 0, f1.apply(void 0, new Array(2)), "7c");
assertEquals(void 0, f1.apply(void 0, new Array(4242)), "7d");
assertEquals(42, f1.apply(void 0, new Array(42, 43)), "7e");
assertEquals("foo", f1.apply(void 0, new Array("foo", "bar", "ba", "b")), "7f");
var arr = new Array(42, "foo", "fish", "horse");
......@@ -108,7 +108,7 @@ function s() {
assertEquals("bar42foofishhorse", s.apply("bar", arr), "apply to string");
function al() {
assertEquals(345, this);
assertEquals(Object(345), this);
return arguments.length + arguments[arguments.length - 1];
}
......@@ -186,7 +186,7 @@ primes[0] = "";
primes[1] = holey;
assertThrows("String.prototype.concat.apply.apply('foo', primes)");
assertEquals("morseper",
String.prototype.concat.apply.apply(String.prototype.concat, primes),
String.prototype.concat.apply.apply(String.prototype.concat, primes),
"moreseper-prime");
delete(Array.prototype["1"]);
......@@ -73,11 +73,11 @@ function NonObjectReceiver(receiver) {
return ReturnReceiver.apply(receiver, arguments);
}
assertEquals(42, NonObjectReceiver(42));
assertEquals(Object(42), NonObjectReceiver(42));
assertEquals("object", typeof NonObjectReceiver(42));
assertTrue(NonObjectReceiver(42) instanceof Number);
assertTrue(this === NonObjectReceiver(null));
assertTrue(this === NonObjectReceiver(void 0));
assertInstanceof(NonObjectReceiver(42), Number);
assertSame(this, NonObjectReceiver(null));
assertSame(this, NonObjectReceiver(void 0));
function FunctionReceiver() {
......
......@@ -79,36 +79,38 @@ assertTrue(typeof(A(10000)) == 'undefined');
assertTrue(typeof(A(10000, 0)) == 'undefined');
// String access.
assertEquals(0, A('0'));
assertEquals(0, A('0',1));
assertEquals('0', A('0'));
assertEquals('0', A('0',1));
assertEquals(2, A('1',2));
assertEquals(2, A('1',2,3,4,5));
assertEquals(5, A('4',2,3,4,5));
assertTrue(typeof A('1') == 'undefined');
assertTrue(typeof A('3',2,1) == 'undefined');
assertEquals('undefined', typeof A('1'));
assertEquals('undefined', typeof A('3',2,1));
assertEquals(A, A('callee'));
assertEquals(1, A('length'));
assertEquals(2, A('length',2));
assertEquals(5, A('length',2,3,4,5));
assertEquals({}.toString, A('toString'));
assertEquals({}.isPrototypeOf, A('isPrototypeOf'));
assertTrue(typeof A('xxx') == 'undefined');
assertEquals('undefined', typeof A('xxx'));
// Object access.
function O(key) {
return { toString: function() { return key; } };
}
assertEquals(0, A(O(0)));
assertEquals(0, A(O(0),1));
var O0 = O(0);
assertSame(O0, A(O0));
assertSame(O0, A(O0,1));
assertEquals(2, A(O(1),2));
assertEquals(2, A(O(1),2,3,4,5));
assertEquals(5, A(O(4),2,3,4,5));
assertTrue(typeof A(O(1)) == 'undefined');
assertTrue(typeof A(O(3),2,1) == 'undefined');
assertEquals(0, A(O('0')));
assertEquals(0, A(O('0'),1));
O0 = O('0');
assertSame(O0, A(O0));
assertSame(O0, A(O0,1));
assertEquals(2, A(O('1'),2));
assertEquals(2, A(O('1'),2,3,4,5));
assertEquals(5, A(O('4'),2,3,4,5));
......
......@@ -102,7 +102,7 @@ assertEquals('undefined', typeof a[Math.pow(2,32)-2], "top");
var a = new Array();
assertEquals(12, a.length = new Number(12));
assertEquals(Object(12), a.length = new Number(12));
assertEquals(12, a.length);
......
......@@ -46,8 +46,8 @@ assertFalse(AndBB(1, 0));
assertFalse(AndBB(0, 1));
assertFalse(AndBB(1, 1));
assertFalse(AndBN(0, 0));
assertTrue(AndBN(0, 1));
assertEquals(0, AndBN(0, 0));
assertEquals(1, AndBN(0, 1));
assertFalse(AndBN(1, 0));
assertEquals(1, AndBN(0, 1));
assertEquals(2, AndBN(0, 2));
......
......@@ -50,20 +50,20 @@ f();
var valueOfCount = 0;
function g() {
const o = { valueOf: function() { valueOfCount++; return 42; } }
assertEquals(42, o);
const o = { valueOf: function() { valueOfCount++; return 42; } };
assertEquals(42, +o);
assertEquals(1, valueOfCount);
o++;
assertEquals(42, o);
assertEquals(42, +o);
assertEquals(3, valueOfCount);
++o;
assertEquals(42, o);
assertEquals(42, +o);
assertEquals(5, valueOfCount);
o--;
assertEquals(42, o);
assertEquals(42, +o);
assertEquals(7, valueOfCount);
--o;
assertEquals(42, o);
assertEquals(42, +o);
assertEquals(9, valueOfCount);
}
......
......@@ -187,9 +187,9 @@ for (var add_non_ascii_character_to_subject = 0;
var ignore_case = (j == 0);
var flag = ignore_case ? "i" : "";
var re = new RegExp(mixed, flag);
assertEquals(ignore_case || (full && add_non_ascii_character_to_subject),
re.test("A" + suffix),
58 + flag + f);
var expected =
ignore_case || (full && !!add_non_ascii_character_to_subject);
assertEquals(expected, re.test("A" + suffix), 58 + flag + f);
assertTrue(re.test("a" + suffix), 59 + flag + f);
assertTrue(re.test("~" + suffix), 60 + flag + f);
assertTrue(re.test(cyrillic.MIDDLE), 61 + flag + f);
......
......@@ -31,9 +31,9 @@
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
Debug = debug.Debug;
var name;
var test_name;
var listener_delegate;
var listener_called;
var exception;
......@@ -48,7 +48,7 @@ function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.Break) {
break_count++;
listener_called = true;
listener_delegate(exec_state)
listener_delegate(exec_state);
}
} catch (e) {
exception = e;
......@@ -59,7 +59,7 @@ function listener(event, exec_state, event_data, data) {
Debug.setListener(listener);
// Initialize for a noew test.
// Initialize for a new test.
function BeginTest(name) {
test_name = name;
listener_delegate = null;
......@@ -72,7 +72,7 @@ function BeginTest(name) {
// Check result of a test.
function EndTest() {
assertTrue(listener_called, "listerner not called for " + test_name);
assertNull(exception, test_name)
assertNull(exception, test_name);
end_test_count++;
}
......@@ -87,7 +87,9 @@ function CheckScopeChain(scopes, exec_state) {
// Check the global object when hitting the global scope.
if (scopes[i] == debug.ScopeType.Global) {
assertEquals(this, scope.scopeObject().value());
// Objects don't have same class (one is "global", other is "Object",
// so just check the properties directly.
assertPropertiesEqual(this, scope.scopeObject().value());
}
}
......@@ -96,7 +98,7 @@ function CheckScopeChain(scopes, exec_state) {
// Send a scopes request and check the result.
var json;
request_json = '{"seq":0,"type":"request","command":"scopes"}'
var request_json = '{"seq":0,"type":"request","command":"scopes"}';
var response_json = dcp.processDebugJSONRequest(request_json);
var response = JSON.parse(response_json);
assertEquals(scopes.length, response.body.scopes.length);
......@@ -121,7 +123,7 @@ function CheckScopeChain(scopes, exec_state) {
// Check that the content of the scope is as expected. For functions just check
// that there is a function.
function CheckScopeContent(content, number, exec_state) {
var scope = exec_state.frame().scope(number)
var scope = exec_state.frame().scope(number);
var count = 0;
for (var p in content) {
var property_mirror = scope.scopeObject().property(p);
......@@ -163,9 +165,9 @@ function CheckScopeContent(content, number, exec_state) {
// Send a scope request for information on a single scope and check the
// result.
request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"number":'
var request_json = '{"seq":0,"type":"request","command":"scope","arguments":{"number":';
request_json += scope.scopeIndex();
request_json += '}}'
request_json += '}}';
var response_json = dcp.processDebugJSONRequest(request_json);
var response = JSON.parse(response_json);
assertEquals(scope.scopeType(), response.body.type);
......@@ -195,8 +197,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
}
local_1()
};
local_1();
EndTest();
......@@ -211,8 +213,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1}, 0, exec_state);
}
local_2(1)
};
local_2(1);
EndTest();
......@@ -228,8 +230,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,x:3}, 0, exec_state);
}
local_3(1)
};
local_3(1);
EndTest();
......@@ -246,8 +248,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4}, 0, exec_state);
}
local_4(1, 2)
};
local_4(1, 2);
EndTest();
......@@ -263,8 +265,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
}
local_5()
};
local_5();
EndTest();
......@@ -280,8 +282,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({i:5}, 0, exec_state);
}
local_6()
};
local_6();
EndTest();
......@@ -301,8 +303,8 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 0, exec_state);
}
local_7(1, 2)
};
local_7(1, 2);
EndTest();
......@@ -320,8 +322,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
}
with_1()
};
with_1();
EndTest();
......@@ -343,8 +345,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
CheckScopeContent({}, 1, exec_state);
}
with_2()
};
with_2();
EndTest();
......@@ -362,8 +364,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2}, 0, exec_state);
}
with_3()
};
with_3();
EndTest();
......@@ -385,8 +387,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:2,b:1}, 0, exec_state);
CheckScopeContent({a:1,b:2}, 1, exec_state);
}
with_4()
};
with_4();
EndTest();
......@@ -411,8 +413,8 @@ listener_delegate = function(exec_state) {
CheckScopeContent(with_object, 1, exec_state);
assertEquals(exec_state.frame().scope(0).scopeObject(), exec_state.frame().scope(1).scopeObject());
assertEquals(with_object, exec_state.frame().scope(1).scopeObject().value());
}
with_5()
};
with_5();
EndTest();
......@@ -433,8 +435,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1}, 1, exec_state);
}
closure_1(1)()
};
closure_1(1)();
EndTest();
......@@ -458,8 +460,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,x:3}, 1, exec_state);
}
closure_2(1, 2)()
};
closure_2(1, 2)();
EndTest();
......@@ -484,8 +486,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state);
}
closure_3(1, 2)()
};
closure_3(1, 2)();
EndTest();
......@@ -513,8 +515,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state);
}
closure_4(1, 2)()
};
closure_4(1, 2)();
EndTest();
......@@ -541,8 +543,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state);
}
closure_5(1, 2)()
};
closure_5(1, 2)();
EndTest();
......@@ -559,7 +561,7 @@ function closure_6(a, b) {
debugger;
some_global = a;
return f;
}
};
}
return f(a, b);
}
......@@ -571,8 +573,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1}, 1, exec_state);
CheckScopeContent({f:function(){}}, 2, exec_state);
}
closure_6(1, 2)()
};
closure_6(1, 2)();
EndTest();
......@@ -593,7 +595,7 @@ function closure_7(a, b) {
debugger;
some_global = a;
return f;
}
};
}
return f(a, b);
}
......@@ -606,8 +608,8 @@ listener_delegate = function(exec_state) {
CheckScopeContent({}, 0, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 1, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 2, exec_state);
}
closure_7(1, 2)()
};
closure_7(1, 2)();
EndTest();
......@@ -623,7 +625,7 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({x: 2}, 0, exec_state);
}
};
closure_8();
EndTest();
......@@ -633,7 +635,7 @@ function closure_9() {
eval("var y = 1;");
eval("var z = 1;");
(function inner(x) {
y++;
y++;
z++;
debugger;
})(2);
......@@ -643,7 +645,7 @@ listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Local,
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
}
};
closure_9();
EndTest();
......@@ -670,7 +672,7 @@ function the_full_monty(a, b) {
return f;
}
}
}
};
}
}
return f(a, b);
......@@ -690,8 +692,8 @@ listener_delegate = function(exec_state) {
CheckScopeContent({j:13}, 3, exec_state);
CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state);
}
the_full_monty(1, 2)()
};
the_full_monty(1, 2)();
EndTest();
......@@ -710,7 +712,7 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Closure,
debug.ScopeType.Global], exec_state);
CheckScopeContent({x: 2}, 0, exec_state);
}
};
closure_in_with_1();
EndTest();
......@@ -735,7 +737,7 @@ listener_delegate = function(exec_state) {
CheckScopeContent({x: 3}, 0, exec_state);
CheckScopeContent({x: 2}, 1, exec_state);
CheckScopeContent({x: 1}, 2, exec_state);
}
};
closure_in_with_2();
EndTest();
......@@ -750,7 +752,7 @@ function createClosure(a) {
debugger;
}
})(2);
}
};
}
function closure_in_with_3() {
......@@ -773,7 +775,7 @@ EndTest();
BeginTest("Global");
listener_delegate = function(exec_state) {
CheckScopeChain([debug.ScopeType.Global], exec_state);
}
};
debugger;
EndTest();
......@@ -793,8 +795,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Local,
debug.ScopeType.Global], exec_state);
CheckScopeContent({e:'Exception'}, 0, exec_state);
}
catch_block_1()
};
catch_block_1();
EndTest();
......@@ -817,8 +819,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Global], exec_state);
CheckScopeContent({n:10}, 0, exec_state);
CheckScopeContent({e:'Exception'}, 1, exec_state);
}
catch_block_2()
};
catch_block_2();
EndTest();
......@@ -841,8 +843,8 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Global], exec_state);
CheckScopeContent({e:'Exception'}, 0, exec_state);
CheckScopeContent({y:78}, 1, exec_state);
}
catch_block_3()
};
catch_block_3();
EndTest();
......@@ -868,10 +870,12 @@ listener_delegate = function(exec_state) {
CheckScopeContent({n:10}, 0, exec_state);
CheckScopeContent({e:'Exception'}, 1, exec_state);
CheckScopeContent({y:98}, 2, exec_state);
}
catch_block_4()
};
catch_block_4();
EndTest();
assertEquals(begin_test_count, break_count, 'one or more tests did not enter the debugger');
assertEquals(begin_test_count, end_test_count, 'one or more tests did not have its result checked');
assertEquals(begin_test_count, break_count,
'one or more tests did not enter the debugger');
assertEquals(begin_test_count, end_test_count,
'one or more tests did not have its result checked');
......@@ -35,13 +35,13 @@ function zero() {
function test() {
assertEquals(0, Math.abs(0));
assertEquals(0, Math.abs(zero()));
assertEquals(1/0, 1/Math.abs(-0)); // 0 == -0, so we use reciprocals.
assertEquals(0, Math.abs(-0));
assertEquals(Infinity, Math.abs(Infinity));
assertEquals(Infinity, Math.abs(-Infinity));
assertNaN(Math.abs(NaN));
assertNaN(Math.abs(-NaN));
assertEquals('Infinity', Math.abs(Number('+Infinity').toString()));
assertEquals('Infinity', Math.abs(Number('-Infinity').toString()));
assertEquals(NaN, Math.abs(NaN));
assertEquals(NaN, Math.abs(-NaN));
assertEquals('Infinity', Math.abs(Number('+Infinity')).toString());
assertEquals('Infinity', Math.abs(Number('-Infinity')).toString());
assertEquals('NaN', Math.abs(NaN).toString());
assertEquals('NaN', Math.abs(-NaN).toString());
......@@ -85,8 +85,8 @@ function test() {
assertEquals(two_31 - 1, Math.abs(two_31 - 1));
assertEquals(two_31 - 1, Math.abs(-two_31 + 1));
assertNaN(Math.abs("not a number"));
assertNaN(Math.abs([1, 2, 3]));
assertEquals(NaN, Math.abs("not a number"));
assertEquals(NaN, Math.abs([1, 2, 3]));
assertEquals(42, Math.abs({valueOf: function() { return 42; } }));
assertEquals(42, Math.abs({valueOf: function() { return -42; } }));
}
......
......@@ -76,9 +76,9 @@ assertEquals(-1, Math.min(+0, -0, -1));
assertEquals(-1, Math.min(-1, +0, -0));
assertEquals(-1, Math.min(+0, -1, -0));
assertEquals(-1, Math.min(-0, -1, +0));
assertNaN(Math.min('oxen'));
assertNaN(Math.min('oxen', 1));
assertNaN(Math.min(1, 'oxen'));
assertEquals(NaN, Math.min('oxen'));
assertEquals(NaN, Math.min('oxen', 1));
assertEquals(NaN, Math.min(1, 'oxen'));
// Test Math.max().
......@@ -109,9 +109,9 @@ assertEquals(1, Math.max(+0, -0, +1));
assertEquals(1, Math.max(+1, +0, -0));
assertEquals(1, Math.max(+0, +1, -0));
assertEquals(1, Math.max(-0, +1, +0));
assertNaN(Math.max('oxen'));
assertNaN(Math.max('oxen', 1));
assertNaN(Math.max(1, 'oxen'));
assertEquals(NaN, Math.max('oxen'));
assertEquals(NaN, Math.max('oxen', 1));
assertEquals(NaN, Math.max(1, 'oxen'));
assertEquals(Infinity, 1/Math.max(ZERO, -0));
assertEquals(Infinity, 1/Math.max(-0, ZERO));
......@@ -50,10 +50,10 @@ function testNumberMirror(n) {
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('number', fromJSON.type);
if (!isNaN(n)) {
if (isFinite(n)) {
assertEquals(n, fromJSON.value);
} else {
// NaN values are encoded as strings.
// NaN and Infinity values are encoded as strings.
assertTrue(typeof fromJSON.value == 'string');
if (n === Infinity) {
assertEquals('Infinity', fromJSON.value);
......
......@@ -38,7 +38,7 @@ function MirrorRefCache(json_refs) {
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
};
function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
// Create mirror and JSON representation.
......@@ -66,7 +66,7 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected');
var names = mirror.propertyNames();
var properties = mirror.properties()
var properties = mirror.properties();
assertEquals(names.length, properties.length);
for (var i = 0; i < properties.length; i++) {
assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
......@@ -130,15 +130,20 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes');
}
// Lookup the serialized object from the handle reference.
// Lookup the serialized object from the handle reference.
var o = refs.lookup(fromJSON.properties[i].ref);
assertTrue(o != void 0, 'Referenced object is not serialized');
assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name);
if (properties[i].value().isPrimitive()) {
// Special check for NaN as NaN == NaN is false.
if (properties[i].value().isNumber() && isNaN(properties[i].value().value())) {
assertEquals('NaN', o.value, 'Unexpected serialized property value for ' + name);
if (properties[i].value().type() == "null" ||
properties[i].value().type() == "undefined") {
// Null and undefined has no value property.
assertFalse("value" in o, 'Unexpected value property for ' + name);
} else if (properties[i].value().type() == "number" &&
!isFinite(properties[i].value().value())) {
assertEquals(String(properties[i].value().value()), o.value,
'Unexpected serialized property value for ' + name);
} else {
assertEquals(properties[i].value().value(), o.value, 'Unexpected serialized property value for ' + name);
}
......
......@@ -43,236 +43,313 @@ MjsUnitAssertionError.prototype.toString = function () {
};
function classOf(object) {
var string = Object.prototype.toString.call(object);
// String has format [object <ClassName>].
return string.substring(8, string.length - 1);
}
// Expected and found values the same objects, or the same primitive
// values.
// For known primitive values, please use assertEquals.
var assertSame;
// Expected and found values are identical primitive values or functions
// or similarly structured objects (checking internal properties
// of, e.g., Number and Date objects, the elements of arrays
// and the properties of non-Array objects).
var assertEquals;
// The found object is an Array with the same length and elements
// as the expected object. The expected object doesn't need to be an Array,
// as long as it's "array-ish".
var assertArrayEquals;
// The found object must have the same enumerable properties as the
// expected object. The type of object isn't checked.
var assertPropertiesEqual;
// Assert that the string conversion of the found value is equal to
// the expected string. Only kept for backwards compatability, please
// check the real structure of the found value.
var assertToStringEquals;
// Checks that the found value is true. Use with boolean expressions
// for tests that doesn't have their own assertXXX function.
var assertTrue;
// Checks that the found value is false.
var assertFalse;
// Checks that the found value is null. Kept for historical compatability,
// please just use assertEquals(null, expected).
var assertNull;
// Checks that the found value is *not* null.
var assertNotNull;
// Assert that the passed function or eval code throws an exception.
// The optional second argument is an exception constructor that the
// thrown exception is checked against with "instanceof".
// The optional third argument is a message type string that is compared
// to the type property on the thrown exception.
var assertThrows;
// Assert that the passed function or eval code does not throw an exception.
var assertDoesNotThrow;
// Asserts that the found value is an instance of the constructor passed
// as the second argument.
var assertInstanceof;
// Assert that this code is never executed (i.e., always fails if executed).
var assertUnreachable;
(function () { // Scope for utility functions.
function classOf(object) {
// Argument must not be null or undefined.
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":
return JSON.stringify(value);
case "number":
if (value === 0 && (1 / value) < 0) return "-0";
// FALLTHROUGH.
case "boolean":
case "undefined":
case "function":
return String(value);
case "object":
if (value === null) return "null";
var objectClass = classOf(value);
switch (objectClass) {
function PrettyPrint(value) {
switch (typeof value) {
case "string":
return JSON.stringify(value);
case "number":
if (value === 0 && (1 / value) < 0) return "-0";
// FALLTHROUGH.
case "boolean":
case "undefined":
case "function":
return String(value);
case "object":
if (value === null) return "null";
var objectClass = classOf(value);
switch (objectClass) {
case "Number":
case "String":
case "Boolean":
case "Date":
return objectClass + "(" + MjsUnitToString(value.valueOf()) + ")";
return objectClass + "(" + PrettyPrint(value.valueOf()) + ")";
case "RegExp":
return value.toString();
case "Array":
return "[" + value.map(MjsUnitArrayElementToString).join(",") + "]";
return "[" + value.map(PrettyPrintArrayElement).join(",") + "]";
case "Object":
break;
default:
return objectClass + "()";
}
// [[Class]] is "Object".
var constructor = value.constructor.name;
if (name) return name + "()";
return "Object()";
default:
return "-- unknown value --";
}
// [[Class]] is "Object".
var name = value.constructor.name;
if (name) return name + "()";
return "Object()";
default:
return "-- unknown value --";
}
}
}
function MjsUnitArrayElementToString(value, index, array) {
if (value === undefined && !(index in array)) return "";
return MjsUnitToString(value);
}
function fail(expected, found, name_opt) {
var message = "Fail" + "ure";
if (name_opt) {
// Fix this when we ditch the old test runner.
message += " (" + name_opt + ")";
function PrettyPrintArrayElement(value, index, array) {
if (value === undefined && !(index in array)) return "";
return PrettyPrint(value);
}
message += ": expected <" + MjsUnitToString(expected) +
"> found <" + MjsUnitToString(found) + ">";
throw new MjsUnitAssertionError(message);
}
function fail(expectedText, found, name_opt) {
var message = "Fail" + "ure";
if (name_opt) {
// Fix this when we ditch the old test runner.
message += " (" + name_opt + ")";
}
function deepObjectEquals(a, b) {
var aProps = [];
for (var key in a) {
aProps.push(key);
}
var bProps = [];
for (key in b) {
bProps.push(key);
message += ": expected <" + expectedText +
"> found <" + PrettyPrint(found) + ">";
throw new MjsUnitAssertionError(message);
}
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) {
// Check for -0.
if (a === 0 && b === 0) return (1 / a) === (1 / b);
return true;
}
if (typeof a == "number" && typeof b == "number" && isNaN(a) && isNaN(b)) {
return true;
}
if (a == null || b == null) return false;
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 (aClass === "Array") {
if (bClass !== "Array")
return false;
if (a.length != b.length)
function deepObjectEquals(a, b) {
var aProps = Object.keys(a);
aProps.sort();
var bProps = Object.keys(b);
bProps.sort();
if (!deepEquals(aProps, bProps)) {
return false;
for (var i = 0; i < a.length; i++) {
if (i in a) {
if (!(i in b) || !(deepEquals(a[i], b[i])))
return false;
} else if (i in b) {
}
for (var i = 0; i < aProps.length; i++) {
if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
return false;
}
}
return true;
} else if (bClass == "Array") {
return false;
} else {
return deepObjectEquals(a, b);
}
}
function assertSame(expected, found, name_opt) {
if (found !== expected) {
fail(expected, found, name_opt);
function deepEquals(a, b) {
if (a === b) {
// Check for -0.
if (a === 0) return (1 / a) === (1 / b);
return true;
}
if (typeof a != typeof b) return false;
if (typeof a == "number") return isNaN(a) && isNaN(b);
if (typeof a !== "object" && typeof a !== "function") return false;
// Neither a nor b is primitive.
var objectClass = classOf(a);
if (objectClass !== classOf(b)) return false;
if (objectClass === "RegExp") {
// For RegExp, just compare pattern and flags using its toString.
return (a.toString() === b.toString());
}
// Functions are only identical to themselves.
if (objectClass === "Function") return false;
if (objectClass === "Array") {
var elementCount = 0;
if (a.length != b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!deepEquals(a[i], b[i])) return false;
}
return true;
}
if (objectClass == "String" || objectClass == "Number" ||
objectClass == "Boolean" || objectClass == "Date") {
if (a.valueOf() !== b.valueOf()) return false;
}
return deepObjectEquals(a, b);
}
}
function assertEquals(expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(expected, found, name_opt);
}
}
assertSame = function assertSame(expected, found, name_opt) {
if (found === expected) {
if (expected !== 0 || (1 / expected) == (1 / found)) return;
} else if (isNaN(expected) && isNaN(found)) {
return;
}
fail(PrettyPrint(expected), found, name_opt);
};
function assertArrayEquals(expected, found, name_opt) {
var start = "";
if (name_opt) {
start = name_opt + " - ";
}
assertEquals(expected.length, found.length, start + "array length");
if (expected.length == found.length) {
for (var i = 0; i < expected.length; ++i) {
assertEquals(expected[i], found[i], start + "array element at index " + i);
assertEquals = function assertEquals(expected, found, name_opt) {
if (!deepEquals(found, expected)) {
fail(PrettyPrint(expected), found, name_opt);
}
}
}
};
function assertTrue(value, name_opt) {
assertEquals(true, value, name_opt);
}
assertArrayEquals = function assertArrayEquals(expected, found, name_opt) {
var start = "";
if (name_opt) {
start = name_opt + " - ";
}
assertEquals(expected.length, found.length, start + "array length");
if (expected.length == found.length) {
for (var i = 0; i < expected.length; ++i) {
assertEquals(expected[i], found[i],
start + "array element at index " + i);
}
}
};
function assertFalse(value, name_opt) {
assertEquals(false, value, name_opt);
}
assertPropertiesEqual = function assertPropertiesEqual(expected, found,
name_opt) {
// Check properties only.
if (!deepObjectEquals(expected, found)) {
fail(expected, found, name_opt);
}
};
function assertNaN(value, name_opt) {
if (!isNaN(value)) {
fail("NaN", value, name_opt);
}
}
assertToStringEquals = function assertToStringEquals(expected, found,
name_opt) {
if (expected != String(found)) {
fail(expected, found, name_opt);
}
};
function assertNull(value, name_opt) {
if (value !== null) {
fail("null", value, name_opt);
}
}
assertTrue = function assertTrue(value, name_opt) {
assertEquals(true, value, name_opt);
};
function assertNotNull(value, name_opt) {
if (value === null) {
fail("not null", value, name_opt);
}
}
assertFalse = function assertFalse(value, name_opt) {
assertEquals(false, value, name_opt);
};
function assertThrows(code, type_opt, cause_opt) {
var threwException = true;
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
assertNull = function assertNull(value, name_opt) {
if (value !== null) {
fail("null", value, name_opt);
}
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");
}
};
function assertInstanceof(obj, type) {
if (!(obj instanceof type)) {
assertTrue(false, "Object <" + obj + "> is not an instance of <" + type + ">");
}
}
assertNotNull = function assertNotNull(value, name_opt) {
if (value === null) {
fail("not null", value, name_opt);
}
};
function assertDoesNotThrow(code) {
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
assertThrows = function assertThrows(code, type_opt, cause_opt) {
var threwException = true;
try {
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);
}
// Success.
return;
}
} catch (e) {
assertTrue(false, "threw an exception: " + (e.message || e));
}
}
throw new MjsUnitAssertionError("Did not throw exception");
};
function assertUnreachable(name_opt) {
// Fix this when we ditch the old test runner.
var message = "Fail" + "ure: unreachable";
if (name_opt) {
message += " - " + name_opt;
}
throw new MjsUnitAssertionError(message);
}
assertInstanceof = function assertInstanceof(obj, type) {
if (!(obj instanceof type)) {
var actualTypeName = null;
var actualConstructor = Object.prototypeOf(obj).constructor;
if (typeof actualConstructor == "function") {
actualTypeName = actualConstructor.name || String(actualConstructor);
}
fail("Object <" + PrettyPrint(obj) + "> is not an instance of <" +
(type.name || type) + ">" +
(actualTypeName ? " but of < " + actualTypeName + ">" : ""));
}
};
assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) {
try {
if (typeof code == 'function') {
code();
} else {
eval(code);
}
} catch (e) {
fail("threw an exception: ", e.message || e, name_opt);
}
};
assertUnreachable = function assertUnreachable(name_opt) {
// Fix this when we ditch the old test runner.
var message = "Fail" + "ure: unreachable";
if (name_opt) {
message += " - " + name_opt;
}
throw new MjsUnitAssertionError(message);
};
})();
......@@ -26,7 +26,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --call_regexp
var callbacks = [ function() {return 'foo'}, "nonobject", /abc/ ];
var callbacks = [ function() { return 'foo'; }, "nonobject", /abc/ ];
assertEquals('foo', callbacks['0']());
assertThrows("callbacks['1']()");
assertEquals('abc', callbacks['2']("abcdefg"));
assertEquals(['abc'], callbacks['2']("abcdefg"));
......@@ -55,7 +55,7 @@ assertEquals("-90", (-90).toString());
assertEquals("-90.12", (-90.12).toString());
assertEquals("-0.1", (-0.1).toString());
assertEquals("-0.01", (-0.01).toString());
assertEquals("-0.0123", (-0.0123).toString())
assertEquals("-0.0123", (-0.0123).toString());
assertEquals("-111111111111111110000", (-111111111111111111111).toString());
assertEquals("-1.1111111111111111e+21", (-1111111111111111111111).toString());
assertEquals("-1.1111111111111111e+22", (-11111111111111111111111).toString());
......@@ -219,7 +219,7 @@ assertEquals("0.12312312312312299889", (0.123123123123123).toFixed(20));
// Test that we round up even when the last digit generated is even.
// dtoa does not do this in its original form.
assertEquals("1", 0.5.toFixed(0), "0.5.toFixed(0)");
assertEquals("-1", -0.5.toFixed(0), "-0.5.toFixed(0)");
assertEquals("-1", (-0.5).toFixed(0), "(-0.5).toFixed(0)");
assertEquals("1.3", 1.25.toFixed(1), "1.25.toFixed(1)");
// This is bizare, but Spidermonkey and KJS behave the same.
assertEquals("234.2040", (234.20405).toFixed(4), "234.2040.toFixed(4)");
......
......@@ -91,7 +91,7 @@ assertEquals("foobar", desc.value);
// Since writable is not affected by seal we should still be able to
// update the values.
obj.x = "43";
assertEquals(43, obj.x);
assertEquals("43", obj.x);
// Test on accessors.
var obj2 = {};
......@@ -142,7 +142,7 @@ assertFalse(Object.isSealed(arr));
Object.seal(arr);
assertTrue(Object.isSealed(arr));
assertFalse(Object.isExtensible(arr));
// Since the values in the array is still writable this object
// Since the values in the array is still writable this object
// is not frozen.
assertFalse(Object.isFrozen(arr));
......@@ -186,5 +186,5 @@ Object.preventExtensions(obj4);
assertFalse(Object.isSealed(obj4));
// Make sure that Object.seal returns the sealed object.
var obj4 = {}
assertTrue(obj4 === Object.seal(obj4))
var obj4 = {};
assertTrue(obj4 === Object.seal(obj4));
......@@ -30,7 +30,7 @@
function test() {
eval = /foo/;
assertEquals("foo", eval("foobar"));
assertEquals(["foo"], eval("foobar"));
}
test();
......@@ -39,19 +39,20 @@ assertEquals(0, "y".search(/(x)?\1y/));
assertEquals("z", "y".replace(/(x)?\1y/, "z"));
assertEquals("", "y".replace(/(x)?y/, "$1"));
assertEquals("undefined", "y".replace(/(x)?\1y/,
function($0, $1){
return String($1);
function($0, $1){
return String($1);
}));
assertEquals("undefined", "y".replace(/(x)?y/,
function($0, $1){
return String($1);
assertEquals("undefined", "y".replace(/(x)?y/,
function($0, $1){
return String($1);
}));
assertEquals("undefined", "y".replace(/(x)?y/,
function($0, $1){
return $1;
assertEquals("undefined", "y".replace(/(x)?y/,
function($0, $1){
return $1;
}));
// See https://bugzilla.mozilla.org/show_bug.cgi?id=476146
assertEquals("bbc,b", /^(b+|a){1,2}?bc/.exec("bbc"));
assertEquals("bbaa,a,,a", /((\3|b)\2(a)){2,}/.exec("bbaababbabaaaaabbaaaabba"));
assertEquals(["bbc", "b"], /^(b+|a){1,2}?bc/.exec("bbc"));
assertEquals(["bbaa", "a", "", "a"],
/((\3|b)\2(a)){2,}/.exec("bbaababbabaaaaabbaaaabba"));
......@@ -27,16 +27,16 @@
// Test that we don't cache the result of a regexp match across a
// compile event.
var re = /x/;
var re = /x/;
assertEquals("a.yb", "axyb".replace(re, "."));
re.compile("y")
re.compile("y");
assertEquals("ax.b", "axyb".replace(re, "."));
re.compile("(x)");
assertEquals("x,x", re.exec("axyb"));
assertEquals(["x", "x"], re.exec("axyb"));
re.compile("(y)");
assertEquals("y,y", re.exec("axyb"));
assertEquals(["y", "y"], re.exec("axyb"));
......@@ -134,7 +134,8 @@ function f() { return RegExp.$1; };
assertEquals('abcd', 'abcd'.replace(re, f));
// lastParen where the last parenthesis didn't match.
assertEquals("foo,", /foo(?:a(x))?/.exec("foobx"), "lastParen setup");
assertEquals(["foo",undefined], /foo(?:a(x))?/.exec("foobx"),
"lastParen setup");
assertEquals("", RegExp.lastParen, "lastParen");
// The same test for $1 to $9.
......
......@@ -28,18 +28,18 @@
// Regexp shouldn't use String.prototype.slice()
var s = new String("foo");
assertEquals("f", s.slice(0,1));
String.prototype.slice = function() { return "x"; }
String.prototype.slice = function() { return "x"; };
assertEquals("x", s.slice(0,1));
assertEquals("g", /g/.exec("gg"));
assertEquals(["g"], /g/.exec("gg"));
// Regexp shouldn't use String.prototype.charAt()
var f1 = new RegExp("f", "i");
assertEquals("F", f1.exec("F"));
assertEquals(["F"], f1.exec("F"));
assertEquals("f", "foo".charAt(0));
String.prototype.charAt = function(idx) { return 'g'; };
assertEquals("g", "foo".charAt(0));
var f2 = new RegExp("[g]", "i");
assertEquals("G", f2.exec("G"));
assertEquals(["G"], f2.exec("G"));
assertTrue(f2.ignoreCase);
// On the other hand test is defined in a semi-coherent way as a call to exec.
......@@ -47,5 +47,5 @@ assertTrue(f2.ignoreCase);
// We match other browsers in using the original value of RegExp.prototype.exec.
// I.e., RegExp.prototype.test shouldn't use the current value of
// RegExp.prototype.exec.
RegExp.prototype.exec = function(string) { return 'x'; }
RegExp.prototype.exec = function(string) { return 'x'; };
assertFalse(/f/.test('x'));
......@@ -333,9 +333,9 @@ assertFalse(/f(o)$\1/.test('foo'), "backref detects at_end");
// Check decimal escapes doesn't overflow.
// (Note: \214 is interpreted as octal).
assertEquals(/\2147483648/.exec("\x8c7483648"),
["\x8c7483648"],
"Overflow decimal escape");
assertArrayEquals(["\x8c7483648"],
/\2147483648/.exec("\x8c7483648"),
"Overflow decimal escape");
// Check numbers in quantifiers doesn't overflow and doesn't throw on
......@@ -435,8 +435,8 @@ assertEquals(0, re.lastIndex);
re.lastIndex = 42;
re.someOtherProperty = 42;
re.someDeletableProperty = 42;
re[37] = 37;
re[42] = 42;
re[37] = 37;
re[42] = 42;
re.compile("ra+", "i");
assertEquals("ra+", re.source);
......@@ -466,7 +466,7 @@ assertEquals(37, re.someOtherProperty);
assertEquals(37, re[42]);
// Test boundary-checks.
function assertRegExpTest(re, input, test) {
function assertRegExpTest(re, input, test) {
assertEquals(test, re.test(input), "test:" + re + ":" + input);
}
......@@ -525,7 +525,7 @@ for (var i = 0; i < 100; i++) {
assertEquals(1, res.index);
assertEquals("axyzb", res.input);
assertEquals(undefined, res.foobar);
res.foobar = "Arglebargle";
res[3] = "Glopglyf";
assertEquals("Arglebargle", res.foobar);
......@@ -534,18 +534,18 @@ for (var i = 0; i < 100; i++) {
// Test that we perform the spec required conversions in the correct order.
var log;
var string = "the string";
var fakeLastIndex = {
valueOf: function() {
var fakeLastIndex = {
valueOf: function() {
log.push("li");
return 0;
}
}
};
var fakeString = {
var fakeString = {
toString: function() {
log.push("ts");
return string;
},
length: 0
},
length: 0
};
var re = /str/;
......
......@@ -34,43 +34,43 @@ const NONE = 0;
const READ_ONLY = 1;
// Use DeclareGlobal...
%SetProperty(this.__proto__, "a", "1234", NONE);
%SetProperty(this.__proto__, "a", 1234, NONE);
assertEquals(1234, a);
eval("var a = 5678;");
assertEquals(5678, a);
%SetProperty(this.__proto__, "b", "1234", NONE);
%SetProperty(this.__proto__, "b", 1234, NONE);
assertEquals(1234, b);
eval("const b = 5678;");
assertEquals(5678, b);
%SetProperty(this.__proto__, "c", "1234", READ_ONLY);
%SetProperty(this.__proto__, "c", 1234, READ_ONLY);
assertEquals(1234, c);
eval("var c = 5678;");
assertEquals(5678, c);
%SetProperty(this.__proto__, "d", "1234", READ_ONLY);
%SetProperty(this.__proto__, "d", 1234, READ_ONLY);
assertEquals(1234, d);
eval("const d = 5678;");
assertEquals(5678, d);
// Use DeclareContextSlot...
%SetProperty(this.__proto__, "x", "1234", NONE);
%SetProperty(this.__proto__, "x", 1234, NONE);
assertEquals(1234, x);
eval("with({}) { var x = 5678; }");
assertEquals(5678, x);
%SetProperty(this.__proto__, "y", "1234", NONE);
%SetProperty(this.__proto__, "y", 1234, NONE);
assertEquals(1234, y);
eval("with({}) { const y = 5678; }");
assertEquals(5678, y);
%SetProperty(this.__proto__, "z", "1234", READ_ONLY);
%SetProperty(this.__proto__, "z", 1234, READ_ONLY);
assertEquals(1234, z);
eval("with({}) { var z = 5678; }");
assertEquals(5678, z);
%SetProperty(this.__proto__, "w", "1234", READ_ONLY);
%SetProperty(this.__proto__, "w", 1234, READ_ONLY);
assertEquals(1234, w);
eval("with({}) { const w = 5678; }");
assertEquals(5678, w);
......
......@@ -27,24 +27,24 @@
// See http://code.google.com/p/v8/issues/detail?id=176
assertEquals("f,",
"foo".match(/(?:(?=(f)o))?f/).toString(),
"zero length match in (?:) with capture in lookahead");
assertEquals("f,",
"foo".match(/(?=(f)o)?f/).toString(),
"zero length match in (?=) with capture in lookahead");
assertEquals("fo,f",
"foo".match(/(?:(?=(f)o)f)?o/),
"non-zero length match with capture in lookahead");
assertEquals("fo,f",
"foo".match(/(?:(?=(f)o)f?)?o/),
"non-zero length match with greedy ? in (?:)");
assertEquals("fo,f",
"foo".match(/(?:(?=(f)o)f??)?o/),
"non-zero length match with non-greedy ? in (?:), o forces backtrack");
assertEquals("fo,f",
"foo".match(/(?:(?=(f)o)f??)?./),
"non-zero length match with non-greedy ? in (?:), zero length match causes backtrack");
assertEquals("f,",
"foo".match(/(?:(?=(f)o)fx)?./),
"x causes backtrack inside (?:)");
assertArrayEquals(["f", undefined],
"foo".match(/(?:(?=(f)o))?f/),
"zero length match in (?:) with capture in lookahead");
assertArrayEquals(["f", undefined],
"foo".match(/(?=(f)o)?f/),
"zero length match in (?=) with capture in lookahead");
assertArrayEquals(["fo", "f"],
"foo".match(/(?:(?=(f)o)f)?o/),
"non-zero length match with capture in lookahead");
assertArrayEquals(["fo", "f"],
"foo".match(/(?:(?=(f)o)f?)?o/),
"non-zero length match with greedy ? in (?:)");
assertArrayEquals(["fo", "f"],
"foo".match(/(?:(?=(f)o)f??)?o/),
"non-zero length match with non-greedy ? in (?:), o forces backtrack");
assertArrayEquals(["fo", "f"],
"foo".match(/(?:(?=(f)o)f??)?./),
"non-zero length match with non-greedy ? in (?:), zero length match causes backtrack");
assertArrayEquals(["f", undefined],
"foo".match(/(?:(?=(f)o)fx)?./),
"x causes backtrack inside (?:)");
......@@ -27,4 +27,4 @@
// See http://code.google.com/p/v8/issues/detail?id=187
assertEquals("f,", "foo".match(/(?:(?=(f)o)fx|)./));
assertEquals(["f", undefined], "foo".match(/(?:(?=(f)o)fx|)./));
......@@ -28,5 +28,5 @@
// See http://code.google.com/p/v8/issues/detail?id=399
var date = new Date(1.009804e12);
var year = String(date).match(/.*(200\d)/)[1];
var year = Number(String(date).match(/.*(200\d)/)[1]);
assertEquals(year, date.getFullYear());
......@@ -65,8 +65,10 @@ function test(num) {
assertEquals(" ", fcc(0x20 + 0.5, 0x20));
var receiver = (num < 5) ? String : (num < 9) ? "dummy" : 42;
fcc2 = (num < 5) ? fcc : (num < 9) ? constFun("dummy") : constFun(42);
var expected = (num < 5) ? " " : (num < 9) ? "dummy" : 42;
fcc2 = (num < 5) ? fcc
: (num < 9) ? constFun(Object("dummy"))
: constFun(Object(42));
var expected = (num < 5) ? " " : (num < 9) ? Object("dummy") : Object(42);
assertEquals(expected, receiver.fromCharCode(0x20));
assertEquals(expected, receiver.fromCharCode(0x20 - 0x10000));
assertEquals(expected, receiver.fromCharCode(0x20 + 0.5));
......
......@@ -61,7 +61,7 @@ assertEquals("undefined", typeof(foo[3]), "out of range");
assertEquals("undefined", typeof(foo[-2]), "negative index");
var S = new String("foo");
assertEquals("foo", S);
assertEquals(Object("foo"), S);
assertEquals("f", S[0], "string object");
assertEquals("f", S["0"], "string object");
S[0] = 'bente';
......@@ -131,7 +131,7 @@ assertEquals(false, 3 in S);
assertEquals(false, "3" in S);
var N = new Number(43);
assertEquals(43, N);
assertEquals(Object(43), N);
N[-2] = "Alpha";
assertEquals("Alpha", N[-2]);
N[0] = "Zappa";
......
......@@ -54,7 +54,7 @@ assertEquals(Object.keys(function () {}), []);
assertEquals('string', typeof(Object.keys([1])[0]));
function argsTest(a, b, c) {
assertEquals([0, 1, 2], Object.keys(arguments));
assertEquals(['0', '1', '2'], Object.keys(arguments));
}
argsTest(1, 2, 3);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -157,6 +157,7 @@ function assertNoEntry(codeMap, addr) {
codeMap.addStaticCode(0x15500, newCodeEntry(0x5000, 'lib2'));
codeMap.addStaticCode(0x155500, newCodeEntry(0x10000, 'lib3'));
var allStatics = codeMap.getAllStaticEntries();
allStatics = allStatics.map(String);
allStatics.sort();
assertEquals(['lib1: 3000', 'lib2: 5000', 'lib3: 10000'], allStatics);
})();
......@@ -168,13 +169,15 @@ function assertNoEntry(codeMap, addr) {
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3'));
var allDynamics = codeMap.getAllDynamicEntries();
allDynamics = allDynamics.map(String);
allDynamics.sort();
assertEquals(['code1: 200', 'code2: 100', 'code3: 50'], allDynamics);
codeMap.deleteCode(0x1700);
var allDynamics2 = codeMap.getAllDynamicEntries();
allDynamics2 = allDynamics2.map(String);
allDynamics2.sort();
assertEquals(['code1: 200', 'code3: 50'], allDynamics2);
codeMap.deleteCode(0x1500);
var allDynamics3 = codeMap.getAllDynamicEntries();
assertEquals(['code3: 50'], allDynamics3);
assertEquals(['code3: 50'], allDynamics3.map(String));
})();
......@@ -81,13 +81,13 @@ function createSampleTree() {
(function testSplay() {
var tree = new SplayTree();
tree.root_ = createSampleTree();
assertArrayEquals(['50', '30', '60', '10', '40', '90', '20', '70', '100', '15', '80'],
assertArrayEquals([50, 30, 60, 10, 40, 90, 20, 70, 100, 15, 80],
tree.exportValues());
tree.splay_(50);
assertArrayEquals(['50', '30', '60', '10', '40', '90', '20', '70', '100', '15', '80'],
assertArrayEquals([50, 30, 60, 10, 40, 90, 20, 70, 100, 15, 80],
tree.exportValues());
tree.splay_(80);
assertArrayEquals(['80', '60', '90', '50', '70', '100', '30', '10', '40', '20', '15'],
assertArrayEquals([80, 60, 90, 50, 70, 100, 30, 10, 40, 20, 15],
tree.exportValues());
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment