| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 if (proto == heap->null_value()) return false; | 287 if (proto == heap->null_value()) return false; |
| 288 array_proto = JSObject::cast(proto); | 288 array_proto = JSObject::cast(proto); |
| 289 if (array_proto != native_context->initial_object_prototype()) return false; | 289 if (array_proto != native_context->initial_object_prototype()) return false; |
| 290 if (array_proto->elements() != heap->empty_fixed_array()) return false; | 290 if (array_proto->elements() != heap->empty_fixed_array()) return false; |
| 291 return array_proto->GetPrototype()->IsNull(); | 291 return array_proto->GetPrototype()->IsNull(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 | 294 |
| 295 // Returns empty handle if not applicable. | 295 // Returns empty handle if not applicable. |
| 296 MUST_USE_RESULT | 296 MUST_USE_RESULT |
| 297 static inline Handle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( | 297 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( |
| 298 Isolate* isolate, | 298 Isolate* isolate, |
| 299 Handle<Object> receiver, | 299 Handle<Object> receiver, |
| 300 Arguments* args, | 300 Arguments* args, |
| 301 int first_added_arg) { | 301 int first_added_arg) { |
| 302 if (!receiver->IsJSArray()) return Handle<FixedArrayBase>::null(); | 302 if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>(); |
| 303 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 303 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 304 if (array->map()->is_observed()) return Handle<FixedArrayBase>::null(); | 304 if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>(); |
| 305 if (!array->map()->is_extensible()) return Handle<FixedArrayBase>::null(); | 305 if (!array->map()->is_extensible()) return MaybeHandle<FixedArrayBase>(); |
| 306 Handle<FixedArrayBase> elms(array->elements(), isolate); | 306 Handle<FixedArrayBase> elms(array->elements(), isolate); |
| 307 Heap* heap = isolate->heap(); | 307 Heap* heap = isolate->heap(); |
| 308 Map* map = elms->map(); | 308 Map* map = elms->map(); |
| 309 if (map == heap->fixed_array_map()) { | 309 if (map == heap->fixed_array_map()) { |
| 310 if (args == NULL || array->HasFastObjectElements()) return elms; | 310 if (args == NULL || array->HasFastObjectElements()) return elms; |
| 311 } else if (map == heap->fixed_cow_array_map()) { | 311 } else if (map == heap->fixed_cow_array_map()) { |
| 312 elms = JSObject::EnsureWritableFastElements(array); | 312 elms = JSObject::EnsureWritableFastElements(array); |
| 313 if (args == NULL || array->HasFastObjectElements()) return elms; | 313 if (args == NULL || array->HasFastObjectElements()) return elms; |
| 314 } else if (map == heap->fixed_double_array_map()) { | 314 } else if (map == heap->fixed_double_array_map()) { |
| 315 if (args == NULL) return elms; | 315 if (args == NULL) return elms; |
| 316 } else { | 316 } else { |
| 317 return Handle<FixedArrayBase>::null(); | 317 return MaybeHandle<FixedArrayBase>(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 // Need to ensure that the arguments passed in args can be contained in | 320 // Need to ensure that the arguments passed in args can be contained in |
| 321 // the array. | 321 // the array. |
| 322 int args_length = args->length(); | 322 int args_length = args->length(); |
| 323 if (first_added_arg >= args_length) return handle(array->elements(), isolate); | 323 if (first_added_arg >= args_length) return handle(array->elements(), isolate); |
| 324 | 324 |
| 325 ElementsKind origin_kind = array->map()->elements_kind(); | 325 ElementsKind origin_kind = array->map()->elements_kind(); |
| 326 ASSERT(!IsFastObjectElementsKind(origin_kind)); | 326 ASSERT(!IsFastObjectElementsKind(origin_kind)); |
| 327 ElementsKind target_kind = origin_kind; | 327 ElementsKind target_kind = origin_kind; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 argv.start(), | 384 argv.start(), |
| 385 &pending_exception); | 385 &pending_exception); |
| 386 if (pending_exception) return Failure::Exception(); | 386 if (pending_exception) return Failure::Exception(); |
| 387 return *result; | 387 return *result; |
| 388 } | 388 } |
| 389 | 389 |
| 390 | 390 |
| 391 BUILTIN(ArrayPush) { | 391 BUILTIN(ArrayPush) { |
| 392 HandleScope scope(isolate); | 392 HandleScope scope(isolate); |
| 393 Handle<Object> receiver = args.receiver(); | 393 Handle<Object> receiver = args.receiver(); |
| 394 Handle<FixedArrayBase> elms_obj = | 394 MaybeHandle<FixedArrayBase> maybe_elms_obj = |
| 395 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1); | 395 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1); |
| 396 if (elms_obj.is_null()) return CallJsBuiltin(isolate, "ArrayPush", args); | 396 Handle<FixedArrayBase> elms_obj; |
| 397 if (!maybe_elms_obj.ToHandle(&elms_obj)) { |
| 398 return CallJsBuiltin(isolate, "ArrayPush", args); |
| 399 } |
| 397 | 400 |
| 398 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 401 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 399 ASSERT(!array->map()->is_observed()); | 402 ASSERT(!array->map()->is_observed()); |
| 400 | 403 |
| 401 ElementsKind kind = array->GetElementsKind(); | 404 ElementsKind kind = array->GetElementsKind(); |
| 402 | 405 |
| 403 if (IsFastSmiOrObjectElementsKind(kind)) { | 406 if (IsFastSmiOrObjectElementsKind(kind)) { |
| 404 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); | 407 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); |
| 405 | 408 |
| 406 int len = Smi::cast(array->length())->value(); | 409 int len = Smi::cast(array->length())->value(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // Set the length. | 492 // Set the length. |
| 490 array->set_length(Smi::FromInt(new_length)); | 493 array->set_length(Smi::FromInt(new_length)); |
| 491 return Smi::FromInt(new_length); | 494 return Smi::FromInt(new_length); |
| 492 } | 495 } |
| 493 } | 496 } |
| 494 | 497 |
| 495 | 498 |
| 496 BUILTIN(ArrayPop) { | 499 BUILTIN(ArrayPop) { |
| 497 HandleScope scope(isolate); | 500 HandleScope scope(isolate); |
| 498 Handle<Object> receiver = args.receiver(); | 501 Handle<Object> receiver = args.receiver(); |
| 499 Handle<FixedArrayBase> elms_obj = | 502 MaybeHandle<FixedArrayBase> maybe_elms_obj = |
| 500 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); | 503 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); |
| 501 if (elms_obj.is_null()) return CallJsBuiltin(isolate, "ArrayPop", args); | 504 Handle<FixedArrayBase> elms_obj; |
| 505 if (!maybe_elms_obj.ToHandle(&elms_obj)) { |
| 506 return CallJsBuiltin(isolate, "ArrayPop", args); |
| 507 } |
| 502 | 508 |
| 503 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 509 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 504 ASSERT(!array->map()->is_observed()); | 510 ASSERT(!array->map()->is_observed()); |
| 505 | 511 |
| 506 int len = Smi::cast(array->length())->value(); | 512 int len = Smi::cast(array->length())->value(); |
| 507 if (len == 0) return isolate->heap()->undefined_value(); | 513 if (len == 0) return isolate->heap()->undefined_value(); |
| 508 | 514 |
| 509 ElementsAccessor* accessor = array->GetElementsAccessor(); | 515 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 510 int new_length = len - 1; | 516 int new_length = len - 1; |
| 511 Handle<Object> element; | 517 Handle<Object> element; |
| 512 if (accessor->HasElement(*array, *array, new_length, *elms_obj)) { | 518 if (accessor->HasElement(*array, *array, new_length, *elms_obj)) { |
| 513 element = accessor->Get( | 519 element = accessor->Get( |
| 514 array, array, new_length, elms_obj); | 520 array, array, new_length, elms_obj); |
| 515 } else { | 521 } else { |
| 516 Handle<Object> proto(array->GetPrototype(), isolate); | 522 Handle<Object> proto(array->GetPrototype(), isolate); |
| 517 element = Object::GetElement(isolate, proto, len - 1); | 523 element = Object::GetElement(isolate, proto, len - 1); |
| 518 } | 524 } |
| 519 RETURN_IF_EMPTY_HANDLE(isolate, element); | 525 RETURN_IF_EMPTY_HANDLE(isolate, element); |
| 520 RETURN_IF_EMPTY_HANDLE(isolate, | 526 RETURN_IF_EMPTY_HANDLE(isolate, |
| 521 accessor->SetLength( | 527 accessor->SetLength( |
| 522 array, handle(Smi::FromInt(new_length), isolate))); | 528 array, handle(Smi::FromInt(new_length), isolate))); |
| 523 return *element; | 529 return *element; |
| 524 } | 530 } |
| 525 | 531 |
| 526 | 532 |
| 527 BUILTIN(ArrayShift) { | 533 BUILTIN(ArrayShift) { |
| 528 HandleScope scope(isolate); | 534 HandleScope scope(isolate); |
| 529 Heap* heap = isolate->heap(); | 535 Heap* heap = isolate->heap(); |
| 530 Handle<Object> receiver = args.receiver(); | 536 Handle<Object> receiver = args.receiver(); |
| 531 Handle<FixedArrayBase> elms_obj = | 537 MaybeHandle<FixedArrayBase> maybe_elms_obj = |
| 532 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); | 538 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); |
| 533 if (elms_obj.is_null() || | 539 Handle<FixedArrayBase> elms_obj; |
| 540 if (!maybe_elms_obj.ToHandle(&elms_obj) || |
| 534 !IsJSArrayFastElementMovingAllowed(heap, | 541 !IsJSArrayFastElementMovingAllowed(heap, |
| 535 *Handle<JSArray>::cast(receiver))) { | 542 *Handle<JSArray>::cast(receiver))) { |
| 536 return CallJsBuiltin(isolate, "ArrayShift", args); | 543 return CallJsBuiltin(isolate, "ArrayShift", args); |
| 537 } | 544 } |
| 538 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 545 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 539 ASSERT(!array->map()->is_observed()); | 546 ASSERT(!array->map()->is_observed()); |
| 540 | 547 |
| 541 int len = Smi::cast(array->length())->value(); | 548 int len = Smi::cast(array->length())->value(); |
| 542 if (len == 0) return heap->undefined_value(); | 549 if (len == 0) return heap->undefined_value(); |
| 543 | 550 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 569 array->set_length(Smi::FromInt(len - 1)); | 576 array->set_length(Smi::FromInt(len - 1)); |
| 570 | 577 |
| 571 return *first; | 578 return *first; |
| 572 } | 579 } |
| 573 | 580 |
| 574 | 581 |
| 575 BUILTIN(ArrayUnshift) { | 582 BUILTIN(ArrayUnshift) { |
| 576 HandleScope scope(isolate); | 583 HandleScope scope(isolate); |
| 577 Heap* heap = isolate->heap(); | 584 Heap* heap = isolate->heap(); |
| 578 Handle<Object> receiver = args.receiver(); | 585 Handle<Object> receiver = args.receiver(); |
| 579 Handle<FixedArrayBase> elms_obj = | 586 MaybeHandle<FixedArrayBase> maybe_elms_obj = |
| 580 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); | 587 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); |
| 581 if (elms_obj.is_null() || | 588 Handle<FixedArrayBase> elms_obj; |
| 589 if (!maybe_elms_obj.ToHandle(&elms_obj) || |
| 582 !IsJSArrayFastElementMovingAllowed(heap, | 590 !IsJSArrayFastElementMovingAllowed(heap, |
| 583 *Handle<JSArray>::cast(receiver))) { | 591 *Handle<JSArray>::cast(receiver))) { |
| 584 return CallJsBuiltin(isolate, "ArrayUnshift", args); | 592 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
| 585 } | 593 } |
| 586 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 594 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 587 ASSERT(!array->map()->is_observed()); | 595 ASSERT(!array->map()->is_observed()); |
| 588 if (!array->HasFastSmiOrObjectElements()) { | 596 if (!array->HasFastSmiOrObjectElements()) { |
| 589 return CallJsBuiltin(isolate, "ArrayUnshift", args); | 597 return CallJsBuiltin(isolate, "ArrayUnshift", args); |
| 590 } | 598 } |
| 591 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); | 599 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 accessor->CopyElements( | 779 accessor->CopyElements( |
| 772 elms, k, kind, handle(result_array->elements(), isolate), 0, result_len); | 780 elms, k, kind, handle(result_array->elements(), isolate), 0, result_len); |
| 773 return *result_array; | 781 return *result_array; |
| 774 } | 782 } |
| 775 | 783 |
| 776 | 784 |
| 777 BUILTIN(ArraySplice) { | 785 BUILTIN(ArraySplice) { |
| 778 HandleScope scope(isolate); | 786 HandleScope scope(isolate); |
| 779 Heap* heap = isolate->heap(); | 787 Heap* heap = isolate->heap(); |
| 780 Handle<Object> receiver = args.receiver(); | 788 Handle<Object> receiver = args.receiver(); |
| 781 Handle<FixedArrayBase> elms_obj = | 789 MaybeHandle<FixedArrayBase> maybe_elms_obj = |
| 782 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3); | 790 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3); |
| 783 if (elms_obj.is_null() || | 791 Handle<FixedArrayBase> elms_obj; |
| 792 if (!maybe_elms_obj.ToHandle(&elms_obj) || |
| 784 !IsJSArrayFastElementMovingAllowed(heap, | 793 !IsJSArrayFastElementMovingAllowed(heap, |
| 785 *Handle<JSArray>::cast(receiver))) { | 794 *Handle<JSArray>::cast(receiver))) { |
| 786 return CallJsBuiltin(isolate, "ArraySplice", args); | 795 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 787 } | 796 } |
| 788 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 797 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 789 ASSERT(!array->map()->is_observed()); | 798 ASSERT(!array->map()->is_observed()); |
| 790 | 799 |
| 791 int len = Smi::cast(array->length())->value(); | 800 int len = Smi::cast(array->length())->value(); |
| 792 | 801 |
| 793 int n_arguments = args.length() - 1; | 802 int n_arguments = args.length() - 1; |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 } | 1744 } |
| 1736 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1745 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1737 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1746 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1738 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1747 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 1739 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1748 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1740 #undef DEFINE_BUILTIN_ACCESSOR_C | 1749 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1741 #undef DEFINE_BUILTIN_ACCESSOR_A | 1750 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1742 | 1751 |
| 1743 | 1752 |
| 1744 } } // namespace v8::internal | 1753 } } // namespace v8::internal |
| OLD | NEW |