Commit 939011bb authored by ager@chromium.org's avatar ager@chromium.org

Add a number of old tests to the mjsunit test suite.

R=kasperl@chromium.org
BUG=
TEST=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8298 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b84d0776
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(function() {
function f(x) {
var arguments = [ 1, 2, 3 ];
return x;
}
assertEquals(7, f(7));
})();
(function() {
function f(x) {
arguments[0] = 991;
var arguments = [ 1, 2, 3 ];
return x;
}
assertEquals(991, f(7));
})();
(function() {
function f(x) {
arguments[0] = 991;
for (var i = 0; i < 10; i++) {
if (i == 5) {
var arguments = [ 1, 2, 3 ];
}
}
return x;
}
assertEquals(991, f(7));
})();
(function() {
function f(x, s) {
eval(s);
return x;
}
assertEquals(7, f(7, "var arguments = [ 1, 2, 3 ];"));
})();
(function() {
function f(x, s) {
var tmp = arguments[0];
eval(s);
return tmp;
}
assertEquals(7, f(7, "var arguments = [ 1, 2, 3 ];"));
})();
(function() {
function f(x, s) {
var tmp = arguments[0];
eval(s);
return tmp;
}
assertEquals(7, f(7, ""));
})();
(function() {
function f(x, s) {
var tmp = arguments[0];
eval(s);
return x;
}
assertEquals(7, f(7, "var arguments = [ 1, 2, 3 ];"));
})();
(function() {
function f(x, s) {
var tmp = arguments[0];
eval(s);
return x;
}
assertEquals(7, f(7, ""));
})();
(function() {
function f(x) {
function g(y) {
x = y;
}
arguments = {};
g(991);
return x;
}
assertEquals(991, f(7));
})();
(function() {
function f(x) {
function g(y, s) {
eval(s);
}
arguments = {};
g(991, "x = y;");
return x;
}
assertEquals(991, f(7));
})();
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests to verify proper arguments handling if the arguments
// variable is declared as a parameter or local variable.
function e(a) {
assertEquals(9, a.length);
assertEquals("arguments", a);
};
e("arguments");
function f(arguments) {
assertEquals(9, arguments.length);
assertEquals("arguments", arguments);
};
f("arguments");
function g(x) {
var arguments;
assertEquals("arguments", x);
assertEquals(1, arguments.length);
assertEquals("[object Arguments]", '' + arguments);
};
g("arguments");
function h(x) {
assertEquals("arguments", x);
assertEquals(1, arguments.length);
assertEquals("[object Arguments]", '' + arguments);
var arguments = "foobar";
assertEquals("arguments", x);
assertEquals(6, arguments.length);
assertEquals("foobar", '' + arguments);
};
h("arguments");
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function foo(x) {
var a = arguments;
function bar(i) {
assertEquals(i, ++a[0]);
assertEquals(i, x);
};
bar(1);
bar(2);
bar(3);
return bar;
}
var baz = foo(0);
baz(4);
baz(5);
baz(6);
// Copyright 2008 the V8 project authors. All rights reserved. // Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
...@@ -50,8 +50,6 @@ assertEquals(1, argc2(1)); ...@@ -50,8 +50,6 @@ assertEquals(1, argc2(1));
assertEquals(2, argc2(1, 2)); assertEquals(2, argc2(1, 2));
assertEquals(3, argc2(1, 2, 3)); assertEquals(3, argc2(1, 2, 3));
var index; var index;
function argv0() { function argv0() {
...@@ -95,3 +93,90 @@ assertEquals(9, argv2(7, 8, 9)); ...@@ -95,3 +93,90 @@ assertEquals(9, argv2(7, 8, 9));
// an unexpected number of arguments works. // an unexpected number of arguments works.
function f(a) { return arguments.length; }; function f(a) { return arguments.length; };
assertEquals(3, f(1, 2, 3)); assertEquals(3, f(1, 2, 3));
function f1(x, y) {
function g(a) {
a[0] = "three";
return a.length;
}
var l = g(arguments);
y = 5;
assertEquals(2, l);
assertEquals("three", x);
assertEquals(5, y);
}
f1(3, "five");
function f2() {
if (arguments[0] > 0) {
return arguments.callee(arguments[0] - 1) + arguments[0];
}
return 0;
}
assertEquals(55, f2(10));
function f3() {
assertEquals(0, arguments.length);
}
f3();
function f4() {
var arguments = 0;
assertEquals(void 0, arguments.length);
}
f4();
function f5(x, y, z) {
function g(a) {
x = "two";
y = "three";
a[1] = "drei";
a[2] = "fuenf";
};
g(arguments);
assertEquals("two", x);
assertEquals("drei", y);
assertEquals("fuenf", z);
}
f5(2, 3, 5);
function f6(x, y) {
x = "x";
arguments[1] = "y";
return [arguments.length, arguments[0], y, arguments[2]];
}
assertArrayEquals([0, "x", "y", void 0], f6());
assertArrayEquals([1, "x", "y", void 0], f6(1));
assertArrayEquals([2, "x", "y", void 0], f6(9, 17));
assertArrayEquals([3, "x", "y", 7], f6(3, 5, 7));
assertArrayEquals([4, "x", "y", "c"], f6("a", "b", "c", "d"));
function list_args(a) {
assertEquals("function", typeof a.callee);
var result = [];
result.push(a.length);
for (i = 0; i < a.length; i++) result.push(a[i]);
return result;
}
function f1(x, y) {
function g(p) {
x = p;
}
g(y);
return list_args(arguments);
}
assertArrayEquals([0], f1());
assertArrayEquals([1, void 0], f1(3));
assertArrayEquals([2, 5, 5], f1(3, 5));
assertArrayEquals([3, 5, 5, 7], f1(3, 5, 7));
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
assertEquals(Boolean(void 0), false);
assertEquals(Boolean(null), false);
assertEquals(Boolean(false), false);
assertEquals(Boolean(true), true);
assertEquals(Boolean(0), false);
assertEquals(Boolean(1), true);
assertEquals(Boolean(assertEquals), true);
assertEquals(Boolean(new Object()), true);
assertTrue(new Boolean(false) !== false);
assertTrue(new Boolean(false) == false);
assertTrue(new Boolean(true) !== true);
assertTrue(new Boolean(true) == true);
assertEquals(true, !false);
assertEquals(false, !true);
assertEquals(true, !!true);
assertEquals(false, !!false);
assertEquals(true, true ? true : false);
assertEquals(false, false ? true : false);
assertEquals(false, true ? false : true);
assertEquals(true, false ? false : true);
assertEquals(true, true && true);
assertEquals(false, true && false);
assertEquals(false, false && true);
assertEquals(false, false && false);
// Regression.
var t = 42;
assertEquals(void 0, t.p);
assertEquals(void 0, t.p && true);
assertEquals(void 0, t.p && false);
assertEquals(void 0, t.p && (t.p == 0));
assertEquals(void 0, t.p && (t.p == null));
assertEquals(void 0, t.p && (t.p == t.p));
var o = new Object();
o.p = 'foo';
assertEquals('foo', o.p);
assertEquals('foo', o.p || true);
assertEquals('foo', o.p || false);
assertEquals('foo', o.p || (o.p == 0));
assertEquals('foo', o.p || (o.p == null));
assertEquals('foo', o.p || (o.p == o.p));
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function f() {
var i = 10;
var c = 0;
while (i-- > 0) {
c++;
if (i == 5) ;
}
assertEquals(10, c);
}
f();
function f2() {
var i = 10;
var c = 0;
while (i-- > 0) {
c++;
if (i == 5) break;
}
assertEquals(5, c);
}
f2();
function f3() {
var i = 10;
var c = 0;
outer: while (i-- > 0) {
var j = 10;
inner1: inner2: inner3: while (j-- > 0) {
c++;
if (i == 8)
break inner2;
if (i == 6)
break outer;
}
}
assertEquals(22, c);
}
f3();
outer2: {
break outer2;
assertUnreachable();
}
outer3: break outer3; // nop
l1: l2: l3: break l2; // nop
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var k = 0x1000000000000081;
assertEquals(1152921504606847200, k);
k = 0x1000000000000281;
assertEquals(1152921504606847700, k);
k = 0x10000000000002810;
assertEquals(18446744073709564000, k);
k = 0x10000000000002810000;
assertEquals(7.555786372591437e+22, k);
k = 0xffffffffffffffff;
assertEquals(18446744073709552000, k);
k = 0xffffffffffffffffffff;
assertEquals(1.2089258196146292e+24, k);
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var undef = void 0;
assertEquals(1, 1 || 0);
assertEquals(2, 0 || 2);
assertEquals('foo', 0 || 'foo');
assertEquals(undef, undef || undef);
assertEquals('foo', 'foo' || 'bar');
assertEquals('bar', undef || 'bar');
assertEquals('bar', undef || 'bar' || 'baz');
assertEquals('baz', undef || undef || 'baz');
assertEquals(0, 1 && 0);
assertEquals(0, 0 && 2);
assertEquals(0, 0 && 'foo');
assertEquals(undef, undef && undef);
assertEquals('bar', 'foo' && 'bar');
assertEquals(undef, undef && 'bar');
assertEquals('baz', 'foo' && 'bar' && 'baz');
assertEquals(undef, 'foo' && undef && 'baz');
assertEquals(0, undef && undef || 0);
assertEquals('bar', undef && 0 || 'bar');
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var s = 'foo\
bar';
assertEquals("foobar", s);
This diff is collapsed.
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