Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/bootstrapper.cc

Issue 1478303002: Revert of [runtime] Replace global object link with native context link in all contexts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/arm64/macro-assembler-arm64.cc ('k') | src/code-stubs-hydrogen.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 } 1045 }
1046 1046
1047 1047
1048 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object, 1048 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object,
1049 Handle<FixedArray> outdated_contexts) { 1049 Handle<FixedArray> outdated_contexts) {
1050 Handle<JSGlobalObject> global_object_from_snapshot( 1050 Handle<JSGlobalObject> global_object_from_snapshot(
1051 JSGlobalObject::cast(native_context()->extension())); 1051 JSGlobalObject::cast(native_context()->extension()));
1052 native_context()->set_extension(*global_object); 1052 native_context()->set_extension(*global_object);
1053 native_context()->set_security_token(*global_object); 1053 native_context()->set_security_token(*global_object);
1054 1054
1055 // Replace outdated global objects in deserialized contexts.
1056 for (int i = 0; i < outdated_contexts->length(); ++i) {
1057 Context* context = Context::cast(outdated_contexts->get(i));
1058 // Assert that there is only one native context.
1059 DCHECK(!context->IsNativeContext() || context == *native_context());
1060 DCHECK_EQ(context->global_object(), *global_object_from_snapshot);
1061 context->set_global_object(*global_object);
1062 }
1063
1055 TransferNamedProperties(global_object_from_snapshot, global_object); 1064 TransferNamedProperties(global_object_from_snapshot, global_object);
1056 TransferIndexedProperties(global_object_from_snapshot, global_object); 1065 TransferIndexedProperties(global_object_from_snapshot, global_object);
1057 } 1066 }
1058 1067
1059 1068
1060 // This is only called if we are not using snapshots. The equivalent 1069 // This is only called if we are not using snapshots. The equivalent
1061 // work in the snapshot case is done in HookUpGlobalObject. 1070 // work in the snapshot case is done in HookUpGlobalObject.
1062 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, 1071 void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
1063 Handle<JSFunction> empty_function, 1072 Handle<JSFunction> empty_function,
1064 ContextType context_type) { 1073 ContextType context_type) {
1065 // --- N a t i v e C o n t e x t --- 1074 // --- N a t i v e C o n t e x t ---
1066 // Use the empty function as closure (no scope info). 1075 // Use the empty function as closure (no scope info).
1067 native_context()->set_closure(*empty_function); 1076 native_context()->set_closure(*empty_function);
1068 native_context()->set_previous(NULL); 1077 native_context()->set_previous(NULL);
1069 // Set extension and global object. 1078 // Set extension and global object.
1070 native_context()->set_extension(*global_object); 1079 native_context()->set_extension(*global_object);
1080 native_context()->set_global_object(*global_object);
1071 // Security setup: Set the security token of the native context to the global 1081 // Security setup: Set the security token of the native context to the global
1072 // object. This makes the security check between two different contexts fail 1082 // object. This makes the security check between two different contexts fail
1073 // by default even in case of global object reinitialization. 1083 // by default even in case of global object reinitialization.
1074 native_context()->set_security_token(*global_object); 1084 native_context()->set_security_token(*global_object);
1075 1085
1076 Isolate* isolate = global_object->GetIsolate(); 1086 Isolate* isolate = global_object->GetIsolate();
1077 Factory* factory = isolate->factory(); 1087 Factory* factory = isolate->factory();
1078 1088
1079 Handle<ScriptContextTable> script_context_table = 1089 Handle<ScriptContextTable> script_context_table =
1080 factory->NewScriptContextTable(); 1090 factory->NewScriptContextTable();
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 Handle<String> script_name = 1616 Handle<String> script_name =
1607 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked(); 1617 isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
1608 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript( 1618 Handle<SharedFunctionInfo> function_info = Compiler::CompileScript(
1609 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(), 1619 source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
1610 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE, 1620 context, NULL, NULL, ScriptCompiler::kNoCompileOptions, NATIVES_CODE,
1611 false); 1621 false);
1612 if (function_info.is_null()) return false; 1622 if (function_info.is_null()) return false;
1613 1623
1614 DCHECK(context->IsNativeContext()); 1624 DCHECK(context->IsNativeContext());
1615 1625
1626 Handle<Context> runtime_context(context->runtime_context());
1616 Handle<JSFunction> fun = 1627 Handle<JSFunction> fun =
1617 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info, 1628 isolate->factory()->NewFunctionFromSharedFunctionInfo(function_info,
1618 context); 1629 runtime_context);
1619 Handle<Object> receiver = isolate->factory()->undefined_value(); 1630 Handle<Object> receiver = isolate->factory()->undefined_value();
1620 1631
1621 // For non-extension scripts, run script to get the function wrapper. 1632 // For non-extension scripts, run script to get the function wrapper.
1622 Handle<Object> wrapper; 1633 Handle<Object> wrapper;
1623 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) { 1634 if (!Execution::Call(isolate, fun, receiver, 0, NULL).ToHandle(&wrapper)) {
1624 return false; 1635 return false;
1625 } 1636 }
1626 // Then run the function wrapper. 1637 // Then run the function wrapper.
1627 return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver, 1638 return !Execution::Call(isolate, Handle<JSFunction>::cast(wrapper), receiver,
1628 argc, argv).is_null(); 1639 argc, argv).is_null();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 Handle<JSObject> global = isolate()->global_object(); 1746 Handle<JSObject> global = isolate()->global_object();
1736 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM); 1747 JSObject::AddProperty(global, natives_key, utils, DONT_ENUM);
1737 break; 1748 break;
1738 } 1749 }
1739 case THIN_CONTEXT: 1750 case THIN_CONTEXT:
1740 break; 1751 break;
1741 } 1752 }
1742 1753
1743 // The utils object can be removed for cases that reach this point. 1754 // The utils object can be removed for cases that reach this point.
1744 native_context()->set_natives_utils_object(heap()->undefined_value()); 1755 native_context()->set_natives_utils_object(heap()->undefined_value());
1756
1757 #ifdef DEBUG
1758 JSGlobalObject* dummy = native_context()->runtime_context()->global_object();
1759 DCHECK_EQ(0, dummy->elements()->length());
1760 DCHECK_EQ(0, GlobalDictionary::cast(dummy->properties())->NumberOfElements());
1761 #endif
1745 } 1762 }
1746 1763
1747 1764
1748 void Bootstrapper::ExportFromRuntime(Isolate* isolate, 1765 void Bootstrapper::ExportFromRuntime(Isolate* isolate,
1749 Handle<JSObject> container) { 1766 Handle<JSObject> container) {
1750 Factory* factory = isolate->factory(); 1767 Factory* factory = isolate->factory();
1751 HandleScope scope(isolate); 1768 HandleScope scope(isolate);
1752 Handle<Context> native_context = isolate->native_context(); 1769 Handle<Context> native_context = isolate->native_context();
1753 #define EXPORT_PRIVATE_SYMBOL(NAME) \ 1770 #define EXPORT_PRIVATE_SYMBOL(NAME) \
1754 Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \ 1771 Handle<String> NAME##_name = factory->NewStringFromAsciiChecked(#NAME); \
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 initial_map->AppendDescriptor(&d); 2236 initial_map->AppendDescriptor(&d);
2220 } 2237 }
2221 2238
2222 return array_function; 2239 return array_function;
2223 } 2240 }
2224 2241
2225 2242
2226 bool Genesis::InstallNatives(ContextType context_type) { 2243 bool Genesis::InstallNatives(ContextType context_type) {
2227 HandleScope scope(isolate()); 2244 HandleScope scope(isolate());
2228 2245
2246 // Create a bridge function that has context in the native context.
2247 Handle<JSFunction> bridge = factory()->NewFunction(factory()->empty_string());
2248 DCHECK(bridge->context() == *isolate()->native_context());
2249
2250 // Allocate the runtime context.
2251 {
2252 Handle<Context> context =
2253 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
2254 native_context()->set_runtime_context(*context);
2255 Handle<Code> code = isolate()->builtins()->Illegal();
2256 Handle<JSFunction> global_fun =
2257 factory()->NewFunction(factory()->empty_string(), code,
2258 JS_GLOBAL_OBJECT_TYPE, JSGlobalObject::kSize);
2259 global_fun->initial_map()->set_dictionary_map(true);
2260 global_fun->initial_map()->set_prototype(heap()->null_value());
2261 Handle<JSGlobalObject> dummy_global =
2262 Handle<JSGlobalObject>::cast(factory()->NewJSGlobalObject(global_fun));
2263 dummy_global->set_native_context(*native_context());
2264 dummy_global->set_global_proxy(native_context()->global_proxy());
2265 context->set_global_object(*dummy_global);
2266 // Something went wrong if we actually need to write into the dummy global.
2267 dummy_global->set_properties(*GlobalDictionary::New(isolate(), 0));
2268 dummy_global->set_elements(heap()->empty_fixed_array());
2269 }
2270
2229 // Set up the utils object as shared container between native scripts. 2271 // Set up the utils object as shared container between native scripts.
2230 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function()); 2272 Handle<JSObject> utils = factory()->NewJSObject(isolate()->object_function());
2231 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16, 2273 JSObject::NormalizeProperties(utils, CLEAR_INOBJECT_PROPERTIES, 16,
2232 "utils container for native scripts"); 2274 "utils container for native scripts");
2233 native_context()->set_natives_utils_object(*utils); 2275 native_context()->set_natives_utils_object(*utils);
2234 2276
2235 // Set up the extras utils object as a shared container between native 2277 // Set up the extras utils object as a shared container between native
2236 // scripts and extras. (Extras consume things added there by native scripts.) 2278 // scripts and extras. (Extras consume things added there by native scripts.)
2237 Handle<JSObject> extras_utils = 2279 Handle<JSObject> extras_utils =
2238 factory()->NewJSObject(isolate()->object_function()); 2280 factory()->NewJSObject(isolate()->object_function());
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 3184 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
3143 CreateStrictModeFunctionMaps(empty_function); 3185 CreateStrictModeFunctionMaps(empty_function);
3144 CreateStrongModeFunctionMaps(empty_function); 3186 CreateStrongModeFunctionMaps(empty_function);
3145 CreateIteratorMaps(); 3187 CreateIteratorMaps();
3146 Handle<JSGlobalObject> global_object = 3188 Handle<JSGlobalObject> global_object =
3147 CreateNewGlobals(global_proxy_template, global_proxy); 3189 CreateNewGlobals(global_proxy_template, global_proxy);
3148 HookUpGlobalProxy(global_object, global_proxy); 3190 HookUpGlobalProxy(global_object, global_proxy);
3149 InitializeGlobal(global_object, empty_function, context_type); 3191 InitializeGlobal(global_object, empty_function, context_type);
3150 InitializeNormalizedMapCaches(); 3192 InitializeNormalizedMapCaches();
3151 3193
3152 // TODO(yangguo): Find a way to prevent accidentially installing properties
3153 // on the global object.
3154 if (!InstallNatives(context_type)) return; 3194 if (!InstallNatives(context_type)) return;
3155 3195
3156 MakeFunctionInstancePrototypeWritable(); 3196 MakeFunctionInstancePrototypeWritable();
3157 3197
3158 if (context_type != THIN_CONTEXT) { 3198 if (context_type != THIN_CONTEXT) {
3159 if (!InstallExtraNatives()) return; 3199 if (!InstallExtraNatives()) return;
3160 if (!ConfigureGlobalObjects(global_proxy_template)) return; 3200 if (!ConfigureGlobalObjects(global_proxy_template)) return;
3161 } 3201 }
3162 isolate->counters()->contexts_created_from_scratch()->Increment(); 3202 isolate->counters()->contexts_created_from_scratch()->Increment();
3163 // Re-initialize the counter because it got incremented during snapshot 3203 // Re-initialize the counter because it got incremented during snapshot
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3220 } 3260 }
3221 3261
3222 3262
3223 // Called when the top-level V8 mutex is destroyed. 3263 // Called when the top-level V8 mutex is destroyed.
3224 void Bootstrapper::FreeThreadResources() { 3264 void Bootstrapper::FreeThreadResources() {
3225 DCHECK(!IsActive()); 3265 DCHECK(!IsActive());
3226 } 3266 }
3227 3267
3228 } // namespace internal 3268 } // namespace internal
3229 } // namespace v8 3269 } // namespace v8
OLDNEW
« no previous file with comments | « src/arm64/macro-assembler-arm64.cc ('k') | src/code-stubs-hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698