source: webkit/trunk/JavaScriptCore/kjs/ExecState.h@ 32652

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

Reviewed by Darin.

Fix run-webkit-tests --threading
and provisionally fix <https://bugs.webkit.org/show_bug.cgi?id=18661>
Proxy server issue in Sunday's Nightly

Changed ClassInfo objects for built-in objects to hold a getter function returning
a per-thread instance. This makes it safe to share these ClassInfo objects between threads -
and these are the only ones that need to be shared.

  • Property svn:eol-style set to native
File size: 9.6 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 1999-2001 Harri Porten ([email protected])
4 * Copyright (C) 2001 Peter Kelly ([email protected])
5 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef ExecState_h
25#define ExecState_h
26
27#include "LabelStack.h"
28#include "LocalStorageEntry.h"
29#include "completion.h"
30#include "list.h"
31#include "scope_chain.h"
32
33namespace KJS {
34
35 class ActivationImp;
36 class CommonIdentifiers;
37 class EvalNode;
38 class FunctionBodyNode;
39 class FunctionImp;
40 class GlobalFuncImp;
41 struct HashTable;
42 class Interpreter;
43 class JSGlobalObject;
44 class JSVariableObject;
45 class ProgramNode;
46 class ScopeNode;
47
48 enum CodeType { GlobalCode, EvalCode, FunctionCode };
49
50 struct PerThreadData {
51 const HashTable* arrayTable;
52 const HashTable* dateTable;
53 const HashTable* mathTable;
54 const HashTable* numberTable;
55 const HashTable* RegExpImpTable;
56 const HashTable* RegExpObjectImpTable;
57 const HashTable* stringTable;
58
59 CommonIdentifiers* propertyNames;
60 const List emptyList;
61 };
62
63 // Represents the current state of script execution.
64 // Passed as the first argument to most functions.
65 class ExecState : Noncopyable {
66 friend class JSGlobalObject;
67 public:
68 // Global object that was in scope when the current script started executing.
69 JSGlobalObject* dynamicGlobalObject() const { return m_globalObject; }
70
71 // Global object that was in scope when the current body of code was defined.
72 JSGlobalObject* lexicalGlobalObject() const;
73
74 void setException(JSValue* exception) { m_exception = exception; }
75 void clearException() { m_exception = 0; }
76 JSValue* exception() const { return m_exception; }
77 JSValue** exceptionSlot() { return &m_exception; }
78 bool hadException() const { return !!m_exception; }
79 JSValue* takeException() { JSValue* exception = m_exception; m_exception = 0; return exception; }
80
81 const ScopeChain& scopeChain() const { return m_scopeChain; }
82 void pushScope(JSObject* s) { m_scopeChain.push(s); }
83 void popScope() { m_scopeChain.pop(); }
84 void replaceScopeChainTop(JSObject* o) { m_scopeChain.replaceTop(o); }
85
86 JSVariableObject* variableObject() const { return m_variableObject; }
87 void setVariableObject(JSVariableObject* v) { m_variableObject = v; }
88
89 JSObject* thisValue() const { return m_thisValue; }
90 JSObject* globalThisValue() const { return m_globalThisValue; }
91
92 ExecState* callingExecState() { return m_callingExec; }
93
94 ActivationImp* activationObject() { return m_activation; }
95 void setActivationObject(ActivationImp* a) { m_activation = a; }
96 CodeType codeType() { return m_codeType; }
97 ScopeNode* scopeNode() { return m_scopeNode; }
98 FunctionImp* function() const { return m_function; }
99 const List* arguments() const { return m_arguments; }
100
101 LabelStack& seenLabels() { return m_labelStack; }
102
103 void pushIteration() { m_iterationDepth++; }
104 void popIteration() { m_iterationDepth--; }
105 bool inIteration() const { return (m_iterationDepth > 0); }
106
107 void pushSwitch() { m_switchDepth++; }
108 void popSwitch() { m_switchDepth--; }
109 bool inSwitch() const { return (m_switchDepth > 0); }
110
111 // These pointers are used to avoid accessing global variables for these,
112 // to avoid taking PIC branches in Mach-O binaries.
113 const CommonIdentifiers& propertyNames() const { return *m_perThreadData->propertyNames; }
114 const List& emptyList() const { return m_perThreadData->emptyList; }
115 static const HashTable* arrayTable(ExecState* exec) { return exec->m_perThreadData->arrayTable; }
116 static const HashTable* dateTable(ExecState* exec) { return exec->m_perThreadData->dateTable; }
117 static const HashTable* mathTable(ExecState* exec) { return exec->m_perThreadData->mathTable; }
118 static const HashTable* numberTable(ExecState* exec) { return exec->m_perThreadData->numberTable; }
119 static const HashTable* RegExpImpTable(ExecState* exec) { return exec->m_perThreadData->RegExpImpTable; }
120 static const HashTable* RegExpObjectImpTable(ExecState* exec) { return exec->m_perThreadData->RegExpObjectImpTable; }
121 static const HashTable* stringTable(ExecState* exec) { return exec->m_perThreadData->stringTable; }
122
123 LocalStorage& localStorage() { return *m_localStorage; }
124 void setLocalStorage(LocalStorage* s) { m_localStorage = s; }
125
126 // These are only valid right after calling execute().
127 ComplType completionType() const { return m_completionType; }
128 const Identifier& breakOrContinueTarget() const
129 {
130 ASSERT(m_completionType == Break || m_completionType == Continue);
131 return *m_breakOrContinueTarget;
132 }
133
134 // Only for use in the implementation of execute().
135 void setCompletionType(ComplType type)
136 {
137 ASSERT(type != Break);
138 ASSERT(type != Continue);
139 m_completionType = type;
140 }
141 JSValue* setNormalCompletion()
142 {
143 ASSERT(!hadException());
144 m_completionType = Normal;
145 return 0;
146 }
147 JSValue* setNormalCompletion(JSValue* value)
148 {
149 ASSERT(!hadException());
150 m_completionType = Normal;
151 return value;
152 }
153 JSValue* setBreakCompletion(const Identifier* target)
154 {
155 ASSERT(!hadException());
156 m_completionType = Break;
157 m_breakOrContinueTarget = target;
158 return 0;
159 }
160 JSValue* setContinueCompletion(const Identifier* target)
161 {
162 ASSERT(!hadException());
163 m_completionType = Continue;
164 m_breakOrContinueTarget = target;
165 return 0;
166 }
167 JSValue* setReturnValueCompletion(JSValue* returnValue)
168 {
169 ASSERT(!hadException());
170 ASSERT(returnValue);
171 m_completionType = ReturnValue;
172 return returnValue;
173 }
174 JSValue* setThrowCompletion(JSValue* exception)
175 {
176 ASSERT(!hadException());
177 ASSERT(exception);
178 m_completionType = Throw;
179 return exception;
180 }
181 JSValue* setInterruptedCompletion()
182 {
183 ASSERT(!hadException());
184 m_completionType = Interrupted;
185 return 0;
186 }
187
188 protected:
189 ExecState(JSGlobalObject*, JSObject* thisObject);
190 ExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*);
191 ExecState(JSGlobalObject*, JSObject* thisObject, EvalNode*, ExecState* callingExecState, const ScopeChain&, JSVariableObject*);
192 ExecState(JSGlobalObject*, JSObject* thisObject, JSObject* globalThisValue, FunctionBodyNode*, ExecState* callingExecState, FunctionImp*, const List& args);
193 ~ExecState();
194
195 // ExecStates are always stack-allocated, and the garbage collector
196 // marks the stack, so we don't need to protect the objects below from GC.
197
198 JSGlobalObject* m_globalObject;
199 JSValue* m_exception;
200
201 ExecState* m_callingExec;
202
203 const PerThreadData* m_perThreadData;
204
205 ScopeNode* m_scopeNode;
206
207 FunctionImp* m_function;
208 const List* m_arguments;
209 ActivationImp* m_activation;
210 LocalStorage* m_localStorage;
211
212 ScopeChain m_scopeChain;
213 ScopeChainNode m_inlineScopeChainNode;
214 JSVariableObject* m_variableObject;
215
216 JSObject* m_thisValue;
217 JSObject* m_globalThisValue;
218
219 LabelStack m_labelStack;
220 int m_iterationDepth;
221 int m_switchDepth;
222 CodeType m_codeType;
223
224 ComplType m_completionType;
225 const Identifier* m_breakOrContinueTarget;
226 };
227
228 class GlobalExecState : public ExecState {
229 public:
230 GlobalExecState(JSGlobalObject*, JSObject* thisObject);
231 ~GlobalExecState();
232 };
233
234 class InterpreterExecState : public ExecState {
235 public:
236 InterpreterExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*);
237 ~InterpreterExecState();
238 };
239
240 class EvalExecState : public ExecState {
241 public:
242 EvalExecState(JSGlobalObject*, JSObject* thisObj, EvalNode*, ExecState* callingExec, const ScopeChain&, JSVariableObject*);
243 ~EvalExecState();
244 };
245
246 class FunctionExecState : public ExecState {
247 public:
248 FunctionExecState(JSGlobalObject*, JSObject* thisObject, JSObject* globalThisValue, FunctionBodyNode*,
249 ExecState* callingExecState, FunctionImp*, const List& args);
250 ~FunctionExecState();
251 };
252
253} // namespace KJS
254
255#endif // ExecState_h
Note: See TracBrowser for help on using the repository browser.