call_code(isolate->builtins()->builtin(call)); Handle prototype; return maybe_prototype.ToHandle(&prototype) ? factory->NewFunction(name, call_code, prototype, type, instance_size, 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); } Handle SimpleCreateFunction(Isolate* isolate, Handle name, Builtins::Name call, int len, bool adapt) { Handle fun = CreateFunction(isolate, name, JS_OBJECT_TYPE, JSObject::kHeaderSize, MaybeHandle(), call); if (adapt) { fun->shared()->set_internal_formal_parameter_count(len); } else { fun->shared()->DontAdaptArguments(); } fun->shared()->set_length(len); return fun; } Handle SimpleInstallFunction(Handle base, Handle name, Builtins::Name call, int len, bool adapt, PropertyAttributes attrs = DONT_ENUM) { Handle fun = SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt); InstallFunction(base, fun, name, attrs); return fun; } Handle SimpleInstallFunction(Handle base, const char* name, Builtins::Name call, int len, bool adapt, PropertyAttributes attrs = DONT_ENUM) { Factory* const factory = base->GetIsolate()->factory(); return SimpleInstallFunction(base, factory->InternalizeUtf8String(name), call, len, adapt, attrs); } Handle SimpleInstallFunction(Handle base, const char* name, Builtins::Name call, int len, bool adapt, BuiltinFunctionId id) { Handle fun = SimpleInstallFunction(base, name, call, len, adapt); fun->shared()->set_builtin_function_id(id); return fun; } void SimpleInstallGetterSetter(Handle base, Handle name, Builtins::Name call_getter, Builtins::Name call_setter, PropertyAttributes attribs) { Isolate* const isolate = base->GetIsolate(); Handle getter_name = Name::ToFunctionName(name, isolate->factory()->get_string()) .ToHandleChecked(); Handle getter = SimpleCreateFunction(isolate, getter_name, call_getter, 0, true); getter->shared()->set_native(true); Handle setter_name = Name::ToFunctionName(name, isolate->factory()->set_string()) .ToHandleChecked(); Handle setter = SimpleCreateFunction(isolate, setter_name, call_setter, 1, true); setter->shared()->set_native(true); JSObject::DefineAccessor(base, name, getter, setter, attribs).Check(); } Handle SimpleInstallGetter(Handle base, Handle name, Handle property_name, Builtins::Name call, bool adapt) { Isolate* const isolate = base->GetIsolate(); Handle getter_name = Name::ToFunctionName(name, isolate->factory()->get_string()) .ToHandleChecked(); Handle getter = SimpleCreateFunction(isolate, getter_name, call, 0, adapt); getter->shared()->set_native(true); Handle setter = isolate->factory()->undefined_value(); JSObject::DefineAccessor(base, property_name, getter, setter, DONT_ENUM) .Check(); return getter; } Handle SimpleInstallGetter(Handle base, Handle name, Builtins::Name call, bool adapt) { return SimpleInstallGetter(base, name, name, call, adapt); } Handle SimpleInstallGetter(Handle base, Handle name, Builtins::Name call, bool adapt, BuiltinFunctionId id) { Handle fun = SimpleInstallGetter(base, name, call, adapt); fun->shared()->set_builtin_function_id(id); return fun; } } // namespace 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 = factory()->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 = factory()->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_ = factory()->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); // Ban re-setting Object.prototype.__proto__ to prevent Proxy security bug map->set_immutable_proto(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 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 = factory->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 = factory->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系统代码 收藏喜欢的文章 多个平台共享账号 去登录 首次使用?从这里 注册
您还没有登录,登录后您可以:
首次使用?从这里 注册