⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bootstrapper.cc.svn-base

📁 Google浏览器V8内核代码
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
            JSObject::cast(global_context()->object_function()->prototype()));    Handle<JSFunction> function =        Factory::NewFunctionWithPrototype(symbol, JS_OBJECT_TYPE,                                          JSObject::kHeaderSize, prototype,                                          code, true);    function->shared()->set_instance_class_name(*symbol);    Handle<JSObject> result = Factory::NewJSObject(function);    global_context()->set_arguments_boilerplate(*result);    // Note: callee must be added as the first property and    //       length must be added as the second property.    SetProperty(result, Factory::callee_symbol(), Factory::undefined_value(),                DONT_ENUM);    SetProperty(result, Factory::length_symbol(), Factory::undefined_value(),                DONT_ENUM);    // Check the state of the object.    ASSERT(result->HasFastProperties());    ASSERT(result->HasFastElements());  }  {  // --- context extension    // Create a function for the context extension objects.    Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));    Handle<JSFunction> context_extension_fun =        Factory::NewFunction(Factory::empty_symbol(), JS_OBJECT_TYPE,                             JSObject::kHeaderSize, code, true);    Handle<String> name = Factory::LookupAsciiSymbol("context_extension");    context_extension_fun->shared()->set_instance_class_name(*name);    global_context()->set_context_extension_function(*context_extension_fun);  }  // Setup the call-as-function delegate.  Handle<Code> code =      Handle<Code>(Builtins::builtin(Builtins::HandleApiCallAsFunction));  Handle<JSFunction> delegate =      Factory::NewFunction(Factory::empty_symbol(), JS_OBJECT_TYPE,                           JSObject::kHeaderSize, code, true);  global_context()->set_call_as_function_delegate(*delegate);  delegate->shared()->DontAdaptArguments();  global_context()->set_special_function_table(Heap::empty_fixed_array());  // Initialize the out of memory slot.  global_context()->set_out_of_memory(Heap::false_value());}bool Genesis::CompileBuiltin(int index) {  Vector<const char> name = Natives::GetScriptName(index);  Handle<String> source_code = Bootstrapper::NativesSourceLookup(index);  return CompileNative(name, source_code);}bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) {  HandleScope scope;  Debugger::set_compiling_natives(true);  bool result =      CompileScriptCached(name, source, &natives_cache, NULL, true);  ASSERT(Top::has_pending_exception() != result);  if (!result) Top::clear_pending_exception();  Debugger::set_compiling_natives(false);  return result;}bool Genesis::CompileScriptCached(Vector<const char> name,                                  Handle<String> source,                                  SourceCodeCache* cache,                                  v8::Extension* extension,                                  bool use_runtime_context) {  HandleScope scope;  Handle<JSFunction> boilerplate;  // If we can't find the function in the cache, we compile a new  // function and insert it into the cache.  if (!cache->Lookup(name, &boilerplate)) {#ifdef DEBUG    ASSERT(source->IsAscii());#endif    Handle<String> script_name = Factory::NewStringFromUtf8(name);    boilerplate =        Compiler::Compile(source, script_name, 0, 0, extension, NULL);    if (boilerplate.is_null()) return false;    cache->Add(name, boilerplate);  }  // Setup the function context. Conceptually, we should clone the  // function before overwriting the context but since we're in a  // single-threaded environment it is not strictly necessary.  ASSERT(Top::context()->IsGlobalContext());  Handle<Context> context =      Handle<Context>(use_runtime_context                      ? Top::context()->runtime_context()                      : Top::context());  Handle<JSFunction> fun =      Factory::NewFunctionFromBoilerplate(boilerplate, context);  // Call function using the either the runtime object or the global  // object as the receiver. Provide no parameters.  Handle<Object> receiver =      Handle<Object>(use_runtime_context                     ? Top::context()->builtins()                     : Top::context()->global());  bool has_pending_exception;  Handle<Object> result =      Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);  if (has_pending_exception) return false;  return PendingFixups::Process(      Handle<JSBuiltinsObject>(Top::context()->builtins()));}#define INSTALL_NATIVE(Type, name, var)                                  \  Handle<String> var##_name = Factory::LookupAsciiSymbol(name);          \  global_context()->set_##var(Type::cast(global_context()->              \                                           builtins()->                  \                                             GetProperty(*var##_name)));void Genesis::InstallNativeFunctions() {  HandleScope scope;  INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun);  INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun);  INSTALL_NATIVE(JSFunction, "ToString", to_string_fun);  INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun);  INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun);  INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun);  INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun);  INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun);  INSTALL_NATIVE(JSFunction, "ToBoolean", to_boolean_fun);  INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun);  INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance",                 configure_instance_fun);  INSTALL_NATIVE(JSFunction, "MakeMessage", make_message_fun);  INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);  INSTALL_NATIVE(JSObject, "functionCache", function_cache);}#undef INSTALL_NATIVEbool Genesis::InstallNatives() {  HandleScope scope;  // Create a function for the builtins object. Allocate space for the  // JavaScript builtins, a reference to the builtins object  // (itself) and a reference to the global_context directly in the object.  Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));  Handle<JSFunction> builtins_fun =      Factory::NewFunction(Factory::empty_symbol(), JS_BUILTINS_OBJECT_TYPE,                           JSBuiltinsObject::kSize, code, true);  Handle<String> name = Factory::LookupAsciiSymbol("builtins");  builtins_fun->shared()->set_instance_class_name(*name);  SetExpectedNofProperties(builtins_fun, 100);  // Allocate the builtins object.  Handle<JSBuiltinsObject> builtins =      Handle<JSBuiltinsObject>::cast(Factory::NewJSObject(builtins_fun,                                                          TENURED));  builtins->set_builtins(*builtins);  builtins->set_global_context(*global_context());  // Setup the 'global' properties of the builtins object. The  // 'global' property that refers to the global object is the only  // way to get from code running in the builtins context to the  // global object.  static const PropertyAttributes attributes =      static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);  SetProperty(builtins, Factory::LookupAsciiSymbol("global"),              Handle<Object>(global_context()->global()), attributes);  // Setup the reference from the global object to the builtins object.  JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins);  // Create a bridge function that has context in the global context.  Handle<JSFunction> bridge =      Factory::NewFunction(Factory::empty_symbol(), Factory::undefined_value());  ASSERT(bridge->context() == *Top::global_context());  // Allocate the builtins context.  Handle<Context> context =    Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);  context->set_global(*builtins);  // override builtins global object  global_context()->set_runtime_context(*context);  {  // -- S c r i p t    // Builtin functions for Script.    Handle<JSFunction> script_fun =        InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,                        Top::initial_object_prototype(), Builtins::Illegal,                        false);    Handle<JSObject> prototype =        Factory::NewJSObject(Top::object_function(), TENURED);    SetPrototype(script_fun, prototype);    global_context()->set_script_function(*script_fun);    // Add 'source' and 'data' property to scripts.    PropertyAttributes common_attributes =        static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);    Handle<Proxy> proxy_source = Factory::NewProxy(&Accessors::ScriptSource);    Handle<DescriptorArray> script_descriptors =        Factory::CopyAppendProxyDescriptor(            Factory::empty_descriptor_array(),            Factory::LookupAsciiSymbol("source"),            proxy_source,            common_attributes);    Handle<Proxy> proxy_data = Factory::NewProxy(&Accessors::ScriptName);    script_descriptors =        Factory::CopyAppendProxyDescriptor(            script_descriptors,            Factory::LookupAsciiSymbol("name"),            proxy_data,            common_attributes);    Handle<Proxy> proxy_line_offset =        Factory::NewProxy(&Accessors::ScriptLineOffset);    script_descriptors =        Factory::CopyAppendProxyDescriptor(            script_descriptors,            Factory::LookupAsciiSymbol("line_offset"),            proxy_line_offset,            common_attributes);    Handle<Proxy> proxy_column_offset =        Factory::NewProxy(&Accessors::ScriptColumnOffset);    script_descriptors =        Factory::CopyAppendProxyDescriptor(            script_descriptors,            Factory::LookupAsciiSymbol("column_offset"),            proxy_column_offset,            common_attributes);    Handle<Proxy> proxy_type = Factory::NewProxy(&Accessors::ScriptType);    script_descriptors =        Factory::CopyAppendProxyDescriptor(            script_descriptors,            Factory::LookupAsciiSymbol("type"),            proxy_type,            common_attributes);    Handle<Map> script_map = Handle<Map>(script_fun->initial_map());    script_map->set_instance_descriptors(*script_descriptors);    // Allocate the empty script.    Handle<Script> script = Factory::NewScript(Factory::empty_string());    global_context()->set_empty_script(*script);  }  if (FLAG_natives_file == NULL) {    // Without natives file, install default natives.    for (int i = Natives::GetDelayCount();         i < Natives::GetBuiltinsCount();         i++) {      if (!CompileBuiltin(i)) return false;    }    // Setup natives with lazy loading.    SetupLazy(Handle<JSFunction>(global_context()->date_function()),              Natives::GetIndex("date"),              Top::global_context(),              Handle<Context>(Top::context()->runtime_context()),              Handle<Context>(Top::security_context()));    SetupLazy(Handle<JSFunction>(global_context()->regexp_function()),              Natives::GetIndex("regexp"),              Top::global_context(),              Handle<Context>(Top::context()->runtime_context()),              Handle<Context>(Top::security_context()));  } else if (strlen(FLAG_natives_file) != 0) {    // Otherwise install natives from natives file if file exists and    // compiles.    bool exists;    Vector<const char> source = ReadFile(FLAG_natives_file, &exists);    Handle<String> source_string = Factory::NewStringFromAscii(source);    if (source.is_empty()) return false;    bool result = CompileNative(CStrVector(FLAG_natives_file), source_string);    if (!result) return false;  } else {    // Empty natives file name - do not install any natives.    PrintF("Warning: Running without installed natives!\n");    return true;  }  InstallNativeFunctions();  // Install Function.prototype.call and apply.  { Handle<String> key = Factory::function_class_symbol();    Handle<JSFunction> function =        Handle<JSFunction>::cast(GetProperty(Top::global(), key));    Handle<JSObject> proto =        Handle<JSObject>(JSObject::cast(function->instance_prototype()));    // Install the call and the apply functions.    Handle<JSFunction> call =        InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize,                        Factory::NewJSObject(Top::object_function(), TENURED),                        Builtins::FunctionCall,                        false);    Handle<JSFunction> apply =        InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,                        Factory::NewJSObject(Top::object_function(), TENURED),                        Builtins::FunctionApply,                        false);    // Make sure that Function.prototype.call appears to be compiled.    // The code will never be called, but inline caching for call will    // only work if it appears to be compiled.    call->shared()->DontAdaptArguments();    ASSERT(call->is_compiled());    // Set the expected paramters for apply to 2; required by builtin.    apply->shared()->set_formal_parameter_count(2);    // Set the lengths for the functions to satisfy ECMA-262.    call->shared()->set_length(1);    apply->shared()->set_length(2);  }  // Make sure that the builtins object has fast properties.  // If the ASSERT below fails, please increase the expected number of  // properties for the builtins object.  ASSERT(builtins->HasFastProperties());#ifdef DEBUG  builtins->Verify();#endif  return true;}bool Genesis::InstallSpecialObjects() {  HandleScope scope;  Handle<JSGlobalObject> global(      JSGlobalObject::cast(global_context()->global()));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -