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

Side by Side Diff: src/objects.cc

Issue 1775973002: Add GetProperty/GetElement to JSReceiver and use it where possible (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // 2. (default elementTypes -- not applicable.) 609 // 2. (default elementTypes -- not applicable.)
610 // 3. If Type(obj) is not Object, throw a TypeError exception. 610 // 3. If Type(obj) is not Object, throw a TypeError exception.
611 if (!object->IsJSReceiver()) { 611 if (!object->IsJSReceiver()) {
612 THROW_NEW_ERROR(isolate, 612 THROW_NEW_ERROR(isolate,
613 NewTypeError(MessageTemplate::kCalledOnNonObject, 613 NewTypeError(MessageTemplate::kCalledOnNonObject,
614 isolate->factory()->NewStringFromAsciiChecked( 614 isolate->factory()->NewStringFromAsciiChecked(
615 "CreateListFromArrayLike")), 615 "CreateListFromArrayLike")),
616 FixedArray); 616 FixedArray);
617 } 617 }
618 // 4. Let len be ? ToLength(? Get(obj, "length")). 618 // 4. Let len be ? ToLength(? Get(obj, "length")).
619 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
619 Handle<Object> raw_length_obj; 620 Handle<Object> raw_length_obj;
620 ASSIGN_RETURN_ON_EXCEPTION( 621 ASSIGN_RETURN_ON_EXCEPTION(
621 isolate, raw_length_obj, 622 isolate, raw_length_obj,
622 JSReceiver::GetProperty(object, isolate->factory()->length_string()), 623 JSReceiver::GetProperty(receiver, isolate->factory()->length_string()),
623 FixedArray); 624 FixedArray);
624 Handle<Object> raw_length_number; 625 Handle<Object> raw_length_number;
625 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number, 626 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number,
626 Object::ToLength(isolate, raw_length_obj), 627 Object::ToLength(isolate, raw_length_obj),
627 FixedArray); 628 FixedArray);
628 uint32_t len; 629 uint32_t len;
629 if (!raw_length_number->ToUint32(&len) || 630 if (!raw_length_number->ToUint32(&len) ||
630 len > static_cast<uint32_t>(FixedArray::kMaxLength)) { 631 len > static_cast<uint32_t>(FixedArray::kMaxLength)) {
631 THROW_NEW_ERROR(isolate, 632 THROW_NEW_ERROR(isolate,
632 NewRangeError(MessageTemplate::kInvalidArrayLength), 633 NewRangeError(MessageTemplate::kInvalidArrayLength),
633 FixedArray); 634 FixedArray);
634 } 635 }
635 // 5. Let list be an empty List. 636 // 5. Let list be an empty List.
636 Handle<FixedArray> list = isolate->factory()->NewFixedArray(len); 637 Handle<FixedArray> list = isolate->factory()->NewFixedArray(len);
637 // 6. Let index be 0. 638 // 6. Let index be 0.
638 // 7. Repeat while index < len: 639 // 7. Repeat while index < len:
639 for (uint32_t index = 0; index < len; ++index) { 640 for (uint32_t index = 0; index < len; ++index) {
640 // 7a. Let indexName be ToString(index). 641 // 7a. Let indexName be ToString(index).
641 // 7b. Let next be ? Get(obj, indexName). 642 // 7b. Let next be ? Get(obj, indexName).
642 Handle<Object> next; 643 Handle<Object> next;
643 ASSIGN_RETURN_ON_EXCEPTION( 644 ASSIGN_RETURN_ON_EXCEPTION(isolate, next,
644 isolate, next, Object::GetElement(isolate, object, index), FixedArray); 645 JSReceiver::GetElement(isolate, receiver, index),
646 FixedArray);
645 switch (element_types) { 647 switch (element_types) {
646 case ElementTypes::kAll: 648 case ElementTypes::kAll:
647 // Nothing to do. 649 // Nothing to do.
648 break; 650 break;
649 case ElementTypes::kStringAndSymbol: { 651 case ElementTypes::kStringAndSymbol: {
650 // 7c. If Type(next) is not an element of elementTypes, throw a 652 // 7c. If Type(next) is not an element of elementTypes, throw a
651 // TypeError exception. 653 // TypeError exception.
652 if (!next->IsName()) { 654 if (!next->IsName()) {
653 THROW_NEW_ERROR(isolate, 655 THROW_NEW_ERROR(isolate,
654 NewTypeError(MessageTemplate::kNotPropertyName, next), 656 NewTypeError(MessageTemplate::kNotPropertyName, next),
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 JSReceiver::GetFunctionRealm(Handle<JSReceiver>::cast(constructor)), 1550 JSReceiver::GetFunctionRealm(Handle<JSReceiver>::cast(constructor)),
1549 Object); 1551 Object);
1550 if (*constructor_context != *native_context && 1552 if (*constructor_context != *native_context &&
1551 *constructor == constructor_context->array_function()) { 1553 *constructor == constructor_context->array_function()) {
1552 constructor = isolate->factory()->undefined_value(); 1554 constructor = isolate->factory()->undefined_value();
1553 } 1555 }
1554 } 1556 }
1555 if (constructor->IsJSReceiver()) { 1557 if (constructor->IsJSReceiver()) {
1556 ASSIGN_RETURN_ON_EXCEPTION( 1558 ASSIGN_RETURN_ON_EXCEPTION(
1557 isolate, constructor, 1559 isolate, constructor,
1558 Object::GetProperty(constructor, 1560 JSReceiver::GetProperty(Handle<JSReceiver>::cast(constructor),
1559 isolate->factory()->species_symbol()), 1561 isolate->factory()->species_symbol()),
1560 Object); 1562 Object);
1561 if (constructor->IsNull()) { 1563 if (constructor->IsNull()) {
1562 constructor = isolate->factory()->undefined_value(); 1564 constructor = isolate->factory()->undefined_value();
1563 } 1565 }
1564 } 1566 }
1565 } 1567 }
1566 if (constructor->IsUndefined()) { 1568 if (constructor->IsUndefined()) {
1567 return default_species; 1569 return default_species;
1568 } else { 1570 } else {
1569 if (!constructor->IsConstructor()) { 1571 if (!constructor->IsConstructor()) {
(...skipping 5593 matching lines...) Expand 10 before | Expand all | Expand 10 after
7163 7165
7164 // 3. Let D be a newly created Property Descriptor with no fields. 7166 // 3. Let D be a newly created Property Descriptor with no fields.
7165 DCHECK(desc->is_empty()); 7167 DCHECK(desc->is_empty());
7166 // 4. Let X be O's own property whose key is P. 7168 // 4. Let X be O's own property whose key is P.
7167 // 5. If X is a data property, then 7169 // 5. If X is a data property, then
7168 bool is_accessor_pair = it->state() == LookupIterator::ACCESSOR && 7170 bool is_accessor_pair = it->state() == LookupIterator::ACCESSOR &&
7169 it->GetAccessors()->IsAccessorPair(); 7171 it->GetAccessors()->IsAccessorPair();
7170 if (!is_accessor_pair) { 7172 if (!is_accessor_pair) {
7171 // 5a. Set D.[[Value]] to the value of X's [[Value]] attribute. 7173 // 5a. Set D.[[Value]] to the value of X's [[Value]] attribute.
7172 Handle<Object> value; 7174 Handle<Object> value;
7173 if (!JSObject::GetProperty(it).ToHandle(&value)) { 7175 if (!Object::GetProperty(it).ToHandle(&value)) {
7174 DCHECK(isolate->has_pending_exception()); 7176 DCHECK(isolate->has_pending_exception());
7175 return Nothing<bool>(); 7177 return Nothing<bool>();
7176 } 7178 }
7177 desc->set_value(value); 7179 desc->set_value(value);
7178 // 5b. Set D.[[Writable]] to the value of X's [[Writable]] attribute 7180 // 5b. Set D.[[Writable]] to the value of X's [[Writable]] attribute
7179 desc->set_writable((attrs & READ_ONLY) == 0); 7181 desc->set_writable((attrs & READ_ONLY) == 0);
7180 } else { 7182 } else {
7181 // 6. Else X is an accessor property, so 7183 // 6. Else X is an accessor property, so
7182 Handle<AccessorPair> accessors = 7184 Handle<AccessorPair> accessors =
7183 Handle<AccessorPair>::cast(it->GetAccessors()); 7185 Handle<AccessorPair>::cast(it->GetAccessors());
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
8030 PropertyFilter filter = static_cast<PropertyFilter>( 8032 PropertyFilter filter = static_cast<PropertyFilter>(
8031 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE); 8033 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE);
8032 KeyAccumulator accumulator(isolate, OWN_ONLY, filter); 8034 KeyAccumulator accumulator(isolate, OWN_ONLY, filter);
8033 accumulator.NextPrototype(); 8035 accumulator.NextPrototype();
8034 copy->CollectOwnPropertyNames(&accumulator, filter); 8036 copy->CollectOwnPropertyNames(&accumulator, filter);
8035 Handle<FixedArray> names = accumulator.GetKeys(); 8037 Handle<FixedArray> names = accumulator.GetKeys();
8036 for (int i = 0; i < names->length(); i++) { 8038 for (int i = 0; i < names->length(); i++) {
8037 DCHECK(names->get(i)->IsName()); 8039 DCHECK(names->get(i)->IsName());
8038 Handle<Name> name(Name::cast(names->get(i))); 8040 Handle<Name> name(Name::cast(names->get(i)));
8039 Handle<Object> value = 8041 Handle<Object> value =
8040 Object::GetProperty(copy, name).ToHandleChecked(); 8042 JSObject::GetProperty(copy, name).ToHandleChecked();
8041 if (value->IsJSObject()) { 8043 if (value->IsJSObject()) {
8042 Handle<JSObject> result; 8044 Handle<JSObject> result;
8043 ASSIGN_RETURN_ON_EXCEPTION( 8045 ASSIGN_RETURN_ON_EXCEPTION(
8044 isolate, result, 8046 isolate, result,
8045 VisitElementOrProperty(copy, Handle<JSObject>::cast(value)), 8047 VisitElementOrProperty(copy, Handle<JSObject>::cast(value)),
8046 JSObject); 8048 JSObject);
8047 if (copying) { 8049 if (copying) {
8048 // Creating object copy for literals. No strict mode needed. 8050 // Creating object copy for literals. No strict mode needed.
8049 JSObject::SetProperty(copy, name, result, SLOPPY).Assert(); 8051 JSObject::SetProperty(copy, name, result, SLOPPY).Assert();
8050 } 8052 }
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
8811 if (details.kind() == kData) { 8813 if (details.kind() == kData) {
8812 if (details.location() == kDescriptor) { 8814 if (details.location() == kDescriptor) {
8813 prop_value = handle(descriptors->GetValue(index), isolate); 8815 prop_value = handle(descriptors->GetValue(index), isolate);
8814 } else { 8816 } else {
8815 Representation representation = details.representation(); 8817 Representation representation = details.representation();
8816 FieldIndex field_index = FieldIndex::ForDescriptor(*map, index); 8818 FieldIndex field_index = FieldIndex::ForDescriptor(*map, index);
8817 prop_value = 8819 prop_value =
8818 JSObject::FastPropertyAt(object, representation, field_index); 8820 JSObject::FastPropertyAt(object, representation, field_index);
8819 } 8821 }
8820 } else { 8822 } else {
8821 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, prop_value, 8823 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8822 Object::GetProperty(object, next_key), 8824 isolate, prop_value, JSReceiver::GetProperty(object, next_key),
8823 Nothing<bool>()); 8825 Nothing<bool>());
8824 stable = object->map() == *map; 8826 stable = object->map() == *map;
8825 } 8827 }
8826 } else { 8828 } else {
8827 // If the map did change, do a slower lookup. We are still guaranteed that 8829 // If the map did change, do a slower lookup. We are still guaranteed that
8828 // the object has a simple shape, and that the key is a name. 8830 // the object has a simple shape, and that the key is a name.
8829 LookupIterator it(object, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR); 8831 LookupIterator it(object, next_key, LookupIterator::OWN_SKIP_INTERCEPTOR);
8830 if (!it.IsFound()) continue; 8832 if (!it.IsFound()) continue;
8831 DCHECK(it.state() == LookupIterator::DATA || 8833 DCHECK(it.state() == LookupIterator::DATA ||
8832 it.state() == LookupIterator::ACCESSOR); 8834 it.state() == LookupIterator::ACCESSOR);
8833 if (!it.IsEnumerable()) continue; 8835 if (!it.IsEnumerable()) continue;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
8985 8987
8986 Handle<Object> old_value = isolate->factory()->the_hole_value(); 8988 Handle<Object> old_value = isolate->factory()->the_hole_value();
8987 bool is_observed = object->map()->is_observed() && 8989 bool is_observed = object->map()->is_observed() &&
8988 (it->IsElement() || !it->name()->IsPrivate()); 8990 (it->IsElement() || !it->name()->IsPrivate());
8989 bool preexists = false; 8991 bool preexists = false;
8990 if (is_observed) { 8992 if (is_observed) {
8991 CHECK(GetPropertyAttributes(it).IsJust()); 8993 CHECK(GetPropertyAttributes(it).IsJust());
8992 preexists = it->IsFound(); 8994 preexists = it->IsFound();
8993 if (preexists && (it->state() == LookupIterator::DATA || 8995 if (preexists && (it->state() == LookupIterator::DATA ||
8994 it->GetAccessors()->IsAccessorInfo())) { 8996 it->GetAccessors()->IsAccessorInfo())) {
8995 old_value = GetProperty(it).ToHandleChecked(); 8997 old_value = Object::GetProperty(it).ToHandleChecked();
8996 } 8998 }
8997 } 8999 }
8998 9000
8999 DCHECK(getter->IsCallable() || getter->IsUndefined() || getter->IsNull() || 9001 DCHECK(getter->IsCallable() || getter->IsUndefined() || getter->IsNull() ||
9000 getter->IsFunctionTemplateInfo()); 9002 getter->IsFunctionTemplateInfo());
9001 DCHECK(setter->IsCallable() || setter->IsUndefined() || setter->IsNull() || 9003 DCHECK(setter->IsCallable() || setter->IsUndefined() || setter->IsNull() ||
9002 getter->IsFunctionTemplateInfo()); 9004 getter->IsFunctionTemplateInfo());
9003 // At least one of the accessors needs to be a new value. 9005 // At least one of the accessors needs to be a new value.
9004 DCHECK(!getter->IsNull() || !setter->IsNull()); 9006 DCHECK(!getter->IsNull() || !setter->IsNull());
9005 if (!getter->IsNull()) { 9007 if (!getter->IsNull()) {
(...skipping 4451 matching lines...) Expand 10 before | Expand all | Expand 10 after
13457 return line; 13459 return line;
13458 } 13460 }
13459 13461
13460 13462
13461 Handle<Object> Script::GetNameOrSourceURL(Handle<Script> script) { 13463 Handle<Object> Script::GetNameOrSourceURL(Handle<Script> script) {
13462 Isolate* isolate = script->GetIsolate(); 13464 Isolate* isolate = script->GetIsolate();
13463 Handle<String> name_or_source_url_key = 13465 Handle<String> name_or_source_url_key =
13464 isolate->factory()->InternalizeOneByteString( 13466 isolate->factory()->InternalizeOneByteString(
13465 STATIC_CHAR_VECTOR("nameOrSourceURL")); 13467 STATIC_CHAR_VECTOR("nameOrSourceURL"));
13466 Handle<JSObject> script_wrapper = Script::GetWrapper(script); 13468 Handle<JSObject> script_wrapper = Script::GetWrapper(script);
13467 Handle<Object> property = Object::GetProperty( 13469 Handle<Object> property =
13468 script_wrapper, name_or_source_url_key).ToHandleChecked(); 13470 JSReceiver::GetProperty(script_wrapper, name_or_source_url_key)
13471 .ToHandleChecked();
13469 DCHECK(property->IsJSFunction()); 13472 DCHECK(property->IsJSFunction());
13470 Handle<Object> result; 13473 Handle<Object> result;
13471 // Do not check against pending exception, since this function may be called 13474 // Do not check against pending exception, since this function may be called
13472 // when an exception has already been pending. 13475 // when an exception has already been pending.
13473 if (!Execution::TryCall(isolate, property, script_wrapper, 0, NULL) 13476 if (!Execution::TryCall(isolate, property, script_wrapper, 0, NULL)
13474 .ToHandle(&result)) { 13477 .ToHandle(&result)) {
13475 return isolate->factory()->undefined_value(); 13478 return isolate->factory()->undefined_value();
13476 } 13479 }
13477 return result; 13480 return result;
13478 } 13481 }
(...skipping 3211 matching lines...) Expand 10 before | Expand all | Expand 10 after
16690 if (object->IsNull()) return isolate->factory()->null_to_string(); 16693 if (object->IsNull()) return isolate->factory()->null_to_string();
16691 16694
16692 Handle<JSReceiver> receiver = 16695 Handle<JSReceiver> receiver =
16693 Object::ToObject(isolate, object).ToHandleChecked(); 16696 Object::ToObject(isolate, object).ToHandleChecked();
16694 16697
16695 Handle<String> tag; 16698 Handle<String> tag;
16696 if (FLAG_harmony_tostring) { 16699 if (FLAG_harmony_tostring) {
16697 Handle<Object> to_string_tag; 16700 Handle<Object> to_string_tag;
16698 ASSIGN_RETURN_ON_EXCEPTION( 16701 ASSIGN_RETURN_ON_EXCEPTION(
16699 isolate, to_string_tag, 16702 isolate, to_string_tag,
16700 GetProperty(receiver, isolate->factory()->to_string_tag_symbol()), 16703 JSReceiver::GetProperty(receiver,
16704 isolate->factory()->to_string_tag_symbol()),
16701 String); 16705 String);
16702 if (to_string_tag->IsString()) { 16706 if (to_string_tag->IsString()) {
16703 tag = Handle<String>::cast(to_string_tag); 16707 tag = Handle<String>::cast(to_string_tag);
16704 } 16708 }
16705 } 16709 }
16706 16710
16707 if (tag.is_null()) { 16711 if (tag.is_null()) {
16708 ASSIGN_RETURN_ON_EXCEPTION(isolate, tag, 16712 ASSIGN_RETURN_ON_EXCEPTION(isolate, tag,
16709 JSReceiver::BuiltinStringTag(receiver), String); 16713 JSReceiver::BuiltinStringTag(receiver), String);
16710 } 16714 }
(...skipping 3129 matching lines...) Expand 10 before | Expand all | Expand 10 after
19840 if (cell->value() != *new_value) { 19844 if (cell->value() != *new_value) {
19841 cell->set_value(*new_value); 19845 cell->set_value(*new_value);
19842 Isolate* isolate = cell->GetIsolate(); 19846 Isolate* isolate = cell->GetIsolate();
19843 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19847 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19844 isolate, DependentCode::kPropertyCellChangedGroup); 19848 isolate, DependentCode::kPropertyCellChangedGroup);
19845 } 19849 }
19846 } 19850 }
19847 19851
19848 } // namespace internal 19852 } // namespace internal
19849 } // namespace v8 19853 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698