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

Side by Side Diff: src/bootstrapper.cc

Issue 238773009: Set code on the SharedFunctionInfo before creating the function. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/factory.h » ('j') | 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 "bootstrapper.h" 5 #include "bootstrapper.h"
6 6
7 #include "accessors.h" 7 #include "accessors.h"
8 #include "isolate-inl.h" 8 #include "isolate-inl.h"
9 #include "natives.h" 9 #include "natives.h"
10 #include "snapshot.h" 10 #include "snapshot.h"
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 InstanceType type, 348 InstanceType type,
349 int instance_size, 349 int instance_size,
350 Handle<JSObject> prototype, 350 Handle<JSObject> prototype,
351 Builtins::Name call, 351 Builtins::Name call,
352 bool install_initial_map, 352 bool install_initial_map,
353 bool set_instance_class_name) { 353 bool set_instance_class_name) {
354 Isolate* isolate = target->GetIsolate(); 354 Isolate* isolate = target->GetIsolate();
355 Factory* factory = isolate->factory(); 355 Factory* factory = isolate->factory();
356 Handle<String> internalized_name = factory->InternalizeUtf8String(name); 356 Handle<String> internalized_name = factory->InternalizeUtf8String(name);
357 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); 357 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call));
358 Handle<JSFunction> function = prototype.is_null() ? 358 Handle<JSFunction> function = prototype.is_null()
359 factory->NewFunctionWithoutPrototype(internalized_name, call_code) : 359 ? factory->NewFunction(internalized_name, call_code)
360 factory->NewFunctionWithPrototype(internalized_name, 360 : factory->NewFunctionWithPrototype(internalized_name,
361 type, 361 type,
362 instance_size, 362 instance_size,
363 prototype, 363 prototype,
364 call_code, 364 call_code,
365 install_initial_map); 365 install_initial_map);
366 PropertyAttributes attributes; 366 PropertyAttributes attributes;
367 if (target->IsJSBuiltinsObject()) { 367 if (target->IsJSBuiltinsObject()) {
368 attributes = 368 attributes =
369 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); 369 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
370 } else { 370 } else {
371 attributes = DONT_ENUM; 371 attributes = DONT_ENUM;
372 } 372 }
373 JSObject::SetLocalPropertyIgnoreAttributes( 373 JSObject::SetLocalPropertyIgnoreAttributes(
374 target, internalized_name, function, attributes).Check(); 374 target, internalized_name, function, attributes).Check();
375 if (set_instance_class_name) { 375 if (set_instance_class_name) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // The final map for functions. Writeable prototype. 451 // The final map for functions. Writeable prototype.
452 // This map is installed in MakeFunctionInstancePrototypeWritable. 452 // This map is installed in MakeFunctionInstancePrototypeWritable.
453 sloppy_function_map_writable_prototype_ = 453 sloppy_function_map_writable_prototype_ =
454 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); 454 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
455 455
456 Factory* factory = isolate->factory(); 456 Factory* factory = isolate->factory();
457 457
458 Handle<String> object_name = factory->Object_string(); 458 Handle<String> object_name = factory->Object_string();
459 459
460 { // --- O b j e c t --- 460 { // --- O b j e c t ---
461 Handle<JSFunction> object_fun = 461 Handle<JSFunction> object_fun = factory->NewFunctionWithPrototype(
462 factory->NewFunction(object_name, factory->null_value()); 462 object_name, factory->null_value());
463 Handle<Map> object_function_map = 463 Handle<Map> object_function_map =
464 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 464 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
465 object_fun->set_initial_map(*object_function_map); 465 object_fun->set_initial_map(*object_function_map);
466 object_function_map->set_constructor(*object_fun); 466 object_function_map->set_constructor(*object_fun);
467 467
468 native_context()->set_object_function(*object_fun); 468 native_context()->set_object_function(*object_fun);
469 469
470 // Allocate a new prototype for the object function. 470 // Allocate a new prototype for the object function.
471 Handle<JSObject> prototype = factory->NewJSObject( 471 Handle<JSObject> prototype = factory->NewJSObject(
472 isolate->object_function(), 472 isolate->object_function(),
473 TENURED); 473 TENURED);
474 474
475 native_context()->set_initial_object_prototype(*prototype); 475 native_context()->set_initial_object_prototype(*prototype);
476 // For bootstrapping set the array prototype to be the same as the object 476 // For bootstrapping set the array prototype to be the same as the object
477 // prototype, otherwise the missing initial_array_prototype will cause 477 // prototype, otherwise the missing initial_array_prototype will cause
478 // assertions during startup. 478 // assertions during startup.
479 native_context()->set_initial_array_prototype(*prototype); 479 native_context()->set_initial_array_prototype(*prototype);
480 Accessors::FunctionSetPrototype(object_fun, prototype); 480 Accessors::FunctionSetPrototype(object_fun, prototype);
481 } 481 }
482 482
483 // Allocate the empty function as the prototype for function ECMAScript 483 // Allocate the empty function as the prototype for function ECMAScript
484 // 262 15.3.4. 484 // 262 15.3.4.
485 Handle<String> empty_string = 485 Handle<String> empty_string =
486 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); 486 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty"));
487 Handle<Code> code = 487 Handle<Code> code =
488 Handle<Code>(isolate->builtins()->builtin(Builtins::kEmptyFunction)); 488 Handle<Code>(isolate->builtins()->builtin(Builtins::kEmptyFunction));
489 Handle<JSFunction> empty_function = 489 Handle<JSFunction> empty_function = factory->NewFunction(empty_string, code);
490 factory->NewFunctionWithoutPrototype(empty_string, code);
491 490
492 // --- E m p t y --- 491 // --- E m p t y ---
493 Handle<String> source = 492 Handle<String> source =
494 factory->NewStringFromOneByte(STATIC_ASCII_VECTOR("() {}")); 493 factory->NewStringFromOneByte(STATIC_ASCII_VECTOR("() {}"));
495 Handle<Script> script = factory->NewScript(source); 494 Handle<Script> script = factory->NewScript(source);
496 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 495 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
497 empty_function->shared()->set_script(*script); 496 empty_function->shared()->set_script(*script);
498 empty_function->shared()->set_start_position(0); 497 empty_function->shared()->set_start_position(0);
499 empty_function->shared()->set_end_position(source->length()); 498 empty_function->shared()->set_end_position(source->length());
500 empty_function->shared()->DontAdaptArguments(); 499 empty_function->shared()->DontAdaptArguments();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 558 }
560 559
561 560
562 // ECMAScript 5th Edition, 13.2.3 561 // ECMAScript 5th Edition, 13.2.3
563 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { 562 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
564 if (throw_type_error_function.is_null()) { 563 if (throw_type_error_function.is_null()) {
565 Handle<String> name = factory()->InternalizeOneByteString( 564 Handle<String> name = factory()->InternalizeOneByteString(
566 STATIC_ASCII_VECTOR("ThrowTypeError")); 565 STATIC_ASCII_VECTOR("ThrowTypeError"));
567 Handle<Code> code(isolate()->builtins()->builtin( 566 Handle<Code> code(isolate()->builtins()->builtin(
568 Builtins::kStrictModePoisonPill)); 567 Builtins::kStrictModePoisonPill));
569 throw_type_error_function = 568 throw_type_error_function = factory()->NewFunction(name, code);
570 factory()->NewFunctionWithoutPrototype(name, code);
571 throw_type_error_function->set_map(native_context()->sloppy_function_map()); 569 throw_type_error_function->set_map(native_context()->sloppy_function_map());
572 throw_type_error_function->shared()->DontAdaptArguments(); 570 throw_type_error_function->shared()->DontAdaptArguments();
573 571
574 JSObject::PreventExtensions(throw_type_error_function).Assert(); 572 JSObject::PreventExtensions(throw_type_error_function).Assert();
575 } 573 }
576 return throw_type_error_function; 574 return throw_type_error_function;
577 } 575 }
578 576
579 577
580 Handle<Map> Genesis::CreateStrictFunctionMap( 578 Handle<Map> Genesis::CreateStrictFunctionMap(
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 Smi::FromInt(0), 1009 Smi::FromInt(0),
1012 SKIP_WRITE_BARRIER); // It's a Smi. 1010 SKIP_WRITE_BARRIER); // It's a Smi.
1013 initial_map->set_prototype(*proto); 1011 initial_map->set_prototype(*proto);
1014 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), 1012 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
1015 JSRegExp::IRREGEXP, factory->empty_string(), 1013 JSRegExp::IRREGEXP, factory->empty_string(),
1016 JSRegExp::Flags(0), 0); 1014 JSRegExp::Flags(0), 0);
1017 } 1015 }
1018 1016
1019 { // -- J S O N 1017 { // -- J S O N
1020 Handle<String> name = factory->InternalizeUtf8String("JSON"); 1018 Handle<String> name = factory->InternalizeUtf8String("JSON");
1021 Handle<JSFunction> cons = factory->NewFunction(name, 1019 Handle<JSFunction> cons = factory->NewFunctionWithPrototype(
1022 factory->the_hole_value()); 1020 name, factory->the_hole_value());
1023 JSFunction::SetInstancePrototype(cons, 1021 JSFunction::SetInstancePrototype(cons,
1024 Handle<Object>(native_context()->initial_object_prototype(), isolate)); 1022 Handle<Object>(native_context()->initial_object_prototype(), isolate));
1025 cons->SetInstanceClassName(*name); 1023 cons->SetInstanceClassName(*name);
1026 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); 1024 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED);
1027 ASSERT(json_object->IsJSObject()); 1025 ASSERT(json_object->IsJSObject());
1028 JSObject::SetLocalPropertyIgnoreAttributes( 1026 JSObject::SetLocalPropertyIgnoreAttributes(
1029 global, name, json_object, DONT_ENUM).Check(); 1027 global, name, json_object, DONT_ENUM).Check();
1030 native_context()->set_json_object(*json_object); 1028 native_context()->set_json_object(*json_object);
1031 } 1029 }
1032 1030
(...skipping 25 matching lines...) Expand all
1058 Builtins::kIllegal, true, true); 1056 Builtins::kIllegal, true, true);
1059 native_context()->set_data_view_fun(*data_view_fun); 1057 native_context()->set_data_view_fun(*data_view_fun);
1060 } 1058 }
1061 1059
1062 { // --- arguments_boilerplate_ 1060 { // --- arguments_boilerplate_
1063 // Make sure we can recognize argument objects at runtime. 1061 // Make sure we can recognize argument objects at runtime.
1064 // This is done by introducing an anonymous function with 1062 // This is done by introducing an anonymous function with
1065 // class_name equals 'Arguments'. 1063 // class_name equals 'Arguments'.
1066 Handle<String> arguments_string = factory->InternalizeOneByteString( 1064 Handle<String> arguments_string = factory->InternalizeOneByteString(
1067 STATIC_ASCII_VECTOR("Arguments")); 1065 STATIC_ASCII_VECTOR("Arguments"));
1068 Handle<Code> code = Handle<Code>( 1066 Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal));
1069 isolate->builtins()->builtin(Builtins::kIllegal)); 1067 Handle<JSObject> prototype(
1070 Handle<JSObject> prototype = 1068 JSObject::cast(native_context()->object_function()->prototype()));
1071 Handle<JSObject>(
1072 JSObject::cast(native_context()->object_function()->prototype()));
1073 1069
1074 Handle<JSFunction> function = 1070 Handle<JSFunction> function =
1075 factory->NewFunctionWithPrototype(arguments_string, 1071 factory->NewFunctionWithPrototype(arguments_string,
1076 JS_OBJECT_TYPE, 1072 JS_OBJECT_TYPE,
1077 JSObject::kHeaderSize, 1073 JSObject::kHeaderSize,
1078 prototype, 1074 prototype,
1079 code, 1075 code,
1080 false); 1076 false);
1081 ASSERT(!function->has_initial_map()); 1077 ASSERT(!function->has_initial_map());
1082 function->shared()->set_instance_class_name(*arguments_string); 1078 function->shared()->set_instance_class_name(*arguments_string);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 Handle<String> builtins_string = 1640 Handle<String> builtins_string =
1645 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); 1641 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins"));
1646 JSObject::SetLocalPropertyIgnoreAttributes( 1642 JSObject::SetLocalPropertyIgnoreAttributes(
1647 builtins, builtins_string, builtins, attributes).Check(); 1643 builtins, builtins_string, builtins, attributes).Check();
1648 1644
1649 // Set up the reference from the global object to the builtins object. 1645 // Set up the reference from the global object to the builtins object.
1650 JSGlobalObject::cast(native_context()->global_object())-> 1646 JSGlobalObject::cast(native_context()->global_object())->
1651 set_builtins(*builtins); 1647 set_builtins(*builtins);
1652 1648
1653 // Create a bridge function that has context in the native context. 1649 // Create a bridge function that has context in the native context.
1654 Handle<JSFunction> bridge = 1650 Handle<JSFunction> bridge = factory()->NewFunctionWithPrototype(
1655 factory()->NewFunction(factory()->empty_string(), 1651 factory()->empty_string(), factory()->undefined_value());
1656 factory()->undefined_value());
1657 ASSERT(bridge->context() == *isolate()->native_context()); 1652 ASSERT(bridge->context() == *isolate()->native_context());
1658 1653
1659 // Allocate the builtins context. 1654 // Allocate the builtins context.
1660 Handle<Context> context = 1655 Handle<Context> context =
1661 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); 1656 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
1662 context->set_global_object(*builtins); // override builtins global object 1657 context->set_global_object(*builtins); // override builtins global object
1663 1658
1664 native_context()->set_runtime_context(*context); 1659 native_context()->set_runtime_context(*context);
1665 1660
1666 { // -- S c r i p t 1661 { // -- S c r i p t
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 return from + sizeof(NestingCounterType); 2655 return from + sizeof(NestingCounterType);
2661 } 2656 }
2662 2657
2663 2658
2664 // Called when the top-level V8 mutex is destroyed. 2659 // Called when the top-level V8 mutex is destroyed.
2665 void Bootstrapper::FreeThreadResources() { 2660 void Bootstrapper::FreeThreadResources() {
2666 ASSERT(!IsActive()); 2661 ASSERT(!IsActive());
2667 } 2662 }
2668 2663
2669 } } // namespace v8::internal 2664 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698