| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 for (var i = 0; i < limit; i++) { | 48 for (var i = 0; i < limit; i++) { |
| 49 assertTrue(object.hasOwnProperty(i)); | 49 assertTrue(object.hasOwnProperty(i)); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 // ---------------------------------------------------------------------- | 54 // ---------------------------------------------------------------------- |
| 55 // shift. | 55 // shift. |
| 56 // ---------------------------------------------------------------------- | 56 // ---------------------------------------------------------------------- |
| 57 | 57 |
| 58 function runTest() { | 58 function runTest1() { |
| 59 var nonArray = new constructor(); | 59 var nonArray = new constructor(); |
| 60 var array = ['zero', , 'two']; | 60 var array = ['zero', , 'two']; |
| 61 // Shift away the zero. | 61 // Shift away the zero. |
| 62 assertEquals('zero', array.shift()); | 62 assertEquals('zero', array.shift()); |
| 63 assertEquals('zero', Array.prototype.shift.call(nonArray)); | 63 assertEquals('zero', Array.prototype.shift.call(nonArray)); |
| 64 // Check that the local object has properties 0 and 1 with the right | 64 // Check that the local object has properties 0 and 1 with the right |
| 65 // values. | 65 // values. |
| 66 assertEquals(2, array.length); | 66 assertEquals(2, array.length); |
| 67 assertEquals(2, nonArray.length); | 67 assertEquals(2, nonArray.length); |
| 68 assertHasOwnProperties(array, 2); | 68 assertHasOwnProperties(array, 2); |
| 69 assertHasOwnProperties(nonArray, 2); | 69 assertHasOwnProperties(nonArray, 2); |
| 70 // Note: Spidermonkey is inconsistent here. It treats arrays | 70 // Note: Spidermonkey is inconsistent here. It treats arrays |
| 71 // differently from non-arrays. It only consults the prototype for | 71 // differently from non-arrays. It only consults the prototype for |
| 72 // non-arrays. Therefore, array[0] is undefined in Spidermonkey and | 72 // non-arrays. Therefore, array[0] is undefined in Spidermonkey and |
| 73 // 'one' in V8 and KJS. | 73 // 'one' in V8 and KJS. |
| 74 assertEquals('one', array[0]); | 74 assertEquals('one', array[0]); |
| 75 assertEquals('one', nonArray[0]); | 75 assertEquals('one', nonArray[0]); |
| 76 assertEquals('two', array[1]); | 76 assertEquals('two', array[1]); |
| 77 assertEquals('two', nonArray[1]); | 77 assertEquals('two', nonArray[1]); |
| 78 // Get index 2 from the prototype. | 78 // Get index 2 from the prototype. |
| 79 assertEquals('two', array[2]); | 79 assertEquals('two', array[2]); |
| 80 assertEquals('two', nonArray[2]); | 80 assertEquals('two', nonArray[2]); |
| 81 } | 81 } |
| 82 | 82 |
| 83 runTest(); | 83 runTest1(); |
| 84 | 84 |
| 85 // ---------------------------------------------------------------------- | 85 // ---------------------------------------------------------------------- |
| 86 // unshift. | 86 // unshift. |
| 87 // ---------------------------------------------------------------------- | 87 // ---------------------------------------------------------------------- |
| 88 | 88 |
| 89 runTest = function() { | 89 runTest2 = function() { |
| 90 var nonArray = new constructor(); | 90 var nonArray = new constructor(); |
| 91 var array = ['zero', , 'two']; | 91 var array = ['zero', , 'two']; |
| 92 // Unshift a new 'zero'. | 92 // Unshift a new 'zero'. |
| 93 assertEquals(4, array.unshift('zero')); | 93 assertEquals(4, array.unshift('zero')); |
| 94 assertEquals(4, Array.prototype.unshift.call(nonArray, 'zero')); | 94 assertEquals(4, Array.prototype.unshift.call(nonArray, 'zero')); |
| 95 // Check that the local object has properties 0 through 3 with the | 95 // Check that the local object has properties 0 through 3 with the |
| 96 // right values. | 96 // right values. |
| 97 assertEquals(4, array.length); | 97 assertEquals(4, array.length); |
| 98 assertEquals(4, nonArray.length); | 98 assertEquals(4, nonArray.length); |
| 99 assertHasOwnProperties(array, 4); | 99 assertHasOwnProperties(array, 4); |
| 100 assertHasOwnProperties(nonArray, 4); | 100 assertHasOwnProperties(nonArray, 4); |
| 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 runTest(); | 113 runTest2(); |
| 114 | 114 |
| 115 | 115 |
| 116 // ---------------------------------------------------------------------- | 116 // ---------------------------------------------------------------------- |
| 117 // splice | 117 // splice |
| 118 // ---------------------------------------------------------------------- | 118 // ---------------------------------------------------------------------- |
| 119 | 119 |
| 120 runTest = function() { | 120 runTest3 = function() { |
| 121 var nonArray = new constructor(); | 121 var nonArray = new constructor(); |
| 122 var array = ['zero', , 'two']; | 122 var array = ['zero', , 'two']; |
| 123 // Delete the first element by splicing in nothing. | 123 // Delete the first element by splicing in nothing. |
| 124 assertArrayEquals(['zero'], array.splice(0, 1)); | 124 assertArrayEquals(['zero'], array.splice(0, 1)); |
| 125 assertArrayEquals(['zero'], Array.prototype.splice.call(nonArray, 0, 1)); | 125 assertArrayEquals(['zero'], Array.prototype.splice.call(nonArray, 0, 1)); |
| 126 // Check that the local object has properties 0 and 1 with the right | 126 // Check that the local object has properties 0 and 1 with the right |
| 127 // values. | 127 // values. |
| 128 assertEquals(2, array.length); | 128 assertEquals(2, array.length); |
| 129 assertEquals(2, nonArray.length); | 129 assertEquals(2, nonArray.length); |
| 130 assertHasOwnProperties(array, 2); | 130 assertHasOwnProperties(array, 2); |
| 131 assertHasOwnProperties(nonArray, 2); | 131 assertHasOwnProperties(nonArray, 2); |
| 132 // Again Spidermonkey is inconsistent. array[0] is undefined | 132 // Again Spidermonkey is inconsistent. array[0] is undefined |
| 133 // instead of 'one'. | 133 // instead of 'one'. |
| 134 assertEquals('one', array[0]); | 134 assertEquals('one', array[0]); |
| 135 assertEquals('one', nonArray[0]); | 135 assertEquals('one', nonArray[0]); |
| 136 assertEquals('two', array[1]); | 136 assertEquals('two', array[1]); |
| 137 assertEquals('two', nonArray[1]); | 137 assertEquals('two', nonArray[1]); |
| 138 // Get index 2 from the prototype. | 138 // Get index 2 from the prototype. |
| 139 assertEquals('two', array[2]); | 139 assertEquals('two', array[2]); |
| 140 assertEquals('two', nonArray[2]); | 140 assertEquals('two', nonArray[2]); |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 runTest(); | 143 runTest3(); |
| 144 | 144 |
| 145 | 145 |
| 146 // ---------------------------------------------------------------------- | 146 // ---------------------------------------------------------------------- |
| 147 // slice | 147 // slice |
| 148 // ---------------------------------------------------------------------- | 148 // ---------------------------------------------------------------------- |
| 149 | 149 |
| 150 runTest = 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 runTest(); | 159 runTest4(); |
| OLD | NEW |