Changeset 37433 in webkit for trunk/JavaScriptCore/kjs/ExecState.h
- Timestamp:
- Oct 8, 2008, 5:40:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ExecState.h
r37428 r37433 24 24 #define ExecState_h 25 25 26 // FIXME: Rename this file to CallFrame.h. 27 26 28 #include "JSGlobalData.h" 27 29 #include "Machine.h" … … 30 32 namespace JSC { 31 33 32 class ExecState; 33 class JSValue; 34 class Register; 35 36 typedef ExecState CallFrame; 34 class Arguments; 35 class JSActivation; 37 36 38 37 // Represents the current state of script execution. 39 38 // Passed as the first argument to most functions. 40 class ExecState : private Register , Noncopyable{39 class ExecState : private Register { 41 40 public: 42 static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); } 43 Register* registers() { return this; } 41 JSFunction* callee() const { return this[RegisterFile::Callee].function(); } 42 CodeBlock* codeBlock() const { return this[RegisterFile::CodeBlock].Register::codeBlock(); } 43 ScopeChainNode* scopeChain() const { return this[RegisterFile::ScopeChain].Register::scopeChain(); } 44 45 JSValue* thisValue(); 44 46 45 47 // Global object in which execution began. … … 48 50 // Global object in which the currently executing code was defined. 49 51 // Differs from dynamicGlobalObject() during function calls across web browser frames. 50 JSGlobalObject* lexicalGlobalObject() 52 JSGlobalObject* lexicalGlobalObject() const 51 53 { 52 return Machine::scopeChain(this)->globalObject();54 return scopeChain()->globalObject(); 53 55 } 54 56 55 57 // Differs from lexicalGlobalObject because this will have DOM window shell rather than 56 // the actual DOM window .57 JSObject* globalThisValue() 58 // the actual DOM window, which can't be "this" for security reasons. 59 JSObject* globalThisValue() const 58 60 { 59 return Machine::scopeChain(this)->globalThisObject();61 return scopeChain()->globalThisObject(); 60 62 } 61 63 62 JSGlobalData& globalData() 64 // FIXME: Elsewhere, we use JSGlobalData* rather than JSGlobalData&. 65 // We should make this more uniform and either use a reference everywhere 66 // or a pointer everywhere. 67 JSGlobalData& globalData() const 63 68 { 64 return * Machine::scopeChain(this)->globalData;69 return *scopeChain()->globalData; 65 70 } 66 71 67 72 // Convenience functions for access to global data. 73 // It takes a few memory references to get from a call frame to the global data 74 // pointer, so these are inefficient, and should be used sparingly in new code. 75 // But they're used in many places in legacy code, so they're not going away any time soon. 68 76 69 77 void setException(JSValue* exception) { globalData().exception = exception; } 70 78 void clearException() { globalData().exception = 0; } 71 JSValue* exception() { return globalData().exception; }79 JSValue* exception() const { return globalData().exception; } 72 80 JSValue** exceptionSlot() { return &globalData().exception; } 73 bool hadException() { return !!globalData().exception; }81 bool hadException() const { return !!globalData().exception; } 74 82 75 IdentifierTable* identifierTable() { return globalData().identifierTable; } 76 const CommonIdentifiers& propertyNames() { return *globalData().propertyNames; } 77 const ArgList& emptyList() { return *globalData().emptyList; } 78 Lexer* lexer() { return globalData().lexer; } 79 Parser* parser() { return globalData().parser; } 83 const CommonIdentifiers& propertyNames() const { return *globalData().propertyNames; } 84 const ArgList& emptyList() const { return *globalData().emptyList; } 80 85 Machine* machine() { return globalData().machine; } 81 86 Heap* heap() { return &globalData().heap; } … … 90 95 91 96 private: 97 friend class Arguments; 98 friend class JSActivation; 99 friend class JSGlobalObject; 100 friend class Machine; 101 102 static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); } 103 Register* registers() { return this; } 104 105 CallFrame& operator=(const Register& r) { *static_cast<Register*>(this) = r; return *this; } 106 107 int argumentCount() const { return this[RegisterFile::ArgumentCount].i(); } 108 CallFrame* callerFrame() const { return this[RegisterFile::CallerFrame].callFrame(); } 109 Arguments* optionalCalleeArguments() const { return this[RegisterFile::OptionalCalleeArguments].arguments(); } 110 Instruction* returnPC() const { return this[RegisterFile::ReturnPC].vPC(); } 111 int returnValueRegister() const { return this[RegisterFile::ReturnValueRegister].i(); } 112 113 void setArgumentCount(int count) { this[RegisterFile::ArgumentCount] = count; } 114 void setCallee(JSFunction* callee) { this[RegisterFile::Callee] = callee; } 115 void setCalleeArguments(Arguments* arguments) { this[RegisterFile::OptionalCalleeArguments] = arguments; } 116 void setCallerFrame(CallFrame* callerFrame) { this[RegisterFile::CallerFrame] = callerFrame; } 117 void setCodeBlock(CodeBlock* codeBlock) { this[RegisterFile::CodeBlock] = codeBlock; } 118 void setScopeChain(ScopeChainNode* scopeChain) { this[RegisterFile::ScopeChain] = scopeChain; } 119 120 ALWAYS_INLINE void init(CodeBlock* codeBlock, Instruction* vPC, ScopeChainNode* scopeChain, 121 CallFrame* callerFrame, int returnValueRegister, int argc, JSFunction* function) 122 { 123 ASSERT(callerFrame); // Use noCaller() rather than 0 for the outer host call frame caller. 124 125 setCodeBlock(codeBlock); 126 setScopeChain(scopeChain); 127 setCallerFrame(callerFrame); 128 this[RegisterFile::ReturnPC] = vPC; 129 this[RegisterFile::ReturnValueRegister] = returnValueRegister; 130 setArgumentCount(argc); // original argument count (for the sake of the "arguments" object) 131 setCallee(function); 132 setCalleeArguments(0); 133 } 134 135 static const intptr_t HostCallFrameFlag = 1; 136 137 static CallFrame* noCaller() { return reinterpret_cast<CallFrame*>(HostCallFrameFlag); } 138 bool hasHostCallFrameFlag() const { return reinterpret_cast<intptr_t>(this) & HostCallFrameFlag; } 139 CallFrame* addHostCallFrameFlag() const { return reinterpret_cast<CallFrame*>(reinterpret_cast<intptr_t>(this) | HostCallFrameFlag); } 140 CallFrame* removeHostCallFrameFlag() { return reinterpret_cast<CallFrame*>(reinterpret_cast<intptr_t>(this) & ~HostCallFrameFlag); } 141 92 142 ExecState(); 93 143 ~ExecState();
Note:
See TracChangeset
for help on using the changeset viewer.