OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/base/ieee754.h" | 9 #include "src/base/ieee754.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 js_global_object_function->initial_map()->set_is_prototype_map(true); | 953 js_global_object_function->initial_map()->set_is_prototype_map(true); |
954 js_global_object_function->initial_map()->set_dictionary_map(true); | 954 js_global_object_function->initial_map()->set_dictionary_map(true); |
955 Handle<JSGlobalObject> global_object = | 955 Handle<JSGlobalObject> global_object = |
956 factory()->NewJSGlobalObject(js_global_object_function); | 956 factory()->NewJSGlobalObject(js_global_object_function); |
957 | 957 |
958 // Step 2: (re)initialize the global proxy object. | 958 // Step 2: (re)initialize the global proxy object. |
959 Handle<JSFunction> global_proxy_function; | 959 Handle<JSFunction> global_proxy_function; |
960 if (global_proxy_template.IsEmpty()) { | 960 if (global_proxy_template.IsEmpty()) { |
961 Handle<String> name = Handle<String>(heap()->empty_string()); | 961 Handle<String> name = Handle<String>(heap()->empty_string()); |
962 Handle<Code> code = isolate()->builtins()->Illegal(); | 962 Handle<Code> code = isolate()->builtins()->Illegal(); |
963 global_proxy_function = | 963 global_proxy_function = factory()->NewFunction( |
964 factory()->NewFunction(name, code, JS_GLOBAL_PROXY_TYPE, | 964 name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::SizeFor(0)); |
965 JSGlobalProxy::kSizeWithInternalFields); | |
966 } else { | 965 } else { |
967 Handle<ObjectTemplateInfo> data = | 966 Handle<ObjectTemplateInfo> data = |
968 v8::Utils::OpenHandle(*global_proxy_template); | 967 v8::Utils::OpenHandle(*global_proxy_template); |
969 Handle<FunctionTemplateInfo> global_constructor( | 968 Handle<FunctionTemplateInfo> global_constructor( |
970 FunctionTemplateInfo::cast(data->constructor())); | 969 FunctionTemplateInfo::cast(data->constructor())); |
971 global_proxy_function = ApiNatives::CreateApiFunction( | 970 global_proxy_function = ApiNatives::CreateApiFunction( |
972 isolate(), global_constructor, factory()->the_hole_value(), | 971 isolate(), global_constructor, factory()->the_hole_value(), |
973 ApiNatives::GlobalProxyType); | 972 ApiNatives::GlobalProxyType); |
974 } | 973 } |
975 Handle<String> global_name = factory()->global_string(); | 974 Handle<String> global_name = factory()->global_string(); |
(...skipping 3385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4361 if (check.HasOverflowed()) { | 4360 if (check.HasOverflowed()) { |
4362 isolate->StackOverflow(); | 4361 isolate->StackOverflow(); |
4363 return; | 4362 return; |
4364 } | 4363 } |
4365 | 4364 |
4366 // The deserializer needs to hook up references to the global proxy. | 4365 // The deserializer needs to hook up references to the global proxy. |
4367 // Create an uninitialized global proxy now if we don't have one | 4366 // Create an uninitialized global proxy now if we don't have one |
4368 // and initialize it later in CreateNewGlobals. | 4367 // and initialize it later in CreateNewGlobals. |
4369 Handle<JSGlobalProxy> global_proxy; | 4368 Handle<JSGlobalProxy> global_proxy; |
4370 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 4369 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
4371 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); | 4370 const int internal_field_count = |
| 4371 !global_proxy_template.IsEmpty() |
| 4372 ? global_proxy_template->InternalFieldCount() |
| 4373 : 0; |
| 4374 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy( |
| 4375 JSGlobalProxy::SizeFor(internal_field_count)); |
4372 } | 4376 } |
4373 | 4377 |
4374 // We can only de-serialize a context if the isolate was initialized from | 4378 // We can only de-serialize a context if the isolate was initialized from |
4375 // a snapshot. Otherwise we have to build the context from scratch. | 4379 // a snapshot. Otherwise we have to build the context from scratch. |
4376 // Also create a context from scratch to expose natives, if required by flag. | 4380 // Also create a context from scratch to expose natives, if required by flag. |
4377 if (!isolate->initialized_from_snapshot() || | 4381 if (!isolate->initialized_from_snapshot() || |
4378 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, | 4382 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, |
4379 context_snapshot_index) | 4383 context_snapshot_index) |
4380 .ToHandle(&native_context_)) { | 4384 .ToHandle(&native_context_)) { |
4381 native_context_ = Handle<Context>(); | 4385 native_context_ = Handle<Context>(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4470 | 4474 |
4471 // During genesis, the boilerplate for stack overflow won't work until the | 4475 // During genesis, the boilerplate for stack overflow won't work until the |
4472 // environment has been at least partially initialized. Add a stack check | 4476 // environment has been at least partially initialized. Add a stack check |
4473 // before entering JS code to catch overflow early. | 4477 // before entering JS code to catch overflow early. |
4474 StackLimitCheck check(isolate); | 4478 StackLimitCheck check(isolate); |
4475 if (check.HasOverflowed()) { | 4479 if (check.HasOverflowed()) { |
4476 isolate->StackOverflow(); | 4480 isolate->StackOverflow(); |
4477 return; | 4481 return; |
4478 } | 4482 } |
4479 | 4483 |
| 4484 const int proxy_size = |
| 4485 JSGlobalProxy::SizeFor(global_proxy_template->InternalFieldCount()); |
| 4486 |
4480 Handle<JSGlobalProxy> global_proxy; | 4487 Handle<JSGlobalProxy> global_proxy; |
4481 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 4488 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
4482 global_proxy = factory()->NewUninitializedJSGlobalProxy(); | 4489 global_proxy = factory()->NewUninitializedJSGlobalProxy(proxy_size); |
4483 } | 4490 } |
4484 | 4491 |
4485 // CreateNewGlobals. | 4492 // CreateNewGlobals. |
4486 Handle<ObjectTemplateInfo> global_proxy_data = | 4493 Handle<ObjectTemplateInfo> global_proxy_data = |
4487 v8::Utils::OpenHandle(*global_proxy_template); | 4494 v8::Utils::OpenHandle(*global_proxy_template); |
4488 Handle<FunctionTemplateInfo> global_constructor( | 4495 Handle<FunctionTemplateInfo> global_constructor( |
4489 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 4496 FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
4490 Handle<SharedFunctionInfo> shared = | 4497 Handle<SharedFunctionInfo> shared = |
4491 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, | 4498 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, |
4492 global_constructor); | 4499 global_constructor); |
4493 Handle<Map> initial_map = | 4500 Handle<Map> initial_map = |
4494 factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); | 4501 factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); |
4495 Handle<JSFunction> global_proxy_function = | 4502 Handle<JSFunction> global_proxy_function = |
4496 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 4503 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
4497 initial_map, shared, factory()->undefined_value()); | 4504 initial_map, shared, factory()->undefined_value()); |
4498 DCHECK_EQ(global_proxy_data->internal_field_count(), | 4505 DCHECK_EQ(global_proxy_data->internal_field_count(), |
4499 v8::Context::kProxyInternalFieldCount); | 4506 global_proxy_template->InternalFieldCount()); |
4500 Handle<Map> global_proxy_map = isolate->factory()->NewMap( | 4507 Handle<Map> global_proxy_map = isolate->factory()->NewMap( |
4501 JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSizeWithInternalFields, | 4508 JS_GLOBAL_PROXY_TYPE, proxy_size, FAST_HOLEY_SMI_ELEMENTS); |
4502 FAST_HOLEY_SMI_ELEMENTS); | |
4503 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, | 4509 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, |
4504 factory()->null_value()); | 4510 factory()->null_value()); |
4505 global_proxy_map->set_is_access_check_needed(true); | 4511 global_proxy_map->set_is_access_check_needed(true); |
4506 global_proxy_map->set_is_callable(); | 4512 global_proxy_map->set_is_callable(); |
4507 global_proxy_map->set_is_constructor(true); | 4513 global_proxy_map->set_is_constructor(true); |
4508 global_proxy_map->set_has_hidden_prototype(true); | 4514 global_proxy_map->set_has_hidden_prototype(true); |
4509 | 4515 |
4510 Handle<String> global_name = factory()->global_string(); | 4516 Handle<String> global_name = factory()->global_string(); |
4511 global_proxy_function->shared()->set_instance_class_name(*global_name); | 4517 global_proxy_function->shared()->set_instance_class_name(*global_name); |
4512 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | 4518 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
(...skipping 30 matching lines...) Expand all Loading... |
4543 } | 4549 } |
4544 | 4550 |
4545 | 4551 |
4546 // Called when the top-level V8 mutex is destroyed. | 4552 // Called when the top-level V8 mutex is destroyed. |
4547 void Bootstrapper::FreeThreadResources() { | 4553 void Bootstrapper::FreeThreadResources() { |
4548 DCHECK(!IsActive()); | 4554 DCHECK(!IsActive()); |
4549 } | 4555 } |
4550 | 4556 |
4551 } // namespace internal | 4557 } // namespace internal |
4552 } // namespace v8 | 4558 } // namespace v8 |
OLD | NEW |