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

Side by Side Diff: src/factory.cc

Issue 725593002: Install the constructor property on custom prototype before optimizing it as a prototype (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « src/factory.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/factory.h" 5 #include "src/factory.h"
6 6
7 #include "src/allocation-site-scopes.h" 7 #include "src/allocation-site-scopes.h"
8 #include "src/base/bits.h" 8 #include "src/base/bits.h"
9 #include "src/conversions.h" 9 #include "src/conversions.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 bool read_only_prototype) { 1301 bool read_only_prototype) {
1302 Handle<Map> map = read_only_prototype 1302 Handle<Map> map = read_only_prototype
1303 ? isolate()->sloppy_function_with_readonly_prototype_map() 1303 ? isolate()->sloppy_function_with_readonly_prototype_map()
1304 : isolate()->sloppy_function_map(); 1304 : isolate()->sloppy_function_map();
1305 Handle<JSFunction> result = NewFunction(map, name, code); 1305 Handle<JSFunction> result = NewFunction(map, name, code);
1306 result->set_prototype_or_initial_map(*prototype); 1306 result->set_prototype_or_initial_map(*prototype);
1307 return result; 1307 return result;
1308 } 1308 }
1309 1309
1310 1310
1311 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1311 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code,
1312 Handle<Code> code,
1313 Handle<Object> prototype, 1312 Handle<Object> prototype,
1314 InstanceType type, 1313 InstanceType type, int instance_size,
1315 int instance_size, 1314 bool read_only_prototype,
1316 bool read_only_prototype) { 1315 bool install_constructor) {
1317 // Allocate the function 1316 // Allocate the function
1318 Handle<JSFunction> function = NewFunction( 1317 Handle<JSFunction> function = NewFunction(
1319 name, code, prototype, read_only_prototype); 1318 name, code, prototype, read_only_prototype);
1320 1319
1321 ElementsKind elements_kind = 1320 ElementsKind elements_kind =
1322 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; 1321 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS;
1323 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); 1322 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind);
1324 if (prototype->IsTheHole() && !function->shared()->is_generator()) { 1323 if (!function->shared()->is_generator()) {
1325 prototype = NewFunctionPrototype(function); 1324 if (prototype->IsTheHole()) {
1325 prototype = NewFunctionPrototype(function);
1326 } else if (install_constructor) {
1327 JSObject::AddProperty(Handle<JSObject>::cast(prototype),
1328 constructor_string(), function, DONT_ENUM);
1329 }
1326 } 1330 }
1327 1331
1328 JSFunction::SetInitialMap(function, initial_map, 1332 JSFunction::SetInitialMap(function, initial_map,
1329 Handle<JSReceiver>::cast(prototype)); 1333 Handle<JSReceiver>::cast(prototype));
1330 1334
1331 return function; 1335 return function;
1332 } 1336 }
1333 1337
1334 1338
1335 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1339 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 case GlobalProxyType: 2275 case GlobalProxyType:
2272 type = JS_GLOBAL_PROXY_TYPE; 2276 type = JS_GLOBAL_PROXY_TYPE;
2273 instance_size += JSGlobalProxy::kSize; 2277 instance_size += JSGlobalProxy::kSize;
2274 break; 2278 break;
2275 default: 2279 default:
2276 UNREACHABLE(); 2280 UNREACHABLE();
2277 type = JS_OBJECT_TYPE; // Keep the compiler happy. 2281 type = JS_OBJECT_TYPE; // Keep the compiler happy.
2278 break; 2282 break;
2279 } 2283 }
2280 2284
2281 result = NewFunction(empty_string(), code, prototype, type, 2285 result = NewFunction(empty_string(), code, prototype, type, instance_size,
2282 instance_size, obj->read_only_prototype()); 2286 obj->read_only_prototype(), true);
2283 } 2287 }
2284 2288
2285 result->shared()->set_length(obj->length()); 2289 result->shared()->set_length(obj->length());
2286 Handle<Object> class_name(obj->class_name(), isolate()); 2290 Handle<Object> class_name(obj->class_name(), isolate());
2287 if (class_name->IsString()) { 2291 if (class_name->IsString()) {
2288 result->shared()->set_instance_class_name(*class_name); 2292 result->shared()->set_instance_class_name(*class_name);
2289 result->shared()->set_name(*class_name); 2293 result->shared()->set_name(*class_name);
2290 } 2294 }
2291 result->shared()->set_function_data(*obj); 2295 result->shared()->set_function_data(*obj);
2292 result->shared()->set_construct_stub(*construct_stub); 2296 result->shared()->set_construct_stub(*construct_stub);
2293 result->shared()->DontAdaptArguments(); 2297 result->shared()->DontAdaptArguments();
2294 2298
2295 if (obj->remove_prototype()) { 2299 if (obj->remove_prototype()) {
2296 DCHECK(result->shared()->IsApiFunction()); 2300 DCHECK(result->shared()->IsApiFunction());
2297 DCHECK(!result->has_initial_map()); 2301 DCHECK(!result->has_initial_map());
2298 DCHECK(!result->has_prototype()); 2302 DCHECK(!result->has_prototype());
2299 return result; 2303 return result;
2300 } 2304 }
2301 2305
2302 if (prototype->IsTheHole()) {
2303 #ifdef DEBUG 2306 #ifdef DEBUG
2304 LookupIterator it(handle(JSObject::cast(result->prototype())), 2307 LookupIterator it(handle(JSObject::cast(result->prototype())),
2305 constructor_string(), 2308 constructor_string(), LookupIterator::OWN_SKIP_INTERCEPTOR);
2306 LookupIterator::OWN_SKIP_INTERCEPTOR); 2309 MaybeHandle<Object> maybe_prop = Object::GetProperty(&it);
2307 MaybeHandle<Object> maybe_prop = Object::GetProperty(&it); 2310 DCHECK(it.IsFound());
2308 DCHECK(it.IsFound()); 2311 DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result));
2309 DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result));
2310 #endif 2312 #endif
2311 } else {
2312 JSObject::AddProperty(handle(JSObject::cast(result->prototype())),
2313 constructor_string(), result, DONT_ENUM);
2314 }
2315 2313
2316 // Down from here is only valid for API functions that can be used as a 2314 // Down from here is only valid for API functions that can be used as a
2317 // constructor (don't set the "remove prototype" flag). 2315 // constructor (don't set the "remove prototype" flag).
2318 2316
2319 Handle<Map> map(result->initial_map()); 2317 Handle<Map> map(result->initial_map());
2320 2318
2321 // Mark as undetectable if needed. 2319 // Mark as undetectable if needed.
2322 if (obj->undetectable()) { 2320 if (obj->undetectable()) {
2323 map->set_is_undetectable(); 2321 map->set_is_undetectable();
2324 } 2322 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 return Handle<Object>::null(); 2516 return Handle<Object>::null();
2519 } 2517 }
2520 2518
2521 2519
2522 Handle<Object> Factory::ToBoolean(bool value) { 2520 Handle<Object> Factory::ToBoolean(bool value) {
2523 return value ? true_value() : false_value(); 2521 return value ? true_value() : false_value();
2524 } 2522 }
2525 2523
2526 2524
2527 } } // namespace v8::internal 2525 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698