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

Side by Side Diff: src/objects.cc

Issue 1510753005: Fix Function subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased and updated reflect-construct test Created 5 years 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
OLDNEW
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
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
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 switch (language_mode) {
9283 case STRICT:
9284 transition_symbol = factory->strict_function_transition_symbol();
9285 break;
9286 case STRONG:
9287 transition_symbol = factory->strong_function_transition_symbol();
9288 break;
9289 default:
Toon Verwaest 2015/12/10 13:10:54 case SLOPPY:
Igor Sheludko 2015/12/10 16:39:47 Does not work: this forces me to add "case STRONG_
9290 UNREACHABLE();
9291 break;
9292 }
9293 Map* maybe_transition =
9294 TransitionArray::SearchSpecial(*initial_map, *transition_symbol);
9295 if (maybe_transition != NULL) {
9296 return handle(maybe_transition, isolate);
9297 }
9298
9299 // Create new map taking descriptors from the |function_map| and all
9300 // the other details from the |initial_map|.
9301 Handle<Map> map =
9302 Map::CopyInitialMap(function_map, initial_map->instance_size(),
9303 initial_map->GetInObjectProperties(),
9304 initial_map->unused_property_fields());
9305 map->SetConstructor(initial_map->GetConstructor());
9306 map->set_prototype(initial_map->prototype());
9307
Toon Verwaest 2015/12/10 13:10:54 if (TransitionArray::CanHaveMoreTransitions(initia
Igor Sheludko 2015/12/10 16:39:47 Done.
9308 Map::ConnectTransition(initial_map, map, transition_symbol,
9309 SPECIAL_TRANSITION);
9310 return map;
9311 }
9312
9313
9258 Handle<Map> Map::CopyForObserved(Handle<Map> map) { 9314 Handle<Map> Map::CopyForObserved(Handle<Map> map) {
9259 DCHECK(!map->is_observed()); 9315 DCHECK(!map->is_observed());
9260 9316
9261 Isolate* isolate = map->GetIsolate(); 9317 Isolate* isolate = map->GetIsolate();
9262 9318
9263 bool insert_transition = 9319 bool insert_transition =
9264 TransitionArray::CanHaveMoreTransitions(map) && !map->is_prototype_map(); 9320 TransitionArray::CanHaveMoreTransitions(map) && !map->is_prototype_map();
9265 9321
9266 if (insert_transition) { 9322 if (insert_transition) {
9267 Handle<Map> new_map = CopyForTransition(map, "CopyForObserved"); 9323 Handle<Map> new_map = CopyForTransition(map, "CopyForObserved");
(...skipping 9895 matching lines...) Expand 10 before | Expand all | Expand 10 after
19163 if (cell->value() != *new_value) { 19219 if (cell->value() != *new_value) {
19164 cell->set_value(*new_value); 19220 cell->set_value(*new_value);
19165 Isolate* isolate = cell->GetIsolate(); 19221 Isolate* isolate = cell->GetIsolate();
19166 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19222 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19167 isolate, DependentCode::kPropertyCellChangedGroup); 19223 isolate, DependentCode::kPropertyCellChangedGroup);
19168 } 19224 }
19169 } 19225 }
19170 19226
19171 } // namespace internal 19227 } // namespace internal
19172 } // namespace v8 19228 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698