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-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/api-natives.h" | 9 #include "src/api-natives.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 ? index < static_cast<uint32_t>(String::cast(*object)->length()) | 435 ? index < static_cast<uint32_t>(String::cast(*object)->length()) |
436 : key->Equals(isolate->heap()->length_string())); | 436 : key->Equals(isolate->heap()->length_string())); |
437 } else if (object->IsNull() || object->IsUndefined()) { | 437 } else if (object->IsNull() || object->IsUndefined()) { |
438 THROW_NEW_ERROR_RETURN_FAILURE( | 438 THROW_NEW_ERROR_RETURN_FAILURE( |
439 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); | 439 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
440 } | 440 } |
441 | 441 |
442 return isolate->heap()->false_value(); | 442 return isolate->heap()->false_value(); |
443 } | 443 } |
444 | 444 |
445 BUILTIN(ArrayPush) { | 445 namespace { |
| 446 |
| 447 Object* DoArrayPush(Isolate* isolate, |
| 448 BuiltinArguments<BuiltinExtraArguments::kNone> args) { |
446 HandleScope scope(isolate); | 449 HandleScope scope(isolate); |
447 Handle<Object> receiver = args.receiver(); | 450 Handle<Object> receiver = args.receiver(); |
448 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1)) { | 451 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1)) { |
449 return CallJsIntrinsic(isolate, isolate->array_push(), args); | 452 return CallJsIntrinsic(isolate, isolate->array_push(), args); |
450 } | 453 } |
451 // Fast Elements Path | 454 // Fast Elements Path |
452 int to_add = args.length() - 1; | 455 int to_add = args.length() - 1; |
453 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 456 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
454 int len = Smi::cast(array->length())->value(); | 457 int len = Smi::cast(array->length())->value(); |
455 if (to_add == 0) return Smi::FromInt(len); | 458 if (to_add == 0) return Smi::FromInt(len); |
456 | 459 |
457 // Currently fixed arrays cannot grow too big, so we should never hit this. | 460 // Currently fixed arrays cannot grow too big, so we should never hit this. |
458 DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); | 461 DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); |
459 | 462 |
460 if (JSArray::HasReadOnlyLength(array)) { | 463 if (JSArray::HasReadOnlyLength(array)) { |
461 return CallJsIntrinsic(isolate, isolate->array_push(), args); | 464 return CallJsIntrinsic(isolate, isolate->array_push(), args); |
462 } | 465 } |
463 | 466 |
464 ElementsAccessor* accessor = array->GetElementsAccessor(); | 467 ElementsAccessor* accessor = array->GetElementsAccessor(); |
465 int new_length = accessor->Push(array, &args, to_add); | 468 int new_length = accessor->Push(array, &args, to_add); |
466 return Smi::FromInt(new_length); | 469 return Smi::FromInt(new_length); |
467 } | 470 } |
468 | 471 |
| 472 } // namespace |
| 473 |
| 474 BUILTIN(ArrayPush) { return DoArrayPush(isolate, args); } |
| 475 |
| 476 // TODO(verwaest): This is a temporary helper until the FastArrayPush stub can |
| 477 // tailcall to the builtin directly. |
| 478 RUNTIME_FUNCTION(Runtime_ArrayPush) { |
| 479 DCHECK_EQ(2, args.length()); |
| 480 Arguments* incoming = reinterpret_cast<Arguments*>(args[0]); |
| 481 // Rewrap the arguments as builtins arguments. |
| 482 BuiltinArguments<BuiltinExtraArguments::kNone> caller_args( |
| 483 incoming->length() + 1, incoming->arguments() + 1); |
| 484 return DoArrayPush(isolate, caller_args); |
| 485 } |
469 | 486 |
470 BUILTIN(ArrayPop) { | 487 BUILTIN(ArrayPop) { |
471 HandleScope scope(isolate); | 488 HandleScope scope(isolate); |
472 Handle<Object> receiver = args.receiver(); | 489 Handle<Object> receiver = args.receiver(); |
473 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, nullptr, 0)) { | 490 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, nullptr, 0)) { |
474 return CallJsIntrinsic(isolate, isolate->array_pop(), args); | 491 return CallJsIntrinsic(isolate, isolate->array_pop(), args); |
475 } | 492 } |
476 | 493 |
477 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 494 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
478 DCHECK(!array->map()->is_observed()); | 495 DCHECK(!array->map()->is_observed()); |
(...skipping 4067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4546 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4563 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4547 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4564 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4548 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4565 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4549 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4566 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4550 #undef DEFINE_BUILTIN_ACCESSOR_C | 4567 #undef DEFINE_BUILTIN_ACCESSOR_C |
4551 #undef DEFINE_BUILTIN_ACCESSOR_A | 4568 #undef DEFINE_BUILTIN_ACCESSOR_A |
4552 | 4569 |
4553 | 4570 |
4554 } // namespace internal | 4571 } // namespace internal |
4555 } // namespace v8 | 4572 } // namespace v8 |
OLD | NEW |