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 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); | 1118 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); |
1119 | 1119 |
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 var needs_wrapper = false; |
1128 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1129 if (IS_NULL_OR_UNDEFINED(receiver)) { |
1129 receiver = %GetDefaultReceiver(f) || receiver; | 1130 receiver = %GetDefaultReceiver(f) || receiver; |
1130 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | 1131 } else { |
1131 receiver = ToObject(receiver); | 1132 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1132 } | 1133 } |
1133 | 1134 |
1134 var result = new $Array(); | 1135 var result = new $Array(); |
1135 var accumulator = new InternalArray(); | 1136 var accumulator = new InternalArray(); |
1136 var accumulator_length = 0; | 1137 var accumulator_length = 0; |
1137 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1138 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1138 for (var i = 0; i < length; i++) { | 1139 for (var i = 0; i < length; i++) { |
1139 if (i in array) { | 1140 if (i in array) { |
1140 var element = array[i]; | 1141 var element = array[i]; |
1141 // Prepare break slots for debugger step in. | 1142 // Prepare break slots for debugger step in. |
1142 if (stepping) %DebugPrepareStepInIfStepping(f); | 1143 if (stepping) %DebugPrepareStepInIfStepping(f); |
1143 if (%_CallFunction(receiver, element, i, array, f)) { | 1144 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1145 if (%_CallFunction(new_receiver, element, i, array, f)) { |
1144 accumulator[accumulator_length++] = element; | 1146 accumulator[accumulator_length++] = element; |
1145 } | 1147 } |
1146 } | 1148 } |
1147 } | 1149 } |
1148 %MoveArrayContents(accumulator, result); | 1150 %MoveArrayContents(accumulator, result); |
1149 return result; | 1151 return result; |
1150 } | 1152 } |
1151 | 1153 |
1152 | 1154 |
1153 function ArrayForEach(f, receiver) { | 1155 function ArrayForEach(f, receiver) { |
1154 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | 1156 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
1155 | 1157 |
1156 // Pull out the length so that modifications to the length in the | 1158 // Pull out the length so that modifications to the length in the |
1157 // loop will not affect the looping and side effects are visible. | 1159 // loop will not affect the looping and side effects are visible. |
1158 var array = ToObject(this); | 1160 var array = ToObject(this); |
1159 var length = TO_UINT32(array.length); | 1161 var length = TO_UINT32(array.length); |
1160 | 1162 |
1161 if (!IS_SPEC_FUNCTION(f)) { | 1163 if (!IS_SPEC_FUNCTION(f)) { |
1162 throw MakeTypeError('called_non_callable', [ f ]); | 1164 throw MakeTypeError('called_non_callable', [ f ]); |
1163 } | 1165 } |
| 1166 var needs_wrapper = false; |
1164 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1167 if (IS_NULL_OR_UNDEFINED(receiver)) { |
1165 receiver = %GetDefaultReceiver(f) || receiver; | 1168 receiver = %GetDefaultReceiver(f) || receiver; |
1166 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | 1169 } else { |
1167 receiver = ToObject(receiver); | 1170 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1168 } | 1171 } |
1169 | 1172 |
1170 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1173 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1171 for (var i = 0; i < length; i++) { | 1174 for (var i = 0; i < length; i++) { |
1172 if (i in array) { | 1175 if (i in array) { |
1173 var element = array[i]; | 1176 var element = array[i]; |
1174 // Prepare break slots for debugger step in. | 1177 // Prepare break slots for debugger step in. |
1175 if (stepping) %DebugPrepareStepInIfStepping(f); | 1178 if (stepping) %DebugPrepareStepInIfStepping(f); |
1176 %_CallFunction(receiver, element, i, array, f); | 1179 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1180 %_CallFunction(new_receiver, element, i, array, f); |
1177 } | 1181 } |
1178 } | 1182 } |
1179 } | 1183 } |
1180 | 1184 |
1181 | 1185 |
1182 // Executes the function once for each element present in the | 1186 // Executes the function once for each element present in the |
1183 // array until it finds one where callback returns true. | 1187 // array until it finds one where callback returns true. |
1184 function ArraySome(f, receiver) { | 1188 function ArraySome(f, receiver) { |
1185 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1189 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); |
1186 | 1190 |
1187 // Pull out the length so that modifications to the length in the | 1191 // Pull out the length so that modifications to the length in the |
1188 // loop will not affect the looping and side effects are visible. | 1192 // loop will not affect the looping and side effects are visible. |
1189 var array = ToObject(this); | 1193 var array = ToObject(this); |
1190 var length = TO_UINT32(array.length); | 1194 var length = TO_UINT32(array.length); |
1191 | 1195 |
1192 if (!IS_SPEC_FUNCTION(f)) { | 1196 if (!IS_SPEC_FUNCTION(f)) { |
1193 throw MakeTypeError('called_non_callable', [ f ]); | 1197 throw MakeTypeError('called_non_callable', [ f ]); |
1194 } | 1198 } |
| 1199 var needs_wrapper = false; |
1195 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1200 if (IS_NULL_OR_UNDEFINED(receiver)) { |
1196 receiver = %GetDefaultReceiver(f) || receiver; | 1201 receiver = %GetDefaultReceiver(f) || receiver; |
1197 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | 1202 } else { |
1198 receiver = ToObject(receiver); | 1203 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1199 } | 1204 } |
1200 | 1205 |
1201 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1206 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1202 for (var i = 0; i < length; i++) { | 1207 for (var i = 0; i < length; i++) { |
1203 if (i in array) { | 1208 if (i in array) { |
1204 var element = array[i]; | 1209 var element = array[i]; |
1205 // Prepare break slots for debugger step in. | 1210 // Prepare break slots for debugger step in. |
1206 if (stepping) %DebugPrepareStepInIfStepping(f); | 1211 if (stepping) %DebugPrepareStepInIfStepping(f); |
1207 if (%_CallFunction(receiver, element, i, array, f)) return true; | 1212 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1213 if (%_CallFunction(new_receiver, element, i, array, f)) return true; |
1208 } | 1214 } |
1209 } | 1215 } |
1210 return false; | 1216 return false; |
1211 } | 1217 } |
1212 | 1218 |
1213 | 1219 |
1214 function ArrayEvery(f, receiver) { | 1220 function ArrayEvery(f, receiver) { |
1215 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | 1221 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
1216 | 1222 |
1217 // Pull out the length so that modifications to the length in the | 1223 // Pull out the length so that modifications to the length in the |
1218 // loop will not affect the looping and side effects are visible. | 1224 // loop will not affect the looping and side effects are visible. |
1219 var array = ToObject(this); | 1225 var array = ToObject(this); |
1220 var length = TO_UINT32(array.length); | 1226 var length = TO_UINT32(array.length); |
1221 | 1227 |
1222 if (!IS_SPEC_FUNCTION(f)) { | 1228 if (!IS_SPEC_FUNCTION(f)) { |
1223 throw MakeTypeError('called_non_callable', [ f ]); | 1229 throw MakeTypeError('called_non_callable', [ f ]); |
1224 } | 1230 } |
| 1231 var needs_wrapper = false; |
1225 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1232 if (IS_NULL_OR_UNDEFINED(receiver)) { |
1226 receiver = %GetDefaultReceiver(f) || receiver; | 1233 receiver = %GetDefaultReceiver(f) || receiver; |
1227 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | 1234 } else { |
1228 receiver = ToObject(receiver); | 1235 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1229 } | 1236 } |
1230 | 1237 |
1231 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1238 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1232 for (var i = 0; i < length; i++) { | 1239 for (var i = 0; i < length; i++) { |
1233 if (i in array) { | 1240 if (i in array) { |
1234 var element = array[i]; | 1241 var element = array[i]; |
1235 // Prepare break slots for debugger step in. | 1242 // Prepare break slots for debugger step in. |
1236 if (stepping) %DebugPrepareStepInIfStepping(f); | 1243 if (stepping) %DebugPrepareStepInIfStepping(f); |
1237 if (!%_CallFunction(receiver, element, i, array, f)) return false; | 1244 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1245 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; |
1238 } | 1246 } |
1239 } | 1247 } |
1240 return true; | 1248 return true; |
1241 } | 1249 } |
1242 | 1250 |
1243 function ArrayMap(f, receiver) { | 1251 function ArrayMap(f, receiver) { |
1244 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1252 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
1245 | 1253 |
1246 // Pull out the length so that modifications to the length in the | 1254 // Pull out the length so that modifications to the length in the |
1247 // loop will not affect the looping and side effects are visible. | 1255 // loop will not affect the looping and side effects are visible. |
1248 var array = ToObject(this); | 1256 var array = ToObject(this); |
1249 var length = TO_UINT32(array.length); | 1257 var length = TO_UINT32(array.length); |
1250 | 1258 |
1251 if (!IS_SPEC_FUNCTION(f)) { | 1259 if (!IS_SPEC_FUNCTION(f)) { |
1252 throw MakeTypeError('called_non_callable', [ f ]); | 1260 throw MakeTypeError('called_non_callable', [ f ]); |
1253 } | 1261 } |
| 1262 var needs_wrapper = false; |
1254 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1263 if (IS_NULL_OR_UNDEFINED(receiver)) { |
1255 receiver = %GetDefaultReceiver(f) || receiver; | 1264 receiver = %GetDefaultReceiver(f) || receiver; |
1256 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { | 1265 } else { |
1257 receiver = ToObject(receiver); | 1266 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1258 } | 1267 } |
1259 | 1268 |
1260 var result = new $Array(); | 1269 var result = new $Array(); |
1261 var accumulator = new InternalArray(length); | 1270 var accumulator = new InternalArray(length); |
1262 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1271 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1263 for (var i = 0; i < length; i++) { | 1272 for (var i = 0; i < length; i++) { |
1264 if (i in array) { | 1273 if (i in array) { |
1265 var element = array[i]; | 1274 var element = array[i]; |
1266 // Prepare break slots for debugger step in. | 1275 // Prepare break slots for debugger step in. |
1267 if (stepping) %DebugPrepareStepInIfStepping(f); | 1276 if (stepping) %DebugPrepareStepInIfStepping(f); |
1268 accumulator[i] = %_CallFunction(receiver, element, i, array, f); | 1277 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1278 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); |
1269 } | 1279 } |
1270 } | 1280 } |
1271 %MoveArrayContents(accumulator, result); | 1281 %MoveArrayContents(accumulator, result); |
1272 return result; | 1282 return result; |
1273 } | 1283 } |
1274 | 1284 |
1275 | 1285 |
1276 function ArrayIndexOf(element, index) { | 1286 function ArrayIndexOf(element, index) { |
1277 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); | 1287 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); |
1278 | 1288 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 )); | 1557 )); |
1548 | 1558 |
1549 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1559 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
1550 "join", getFunction("join", ArrayJoin), | 1560 "join", getFunction("join", ArrayJoin), |
1551 "pop", getFunction("pop", ArrayPop), | 1561 "pop", getFunction("pop", ArrayPop), |
1552 "push", getFunction("push", ArrayPush) | 1562 "push", getFunction("push", ArrayPush) |
1553 )); | 1563 )); |
1554 } | 1564 } |
1555 | 1565 |
1556 SetUpArray(); | 1566 SetUpArray(); |
OLD | NEW |