diff options
author | Steve Block <steveblock@google.com> | 2010-09-22 15:07:15 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-09-29 18:15:43 +0100 |
commit | 59151504615d929945dc59db37bf1166937748c6 (patch) | |
tree | 2199adfe73b4618f685bae891d2d54f2cd997f77 /test | |
parent | 9ac36c9faca11611ada13b4054edbaa0738661d0 (diff) | |
download | v8-59151504615d929945dc59db37bf1166937748c6.tar.gz |
Update V8 to r5447 as required by WebKit r67908
Change-Id: I5af6ccf18523cb7e28460e6bbc044444256cdb97
Diffstat (limited to 'test')
-rw-r--r-- | test/mjsunit/array-indexing.js | 154 | ||||
-rw-r--r-- | test/mjsunit/regress/regress-857.js | 37 | ||||
-rw-r--r-- | test/mjsunit/string-fromcharcode.js | 89 |
3 files changed, 263 insertions, 17 deletions
diff --git a/test/mjsunit/array-indexing.js b/test/mjsunit/array-indexing.js index 2322c545..72767422 100644 --- a/test/mjsunit/array-indexing.js +++ b/test/mjsunit/array-indexing.js @@ -26,41 +26,161 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var array = [1,2,3,1,2,3,1,2,3,1,2,3]; +var undef_array = [0,,2,undefined,4,,6,undefined,8,,10]; +// Sparse arrays with length 42000. +var sparse_array = []; +sparse_array[100] = 3; +sparse_array[200] = undefined; +sparse_array[300] = 4; +sparse_array[400] = 5; +sparse_array[500] = 6; +sparse_array[600] = 5; +sparse_array[700] = 4; +sparse_array[800] = undefined; +sparse_array[900] = 3 +sparse_array[41999] = "filler"; + +var dense_object = { 0: 42, 1: 37, length: 2 }; +var sparse_object = { 0: 42, 100000: 37, length: 200000 }; +var funky_object = { 10:42, 100000: 42, 100001: 37, length: 50000 }; +var infinite_object = { 10: 42, 100000: 37, length: Infinity }; // ---------------------------------------------------------------------- // Array.prototype.indexOf. // ---------------------------------------------------------------------- // Negative cases. -assertEquals([].indexOf(1), -1); -assertEquals(array.indexOf(4), -1); -assertEquals(array.indexOf(3, array.length), -1); +assertEquals(-1, [].indexOf(1)); +assertEquals(-1, array.indexOf(4)); +assertEquals(-1, array.indexOf(3, array.length)); -assertEquals(array.indexOf(3), 2); +assertEquals(2, array.indexOf(3)); // Negative index out of range. -assertEquals(array.indexOf(1, -17), 0); +assertEquals(0, array.indexOf(1, -17)); // Negative index in rage. -assertEquals(array.indexOf(1, -11), 3); +assertEquals(3, array.indexOf(1, -11)); // Index in range. -assertEquals(array.indexOf(1, 1), 3); -assertEquals(array.indexOf(1, 3), 3); -assertEquals(array.indexOf(1, 4), 6); +assertEquals(3, array.indexOf(1, 1)); +assertEquals(3, array.indexOf(1, 3)); +assertEquals(6, array.indexOf(1, 4)); + +// Find undefined, not holes. +assertEquals(3, undef_array.indexOf(undefined)); +assertEquals(3, undef_array.indexOf(undefined, 3)); +assertEquals(7, undef_array.indexOf(undefined, 4)); +assertEquals(7, undef_array.indexOf(undefined, 7)); +assertEquals(-1, undef_array.indexOf(undefined, 8)); +assertEquals(3, undef_array.indexOf(undefined, -11)); +assertEquals(3, undef_array.indexOf(undefined, -8)); +assertEquals(7, undef_array.indexOf(undefined, -7)); +assertEquals(7, undef_array.indexOf(undefined, -4)); +assertEquals(-1, undef_array.indexOf(undefined, -3)); + +// Find in sparse array. +assertEquals(100, sparse_array.indexOf(3)); +assertEquals(900, sparse_array.indexOf(3, 101)); +assertEquals(-1, sparse_array.indexOf(3, 901)); +assertEquals(100, sparse_array.indexOf(3, -42000)); +assertEquals(900, sparse_array.indexOf(3, 101 - 42000)); +assertEquals(-1, sparse_array.indexOf(3, 901 - 42000)); + +assertEquals(300, sparse_array.indexOf(4)); +assertEquals(700, sparse_array.indexOf(4, 301)); +assertEquals(-1, sparse_array.indexOf(4, 701)); +assertEquals(300, sparse_array.indexOf(4, -42000)); +assertEquals(700, sparse_array.indexOf(4, 301 - 42000)); +assertEquals(-1, sparse_array.indexOf(4, 701 - 42000)); + +assertEquals(200, sparse_array.indexOf(undefined)); +assertEquals(800, sparse_array.indexOf(undefined, 201)); +assertEquals(-1, sparse_array.indexOf(undefined, 801)); +assertEquals(200, sparse_array.indexOf(undefined, -42000)); +assertEquals(800, sparse_array.indexOf(undefined, 201 - 42000)); +assertEquals(-1, sparse_array.indexOf(undefined, 801 - 42000)); + +// Find in non-arrays. +assertEquals(0, Array.prototype.indexOf.call(dense_object, 42)); +assertEquals(1, Array.prototype.indexOf.call(dense_object, 37)); +assertEquals(-1, Array.prototype.indexOf.call(dense_object, 87)); + +assertEquals(0, Array.prototype.indexOf.call(sparse_object, 42)); +assertEquals(100000, Array.prototype.indexOf.call(sparse_object, 37)); +assertEquals(-1, Array.prototype.indexOf.call(sparse_object, 87)); + +assertEquals(10, Array.prototype.indexOf.call(funky_object, 42)); +assertEquals(-1, Array.prototype.indexOf.call(funky_object, 42, 15)); +assertEquals(-1, Array.prototype.indexOf.call(funky_object, 37)); + +assertEquals(-1, Array.prototype.indexOf.call(infinite_object, 42)); // ---------------------------------------------------------------------- // Array.prototype.lastIndexOf. // ---------------------------------------------------------------------- // Negative cases. -assertEquals([].lastIndexOf(1), -1); -assertEquals(array.lastIndexOf(1, -17), -1); +assertEquals(-1, [].lastIndexOf(1)); +assertEquals(-1, array.lastIndexOf(1, -17)); -assertEquals(array.lastIndexOf(1), 9); +assertEquals(9, array.lastIndexOf(1)); // Index out of range. -assertEquals(array.lastIndexOf(1, array.length), 9); +assertEquals(9, array.lastIndexOf(1, array.length)); // Index in range. -assertEquals(array.lastIndexOf(1, 2), 0); -assertEquals(array.lastIndexOf(1, 4), 3); -assertEquals(array.lastIndexOf(1, 3), 3); +assertEquals(0, array.lastIndexOf(1, 2)); +assertEquals(3, array.lastIndexOf(1, 4)); +assertEquals(3, array.lastIndexOf(1, 3)); // Negative index in range. -assertEquals(array.lastIndexOf(1, -11), 0); +assertEquals(0, array.lastIndexOf(1, -11)); + +// Find undefined, not holes. +assertEquals(7, undef_array.lastIndexOf(undefined)); +assertEquals(-1, undef_array.lastIndexOf(undefined, 2)); +assertEquals(3, undef_array.lastIndexOf(undefined, 3)); +assertEquals(3, undef_array.lastIndexOf(undefined, 6)); +assertEquals(7, undef_array.lastIndexOf(undefined, 7)); +assertEquals(7, undef_array.lastIndexOf(undefined, -1)); +assertEquals(-1, undef_array.lastIndexOf(undefined, -9)); +assertEquals(3, undef_array.lastIndexOf(undefined, -8)); +assertEquals(3, undef_array.lastIndexOf(undefined, -5)); +assertEquals(7, undef_array.lastIndexOf(undefined, -4)); + +// Find in sparse array. +assertEquals(900, sparse_array.lastIndexOf(3)); +assertEquals(100, sparse_array.lastIndexOf(3, 899)); +assertEquals(-1, sparse_array.lastIndexOf(3, 99)); +assertEquals(900, sparse_array.lastIndexOf(3, -1)); +assertEquals(100, sparse_array.lastIndexOf(3, 899 - 42000)); +assertEquals(-1, sparse_array.lastIndexOf(3, 99 - 42000)); + +assertEquals(700, sparse_array.lastIndexOf(4)); +assertEquals(300, sparse_array.lastIndexOf(4, 699)); +assertEquals(-1, sparse_array.lastIndexOf(4, 299)); +assertEquals(700, sparse_array.lastIndexOf(4, -1)); +assertEquals(300, sparse_array.lastIndexOf(4, 699 - 42000)); +assertEquals(-1, sparse_array.lastIndexOf(4, 299 - 42000)); + +assertEquals(800, sparse_array.lastIndexOf(undefined)); +assertEquals(200, sparse_array.lastIndexOf(undefined, 799)); +assertEquals(-1, sparse_array.lastIndexOf(undefined, 199)); +assertEquals(800, sparse_array.lastIndexOf(undefined, -1)); +assertEquals(200, sparse_array.lastIndexOf(undefined, 799 - 42000)); +assertEquals(-1, sparse_array.lastIndexOf(undefined, 199 - 42000)); + +assertEquals(0, Array.prototype.lastIndexOf.call(dense_object, 42)); +assertEquals(1, Array.prototype.lastIndexOf.call(dense_object, 37)); +assertEquals(0, Array.prototype.lastIndexOf.call(sparse_object, 42)); +assertEquals(100000, Array.prototype.lastIndexOf.call(sparse_object, 37)); + +//Find in non-arrays. +assertEquals(0, Array.prototype.lastIndexOf.call(dense_object, 42)); +assertEquals(1, Array.prototype.lastIndexOf.call(dense_object, 37)); +assertEquals(-1, Array.prototype.lastIndexOf.call(dense_object, 87)); + +assertEquals(0, Array.prototype.lastIndexOf.call(sparse_object, 42)); +assertEquals(100000, Array.prototype.lastIndexOf.call(sparse_object, 37)); +assertEquals(-1, Array.prototype.lastIndexOf.call(sparse_object, 87)); + +assertEquals(10, Array.prototype.lastIndexOf.call(funky_object, 42, 15)); +assertEquals(10, Array.prototype.lastIndexOf.call(funky_object, 42)); +assertEquals(-1, Array.prototype.lastIndexOf.call(funky_object, 37)); +assertEquals(-1, Array.prototype.lastIndexOf.call(infinite_object, 42)); diff --git a/test/mjsunit/regress/regress-857.js b/test/mjsunit/regress/regress-857.js new file mode 100644 index 00000000..183248d4 --- /dev/null +++ b/test/mjsunit/regress/regress-857.js @@ -0,0 +1,37 @@ +// Copyright 2010 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. + +// Make sure ES5 15.9.1.15 (ISO 8601 / RFC 3339) time zone offsets of +// the form "+09:00" & "-09:00" get parsed as expected +assertEquals(1283326536000, Date.parse("2010-08-31T22:35:36-09:00")); +assertEquals(1283261736000, Date.parse("2010-08-31T22:35:36+09:00")); +assertEquals(1283326536000, Date.parse("2010-08-31T22:35:36.0-09:00")); +assertEquals(1283261736000, Date.parse("2010-08-31T22:35:36.0+09:00")); +// colon-less time expressions in time zone offsets are not conformant +// with ES5 15.9.1.15 but are nonetheless supported in V8 +assertEquals(1283326536000, Date.parse("2010-08-31T22:35:36-0900")); +assertEquals(1283261736000, Date.parse("2010-08-31T22:35:36+0900")); diff --git a/test/mjsunit/string-fromcharcode.js b/test/mjsunit/string-fromcharcode.js new file mode 100644 index 00000000..7a2db5f9 --- /dev/null +++ b/test/mjsunit/string-fromcharcode.js @@ -0,0 +1,89 @@ +// Copyright 2010 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. + +// Test String.fromCharCode. + + +// Test various receivers and arguments passed to String.fromCharCode. + +Object.prototype.fromCharCode = function(x) { return this; }; + +var fcc = String.fromCharCode; +var fcc2 = fcc; + +function constFun(x) { return function(y) { return x; }; } + +function test(num) { + assertEquals(" ", String.fromCharCode(0x20)); + assertEquals(" ", String.fromCharCode(0x20 + 0x10000)); + assertEquals(" ", String.fromCharCode(0x20 - 0x10000)); + assertEquals(" ", String.fromCharCode(0x20 + 0.5)); + + assertEquals("\u1234", String.fromCharCode(0x1234)); + assertEquals("\u1234", String.fromCharCode(0x1234 + 0x10000)); + assertEquals("\u1234", String.fromCharCode(0x1234 - 0x10000)); + assertEquals("\u1234", String.fromCharCode(0x1234 + 0.5)); + + assertEquals(" ", String.fromCharCode(0x20, 0x20)); + assertEquals(" ", String.fromCharCode(0x20 + 0.5, 0x20)); + + assertEquals(" ", fcc(0x20)); + assertEquals(" ", fcc(0x20 + 0x10000)); + assertEquals(" ", fcc(0x20 - 0x10000)); + assertEquals(" ", fcc(0x20 + 0.5)); + + assertEquals("\u1234", fcc(0x1234)); + assertEquals("\u1234", fcc(0x1234 + 0x10000)); + assertEquals("\u1234", fcc(0x1234 - 0x10000)); + assertEquals("\u1234", fcc(0x1234 + 0.5)); + + assertEquals(" ", fcc(0x20, 0x20)); + 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; + assertEquals(expected, receiver.fromCharCode(0x20)); + assertEquals(expected, receiver.fromCharCode(0x20 - 0x10000)); + assertEquals(expected, receiver.fromCharCode(0x20 + 0.5)); + assertEquals(expected, fcc2(0x20)); + assertEquals(expected, fcc2(0x20 - 0x10000)); + assertEquals(expected, fcc2(0x20 + 0.5)); +} + +// Use loop to test the custom IC. +for (var i = 0; i < 10; i++) { + test(i); +} + + +// Test the custom IC works correctly when the map changes. +for (var i = 0; i < 10; i++) { + var expected = (i < 5) ? " " : 42; + if (i == 5) String.fromCharCode = function() { return 42; }; + assertEquals(expected, String.fromCharCode(0x20)); +} |