OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 if (!func->IsCallable()) { | 666 if (!func->IsCallable()) { |
667 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, | 667 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, |
668 func, name, receiver), | 668 func, name, receiver), |
669 Object); | 669 Object); |
670 } | 670 } |
671 return func; | 671 return func; |
672 } | 672 } |
673 | 673 |
674 | 674 |
675 // static | 675 // static |
| 676 MaybeHandle<FixedArray> Object::CreateListFromArrayLike( |
| 677 Isolate* isolate, Handle<Object> object, ElementTypes element_types) { |
| 678 // 1. ReturnIfAbrupt(object). |
| 679 // 2. (default elementTypes -- not applicable.) |
| 680 // 3. If Type(obj) is not Object, throw a TypeError exception. |
| 681 if (!object->IsJSReceiver()) { |
| 682 THROW_NEW_ERROR(isolate, |
| 683 NewTypeError(MessageTemplate::kCalledOnNonObject, |
| 684 isolate->factory()->NewStringFromAsciiChecked( |
| 685 "CreateListFromArrayLike")), |
| 686 FixedArray); |
| 687 } |
| 688 // 4. Let len be ? ToLength(? Get(obj, "length")). |
| 689 Handle<Object> raw_length_obj; |
| 690 ASSIGN_RETURN_ON_EXCEPTION( |
| 691 isolate, raw_length_obj, |
| 692 JSReceiver::GetProperty(object, isolate->factory()->length_string()), |
| 693 FixedArray); |
| 694 Handle<Object> raw_length_number; |
| 695 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number, |
| 696 Object::ToLength(isolate, raw_length_obj), |
| 697 FixedArray); |
| 698 uint32_t len; |
| 699 if (!raw_length_number->ToUint32(&len) || |
| 700 len > static_cast<uint32_t>(FixedArray::kMaxLength)) { |
| 701 THROW_NEW_ERROR(isolate, |
| 702 NewRangeError(MessageTemplate::kInvalidArrayLength), |
| 703 FixedArray); |
| 704 } |
| 705 // 5. Let list be an empty List. |
| 706 Handle<FixedArray> list = isolate->factory()->NewFixedArray(len); |
| 707 // 6. Let index be 0. |
| 708 // 7. Repeat while index < len: |
| 709 for (uint32_t index = 0; index < len; ++index) { |
| 710 // 7a. Let indexName be ToString(index). |
| 711 // 7b. Let next be ? Get(obj, indexName). |
| 712 Handle<Object> next; |
| 713 ASSIGN_RETURN_ON_EXCEPTION( |
| 714 isolate, next, Object::GetElement(isolate, object, index), FixedArray); |
| 715 switch (element_types) { |
| 716 case ElementTypes::kAll: |
| 717 // Nothing to do. |
| 718 break; |
| 719 case ElementTypes::kStringAndSymbol: { |
| 720 // 7c. If Type(next) is not an element of elementTypes, throw a |
| 721 // TypeError exception. |
| 722 if (!next->IsName()) { |
| 723 THROW_NEW_ERROR(isolate, |
| 724 NewTypeError(MessageTemplate::kNotPropertyName, next), |
| 725 FixedArray); |
| 726 } |
| 727 // 7d. Append next as the last element of list. |
| 728 // Internalize on the fly so we can use pointer identity later. |
| 729 next = isolate->factory()->InternalizeName(Handle<Name>::cast(next)); |
| 730 break; |
| 731 } |
| 732 } |
| 733 list->set(index, *next); |
| 734 // 7e. Set index to index + 1. (See loop header.) |
| 735 } |
| 736 // 8. Return list. |
| 737 return list; |
| 738 } |
| 739 |
| 740 |
| 741 // static |
676 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { | 742 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { |
677 for (; it->IsFound(); it->Next()) { | 743 for (; it->IsFound(); it->Next()) { |
678 switch (it->state()) { | 744 switch (it->state()) { |
679 case LookupIterator::NOT_FOUND: | 745 case LookupIterator::NOT_FOUND: |
680 case LookupIterator::TRANSITION: | 746 case LookupIterator::TRANSITION: |
681 UNREACHABLE(); | 747 UNREACHABLE(); |
682 case LookupIterator::JSPROXY: | 748 case LookupIterator::JSPROXY: |
683 // Call the "has" trap on proxies. | 749 // Call the "has" trap on proxies. |
684 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(), | 750 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(), |
685 it->GetName()); | 751 it->GetName()); |
(...skipping 7777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8463 Execution::Call(isolate, isolate->proxy_enumerate(), | 8529 Execution::Call(isolate, isolate->proxy_enumerate(), |
8464 isolate->factory()->undefined_value(), arraysize(args), | 8530 isolate->factory()->undefined_value(), arraysize(args), |
8465 args), | 8531 args), |
8466 Nothing<bool>()); | 8532 Nothing<bool>()); |
8467 accumulator->NextPrototype(); | 8533 accumulator->NextPrototype(); |
8468 accumulator->AddKeysFromProxy(Handle<JSObject>::cast(trap_result_array)); | 8534 accumulator->AddKeysFromProxy(Handle<JSObject>::cast(trap_result_array)); |
8469 return Just(true); | 8535 return Just(true); |
8470 } | 8536 } |
8471 | 8537 |
8472 | 8538 |
8473 // ES6 7.3.17 for elementTypes = (String, Symbol) | |
8474 static MaybeHandle<FixedArray> CreateListFromArrayLike_StringSymbol( | |
8475 Isolate* isolate, Handle<Object> object) { | |
8476 // 1. ReturnIfAbrupt(object). | |
8477 // 2. (default elementTypes -- not applicable.) | |
8478 // 3. If Type(obj) is not Object, throw a TypeError exception. | |
8479 if (!object->IsJSReceiver()) { | |
8480 isolate->Throw(*isolate->factory()->NewTypeError( | |
8481 MessageTemplate::kCalledOnNonObject, | |
8482 isolate->factory()->NewStringFromAsciiChecked( | |
8483 "CreateListFromArrayLike"))); | |
8484 return MaybeHandle<FixedArray>(); | |
8485 } | |
8486 // 4. Let len be ? ToLength(? Get(obj, "length")). | |
8487 Handle<Object> raw_length_obj; | |
8488 ASSIGN_RETURN_ON_EXCEPTION( | |
8489 isolate, raw_length_obj, | |
8490 JSReceiver::GetProperty(object, isolate->factory()->length_string()), | |
8491 FixedArray); | |
8492 Handle<Object> raw_length_number; | |
8493 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number, | |
8494 Object::ToLength(isolate, raw_length_obj), | |
8495 FixedArray); | |
8496 uint32_t len; | |
8497 if (!raw_length_number->ToUint32(&len) || | |
8498 len > static_cast<uint32_t>(FixedArray::kMaxLength)) { | |
8499 isolate->Throw(*isolate->factory()->NewRangeError( | |
8500 MessageTemplate::kInvalidArrayLength)); | |
8501 return MaybeHandle<FixedArray>(); | |
8502 } | |
8503 // 5. Let list be an empty List. | |
8504 Handle<FixedArray> list = isolate->factory()->NewFixedArray(len); | |
8505 // 6. Let index be 0. | |
8506 // 7. Repeat while index < len: | |
8507 for (uint32_t index = 0; index < len; ++index) { | |
8508 // 7a. Let indexName be ToString(index). | |
8509 // 7b. Let next be ? Get(obj, indexName). | |
8510 Handle<Object> next; | |
8511 ASSIGN_RETURN_ON_EXCEPTION( | |
8512 isolate, next, Object::GetElement(isolate, object, index), FixedArray); | |
8513 // 7c. If Type(next) is not an element of elementTypes, throw a | |
8514 // TypeError exception. | |
8515 if (!next->IsName()) { | |
8516 isolate->Throw(*isolate->factory()->NewTypeError( | |
8517 MessageTemplate::kNotPropertyName, next)); | |
8518 return MaybeHandle<FixedArray>(); | |
8519 } | |
8520 // 7d. Append next as the last element of list. | |
8521 // Internalize on the fly so we can use pointer identity later. | |
8522 next = isolate->factory()->InternalizeName(Handle<Name>::cast(next)); | |
8523 list->set(index, *next); | |
8524 // 7e. Set index to index + 1. (See loop header.) | |
8525 } | |
8526 // 8. Return list. | |
8527 return list; | |
8528 } | |
8529 | |
8530 | |
8531 // ES6 9.5.12 | 8539 // ES6 9.5.12 |
8532 // Returns |true| on success, |nothing| in case of exception. | 8540 // Returns |true| on success, |nothing| in case of exception. |
8533 // static | 8541 // static |
8534 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, | 8542 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, |
8535 Handle<JSReceiver> receiver, | 8543 Handle<JSReceiver> receiver, |
8536 Handle<JSProxy> proxy, | 8544 Handle<JSProxy> proxy, |
8537 PropertyFilter filter, | 8545 PropertyFilter filter, |
8538 KeyAccumulator* accumulator) { | 8546 KeyAccumulator* accumulator) { |
8539 STACK_CHECK(Nothing<bool>()); | 8547 STACK_CHECK(Nothing<bool>()); |
8540 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 8548 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
(...skipping 24 matching lines...) Expand all Loading... |
8565 Handle<Object> args[] = {target}; | 8573 Handle<Object> args[] = {target}; |
8566 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 8574 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
8567 isolate, trap_result_array, | 8575 isolate, trap_result_array, |
8568 Execution::Call(isolate, trap, handler, arraysize(args), args), | 8576 Execution::Call(isolate, trap, handler, arraysize(args), args), |
8569 Nothing<bool>()); | 8577 Nothing<bool>()); |
8570 // 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, | 8578 // 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, |
8571 // «String, Symbol»). | 8579 // «String, Symbol»). |
8572 Handle<FixedArray> trap_result; | 8580 Handle<FixedArray> trap_result; |
8573 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 8581 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
8574 isolate, trap_result, | 8582 isolate, trap_result, |
8575 CreateListFromArrayLike_StringSymbol(isolate, trap_result_array), | 8583 Object::CreateListFromArrayLike(isolate, trap_result_array, |
| 8584 ElementTypes::kStringAndSymbol), |
8576 Nothing<bool>()); | 8585 Nothing<bool>()); |
8577 // 9. Let extensibleTarget be ? IsExtensible(target). | 8586 // 9. Let extensibleTarget be ? IsExtensible(target). |
8578 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); | 8587 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); |
8579 MAYBE_RETURN(maybe_extensible, Nothing<bool>()); | 8588 MAYBE_RETURN(maybe_extensible, Nothing<bool>()); |
8580 bool extensible_target = maybe_extensible.FromJust(); | 8589 bool extensible_target = maybe_extensible.FromJust(); |
8581 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). | 8590 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). |
8582 Handle<FixedArray> target_keys; | 8591 Handle<FixedArray> target_keys; |
8583 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys, | 8592 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys, |
8584 JSReceiver::OwnPropertyKeys(target), | 8593 JSReceiver::OwnPropertyKeys(target), |
8585 Nothing<bool>()); | 8594 Nothing<bool>()); |
(...skipping 10770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19356 if (cell->value() != *new_value) { | 19365 if (cell->value() != *new_value) { |
19357 cell->set_value(*new_value); | 19366 cell->set_value(*new_value); |
19358 Isolate* isolate = cell->GetIsolate(); | 19367 Isolate* isolate = cell->GetIsolate(); |
19359 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19368 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19360 isolate, DependentCode::kPropertyCellChangedGroup); | 19369 isolate, DependentCode::kPropertyCellChangedGroup); |
19361 } | 19370 } |
19362 } | 19371 } |
19363 | 19372 |
19364 } // namespace internal | 19373 } // namespace internal |
19365 } // namespace v8 | 19374 } // namespace v8 |
OLD | NEW |