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);
......
This diff is collapsed.
......@@ -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);
}
......
This diff is collapsed.
......@@ -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 diff is collapsed.
......@@ -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