Index: src/objects.h |
diff --git a/src/objects.h b/src/objects.h |
index 3187467b380a9cde1d4355ea007238fb1075e317..2a25d2de486348d81c404a74fd0c80326365963e 100644 |
--- a/src/objects.h |
+++ b/src/objects.h |
@@ -78,7 +78,7 @@ |
// - MapCache |
// - Context |
// - JSFunctionResultCache |
-// - SerializedScopeInfo |
+// - ScopeInfo |
// - FixedDoubleArray |
// - ExternalArray |
// - ExternalPixelArray |
@@ -814,7 +814,7 @@ class MaybeObject BASE_EMBEDDED { |
V(FixedDoubleArray) \ |
V(Context) \ |
V(GlobalContext) \ |
- V(SerializedScopeInfo) \ |
+ V(ScopeInfo) \ |
V(JSFunction) \ |
V(Code) \ |
V(Oddball) \ |
@@ -3098,14 +3098,16 @@ class JSFunctionResultCache: public FixedArray { |
}; |
+// ScopeInfo represents information about different scopes of a source |
+// program and the allocation of the scope's variables. Scope information |
+// is stored in a compressed form in ScopeInfo objects and is used |
+// at runtime (stack dumps, deoptimization, etc.). |
+ |
// This object provides quick access to scope info details for runtime |
-// routines w/o the need to explicitly create a ScopeInfo object. |
-class SerializedScopeInfo : public FixedArray { |
+// routines. |
+class ScopeInfo : public FixedArray { |
public : |
- static SerializedScopeInfo* cast(Object* object) { |
- ASSERT(object->IsSerializedScopeInfo()); |
- return reinterpret_cast<SerializedScopeInfo*>(object); |
- } |
+ static inline ScopeInfo* cast(Object* object); |
// Return the type of this scope. |
ScopeType Type(); |
@@ -3116,18 +3118,57 @@ class SerializedScopeInfo : public FixedArray { |
// Is this scope a strict mode scope? |
bool IsStrictMode(); |
- // Return the number of stack slots for code. |
+ // Does this scope make a non-strict eval call? |
+ bool CallsNonStrictEval() { |
+ return CallsEval() && !IsStrictMode(); |
+ } |
+ |
+ // Return the total number of locals allocated on the stack and in the |
+ // context. This includes the parameters that are allocated in the context. |
+ int NumberOfLocals(); |
+ |
+ // Return the number of stack slots for code. This number consists of two |
+ // parts: |
+ // 1. One stack slot per stack allocated local. |
+ // 2. One stack slot for the function name if it is stack allocated. |
int NumberOfStackSlots(); |
- // Return the number of context slots for code. |
- int NumberOfContextSlots(); |
+ // Return the number of context slots for code if a context is allocated. This |
+ // number consists of three parts: |
+ // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
+ // 2. One context slot per context allocated local. |
+ // 3. One context slot for the function name if it is context allocated. |
+ // Parameters allocated in the context count as context allocated locals. If |
+ // no contexts are allocated for this scope ContextLength returns 0. |
+ int ContextLength(); |
+ |
+ // Is this scope the scope of a named function expression? |
+ bool HasFunctionName(); |
- // Return if this has context slots besides MIN_CONTEXT_SLOTS; |
+ // Return if this has context allocated locals. |
bool HasHeapAllocatedLocals(); |
// Return if contexts are allocated for this scope. |
bool HasContext(); |
+ // Return the function_name if present. |
+ String* FunctionName(); |
+ |
+ // Return the name of the given parameter. |
+ String* ParameterName(int var); |
+ |
+ // Return the name of the given local. |
+ String* LocalName(int var); |
+ |
+ // Return the name of the given stack local. |
+ String* StackLocalName(int var); |
+ |
+ // Return the name of the given context local. |
+ String* ContextLocalName(int var); |
+ |
+ // Return the mode of the given context local. |
+ VariableMode ContextLocalMode(int var); |
+ |
// Lookup support for serialized scope info. Returns the |
// the stack slot index for a given slot name if the slot is |
// present; otherwise returns a value < 0. The name must be a symbol |
@@ -3152,17 +3193,98 @@ class SerializedScopeInfo : public FixedArray { |
// must be a symbol (canonicalized). |
int FunctionContextSlotIndex(String* name, VariableMode* mode); |
- static Handle<SerializedScopeInfo> Create(Scope* scope); |
+ static Handle<ScopeInfo> Create(Scope* scope); |
// Serializes empty scope info. |
- static SerializedScopeInfo* Empty(); |
+ static ScopeInfo* Empty(); |
+ |
+#ifdef DEBUG |
+ void Print(); |
+#endif |
+ |
+ // The layout of the static part of a ScopeInfo is as follows. Each entry is |
+ // numeric and occupies one array slot. |
+ // 1. A set of properties of the scope |
+ // 2. The number of parameters. This only applies to function scopes. For |
+ // non-function scopes this is 0. |
+ // 3. The number of non-parameter variables allocated on the stack. |
+ // 4. The number of non-parameter and parameter variables allocated in the |
+ // context. |
+#define FOR_EACH_NUMERIC_FIELD(V) \ |
+ V(Flags) \ |
+ V(NumParameters) \ |
+ V(NumStackLocals) \ |
+ V(NumContextLocals) |
+ |
+#define FIELD_ACCESSORS(name) \ |
+ void Set##name(int value) { \ |
+ set(k##name, Smi::FromInt(value)); \ |
+ } \ |
+ int name() { \ |
+ if (length() > 0) { \ |
+ return Smi::cast(get(k##name))->value(); \ |
+ } else { \ |
+ return 0; \ |
+ } \ |
+ } |
+ FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS) |
+#undef FIELD_ACCESSORS |
private: |
- Object** ContextEntriesAddr(); |
+ enum { |
+#define DECL_INDEX(name) k##name, |
+ FOR_EACH_NUMERIC_FIELD(DECL_INDEX) |
+#undef DECL_INDEX |
+#undef FOR_EACH_NUMERIC_FIELD |
+ kVariablePartIndex |
+ }; |
- Object** ParameterEntriesAddr(); |
+ // The layout of the variable part of a ScopeInfo is as follows: |
+ // 1. ParameterEntries: |
+ // This part stores the names of the parameters for function scopes. One |
+ // slot is used per parameter, so in total this part occupies |
+ // NumParameters() slots in the array. For other scopes than function |
+ // scopes NumParameters() is 0. |
+ // 2. StackLocalEntries: |
+ // Contains the names of local variables that are allocated on the stack, |
+ // in increasing order of the stack slot index. One slot is used per |
+ // stack local, so in total this part occupies NumStackLocals() slots |
+ // in the array. |
+ // 3. ContextLocalNameEntries: |
+ // Contains the names of local variables and parameters that are allocated |
+ // in the context. They are stored in increasing order of the context slot |
+ // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
+ // context local, so in total this part occupies NumContextLocals() |
+ // slots in the array. |
+ // 4. ContextLocalModeEntries: |
+ // Contains the variable modes corresponding to the context locals in |
+ // ContextLocalNameEntries. One slot is used per context local, so in total |
+ // this part occupies NumContextLocals() slots in the array. |
+ // 5. FunctionNameEntryIndex: |
+ // If the scope belongs to a named function expression this part contains |
+ // information about the function variable. It always occupies two array |
+ // slots: a. The name of the function variable. |
+ // b. The context or stack slot index for the variable. |
+ int ParameterEntriesIndex(); |
+ int StackLocalEntriesIndex(); |
+ int ContextLocalNameEntriesIndex(); |
+ int ContextLocalModeEntriesIndex(); |
+ int FunctionNameEntryIndex(); |
+ |
+ // Location of the function variable for named function expressions. |
+ enum FunctionVariableInfo { |
+ NONE, // No function name present. |
+ STACK, // Function |
+ CONTEXT, |
+ UNUSED |
+ }; |
- Object** StackSlotEntriesAddr(); |
+ // Properties of scopes. |
+ class TypeField: public BitField<ScopeType, 0, 3> {}; |
+ class CallsEvalField: public BitField<bool, 3, 1> {}; |
+ class StrictModeField: public BitField<bool, 4, 1> {}; |
+ class FunctionVariableField: public BitField<FunctionVariableInfo, 5, 2> {}; |
+ class FunctionVariableMode: public BitField<VariableMode, 7, 3> {}; |
}; |
@@ -4685,7 +4807,7 @@ class SharedFunctionInfo: public HeapObject { |
DECL_ACCESSORS(code, Code) |
// [scope_info]: Scope info. |
- DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
+ DECL_ACCESSORS(scope_info, ScopeInfo) |
// [construct stub]: Code stub for constructing instances of this function. |
DECL_ACCESSORS(construct_stub, Code) |