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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = |
964 factory()->NewFunction(name, code, JS_GLOBAL_PROXY_TYPE, | 964 factory()->NewFunction(name, code, JS_GLOBAL_PROXY_TYPE, |
965 JSGlobalProxy::kSizeWithInternalFields); | 965 JSGlobalProxy::SizeWithInternalFields(0)); |
966 } else { | 966 } else { |
967 Handle<ObjectTemplateInfo> data = | 967 Handle<ObjectTemplateInfo> data = |
968 v8::Utils::OpenHandle(*global_proxy_template); | 968 v8::Utils::OpenHandle(*global_proxy_template); |
969 Handle<FunctionTemplateInfo> global_constructor( | 969 Handle<FunctionTemplateInfo> global_constructor( |
970 FunctionTemplateInfo::cast(data->constructor())); | 970 FunctionTemplateInfo::cast(data->constructor())); |
971 global_proxy_function = ApiNatives::CreateApiFunction( | 971 global_proxy_function = ApiNatives::CreateApiFunction( |
972 isolate(), global_constructor, factory()->the_hole_value(), | 972 isolate(), global_constructor, factory()->the_hole_value(), |
973 ApiNatives::GlobalProxyType); | 973 ApiNatives::GlobalProxyType); |
974 } | 974 } |
975 Handle<String> global_name = factory()->global_string(); | 975 Handle<String> global_name = factory()->global_string(); |
(...skipping 3385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4361 if (check.HasOverflowed()) { | 4361 if (check.HasOverflowed()) { |
4362 isolate->StackOverflow(); | 4362 isolate->StackOverflow(); |
4363 return; | 4363 return; |
4364 } | 4364 } |
4365 | 4365 |
4366 // The deserializer needs to hook up references to the global proxy. | 4366 // The deserializer needs to hook up references to the global proxy. |
4367 // Create an uninitialized global proxy now if we don't have one | 4367 // Create an uninitialized global proxy now if we don't have one |
4368 // and initialize it later in CreateNewGlobals. | 4368 // and initialize it later in CreateNewGlobals. |
4369 Handle<JSGlobalProxy> global_proxy; | 4369 Handle<JSGlobalProxy> global_proxy; |
4370 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 4370 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
4371 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy(); | 4371 const int internal_field_count = |
| 4372 !global_proxy_template.IsEmpty() |
| 4373 ? global_proxy_template->InternalFieldCount() |
| 4374 : 0; |
| 4375 global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy( |
| 4376 JSGlobalProxy::SizeWithInternalFields(internal_field_count)); |
4372 } | 4377 } |
4373 | 4378 |
4374 // We can only de-serialize a context if the isolate was initialized from | 4379 // 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. | 4380 // 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. | 4381 // Also create a context from scratch to expose natives, if required by flag. |
4377 if (!isolate->initialized_from_snapshot() || | 4382 if (!isolate->initialized_from_snapshot() || |
4378 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, | 4383 !Snapshot::NewContextFromSnapshot(isolate, global_proxy, |
4379 context_snapshot_index) | 4384 context_snapshot_index) |
4380 .ToHandle(&native_context_)) { | 4385 .ToHandle(&native_context_)) { |
4381 native_context_ = Handle<Context>(); | 4386 native_context_ = Handle<Context>(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4470 | 4475 |
4471 // During genesis, the boilerplate for stack overflow won't work until the | 4476 // During genesis, the boilerplate for stack overflow won't work until the |
4472 // environment has been at least partially initialized. Add a stack check | 4477 // environment has been at least partially initialized. Add a stack check |
4473 // before entering JS code to catch overflow early. | 4478 // before entering JS code to catch overflow early. |
4474 StackLimitCheck check(isolate); | 4479 StackLimitCheck check(isolate); |
4475 if (check.HasOverflowed()) { | 4480 if (check.HasOverflowed()) { |
4476 isolate->StackOverflow(); | 4481 isolate->StackOverflow(); |
4477 return; | 4482 return; |
4478 } | 4483 } |
4479 | 4484 |
| 4485 const int proxy_size = JSGlobalProxy::SizeWithInternalFields( |
| 4486 global_proxy_template->InternalFieldCount()); |
| 4487 |
4480 Handle<JSGlobalProxy> global_proxy; | 4488 Handle<JSGlobalProxy> global_proxy; |
4481 if (!maybe_global_proxy.ToHandle(&global_proxy)) { | 4489 if (!maybe_global_proxy.ToHandle(&global_proxy)) { |
4482 global_proxy = factory()->NewUninitializedJSGlobalProxy(); | 4490 global_proxy = factory()->NewUninitializedJSGlobalProxy(proxy_size); |
4483 } | 4491 } |
4484 | 4492 |
4485 // CreateNewGlobals. | 4493 // CreateNewGlobals. |
4486 Handle<ObjectTemplateInfo> global_proxy_data = | 4494 Handle<ObjectTemplateInfo> global_proxy_data = |
4487 v8::Utils::OpenHandle(*global_proxy_template); | 4495 v8::Utils::OpenHandle(*global_proxy_template); |
4488 Handle<FunctionTemplateInfo> global_constructor( | 4496 Handle<FunctionTemplateInfo> global_constructor( |
4489 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 4497 FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
4490 Handle<SharedFunctionInfo> shared = | 4498 Handle<SharedFunctionInfo> shared = |
4491 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, | 4499 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, |
4492 global_constructor); | 4500 global_constructor); |
4493 Handle<Map> initial_map = | 4501 Handle<Map> initial_map = |
4494 factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); | 4502 factory()->CreateSloppyFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE); |
4495 Handle<JSFunction> global_proxy_function = | 4503 Handle<JSFunction> global_proxy_function = |
4496 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 4504 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
4497 initial_map, shared, factory()->undefined_value()); | 4505 initial_map, shared, factory()->undefined_value()); |
4498 DCHECK_EQ(global_proxy_data->internal_field_count(), | 4506 DCHECK_EQ(global_proxy_data->internal_field_count(), |
4499 v8::Context::kProxyInternalFieldCount); | 4507 global_proxy_template->InternalFieldCount()); |
4500 Handle<Map> global_proxy_map = isolate->factory()->NewMap( | 4508 Handle<Map> global_proxy_map = isolate->factory()->NewMap( |
4501 JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSizeWithInternalFields, | 4509 JS_GLOBAL_PROXY_TYPE, proxy_size, FAST_HOLEY_SMI_ELEMENTS); |
4502 FAST_HOLEY_SMI_ELEMENTS); | |
4503 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, | 4510 JSFunction::SetInitialMap(global_proxy_function, global_proxy_map, |
4504 factory()->null_value()); | 4511 factory()->null_value()); |
4505 global_proxy_map->set_is_access_check_needed(true); | 4512 global_proxy_map->set_is_access_check_needed(true); |
4506 global_proxy_map->set_is_callable(); | 4513 global_proxy_map->set_is_callable(); |
4507 global_proxy_map->set_is_constructor(true); | 4514 global_proxy_map->set_is_constructor(true); |
4508 global_proxy_map->set_has_hidden_prototype(true); | 4515 global_proxy_map->set_has_hidden_prototype(true); |
4509 | 4516 |
4510 Handle<String> global_name = factory()->global_string(); | 4517 Handle<String> global_name = factory()->global_string(); |
4511 global_proxy_function->shared()->set_instance_class_name(*global_name); | 4518 global_proxy_function->shared()->set_instance_class_name(*global_name); |
4512 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); | 4519 factory()->ReinitializeJSGlobalProxy(global_proxy, global_proxy_function); |
(...skipping 30 matching lines...) Expand all Loading... |
4543 } | 4550 } |
4544 | 4551 |
4545 | 4552 |
4546 // Called when the top-level V8 mutex is destroyed. | 4553 // Called when the top-level V8 mutex is destroyed. |
4547 void Bootstrapper::FreeThreadResources() { | 4554 void Bootstrapper::FreeThreadResources() { |
4548 DCHECK(!IsActive()); | 4555 DCHECK(!IsActive()); |
4549 } | 4556 } |
4550 | 4557 |
4551 } // namespace internal | 4558 } // namespace internal |
4552 } // namespace v8 | 4559 } // namespace v8 |
OLD | NEW |