| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 // Pull out the length so that modifications to the length in the | 1120 // Pull out the length so that modifications to the length in the |
| 1121 // loop will not affect the looping and side effects are visible. | 1121 // loop will not affect the looping and side effects are visible. |
| 1122 var array = ToObject(this); | 1122 var array = ToObject(this); |
| 1123 var length = ToUint32(array.length); | 1123 var length = ToUint32(array.length); |
| 1124 | 1124 |
| 1125 if (!IS_SPEC_FUNCTION(f)) { | 1125 if (!IS_SPEC_FUNCTION(f)) { |
| 1126 throw MakeTypeError('called_non_callable', [ f ]); | 1126 throw MakeTypeError('called_non_callable', [ f ]); |
| 1127 } | 1127 } |
| 1128 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1128 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1129 receiver = %GetDefaultReceiver(f) || receiver; | 1129 receiver = %GetDefaultReceiver(f) || receiver; |
| 1130 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | |
| 1131 receiver = ToObject(receiver); | |
| 1132 } | 1130 } |
| 1131 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1133 | 1132 |
| 1134 var result = new $Array(); | 1133 var result = new $Array(); |
| 1135 var accumulator = new InternalArray(); | 1134 var accumulator = new InternalArray(); |
| 1136 var accumulator_length = 0; | 1135 var accumulator_length = 0; |
| 1137 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1136 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1138 for (var i = 0; i < length; i++) { | 1137 for (var i = 0; i < length; i++) { |
| 1139 if (i in array) { | 1138 if (i in array) { |
| 1140 var element = array[i]; | 1139 var element = array[i]; |
| 1141 // Prepare break slots for debugger step in. | 1140 // Prepare break slots for debugger step in. |
| 1142 if (stepping) %DebugPrepareStepInIfStepping(f); | 1141 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1143 if (%_CallFunction(receiver, element, i, array, f)) { | 1142 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1143 if (%_CallFunction(new_receiver, element, i, array, f)) { |
| 1144 accumulator[accumulator_length++] = element; | 1144 accumulator[accumulator_length++] = element; |
| 1145 } | 1145 } |
| 1146 } | 1146 } |
| 1147 } | 1147 } |
| 1148 %MoveArrayContents(accumulator, result); | 1148 %MoveArrayContents(accumulator, result); |
| 1149 return result; | 1149 return result; |
| 1150 } | 1150 } |
| 1151 | 1151 |
| 1152 | 1152 |
| 1153 function ArrayForEach(f, receiver) { | 1153 function ArrayForEach(f, receiver) { |
| 1154 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | 1154 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
| 1155 | 1155 |
| 1156 // Pull out the length so that modifications to the length in the | 1156 // Pull out the length so that modifications to the length in the |
| 1157 // loop will not affect the looping and side effects are visible. | 1157 // loop will not affect the looping and side effects are visible. |
| 1158 var array = ToObject(this); | 1158 var array = ToObject(this); |
| 1159 var length = TO_UINT32(array.length); | 1159 var length = TO_UINT32(array.length); |
| 1160 | 1160 |
| 1161 if (!IS_SPEC_FUNCTION(f)) { | 1161 if (!IS_SPEC_FUNCTION(f)) { |
| 1162 throw MakeTypeError('called_non_callable', [ f ]); | 1162 throw MakeTypeError('called_non_callable', [ f ]); |
| 1163 } | 1163 } |
| 1164 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1164 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1165 receiver = %GetDefaultReceiver(f) || receiver; | 1165 receiver = %GetDefaultReceiver(f) || receiver; |
| 1166 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | |
| 1167 receiver = ToObject(receiver); | |
| 1168 } | 1166 } |
| 1167 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1169 | 1168 |
| 1170 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1169 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1171 for (var i = 0; i < length; i++) { | 1170 for (var i = 0; i < length; i++) { |
| 1172 if (i in array) { | 1171 if (i in array) { |
| 1173 var element = array[i]; | 1172 var element = array[i]; |
| 1174 // Prepare break slots for debugger step in. | 1173 // Prepare break slots for debugger step in. |
| 1175 if (stepping) %DebugPrepareStepInIfStepping(f); | 1174 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1176 %_CallFunction(receiver, element, i, array, f); | 1175 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1176 %_CallFunction(new_receiver, element, i, array, f); |
| 1177 } | 1177 } |
| 1178 } | 1178 } |
| 1179 } | 1179 } |
| 1180 | 1180 |
| 1181 | 1181 |
| 1182 // Executes the function once for each element present in the | 1182 // Executes the function once for each element present in the |
| 1183 // array until it finds one where callback returns true. | 1183 // array until it finds one where callback returns true. |
| 1184 function ArraySome(f, receiver) { | 1184 function ArraySome(f, receiver) { |
| 1185 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1185 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); |
| 1186 | 1186 |
| 1187 // Pull out the length so that modifications to the length in the | 1187 // Pull out the length so that modifications to the length in the |
| 1188 // loop will not affect the looping and side effects are visible. | 1188 // loop will not affect the looping and side effects are visible. |
| 1189 var array = ToObject(this); | 1189 var array = ToObject(this); |
| 1190 var length = TO_UINT32(array.length); | 1190 var length = TO_UINT32(array.length); |
| 1191 | 1191 |
| 1192 if (!IS_SPEC_FUNCTION(f)) { | 1192 if (!IS_SPEC_FUNCTION(f)) { |
| 1193 throw MakeTypeError('called_non_callable', [ f ]); | 1193 throw MakeTypeError('called_non_callable', [ f ]); |
| 1194 } | 1194 } |
| 1195 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1195 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1196 receiver = %GetDefaultReceiver(f) || receiver; | 1196 receiver = %GetDefaultReceiver(f) || receiver; |
| 1197 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | |
| 1198 receiver = ToObject(receiver); | |
| 1199 } | 1197 } |
| 1198 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1200 | 1199 |
| 1201 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1200 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1202 for (var i = 0; i < length; i++) { | 1201 for (var i = 0; i < length; i++) { |
| 1203 if (i in array) { | 1202 if (i in array) { |
| 1204 var element = array[i]; | 1203 var element = array[i]; |
| 1205 // Prepare break slots for debugger step in. | 1204 // Prepare break slots for debugger step in. |
| 1206 if (stepping) %DebugPrepareStepInIfStepping(f); | 1205 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1207 if (%_CallFunction(receiver, element, i, array, f)) return true; | 1206 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1207 if (%_CallFunction(new_receiver, element, i, array, f)) return true; |
| 1208 } | 1208 } |
| 1209 } | 1209 } |
| 1210 return false; | 1210 return false; |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 | 1213 |
| 1214 function ArrayEvery(f, receiver) { | 1214 function ArrayEvery(f, receiver) { |
| 1215 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | 1215 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
| 1216 | 1216 |
| 1217 // Pull out the length so that modifications to the length in the | 1217 // Pull out the length so that modifications to the length in the |
| 1218 // loop will not affect the looping and side effects are visible. | 1218 // loop will not affect the looping and side effects are visible. |
| 1219 var array = ToObject(this); | 1219 var array = ToObject(this); |
| 1220 var length = TO_UINT32(array.length); | 1220 var length = TO_UINT32(array.length); |
| 1221 | 1221 |
| 1222 if (!IS_SPEC_FUNCTION(f)) { | 1222 if (!IS_SPEC_FUNCTION(f)) { |
| 1223 throw MakeTypeError('called_non_callable', [ f ]); | 1223 throw MakeTypeError('called_non_callable', [ f ]); |
| 1224 } | 1224 } |
| 1225 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1225 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1226 receiver = %GetDefaultReceiver(f) || receiver; | 1226 receiver = %GetDefaultReceiver(f) || receiver; |
| 1227 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | |
| 1228 receiver = ToObject(receiver); | |
| 1229 } | 1227 } |
| 1228 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1230 | 1229 |
| 1231 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1230 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1232 for (var i = 0; i < length; i++) { | 1231 for (var i = 0; i < length; i++) { |
| 1233 if (i in array) { | 1232 if (i in array) { |
| 1234 var element = array[i]; | 1233 var element = array[i]; |
| 1235 // Prepare break slots for debugger step in. | 1234 // Prepare break slots for debugger step in. |
| 1236 if (stepping) %DebugPrepareStepInIfStepping(f); | 1235 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1237 if (!%_CallFunction(receiver, element, i, array, f)) return false; | 1236 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1237 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; |
| 1238 } | 1238 } |
| 1239 } | 1239 } |
| 1240 return true; | 1240 return true; |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 function ArrayMap(f, receiver) { | 1243 function ArrayMap(f, receiver) { |
| 1244 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1244 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
| 1245 | 1245 |
| 1246 // Pull out the length so that modifications to the length in the | 1246 // Pull out the length so that modifications to the length in the |
| 1247 // loop will not affect the looping and side effects are visible. | 1247 // loop will not affect the looping and side effects are visible. |
| 1248 var array = ToObject(this); | 1248 var array = ToObject(this); |
| 1249 var length = TO_UINT32(array.length); | 1249 var length = TO_UINT32(array.length); |
| 1250 | 1250 |
| 1251 if (!IS_SPEC_FUNCTION(f)) { | 1251 if (!IS_SPEC_FUNCTION(f)) { |
| 1252 throw MakeTypeError('called_non_callable', [ f ]); | 1252 throw MakeTypeError('called_non_callable', [ f ]); |
| 1253 } | 1253 } |
| 1254 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1254 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1255 receiver = %GetDefaultReceiver(f) || receiver; | 1255 receiver = %GetDefaultReceiver(f) || receiver; |
| 1256 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | |
| 1257 receiver = ToObject(receiver); | |
| 1258 } | 1256 } |
| 1257 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1259 | 1258 |
| 1260 var result = new $Array(); | 1259 var result = new $Array(); |
| 1261 var accumulator = new InternalArray(length); | 1260 var accumulator = new InternalArray(length); |
| 1262 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1261 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1263 for (var i = 0; i < length; i++) { | 1262 for (var i = 0; i < length; i++) { |
| 1264 if (i in array) { | 1263 if (i in array) { |
| 1265 var element = array[i]; | 1264 var element = array[i]; |
| 1266 // Prepare break slots for debugger step in. | 1265 // Prepare break slots for debugger step in. |
| 1267 if (stepping) %DebugPrepareStepInIfStepping(f); | 1266 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1268 accumulator[i] = %_CallFunction(receiver, element, i, array, f); | 1267 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1268 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); |
| 1269 } | 1269 } |
| 1270 } | 1270 } |
| 1271 %MoveArrayContents(accumulator, result); | 1271 %MoveArrayContents(accumulator, result); |
| 1272 return result; | 1272 return result; |
| 1273 } | 1273 } |
| 1274 | 1274 |
| 1275 | 1275 |
| 1276 function ArrayIndexOf(element, index) { | 1276 function ArrayIndexOf(element, index) { |
| 1277 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); | 1277 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); |
| 1278 | 1278 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 )); | 1547 )); |
| 1548 | 1548 |
| 1549 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1549 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
| 1550 "join", getFunction("join", ArrayJoin), | 1550 "join", getFunction("join", ArrayJoin), |
| 1551 "pop", getFunction("pop", ArrayPop), | 1551 "pop", getFunction("pop", ArrayPop), |
| 1552 "push", getFunction("push", ArrayPush) | 1552 "push", getFunction("push", ArrayPush) |
| 1553 )); | 1553 )); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| 1556 SetUpArray(); | 1556 SetUpArray(); |
| OLD | NEW |