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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return Handle<String>::cast(cached_source); | 52 return Handle<String>::cast(cached_source); |
53 } | 53 } |
54 | 54 |
55 | 55 |
56 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); | 56 template Handle<String> Bootstrapper::SourceLookup<Natives>(int index); |
57 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( | 57 template Handle<String> Bootstrapper::SourceLookup<ExperimentalNatives>( |
58 int index); | 58 int index); |
59 template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>( | 59 template Handle<String> Bootstrapper::SourceLookup<ExperimentalExtraNatives>( |
60 int index); | 60 int index); |
61 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); | 61 template Handle<String> Bootstrapper::SourceLookup<ExtraNatives>(int index); |
62 template Handle<String> Bootstrapper::SourceLookup<CodeStubNatives>(int index); | |
63 | 62 |
64 | 63 |
65 void Bootstrapper::Initialize(bool create_heap_objects) { | 64 void Bootstrapper::Initialize(bool create_heap_objects) { |
66 extensions_cache_.Initialize(isolate_, create_heap_objects); | 65 extensions_cache_.Initialize(isolate_, create_heap_objects); |
67 } | 66 } |
68 | 67 |
69 | 68 |
70 static const char* GCFunctionName() { | 69 static const char* GCFunctionName() { |
71 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; | 70 bool flag_given = FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0; |
72 return flag_given ? FLAG_expose_gc_as : "gc"; | 71 return flag_given ? FLAG_expose_gc_as : "gc"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 122 } |
124 } | 123 } |
125 | 124 |
126 | 125 |
127 void Bootstrapper::TearDown() { | 126 void Bootstrapper::TearDown() { |
128 DeleteNativeSources(Natives::GetSourceCache(isolate_->heap())); | 127 DeleteNativeSources(Natives::GetSourceCache(isolate_->heap())); |
129 DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap())); | 128 DeleteNativeSources(ExperimentalNatives::GetSourceCache(isolate_->heap())); |
130 DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap())); | 129 DeleteNativeSources(ExtraNatives::GetSourceCache(isolate_->heap())); |
131 DeleteNativeSources( | 130 DeleteNativeSources( |
132 ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); | 131 ExperimentalExtraNatives::GetSourceCache(isolate_->heap())); |
133 DeleteNativeSources(CodeStubNatives::GetSourceCache(isolate_->heap())); | |
134 | 132 |
135 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical | 133 extensions_cache_.Initialize(isolate_, false); // Yes, symmetrical |
136 } | 134 } |
137 | 135 |
138 | 136 |
139 class Genesis BASE_EMBEDDED { | 137 class Genesis BASE_EMBEDDED { |
140 public: | 138 public: |
141 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, | 139 Genesis(Isolate* isolate, MaybeHandle<JSGlobalProxy> maybe_global_proxy, |
142 v8::Local<v8::ObjectTemplate> global_proxy_template, | 140 v8::Local<v8::ObjectTemplate> global_proxy_template, |
143 v8::ExtensionConfiguration* extensions, ContextType context_type); | 141 v8::ExtensionConfiguration* extensions, ContextType context_type); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 extensions, context_type); | 332 extensions, context_type); |
335 Handle<Context> env = genesis.result(); | 333 Handle<Context> env = genesis.result(); |
336 if (env.is_null() || | 334 if (env.is_null() || |
337 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { | 335 (context_type != THIN_CONTEXT && !InstallExtensions(env, extensions))) { |
338 return Handle<Context>(); | 336 return Handle<Context>(); |
339 } | 337 } |
340 return scope.CloseAndEscape(env); | 338 return scope.CloseAndEscape(env); |
341 } | 339 } |
342 | 340 |
343 | 341 |
344 bool Bootstrapper::CreateCodeStubContext(Isolate* isolate) { | |
345 HandleScope scope(isolate); | |
346 SaveContext save_context(isolate); | |
347 BootstrapperActive active(this); | |
348 | |
349 v8::ExtensionConfiguration no_extensions; | |
350 Handle<Context> native_context = CreateEnvironment( | |
351 MaybeHandle<JSGlobalProxy>(), v8::Local<v8::ObjectTemplate>(), | |
352 &no_extensions, THIN_CONTEXT); | |
353 isolate->heap()->SetRootCodeStubContext(*native_context); | |
354 isolate->set_context(*native_context); | |
355 Handle<JSObject> code_stub_exports = | |
356 isolate->factory()->NewJSObject(isolate->object_function()); | |
357 JSObject::NormalizeProperties(code_stub_exports, CLEAR_INOBJECT_PROPERTIES, 2, | |
358 "container to export to extra natives"); | |
359 isolate->heap()->SetRootCodeStubExportsObject(*code_stub_exports); | |
360 return InstallCodeStubNatives(isolate); | |
361 } | |
362 | |
363 | |
364 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { | 342 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) { |
365 // object.__proto__ = proto; | 343 // object.__proto__ = proto; |
366 Handle<Map> old_map = Handle<Map>(object->map()); | 344 Handle<Map> old_map = Handle<Map>(object->map()); |
367 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); | 345 Handle<Map> new_map = Map::Copy(old_map, "SetObjectPrototype"); |
368 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); | 346 Map::SetPrototype(new_map, proto, FAST_PROTOTYPE); |
369 JSObject::MigrateToMap(object, new_map); | 347 JSObject::MigrateToMap(object, new_map); |
370 } | 348 } |
371 | 349 |
372 | 350 |
373 void Bootstrapper::DetachGlobal(Handle<Context> env) { | 351 void Bootstrapper::DetachGlobal(Handle<Context> env) { |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index); | 1545 isolate->bootstrapper()->SourceLookup<ExperimentalExtraNatives>(index); |
1568 Handle<Object> global = isolate->global_object(); | 1546 Handle<Object> global = isolate->global_object(); |
1569 Handle<Object> binding = isolate->extras_binding_object(); | 1547 Handle<Object> binding = isolate->extras_binding_object(); |
1570 Handle<Object> extras_utils = isolate->extras_utils_object(); | 1548 Handle<Object> extras_utils = isolate->extras_utils_object(); |
1571 Handle<Object> args[] = {global, binding, extras_utils}; | 1549 Handle<Object> args[] = {global, binding, extras_utils}; |
1572 return Bootstrapper::CompileNative(isolate, name, source_code, | 1550 return Bootstrapper::CompileNative(isolate, name, source_code, |
1573 arraysize(args), args); | 1551 arraysize(args), args); |
1574 } | 1552 } |
1575 | 1553 |
1576 | 1554 |
1577 bool Bootstrapper::CompileCodeStubBuiltin(Isolate* isolate, int index) { | |
1578 HandleScope scope(isolate); | |
1579 Vector<const char> name = CodeStubNatives::GetScriptName(index); | |
1580 Handle<String> source_code = | |
1581 isolate->bootstrapper()->SourceLookup<CodeStubNatives>(index); | |
1582 Handle<JSObject> global(isolate->global_object()); | |
1583 Handle<JSObject> exports(isolate->heap()->code_stub_exports_object()); | |
1584 Handle<Object> args[] = {global, exports}; | |
1585 bool result = | |
1586 CompileNative(isolate, name, source_code, arraysize(args), args); | |
1587 return result; | |
1588 } | |
1589 | |
1590 | |
1591 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, | 1555 bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name, |
1592 Handle<String> source, int argc, | 1556 Handle<String> source, int argc, |
1593 Handle<Object> argv[]) { | 1557 Handle<Object> argv[]) { |
1594 SuppressDebug compiling_natives(isolate->debug()); | 1558 SuppressDebug compiling_natives(isolate->debug()); |
1595 // During genesis, the boilerplate for stack overflow won't work until the | 1559 // During genesis, the boilerplate for stack overflow won't work until the |
1596 // environment has been at least partially initialized. Add a stack check | 1560 // environment has been at least partially initialized. Add a stack check |
1597 // before entering JS code to catch overflow early. | 1561 // before entering JS code to catch overflow early. |
1598 StackLimitCheck check(isolate); | 1562 StackLimitCheck check(isolate); |
1599 if (check.JsHasOverflowed(1 * KB)) { | 1563 if (check.JsHasOverflowed(1 * KB)) { |
1600 isolate->StackOverflow(); | 1564 isolate->StackOverflow(); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 | 2557 |
2594 | 2558 |
2595 bool Genesis::InstallDebuggerNatives() { | 2559 bool Genesis::InstallDebuggerNatives() { |
2596 for (int i = 0; i < Natives::GetDebuggerCount(); ++i) { | 2560 for (int i = 0; i < Natives::GetDebuggerCount(); ++i) { |
2597 if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false; | 2561 if (!Bootstrapper::CompileBuiltin(isolate(), i)) return false; |
2598 } | 2562 } |
2599 return CallUtilsFunction(isolate(), "PostDebug"); | 2563 return CallUtilsFunction(isolate(), "PostDebug"); |
2600 } | 2564 } |
2601 | 2565 |
2602 | 2566 |
2603 bool Bootstrapper::InstallCodeStubNatives(Isolate* isolate) { | |
2604 for (int i = CodeStubNatives::GetDebuggerCount(); | |
2605 i < CodeStubNatives::GetBuiltinsCount(); i++) { | |
2606 if (!CompileCodeStubBuiltin(isolate, i)) return false; | |
2607 } | |
2608 | |
2609 return true; | |
2610 } | |
2611 | |
2612 | |
2613 static void InstallBuiltinFunctionId(Handle<JSObject> holder, | 2567 static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
2614 const char* function_name, | 2568 const char* function_name, |
2615 BuiltinFunctionId id) { | 2569 BuiltinFunctionId id) { |
2616 Isolate* isolate = holder->GetIsolate(); | 2570 Isolate* isolate = holder->GetIsolate(); |
2617 Handle<Object> function_object = | 2571 Handle<Object> function_object = |
2618 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); | 2572 Object::GetProperty(isolate, holder, function_name).ToHandleChecked(); |
2619 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); | 2573 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); |
2620 function->shared()->set_function_data(Smi::FromInt(id)); | 2574 function->shared()->set_function_data(Smi::FromInt(id)); |
2621 } | 2575 } |
2622 | 2576 |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3220 } | 3174 } |
3221 | 3175 |
3222 | 3176 |
3223 // Called when the top-level V8 mutex is destroyed. | 3177 // Called when the top-level V8 mutex is destroyed. |
3224 void Bootstrapper::FreeThreadResources() { | 3178 void Bootstrapper::FreeThreadResources() { |
3225 DCHECK(!IsActive()); | 3179 DCHECK(!IsActive()); |
3226 } | 3180 } |
3227 | 3181 |
3228 } // namespace internal | 3182 } // namespace internal |
3229 } // namespace v8 | 3183 } // namespace v8 |
OLD | NEW |