| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 Handle<JSFunction> object_fun = | 448 Handle<JSFunction> object_fun = |
| 449 Factory::NewFunction(object_name, Factory::null_value()); | 449 Factory::NewFunction(object_name, Factory::null_value()); |
| 450 Handle<Map> object_function_map = | 450 Handle<Map> object_function_map = |
| 451 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 451 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 452 object_fun->set_initial_map(*object_function_map); | 452 object_fun->set_initial_map(*object_function_map); |
| 453 object_function_map->set_constructor(*object_fun); | 453 object_function_map->set_constructor(*object_fun); |
| 454 | 454 |
| 455 global_context()->set_object_function(*object_fun); | 455 global_context()->set_object_function(*object_fun); |
| 456 | 456 |
| 457 // Allocate a new prototype for the object function. | 457 // Allocate a new prototype for the object function. |
| 458 Handle<JSObject> prototype = Factory::NewJSObject(Top::object_function(), | 458 Handle<JSObject> prototype = Factory::NewJSObject( |
| 459 TENURED); | 459 Isolate::Current()->object_function(), |
| 460 TENURED); |
| 460 | 461 |
| 461 global_context()->set_initial_object_prototype(*prototype); | 462 global_context()->set_initial_object_prototype(*prototype); |
| 462 SetPrototype(object_fun, prototype); | 463 SetPrototype(object_fun, prototype); |
| 463 object_function_map-> | 464 object_function_map-> |
| 464 set_instance_descriptors(HEAP->empty_descriptor_array()); | 465 set_instance_descriptors(HEAP->empty_descriptor_array()); |
| 465 } | 466 } |
| 466 | 467 |
| 467 // Allocate the empty function as the prototype for function ECMAScript | 468 // Allocate the empty function as the prototype for function ECMAScript |
| 468 // 262 15.3.4. | 469 // 262 15.3.4. |
| 469 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); | 470 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 498 | 499 |
| 499 | 500 |
| 500 void Genesis::CreateRoots() { | 501 void Genesis::CreateRoots() { |
| 501 // Allocate the global context FixedArray first and then patch the | 502 // Allocate the global context FixedArray first and then patch the |
| 502 // closure and extension object later (we need the empty function | 503 // closure and extension object later (we need the empty function |
| 503 // and the global object, but in order to create those, we need the | 504 // and the global object, but in order to create those, we need the |
| 504 // global context). | 505 // global context). |
| 505 global_context_ = | 506 global_context_ = |
| 506 Handle<Context>::cast( | 507 Handle<Context>::cast( |
| 507 GlobalHandles::Create(*Factory::NewGlobalContext())); | 508 GlobalHandles::Create(*Factory::NewGlobalContext())); |
| 508 Top::set_context(*global_context()); | 509 Isolate::Current()->set_context(*global_context()); |
| 509 | 510 |
| 510 // Allocate the message listeners object. | 511 // Allocate the message listeners object. |
| 511 { | 512 { |
| 512 v8::NeanderArray listeners; | 513 v8::NeanderArray listeners; |
| 513 global_context()->set_message_listeners(*listeners.value()); | 514 global_context()->set_message_listeners(*listeners.value()); |
| 514 } | 515 } |
| 515 } | 516 } |
| 516 | 517 |
| 517 | 518 |
| 518 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( | 519 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); | 554 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); |
| 554 js_global_function = | 555 js_global_function = |
| 555 Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE, | 556 Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE, |
| 556 JSGlobalObject::kSize, code, true); | 557 JSGlobalObject::kSize, code, true); |
| 557 // Change the constructor property of the prototype of the | 558 // Change the constructor property of the prototype of the |
| 558 // hidden global function to refer to the Object function. | 559 // hidden global function to refer to the Object function. |
| 559 Handle<JSObject> prototype = | 560 Handle<JSObject> prototype = |
| 560 Handle<JSObject>( | 561 Handle<JSObject>( |
| 561 JSObject::cast(js_global_function->instance_prototype())); | 562 JSObject::cast(js_global_function->instance_prototype())); |
| 562 SetProperty(prototype, Factory::constructor_symbol(), | 563 SetProperty(prototype, Factory::constructor_symbol(), |
| 563 Top::object_function(), NONE); | 564 Isolate::Current()->object_function(), NONE); |
| 564 } else { | 565 } else { |
| 565 Handle<FunctionTemplateInfo> js_global_constructor( | 566 Handle<FunctionTemplateInfo> js_global_constructor( |
| 566 FunctionTemplateInfo::cast(js_global_template->constructor())); | 567 FunctionTemplateInfo::cast(js_global_template->constructor())); |
| 567 js_global_function = | 568 js_global_function = |
| 568 Factory::CreateApiFunction(js_global_constructor, | 569 Factory::CreateApiFunction(js_global_constructor, |
| 569 Factory::InnerGlobalObject); | 570 Factory::InnerGlobalObject); |
| 570 } | 571 } |
| 571 | 572 |
| 572 js_global_function->initial_map()->set_is_hidden_prototype(); | 573 js_global_function->initial_map()->set_is_hidden_prototype(); |
| 573 Handle<GlobalObject> inner_global = | 574 Handle<GlobalObject> inner_global = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 // Set extension and global object. | 656 // Set extension and global object. |
| 656 global_context()->set_extension(*inner_global); | 657 global_context()->set_extension(*inner_global); |
| 657 global_context()->set_global(*inner_global); | 658 global_context()->set_global(*inner_global); |
| 658 // Security setup: Set the security token of the global object to | 659 // Security setup: Set the security token of the global object to |
| 659 // its the inner global. This makes the security check between two | 660 // its the inner global. This makes the security check between two |
| 660 // different contexts fail by default even in case of global | 661 // different contexts fail by default even in case of global |
| 661 // object reinitialization. | 662 // object reinitialization. |
| 662 global_context()->set_security_token(*inner_global); | 663 global_context()->set_security_token(*inner_global); |
| 663 | 664 |
| 664 Handle<String> object_name = Handle<String>(HEAP->Object_symbol()); | 665 Handle<String> object_name = Handle<String>(HEAP->Object_symbol()); |
| 665 SetProperty(inner_global, object_name, Top::object_function(), DONT_ENUM); | 666 SetProperty(inner_global, object_name, |
| 667 Isolate::Current()->object_function(), DONT_ENUM); |
| 666 | 668 |
| 667 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); | 669 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); |
| 668 | 670 |
| 669 // Install global Function object | 671 // Install global Function object |
| 670 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 672 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 671 empty_function, Builtins::Illegal, true); // ECMA native. | 673 empty_function, Builtins::Illegal, true); // ECMA native. |
| 672 | 674 |
| 673 { // --- A r r a y --- | 675 { // --- A r r a y --- |
| 674 Handle<JSFunction> array_function = | 676 Handle<JSFunction> array_function = |
| 675 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, | 677 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
| 676 Top::initial_object_prototype(), Builtins::ArrayCode, | 678 Isolate::Current()->initial_object_prototype(), |
| 677 true); | 679 Builtins::ArrayCode, true); |
| 678 array_function->shared()->set_construct_stub( | 680 array_function->shared()->set_construct_stub( |
| 679 Builtins::builtin(Builtins::ArrayConstructCode)); | 681 Builtins::builtin(Builtins::ArrayConstructCode)); |
| 680 array_function->shared()->DontAdaptArguments(); | 682 array_function->shared()->DontAdaptArguments(); |
| 681 | 683 |
| 682 // This seems a bit hackish, but we need to make sure Array.length | 684 // This seems a bit hackish, but we need to make sure Array.length |
| 683 // is 1. | 685 // is 1. |
| 684 array_function->shared()->set_length(1); | 686 array_function->shared()->set_length(1); |
| 685 Handle<DescriptorArray> array_descriptors = | 687 Handle<DescriptorArray> array_descriptors = |
| 686 Factory::CopyAppendProxyDescriptor( | 688 Factory::CopyAppendProxyDescriptor( |
| 687 Factory::empty_descriptor_array(), | 689 Factory::empty_descriptor_array(), |
| 688 Factory::length_symbol(), | 690 Factory::length_symbol(), |
| 689 Factory::NewProxy(&Accessors::ArrayLength), | 691 Factory::NewProxy(&Accessors::ArrayLength), |
| 690 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); | 692 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); |
| 691 | 693 |
| 692 // Cache the fast JavaScript array map | 694 // Cache the fast JavaScript array map |
| 693 global_context()->set_js_array_map(array_function->initial_map()); | 695 global_context()->set_js_array_map(array_function->initial_map()); |
| 694 global_context()->js_array_map()->set_instance_descriptors( | 696 global_context()->js_array_map()->set_instance_descriptors( |
| 695 *array_descriptors); | 697 *array_descriptors); |
| 696 // array_function is used internally. JS code creating array object should | 698 // array_function is used internally. JS code creating array object should |
| 697 // search for the 'Array' property on the global object and use that one | 699 // search for the 'Array' property on the global object and use that one |
| 698 // as the constructor. 'Array' property on a global object can be | 700 // as the constructor. 'Array' property on a global object can be |
| 699 // overwritten by JS code. | 701 // overwritten by JS code. |
| 700 global_context()->set_array_function(*array_function); | 702 global_context()->set_array_function(*array_function); |
| 701 } | 703 } |
| 702 | 704 |
| 703 { // --- N u m b e r --- | 705 { // --- N u m b e r --- |
| 704 Handle<JSFunction> number_fun = | 706 Handle<JSFunction> number_fun = |
| 705 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 707 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
| 706 Top::initial_object_prototype(), Builtins::Illegal, | 708 Isolate::Current()->initial_object_prototype(), |
| 707 true); | 709 Builtins::Illegal, true); |
| 708 global_context()->set_number_function(*number_fun); | 710 global_context()->set_number_function(*number_fun); |
| 709 } | 711 } |
| 710 | 712 |
| 711 { // --- B o o l e a n --- | 713 { // --- B o o l e a n --- |
| 712 Handle<JSFunction> boolean_fun = | 714 Handle<JSFunction> boolean_fun = |
| 713 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, | 715 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, |
| 714 Top::initial_object_prototype(), Builtins::Illegal, | 716 Isolate::Current()->initial_object_prototype(), |
| 715 true); | 717 Builtins::Illegal, true); |
| 716 global_context()->set_boolean_function(*boolean_fun); | 718 global_context()->set_boolean_function(*boolean_fun); |
| 717 } | 719 } |
| 718 | 720 |
| 719 { // --- S t r i n g --- | 721 { // --- S t r i n g --- |
| 720 Handle<JSFunction> string_fun = | 722 Handle<JSFunction> string_fun = |
| 721 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, | 723 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, |
| 722 Top::initial_object_prototype(), Builtins::Illegal, | 724 Isolate::Current()->initial_object_prototype(), |
| 723 true); | 725 Builtins::Illegal, true); |
| 724 global_context()->set_string_function(*string_fun); | 726 global_context()->set_string_function(*string_fun); |
| 725 // Add 'length' property to strings. | 727 // Add 'length' property to strings. |
| 726 Handle<DescriptorArray> string_descriptors = | 728 Handle<DescriptorArray> string_descriptors = |
| 727 Factory::CopyAppendProxyDescriptor( | 729 Factory::CopyAppendProxyDescriptor( |
| 728 Factory::empty_descriptor_array(), | 730 Factory::empty_descriptor_array(), |
| 729 Factory::length_symbol(), | 731 Factory::length_symbol(), |
| 730 Factory::NewProxy(&Accessors::StringLength), | 732 Factory::NewProxy(&Accessors::StringLength), |
| 731 static_cast<PropertyAttributes>(DONT_ENUM | | 733 static_cast<PropertyAttributes>(DONT_ENUM | |
| 732 DONT_DELETE | | 734 DONT_DELETE | |
| 733 READ_ONLY)); | 735 READ_ONLY)); |
| 734 | 736 |
| 735 Handle<Map> string_map = | 737 Handle<Map> string_map = |
| 736 Handle<Map>(global_context()->string_function()->initial_map()); | 738 Handle<Map>(global_context()->string_function()->initial_map()); |
| 737 string_map->set_instance_descriptors(*string_descriptors); | 739 string_map->set_instance_descriptors(*string_descriptors); |
| 738 } | 740 } |
| 739 | 741 |
| 740 { // --- D a t e --- | 742 { // --- D a t e --- |
| 741 // Builtin functions for Date.prototype. | 743 // Builtin functions for Date.prototype. |
| 742 Handle<JSFunction> date_fun = | 744 Handle<JSFunction> date_fun = |
| 743 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize, | 745 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize, |
| 744 Top::initial_object_prototype(), Builtins::Illegal, | 746 Isolate::Current()->initial_object_prototype(), |
| 745 true); | 747 Builtins::Illegal, true); |
| 746 | 748 |
| 747 global_context()->set_date_function(*date_fun); | 749 global_context()->set_date_function(*date_fun); |
| 748 } | 750 } |
| 749 | 751 |
| 750 | 752 |
| 751 { // -- R e g E x p | 753 { // -- R e g E x p |
| 752 // Builtin functions for RegExp.prototype. | 754 // Builtin functions for RegExp.prototype. |
| 753 Handle<JSFunction> regexp_fun = | 755 Handle<JSFunction> regexp_fun = |
| 754 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, | 756 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
| 755 Top::initial_object_prototype(), Builtins::Illegal, | 757 Isolate::Current()->initial_object_prototype(), |
| 756 true); | 758 Builtins::Illegal, true); |
| 757 global_context()->set_regexp_function(*regexp_fun); | 759 global_context()->set_regexp_function(*regexp_fun); |
| 758 | 760 |
| 759 ASSERT(regexp_fun->has_initial_map()); | 761 ASSERT(regexp_fun->has_initial_map()); |
| 760 Handle<Map> initial_map(regexp_fun->initial_map()); | 762 Handle<Map> initial_map(regexp_fun->initial_map()); |
| 761 | 763 |
| 762 ASSERT_EQ(0, initial_map->inobject_properties()); | 764 ASSERT_EQ(0, initial_map->inobject_properties()); |
| 763 | 765 |
| 764 Handle<DescriptorArray> descriptors = Factory::NewDescriptorArray(5); | 766 Handle<DescriptorArray> descriptors = Factory::NewDescriptorArray(5); |
| 765 PropertyAttributes final = | 767 PropertyAttributes final = |
| 766 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 768 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 | 939 |
| 938 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { | 940 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) { |
| 939 HandleScope scope; | 941 HandleScope scope; |
| 940 #ifdef ENABLE_DEBUGGER_SUPPORT | 942 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 941 Debugger::set_compiling_natives(true); | 943 Debugger::set_compiling_natives(true); |
| 942 #endif | 944 #endif |
| 943 bool result = CompileScriptCached(name, | 945 bool result = CompileScriptCached(name, |
| 944 source, | 946 source, |
| 945 NULL, | 947 NULL, |
| 946 NULL, | 948 NULL, |
| 947 Handle<Context>(Top::context()), | 949 Handle<Context>( |
| 950 Isolate::Current()->context()), |
| 948 true); | 951 true); |
| 949 ASSERT(Top::has_pending_exception() != result); | 952 ASSERT(Isolate::Current()->has_pending_exception() != result); |
| 950 if (!result) Top::clear_pending_exception(); | 953 if (!result) Isolate::Current()->clear_pending_exception(); |
| 951 #ifdef ENABLE_DEBUGGER_SUPPORT | 954 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 952 Debugger::set_compiling_natives(false); | 955 Debugger::set_compiling_natives(false); |
| 953 #endif | 956 #endif |
| 954 return result; | 957 return result; |
| 955 } | 958 } |
| 956 | 959 |
| 957 | 960 |
| 958 bool Genesis::CompileScriptCached(Vector<const char> name, | 961 bool Genesis::CompileScriptCached(Vector<const char> name, |
| 959 Handle<String> source, | 962 Handle<String> source, |
| 960 SourceCodeCache* cache, | 963 SourceCodeCache* cache, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 1067 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 1065 SetProperty(builtins, Factory::LookupAsciiSymbol("global"), | 1068 SetProperty(builtins, Factory::LookupAsciiSymbol("global"), |
| 1066 Handle<Object>(global_context()->global()), attributes); | 1069 Handle<Object>(global_context()->global()), attributes); |
| 1067 | 1070 |
| 1068 // Setup the reference from the global object to the builtins object. | 1071 // Setup the reference from the global object to the builtins object. |
| 1069 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins); | 1072 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins); |
| 1070 | 1073 |
| 1071 // Create a bridge function that has context in the global context. | 1074 // Create a bridge function that has context in the global context. |
| 1072 Handle<JSFunction> bridge = | 1075 Handle<JSFunction> bridge = |
| 1073 Factory::NewFunction(Factory::empty_symbol(), Factory::undefined_value()); | 1076 Factory::NewFunction(Factory::empty_symbol(), Factory::undefined_value()); |
| 1074 ASSERT(bridge->context() == *Top::global_context()); | 1077 ASSERT(bridge->context() == *Isolate::Current()->global_context()); |
| 1075 | 1078 |
| 1076 // Allocate the builtins context. | 1079 // Allocate the builtins context. |
| 1077 Handle<Context> context = | 1080 Handle<Context> context = |
| 1078 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); | 1081 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); |
| 1079 context->set_global(*builtins); // override builtins global object | 1082 context->set_global(*builtins); // override builtins global object |
| 1080 | 1083 |
| 1081 global_context()->set_runtime_context(*context); | 1084 global_context()->set_runtime_context(*context); |
| 1082 | 1085 |
| 1083 { // -- S c r i p t | 1086 { // -- S c r i p t |
| 1084 // Builtin functions for Script. | 1087 // Builtin functions for Script. |
| 1085 Handle<JSFunction> script_fun = | 1088 Handle<JSFunction> script_fun = |
| 1086 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, | 1089 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, |
| 1087 Top::initial_object_prototype(), Builtins::Illegal, | 1090 Isolate::Current()->initial_object_prototype(), |
| 1088 false); | 1091 Builtins::Illegal, false); |
| 1089 Handle<JSObject> prototype = | 1092 Handle<JSObject> prototype = |
| 1090 Factory::NewJSObject(Top::object_function(), TENURED); | 1093 Factory::NewJSObject(Isolate::Current()->object_function(), TENURED); |
| 1091 SetPrototype(script_fun, prototype); | 1094 SetPrototype(script_fun, prototype); |
| 1092 global_context()->set_script_function(*script_fun); | 1095 global_context()->set_script_function(*script_fun); |
| 1093 | 1096 |
| 1094 // Add 'source' and 'data' property to scripts. | 1097 // Add 'source' and 'data' property to scripts. |
| 1095 PropertyAttributes common_attributes = | 1098 PropertyAttributes common_attributes = |
| 1096 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 1099 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1097 Handle<Proxy> proxy_source = Factory::NewProxy(&Accessors::ScriptSource); | 1100 Handle<Proxy> proxy_source = Factory::NewProxy(&Accessors::ScriptSource); |
| 1098 Handle<DescriptorArray> script_descriptors = | 1101 Handle<DescriptorArray> script_descriptors = |
| 1099 Factory::CopyAppendProxyDescriptor( | 1102 Factory::CopyAppendProxyDescriptor( |
| 1100 Factory::empty_descriptor_array(), | 1103 Factory::empty_descriptor_array(), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 Handle<Script> script = Factory::NewScript(Factory::empty_string()); | 1204 Handle<Script> script = Factory::NewScript(Factory::empty_string()); |
| 1202 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 1205 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 1203 HEAP->public_set_empty_script(*script); | 1206 HEAP->public_set_empty_script(*script); |
| 1204 } | 1207 } |
| 1205 { | 1208 { |
| 1206 // Builtin function for OpaqueReference -- a JSValue-based object, | 1209 // Builtin function for OpaqueReference -- a JSValue-based object, |
| 1207 // that keeps its field isolated from JavaScript code. It may store | 1210 // that keeps its field isolated from JavaScript code. It may store |
| 1208 // objects, that JavaScript code may not access. | 1211 // objects, that JavaScript code may not access. |
| 1209 Handle<JSFunction> opaque_reference_fun = | 1212 Handle<JSFunction> opaque_reference_fun = |
| 1210 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, | 1213 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, |
| 1211 JSValue::kSize, Top::initial_object_prototype(), | 1214 JSValue::kSize, |
| 1215 Isolate::Current()->initial_object_prototype(), |
| 1212 Builtins::Illegal, false); | 1216 Builtins::Illegal, false); |
| 1213 Handle<JSObject> prototype = | 1217 Handle<JSObject> prototype = |
| 1214 Factory::NewJSObject(Top::object_function(), TENURED); | 1218 Factory::NewJSObject(Isolate::Current()->object_function(), TENURED); |
| 1215 SetPrototype(opaque_reference_fun, prototype); | 1219 SetPrototype(opaque_reference_fun, prototype); |
| 1216 global_context()->set_opaque_reference_function(*opaque_reference_fun); | 1220 global_context()->set_opaque_reference_function(*opaque_reference_fun); |
| 1217 } | 1221 } |
| 1218 | 1222 |
| 1219 if (FLAG_disable_native_files) { | 1223 if (FLAG_disable_native_files) { |
| 1220 PrintF("Warning: Running without installed natives!\n"); | 1224 PrintF("Warning: Running without installed natives!\n"); |
| 1221 return true; | 1225 return true; |
| 1222 } | 1226 } |
| 1223 | 1227 |
| 1224 // Install natives. | 1228 // Install natives. |
| 1225 for (int i = Natives::GetDebuggerCount(); | 1229 for (int i = Natives::GetDebuggerCount(); |
| 1226 i < Natives::GetBuiltinsCount(); | 1230 i < Natives::GetBuiltinsCount(); |
| 1227 i++) { | 1231 i++) { |
| 1228 Vector<const char> name = Natives::GetScriptName(i); | 1232 Vector<const char> name = Natives::GetScriptName(i); |
| 1229 if (!CompileBuiltin(i)) return false; | 1233 if (!CompileBuiltin(i)) return false; |
| 1230 // TODO(ager): We really only need to install the JS builtin | 1234 // TODO(ager): We really only need to install the JS builtin |
| 1231 // functions on the builtins object after compiling and running | 1235 // functions on the builtins object after compiling and running |
| 1232 // runtime.js. | 1236 // runtime.js. |
| 1233 if (!InstallJSBuiltins(builtins)) return false; | 1237 if (!InstallJSBuiltins(builtins)) return false; |
| 1234 } | 1238 } |
| 1235 | 1239 |
| 1236 InstallNativeFunctions(); | 1240 InstallNativeFunctions(); |
| 1237 | 1241 |
| 1238 InstallCustomCallGenerators(); | 1242 InstallCustomCallGenerators(); |
| 1239 | 1243 |
| 1240 // Install Function.prototype.call and apply. | 1244 // Install Function.prototype.call and apply. |
| 1241 { Handle<String> key = Factory::function_class_symbol(); | 1245 { Handle<String> key = Factory::function_class_symbol(); |
| 1242 Handle<JSFunction> function = | 1246 Handle<JSFunction> function = |
| 1243 Handle<JSFunction>::cast(GetProperty(Top::global(), key)); | 1247 Handle<JSFunction>::cast( |
| 1248 GetProperty(Isolate::Current()->global(), key)); |
| 1244 Handle<JSObject> proto = | 1249 Handle<JSObject> proto = |
| 1245 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 1250 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 1246 | 1251 |
| 1247 // Install the call and the apply functions. | 1252 // Install the call and the apply functions. |
| 1248 Handle<JSFunction> call = | 1253 Handle<JSFunction> call = |
| 1249 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1254 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
| 1250 Handle<JSObject>::null(), | 1255 Handle<JSObject>::null(), |
| 1251 Builtins::FunctionCall, | 1256 Builtins::FunctionCall, |
| 1252 false); | 1257 false); |
| 1253 Handle<JSFunction> apply = | 1258 Handle<JSFunction> apply = |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 } | 1398 } |
| 1394 | 1399 |
| 1395 | 1400 |
| 1396 int BootstrapperActive::nesting_ = 0; | 1401 int BootstrapperActive::nesting_ = 0; |
| 1397 | 1402 |
| 1398 | 1403 |
| 1399 bool Bootstrapper::InstallExtensions(Handle<Context> global_context, | 1404 bool Bootstrapper::InstallExtensions(Handle<Context> global_context, |
| 1400 v8::ExtensionConfiguration* extensions) { | 1405 v8::ExtensionConfiguration* extensions) { |
| 1401 BootstrapperActive active; | 1406 BootstrapperActive active; |
| 1402 SaveContext saved_context; | 1407 SaveContext saved_context; |
| 1403 Top::set_context(*global_context); | 1408 Isolate::Current()->set_context(*global_context); |
| 1404 if (!Genesis::InstallExtensions(global_context, extensions)) return false; | 1409 if (!Genesis::InstallExtensions(global_context, extensions)) return false; |
| 1405 Genesis::InstallSpecialObjects(global_context); | 1410 Genesis::InstallSpecialObjects(global_context); |
| 1406 return true; | 1411 return true; |
| 1407 } | 1412 } |
| 1408 | 1413 |
| 1409 | 1414 |
| 1410 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { | 1415 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { |
| 1411 HandleScope scope; | 1416 HandleScope scope; |
| 1412 Handle<JSGlobalObject> js_global( | 1417 Handle<JSGlobalObject> js_global( |
| 1413 JSGlobalObject::cast(global_context->global())); | 1418 JSGlobalObject::cast(global_context->global())); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 // Install the extension's dependencies | 1521 // Install the extension's dependencies |
| 1517 for (int i = 0; i < extension->dependency_count(); i++) { | 1522 for (int i = 0; i < extension->dependency_count(); i++) { |
| 1518 if (!InstallExtension(extension->dependencies()[i])) return false; | 1523 if (!InstallExtension(extension->dependencies()[i])) return false; |
| 1519 } | 1524 } |
| 1520 Vector<const char> source = CStrVector(extension->source()); | 1525 Vector<const char> source = CStrVector(extension->source()); |
| 1521 Handle<String> source_code = Factory::NewStringFromAscii(source); | 1526 Handle<String> source_code = Factory::NewStringFromAscii(source); |
| 1522 bool result = CompileScriptCached(CStrVector(extension->name()), | 1527 bool result = CompileScriptCached(CStrVector(extension->name()), |
| 1523 source_code, | 1528 source_code, |
| 1524 &extensions_cache, | 1529 &extensions_cache, |
| 1525 extension, | 1530 extension, |
| 1526 Handle<Context>(Top::context()), | 1531 Handle<Context>( |
| 1532 Isolate::Current()->context()), |
| 1527 false); | 1533 false); |
| 1528 ASSERT(Top::has_pending_exception() != result); | 1534 ASSERT(Isolate::Current()->has_pending_exception() != result); |
| 1529 if (!result) { | 1535 if (!result) { |
| 1530 Top::clear_pending_exception(); | 1536 Isolate::Current()->clear_pending_exception(); |
| 1531 } | 1537 } |
| 1532 current->set_state(v8::INSTALLED); | 1538 current->set_state(v8::INSTALLED); |
| 1533 return result; | 1539 return result; |
| 1534 } | 1540 } |
| 1535 | 1541 |
| 1536 | 1542 |
| 1537 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { | 1543 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { |
| 1538 HandleScope scope; | 1544 HandleScope scope; |
| 1539 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { | 1545 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { |
| 1540 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); | 1546 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 bool Genesis::ConfigureApiObject(Handle<JSObject> object, | 1587 bool Genesis::ConfigureApiObject(Handle<JSObject> object, |
| 1582 Handle<ObjectTemplateInfo> object_template) { | 1588 Handle<ObjectTemplateInfo> object_template) { |
| 1583 ASSERT(!object_template.is_null()); | 1589 ASSERT(!object_template.is_null()); |
| 1584 ASSERT(object->IsInstanceOf( | 1590 ASSERT(object->IsInstanceOf( |
| 1585 FunctionTemplateInfo::cast(object_template->constructor()))); | 1591 FunctionTemplateInfo::cast(object_template->constructor()))); |
| 1586 | 1592 |
| 1587 bool pending_exception = false; | 1593 bool pending_exception = false; |
| 1588 Handle<JSObject> obj = | 1594 Handle<JSObject> obj = |
| 1589 Execution::InstantiateObject(object_template, &pending_exception); | 1595 Execution::InstantiateObject(object_template, &pending_exception); |
| 1590 if (pending_exception) { | 1596 if (pending_exception) { |
| 1591 ASSERT(Top::has_pending_exception()); | 1597 ASSERT(Isolate::Current()->has_pending_exception()); |
| 1592 Top::clear_pending_exception(); | 1598 Isolate::Current()->clear_pending_exception(); |
| 1593 return false; | 1599 return false; |
| 1594 } | 1600 } |
| 1595 TransferObject(obj, object); | 1601 TransferObject(obj, object); |
| 1596 return true; | 1602 return true; |
| 1597 } | 1603 } |
| 1598 | 1604 |
| 1599 | 1605 |
| 1600 void Genesis::TransferNamedProperties(Handle<JSObject> from, | 1606 void Genesis::TransferNamedProperties(Handle<JSObject> from, |
| 1601 Handle<JSObject> to) { | 1607 Handle<JSObject> to) { |
| 1602 if (from->HasFastProperties()) { | 1608 if (from->HasFastProperties()) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 } | 1708 } |
| 1703 | 1709 |
| 1704 | 1710 |
| 1705 void Genesis::MakeFunctionInstancePrototypeWritable() { | 1711 void Genesis::MakeFunctionInstancePrototypeWritable() { |
| 1706 // Make a new function map so all future functions | 1712 // Make a new function map so all future functions |
| 1707 // will have settable and enumerable prototype properties. | 1713 // will have settable and enumerable prototype properties. |
| 1708 HandleScope scope; | 1714 HandleScope scope; |
| 1709 | 1715 |
| 1710 Handle<DescriptorArray> function_map_descriptors = | 1716 Handle<DescriptorArray> function_map_descriptors = |
| 1711 ComputeFunctionInstanceDescriptor(ADD_WRITEABLE_PROTOTYPE); | 1717 ComputeFunctionInstanceDescriptor(ADD_WRITEABLE_PROTOTYPE); |
| 1712 Handle<Map> fm = Factory::CopyMapDropDescriptors(Top::function_map()); | 1718 Handle<Map> fm = Factory::CopyMapDropDescriptors( |
| 1719 Isolate::Current()->function_map()); |
| 1713 fm->set_instance_descriptors(*function_map_descriptors); | 1720 fm->set_instance_descriptors(*function_map_descriptors); |
| 1714 fm->set_function_with_prototype(true); | 1721 fm->set_function_with_prototype(true); |
| 1715 Top::context()->global_context()->set_function_map(*fm); | 1722 Isolate::Current()->context()->global_context()->set_function_map(*fm); |
| 1716 } | 1723 } |
| 1717 | 1724 |
| 1718 | 1725 |
| 1719 Genesis::Genesis(Handle<Object> global_object, | 1726 Genesis::Genesis(Handle<Object> global_object, |
| 1720 v8::Handle<v8::ObjectTemplate> global_template, | 1727 v8::Handle<v8::ObjectTemplate> global_template, |
| 1721 v8::ExtensionConfiguration* extensions) { | 1728 v8::ExtensionConfiguration* extensions) { |
| 1722 result_ = Handle<Context>::null(); | 1729 result_ = Handle<Context>::null(); |
| 1723 // If V8 isn't running and cannot be initialized, just return. | 1730 // If V8 isn't running and cannot be initialized, just return. |
| 1724 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; | 1731 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; |
| 1725 | 1732 |
| 1726 // Before creating the roots we must save the context and restore it | 1733 // Before creating the roots we must save the context and restore it |
| 1727 // on all function exits. | 1734 // on all function exits. |
| 1728 HandleScope scope; | 1735 HandleScope scope; |
| 1729 SaveContext saved_context; | 1736 SaveContext saved_context; |
| 1730 | 1737 |
| 1731 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); | 1738 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); |
| 1732 if (!new_context.is_null()) { | 1739 if (!new_context.is_null()) { |
| 1733 global_context_ = | 1740 global_context_ = |
| 1734 Handle<Context>::cast(GlobalHandles::Create(*new_context)); | 1741 Handle<Context>::cast(GlobalHandles::Create(*new_context)); |
| 1735 Top::set_context(*global_context_); | 1742 Isolate::Current()->set_context(*global_context_); |
| 1736 i::Counters::contexts_created_by_snapshot.Increment(); | 1743 i::Counters::contexts_created_by_snapshot.Increment(); |
| 1737 result_ = global_context_; | 1744 result_ = global_context_; |
| 1738 JSFunction* empty_function = | 1745 JSFunction* empty_function = |
| 1739 JSFunction::cast(result_->function_map()->prototype()); | 1746 JSFunction::cast(result_->function_map()->prototype()); |
| 1740 empty_function_ = Handle<JSFunction>(empty_function); | 1747 empty_function_ = Handle<JSFunction>(empty_function); |
| 1741 Handle<GlobalObject> inner_global; | 1748 Handle<GlobalObject> inner_global; |
| 1742 Handle<JSGlobalProxy> global_proxy = | 1749 Handle<JSGlobalProxy> global_proxy = |
| 1743 CreateNewGlobals(global_template, | 1750 CreateNewGlobals(global_template, |
| 1744 global_object, | 1751 global_object, |
| 1745 &inner_global); | 1752 &inner_global); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 } | 1817 } |
| 1811 | 1818 |
| 1812 | 1819 |
| 1813 // Restore statics that are thread local. | 1820 // Restore statics that are thread local. |
| 1814 char* BootstrapperActive::RestoreState(char* from) { | 1821 char* BootstrapperActive::RestoreState(char* from) { |
| 1815 nesting_ = *reinterpret_cast<int*>(from); | 1822 nesting_ = *reinterpret_cast<int*>(from); |
| 1816 return from + sizeof(nesting_); | 1823 return from + sizeof(nesting_); |
| 1817 } | 1824 } |
| 1818 | 1825 |
| 1819 } } // namespace v8::internal | 1826 } } // namespace v8::internal |
| OLD | NEW |