OLD | NEW |
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 InstanceType type, | 351 InstanceType type, |
352 int instance_size, | 352 int instance_size, |
353 MaybeHandle<JSObject> maybe_prototype, | 353 MaybeHandle<JSObject> maybe_prototype, |
354 Builtins::Name call) { | 354 Builtins::Name call) { |
355 Isolate* isolate = target->GetIsolate(); | 355 Isolate* isolate = target->GetIsolate(); |
356 Factory* factory = isolate->factory(); | 356 Factory* factory = isolate->factory(); |
357 Handle<String> internalized_name = factory->InternalizeUtf8String(name); | 357 Handle<String> internalized_name = factory->InternalizeUtf8String(name); |
358 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); | 358 Handle<Code> call_code = Handle<Code>(isolate->builtins()->builtin(call)); |
359 Handle<JSObject> prototype; | 359 Handle<JSObject> prototype; |
360 Handle<JSFunction> function = maybe_prototype.ToHandle(&prototype) | 360 Handle<JSFunction> function = maybe_prototype.ToHandle(&prototype) |
361 ? factory->NewFunction(prototype, internalized_name, type, | 361 ? factory->NewFunction(internalized_name, call_code, prototype, |
362 instance_size, call_code) | 362 type, instance_size) |
363 : factory->NewFunction(internalized_name, call_code); | 363 : factory->NewFunctionWithoutPrototype(internalized_name, call_code); |
364 PropertyAttributes attributes; | 364 PropertyAttributes attributes; |
365 if (target->IsJSBuiltinsObject()) { | 365 if (target->IsJSBuiltinsObject()) { |
366 attributes = | 366 attributes = |
367 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 367 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
368 } else { | 368 } else { |
369 attributes = DONT_ENUM; | 369 attributes = DONT_ENUM; |
370 } | 370 } |
371 JSObject::SetLocalPropertyIgnoreAttributes( | 371 JSObject::SetLocalPropertyIgnoreAttributes( |
372 target, internalized_name, function, attributes).Check(); | 372 target, internalized_name, function, attributes).Check(); |
373 if (target->IsJSGlobalObject()) { | 373 if (target->IsJSGlobalObject()) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 // assertions during startup. | 481 // assertions during startup. |
482 native_context()->set_initial_array_prototype(*prototype); | 482 native_context()->set_initial_array_prototype(*prototype); |
483 Accessors::FunctionSetPrototype(object_fun, prototype); | 483 Accessors::FunctionSetPrototype(object_fun, prototype); |
484 } | 484 } |
485 | 485 |
486 // Allocate the empty function as the prototype for function ECMAScript | 486 // Allocate the empty function as the prototype for function ECMAScript |
487 // 262 15.3.4. | 487 // 262 15.3.4. |
488 Handle<String> empty_string = | 488 Handle<String> empty_string = |
489 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); | 489 factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); |
490 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); | 490 Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); |
491 Handle<JSFunction> empty_function = factory->NewFunction(empty_string, code); | 491 Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype( |
| 492 empty_string, code); |
492 | 493 |
493 // --- E m p t y --- | 494 // --- E m p t y --- |
494 Handle<String> source = factory->NewStringFromStaticAscii("() {}"); | 495 Handle<String> source = factory->NewStringFromStaticAscii("() {}"); |
495 Handle<Script> script = factory->NewScript(source); | 496 Handle<Script> script = factory->NewScript(source); |
496 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 497 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
497 empty_function->shared()->set_script(*script); | 498 empty_function->shared()->set_script(*script); |
498 empty_function->shared()->set_start_position(0); | 499 empty_function->shared()->set_start_position(0); |
499 empty_function->shared()->set_end_position(source->length()); | 500 empty_function->shared()->set_end_position(source->length()); |
500 empty_function->shared()->DontAdaptArguments(); | 501 empty_function->shared()->DontAdaptArguments(); |
501 | 502 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 563 } |
563 | 564 |
564 | 565 |
565 // ECMAScript 5th Edition, 13.2.3 | 566 // ECMAScript 5th Edition, 13.2.3 |
566 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { | 567 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { |
567 if (throw_type_error_function.is_null()) { | 568 if (throw_type_error_function.is_null()) { |
568 Handle<String> name = factory()->InternalizeOneByteString( | 569 Handle<String> name = factory()->InternalizeOneByteString( |
569 STATIC_ASCII_VECTOR("ThrowTypeError")); | 570 STATIC_ASCII_VECTOR("ThrowTypeError")); |
570 Handle<Code> code(isolate()->builtins()->builtin( | 571 Handle<Code> code(isolate()->builtins()->builtin( |
571 Builtins::kStrictModePoisonPill)); | 572 Builtins::kStrictModePoisonPill)); |
572 throw_type_error_function = factory()->NewFunction(name, code); | 573 throw_type_error_function = factory()->NewFunctionWithoutPrototype( |
| 574 name, code); |
573 throw_type_error_function->set_map(native_context()->sloppy_function_map()); | 575 throw_type_error_function->set_map(native_context()->sloppy_function_map()); |
574 throw_type_error_function->shared()->DontAdaptArguments(); | 576 throw_type_error_function->shared()->DontAdaptArguments(); |
575 | 577 |
576 JSObject::PreventExtensions(throw_type_error_function).Assert(); | 578 JSObject::PreventExtensions(throw_type_error_function).Assert(); |
577 } | 579 } |
578 return throw_type_error_function; | 580 return throw_type_error_function; |
579 } | 581 } |
580 | 582 |
581 | 583 |
582 Handle<Map> Genesis::CreateStrictFunctionMap( | 584 Handle<Map> Genesis::CreateStrictFunctionMap( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 js_global_template = | 703 js_global_template = |
702 Handle<ObjectTemplateInfo>::cast(proto_template); | 704 Handle<ObjectTemplateInfo>::cast(proto_template); |
703 } | 705 } |
704 } | 706 } |
705 | 707 |
706 if (js_global_template.is_null()) { | 708 if (js_global_template.is_null()) { |
707 Handle<String> name = Handle<String>(heap()->empty_string()); | 709 Handle<String> name = Handle<String>(heap()->empty_string()); |
708 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( | 710 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( |
709 Builtins::kIllegal)); | 711 Builtins::kIllegal)); |
710 js_global_function = factory()->NewFunction( | 712 js_global_function = factory()->NewFunction( |
711 name, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize, code); | 713 name, code, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize); |
712 // Change the constructor property of the prototype of the | 714 // Change the constructor property of the prototype of the |
713 // hidden global function to refer to the Object function. | 715 // hidden global function to refer to the Object function. |
714 Handle<JSObject> prototype = | 716 Handle<JSObject> prototype = |
715 Handle<JSObject>( | 717 Handle<JSObject>( |
716 JSObject::cast(js_global_function->instance_prototype())); | 718 JSObject::cast(js_global_function->instance_prototype())); |
717 JSObject::SetLocalPropertyIgnoreAttributes( | 719 JSObject::SetLocalPropertyIgnoreAttributes( |
718 prototype, factory()->constructor_string(), | 720 prototype, factory()->constructor_string(), |
719 isolate()->object_function(), NONE).Check(); | 721 isolate()->object_function(), NONE).Check(); |
720 } else { | 722 } else { |
721 Handle<FunctionTemplateInfo> js_global_constructor( | 723 Handle<FunctionTemplateInfo> js_global_constructor( |
(...skipping 12 matching lines...) Expand all Loading... |
734 *inner_global_out = inner_global; | 736 *inner_global_out = inner_global; |
735 } | 737 } |
736 | 738 |
737 // Step 2: create or re-initialize the global proxy object. | 739 // Step 2: create or re-initialize the global proxy object. |
738 Handle<JSFunction> global_proxy_function; | 740 Handle<JSFunction> global_proxy_function; |
739 if (global_template.IsEmpty()) { | 741 if (global_template.IsEmpty()) { |
740 Handle<String> name = Handle<String>(heap()->empty_string()); | 742 Handle<String> name = Handle<String>(heap()->empty_string()); |
741 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( | 743 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin( |
742 Builtins::kIllegal)); | 744 Builtins::kIllegal)); |
743 global_proxy_function = factory()->NewFunction( | 745 global_proxy_function = factory()->NewFunction( |
744 name, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize, code); | 746 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize); |
745 } else { | 747 } else { |
746 Handle<ObjectTemplateInfo> data = | 748 Handle<ObjectTemplateInfo> data = |
747 v8::Utils::OpenHandle(*global_template); | 749 v8::Utils::OpenHandle(*global_template); |
748 Handle<FunctionTemplateInfo> global_constructor( | 750 Handle<FunctionTemplateInfo> global_constructor( |
749 FunctionTemplateInfo::cast(data->constructor())); | 751 FunctionTemplateInfo::cast(data->constructor())); |
750 global_proxy_function = | 752 global_proxy_function = |
751 factory()->CreateApiFunction(global_constructor, | 753 factory()->CreateApiFunction(global_constructor, |
752 factory()->the_hole_value(), | 754 factory()->the_hole_value(), |
753 factory()->OuterGlobalObject); | 755 factory()->OuterGlobalObject); |
754 } | 756 } |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 isolate->initial_object_prototype(), Builtins::kIllegal); | 1079 isolate->initial_object_prototype(), Builtins::kIllegal); |
1078 | 1080 |
1079 { // --- arguments_boilerplate_ | 1081 { // --- arguments_boilerplate_ |
1080 // Make sure we can recognize argument objects at runtime. | 1082 // Make sure we can recognize argument objects at runtime. |
1081 // This is done by introducing an anonymous function with | 1083 // This is done by introducing an anonymous function with |
1082 // class_name equals 'Arguments'. | 1084 // class_name equals 'Arguments'. |
1083 Handle<String> arguments_string = factory->InternalizeOneByteString( | 1085 Handle<String> arguments_string = factory->InternalizeOneByteString( |
1084 STATIC_ASCII_VECTOR("Arguments")); | 1086 STATIC_ASCII_VECTOR("Arguments")); |
1085 Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal)); | 1087 Handle<Code> code(isolate->builtins()->builtin(Builtins::kIllegal)); |
1086 | 1088 |
1087 Handle<JSFunction> function = factory->NewFunction(arguments_string, code); | 1089 Handle<JSFunction> function = factory->NewFunctionWithoutPrototype( |
| 1090 arguments_string, code); |
1088 ASSERT(!function->has_initial_map()); | 1091 ASSERT(!function->has_initial_map()); |
1089 function->shared()->set_instance_class_name(*arguments_string); | 1092 function->shared()->set_instance_class_name(*arguments_string); |
1090 function->shared()->set_expected_nof_properties(2); | 1093 function->shared()->set_expected_nof_properties(2); |
1091 function->set_prototype_or_initial_map( | 1094 function->set_prototype_or_initial_map( |
1092 native_context()->object_function()->prototype()); | 1095 native_context()->object_function()->prototype()); |
1093 Handle<JSObject> result = factory->NewJSObject(function); | 1096 Handle<JSObject> result = factory->NewJSObject(function); |
1094 | 1097 |
1095 native_context()->set_sloppy_arguments_boilerplate(*result); | 1098 native_context()->set_sloppy_arguments_boilerplate(*result); |
1096 // Note: length must be added as the first property and | 1099 // Note: length must be added as the first property and |
1097 // callee must be added as the second property. | 1100 // callee must be added as the second property. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 ASSERT(result->HasFastProperties()); | 1220 ASSERT(result->HasFastProperties()); |
1218 ASSERT(result->HasFastObjectElements()); | 1221 ASSERT(result->HasFastObjectElements()); |
1219 #endif | 1222 #endif |
1220 } | 1223 } |
1221 | 1224 |
1222 { // --- context extension | 1225 { // --- context extension |
1223 // Create a function for the context extension objects. | 1226 // Create a function for the context extension objects. |
1224 Handle<Code> code = Handle<Code>( | 1227 Handle<Code> code = Handle<Code>( |
1225 isolate->builtins()->builtin(Builtins::kIllegal)); | 1228 isolate->builtins()->builtin(Builtins::kIllegal)); |
1226 Handle<JSFunction> context_extension_fun = factory->NewFunction( | 1229 Handle<JSFunction> context_extension_fun = factory->NewFunction( |
1227 factory->empty_string(), JS_CONTEXT_EXTENSION_OBJECT_TYPE, | 1230 factory->empty_string(), code, JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
1228 JSObject::kHeaderSize, code); | 1231 JSObject::kHeaderSize); |
1229 | 1232 |
1230 Handle<String> name = factory->InternalizeOneByteString( | 1233 Handle<String> name = factory->InternalizeOneByteString( |
1231 STATIC_ASCII_VECTOR("context_extension")); | 1234 STATIC_ASCII_VECTOR("context_extension")); |
1232 context_extension_fun->shared()->set_instance_class_name(*name); | 1235 context_extension_fun->shared()->set_instance_class_name(*name); |
1233 native_context()->set_context_extension_function(*context_extension_fun); | 1236 native_context()->set_context_extension_function(*context_extension_fun); |
1234 } | 1237 } |
1235 | 1238 |
1236 | 1239 |
1237 { | 1240 { |
1238 // Set up the call-as-function delegate. | 1241 // Set up the call-as-function delegate. |
1239 Handle<Code> code = | 1242 Handle<Code> code = |
1240 Handle<Code>(isolate->builtins()->builtin( | 1243 Handle<Code>(isolate->builtins()->builtin( |
1241 Builtins::kHandleApiCallAsFunction)); | 1244 Builtins::kHandleApiCallAsFunction)); |
1242 Handle<JSFunction> delegate = factory->NewFunction( | 1245 Handle<JSFunction> delegate = factory->NewFunction( |
1243 factory->empty_string(), JS_OBJECT_TYPE, JSObject::kHeaderSize, code); | 1246 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
1244 native_context()->set_call_as_function_delegate(*delegate); | 1247 native_context()->set_call_as_function_delegate(*delegate); |
1245 delegate->shared()->DontAdaptArguments(); | 1248 delegate->shared()->DontAdaptArguments(); |
1246 } | 1249 } |
1247 | 1250 |
1248 { | 1251 { |
1249 // Set up the call-as-constructor delegate. | 1252 // Set up the call-as-constructor delegate. |
1250 Handle<Code> code = | 1253 Handle<Code> code = |
1251 Handle<Code>(isolate->builtins()->builtin( | 1254 Handle<Code>(isolate->builtins()->builtin( |
1252 Builtins::kHandleApiCallAsConstructor)); | 1255 Builtins::kHandleApiCallAsConstructor)); |
1253 Handle<JSFunction> delegate = factory->NewFunction( | 1256 Handle<JSFunction> delegate = factory->NewFunction( |
1254 factory->empty_string(), JS_OBJECT_TYPE, JSObject::kHeaderSize, code); | 1257 factory->empty_string(), code, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
1255 native_context()->set_call_as_constructor_delegate(*delegate); | 1258 native_context()->set_call_as_constructor_delegate(*delegate); |
1256 delegate->shared()->DontAdaptArguments(); | 1259 delegate->shared()->DontAdaptArguments(); |
1257 } | 1260 } |
1258 | 1261 |
1259 // Initialize the embedder data slot. | 1262 // Initialize the embedder data slot. |
1260 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); | 1263 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
1261 native_context()->set_embedder_data(*embedder_data); | 1264 native_context()->set_embedder_data(*embedder_data); |
1262 } | 1265 } |
1263 | 1266 |
1264 | 1267 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 | 1607 |
1605 bool Genesis::InstallNatives() { | 1608 bool Genesis::InstallNatives() { |
1606 HandleScope scope(isolate()); | 1609 HandleScope scope(isolate()); |
1607 | 1610 |
1608 // Create a function for the builtins object. Allocate space for the | 1611 // Create a function for the builtins object. Allocate space for the |
1609 // JavaScript builtins, a reference to the builtins object | 1612 // JavaScript builtins, a reference to the builtins object |
1610 // (itself) and a reference to the native_context directly in the object. | 1613 // (itself) and a reference to the native_context directly in the object. |
1611 Handle<Code> code = Handle<Code>( | 1614 Handle<Code> code = Handle<Code>( |
1612 isolate()->builtins()->builtin(Builtins::kIllegal)); | 1615 isolate()->builtins()->builtin(Builtins::kIllegal)); |
1613 Handle<JSFunction> builtins_fun = factory()->NewFunction( | 1616 Handle<JSFunction> builtins_fun = factory()->NewFunction( |
1614 factory()->empty_string(), JS_BUILTINS_OBJECT_TYPE, | 1617 factory()->empty_string(), code, JS_BUILTINS_OBJECT_TYPE, |
1615 JSBuiltinsObject::kSize, code); | 1618 JSBuiltinsObject::kSize); |
1616 | 1619 |
1617 Handle<String> name = | 1620 Handle<String> name = |
1618 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); | 1621 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); |
1619 builtins_fun->shared()->set_instance_class_name(*name); | 1622 builtins_fun->shared()->set_instance_class_name(*name); |
1620 builtins_fun->initial_map()->set_dictionary_map(true); | 1623 builtins_fun->initial_map()->set_dictionary_map(true); |
1621 builtins_fun->initial_map()->set_prototype(heap()->null_value()); | 1624 builtins_fun->initial_map()->set_prototype(heap()->null_value()); |
1622 | 1625 |
1623 // Allocate the builtins object. | 1626 // Allocate the builtins object. |
1624 Handle<JSBuiltinsObject> builtins = | 1627 Handle<JSBuiltinsObject> builtins = |
1625 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); | 1628 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 return from + sizeof(NestingCounterType); | 2652 return from + sizeof(NestingCounterType); |
2650 } | 2653 } |
2651 | 2654 |
2652 | 2655 |
2653 // Called when the top-level V8 mutex is destroyed. | 2656 // Called when the top-level V8 mutex is destroyed. |
2654 void Bootstrapper::FreeThreadResources() { | 2657 void Bootstrapper::FreeThreadResources() { |
2655 ASSERT(!IsActive()); | 2658 ASSERT(!IsActive()); |
2656 } | 2659 } |
2657 | 2660 |
2658 } } // namespace v8::internal | 2661 } } // namespace v8::internal |
OLD | NEW |