source: webkit/trunk/JavaScriptCore/runtime/ExecState.h@ 38524

Last change on this file since 38524 was 38524, checked in by [email protected], 17 years ago

2008-11-17 Geoffrey Garen <[email protected]>

Not reviewed.


Try to fix Windows build.

  • API/APICast.h:
  • runtime/ExecState.h:
  • Property svn:eol-style set to native
File size: 7.2 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef ExecState_h
24#define ExecState_h
25
26// FIXME: Rename this file to CallFrame.h.
27
28#include "JSGlobalData.h"
29#include "RegisterFile.h"
30#include "ScopeChain.h"
31
32namespace JSC {
33
34 class Arguments;
35 class JSActivation;
36 class Interpreter;
37
38 // Represents the current state of script execution.
39 // Passed as the first argument to most functions.
40 class ExecState : private Register {
41 public:
42 JSFunction* callee() const { return this[RegisterFile::Callee].function(); }
43 CodeBlock* codeBlock() const { return this[RegisterFile::CodeBlock].Register::codeBlock(); }
44 ScopeChainNode* scopeChain() const { return this[RegisterFile::ScopeChain].Register::scopeChain(); }
45
46 JSValue* thisValue();
47
48 // Global object in which execution began.
49 JSGlobalObject* dynamicGlobalObject();
50
51 // Global object in which the currently executing code was defined.
52 // Differs from dynamicGlobalObject() during function calls across web browser frames.
53 JSGlobalObject* lexicalGlobalObject() const
54 {
55 return scopeChain()->globalObject();
56 }
57
58 // Differs from lexicalGlobalObject because this will have DOM window shell rather than
59 // the actual DOM window, which can't be "this" for security reasons.
60 JSObject* globalThisValue() const
61 {
62 return scopeChain()->globalThisObject();
63 }
64
65 // FIXME: Elsewhere, we use JSGlobalData* rather than JSGlobalData&.
66 // We should make this more uniform and either use a reference everywhere
67 // or a pointer everywhere.
68 JSGlobalData& globalData() const
69 {
70 return *scopeChain()->globalData;
71 }
72
73 // Convenience functions for access to global data.
74 // It takes a few memory references to get from a call frame to the global data
75 // pointer, so these are inefficient, and should be used sparingly in new code.
76 // But they're used in many places in legacy code, so they're not going away any time soon.
77
78 void setException(JSValue* exception) { globalData().exception = exception; }
79 void clearException() { globalData().exception = noValue(); }
80 JSValue* exception() const { return globalData().exception; }
81 JSValue** exceptionSlot() { return &globalData().exception; }
82 bool hadException() const { return !!globalData().exception; }
83
84 const CommonIdentifiers& propertyNames() const { return *globalData().propertyNames; }
85 const ArgList& emptyList() const { return *globalData().emptyList; }
86 Interpreter* interpreter() { return globalData().interpreter; }
87 Heap* heap() { return &globalData().heap; }
88
89 static const HashTable* arrayTable(CallFrame* callFrame) { return callFrame->globalData().arrayTable; }
90 static const HashTable* dateTable(CallFrame* callFrame) { return callFrame->globalData().dateTable; }
91 static const HashTable* mathTable(CallFrame* callFrame) { return callFrame->globalData().mathTable; }
92 static const HashTable* numberTable(CallFrame* callFrame) { return callFrame->globalData().numberTable; }
93 static const HashTable* regExpTable(CallFrame* callFrame) { return callFrame->globalData().regExpTable; }
94 static const HashTable* regExpConstructorTable(CallFrame* callFrame) { return callFrame->globalData().regExpConstructorTable; }
95 static const HashTable* stringTable(CallFrame* callFrame) { return callFrame->globalData().stringTable; }
96
97 private:
98 friend class Arguments;
99 friend class JSActivation;
100 friend class JSGlobalObject;
101 friend class Interpreter;
102
103 static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); }
104 Register* registers() { return this; }
105
106 CallFrame& operator=(const Register& r) { *static_cast<Register*>(this) = r; return *this; }
107
108 int argumentCount() const { return this[RegisterFile::ArgumentCount].i(); }
109 CallFrame* callerFrame() const { return this[RegisterFile::CallerFrame].callFrame(); }
110 Arguments* optionalCalleeArguments() const { return this[RegisterFile::OptionalCalleeArguments].arguments(); }
111 Instruction* returnPC() const { return this[RegisterFile::ReturnPC].vPC(); }
112 int returnValueRegister() const { return this[RegisterFile::ReturnValueRegister].i(); }
113
114 void setArgumentCount(int count) { this[RegisterFile::ArgumentCount] = count; }
115 void setCallee(JSFunction* callee) { this[RegisterFile::Callee] = callee; }
116 void setCalleeArguments(Arguments* arguments) { this[RegisterFile::OptionalCalleeArguments] = arguments; }
117 void setCallerFrame(CallFrame* callerFrame) { this[RegisterFile::CallerFrame] = callerFrame; }
118 void setCodeBlock(CodeBlock* codeBlock) { this[RegisterFile::CodeBlock] = codeBlock; }
119 void setScopeChain(ScopeChainNode* scopeChain) { this[RegisterFile::ScopeChain] = scopeChain; }
120
121 ALWAYS_INLINE void init(CodeBlock* codeBlock, Instruction* vPC, ScopeChainNode* scopeChain,
122 CallFrame* callerFrame, int returnValueRegister, int argc, JSFunction* function)
123 {
124 ASSERT(callerFrame); // Use noCaller() rather than 0 for the outer host call frame caller.
125
126 setCodeBlock(codeBlock);
127 setScopeChain(scopeChain);
128 setCallerFrame(callerFrame);
129 this[RegisterFile::ReturnPC] = vPC;
130 this[RegisterFile::ReturnValueRegister] = returnValueRegister;
131 setArgumentCount(argc); // original argument count (for the sake of the "arguments" object)
132 setCallee(function);
133 setCalleeArguments(0);
134 }
135
136 static const intptr_t HostCallFrameFlag = 1;
137
138 static CallFrame* noCaller() { return reinterpret_cast<CallFrame*>(HostCallFrameFlag); }
139 bool hasHostCallFrameFlag() const { return reinterpret_cast<intptr_t>(this) & HostCallFrameFlag; }
140 CallFrame* addHostCallFrameFlag() const { return reinterpret_cast<CallFrame*>(reinterpret_cast<intptr_t>(this) | HostCallFrameFlag); }
141 CallFrame* removeHostCallFrameFlag() { return reinterpret_cast<CallFrame*>(reinterpret_cast<intptr_t>(this) & ~HostCallFrameFlag); }
142
143 ExecState();
144 ~ExecState();
145 };
146
147} // namespace JSC
148
149#endif // ExecState_h
Note: See TracBrowser for help on using the repository browser.