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

Unified Diff: src/scopeinfo.cc

Issue 1178903003: Add script context with context-allocated "const this" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Add test 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/runtime/runtime-compiler.cc ('k') | src/scopes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopeinfo.cc
diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc
index b819b172c4ad1db78926b0d59dc253d9841de94f..72c36c2665942f0ad9a66a691d342baf791b6008 100644
--- a/src/scopeinfo.cc
+++ b/src/scopeinfo.cc
@@ -6,6 +6,7 @@
#include "src/v8.h"
+#include "src/bootstrapper.h"
#include "src/scopeinfo.h"
#include "src/scopes.h"
@@ -192,6 +193,77 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
}
+Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) {
+ DCHECK(isolate->bootstrapper()->IsActive());
+
+ const int stack_local_count = 0;
+ const int context_local_count = 1;
+ const int strong_mode_free_variable_count = 0;
+ const bool simple_parameter_list = true;
+ const VariableAllocationInfo receiver_info = CONTEXT;
+ const VariableAllocationInfo function_name_info = NONE;
+ const VariableMode function_variable_mode = VAR;
+ const bool has_function_name = false;
+ const bool has_receiver = true;
+ const int parameter_count = 0;
+ const int length = kVariablePartIndex + parameter_count +
+ (1 + stack_local_count) + 2 * context_local_count +
+ 3 * strong_mode_free_variable_count +
+ (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0);
+
+ Factory* factory = isolate->factory();
+ Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
+
+ // Encode the flags.
+ int flags = ScopeTypeField::encode(SCRIPT_SCOPE) |
+ CallsEvalField::encode(false) |
+ LanguageModeField::encode(SLOPPY) |
+ ReceiverVariableField::encode(receiver_info) |
+ FunctionVariableField::encode(function_name_info) |
+ FunctionVariableMode::encode(function_variable_mode) |
+ AsmModuleField::encode(false) | AsmFunctionField::encode(false) |
+ IsSimpleParameterListField::encode(simple_parameter_list) |
+ BlockScopeIsClassScopeField::encode(false) |
+ FunctionKindField::encode(FunctionKind::kNormalFunction);
+ scope_info->SetFlags(flags);
+ scope_info->SetParameterCount(parameter_count);
+ scope_info->SetStackLocalCount(stack_local_count);
+ scope_info->SetContextLocalCount(context_local_count);
+ scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count);
+
+ int index = kVariablePartIndex;
+ const int first_slot_index = 0;
+ DCHECK(index == scope_info->StackLocalFirstSlotIndex());
+ scope_info->set(index++, Smi::FromInt(first_slot_index));
+ DCHECK(index == scope_info->StackLocalEntriesIndex());
+
+ // Here we add info for context-allocated "this".
+ DCHECK(index == scope_info->ContextLocalNameEntriesIndex());
+ scope_info->set(index++, *isolate->factory()->this_string());
+ DCHECK(index == scope_info->ContextLocalInfoEntriesIndex());
+ const uint32_t value = ContextLocalMode::encode(CONST) |
+ ContextLocalInitFlag::encode(kCreatedInitialized) |
+ ContextLocalMaybeAssignedFlag::encode(kNotAssigned);
+ scope_info->set(index++, Smi::FromInt(value));
+
+ DCHECK(index == scope_info->StrongModeFreeVariableNameEntriesIndex());
+ DCHECK(index == scope_info->StrongModeFreeVariablePositionEntriesIndex());
+
+ // And here we record that this scopeinfo binds a receiver.
+ DCHECK(index == scope_info->ReceiverEntryIndex());
+ const int receiver_index = Context::MIN_CONTEXT_SLOTS + 0;
+ scope_info->set(index++, Smi::FromInt(receiver_index));
+
+ DCHECK(index == scope_info->FunctionNameEntryIndex());
+
+ DCHECK_EQ(index, scope_info->length());
+ DCHECK_EQ(scope_info->ParameterCount(), 0);
+ DCHECK_EQ(scope_info->ContextLength(), Context::MIN_CONTEXT_SLOTS + 1);
+
+ return scope_info;
+}
+
+
ScopeInfo* ScopeInfo::Empty(Isolate* isolate) {
return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array());
}
« no previous file with comments | « src/runtime/runtime-compiler.cc ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698