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

Unified Diff: src/scopeinfo.cc

Issue 1005063002: Strawman: check strong mode free variables against the global object. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: arrow func param fix Created 5 years, 9 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/pending-compilation-error-handler.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 d62bc4129588196d3f3faf6d7c1fd035b39bbaa6..99d4c38297890a22631e33a1aa1aa3cce1add481 100644
--- a/src/scopeinfo.cc
+++ b/src/scopeinfo.cc
@@ -18,9 +18,14 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
// Collect stack and context locals.
ZoneList<Variable*> stack_locals(scope->StackLocalCount(), zone);
ZoneList<Variable*> context_locals(scope->ContextLocalCount(), zone);
- scope->CollectStackAndContextLocals(&stack_locals, &context_locals);
+ ZoneList<Variable*> strong_mode_free_variables(0, zone);
+
+ scope->CollectStackAndContextLocals(&stack_locals, &context_locals,
+ &strong_mode_free_variables);
const int stack_local_count = stack_locals.length();
const int context_local_count = context_locals.length();
+ const int strong_mode_free_variable_count =
+ strong_mode_free_variables.length();
// Make sure we allocate the correct amount.
DCHECK(scope->StackLocalCount() == stack_local_count);
DCHECK(scope->ContextLocalCount() == context_local_count);
@@ -49,9 +54,10 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
const bool has_function_name = function_name_info != NONE;
const int parameter_count = scope->num_parameters();
- const int length = kVariablePartIndex
- + parameter_count + stack_local_count + 2 * context_local_count
- + (has_function_name ? 2 : 0);
+ const int length = kVariablePartIndex + parameter_count + stack_local_count +
+ 2 * context_local_count +
+ 3 * strong_mode_free_variable_count +
+ (has_function_name ? 2 : 0);
Factory* factory = isolate->factory();
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
@@ -71,6 +77,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
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;
// Add parameters.
@@ -113,6 +120,25 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
scope_info->set(index++, Smi::FromInt(value));
}
+ DCHECK(index == scope_info->StrongModeFreeVariableNameEntriesIndex());
+ for (int i = 0; i < strong_mode_free_variable_count; ++i) {
+ scope_info->set(index++, *strong_mode_free_variables[i]->name());
+ }
+
+ DCHECK(index == scope_info->StrongModeFreeVariablePositionEntriesIndex());
+ for (int i = 0; i < strong_mode_free_variable_count; ++i) {
+ // Unfortunately, the source code positions are stored as int even though
+ // int32_t would be enough (given the maximum source code length).
+ Handle<Object> start_position = factory->NewNumberFromInt(
+ static_cast<int32_t>(strong_mode_free_variables[i]
+ ->strong_mode_reference_start_position()));
+ scope_info->set(index++, *start_position);
+ Handle<Object> end_position = factory->NewNumberFromInt(
+ static_cast<int32_t>(strong_mode_free_variables[i]
+ ->strong_mode_reference_end_position()));
+ scope_info->set(index++, *end_position);
+ }
+
// If present, add the function variable name and its index.
DCHECK(index == scope_info->FunctionNameEntryIndex());
if (has_function_name) {
@@ -285,6 +311,35 @@ bool ScopeInfo::LocalIsSynthetic(int var) {
}
+String* ScopeInfo::StrongModeFreeVariableName(int var) {
+ DCHECK(0 <= var && var < StrongModeFreeVariableCount());
+ int info_index = StrongModeFreeVariableNameEntriesIndex() + var;
+ return String::cast(get(info_index));
+}
+
+
+int ScopeInfo::StrongModeFreeVariableStartPosition(int var) {
+ DCHECK(0 <= var && var < StrongModeFreeVariableCount());
+ int info_index = StrongModeFreeVariablePositionEntriesIndex() + var * 2;
+ int32_t value = 0;
+ bool ok = get(info_index)->ToInt32(&value);
+ USE(ok);
+ DCHECK(ok);
+ return value;
+}
+
+
+int ScopeInfo::StrongModeFreeVariableEndPosition(int var) {
+ DCHECK(0 <= var && var < StrongModeFreeVariableCount());
+ int info_index = StrongModeFreeVariablePositionEntriesIndex() + var * 2 + 1;
+ int32_t value = 0;
+ bool ok = get(info_index)->ToInt32(&value);
+ USE(ok);
+ DCHECK(ok);
+ return value;
+}
+
+
int ScopeInfo::StackSlotIndex(String* name) {
DCHECK(name->IsInternalizedString());
if (length() > 0) {
@@ -432,11 +487,23 @@ int ScopeInfo::ContextLocalInfoEntriesIndex() {
}
-int ScopeInfo::FunctionNameEntryIndex() {
+int ScopeInfo::StrongModeFreeVariableNameEntriesIndex() {
return ContextLocalInfoEntriesIndex() + ContextLocalCount();
}
+int ScopeInfo::StrongModeFreeVariablePositionEntriesIndex() {
+ return StrongModeFreeVariableNameEntriesIndex() +
+ StrongModeFreeVariableCount();
+}
+
+
+int ScopeInfo::FunctionNameEntryIndex() {
+ return StrongModeFreeVariablePositionEntriesIndex() +
+ 2 * StrongModeFreeVariableCount();
+}
+
+
int ContextSlotCache::Hash(Object* data, String* name) {
// Uses only lower 32 bits if pointers are larger.
uintptr_t addr_hash =
« no previous file with comments | « src/pending-compilation-error-handler.cc ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698