| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 ? index < static_cast<uint32_t>(String::cast(*object)->length()) | 413 ? index < static_cast<uint32_t>(String::cast(*object)->length()) |
| 414 : key->Equals(isolate->heap()->length_string())); | 414 : key->Equals(isolate->heap()->length_string())); |
| 415 } else if (object->IsNull() || object->IsUndefined()) { | 415 } else if (object->IsNull() || object->IsUndefined()) { |
| 416 THROW_NEW_ERROR_RETURN_FAILURE( | 416 THROW_NEW_ERROR_RETURN_FAILURE( |
| 417 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); | 417 isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject)); |
| 418 } | 418 } |
| 419 | 419 |
| 420 return isolate->heap()->false_value(); | 420 return isolate->heap()->false_value(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 BUILTIN(ArrayPush) { | 423 namespace { |
| 424 |
| 425 Object* DoArrayPush(Isolate* isolate, |
| 426 BuiltinArguments<BuiltinExtraArguments::kNone> args) { |
| 424 HandleScope scope(isolate); | 427 HandleScope scope(isolate); |
| 425 Handle<Object> receiver = args.receiver(); | 428 Handle<Object> receiver = args.receiver(); |
| 426 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1)) { | 429 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1)) { |
| 427 return CallJsIntrinsic(isolate, isolate->array_push(), args); | 430 return CallJsIntrinsic(isolate, isolate->array_push(), args); |
| 428 } | 431 } |
| 429 // Fast Elements Path | 432 // Fast Elements Path |
| 430 int to_add = args.length() - 1; | 433 int to_add = args.length() - 1; |
| 431 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 434 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 432 int len = Smi::cast(array->length())->value(); | 435 int len = Smi::cast(array->length())->value(); |
| 433 if (to_add == 0) return Smi::FromInt(len); | 436 if (to_add == 0) return Smi::FromInt(len); |
| 434 | 437 |
| 435 // Currently fixed arrays cannot grow too big, so we should never hit this. | 438 // Currently fixed arrays cannot grow too big, so we should never hit this. |
| 436 DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); | 439 DCHECK_LE(to_add, Smi::kMaxValue - Smi::cast(array->length())->value()); |
| 437 | 440 |
| 438 if (JSArray::HasReadOnlyLength(array)) { | 441 if (JSArray::HasReadOnlyLength(array)) { |
| 439 return CallJsIntrinsic(isolate, isolate->array_push(), args); | 442 return CallJsIntrinsic(isolate, isolate->array_push(), args); |
| 440 } | 443 } |
| 441 | 444 |
| 442 ElementsAccessor* accessor = array->GetElementsAccessor(); | 445 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 443 int new_length = accessor->Push(array, &args, to_add); | 446 int new_length = accessor->Push(array, &args, to_add); |
| 444 return Smi::FromInt(new_length); | 447 return Smi::FromInt(new_length); |
| 445 } | 448 } |
| 446 | 449 |
| 450 } // namespace |
| 451 |
| 452 BUILTIN(ArrayPush) { return DoArrayPush(isolate, args); } |
| 453 |
| 454 // TODO(verwaest): This is a temporary helper until the FastArrayPush stub can |
| 455 // tailcall to the builtin directly. |
| 456 RUNTIME_FUNCTION(Runtime_ArrayPush) { |
| 457 DCHECK_EQ(2, args.length()); |
| 458 Arguments* incoming = reinterpret_cast<Arguments*>(args[0]); |
| 459 // Rewrap the arguments as builtins arguments. |
| 460 BuiltinArguments<BuiltinExtraArguments::kNone> caller_args( |
| 461 incoming->length() + 1, incoming->arguments() + 1); |
| 462 return DoArrayPush(isolate, caller_args); |
| 463 } |
| 447 | 464 |
| 448 BUILTIN(ArrayPop) { | 465 BUILTIN(ArrayPop) { |
| 449 HandleScope scope(isolate); | 466 HandleScope scope(isolate); |
| 450 Handle<Object> receiver = args.receiver(); | 467 Handle<Object> receiver = args.receiver(); |
| 451 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, nullptr, 0)) { | 468 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, nullptr, 0)) { |
| 452 return CallJsIntrinsic(isolate, isolate->array_pop(), args); | 469 return CallJsIntrinsic(isolate, isolate->array_pop(), args); |
| 453 } | 470 } |
| 454 | 471 |
| 455 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 472 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 456 DCHECK(!array->map()->is_observed()); | 473 DCHECK(!array->map()->is_observed()); |
| (...skipping 4058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4515 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4532 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 4516 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4533 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4517 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4534 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 4518 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4535 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4519 #undef DEFINE_BUILTIN_ACCESSOR_C | 4536 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 4520 #undef DEFINE_BUILTIN_ACCESSOR_A | 4537 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 4521 | 4538 |
| 4522 | 4539 |
| 4523 } // namespace internal | 4540 } // namespace internal |
| 4524 } // namespace v8 | 4541 } // namespace v8 |
| OLD | NEW |