| 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 #include "src/builtins.h" | 5 #include "src/builtins.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 BUILTIN(ArraySlice) { | 476 BUILTIN(ArraySlice) { |
| 477 HandleScope scope(isolate); | 477 HandleScope scope(isolate); |
| 478 Handle<Object> receiver = args.receiver(); | 478 Handle<Object> receiver = args.receiver(); |
| 479 Handle<JSObject> object; | 479 Handle<JSObject> object; |
| 480 Handle<FixedArrayBase> elms_obj; | 480 Handle<FixedArrayBase> elms_obj; |
| 481 int len = -1; | 481 int len = -1; |
| 482 int relative_start = 0; | 482 int relative_start = 0; |
| 483 int relative_end = 0; | 483 int relative_end = 0; |
| 484 bool is_sloppy_arguments = false; | 484 bool is_sloppy_arguments = false; |
| 485 | 485 |
| 486 // TODO(littledan): Look up @@species only once, not once here and | |
| 487 // again in the JS builtin. Pass the species out? | |
| 488 Handle<Object> species; | |
| 489 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 490 isolate, species, Object::ArraySpeciesConstructor(isolate, receiver)); | |
| 491 if (*species != isolate->context()->native_context()->array_function()) { | |
| 492 return CallJsIntrinsic(isolate, isolate->array_slice(), args); | |
| 493 } | |
| 494 if (receiver->IsJSArray()) { | 486 if (receiver->IsJSArray()) { |
| 495 DisallowHeapAllocation no_gc; | 487 DisallowHeapAllocation no_gc; |
| 496 JSArray* array = JSArray::cast(*receiver); | 488 JSArray* array = JSArray::cast(*receiver); |
| 497 if (!array->HasFastElements() || | 489 if (!array->HasFastElements() || |
| 498 !IsJSArrayFastElementMovingAllowed(isolate, array)) { | 490 !IsJSArrayFastElementMovingAllowed(isolate, array) || |
| 491 !isolate->IsArraySpeciesLookupChainIntact() || |
| 492 // If this is a subclass of Array, then call out to JS |
| 493 !array->map()->new_target_is_base()) { |
| 499 AllowHeapAllocation allow_allocation; | 494 AllowHeapAllocation allow_allocation; |
| 500 return CallJsIntrinsic(isolate, isolate->array_slice(), args); | 495 return CallJsIntrinsic(isolate, isolate->array_slice(), args); |
| 501 } | 496 } |
| 502 len = Smi::cast(array->length())->value(); | 497 len = Smi::cast(array->length())->value(); |
| 503 object = Handle<JSObject>::cast(receiver); | 498 object = Handle<JSObject>::cast(receiver); |
| 504 elms_obj = handle(array->elements(), isolate); | 499 elms_obj = handle(array->elements(), isolate); |
| 505 } else if (receiver->IsJSObject() && | 500 } else if (receiver->IsJSObject() && |
| 506 GetSloppyArgumentsLength(isolate, Handle<JSObject>::cast(receiver), | 501 GetSloppyArgumentsLength(isolate, Handle<JSObject>::cast(receiver), |
| 507 &len)) { | 502 &len)) { |
| 508 // Array.prototype.slice(arguments, ...) is quite a common idiom | 503 // Array.prototype.slice(arguments, ...) is quite a common idiom |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return *result_array; | 561 return *result_array; |
| 567 } | 562 } |
| 568 | 563 |
| 569 | 564 |
| 570 BUILTIN(ArraySplice) { | 565 BUILTIN(ArraySplice) { |
| 571 HandleScope scope(isolate); | 566 HandleScope scope(isolate); |
| 572 Handle<Object> receiver = args.receiver(); | 567 Handle<Object> receiver = args.receiver(); |
| 573 MaybeHandle<FixedArrayBase> maybe_elms_obj = | 568 MaybeHandle<FixedArrayBase> maybe_elms_obj = |
| 574 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3); | 569 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3); |
| 575 Handle<FixedArrayBase> elms_obj; | 570 Handle<FixedArrayBase> elms_obj; |
| 576 if (!maybe_elms_obj.ToHandle(&elms_obj)) { | 571 if (!maybe_elms_obj.ToHandle(&elms_obj) || |
| 577 return CallJsIntrinsic(isolate, isolate->array_splice(), args); | 572 // If this is a subclass of Array, then call out to JS |
| 578 } | 573 !JSArray::cast(*receiver)->map()->new_target_is_base() || |
| 579 // TODO(littledan): Look up @@species only once, not once here and | 574 // If anything with @@species has been messed with, call out to JS |
| 580 // again in the JS builtin. Pass the species out? | 575 !isolate->IsArraySpeciesLookupChainIntact()) { |
| 581 Handle<Object> species; | |
| 582 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 583 isolate, species, Object::ArraySpeciesConstructor(isolate, receiver)); | |
| 584 if (*species != isolate->context()->native_context()->array_function()) { | |
| 585 return CallJsIntrinsic(isolate, isolate->array_splice(), args); | 576 return CallJsIntrinsic(isolate, isolate->array_splice(), args); |
| 586 } | 577 } |
| 587 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 578 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 588 DCHECK(!array->map()->is_observed()); | 579 DCHECK(!array->map()->is_observed()); |
| 589 | 580 |
| 590 int argument_count = args.length() - 1; | 581 int argument_count = args.length() - 1; |
| 591 int relative_start = 0; | 582 int relative_start = 0; |
| 592 if (argument_count > 0) { | 583 if (argument_count > 0) { |
| 593 DisallowHeapAllocation no_gc; | 584 DisallowHeapAllocation no_gc; |
| 594 if (!ClampedToInteger(args[1], &relative_start)) { | 585 if (!ClampedToInteger(args[1], &relative_start)) { |
| (...skipping 3852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4447 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4438 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 4448 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4439 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4449 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4440 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 4450 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4441 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4451 #undef DEFINE_BUILTIN_ACCESSOR_C | 4442 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 4452 #undef DEFINE_BUILTIN_ACCESSOR_A | 4443 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 4453 | 4444 |
| 4454 | 4445 |
| 4455 } // namespace internal | 4446 } // namespace internal |
| 4456 } // namespace v8 | 4447 } // namespace v8 |
| OLD | NEW |