| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // This file contains a number of tests of array functions and their | 28 // This file contains a number of tests of array functions and their |
| 29 // interaction with properties in the prototype chain. | 29 // interaction with properties in the prototype chain. |
| 30 // | 30 // |
| 31 // The behavior of SpiderMonkey is slightly different for arrays (see | 31 // The behavior of SpiderMonkey is slightly different for arrays (see |
| 32 // below). Our behavior is consistent and matches the bahavior of | 32 // below). Our behavior is consistent and matches the bahavior of |
| 33 // KJS. | 33 // KJS. |
| 34 | 34 |
| 35 var proto = { length:3, 0:'zero', 1:'one', 2:'two' } | 35 var proto = { length:3, 0:'zero', 1:'one', 2:'two' }; |
| 36 function constructor() {}; | 36 function constructor() {} |
| 37 constructor.prototype = proto; | 37 constructor.prototype = proto; |
| 38 | 38 |
| 39 // Set elements on the array prototype. | 39 // Set elements on the array prototype. |
| 40 Array.prototype[0] = 'zero'; | 40 Array.prototype[0] = 'zero'; |
| 41 Array.prototype[1] = 'one'; | 41 Array.prototype[1] = 'one'; |
| 42 Array.prototype[2] = 'two'; | 42 Array.prototype[2] = 'two'; |
| 43 | 43 |
| 44 // ---------------------------------------------------------------------- | 44 // ---------------------------------------------------------------------- |
| 45 // Helper functions. | 45 // Helper functions. |
| 46 // ---------------------------------------------------------------------- | 46 // ---------------------------------------------------------------------- |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 assertEquals('zero', array[0]); | 101 assertEquals('zero', array[0]); |
| 102 assertEquals('zero', nonArray[0]); | 102 assertEquals('zero', nonArray[0]); |
| 103 assertEquals('zero', array[1]); | 103 assertEquals('zero', array[1]); |
| 104 assertEquals('zero', nonArray[1]); | 104 assertEquals('zero', nonArray[1]); |
| 105 // Again Spidermonkey is inconsistent. array[2] is undefined | 105 // Again Spidermonkey is inconsistent. array[2] is undefined |
| 106 // instead of 'one'. | 106 // instead of 'one'. |
| 107 assertEquals('one', array[2]); | 107 assertEquals('one', array[2]); |
| 108 assertEquals('one', nonArray[2]); | 108 assertEquals('one', nonArray[2]); |
| 109 assertEquals('two', array[3]); | 109 assertEquals('two', array[3]); |
| 110 assertEquals('two', nonArray[3]); | 110 assertEquals('two', nonArray[3]); |
| 111 } | 111 }; |
| 112 | 112 |
| 113 runTest2(); | 113 runTest2(); |
| 114 | 114 |
| 115 | 115 |
| 116 // ---------------------------------------------------------------------- | 116 // ---------------------------------------------------------------------- |
| 117 // splice | 117 // splice |
| 118 // ---------------------------------------------------------------------- | 118 // ---------------------------------------------------------------------- |
| 119 | 119 |
| 120 runTest3 = function() { | 120 runTest3 = function() { |
| 121 var nonArray = new constructor(); | 121 var nonArray = new constructor(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 150 runTest4 = function() { | 150 runTest4 = function() { |
| 151 var nonArray = new constructor(); | 151 var nonArray = new constructor(); |
| 152 var array = ['zero', , 'two']; | 152 var array = ['zero', , 'two']; |
| 153 // Again Spidermonkey is inconsistent. (array.slice(0, 3))[1] is | 153 // Again Spidermonkey is inconsistent. (array.slice(0, 3))[1] is |
| 154 // undefined instead of 'one'. | 154 // undefined instead of 'one'. |
| 155 assertArrayEquals(['zero', 'one', 'two'], array.slice(0, 3)); | 155 assertArrayEquals(['zero', 'one', 'two'], array.slice(0, 3)); |
| 156 assertArrayEquals(['zero', 'one', 'two'], Array.prototype.slice.call(nonArray,
0, 3)); | 156 assertArrayEquals(['zero', 'one', 'two'], Array.prototype.slice.call(nonArray,
0, 3)); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 runTest4(); | 159 runTest4(); |
| OLD | NEW |