📄 bootstrapper.cc.svn-base
字号:
}Genesis::~Genesis() { ASSERT(current_ == this); current_ = previous_;}static Handle<JSFunction> InstallFunction(Handle<JSObject> target, const char* name, InstanceType type, int instance_size, Handle<JSObject> prototype, Builtins::Name call, bool is_ecma_native) { Handle<String> symbol = Factory::LookupAsciiSymbol(name); Handle<Code> call_code = Handle<Code>(Builtins::builtin(call)); Handle<JSFunction> function = Factory::NewFunctionWithPrototype(symbol, type, instance_size, prototype, call_code, is_ecma_native); SetProperty(target, symbol, function, DONT_ENUM); if (is_ecma_native) { function->shared()->set_instance_class_name(*symbol); } return function;}Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor( bool make_prototype_read_only, bool make_prototype_enumerable) { Handle<DescriptorArray> result = Factory::empty_descriptor_array(); // Add prototype. PropertyAttributes attributes = static_cast<PropertyAttributes>( (make_prototype_enumerable ? 0 : DONT_ENUM) | DONT_DELETE | (make_prototype_read_only ? READ_ONLY : 0)); result = Factory::CopyAppendProxyDescriptor( result, Factory::prototype_symbol(), Factory::NewProxy(&Accessors::FunctionPrototype), attributes); attributes = static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); // Add length. result = Factory::CopyAppendProxyDescriptor( result, Factory::length_symbol(), Factory::NewProxy(&Accessors::FunctionLength), attributes); // Add name. result = Factory::CopyAppendProxyDescriptor( result, Factory::name_symbol(), Factory::NewProxy(&Accessors::FunctionName), attributes); // Add arguments. result = Factory::CopyAppendProxyDescriptor( result, Factory::arguments_symbol(), Factory::NewProxy(&Accessors::FunctionArguments), attributes); // Add caller. result = Factory::CopyAppendProxyDescriptor( result, Factory::caller_symbol(), Factory::NewProxy(&Accessors::FunctionCaller), attributes); return result;}void Genesis::CreateRoots(v8::Handle<v8::ObjectTemplate> global_template, Handle<Object> global_object) { HandleScope scope; // Allocate the global context FixedArray first and then patch the // closure and extension object later (we need the empty function // and the global object, but in order to create those, we need the // global context). global_context_ = Handle<Context>::cast( GlobalHandles::Create(*Factory::NewGlobalContext())); Top::set_security_context(*global_context()); Top::set_context(*global_context()); // Allocate the message listeners object. v8::NeanderArray listeners; global_context()->set_message_listeners(*listeners.value()); // Allocate the debug event listeners object. v8::NeanderArray debug_event_listeners; global_context()->set_debug_event_listeners(*debug_event_listeners.value()); // Allocate the map for function instances. Handle<Map> fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); global_context()->set_function_instance_map(*fm); // Please note that the prototype property for function instances must be // writable. Handle<DescriptorArray> function_map_descriptors = ComputeFunctionInstanceDescriptor(false, true); fm->set_instance_descriptors(*function_map_descriptors); // Allocate the function map first and then patch the prototype later fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); global_context()->set_function_map(*fm); function_map_descriptors = ComputeFunctionInstanceDescriptor(true); fm->set_instance_descriptors(*function_map_descriptors); Handle<String> object_name = Handle<String>(Heap::Object_symbol()); { // --- O b j e c t --- Handle<JSFunction> object_fun = Factory::NewFunction(object_name, Factory::null_value()); Handle<Map> object_function_map = Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); object_fun->set_initial_map(*object_function_map); object_function_map->set_constructor(*object_fun); global_context()->set_object_function(*object_fun); // Allocate a new prototype for the object function. Handle<JSObject> prototype = Factory::NewJSObject(Top::object_function(), TENURED); global_context()->set_initial_object_prototype(*prototype); SetPrototype(object_fun, prototype); object_function_map-> set_instance_descriptors(Heap::empty_descriptor_array()); } // Allocate the empty function as the prototype for function ECMAScript // 262 15.3.4. Handle<String> symbol = Factory::LookupAsciiSymbol("Empty"); Handle<JSFunction> empty_function = Factory::NewFunction(symbol, Factory::null_value()); { // --- E m p t y --- Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::EmptyFunction)); Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}")); empty_function->set_code(*code); empty_function->shared()->set_script(*Factory::NewScript(source)); empty_function->shared()->set_start_position(0); empty_function->shared()->set_end_position(source->length()); empty_function->shared()->DontAdaptArguments(); global_context()->function_map()->set_prototype(*empty_function); global_context()->function_instance_map()->set_prototype(*empty_function); // Allocate the function map first and then patch the prototype later Handle<Map> empty_fm = Factory::CopyMap(fm); empty_fm->set_instance_descriptors(*function_map_descriptors); empty_fm->set_prototype(global_context()->object_function()->prototype()); empty_function->set_map(*empty_fm); } { // --- G l o b a l --- Handle<String> global_name = Factory::LookupAsciiSymbol("global"); Handle<JSFunction> global_function; if (global_template.IsEmpty()) { Handle<String> name = Handle<String>(Heap::empty_symbol()); Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); global_function = Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize, code, true); // Change the constructor property of the prototype of the // hidden global function to refer to the Object function. Handle<JSObject> prototype = Handle<JSObject>( JSObject::cast(global_function->instance_prototype())); SetProperty(prototype, Factory::constructor_symbol(), Top::object_function(), NONE); } else { Handle<ObjectTemplateInfo> data = v8::Utils::OpenHandle(*global_template); Handle<FunctionTemplateInfo> global_constructor = Handle<FunctionTemplateInfo>( FunctionTemplateInfo::cast(data->constructor())); global_function = Factory::CreateApiFunction(global_constructor, true); } SetExpectedNofProperties(global_function, 100); global_function->shared()->set_instance_class_name(*global_name); global_function->initial_map()->set_needs_access_check(); Handle<JSGlobalObject> object; if (global_object.location() != NULL) { ASSERT(global_object->IsJSGlobalObject()); object = ReinitializeJSGlobalObject( global_function, Handle<JSGlobalObject>::cast(global_object)); } else { object = Handle<JSGlobalObject>::cast(Factory::NewJSObject(global_function, TENURED)); } // Set the global context for the global object. object->set_global_context(*global_context()); // Security setup: Set the security token of the global object to // its global context. This makes the security check between two // different contexts fail by default even in case of global // object reinitialization. object->set_security_token(*global_context()); { // --- G l o b a l C o n t e x t --- // use the empty function as closure (no scope info) global_context()->set_closure(*empty_function); global_context()->set_fcontext(*global_context()); global_context()->set_previous(NULL); // set extension and global object global_context()->set_extension(*object); global_context()->set_global(*object); } Handle<JSObject> global = Handle<JSObject>(global_context()->global()); SetProperty(global, object_name, Top::object_function(), DONT_ENUM); } Handle<JSObject> global = Handle<JSObject>(global_context()->global()); // Install global Function object InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, empty_function, Builtins::Illegal, true); // ECMA native. { // --- A r r a y --- Handle<JSFunction> array_function = InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, Top::initial_object_prototype(), Builtins::ArrayCode, true); array_function->shared()->DontAdaptArguments(); // This seems a bit hackish, but we need to make sure Array.length // is 1. array_function->shared()->set_length(1); Handle<DescriptorArray> array_descriptors = Factory::CopyAppendProxyDescriptor( Factory::empty_descriptor_array(), Factory::length_symbol(), Factory::NewProxy(&Accessors::ArrayLength), static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE)); // Cache the fast JavaScript array map global_context()->set_js_array_map(array_function->initial_map()); global_context()->js_array_map()->set_instance_descriptors( *array_descriptors); // array_function is used internally. JS code creating array object should // search for the 'Array' property on the global object and use that one // as the constructor. 'Array' property on a global object can be // overwritten by JS code. global_context()->set_array_function(*array_function); } { // --- N u m b e r --- Handle<JSFunction> number_fun = InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, Top::initial_object_prototype(), Builtins::Illegal, true); global_context()->set_number_function(*number_fun); } { // --- B o o l e a n --- Handle<JSFunction> boolean_fun = InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, Top::initial_object_prototype(), Builtins::Illegal, true); global_context()->set_boolean_function(*boolean_fun); } { // --- S t r i n g --- Handle<JSFunction> string_fun = InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, Top::initial_object_prototype(), Builtins::Illegal, true); global_context()->set_string_function(*string_fun); // Add 'length' property to strings. Handle<DescriptorArray> string_descriptors = Factory::CopyAppendProxyDescriptor( Factory::empty_descriptor_array(), Factory::length_symbol(), Factory::NewProxy(&Accessors::StringLength), static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY)); Handle<Map> string_map = Handle<Map>(global_context()->string_function()->initial_map()); string_map->set_instance_descriptors(*string_descriptors); } { // --- D a t e --- // Builtin functions for Date.prototype. Handle<JSFunction> date_fun = InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize, Top::initial_object_prototype(), Builtins::Illegal, true); global_context()->set_date_function(*date_fun); } { // -- R e g E x p // Builtin functions for RegExp.prototype. Handle<JSFunction> regexp_fun = InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, Top::initial_object_prototype(), Builtins::Illegal, true); global_context()->set_regexp_function(*regexp_fun); } { // --- arguments_boilerplate_ // Make sure we can recognize argument objects at runtime. // This is done by introducing an anonymous function with // class_name equals 'Arguments'. Handle<String> symbol = Factory::LookupAsciiSymbol("Arguments"); Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); Handle<JSObject> prototype = Handle<JSObject>(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -