Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/objects.cc

Issue 1523753002: [es6] Correct Function.prototype.apply, Reflect.construct and Reflect.apply. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: arm port. Small improvements. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if (!func->IsCallable()) { 668 if (!func->IsCallable()) {
669 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, 669 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction,
670 func, name, receiver), 670 func, name, receiver),
671 Object); 671 Object);
672 } 672 }
673 return func; 673 return func;
674 } 674 }
675 675
676 676
677 // static 677 // static
678 MaybeHandle<FixedArray> Object::CreateListFromArrayLike(
679 Isolate* isolate, Handle<Object> object, ElementTypes element_types) {
680 // 1. ReturnIfAbrupt(object).
681 // 2. (default elementTypes -- not applicable.)
682 // 3. If Type(obj) is not Object, throw a TypeError exception.
683 if (!object->IsJSReceiver()) {
684 THROW_NEW_ERROR(isolate,
685 NewTypeError(MessageTemplate::kCalledOnNonObject,
686 isolate->factory()->NewStringFromAsciiChecked(
687 "CreateListFromArrayLike")),
688 FixedArray);
689 }
690 // 4. Let len be ? ToLength(? Get(obj, "length")).
691 Handle<Object> raw_length_obj;
692 ASSIGN_RETURN_ON_EXCEPTION(
693 isolate, raw_length_obj,
694 JSReceiver::GetProperty(object, isolate->factory()->length_string()),
695 FixedArray);
696 Handle<Object> raw_length_number;
697 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number,
698 Object::ToLength(isolate, raw_length_obj),
699 FixedArray);
700 uint32_t len;
701 if (!raw_length_number->ToUint32(&len) ||
702 len > static_cast<uint32_t>(FixedArray::kMaxLength)) {
703 THROW_NEW_ERROR(isolate,
704 NewRangeError(MessageTemplate::kInvalidArrayLength),
705 FixedArray);
706 }
707 // 5. Let list be an empty List.
708 Handle<FixedArray> list = isolate->factory()->NewFixedArray(len);
709 // 6. Let index be 0.
710 // 7. Repeat while index < len:
711 for (uint32_t index = 0; index < len; ++index) {
712 // 7a. Let indexName be ToString(index).
713 // 7b. Let next be ? Get(obj, indexName).
714 Handle<Object> next;
715 ASSIGN_RETURN_ON_EXCEPTION(
716 isolate, next, Object::GetElement(isolate, object, index), FixedArray);
717 switch (element_types) {
718 case ElementTypes::kAll:
719 // Nothing to do.
720 break;
721 case ElementTypes::kStringAndSymbol: {
722 // 7c. If Type(next) is not an element of elementTypes, throw a
723 // TypeError exception.
724 if (!next->IsName()) {
725 THROW_NEW_ERROR(isolate,
726 NewTypeError(MessageTemplate::kNotPropertyName, next),
727 FixedArray);
728 }
729 // 7d. Append next as the last element of list.
730 // Internalize on the fly so we can use pointer identity later.
731 next = isolate->factory()->InternalizeName(Handle<Name>::cast(next));
732 break;
733 }
734 }
735 list->set(index, *next);
736 // 7e. Set index to index + 1. (See loop header.)
737 }
738 // 8. Return list.
739 return list;
740 }
741
742
743 // static
678 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) { 744 Maybe<bool> JSReceiver::HasProperty(LookupIterator* it) {
679 for (; it->IsFound(); it->Next()) { 745 for (; it->IsFound(); it->Next()) {
680 switch (it->state()) { 746 switch (it->state()) {
681 case LookupIterator::NOT_FOUND: 747 case LookupIterator::NOT_FOUND:
682 case LookupIterator::TRANSITION: 748 case LookupIterator::TRANSITION:
683 UNREACHABLE(); 749 UNREACHABLE();
684 case LookupIterator::JSPROXY: 750 case LookupIterator::JSPROXY:
685 // Call the "has" trap on proxies. 751 // Call the "has" trap on proxies.
686 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(), 752 return JSProxy::HasProperty(it->isolate(), it->GetHolder<JSProxy>(),
687 it->GetName()); 753 it->GetName());
(...skipping 7737 matching lines...) Expand 10 before | Expand all | Expand 10 after
8425 Execution::Call(isolate, isolate->proxy_enumerate(), 8491 Execution::Call(isolate, isolate->proxy_enumerate(),
8426 isolate->factory()->undefined_value(), arraysize(args), 8492 isolate->factory()->undefined_value(), arraysize(args),
8427 args), 8493 args),
8428 Nothing<bool>()); 8494 Nothing<bool>());
8429 accumulator->NextPrototype(); 8495 accumulator->NextPrototype();
8430 accumulator->AddKeysFromProxy(Handle<JSObject>::cast(trap_result_array)); 8496 accumulator->AddKeysFromProxy(Handle<JSObject>::cast(trap_result_array));
8431 return Just(true); 8497 return Just(true);
8432 } 8498 }
8433 8499
8434 8500
8435 // ES6 7.3.17 for elementTypes = (String, Symbol)
8436 static MaybeHandle<FixedArray> CreateListFromArrayLike_StringSymbol(
8437 Isolate* isolate, Handle<Object> object) {
8438 // 1. ReturnIfAbrupt(object).
8439 // 2. (default elementTypes -- not applicable.)
8440 // 3. If Type(obj) is not Object, throw a TypeError exception.
8441 if (!object->IsJSReceiver()) {
8442 isolate->Throw(*isolate->factory()->NewTypeError(
8443 MessageTemplate::kCalledOnNonObject,
8444 isolate->factory()->NewStringFromAsciiChecked(
8445 "CreateListFromArrayLike")));
8446 return MaybeHandle<FixedArray>();
8447 }
8448 // 4. Let len be ? ToLength(? Get(obj, "length")).
8449 Handle<Object> raw_length_obj;
8450 ASSIGN_RETURN_ON_EXCEPTION(
8451 isolate, raw_length_obj,
8452 JSReceiver::GetProperty(object, isolate->factory()->length_string()),
8453 FixedArray);
8454 Handle<Object> raw_length_number;
8455 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number,
8456 Object::ToLength(isolate, raw_length_obj),
8457 FixedArray);
8458 uint32_t len;
8459 if (!raw_length_number->ToUint32(&len) ||
8460 len > static_cast<uint32_t>(FixedArray::kMaxLength)) {
8461 isolate->Throw(*isolate->factory()->NewRangeError(
8462 MessageTemplate::kInvalidArrayLength));
8463 return MaybeHandle<FixedArray>();
8464 }
8465 // 5. Let list be an empty List.
8466 Handle<FixedArray> list = isolate->factory()->NewFixedArray(len);
8467 // 6. Let index be 0.
8468 // 7. Repeat while index < len:
8469 for (uint32_t index = 0; index < len; ++index) {
8470 // 7a. Let indexName be ToString(index).
8471 // 7b. Let next be ? Get(obj, indexName).
8472 Handle<Object> next;
8473 ASSIGN_RETURN_ON_EXCEPTION(
8474 isolate, next, Object::GetElement(isolate, object, index), FixedArray);
8475 // 7c. If Type(next) is not an element of elementTypes, throw a
8476 // TypeError exception.
8477 if (!next->IsName()) {
8478 isolate->Throw(*isolate->factory()->NewTypeError(
8479 MessageTemplate::kNotPropertyName, next));
8480 return MaybeHandle<FixedArray>();
8481 }
8482 // 7d. Append next as the last element of list.
8483 // Internalize on the fly so we can use pointer identity later.
8484 next = isolate->factory()->InternalizeName(Handle<Name>::cast(next));
8485 list->set(index, *next);
8486 // 7e. Set index to index + 1. (See loop header.)
8487 }
8488 // 8. Return list.
8489 return list;
8490 }
8491
8492
8493 // ES6 9.5.12 8501 // ES6 9.5.12
8494 // Returns |true| on success, |nothing| in case of exception. 8502 // Returns |true| on success, |nothing| in case of exception.
8495 // static 8503 // static
8496 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate, 8504 Maybe<bool> JSProxy::OwnPropertyKeys(Isolate* isolate,
8497 Handle<JSReceiver> receiver, 8505 Handle<JSReceiver> receiver,
8498 Handle<JSProxy> proxy, 8506 Handle<JSProxy> proxy,
8499 PropertyFilter filter, 8507 PropertyFilter filter,
8500 KeyAccumulator* accumulator) { 8508 KeyAccumulator* accumulator) {
8501 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. 8509 // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
8502 Handle<Object> handler(proxy->handler(), isolate); 8510 Handle<Object> handler(proxy->handler(), isolate);
(...skipping 23 matching lines...) Expand all
8526 Handle<Object> args[] = {target}; 8534 Handle<Object> args[] = {target};
8527 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8535 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8528 isolate, trap_result_array, 8536 isolate, trap_result_array,
8529 Execution::Call(isolate, trap, handler, arraysize(args), args), 8537 Execution::Call(isolate, trap, handler, arraysize(args), args),
8530 Nothing<bool>()); 8538 Nothing<bool>());
8531 // 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, 8539 // 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray,
8532 // «String, Symbol»). 8540 // «String, Symbol»).
8533 Handle<FixedArray> trap_result; 8541 Handle<FixedArray> trap_result;
8534 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8542 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8535 isolate, trap_result, 8543 isolate, trap_result,
8536 CreateListFromArrayLike_StringSymbol(isolate, trap_result_array), 8544 Object::CreateListFromArrayLike(isolate, trap_result_array,
8545 ElementTypes::kStringAndSymbol),
8537 Nothing<bool>()); 8546 Nothing<bool>());
8538 // 9. Let extensibleTarget be ? IsExtensible(target). 8547 // 9. Let extensibleTarget be ? IsExtensible(target).
8539 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); 8548 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target);
8540 MAYBE_RETURN(maybe_extensible, Nothing<bool>()); 8549 MAYBE_RETURN(maybe_extensible, Nothing<bool>());
8541 bool extensible_target = maybe_extensible.FromJust(); 8550 bool extensible_target = maybe_extensible.FromJust();
8542 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). 8551 // 10. Let targetKeys be ? target.[[OwnPropertyKeys]]().
8543 Handle<FixedArray> target_keys; 8552 Handle<FixedArray> target_keys;
8544 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys, 8553 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, target_keys,
8545 JSReceiver::OwnPropertyKeys(target), 8554 JSReceiver::OwnPropertyKeys(target),
8546 Nothing<bool>()); 8555 Nothing<bool>());
(...skipping 10765 matching lines...) Expand 10 before | Expand all | Expand 10 after
19312 if (cell->value() != *new_value) { 19321 if (cell->value() != *new_value) {
19313 cell->set_value(*new_value); 19322 cell->set_value(*new_value);
19314 Isolate* isolate = cell->GetIsolate(); 19323 Isolate* isolate = cell->GetIsolate();
19315 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19324 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19316 isolate, DependentCode::kPropertyCellChangedGroup); 19325 isolate, DependentCode::kPropertyCellChangedGroup);
19317 } 19326 }
19318 } 19327 }
19319 19328
19320 } // namespace internal 19329 } // namespace internal
19321 } // namespace v8 19330 } // namespace v8
OLDNEW
« src/bootstrapper.cc ('K') | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698