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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 Handle<Context> Bootstrapper::CreateEnvironment( | 325 Handle<Context> Bootstrapper::CreateEnvironment( |
326 MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 326 MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
327 v8::Local<v8::ObjectTemplate> global_proxy_template, | 327 v8::Local<v8::ObjectTemplate> global_proxy_template, |
328 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, | 328 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, |
329 GlobalContextType context_type) { | 329 GlobalContextType context_type) { |
330 HandleScope scope(isolate_); | 330 HandleScope scope(isolate_); |
331 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, | 331 Genesis genesis(isolate_, maybe_global_proxy, global_proxy_template, |
332 extensions, context_snapshot_index, context_type); | 332 extensions, context_snapshot_index, context_type); |
333 Handle<Context> env = genesis.result(); | 333 Handle<Context> env = genesis.result(); |
334 if (env.is_null() || | 334 if (env.is_null() || !InstallExtensions(env, extensions)) { |
335 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { | |
336 return Handle<Context>(); | 335 return Handle<Context>(); |
337 } | 336 } |
338 return scope.CloseAndEscape(env); | 337 return scope.CloseAndEscape(env); |
339 } | 338 } |
340 | 339 |
341 | 340 |
342 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | 341 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
343 // object.__proto__ = proto; | 342 // object.__proto__ = proto; |
344 Handle<Map> old_map = Handle<Map>(object->map()); | 343 Handle<Map> old_map = Handle<Map>(object->map()); |
345 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); | 344 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 global, "URIError", JS_ERROR_TYPE, JSObject::kHeaderSize, | 1632 global, "URIError", JS_ERROR_TYPE, JSObject::kHeaderSize, |
1634 isolate->initial_object_prototype(), Builtins::kIllegal); | 1633 isolate->initial_object_prototype(), Builtins::kIllegal); |
1635 InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, | 1634 InstallWithIntrinsicDefaultProto(isolate, uri_error_fun, |
1636 Context::URI_ERROR_FUNCTION_INDEX); | 1635 Context::URI_ERROR_FUNCTION_INDEX); |
1637 } | 1636 } |
1638 | 1637 |
1639 // Initialize the embedder data slot. | 1638 // Initialize the embedder data slot. |
1640 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); | 1639 Handle<FixedArray> embedder_data = factory->NewFixedArray(3); |
1641 native_context()->set_embedder_data(*embedder_data); | 1640 native_context()->set_embedder_data(*embedder_data); |
1642 | 1641 |
1643 if (context_type == THIN_CONTEXT) return; | |
1644 | |
1645 { // -- J S O N | 1642 { // -- J S O N |
1646 Handle<String> name = factory->InternalizeUtf8String("JSON"); | 1643 Handle<String> name = factory->InternalizeUtf8String("JSON"); |
1647 Handle<JSFunction> cons = factory->NewFunction(name); | 1644 Handle<JSFunction> cons = factory->NewFunction(name); |
1648 JSFunction::SetInstancePrototype(cons, | 1645 JSFunction::SetInstancePrototype(cons, |
1649 Handle<Object>(native_context()->initial_object_prototype(), isolate)); | 1646 Handle<Object>(native_context()->initial_object_prototype(), isolate)); |
1650 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); | 1647 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); |
1651 DCHECK(json_object->IsJSObject()); | 1648 DCHECK(json_object->IsJSObject()); |
1652 JSObject::AddProperty(global, name, json_object, DONT_ENUM); | 1649 JSObject::AddProperty(global, name, json_object, DONT_ENUM); |
1653 SimpleInstallFunction(json_object, "parse", Builtins::kJsonParse, 2, false); | 1650 SimpleInstallFunction(json_object, "parse", Builtins::kJsonParse, 2, false); |
1654 SimpleInstallFunction(json_object, "stringify", Builtins::kJsonStringify, 3, | 1651 SimpleInstallFunction(json_object, "stringify", Builtins::kJsonStringify, 3, |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 HandleScope scope(isolate()); | 2349 HandleScope scope(isolate()); |
2353 Handle<String> natives_key = | 2350 Handle<String> natives_key = |
2354 factory()->InternalizeUtf8String(FLAG_expose_natives_as); | 2351 factory()->InternalizeUtf8String(FLAG_expose_natives_as); |
2355 uint32_t dummy_index; | 2352 uint32_t dummy_index; |
2356 if (natives_key->AsArrayIndex(&dummy_index)) break; | 2353 if (natives_key->AsArrayIndex(&dummy_index)) break; |
2357 Handle<Object> utils = isolate()->natives_utils_object(); | 2354 Handle<Object> utils = isolate()->natives_utils_object(); |
2358 Handle<JSObject> global = isolate()->global_object(); | 2355 Handle<JSObject> global = isolate()->global_object(); |
2359 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM); | 2356 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM); |
2360 break; | 2357 break; |
2361 } | 2358 } |
2362 case THIN_CONTEXT: | |
2363 break; | |
2364 } | 2359 } |
2365 | 2360 |
2366 // The utils object can be removed for cases that reach this point. | 2361 // The utils object can be removed for cases that reach this point. |
2367 native_context()->set_natives_utils_object(heap()->undefined_value()); | 2362 native_context()->set_natives_utils_object(heap()->undefined_value()); |
2368 } | 2363 } |
2369 | 2364 |
2370 | 2365 |
2371 void Bootstrapper::ExportFromRuntime(Isolate* isolate, | 2366 void Bootstrapper::ExportFromRuntime(Isolate* isolate, |
2372 Handle<JSObject> container) { | 2367 Handle<JSObject> container) { |
2373 Factory* factory = isolate->factory(); | 2368 Factory* factory = isolate->factory(); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2907 | 2902 |
2908 InstallInternalArray(extras_utils, "InternalPackedArray", FAST_ELEMENTS); | 2903 InstallInternalArray(extras_utils, "InternalPackedArray", FAST_ELEMENTS); |
2909 | 2904 |
2910 int builtin_index = Natives::GetDebuggerCount(); | 2905 int builtin_index = Natives::GetDebuggerCount(); |
2911 // Only run prologue.js and runtime.js at this point. | 2906 // Only run prologue.js and runtime.js at this point. |
2912 DCHECK_EQ(builtin_index, Natives::GetIndex("prologue")); | 2907 DCHECK_EQ(builtin_index, Natives::GetIndex("prologue")); |
2913 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; | 2908 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
2914 DCHECK_EQ(builtin_index, Natives::GetIndex("runtime")); | 2909 DCHECK_EQ(builtin_index, Natives::GetIndex("runtime")); |
2915 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; | 2910 if (!Bootstrapper::CompileBuiltin(isolate(), builtin_index++)) return false; |
2916 | 2911 |
2917 // A thin context is ready at this point. | |
2918 if (context_type == THIN_CONTEXT) return true; | |
2919 | |
2920 { | 2912 { |
2921 // Builtin function for OpaqueReference -- a JSValue-based object, | 2913 // Builtin function for OpaqueReference -- a JSValue-based object, |
2922 // that keeps its field isolated from JavaScript code. It may store | 2914 // that keeps its field isolated from JavaScript code. It may store |
2923 // objects, that JavaScript code may not access. | 2915 // objects, that JavaScript code may not access. |
2924 Handle<JSFunction> opaque_reference_fun = factory()->NewFunction( | 2916 Handle<JSFunction> opaque_reference_fun = factory()->NewFunction( |
2925 factory()->empty_string(), isolate()->builtins()->Illegal(), | 2917 factory()->empty_string(), isolate()->builtins()->Illegal(), |
2926 isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize); | 2918 isolate()->initial_object_prototype(), JS_VALUE_TYPE, JSValue::kSize); |
2927 Handle<JSObject> prototype = | 2919 Handle<JSObject> prototype = |
2928 factory()->NewJSObject(isolate()->object_function(), TENURED); | 2920 factory()->NewJSObject(isolate()->object_function(), TENURED); |
2929 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); | 2921 Accessors::FunctionSetPrototype(opaque_reference_fun, prototype).Assert(); |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3876 Handle<JSGlobalObject> global_object = | 3868 Handle<JSGlobalObject> global_object = |
3877 CreateNewGlobals(global_proxy_template, global_proxy); | 3869 CreateNewGlobals(global_proxy_template, global_proxy); |
3878 HookUpGlobalProxy(global_object, global_proxy); | 3870 HookUpGlobalProxy(global_object, global_proxy); |
3879 InitializeGlobal(global_object, empty_function, context_type); | 3871 InitializeGlobal(global_object, empty_function, context_type); |
3880 InitializeNormalizedMapCaches(); | 3872 InitializeNormalizedMapCaches(); |
3881 | 3873 |
3882 if (!InstallNatives(context_type)) return; | 3874 if (!InstallNatives(context_type)) return; |
3883 | 3875 |
3884 MakeFunctionInstancePrototypeWritable(); | 3876 MakeFunctionInstancePrototypeWritable(); |
3885 | 3877 |
3886 if (context_type != THIN_CONTEXT) { | 3878 if (!InstallExtraNatives()) return; |
3887 if (!InstallExtraNatives()) return; | 3879 if (!ConfigureGlobalObjects(global_proxy_template)) return; |
3888 if (!ConfigureGlobalObjects(global_proxy_template)) return; | 3880 |
3889 } | |
3890 isolate->counters()->contexts_created_from_scratch()->Increment(); | 3881 isolate->counters()->contexts_created_from_scratch()->Increment(); |
3891 // Re-initialize the counter because it got incremented during snapshot | 3882 // Re-initialize the counter because it got incremented during snapshot |
3892 // creation. | 3883 // creation. |
3893 isolate->native_context()->set_errors_thrown(Smi::FromInt(0)); | 3884 isolate->native_context()->set_errors_thrown(Smi::FromInt(0)); |
3894 } | 3885 } |
3895 | 3886 |
3896 // Install experimental natives. Do not include them into the | 3887 // Install experimental natives. Do not include them into the |
3897 // snapshot as we should be able to turn them off at runtime. Re-installing | 3888 // snapshot as we should be able to turn them off at runtime. Re-installing |
3898 // them after they have already been deserialized would also fail. | 3889 // them after they have already been deserialized would also fail. |
3899 if (context_type == FULL_CONTEXT) { | 3890 if (context_type == FULL_CONTEXT) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3948 } | 3939 } |
3949 | 3940 |
3950 | 3941 |
3951 // Called when the top-level V8 mutex is destroyed. | 3942 // Called when the top-level V8 mutex is destroyed. |
3952 void Bootstrapper::FreeThreadResources() { | 3943 void Bootstrapper::FreeThreadResources() { |
3953 DCHECK(!IsActive()); | 3944 DCHECK(!IsActive()); |
3954 } | 3945 } |
3955 | 3946 |
3956 } // namespace internal | 3947 } // namespace internal |
3957 } // namespace v8 | 3948 } // namespace v8 |
OLD | NEW |