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

Side by Side Diff: src/objects.cc

Issue 23857009: Handlify JSObject::AddProperty helpers. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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') | no next file » | 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 1882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 set_properties(values); 1893 set_properties(values);
1894 } 1894 }
1895 1895
1896 set_map(new_map); 1896 set_map(new_map);
1897 1897
1898 FastPropertyAtPut(field_index, storage); 1898 FastPropertyAtPut(field_index, storage);
1899 return value; 1899 return value;
1900 } 1900 }
1901 1901
1902 1902
1903 static MaybeObject* CopyAddFieldDescriptor(Map* map,
1904 Name* name,
1905 int index,
1906 PropertyAttributes attributes,
1907 Representation representation,
1908 TransitionFlag flag) {
1909 FieldDescriptor new_field_desc(name, index, attributes, representation);
1910 return map->CopyAddDescriptor(&new_field_desc, flag);
1911 }
1912
1913
1914 static Handle<Map> CopyAddFieldDescriptor(Handle<Map> map,
1915 Handle<Name> name,
1916 int index,
1917 PropertyAttributes attributes,
1918 Representation representation,
1919 TransitionFlag flag) {
1920 CALL_HEAP_FUNCTION(map->GetIsolate(),
1921 CopyAddFieldDescriptor(
1922 *map, *name, index, attributes, representation, flag),
1923 Map);
1924 }
1925
1926
1903 void JSObject::AddFastProperty(Handle<JSObject> object, 1927 void JSObject::AddFastProperty(Handle<JSObject> object,
Toon Verwaest 2013/09/11 13:11:32 Could we rename this to either JSObject::AddField
1904 Handle<Name> name, 1928 Handle<Name> name,
1905 Handle<Object> value, 1929 Handle<Object> value,
1906 PropertyAttributes attributes, 1930 PropertyAttributes attributes,
1907 StoreFromKeyed store_mode, 1931 StoreFromKeyed store_mode,
1908 ValueType value_type, 1932 ValueType value_type,
1909 TransitionFlag flag) { 1933 TransitionFlag flag) {
1910 CALL_HEAP_FUNCTION_VOID( 1934 ASSERT(!object->IsJSGlobalProxy());
1911 object->GetIsolate(),
1912 object->AddFastProperty(
1913 *name, *value, attributes, store_mode, value_type, flag));
1914 }
1915
1916
1917 MaybeObject* JSObject::AddFastProperty(Name* name,
1918 Object* value,
1919 PropertyAttributes attributes,
1920 StoreFromKeyed store_mode,
1921 ValueType value_type,
1922 TransitionFlag flag) {
1923 ASSERT(!IsJSGlobalProxy());
1924 ASSERT(DescriptorArray::kNotFound == 1935 ASSERT(DescriptorArray::kNotFound ==
1925 map()->instance_descriptors()->Search( 1936 object->map()->instance_descriptors()->Search(
1926 name, map()->NumberOfOwnDescriptors())); 1937 *name, object->map()->NumberOfOwnDescriptors()));
1927 1938
1928 // Normalize the object if the name is an actual name (not the 1939 // Normalize the object if the name is an actual name (not the
1929 // hidden strings) and is not a real identifier. 1940 // hidden strings) and is not a real identifier.
1930 // Normalize the object if it will have too many fast properties. 1941 // Normalize the object if it will have too many fast properties.
1931 Isolate* isolate = GetHeap()->isolate(); 1942 Isolate* isolate = object->GetIsolate();
1932 if (!name->IsCacheable(isolate) || TooManyFastProperties(store_mode)) { 1943 if (!name->IsCacheable(isolate) ||
1933 MaybeObject* maybe_failure = 1944 object->TooManyFastProperties(store_mode)) {
1934 NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 1945 NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0);
1935 if (maybe_failure->IsFailure()) return maybe_failure; 1946 AddSlowProperty(object, name, value, attributes);
1936 return AddSlowProperty(name, value, attributes); 1947 return;
1937 } 1948 }
1938 1949
1939 // Compute the new index for new field. 1950 // Compute the new index for new field.
1940 int index = map()->NextFreePropertyIndex(); 1951 int index = object->map()->NextFreePropertyIndex();
1941 1952
1942 // Allocate new instance descriptors with (name, index) added 1953 // Allocate new instance descriptors with (name, index) added
1943 if (IsJSContextExtensionObject()) value_type = FORCE_TAGGED; 1954 if (object->IsJSContextExtensionObject()) value_type = FORCE_TAGGED;
1944 Representation representation = value->OptimalRepresentation(value_type); 1955 Representation representation = value->OptimalRepresentation(value_type);
1956 Handle<Map> new_map = CopyAddFieldDescriptor(
1957 handle(object->map()), name, index, attributes, representation, flag);
1945 1958
1946 FieldDescriptor new_field(name, index, attributes, representation); 1959 int unused_property_fields = object->map()->unused_property_fields() - 1;
Toon Verwaest 2013/09/11 13:11:32 Now that you created CopyAddFieldDescriptor, you c
1947
1948 Map* new_map;
1949 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&new_field, flag);
1950 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
1951
1952 int unused_property_fields = map()->unused_property_fields() - 1;
1953 if (unused_property_fields < 0) { 1960 if (unused_property_fields < 0) {
1954 unused_property_fields += kFieldsAdded; 1961 unused_property_fields += kFieldsAdded;
1955 } 1962 }
1956 new_map->set_unused_property_fields(unused_property_fields); 1963 new_map->set_unused_property_fields(unused_property_fields);
1957 1964
1958 return AddFastPropertyUsingMap(new_map, name, value, index, representation); 1965 CALL_HEAP_FUNCTION_VOID(
1966 isolate,
1967 object->AddFastPropertyUsingMap(
1968 *new_map, *name, *value, index, representation));
1969 }
1970
1971
1972 static MaybeObject* CopyAddConstantDescriptor(Map* map,
1973 Name* name,
1974 Object* value,
1975 PropertyAttributes attributes,
1976 TransitionFlag flag) {
1977 ConstantDescriptor new_constant_desc(name, value, attributes);
1978 return map->CopyAddDescriptor(&new_constant_desc, flag);
1979 }
1980
1981
1982 static Handle<Map> CopyAddConstantDescriptor(Handle<Map> map,
1983 Handle<Name> name,
1984 Handle<Object> value,
1985 PropertyAttributes attributes,
1986 TransitionFlag flag) {
1987 CALL_HEAP_FUNCTION(map->GetIsolate(),
1988 CopyAddConstantDescriptor(
1989 *map, *name, *value, attributes, flag),
1990 Map);
1959 } 1991 }
1960 1992
1961 1993
1962 void JSObject::AddConstantProperty(Handle<JSObject> object, 1994 void JSObject::AddConstantProperty(Handle<JSObject> object,
1963 Handle<Name> name, 1995 Handle<Name> name,
1964 Handle<Object> constant, 1996 Handle<Object> constant,
1965 PropertyAttributes attributes, 1997 PropertyAttributes attributes,
1966 TransitionFlag flag) { 1998 TransitionFlag initial_flag) {
1967 CALL_HEAP_FUNCTION_VOID(
1968 object->GetIsolate(),
1969 object->AddConstantProperty(*name, *constant, attributes, flag));
1970 }
1971
1972
1973 MaybeObject* JSObject::AddConstantProperty(
1974 Name* name,
1975 Object* constant,
1976 PropertyAttributes attributes,
1977 TransitionFlag initial_flag) {
1978 // Allocate new instance descriptors with (name, constant) added
1979 ConstantDescriptor d(name, constant, attributes);
1980
1981 TransitionFlag flag = 1999 TransitionFlag flag =
1982 // Do not add transitions to global objects. 2000 // Do not add transitions to global objects.
1983 (IsGlobalObject() || 2001 (object->IsGlobalObject() ||
1984 // Don't add transitions to special properties with non-trivial 2002 // Don't add transitions to special properties with non-trivial
1985 // attributes. 2003 // attributes.
1986 attributes != NONE) 2004 attributes != NONE)
1987 ? OMIT_TRANSITION 2005 ? OMIT_TRANSITION
1988 : initial_flag; 2006 : initial_flag;
1989 2007
1990 Map* new_map; 2008 // Allocate new instance descriptors with (name, constant) added.
1991 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&d, flag); 2009 Handle<Map> new_map = CopyAddConstantDescriptor(
1992 if (!maybe_new_map->To(&new_map)) return maybe_new_map; 2010 handle(object->map()), name, constant, attributes, flag);
1993 2011
1994 set_map(new_map); 2012 object->set_map(*new_map);
1995 return constant;
1996 } 2013 }
1997 2014
1998 2015
2016 // TODO(mstarzinger): Temporary wrapper until handlified.
2017 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict,
2018 Handle<Name> name,
2019 Handle<Object> value,
2020 PropertyDetails details) {
2021 CALL_HEAP_FUNCTION(dict->GetIsolate(),
2022 dict->Add(*name, *value, details),
2023 NameDictionary);
2024 }
2025
2026
1999 void JSObject::AddSlowProperty(Handle<JSObject> object, 2027 void JSObject::AddSlowProperty(Handle<JSObject> object,
2000 Handle<Name> name, 2028 Handle<Name> name,
2001 Handle<Object> value, 2029 Handle<Object> value,
2002 PropertyAttributes attributes) { 2030 PropertyAttributes attributes) {
2003 CALL_HEAP_FUNCTION_VOID(object->GetIsolate(), 2031 ASSERT(!object->HasFastProperties());
2004 object->AddSlowProperty(*name, *value, attributes)); 2032 Isolate* isolate = object->GetIsolate();
2005 } 2033 Handle<NameDictionary> dict(object->property_dictionary());
2006 2034 if (object->IsGlobalObject()) {
2007
2008 MaybeObject* JSObject::AddSlowProperty(Name* name,
2009 Object* value,
2010 PropertyAttributes attributes) {
2011 ASSERT(!HasFastProperties());
2012 NameDictionary* dict = property_dictionary();
2013 Object* store_value = value;
2014 if (IsGlobalObject()) {
2015 // In case name is an orphaned property reuse the cell. 2035 // In case name is an orphaned property reuse the cell.
2016 int entry = dict->FindEntry(name); 2036 int entry = dict->FindEntry(*name);
2017 if (entry != NameDictionary::kNotFound) { 2037 if (entry != NameDictionary::kNotFound) {
2018 store_value = dict->ValueAt(entry); 2038 Handle<PropertyCell> cell(PropertyCell::cast(dict->ValueAt(entry)));
2019 MaybeObject* maybe_type = 2039 PropertyCell::SetValueInferType(cell, value);
2020 PropertyCell::cast(store_value)->SetValueInferType(value);
2021 if (maybe_type->IsFailure()) return maybe_type;
2022 // Assign an enumeration index to the property and update 2040 // Assign an enumeration index to the property and update
2023 // SetNextEnumerationIndex. 2041 // SetNextEnumerationIndex.
2024 int index = dict->NextEnumerationIndex(); 2042 int index = dict->NextEnumerationIndex();
2025 PropertyDetails details = PropertyDetails(attributes, NORMAL, index); 2043 PropertyDetails details = PropertyDetails(attributes, NORMAL, index);
2026 dict->SetNextEnumerationIndex(index + 1); 2044 dict->SetNextEnumerationIndex(index + 1);
2027 dict->SetEntry(entry, name, store_value, details); 2045 dict->SetEntry(entry, *name, *cell, details);
2028 return value; 2046 return;
2029 } 2047 }
2030 Heap* heap = GetHeap(); 2048 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell(value);
2031 { MaybeObject* maybe_store_value = 2049 PropertyCell::SetValueInferType(cell, value);
2032 heap->AllocatePropertyCell(value); 2050 value = cell;
2033 if (!maybe_store_value->ToObject(&store_value)) return maybe_store_value;
2034 }
2035 MaybeObject* maybe_type =
2036 PropertyCell::cast(store_value)->SetValueInferType(value);
2037 if (maybe_type->IsFailure()) return maybe_type;
2038 } 2051 }
2039 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); 2052 PropertyDetails details = PropertyDetails(attributes, NORMAL, 0);
2040 Object* result; 2053 Handle<NameDictionary> result = NameDictionaryAdd(dict, name, value, details);
2041 { MaybeObject* maybe_result = dict->Add(name, store_value, details); 2054 if (*dict != *result) object->set_properties(*result);
2042 if (!maybe_result->ToObject(&result)) return maybe_result;
2043 }
2044 if (dict != result) set_properties(NameDictionary::cast(result));
2045 return value;
2046 } 2055 }
2047 2056
2048 2057
2049 Handle<Object> JSObject::AddProperty(Handle<JSObject> object, 2058 Handle<Object> JSObject::AddProperty(Handle<JSObject> object,
2050 Handle<Name> name, 2059 Handle<Name> name,
2051 Handle<Object> value, 2060 Handle<Object> value,
2052 PropertyAttributes attributes, 2061 PropertyAttributes attributes,
2053 StrictModeFlag strict_mode, 2062 StrictModeFlag strict_mode,
2054 JSReceiver::StoreFromKeyed store_mode, 2063 JSReceiver::StoreFromKeyed store_mode,
2055 ExtensibilityCheck extensibility_check, 2064 ExtensibilityCheck extensibility_check,
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after
3781 int modify_index, 3790 int modify_index,
3782 Representation representation, 3791 Representation representation,
3783 StoreMode store_mode) { 3792 StoreMode store_mode) {
3784 CALL_HEAP_FUNCTION( 3793 CALL_HEAP_FUNCTION(
3785 map->GetIsolate(), 3794 map->GetIsolate(),
3786 map->GeneralizeRepresentation(modify_index, representation, store_mode), 3795 map->GeneralizeRepresentation(modify_index, representation, store_mode),
3787 Map); 3796 Map);
3788 } 3797 }
3789 3798
3790 3799
3791 static MaybeObject* SetPropertyUsingTransition(LookupResult* lookup, 3800 MaybeObject* JSObject::SetPropertyUsingTransition(LookupResult* lookup,
3792 Handle<Name> name, 3801 Handle<Name> name,
3793 Handle<Object> value, 3802 Handle<Object> value,
3794 PropertyAttributes attributes) { 3803 PropertyAttributes attributes) {
3795 Map* transition_map = lookup->GetTransitionTarget(); 3804 Map* transition_map = lookup->GetTransitionTarget();
3796 int descriptor = transition_map->LastAdded(); 3805 int descriptor = transition_map->LastAdded();
3797 3806
3798 DescriptorArray* descriptors = transition_map->instance_descriptors(); 3807 DescriptorArray* descriptors = transition_map->instance_descriptors();
3799 PropertyDetails details = descriptors->GetDetails(descriptor); 3808 PropertyDetails details = descriptors->GetDetails(descriptor);
3800 3809
3801 if (details.type() == CALLBACKS || attributes != details.attributes()) { 3810 if (details.type() == CALLBACKS || attributes != details.attributes()) {
(...skipping 10682 matching lines...) Expand 10 before | Expand all | Expand 10 after
14484 } 14493 }
14485 14494
14486 14495
14487 PropertyCell* GlobalObject::GetPropertyCell(LookupResult* result) { 14496 PropertyCell* GlobalObject::GetPropertyCell(LookupResult* result) {
14488 ASSERT(!HasFastProperties()); 14497 ASSERT(!HasFastProperties());
14489 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry()); 14498 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry());
14490 return PropertyCell::cast(value); 14499 return PropertyCell::cast(value);
14491 } 14500 }
14492 14501
14493 14502
14494 // TODO(mstarzinger): Temporary wrapper until handlified.
14495 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict,
14496 Handle<Name> name,
14497 Handle<Object> value,
14498 PropertyDetails details) {
14499 CALL_HEAP_FUNCTION(dict->GetIsolate(),
14500 dict->Add(*name, *value, details),
14501 NameDictionary);
14502 }
14503
14504
14505 Handle<PropertyCell> GlobalObject::EnsurePropertyCell( 14503 Handle<PropertyCell> GlobalObject::EnsurePropertyCell(
14506 Handle<GlobalObject> global, 14504 Handle<GlobalObject> global,
14507 Handle<Name> name) { 14505 Handle<Name> name) {
14508 ASSERT(!global->HasFastProperties()); 14506 ASSERT(!global->HasFastProperties());
14509 int entry = global->property_dictionary()->FindEntry(*name); 14507 int entry = global->property_dictionary()->FindEntry(*name);
14510 if (entry == NameDictionary::kNotFound) { 14508 if (entry == NameDictionary::kNotFound) {
14511 Isolate* isolate = global->GetIsolate(); 14509 Isolate* isolate = global->GetIsolate();
14512 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell( 14510 Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell(
14513 isolate->factory()->the_hole_value()); 14511 isolate->factory()->the_hole_value());
14514 PropertyDetails details(NONE, NORMAL, 0); 14512 PropertyDetails details(NONE, NORMAL, 0);
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
16073 isolate, DependentCode::kPropertyCellChangedGroup); 16071 isolate, DependentCode::kPropertyCellChangedGroup);
16074 16072
16075 if (old_type->Is(Type::None()) || old_type->Is(Type::Undefined())) { 16073 if (old_type->Is(Type::None()) || old_type->Is(Type::Undefined())) {
16076 return *new_type; 16074 return *new_type;
16077 } 16075 }
16078 16076
16079 return Type::Any(); 16077 return Type::Any();
16080 } 16078 }
16081 16079
16082 16080
16081 void PropertyCell::SetValueInferType(Handle<PropertyCell> cell,
16082 Handle<Object> value,
16083 WriteBarrierMode mode) {
16084 CALL_HEAP_FUNCTION_VOID(cell->GetIsolate(),
16085 cell->SetValueInferType(*value, mode));
16086 }
16087
16088
16083 MaybeObject* PropertyCell::SetValueInferType(Object* value, 16089 MaybeObject* PropertyCell::SetValueInferType(Object* value,
16084 WriteBarrierMode ignored) { 16090 WriteBarrierMode ignored) {
16085 set_value(value, ignored); 16091 set_value(value, ignored);
16086 if (!Type::Any()->Is(type())) { 16092 if (!Type::Any()->Is(type())) {
16087 IdempotentPointerToHandleCodeTrampoline trampoline(GetIsolate()); 16093 IdempotentPointerToHandleCodeTrampoline trampoline(GetIsolate());
16088 MaybeObject* maybe_type = trampoline.CallWithReturnValue( 16094 MaybeObject* maybe_type = trampoline.CallWithReturnValue(
16089 &PropertyCell::UpdateType, 16095 &PropertyCell::UpdateType,
16090 Handle<PropertyCell>(this), 16096 Handle<PropertyCell>(this),
16091 Handle<Object>(value, GetIsolate())); 16097 Handle<Object>(value, GetIsolate()));
16092 Type* new_type = NULL; 16098 Type* new_type = NULL;
(...skipping 28 matching lines...) Expand all
16121 #define ERROR_MESSAGES_TEXTS(C, T) T, 16127 #define ERROR_MESSAGES_TEXTS(C, T) T,
16122 static const char* error_messages_[] = { 16128 static const char* error_messages_[] = {
16123 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16129 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16124 }; 16130 };
16125 #undef ERROR_MESSAGES_TEXTS 16131 #undef ERROR_MESSAGES_TEXTS
16126 return error_messages_[reason]; 16132 return error_messages_[reason];
16127 } 16133 }
16128 16134
16129 16135
16130 } } // namespace v8::internal 16136 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698