OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 HeapObject* JSObject::elements() { | 1159 HeapObject* JSObject::elements() { |
1160 Object* array = READ_FIELD(this, kElementsOffset); | 1160 Object* array = READ_FIELD(this, kElementsOffset); |
1161 // In the assert below Dictionary is covered under FixedArray. | 1161 // In the assert below Dictionary is covered under FixedArray. |
1162 ASSERT(array->IsFixedArray() || array->IsPixelArray() || | 1162 ASSERT(array->IsFixedArray() || array->IsPixelArray() || |
1163 array->IsExternalArray()); | 1163 array->IsExternalArray()); |
1164 return reinterpret_cast<HeapObject*>(array); | 1164 return reinterpret_cast<HeapObject*>(array); |
1165 } | 1165 } |
1166 | 1166 |
1167 | 1167 |
1168 void JSObject::set_elements(HeapObject* value, WriteBarrierMode mode) { | 1168 void JSObject::set_elements(HeapObject* value, WriteBarrierMode mode) { |
| 1169 ASSERT(map()->has_fast_elements() == |
| 1170 (value->map() == Heap::fixed_array_map())); |
1169 // In the assert below Dictionary is covered under FixedArray. | 1171 // In the assert below Dictionary is covered under FixedArray. |
1170 ASSERT(value->IsFixedArray() || value->IsPixelArray() || | 1172 ASSERT(value->IsFixedArray() || value->IsPixelArray() || |
1171 value->IsExternalArray()); | 1173 value->IsExternalArray()); |
1172 WRITE_FIELD(this, kElementsOffset, value); | 1174 WRITE_FIELD(this, kElementsOffset, value); |
1173 CONDITIONAL_WRITE_BARRIER(this, kElementsOffset, mode); | 1175 CONDITIONAL_WRITE_BARRIER(this, kElementsOffset, mode); |
1174 } | 1176 } |
1175 | 1177 |
1176 | 1178 |
1177 void JSObject::initialize_properties() { | 1179 void JSObject::initialize_properties() { |
1178 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); | 1180 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); |
1179 WRITE_FIELD(this, kPropertiesOffset, Heap::empty_fixed_array()); | 1181 WRITE_FIELD(this, kPropertiesOffset, Heap::empty_fixed_array()); |
1180 } | 1182 } |
1181 | 1183 |
1182 | 1184 |
1183 void JSObject::initialize_elements() { | 1185 void JSObject::initialize_elements() { |
| 1186 ASSERT(map()->has_fast_elements()); |
1184 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); | 1187 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); |
1185 WRITE_FIELD(this, kElementsOffset, Heap::empty_fixed_array()); | 1188 WRITE_FIELD(this, kElementsOffset, Heap::empty_fixed_array()); |
1186 } | 1189 } |
1187 | 1190 |
1188 | 1191 |
| 1192 Object* JSObject::ResetElements() { |
| 1193 Object* obj = map()->GetFastElementsMap(); |
| 1194 if (obj->IsFailure()) return obj; |
| 1195 set_map(Map::cast(obj)); |
| 1196 initialize_elements(); |
| 1197 return this; |
| 1198 } |
| 1199 |
| 1200 |
1189 ACCESSORS(Oddball, to_string, String, kToStringOffset) | 1201 ACCESSORS(Oddball, to_string, String, kToStringOffset) |
1190 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) | 1202 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
1191 | 1203 |
1192 | 1204 |
1193 Object* JSGlobalPropertyCell::value() { | 1205 Object* JSGlobalPropertyCell::value() { |
1194 return READ_FIELD(this, kValueOffset); | 1206 return READ_FIELD(this, kValueOffset); |
1195 } | 1207 } |
1196 | 1208 |
1197 | 1209 |
1198 void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) { | 1210 void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) { |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 } | 2340 } |
2329 | 2341 |
2330 | 2342 |
2331 void Map::set_prototype(Object* value, WriteBarrierMode mode) { | 2343 void Map::set_prototype(Object* value, WriteBarrierMode mode) { |
2332 ASSERT(value->IsNull() || value->IsJSObject()); | 2344 ASSERT(value->IsNull() || value->IsJSObject()); |
2333 WRITE_FIELD(this, kPrototypeOffset, value); | 2345 WRITE_FIELD(this, kPrototypeOffset, value); |
2334 CONDITIONAL_WRITE_BARRIER(this, kPrototypeOffset, mode); | 2346 CONDITIONAL_WRITE_BARRIER(this, kPrototypeOffset, mode); |
2335 } | 2347 } |
2336 | 2348 |
2337 | 2349 |
| 2350 Object* Map::GetFastElementsMap() { |
| 2351 if (has_fast_elements()) return this; |
| 2352 Object* obj = CopyDropTransitions(); |
| 2353 if (obj->IsFailure()) return obj; |
| 2354 Map* new_map = Map::cast(obj); |
| 2355 new_map->set_has_fast_elements(true); |
| 2356 return new_map; |
| 2357 } |
| 2358 |
| 2359 |
| 2360 Object* Map::GetSlowElementsMap() { |
| 2361 if (!has_fast_elements()) return this; |
| 2362 Object* obj = CopyDropTransitions(); |
| 2363 if (obj->IsFailure()) return obj; |
| 2364 Map* new_map = Map::cast(obj); |
| 2365 new_map->set_has_fast_elements(false); |
| 2366 return new_map; |
| 2367 } |
| 2368 |
| 2369 |
2338 ACCESSORS(Map, instance_descriptors, DescriptorArray, | 2370 ACCESSORS(Map, instance_descriptors, DescriptorArray, |
2339 kInstanceDescriptorsOffset) | 2371 kInstanceDescriptorsOffset) |
2340 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) | 2372 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) |
2341 ACCESSORS(Map, constructor, Object, kConstructorOffset) | 2373 ACCESSORS(Map, constructor, Object, kConstructorOffset) |
2342 | 2374 |
2343 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) | 2375 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) |
2344 ACCESSORS(JSFunction, literals, FixedArray, kLiteralsOffset) | 2376 ACCESSORS(JSFunction, literals, FixedArray, kLiteralsOffset) |
2345 | 2377 |
2346 ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) | 2378 ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) |
2347 ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) | 2379 ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2831 ASSERT(index >= kDataIndex); // Only implementation data can be set this way. | 2863 ASSERT(index >= kDataIndex); // Only implementation data can be set this way. |
2832 FixedArray::cast(data())->set(index, value); | 2864 FixedArray::cast(data())->set(index, value); |
2833 } | 2865 } |
2834 | 2866 |
2835 | 2867 |
2836 JSObject::ElementsKind JSObject::GetElementsKind() { | 2868 JSObject::ElementsKind JSObject::GetElementsKind() { |
2837 HeapObject* array = elements(); | 2869 HeapObject* array = elements(); |
2838 if (array->IsFixedArray()) { | 2870 if (array->IsFixedArray()) { |
2839 // FAST_ELEMENTS or DICTIONARY_ELEMENTS are both stored in a FixedArray. | 2871 // FAST_ELEMENTS or DICTIONARY_ELEMENTS are both stored in a FixedArray. |
2840 if (array->map() == Heap::fixed_array_map()) { | 2872 if (array->map() == Heap::fixed_array_map()) { |
| 2873 ASSERT(map()->has_fast_elements()); |
2841 return FAST_ELEMENTS; | 2874 return FAST_ELEMENTS; |
2842 } | 2875 } |
2843 ASSERT(array->IsDictionary()); | 2876 ASSERT(array->IsDictionary()); |
| 2877 ASSERT(!map()->has_fast_elements()); |
2844 return DICTIONARY_ELEMENTS; | 2878 return DICTIONARY_ELEMENTS; |
2845 } | 2879 } |
| 2880 ASSERT(!map()->has_fast_elements()); |
2846 if (array->IsExternalArray()) { | 2881 if (array->IsExternalArray()) { |
2847 switch (array->map()->instance_type()) { | 2882 switch (array->map()->instance_type()) { |
2848 case EXTERNAL_BYTE_ARRAY_TYPE: | 2883 case EXTERNAL_BYTE_ARRAY_TYPE: |
2849 return EXTERNAL_BYTE_ELEMENTS; | 2884 return EXTERNAL_BYTE_ELEMENTS; |
2850 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: | 2885 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
2851 return EXTERNAL_UNSIGNED_BYTE_ELEMENTS; | 2886 return EXTERNAL_UNSIGNED_BYTE_ELEMENTS; |
2852 case EXTERNAL_SHORT_ARRAY_TYPE: | 2887 case EXTERNAL_SHORT_ARRAY_TYPE: |
2853 return EXTERNAL_SHORT_ELEMENTS; | 2888 return EXTERNAL_SHORT_ELEMENTS; |
2854 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: | 2889 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
2855 return EXTERNAL_UNSIGNED_SHORT_ELEMENTS; | 2890 return EXTERNAL_UNSIGNED_SHORT_ELEMENTS; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3219 #undef WRITE_INT_FIELD | 3254 #undef WRITE_INT_FIELD |
3220 #undef READ_SHORT_FIELD | 3255 #undef READ_SHORT_FIELD |
3221 #undef WRITE_SHORT_FIELD | 3256 #undef WRITE_SHORT_FIELD |
3222 #undef READ_BYTE_FIELD | 3257 #undef READ_BYTE_FIELD |
3223 #undef WRITE_BYTE_FIELD | 3258 #undef WRITE_BYTE_FIELD |
3224 | 3259 |
3225 | 3260 |
3226 } } // namespace v8::internal | 3261 } } // namespace v8::internal |
3227 | 3262 |
3228 #endif // V8_OBJECTS_INL_H_ | 3263 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |