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

Side by Side Diff: src/objects.cc

Issue 249723004: Dictionary::Add() handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 Handle<String>::cast(name)); 660 Handle<String>::cast(name));
661 } 661 }
662 662
663 int entry = property_dictionary->FindEntry(*name); 663 int entry = property_dictionary->FindEntry(*name);
664 if (entry == NameDictionary::kNotFound) { 664 if (entry == NameDictionary::kNotFound) {
665 Handle<Object> store_value = value; 665 Handle<Object> store_value = value;
666 if (object->IsGlobalObject()) { 666 if (object->IsGlobalObject()) {
667 store_value = object->GetIsolate()->factory()->NewPropertyCell(value); 667 store_value = object->GetIsolate()->factory()->NewPropertyCell(value);
668 } 668 }
669 669
670 property_dictionary = NameDictionary::AddNameEntry( 670 property_dictionary = NameDictionary::Add(
671 property_dictionary, name, store_value, details); 671 property_dictionary, *name, store_value, details);
672 object->set_properties(*property_dictionary); 672 object->set_properties(*property_dictionary);
673 return; 673 return;
674 } 674 }
675 675
676 PropertyDetails original_details = property_dictionary->DetailsAt(entry); 676 PropertyDetails original_details = property_dictionary->DetailsAt(entry);
677 int enumeration_index; 677 int enumeration_index;
678 // Preserve the enumeration index unless the property was deleted. 678 // Preserve the enumeration index unless the property was deleted.
679 if (original_details.IsDeleted()) { 679 if (original_details.IsDeleted()) {
680 enumeration_index = property_dictionary->NextEnumerationIndex(); 680 enumeration_index = property_dictionary->NextEnumerationIndex();
681 property_dictionary->SetNextEnumerationIndex(enumeration_index + 1); 681 property_dictionary->SetNextEnumerationIndex(enumeration_index + 1);
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 dict->SetNextEnumerationIndex(index + 1); 1935 dict->SetNextEnumerationIndex(index + 1);
1936 dict->SetEntry(entry, *name, *cell, details); 1936 dict->SetEntry(entry, *name, *cell, details);
1937 return; 1937 return;
1938 } 1938 }
1939 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell(value); 1939 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell(value);
1940 PropertyCell::SetValueInferType(cell, value); 1940 PropertyCell::SetValueInferType(cell, value);
1941 value = cell; 1941 value = cell;
1942 } 1942 }
1943 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); 1943 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0);
1944 Handle<NameDictionary> result = 1944 Handle<NameDictionary> result =
1945 NameDictionary::AddNameEntry(dict, name, value, details); 1945 NameDictionary::Add(dict, *name, value, details);
1946 if (*dict != *result) object->set_properties(*result); 1946 if (*dict != *result) object->set_properties(*result);
1947 } 1947 }
1948 1948
1949 1949
1950 MaybeHandle<Object> JSObject::AddProperty( 1950 MaybeHandle<Object> JSObject::AddProperty(
1951 Handle<JSObject> object, 1951 Handle<JSObject> object,
1952 Handle<Name> name, 1952 Handle<Name> name,
1953 Handle<Object> value, 1953 Handle<Object> value,
1954 PropertyAttributes attributes, 1954 PropertyAttributes attributes,
1955 StrictMode strict_mode, 1955 StrictMode strict_mode,
(...skipping 2678 matching lines...) Expand 10 before | Expand all | Expand 10 after
4634 4634
4635 Handle<DescriptorArray> descs(map->instance_descriptors()); 4635 Handle<DescriptorArray> descs(map->instance_descriptors());
4636 for (int i = 0; i < real_size; i++) { 4636 for (int i = 0; i < real_size; i++) {
4637 PropertyDetails details = descs->GetDetails(i); 4637 PropertyDetails details = descs->GetDetails(i);
4638 switch (details.type()) { 4638 switch (details.type()) {
4639 case CONSTANT: { 4639 case CONSTANT: {
4640 Handle<Name> key(descs->GetKey(i)); 4640 Handle<Name> key(descs->GetKey(i));
4641 Handle<Object> value(descs->GetConstant(i), isolate); 4641 Handle<Object> value(descs->GetConstant(i), isolate);
4642 PropertyDetails d = PropertyDetails( 4642 PropertyDetails d = PropertyDetails(
4643 details.attributes(), NORMAL, i + 1); 4643 details.attributes(), NORMAL, i + 1);
4644 dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d); 4644 dictionary = NameDictionary::Add(dictionary, *key, value, d);
4645 break; 4645 break;
4646 } 4646 }
4647 case FIELD: { 4647 case FIELD: {
4648 Handle<Name> key(descs->GetKey(i)); 4648 Handle<Name> key(descs->GetKey(i));
4649 Handle<Object> value( 4649 Handle<Object> value(
4650 object->RawFastPropertyAt(descs->GetFieldIndex(i)), isolate); 4650 object->RawFastPropertyAt(descs->GetFieldIndex(i)), isolate);
4651 PropertyDetails d = 4651 PropertyDetails d =
4652 PropertyDetails(details.attributes(), NORMAL, i + 1); 4652 PropertyDetails(details.attributes(), NORMAL, i + 1);
4653 dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d); 4653 dictionary = NameDictionary::Add(dictionary, *key, value, d);
4654 break; 4654 break;
4655 } 4655 }
4656 case CALLBACKS: { 4656 case CALLBACKS: {
4657 Handle<Name> key(descs->GetKey(i)); 4657 Handle<Name> key(descs->GetKey(i));
4658 Handle<Object> value(descs->GetCallbacksObject(i), isolate); 4658 Handle<Object> value(descs->GetCallbacksObject(i), isolate);
4659 PropertyDetails d = PropertyDetails( 4659 PropertyDetails d = PropertyDetails(
4660 details.attributes(), CALLBACKS, i + 1); 4660 details.attributes(), CALLBACKS, i + 1);
4661 dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d); 4661 dictionary = NameDictionary::Add(dictionary, *key, value, d);
4662 break; 4662 break;
4663 } 4663 }
4664 case INTERCEPTOR: 4664 case INTERCEPTOR:
4665 break; 4665 break;
4666 case HANDLER: 4666 case HANDLER:
4667 case NORMAL: 4667 case NORMAL:
4668 case NONEXISTENT: 4668 case NONEXISTENT:
4669 UNREACHABLE(); 4669 UNREACHABLE();
4670 break; 4670 break;
4671 } 4671 }
(...skipping 10294 matching lines...) Expand 10 before | Expand all | Expand 10 after
14966 CopyKeysTo( 14966 CopyKeysTo(
14967 FixedArray*, 14967 FixedArray*,
14968 int, 14968 int,
14969 PropertyAttributes, 14969 PropertyAttributes,
14970 Dictionary<NameDictionary, NameDictionaryShape, Name*>::SortMode); 14970 Dictionary<NameDictionary, NameDictionaryShape, Name*>::SortMode);
14971 14971
14972 template int 14972 template int
14973 Dictionary<NameDictionary, NameDictionaryShape, Name*>:: 14973 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
14974 NumberOfElementsFilterAttributes(PropertyAttributes); 14974 NumberOfElementsFilterAttributes(PropertyAttributes);
14975 14975
14976 template MaybeObject* 14976 template Handle<NameDictionary>
14977 Dictionary<NameDictionary, NameDictionaryShape, Name*>::Add( 14977 Dictionary<NameDictionary, NameDictionaryShape, Name*>::Add(
14978 Name*, Object*, PropertyDetails); 14978 Handle<NameDictionary>, Name*, Handle<Object>, PropertyDetails);
14979 14979
14980 template MaybeObject* 14980 template MaybeObject*
14981 Dictionary<NameDictionary, NameDictionaryShape, Name*>:: 14981 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
14982 GenerateNewEnumerationIndices(); 14982 GenerateNewEnumerationIndices();
14983 14983
14984 template int 14984 template int
14985 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 14985 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
14986 NumberOfElementsFilterAttributes(PropertyAttributes); 14986 NumberOfElementsFilterAttributes(PropertyAttributes);
14987 14987
14988 template MaybeObject* 14988 template Handle<SeededNumberDictionary>
14989 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::Add( 14989 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
14990 uint32_t, Object*, PropertyDetails); 14990 Add(Handle<SeededNumberDictionary>,
14991 uint32_t,
14992 Handle<Object>,
14993 PropertyDetails);
14991 14994
14992 template MaybeObject* 14995 template Handle<UnseededNumberDictionary>
14993 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: 14996 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
14994 Add(uint32_t, Object*, PropertyDetails); 14997 Add(Handle<UnseededNumberDictionary>,
14998 uint32_t,
14999 Handle<Object>,
15000 PropertyDetails);
14995 15001
14996 template MaybeObject* 15002 template MaybeObject*
14997 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 15003 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
14998 EnsureCapacity(int, uint32_t); 15004 EnsureCapacity(int, uint32_t);
14999 15005
15000 template MaybeObject* 15006 template MaybeObject*
15001 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: 15007 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
15002 EnsureCapacity(int, uint32_t); 15008 EnsureCapacity(int, uint32_t);
15003 15009
15004 template MaybeObject* 15010 template MaybeObject*
(...skipping 18 matching lines...) Expand all
15023 15029
15024 template 15030 template
15025 int Dictionary<NameDictionary, NameDictionaryShape, Name*>:: 15031 int Dictionary<NameDictionary, NameDictionaryShape, Name*>::
15026 NumberOfEnumElements(); 15032 NumberOfEnumElements();
15027 15033
15028 template 15034 template
15029 int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 15035 int HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
15030 FindEntry(uint32_t); 15036 FindEntry(uint32_t);
15031 15037
15032 15038
15033 Handle<NameDictionary> NameDictionary::AddNameEntry(Handle<NameDictionary> dict,
15034 Handle<Name> name,
15035 Handle<Object> value,
15036 PropertyDetails details) {
15037 CALL_HEAP_FUNCTION(dict->GetIsolate(),
15038 dict->Add(*name, *value, details),
15039 NameDictionary);
15040 }
15041
15042
15043 Handle<Object> JSObject::PrepareSlowElementsForSort( 15039 Handle<Object> JSObject::PrepareSlowElementsForSort(
15044 Handle<JSObject> object, uint32_t limit) { 15040 Handle<JSObject> object, uint32_t limit) {
15045 ASSERT(object->HasDictionaryElements()); 15041 ASSERT(object->HasDictionaryElements());
15046 Isolate* isolate = object->GetIsolate(); 15042 Isolate* isolate = object->GetIsolate();
15047 // Must stay in dictionary mode, either because of requires_slow_elements, 15043 // Must stay in dictionary mode, either because of requires_slow_elements,
15048 // or because we are not going to sort (and therefore compact) all of the 15044 // or because we are not going to sort (and therefore compact) all of the
15049 // elements. 15045 // elements.
15050 Handle<SeededNumberDictionary> dict(object->element_dictionary(), isolate); 15046 Handle<SeededNumberDictionary> dict(object->element_dictionary(), isolate);
15051 Handle<SeededNumberDictionary> new_dict = 15047 Handle<SeededNumberDictionary> new_dict =
15052 isolate->factory()->NewSeededNumberDictionary(dict->NumberOfElements()); 15048 isolate->factory()->NewSeededNumberDictionary(dict->NumberOfElements());
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
15473 Handle<JSGlobalObject> global, 15469 Handle<JSGlobalObject> global,
15474 Handle<Name> name) { 15470 Handle<Name> name) {
15475 ASSERT(!global->HasFastProperties()); 15471 ASSERT(!global->HasFastProperties());
15476 int entry = global->property_dictionary()->FindEntry(*name); 15472 int entry = global->property_dictionary()->FindEntry(*name);
15477 if (entry == NameDictionary::kNotFound) { 15473 if (entry == NameDictionary::kNotFound) {
15478 Isolate* isolate = global->GetIsolate(); 15474 Isolate* isolate = global->GetIsolate();
15479 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell( 15475 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell(
15480 isolate->factory()->the_hole_value()); 15476 isolate->factory()->the_hole_value());
15481 PropertyDetails details(NONE, NORMAL, 0); 15477 PropertyDetails details(NONE, NORMAL, 0);
15482 details = details.AsDeleted(); 15478 details = details.AsDeleted();
15483 Handle<NameDictionary> dictionary = NameDictionary::AddNameEntry( 15479 Handle<NameDictionary> dictionary = NameDictionary::Add(
15484 handle(global->property_dictionary()), name, cell, details); 15480 handle(global->property_dictionary()), *name, cell, details);
15485 global->set_properties(*dictionary); 15481 global->set_properties(*dictionary);
15486 return cell; 15482 return cell;
15487 } else { 15483 } else {
15488 Object* value = global->property_dictionary()->ValueAt(entry); 15484 Object* value = global->property_dictionary()->ValueAt(entry);
15489 ASSERT(value->IsPropertyCell()); 15485 ASSERT(value->IsPropertyCell());
15490 return handle(PropertyCell::cast(value)); 15486 return handle(PropertyCell::cast(value));
15491 } 15487 }
15492 } 15488 }
15493 15489
15494 15490
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
15953 Handle<Object> k = Shape::AsHandle(dictionary->GetIsolate(), key); 15949 Handle<Object> k = Shape::AsHandle(dictionary->GetIsolate(), key);
15954 // TODO(ishell): Figure out if it is necessary to call AsHandle() here. 15950 // TODO(ishell): Figure out if it is necessary to call AsHandle() here.
15955 USE(k); 15951 USE(k);
15956 PropertyDetails details = PropertyDetails(NONE, NORMAL, 0); 15952 PropertyDetails details = PropertyDetails(NONE, NORMAL, 0);
15957 15953
15958 return AddEntry(dictionary, key, value, details, dictionary->Hash(key)); 15954 return AddEntry(dictionary, key, value, details, dictionary->Hash(key));
15959 } 15955 }
15960 15956
15961 15957
15962 template<typename Derived, typename Shape, typename Key> 15958 template<typename Derived, typename Shape, typename Key>
15963 MaybeObject* Dictionary<Derived, Shape, Key>::Add( 15959 Handle<Derived> Dictionary<Derived, Shape, Key>::Add(
15960 Handle<Derived> dictionary,
15964 Key key, 15961 Key key,
15965 Object* value, 15962 Handle<Object> value,
15966 PropertyDetails details) { 15963 PropertyDetails details) {
15967 // Valdate key is absent. 15964 // Valdate key is absent.
15968 SLOW_ASSERT((this->FindEntry(key) == Dictionary::kNotFound)); 15965 SLOW_ASSERT((dictionary->FindEntry(key) == Dictionary::kNotFound));
15969 // Check whether the dictionary should be extended. 15966 // Check whether the dictionary should be extended.
15970 Object* obj; 15967 dictionary = EnsureCapacity(dictionary, 1, key);
15971 { MaybeObject* maybe_obj = EnsureCapacity(1, key);
15972 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
15973 }
15974 15968
15975 return Dictionary::cast(obj)->AddEntry( 15969 return AddEntry(dictionary, key, value, details, dictionary->Hash(key));
15976 key, value, details, Dictionary::Hash(key));
15977 } 15970 }
15978 15971
15979 15972
15980 // Add a key, value pair to the dictionary. 15973 // Add a key, value pair to the dictionary.
15981 template<typename Derived, typename Shape, typename Key> 15974 template<typename Derived, typename Shape, typename Key>
15982 Handle<Derived> Dictionary<Derived, Shape, Key>::AddEntry( 15975 Handle<Derived> Dictionary<Derived, Shape, Key>::AddEntry(
15983 Handle<Derived> dictionary, 15976 Handle<Derived> dictionary,
15984 Key key, 15977 Key key,
15985 Handle<Object> value, 15978 Handle<Object> value,
15986 PropertyDetails details, 15979 PropertyDetails details,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
16042 } 16035 }
16043 16036
16044 16037
16045 Handle<SeededNumberDictionary> SeededNumberDictionary::AddNumberEntry( 16038 Handle<SeededNumberDictionary> SeededNumberDictionary::AddNumberEntry(
16046 Handle<SeededNumberDictionary> dictionary, 16039 Handle<SeededNumberDictionary> dictionary,
16047 uint32_t key, 16040 uint32_t key,
16048 Handle<Object> value, 16041 Handle<Object> value,
16049 PropertyDetails details) { 16042 PropertyDetails details) {
16050 dictionary->UpdateMaxNumberKey(key); 16043 dictionary->UpdateMaxNumberKey(key);
16051 SLOW_ASSERT(dictionary->FindEntry(key) == kNotFound); 16044 SLOW_ASSERT(dictionary->FindEntry(key) == kNotFound);
16052 CALL_HEAP_FUNCTION(dictionary->GetIsolate(), 16045 return Add(dictionary, key, value, details);
16053 dictionary->Add(key, *value, details),
16054 SeededNumberDictionary);
16055 } 16046 }
16056 16047
16057 16048
16058 Handle<UnseededNumberDictionary> UnseededNumberDictionary::AddNumberEntry( 16049 Handle<UnseededNumberDictionary> UnseededNumberDictionary::AddNumberEntry(
16059 Handle<UnseededNumberDictionary> dictionary, 16050 Handle<UnseededNumberDictionary> dictionary,
16060 uint32_t key, 16051 uint32_t key,
16061 Handle<Object> value) { 16052 Handle<Object> value) {
16062 SLOW_ASSERT(dictionary->FindEntry(key) == kNotFound); 16053 SLOW_ASSERT(dictionary->FindEntry(key) == kNotFound);
16063 CALL_HEAP_FUNCTION(dictionary->GetIsolate(), 16054 return Add(dictionary, key, value, PropertyDetails(NONE, NORMAL, 0));
16064 dictionary->Add(
16065 key, *value, PropertyDetails(NONE, NORMAL, 0)),
16066 UnseededNumberDictionary);
16067 } 16055 }
16068 16056
16069 16057
16070 Handle<SeededNumberDictionary> SeededNumberDictionary::AtNumberPut( 16058 Handle<SeededNumberDictionary> SeededNumberDictionary::AtNumberPut(
16071 Handle<SeededNumberDictionary> dictionary, 16059 Handle<SeededNumberDictionary> dictionary,
16072 uint32_t key, 16060 uint32_t key,
16073 Handle<Object> value) { 16061 Handle<Object> value) {
16074 dictionary->UpdateMaxNumberKey(key); 16062 dictionary->UpdateMaxNumberKey(key);
16075 return AtPut(dictionary, key, value); 16063 return AtPut(dictionary, key, value);
16076 } 16064 }
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
17422 #define ERROR_MESSAGES_TEXTS(C, T) T, 17410 #define ERROR_MESSAGES_TEXTS(C, T) T,
17423 static const char* error_messages_[] = { 17411 static const char* error_messages_[] = {
17424 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17412 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
17425 }; 17413 };
17426 #undef ERROR_MESSAGES_TEXTS 17414 #undef ERROR_MESSAGES_TEXTS
17427 return error_messages_[reason]; 17415 return error_messages_[reason];
17428 } 17416 }
17429 17417
17430 17418
17431 } } // namespace v8::internal 17419 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698