OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 BUILTIN(ArrayPush) { | 245 BUILTIN(ArrayPush) { |
246 JSArray* array = JSArray::cast(*args.receiver()); | 246 JSArray* array = JSArray::cast(*args.receiver()); |
247 ASSERT(array->HasFastElements()); | 247 ASSERT(array->HasFastElements()); |
248 | 248 |
249 int len = Smi::cast(array->length())->value(); | 249 int len = Smi::cast(array->length())->value(); |
250 int to_add = args.length() - 1; | 250 int to_add = args.length() - 1; |
251 if (to_add == 0) { | 251 if (to_add == 0) { |
252 return Smi::FromInt(len); | 252 return Smi::FromInt(len); |
253 } | 253 } |
| 254 // Currently fixed arrays cannot grow too big, so |
| 255 // we should never hit this case. |
| 256 ASSERT(to_add <= (Smi::kMaxValue - len)); |
254 | 257 |
255 int new_length = len + to_add; | 258 int new_length = len + to_add; |
256 FixedArray* elms = FixedArray::cast(array->elements()); | 259 FixedArray* elms = FixedArray::cast(array->elements()); |
257 | 260 |
258 if (new_length > elms->length()) { | 261 if (new_length > elms->length()) { |
259 // New backing storage is needed. | 262 // New backing storage is needed. |
260 int capacity = new_length + (new_length >> 1) + 16; | 263 int capacity = new_length + (new_length >> 1) + 16; |
261 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); | 264 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); |
262 if (obj->IsFailure()) return obj; | 265 if (obj->IsFailure()) return obj; |
263 | 266 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 JSArray* array = JSArray::cast(*args.receiver()); | 366 JSArray* array = JSArray::cast(*args.receiver()); |
364 ASSERT(array->HasFastElements()); | 367 ASSERT(array->HasFastElements()); |
365 | 368 |
366 int len = Smi::cast(array->length())->value(); | 369 int len = Smi::cast(array->length())->value(); |
367 int to_add = args.length() - 1; | 370 int to_add = args.length() - 1; |
368 // Note that we cannot quit early if to_add == 0 as | 371 // Note that we cannot quit early if to_add == 0 as |
369 // values should be lifted from prototype into | 372 // values should be lifted from prototype into |
370 // the array. | 373 // the array. |
371 | 374 |
372 int new_length = len + to_add; | 375 int new_length = len + to_add; |
| 376 // Currently fixed arrays cannot grow too big, so |
| 377 // we should never hit this case. |
| 378 ASSERT(to_add <= (Smi::kMaxValue - len)); |
| 379 |
373 FixedArray* elms = FixedArray::cast(array->elements()); | 380 FixedArray* elms = FixedArray::cast(array->elements()); |
374 | 381 |
375 // Fetch the prototype. | 382 // Fetch the prototype. |
376 JSFunction* array_function = | 383 JSFunction* array_function = |
377 Top::context()->global_context()->array_function(); | 384 Top::context()->global_context()->array_function(); |
378 JSObject* prototype = JSObject::cast(array_function->prototype()); | 385 JSObject* prototype = JSObject::cast(array_function->prototype()); |
379 | 386 |
380 if (new_length > elms->length()) { | 387 if (new_length > elms->length()) { |
381 // New backing storage is needed. | 388 // New backing storage is needed. |
382 int capacity = new_length + (new_length >> 1) + 16; | 389 int capacity = new_length + (new_length >> 1) + 16; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 for (int k = actualStart; k < (len - actualDeleteCount); k++) { | 614 for (int k = actualStart; k < (len - actualDeleteCount); k++) { |
608 elms->set(k + itemCount, | 615 elms->set(k + itemCount, |
609 GetElementToMove(k + actualDeleteCount, elms, prototype), | 616 GetElementToMove(k + actualDeleteCount, elms, prototype), |
610 mode); | 617 mode); |
611 } | 618 } |
612 | 619 |
613 for (int k = len; k > new_length; k--) { | 620 for (int k = len; k > new_length; k--) { |
614 elms->set(k - 1, Heap::the_hole_value()); | 621 elms->set(k - 1, Heap::the_hole_value()); |
615 } | 622 } |
616 } else if (itemCount > actualDeleteCount) { | 623 } else if (itemCount > actualDeleteCount) { |
| 624 // Currently fixed arrays cannot grow too big, so |
| 625 // we should never hit this case. |
| 626 ASSERT((itemCount - actualDeleteCount) <= (Smi::kMaxValue - len)); |
| 627 |
617 FixedArray* source_elms = elms; | 628 FixedArray* source_elms = elms; |
618 | 629 |
619 // Check if array need to grow. | 630 // Check if array need to grow. |
620 if (new_length > elms->length()) { | 631 if (new_length > elms->length()) { |
621 // New backing storage is needed. | 632 // New backing storage is needed. |
622 int capacity = new_length + (new_length >> 1) + 16; | 633 int capacity = new_length + (new_length >> 1) + 16; |
623 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); | 634 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); |
624 if (obj->IsFailure()) return obj; | 635 if (obj->IsFailure()) return obj; |
625 | 636 |
626 FixedArray* new_elms = FixedArray::cast(obj); | 637 FixedArray* new_elms = FixedArray::cast(obj); |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 if (entry->contains(pc)) { | 1306 if (entry->contains(pc)) { |
1296 return names_[i]; | 1307 return names_[i]; |
1297 } | 1308 } |
1298 } | 1309 } |
1299 } | 1310 } |
1300 return NULL; | 1311 return NULL; |
1301 } | 1312 } |
1302 | 1313 |
1303 | 1314 |
1304 } } // namespace v8::internal | 1315 } } // namespace v8::internal |
OLD | NEW |