call_code(isolate->builtins()->builtin(call)); Handle prototype; static const bool kReadOnlyPrototype = false; static const bool kInstallConstructor = false; return maybe_prototype.ToHandle(&prototype) ? factory->NewFunction(name, call_code, prototype, type, instance_size, kReadOnlyPrototype, kInstallConstructor, strict_function_map) : factory->NewFunctionWithoutPrototype(name, call_code, strict_function_map); } Handle InstallFunction(Handle target, Handle name, InstanceType type, int instance_size, MaybeHandle maybe_prototype, Builtins::Name call, PropertyAttributes attributes, bool strict_function_map = false) { Handle name_string = Name::ToFunctionName(name).ToHandleChecked(); Handle function = CreateFunction(target->GetIsolate(), name_string, type, instance_size, maybe_prototype, call, strict_function_map); InstallFunction(target, name, function, name_string, attributes); return function; } Handle InstallFunction(Handle target, const char* name, InstanceType type, int instance_size, MaybeHandle maybe_prototype, Builtins::Name call, bool strict_function_map = false) { Factory* const factory = target->GetIsolate()->factory(); PropertyAttributes attributes = DONT_ENUM; return InstallFunction(target, factory->InternalizeUtf8String(name), type, instance_size, maybe_prototype, call, attributes, strict_function_map); } } // namespace void Genesis::SetFunctionInstanceDescriptor(Handle map, FunctionMode function_mode) { int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; Map::EnsureDescriptorSlack(map, size); PropertyAttributes ro_attribs = static_cast(DONT_ENUM | DONT_DELETE | READ_ONLY); PropertyAttributes roc_attribs = static_cast(DONT_ENUM | READ_ONLY); Handle length = Accessors::FunctionLengthInfo(isolate(), roc_attribs); { // Add length. AccessorConstantDescriptor d(Handle(Name::cast(length->name())), length, roc_attribs); map->AppendDescriptor(&d); } Handle name = Accessors::FunctionNameInfo(isolate(), ro_attribs); { // Add name. AccessorConstantDescriptor d(Handle(Name::cast(name->name())), name, roc_attribs); map->AppendDescriptor(&d); } Handle args = Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); { // Add arguments. AccessorConstantDescriptor d(Handle(Name::cast(args->name())), args, ro_attribs); map->AppendDescriptor(&d); } Handle caller = Accessors::FunctionCallerInfo(isolate(), ro_attribs); { // Add caller. AccessorConstantDescriptor d(Handle(Name::cast(caller->name())), caller, ro_attribs); map->AppendDescriptor(&d); } if (IsFunctionModeWithPrototype(function_mode)) { if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { ro_attribs = static_cast(ro_attribs & ~READ_ONLY); } Handle prototype = Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); AccessorConstantDescriptor d(Handle(Name::cast(prototype->name())), prototype, ro_attribs); map->AppendDescriptor(&d); } } Handle Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) { Handle map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); SetFunctionInstanceDescriptor(map, function_mode); if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor(); map->set_is_callable(); return map; } Handle Genesis::CreateEmptyFunction(Isolate* isolate) { // Allocate the map for function instances. Maps are allocated first and their // prototypes patched later, once empty function is created. // Functions with this map will not have a 'prototype' property, and // can not be used as constructors. Handle function_without_prototype_map = CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); native_context()->set_sloppy_function_without_prototype_map( *function_without_prototype_map); // Allocate the function map. This map is temporary, used only for processing // of builtins. // Later the map is replaced with writable prototype map, allocated below. Handle function_map = CreateSloppyFunctionMap(FUNCTION_WITH_READONLY_PROTOTYPE); native_context()->set_sloppy_function_map(*function_map); native_context()->set_sloppy_function_with_readonly_prototype_map( *function_map); // The final map for functions. Writeable prototype. // This map is installed in MakeFunctionInstancePrototypeWritable. sloppy_function_map_writable_prototype_ = CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); Factory* factory = isolate->factory(); Handle object_name = factory->Object_string(); Handle object_function_prototype; { // --- O b j e c t --- Handle object_fun = factory->NewFunction(object_name); int unused = JSObject::kInitialGlobalObjectUnusedPropertiesCount; int instance_size = JSObject::kHeaderSize + kPointerSize * unused; Handle object_function_map = factory->NewMap(JS_OBJECT_TYPE, instance_size); object_function_map->SetInObjectProperties(unused); JSFunction::SetInitialMap(object_fun, object_function_map, isolate->factory()->null_value()); object_function_map->set_unused_property_fields(unused); native_context()->set_object_function(*object_fun); // Allocate a new prototype for the object function. object_function_prototype = factory->NewJSObject(isolate->object_function(), TENURED); Handle map = Map::Copy(handle(object_function_prototype->map()), "EmptyObjectPrototype"); map->set_is_prototype_map(true); object_function_prototype->set_map(*map); native_context()->set_initial_object_prototype(*object_function_prototype); // For bootstrapping set the array prototype to be the same as the object // prototype, otherwise the missing initial_array_prototype will cause // assertions during startup. native_context()->set_initial_array_prototype(*object_function_prototype); Accessors::FunctionSetPrototype(object_fun, object_function_prototype) .Assert(); // Allocate initial strong object map. Handle strong_object_map = Map::Copy(Handle(object_fun->initial_map()), "EmptyStrongObject"); strong_object_map->set_is_strong(); native_context()->set_js_object_strong_map(*strong_object_map); } // Allocate the empty function as the prototype for function - ES6 19.2.3 Handle code(isolate->builtins()->EmptyFunction()); Handle empty_function = factory->NewFunctionWithoutPrototype(factory->empty_string(), code); // Allocate the function map first and then patch the prototype later Handle empty_function_map = CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); DCHECK(!empty_function_map->is_dictionary_map()); Map::SetPrototype(empty_function_map, object_function_prototype); empty_function_map->set_is_prototype_map(true); empty_function->set_map(*empty_function_map); // --- E m p t y --- Handle source = factory->NewStringFromStaticChars("() {}"); Handle 登录后可以享受更多权益 您还没有登录,登录后您可以: 收藏Android系统代码 收藏喜欢的文章 多个平台共享账号 去登录 首次使用?从这里 注册
code(isolate->builtins()->EmptyFunction()); Handle empty_function = factory->NewFunctionWithoutPrototype(factory->empty_string(), code); // Allocate the function map first and then patch the prototype later Handle empty_function_map = CreateSloppyFunctionMap(FUNCTION_WITHOUT_PROTOTYPE); DCHECK(!empty_function_map->is_dictionary_map()); Map::SetPrototype(empty_function_map, object_function_prototype); empty_function_map->set_is_prototype_map(true); empty_function->set_map(*empty_function_map); // --- E m p t y --- Handle source = factory->NewStringFromStaticChars("() {}"); Handle 登录后可以享受更多权益 您还没有登录,登录后您可以: 收藏Android系统代码 收藏喜欢的文章 多个平台共享账号 去登录 首次使用?从这里 注册
您还没有登录,登录后您可以:
首次使用?从这里 注册