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

Unified Diff: src/scopeinfo.cc

Issue 8404030: Version 3.7.1 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 2 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/scopeinfo.h ('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
===================================================================
--- src/scopeinfo.cc (revision 9808)
+++ src/scopeinfo.cc (working copy)
@@ -51,6 +51,7 @@
: function_name_(FACTORY->empty_symbol()),
calls_eval_(scope->calls_eval()),
is_strict_mode_(scope->is_strict_mode()),
+ type_(scope->type()),
parameters_(scope->num_parameters()),
stack_slots_(scope->num_stack_slots()),
context_slots_(scope->num_heap_slots()),
@@ -138,7 +139,7 @@
ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS ==
context_modes_.length());
context_slots_.Add(FACTORY->empty_symbol());
- context_modes_.Add(INTERNAL);
+ context_modes_.Add(proxy->var()->mode());
}
}
}
@@ -150,6 +151,10 @@
//
// - calls eval boolean flag
//
+// - is strict mode scope
+//
+// - scope type
+//
// - number of variables in the context object (smi) (= function context
// slot index + 1)
// - list of pairs (name, Var mode) of context-allocated variables (starting
@@ -181,8 +186,9 @@
// present)
-static inline Object** ReadInt(Object** p, int* x) {
- *x = (reinterpret_cast<Smi*>(*p++))->value();
+template <class T>
+static inline Object** ReadInt(Object** p, T* x) {
+ *x = static_cast<T>((reinterpret_cast<Smi*>(*p++))->value());
return p;
}
@@ -193,20 +199,21 @@
}
-static inline Object** ReadSymbol(Object** p, Handle<String>* s) {
- *s = Handle<String>(reinterpret_cast<String*>(*p++));
+template <class T>
+static inline Object** ReadObject(Object** p, Handle<T>* s) {
+ *s = Handle<T>::cast(Handle<Object>(*p++));
return p;
}
-template <class Allocator>
-static Object** ReadList(Object** p, List<Handle<String>, Allocator >* list) {
+template <class Allocator, class T>
+static Object** ReadList(Object** p, List<Handle<T>, Allocator >* list) {
ASSERT(list->is_empty());
int n;
p = ReadInt(p, &n);
while (n-- > 0) {
- Handle<String> s;
- p = ReadSymbol(p, &s);
+ Handle<T> s;
+ p = ReadObject(p, &s);
list->Add(s);
}
return p;
@@ -223,7 +230,7 @@
while (n-- > 0) {
Handle<String> s;
int m;
- p = ReadSymbol(p, &s);
+ p = ReadObject(p, &s);
p = ReadInt(p, &m);
list->Add(s);
modes->Add(static_cast<VariableMode>(m));
@@ -242,9 +249,10 @@
if (data->length() > 0) {
Object** p0 = data->data_start();
Object** p = p0;
- p = ReadSymbol(p, &function_name_);
+ p = ReadObject(p, &function_name_);
p = ReadBool(p, &calls_eval_);
p = ReadBool(p, &is_strict_mode_);
+ p = ReadInt(p, &type_);
p = ReadList<Allocator>(p, &context_slots_, &context_modes_);
p = ReadList<Allocator>(p, &parameters_);
p = ReadList<Allocator>(p, &stack_slots_);
@@ -265,18 +273,19 @@
}
-static inline Object** WriteSymbol(Object** p, Handle<String> s) {
+template <class T>
+static inline Object** WriteObject(Object** p, Handle<T> s) {
*p++ = *s;
return p;
}
-template <class Allocator>
-static Object** WriteList(Object** p, List<Handle<String>, Allocator >* list) {
+template <class Allocator, class T>
+static Object** WriteList(Object** p, List<Handle<T>, Allocator >* list) {
const int n = list->length();
p = WriteInt(p, n);
for (int i = 0; i < n; i++) {
- p = WriteSymbol(p, list->at(i));
+ p = WriteObject(p, list->at(i));
}
return p;
}
@@ -289,7 +298,7 @@
const int n = list->length();
p = WriteInt(p, n);
for (int i = 0; i < n; i++) {
- p = WriteSymbol(p, list->at(i));
+ p = WriteObject(p, list->at(i));
p = WriteInt(p, modes->at(i));
}
return p;
@@ -298,8 +307,9 @@
template<class Allocator>
Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() {
- // function name, calls eval, is_strict_mode, length for 3 tables:
- const int extra_slots = 1 + 1 + 1 + 3;
+ // function name, calls eval, is_strict_mode, scope type,
+ // length for 3 tables:
+ const int extra_slots = 1 + 1 + 1 + 1 + 3;
int length = extra_slots +
context_slots_.length() * 2 +
parameters_.length() +
@@ -311,9 +321,10 @@
Object** p0 = data->data_start();
Object** p = p0;
- p = WriteSymbol(p, function_name_);
+ p = WriteObject(p, function_name_);
p = WriteBool(p, calls_eval_);
p = WriteBool(p, is_strict_mode_);
+ p = WriteInt(p, type_);
p = WriteList(p, &context_slots_, &context_modes_);
p = WriteList(p, &parameters_);
p = WriteList(p, &stack_slots_);
@@ -361,8 +372,8 @@
Object** SerializedScopeInfo::ContextEntriesAddr() {
ASSERT(length() > 0);
- // +3 for function name, calls eval, strict mode.
- return data_start() + 3;
+ // +4 for function name, calls eval, strict mode, scope type.
+ return data_start() + 4;
}
@@ -406,6 +417,16 @@
}
+ScopeType SerializedScopeInfo::Type() {
+ ASSERT(length() > 0);
+ // +3 for function name, calls eval, strict mode.
+ Object** p = data_start() + 3;
+ ScopeType type;
+ p = ReadInt(p, &type);
+ return type;
+}
+
+
int SerializedScopeInfo::NumberOfStackSlots() {
if (length() > 0) {
Object** p = StackSlotEntriesAddr();
@@ -439,6 +460,12 @@
}
+bool SerializedScopeInfo::HasContext() {
+ return HasHeapAllocatedLocals() ||
+ Type() == WITH_SCOPE;
+}
+
+
int SerializedScopeInfo::StackSlotIndex(String* name) {
ASSERT(name->IsSymbol());
if (length() > 0) {
@@ -513,16 +540,24 @@
}
-int SerializedScopeInfo::FunctionContextSlotIndex(String* name) {
+int SerializedScopeInfo::FunctionContextSlotIndex(String* name,
+ VariableMode* mode) {
ASSERT(name->IsSymbol());
if (length() > 0) {
Object** p = data_start();
if (*p == name) {
p = ContextEntriesAddr();
int number_of_context_slots;
- ReadInt(p, &number_of_context_slots);
+ p = ReadInt(p, &number_of_context_slots);
ASSERT(number_of_context_slots != 0);
// The function context slot is the last entry.
+ if (mode != NULL) {
+ // Seek to context slot entry.
+ p += (number_of_context_slots - 1) * 2;
+ // Seek to mode.
+ ++p;
+ ReadInt(p, mode);
+ }
return number_of_context_slots + Context::MIN_CONTEXT_SLOTS - 1;
}
}
« no previous file with comments | « src/scopeinfo.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698