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 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 for (var i = start_i; i < limit; ++i) { | 265 for (var i = start_i; i < limit; ++i) { |
266 var current = array[i]; | 266 var current = array[i]; |
267 if (!IS_UNDEFINED(current) || i in array) { | 267 if (!IS_UNDEFINED(current) || i in array) { |
268 DefineIndexedProperty(deleted_elements, i - start_i, current); | 268 DefineIndexedProperty(deleted_elements, i - start_i, current); |
269 } | 269 } |
270 } | 270 } |
271 } else { | 271 } else { |
272 var length = indices.length; | 272 var length = indices.length; |
273 for (var k = 0; k < length; ++k) { | 273 for (var k = 0; k < length; ++k) { |
274 var key = indices[k]; | 274 var key = indices[k]; |
275 if (!IS_UNDEFINED(key)) { | 275 if (key >= start_i) { |
276 if (key >= start_i) { | 276 var current = array[key]; |
277 var current = array[key]; | 277 if (!IS_UNDEFINED(current) || key in array) { |
278 if (!IS_UNDEFINED(current) || key in array) { | 278 DefineIndexedProperty(deleted_elements, key - start_i, current); |
279 DefineIndexedProperty(deleted_elements, key - start_i, current); | |
280 } | |
281 } | 279 } |
282 } | 280 } |
283 } | 281 } |
284 } | 282 } |
285 } | 283 } |
286 | 284 |
287 | 285 |
288 // This function implements the optimized splice implementation that can use | 286 // This function implements the optimized splice implementation that can use |
289 // special array operations to handle sparse arrays in a sensible fashion. | 287 // special array operations to handle sparse arrays in a sensible fashion. |
290 function SparseMove(array, start_i, del_count, len, num_additional_args) { | 288 function SparseMove(array, start_i, del_count, len, num_additional_args) { |
(...skipping 16 matching lines...) Expand all Loading... |
307 for (var i = start_i + del_count; i < limit; ++i) { | 305 for (var i = start_i + del_count; i < limit; ++i) { |
308 var current = array[i]; | 306 var current = array[i]; |
309 if (!IS_UNDEFINED(current) || i in array) { | 307 if (!IS_UNDEFINED(current) || i in array) { |
310 new_array[i - del_count + num_additional_args] = current; | 308 new_array[i - del_count + num_additional_args] = current; |
311 } | 309 } |
312 } | 310 } |
313 } else { | 311 } else { |
314 var length = indices.length; | 312 var length = indices.length; |
315 for (var k = 0; k < length; ++k) { | 313 for (var k = 0; k < length; ++k) { |
316 var key = indices[k]; | 314 var key = indices[k]; |
317 if (!IS_UNDEFINED(key)) { | 315 if (key < start_i) { |
318 if (key < start_i) { | 316 var current = array[key]; |
319 var current = array[key]; | 317 if (!IS_UNDEFINED(current) || key in array) { |
320 if (!IS_UNDEFINED(current) || key in array) { | 318 new_array[key] = current; |
321 new_array[key] = current; | 319 } |
322 } | 320 } else if (key >= start_i + del_count) { |
323 } else if (key >= start_i + del_count) { | 321 var current = array[key]; |
324 var current = array[key]; | 322 if (!IS_UNDEFINED(current) || key in array) { |
325 if (!IS_UNDEFINED(current) || key in array) { | 323 var new_key = key - del_count + num_additional_args; |
326 var new_key = key - del_count + num_additional_args; | 324 new_array[new_key] = current; |
327 new_array[new_key] = current; | 325 if (new_key > 0xfffffffe) { |
328 if (new_key > 0xfffffffe) { | 326 big_indices = big_indices || new InternalArray(); |
329 big_indices = big_indices || new InternalArray(); | 327 big_indices.push(new_key); |
330 big_indices.push(new_key); | |
331 } | |
332 } | 328 } |
333 } | 329 } |
334 } | 330 } |
335 } | 331 } |
336 } | 332 } |
337 // Move contents of new_array into this array | 333 // Move contents of new_array into this array |
338 %MoveArrayContents(new_array, array); | 334 %MoveArrayContents(new_array, array); |
339 // Add any moved values that aren't elements anymore. | 335 // Add any moved values that aren't elements anymore. |
340 if (!IS_UNDEFINED(big_indices)) { | 336 if (!IS_UNDEFINED(big_indices)) { |
341 var length = big_indices.length; | 337 var length = big_indices.length; |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 var proto_length = indices; | 1055 var proto_length = indices; |
1060 for (var i = 0; i < proto_length; i++) { | 1056 for (var i = 0; i < proto_length; i++) { |
1061 if (!HAS_OWN_PROPERTY(obj, i) && HAS_OWN_PROPERTY(proto, i)) { | 1057 if (!HAS_OWN_PROPERTY(obj, i) && HAS_OWN_PROPERTY(proto, i)) { |
1062 obj[i] = proto[i]; | 1058 obj[i] = proto[i]; |
1063 if (i >= max) { max = i + 1; } | 1059 if (i >= max) { max = i + 1; } |
1064 } | 1060 } |
1065 } | 1061 } |
1066 } else { | 1062 } else { |
1067 for (var i = 0; i < indices.length; i++) { | 1063 for (var i = 0; i < indices.length; i++) { |
1068 var index = indices[i]; | 1064 var index = indices[i]; |
1069 if (!IS_UNDEFINED(index) && !HAS_OWN_PROPERTY(obj, index) | 1065 if (!HAS_OWN_PROPERTY(obj, index) && HAS_OWN_PROPERTY(proto, index)) { |
1070 && HAS_OWN_PROPERTY(proto, index)) { | |
1071 obj[index] = proto[index]; | 1066 obj[index] = proto[index]; |
1072 if (index >= max) { max = index + 1; } | 1067 if (index >= max) { max = index + 1; } |
1073 } | 1068 } |
1074 } | 1069 } |
1075 } | 1070 } |
1076 } | 1071 } |
1077 return max; | 1072 return max; |
1078 }; | 1073 }; |
1079 | 1074 |
1080 // Set a value of "undefined" on all indices in the range from..to | 1075 // Set a value of "undefined" on all indices in the range from..to |
1081 // where a prototype of obj has an element. I.e., shadow all prototype | 1076 // where a prototype of obj has an element. I.e., shadow all prototype |
1082 // elements in that range. | 1077 // elements in that range. |
1083 var ShadowPrototypeElements = function(obj, from, to) { | 1078 var ShadowPrototypeElements = function(obj, from, to) { |
1084 for (var proto = %_GetPrototype(obj); proto; proto = %_GetPrototype(proto))
{ | 1079 for (var proto = %_GetPrototype(obj); proto; proto = %_GetPrototype(proto))
{ |
1085 var indices = %GetArrayKeys(proto, to); | 1080 var indices = %GetArrayKeys(proto, to); |
1086 if (IS_NUMBER(indices)) { | 1081 if (IS_NUMBER(indices)) { |
1087 // It's an interval. | 1082 // It's an interval. |
1088 var proto_length = indices; | 1083 var proto_length = indices; |
1089 for (var i = from; i < proto_length; i++) { | 1084 for (var i = from; i < proto_length; i++) { |
1090 if (HAS_OWN_PROPERTY(proto, i)) { | 1085 if (HAS_OWN_PROPERTY(proto, i)) { |
1091 obj[i] = UNDEFINED; | 1086 obj[i] = UNDEFINED; |
1092 } | 1087 } |
1093 } | 1088 } |
1094 } else { | 1089 } else { |
1095 for (var i = 0; i < indices.length; i++) { | 1090 for (var i = 0; i < indices.length; i++) { |
1096 var index = indices[i]; | 1091 var index = indices[i]; |
1097 if (!IS_UNDEFINED(index) && from <= index && | 1092 if (from <= index && HAS_OWN_PROPERTY(proto, index)) { |
1098 HAS_OWN_PROPERTY(proto, index)) { | |
1099 obj[index] = UNDEFINED; | 1093 obj[index] = UNDEFINED; |
1100 } | 1094 } |
1101 } | 1095 } |
1102 } | 1096 } |
1103 } | 1097 } |
1104 }; | 1098 }; |
1105 | 1099 |
1106 var SafeRemoveArrayHoles = function SafeRemoveArrayHoles(obj) { | 1100 var SafeRemoveArrayHoles = function SafeRemoveArrayHoles(obj) { |
1107 // Copy defined elements from the end to fill in all holes and undefineds | 1101 // Copy defined elements from the end to fill in all holes and undefineds |
1108 // in the beginning of the array. Write undefineds and holes at the end | 1102 // in the beginning of the array. Write undefineds and holes at the end |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 // Fall through to loop below. | 1366 // Fall through to loop below. |
1373 } else { | 1367 } else { |
1374 if (indices.length == 0) return -1; | 1368 if (indices.length == 0) return -1; |
1375 // Get all the keys in sorted order. | 1369 // Get all the keys in sorted order. |
1376 var sortedKeys = GetSortedArrayKeys(array, indices); | 1370 var sortedKeys = GetSortedArrayKeys(array, indices); |
1377 var n = sortedKeys.length; | 1371 var n = sortedKeys.length; |
1378 var i = 0; | 1372 var i = 0; |
1379 while (i < n && sortedKeys[i] < index) i++; | 1373 while (i < n && sortedKeys[i] < index) i++; |
1380 while (i < n) { | 1374 while (i < n) { |
1381 var key = sortedKeys[i]; | 1375 var key = sortedKeys[i]; |
1382 if (!IS_UNDEFINED(key) && array[key] === element) return key; | 1376 if (array[key] === element) return key; |
1383 i++; | 1377 i++; |
1384 } | 1378 } |
1385 return -1; | 1379 return -1; |
1386 } | 1380 } |
1387 } | 1381 } |
1388 // Lookup through the array. | 1382 // Lookup through the array. |
1389 if (!IS_UNDEFINED(element)) { | 1383 if (!IS_UNDEFINED(element)) { |
1390 for (var i = min; i < max; i++) { | 1384 for (var i = min; i < max; i++) { |
1391 if (array[i] === element) return i; | 1385 if (array[i] === element) return i; |
1392 } | 1386 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 // It's an interval. | 1425 // It's an interval. |
1432 max = indices; // Capped by index already. | 1426 max = indices; // Capped by index already. |
1433 // Fall through to loop below. | 1427 // Fall through to loop below. |
1434 } else { | 1428 } else { |
1435 if (indices.length == 0) return -1; | 1429 if (indices.length == 0) return -1; |
1436 // Get all the keys in sorted order. | 1430 // Get all the keys in sorted order. |
1437 var sortedKeys = GetSortedArrayKeys(array, indices); | 1431 var sortedKeys = GetSortedArrayKeys(array, indices); |
1438 var i = sortedKeys.length - 1; | 1432 var i = sortedKeys.length - 1; |
1439 while (i >= 0) { | 1433 while (i >= 0) { |
1440 var key = sortedKeys[i]; | 1434 var key = sortedKeys[i]; |
1441 if (!IS_UNDEFINED(key) && array[key] === element) return key; | 1435 if (array[key] === element) return key; |
1442 i--; | 1436 i--; |
1443 } | 1437 } |
1444 return -1; | 1438 return -1; |
1445 } | 1439 } |
1446 } | 1440 } |
1447 // Lookup through the array. | 1441 // Lookup through the array. |
1448 if (!IS_UNDEFINED(element)) { | 1442 if (!IS_UNDEFINED(element)) { |
1449 for (var i = max; i >= min; i--) { | 1443 for (var i = max; i >= min; i--) { |
1450 if (array[i] === element) return i; | 1444 if (array[i] === element) return i; |
1451 } | 1445 } |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1961 %InstallToContext([ | 1955 %InstallToContext([ |
1962 "array_pop", ArrayPop, | 1956 "array_pop", ArrayPop, |
1963 "array_push", ArrayPush, | 1957 "array_push", ArrayPush, |
1964 "array_shift", ArrayShift, | 1958 "array_shift", ArrayShift, |
1965 "array_splice", ArraySplice, | 1959 "array_splice", ArraySplice, |
1966 "array_slice", ArraySlice, | 1960 "array_slice", ArraySlice, |
1967 "array_unshift", ArrayUnshift, | 1961 "array_unshift", ArrayUnshift, |
1968 ]); | 1962 ]); |
1969 | 1963 |
1970 }); | 1964 }); |
OLD | NEW |