| 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 static Object* AllocateJSArray() { | 245 static Object* AllocateJSArray() { |
| 246 JSFunction* array_function = | 246 JSFunction* array_function = |
| 247 Top::context()->global_context()->array_function(); | 247 Top::context()->global_context()->array_function(); |
| 248 Object* result = Heap::AllocateJSObject(array_function); | 248 Object* result = Heap::AllocateJSObject(array_function); |
| 249 if (result->IsFailure()) return result; | 249 if (result->IsFailure()) return result; |
| 250 return result; | 250 return result; |
| 251 } | 251 } |
| 252 | 252 |
| 253 | 253 |
| 254 static Object* AllocateEmptyJSArray() { |
| 255 Object* result = AllocateJSArray(); |
| 256 if (result->IsFailure()) return result; |
| 257 JSArray* result_array = JSArray::cast(result); |
| 258 result_array->set_length(Smi::FromInt(0)); |
| 259 result_array->set_elements(Heap::empty_fixed_array()); |
| 260 return result_array; |
| 261 } |
| 262 |
| 263 |
| 254 static void CopyElements(AssertNoAllocation* no_gc, | 264 static void CopyElements(AssertNoAllocation* no_gc, |
| 255 FixedArray* dst, | 265 FixedArray* dst, |
| 256 int dst_index, | 266 int dst_index, |
| 257 FixedArray* src, | 267 FixedArray* src, |
| 258 int src_index, | 268 int src_index, |
| 259 int len) { | 269 int len) { |
| 260 ASSERT(dst != src); // Use MoveElements instead. | 270 ASSERT(dst != src); // Use MoveElements instead. |
| 261 memcpy(dst->data_start() + dst_index, | 271 memcpy(dst->data_start() + dst_index, |
| 262 src->data_start() + src_index, | 272 src->data_start() + src_index, |
| 263 len * kPointerSize); | 273 len * kPointerSize); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6. | 538 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6. |
| 529 int k = (relativeStart < 0) ? Max(len + relativeStart, 0) | 539 int k = (relativeStart < 0) ? Max(len + relativeStart, 0) |
| 530 : Min(relativeStart, len); | 540 : Min(relativeStart, len); |
| 531 | 541 |
| 532 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8. | 542 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8. |
| 533 int final = (relativeEnd < 0) ? Max(len + relativeEnd, 0) | 543 int final = (relativeEnd < 0) ? Max(len + relativeEnd, 0) |
| 534 : Min(relativeEnd, len); | 544 : Min(relativeEnd, len); |
| 535 | 545 |
| 536 // Calculate the length of result array. | 546 // Calculate the length of result array. |
| 537 int result_len = final - k; | 547 int result_len = final - k; |
| 538 if (result_len < 0) { | 548 if (result_len <= 0) { |
| 539 result_len = 0; | 549 return AllocateEmptyJSArray(); |
| 540 } | 550 } |
| 541 | 551 |
| 542 Object* result = AllocateJSArray(); | 552 Object* result = AllocateJSArray(); |
| 543 if (result->IsFailure()) return result; | 553 if (result->IsFailure()) return result; |
| 544 JSArray* result_array = JSArray::cast(result); | 554 JSArray* result_array = JSArray::cast(result); |
| 545 | 555 |
| 546 result = Heap::AllocateUninitializedFixedArray(result_len); | 556 result = Heap::AllocateUninitializedFixedArray(result_len); |
| 547 if (result->IsFailure()) return result; | 557 if (result->IsFailure()) return result; |
| 548 FixedArray* result_elms = FixedArray::cast(result); | 558 FixedArray* result_elms = FixedArray::cast(result); |
| 549 | 559 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 int deleteCount = len; | 609 int deleteCount = len; |
| 600 if (n_arguments > 1) { | 610 if (n_arguments > 1) { |
| 601 Object* arg2 = args[2]; | 611 Object* arg2 = args[2]; |
| 602 if (arg2->IsSmi()) { | 612 if (arg2->IsSmi()) { |
| 603 deleteCount = Smi::cast(arg2)->value(); | 613 deleteCount = Smi::cast(arg2)->value(); |
| 604 } else { | 614 } else { |
| 605 return CallJsBuiltin("ArraySplice", args); | 615 return CallJsBuiltin("ArraySplice", args); |
| 606 } | 616 } |
| 607 } | 617 } |
| 608 int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart); | 618 int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart); |
| 619 if (actualDeleteCount == 0) { |
| 620 return AllocateEmptyJSArray(); |
| 621 } |
| 609 | 622 |
| 610 // Allocate result array. | 623 // Allocate result array. |
| 611 Object* result = AllocateJSArray(); | 624 Object* result = AllocateJSArray(); |
| 612 if (result->IsFailure()) return result; | 625 if (result->IsFailure()) return result; |
| 613 JSArray* result_array = JSArray::cast(result); | 626 JSArray* result_array = JSArray::cast(result); |
| 614 | 627 |
| 615 result = Heap::AllocateUninitializedFixedArray(actualDeleteCount); | 628 result = Heap::AllocateUninitializedFixedArray(actualDeleteCount); |
| 616 if (result->IsFailure()) return result; | 629 if (result->IsFailure()) return result; |
| 617 FixedArray* result_elms = FixedArray::cast(result); | 630 FixedArray* result_elms = FixedArray::cast(result); |
| 618 | 631 |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 if (entry->contains(pc)) { | 1338 if (entry->contains(pc)) { |
| 1326 return names_[i]; | 1339 return names_[i]; |
| 1327 } | 1340 } |
| 1328 } | 1341 } |
| 1329 } | 1342 } |
| 1330 return NULL; | 1343 return NULL; |
| 1331 } | 1344 } |
| 1332 | 1345 |
| 1333 | 1346 |
| 1334 } } // namespace v8::internal | 1347 } } // namespace v8::internal |
| OLD | NEW |