| OLD | NEW |
| 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 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 | 1951 |
| 1952 // Compute the new index for new field. | 1952 // Compute the new index for new field. |
| 1953 int index = map()->NextFreePropertyIndex(); | 1953 int index = map()->NextFreePropertyIndex(); |
| 1954 | 1954 |
| 1955 // Allocate new instance descriptors with (name, index) added | 1955 // Allocate new instance descriptors with (name, index) added |
| 1956 if (IsJSContextExtensionObject()) value_type = FORCE_TAGGED; | 1956 if (IsJSContextExtensionObject()) value_type = FORCE_TAGGED; |
| 1957 Representation representation = value->OptimalRepresentation(value_type); | 1957 Representation representation = value->OptimalRepresentation(value_type); |
| 1958 | 1958 |
| 1959 FieldDescriptor new_field(name, index, attributes, representation); | 1959 FieldDescriptor new_field(name, index, attributes, representation); |
| 1960 | 1960 |
| 1961 ASSERT(index < map()->inobject_properties() || | |
| 1962 (index - map()->inobject_properties()) < properties()->length() || | |
| 1963 map()->unused_property_fields() == 0); | |
| 1964 | |
| 1965 FixedArray* values = NULL; | |
| 1966 | |
| 1967 // TODO(verwaest): Merge with AddFastPropertyUsingMap. | |
| 1968 if (map()->unused_property_fields() == 0) { | |
| 1969 // Make room for the new value | |
| 1970 MaybeObject* maybe_values = | |
| 1971 properties()->CopySize(properties()->length() + kFieldsAdded); | |
| 1972 if (!maybe_values->To(&values)) return maybe_values; | |
| 1973 } | |
| 1974 | |
| 1975 Heap* heap = isolate->heap(); | |
| 1976 | |
| 1977 Object* storage; | |
| 1978 MaybeObject* maybe_storage = | |
| 1979 value->AllocateNewStorageFor(heap, representation); | |
| 1980 if (!maybe_storage->To(&storage)) return maybe_storage; | |
| 1981 | |
| 1982 // Note that Map::CopyAddDescriptor has side-effects, the new map is already | |
| 1983 // inserted in the transition tree. No more allocations that might fail are | |
| 1984 // allowed after this point. | |
| 1985 Map* new_map; | 1961 Map* new_map; |
| 1986 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&new_field, flag); | 1962 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&new_field, flag); |
| 1987 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 1963 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| 1988 | 1964 |
| 1989 if (map()->unused_property_fields() == 0) { | 1965 int unused_property_fields = map()->unused_property_fields() - 1; |
| 1990 ASSERT(values != NULL); | 1966 if (unused_property_fields < 0) { |
| 1991 set_properties(values); | 1967 unused_property_fields += kFieldsAdded; |
| 1992 new_map->set_unused_property_fields(kFieldsAdded - 1); | |
| 1993 } else { | |
| 1994 new_map->set_unused_property_fields(map()->unused_property_fields() - 1); | |
| 1995 } | 1968 } |
| 1969 new_map->set_unused_property_fields(unused_property_fields); |
| 1996 | 1970 |
| 1997 set_map(new_map); | 1971 return AddFastPropertyUsingMap(new_map, name, value, index, representation); |
| 1998 | |
| 1999 FastPropertyAtPut(index, storage); | |
| 2000 return value; | |
| 2001 } | 1972 } |
| 2002 | 1973 |
| 2003 | 1974 |
| 2004 MaybeObject* JSObject::AddConstantProperty( | 1975 MaybeObject* JSObject::AddConstantProperty( |
| 2005 Name* name, | 1976 Name* name, |
| 2006 Object* constant, | 1977 Object* constant, |
| 2007 PropertyAttributes attributes, | 1978 PropertyAttributes attributes, |
| 2008 TransitionFlag initial_flag) { | 1979 TransitionFlag initial_flag) { |
| 2009 // Allocate new instance descriptors with (name, constant) added | 1980 // Allocate new instance descriptors with (name, constant) added |
| 2010 ConstantDescriptor d(name, constant, attributes); | 1981 ConstantDescriptor d(name, constant, attributes); |
| (...skipping 14002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16013 #define ERROR_MESSAGES_TEXTS(C, T) T, | 15984 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16014 static const char* error_messages_[] = { | 15985 static const char* error_messages_[] = { |
| 16015 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 15986 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16016 }; | 15987 }; |
| 16017 #undef ERROR_MESSAGES_TEXTS | 15988 #undef ERROR_MESSAGES_TEXTS |
| 16018 return error_messages_[reason]; | 15989 return error_messages_[reason]; |
| 16019 } | 15990 } |
| 16020 | 15991 |
| 16021 | 15992 |
| 16022 } } // namespace v8::internal | 15993 } } // namespace v8::internal |
| OLD | NEW |