OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 8970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8981 #endif | 8981 #endif |
8982 | 8982 |
8983 return result; | 8983 return result; |
8984 } | 8984 } |
8985 | 8985 |
8986 | 8986 |
8987 Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, | 8987 Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, |
8988 int in_object_properties, | 8988 int in_object_properties, |
8989 int unused_property_fields) { | 8989 int unused_property_fields) { |
8990 #ifdef DEBUG | 8990 #ifdef DEBUG |
| 8991 Isolate* isolate = map->GetIsolate(); |
| 8992 // Strict and strong function maps have Function as a constructor but the |
| 8993 // Function's initial map is a sloppy function map. Same holds for |
| 8994 // GeneratorFunction and its initial map. |
8991 Object* constructor = map->GetConstructor(); | 8995 Object* constructor = map->GetConstructor(); |
8992 DCHECK(constructor->IsJSFunction()); | 8996 DCHECK(constructor->IsJSFunction()); |
8993 DCHECK_EQ(*map, JSFunction::cast(constructor)->initial_map()); | 8997 DCHECK(*map == JSFunction::cast(constructor)->initial_map() || |
| 8998 *map == *isolate->strict_function_map() || |
| 8999 *map == *isolate->strong_function_map() || |
| 9000 *map == *isolate->strict_generator_function_map() || |
| 9001 *map == *isolate->strong_generator_function_map()); |
8994 #endif | 9002 #endif |
8995 // Initial maps must always own their descriptors and it's descriptor array | 9003 // Initial maps must always own their descriptors and it's descriptor array |
8996 // does not contain descriptors that do not belong to the map. | 9004 // does not contain descriptors that do not belong to the map. |
8997 DCHECK(map->owns_descriptors()); | 9005 DCHECK(map->owns_descriptors()); |
8998 DCHECK_EQ(map->NumberOfOwnDescriptors(), | 9006 DCHECK_EQ(map->NumberOfOwnDescriptors(), |
8999 map->instance_descriptors()->number_of_descriptors()); | 9007 map->instance_descriptors()->number_of_descriptors()); |
9000 | 9008 |
9001 Handle<Map> result = RawCopy(map, instance_size); | 9009 Handle<Map> result = RawCopy(map, instance_size); |
9002 | 9010 |
9003 // Please note instance_type and instance_size are set when allocated. | 9011 // Please note instance_type and instance_size are set when allocated. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9248 return new_map; | 9256 return new_map; |
9249 } | 9257 } |
9250 | 9258 |
9251 // Create a new free-floating map only if we are not allowed to store it. | 9259 // Create a new free-floating map only if we are not allowed to store it. |
9252 Handle<Map> new_map = Copy(map, "CopyAsElementsKind"); | 9260 Handle<Map> new_map = Copy(map, "CopyAsElementsKind"); |
9253 new_map->set_elements_kind(kind); | 9261 new_map->set_elements_kind(kind); |
9254 return new_map; | 9262 return new_map; |
9255 } | 9263 } |
9256 | 9264 |
9257 | 9265 |
| 9266 Handle<Map> Map::AsLanguageMode(Handle<Map> initial_map, |
| 9267 LanguageMode language_mode, FunctionKind kind) { |
| 9268 DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type()); |
| 9269 // Initial map for sloppy mode function is stored in the function |
| 9270 // constructor. Initial maps for strict and strong modes are cached as |
| 9271 // special transitions using |strict_function_transition_symbol| and |
| 9272 // |strong_function_transition_symbol| respectively as a key. |
| 9273 if (language_mode == SLOPPY) return initial_map; |
| 9274 Isolate* isolate = initial_map->GetIsolate(); |
| 9275 Factory* factory = isolate->factory(); |
| 9276 Handle<Symbol> transition_symbol; |
| 9277 |
| 9278 int map_index = Context::FunctionMapIndex(language_mode, kind); |
| 9279 Handle<Map> function_map( |
| 9280 Map::cast(isolate->native_context()->get(map_index))); |
| 9281 |
| 9282 STATIC_ASSERT(LANGUAGE_END == 3); |
| 9283 switch (language_mode) { |
| 9284 case STRICT: |
| 9285 transition_symbol = factory->strict_function_transition_symbol(); |
| 9286 break; |
| 9287 case STRONG: |
| 9288 transition_symbol = factory->strong_function_transition_symbol(); |
| 9289 break; |
| 9290 default: |
| 9291 UNREACHABLE(); |
| 9292 break; |
| 9293 } |
| 9294 Map* maybe_transition = |
| 9295 TransitionArray::SearchSpecial(*initial_map, *transition_symbol); |
| 9296 if (maybe_transition != NULL) { |
| 9297 return handle(maybe_transition, isolate); |
| 9298 } |
| 9299 |
| 9300 // Create new map taking descriptors from the |function_map| and all |
| 9301 // the other details from the |initial_map|. |
| 9302 Handle<Map> map = |
| 9303 Map::CopyInitialMap(function_map, initial_map->instance_size(), |
| 9304 initial_map->GetInObjectProperties(), |
| 9305 initial_map->unused_property_fields()); |
| 9306 map->SetConstructor(initial_map->GetConstructor()); |
| 9307 map->set_prototype(initial_map->prototype()); |
| 9308 |
| 9309 if (TransitionArray::CanHaveMoreTransitions(initial_map)) { |
| 9310 Map::ConnectTransition(initial_map, map, transition_symbol, |
| 9311 SPECIAL_TRANSITION); |
| 9312 } |
| 9313 return map; |
| 9314 } |
| 9315 |
| 9316 |
9258 Handle<Map> Map::CopyForObserved(Handle<Map> map) { | 9317 Handle<Map> Map::CopyForObserved(Handle<Map> map) { |
9259 DCHECK(!map->is_observed()); | 9318 DCHECK(!map->is_observed()); |
9260 | 9319 |
9261 Isolate* isolate = map->GetIsolate(); | 9320 Isolate* isolate = map->GetIsolate(); |
9262 | 9321 |
9263 bool insert_transition = | 9322 bool insert_transition = |
9264 TransitionArray::CanHaveMoreTransitions(map) && !map->is_prototype_map(); | 9323 TransitionArray::CanHaveMoreTransitions(map) && !map->is_prototype_map(); |
9265 | 9324 |
9266 if (insert_transition) { | 9325 if (insert_transition) { |
9267 Handle<Map> new_map = CopyForTransition(map, "CopyForObserved"); | 9326 Handle<Map> new_map = CopyForTransition(map, "CopyForObserved"); |
(...skipping 9895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19163 if (cell->value() != *new_value) { | 19222 if (cell->value() != *new_value) { |
19164 cell->set_value(*new_value); | 19223 cell->set_value(*new_value); |
19165 Isolate* isolate = cell->GetIsolate(); | 19224 Isolate* isolate = cell->GetIsolate(); |
19166 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19225 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19167 isolate, DependentCode::kPropertyCellChangedGroup); | 19226 isolate, DependentCode::kPropertyCellChangedGroup); |
19168 } | 19227 } |
19169 } | 19228 } |
19170 | 19229 |
19171 } // namespace internal | 19230 } // namespace internal |
19172 } // namespace v8 | 19231 } // namespace v8 |
OLD | NEW |