Chromium Code Reviews| Index: src/bootstrapper.cc |
| diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
| index 26857502da6705d59e88a1d81fb8b7e74e3f8686..2ecfa0bccba4ed5e0a9e959b205d18debaa83fb3 100644 |
| --- a/src/bootstrapper.cc |
| +++ b/src/bootstrapper.cc |
| @@ -218,6 +218,7 @@ class Genesis BASE_EMBEDDED { |
| void InstallBuiltinFunctionIds(); |
| void InstallExperimentalBuiltinFunctionIds(); |
| void InitializeNormalizedMapCaches(); |
| + void InstallJSProxyMaps(); |
| enum ExtensionTraversalState { |
| UNVISITED, VISITED, INSTALLED |
| @@ -362,6 +363,20 @@ void Bootstrapper::DetachGlobal(Handle<Context> env) { |
| namespace { |
| +Handle<JSFunction> InstallFunction(Handle<JSObject> target, |
| + Handle<Name> property_name, |
| + Handle<JSFunction> function, |
| + Handle<String> function_name, |
| + PropertyAttributes attributes = DONT_ENUM) { |
| + JSObject::AddProperty(target, property_name, function, attributes); |
| + if (target->IsJSGlobalObject()) { |
| + function->shared()->set_instance_class_name(*function_name); |
| + } |
| + function->shared()->set_native(true); |
| + return function; |
| +} |
| + |
| + |
| Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
| InstanceType type, int instance_size, |
| MaybeHandle<JSObject> maybe_prototype, |
| @@ -382,12 +397,7 @@ Handle<JSFunction> InstallFunction(Handle<JSObject> target, Handle<Name> name, |
| kInstallConstructor, strict_function_map) |
| : factory->NewFunctionWithoutPrototype(name_string, call_code, |
| strict_function_map); |
| - JSObject::AddProperty(target, name, function, attributes); |
| - if (target->IsJSGlobalObject()) { |
| - function->shared()->set_instance_class_name(*name_string); |
| - } |
| - function->shared()->set_native(true); |
| - return function; |
| + return InstallFunction(target, name, function, name_string, attributes); |
| } |
| @@ -2110,21 +2120,52 @@ void Genesis::InitializeGlobal_harmony_simd() { |
| } |
| +void Genesis::InstallJSProxyMaps() { |
| + // Allocate the different maps for all Proxy types. |
| + // Next to the default proxy, we need maps indicating callable and |
| + // constructable proxies. |
| + |
| + Handle<Map> proxy_map = |
| + factory()->NewMap(JS_PROXY_TYPE, JSProxy::kSize, FAST_ELEMENTS); |
| + native_context()->set_proxy_map(*proxy_map); |
| + |
| + Handle<Map> proxy_callable_map = Map::Copy(proxy_map, "callable Proxy"); |
| + proxy_callable_map->set_is_callable(); |
| + native_context()->set_proxy_callable_map(*proxy_callable_map); |
| + |
| + Handle<Map> proxy_constructor_map = |
| + Map::Copy(proxy_callable_map, "constructor Proxy"); |
| + proxy_constructor_map->set_is_constructor(true); |
| + native_context()->set_proxy_constructor_map(*proxy_constructor_map); |
| +} |
| + |
| + |
| void Genesis::InitializeGlobal_harmony_proxies() { |
| if (!FLAG_harmony_proxies) return; |
| Handle<JSGlobalObject> global( |
| JSGlobalObject::cast(native_context()->global_object())); |
| Isolate* isolate = global->GetIsolate(); |
| - Handle<JSFunction> proxy_fun = InstallFunction( |
| - global, "Proxy", JS_PROXY_TYPE, JSProxy::kSize, |
| - isolate->initial_object_prototype(), Builtins::kProxyConstructor); |
| - // TODO(verwaest): Set to null in InstallFunction. |
| - proxy_fun->initial_map()->set_prototype(isolate->heap()->null_value()); |
| + Factory* factory = isolate->factory(); |
| + |
| + InstallJSProxyMaps(); |
| + |
| + // Create the Proxy object. |
| + Handle<String> name = factory->InternalizeUtf8String("Proxy"); |
|
Jakob Kummerow
2015/12/07 15:55:07
"Proxy" should probably be in the INTERNALIZED_STR
Camillo Bruni
2015/12/07 16:54:10
indeed, better.
|
| + Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
|
Jakob Kummerow
2015/12/07 15:55:07
This doesn't do anything, feel free to drop it.
|
| + Handle<Code> code(isolate->builtins()->builtin(Builtins::kProxyConstructor)); |
| + Handle<JSFunction> proxy_fun = |
| + factory->NewFunctionWithoutPrototype(name_string, code, false); |
| + JSFunction::SetInitialMap(proxy_fun, |
| + Handle<Map>(native_context()->proxy_map(), isolate), |
| + factory->null_value()); |
| + proxy_fun->map()->set_is_constructor(true); |
|
Toon Verwaest
2015/12/07 16:32:57
this turns all sloppy functions without prototype
Camillo Bruni
2015/12/07 16:54:10
no no, it wont :(... changed
|
| proxy_fun->shared()->set_construct_stub( |
| *isolate->builtins()->ProxyConstructor_ConstructStub()); |
| proxy_fun->shared()->set_internal_formal_parameter_count(2); |
| proxy_fun->shared()->set_length(2); |
| + |
| native_context()->set_proxy_function(*proxy_fun); |
| + InstallFunction(global, name, proxy_fun, name_string); |
| } |