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

Unified Diff: src/bootstrapper.cc

Issue 1173333004: Add script context with context-allocated "const this" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Fix gcmole error in bootstrapper.cc Created 5 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index c675fe7e0d423211669c505a2f1a7a4169a9aa31..c9ba69c53a646cafe5d8bd257acdfe8070e0c083 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -197,6 +197,11 @@ class Genesis BASE_EMBEDDED {
// other objects in the snapshot.
void HookUpGlobalObject(Handle<GlobalObject> global_object,
Handle<FixedArray> outdated_contexts);
+ // The native context has a ScriptContextTable that store declarative bindings
+ // made in script scopes. Add a "this" binding to that table pointing to the
+ // global proxy.
+ void InstallGlobalThisBinding();
+ void HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts);
// New context initialization. Used for creating a context from scratch.
void InitializeGlobal(Handle<GlobalObject> global_object,
Handle<JSFunction> empty_function);
@@ -814,6 +819,41 @@ void Genesis::CreateRoots() {
}
+void Genesis::InstallGlobalThisBinding() {
+ Handle<ScriptContextTable> script_contexts(
+ native_context()->script_context_table());
+ Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate());
+ Handle<JSFunction> closure(native_context()->closure());
+ Handle<Context> context = factory()->NewScriptContext(closure, scope_info);
+
+ // Go ahead and hook it up while we're at it.
+ int slot = scope_info->ReceiverContextSlotIndex();
+ DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS);
+ context->set(slot, native_context()->global_proxy());
+
+ Handle<ScriptContextTable> new_script_contexts =
+ ScriptContextTable::Extend(script_contexts, context);
+ native_context()->set_script_context_table(*new_script_contexts);
+}
+
+
+void Genesis::HookUpGlobalThisBinding(Handle<FixedArray> outdated_contexts) {
+ // One of these contexts should be the one that declares the global "this"
+ // binding.
+ for (int i = 0; i < outdated_contexts->length(); ++i) {
+ Context* context = Context::cast(outdated_contexts->get(i));
+ if (context->IsScriptContext()) {
+ ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
+ int slot = scope_info->ReceiverContextSlotIndex();
+ if (slot >= 0) {
+ DCHECK_EQ(slot, Context::MIN_CONTEXT_SLOTS);
+ context->set(slot, native_context()->global_proxy());
+ }
+ }
+ }
+}
+
+
Handle<GlobalObject> Genesis::CreateNewGlobals(
v8::Handle<v8::ObjectTemplate> global_proxy_template,
Handle<JSGlobalProxy> global_proxy) {
@@ -972,6 +1012,7 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
Handle<ScriptContextTable> script_context_table =
factory->NewScriptContextTable();
native_context()->set_script_context_table(*script_context_table);
+ InstallGlobalThisBinding();
Handle<String> object_name = factory->Object_string();
JSObject::AddProperty(
@@ -3086,6 +3127,7 @@ Genesis::Genesis(Isolate* isolate,
HookUpGlobalObject(global_object, outdated_contexts);
native_context()->builtins()->set_global_proxy(
native_context()->global_proxy());
+ HookUpGlobalThisBinding(outdated_contexts);
if (!ConfigureGlobalObjects(global_proxy_template)) return;
} else {
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698