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

Last change on this file since 27747 was 27341, checked in by aroben, 18 years ago

Windows build fix

  • kjs/ExecState.h:
  • Property svn:eol-style set to native
File size: 4.9 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 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 "value.h"
28#include "types.h"
29#include "CommonIdentifiers.h"
30#include "LabelStack.h"
31#include "scope_chain.h"
32
33namespace KJS {
34
35 enum CodeType {
36 GlobalCode,
37 EvalCode,
38 FunctionCode,
39 };
40
41 class JSGlobalObject;
42 class ScopeChain;
43 class Interpreter;
44 class FunctionImp;
45 class GlobalFuncImp;
46 class FunctionBodyNode;
47 struct LocalStorageEntry;
48
49 /**
50 * Represents the current state of script execution. This is
51 * passed as the first argument to most functions.
52 */
53 class ExecState {
54 friend class Interpreter;
55 friend class FunctionImp;
56 friend class GlobalFuncImp;
57 public:
58 /**
59 * Returns the interpreter currently running code
60 */
61 Interpreter* dynamicInterpreter() const { return m_interpreter; }
62
63 /**
64 * Returns the interpreter associated with the current scope's global object
65 */
66 Interpreter* lexicalInterpreter() const;
67
68 void setException(JSValue* e) { m_exception = e; }
69 void clearException() { m_exception = 0; }
70 JSValue* exception() const { return m_exception; }
71 JSValue** exceptionSlot() { return &m_exception; }
72 bool hadException() const { return !!m_exception; }
73
74 const ScopeChain& scopeChain() const { return scope; }
75
76 JSObject* variableObject() const { return m_variable; }
77 void setVariableObject(JSObject* v) { m_variable = v; }
78
79 JSObject* thisValue() const { return m_thisVal; }
80
81 ExecState* callingExecState() { return m_callingExecState; }
82
83 JSObject* activationObject() { return m_activation; }
84 CodeType codeType() { return m_codeType; }
85 FunctionBodyNode* currentBody() { return m_currentBody; }
86 FunctionImp* function() const { return m_function; }
87 const List* arguments() const { return m_arguments; }
88
89 void pushScope(JSObject* s) { scope.push(s); }
90 void popScope() { scope.pop(); }
91 LabelStack* seenLabels() { return &ls; }
92
93 void pushIteration() { m_iterationDepth++; }
94 void popIteration() { m_iterationDepth--; }
95 bool inIteration() const { return (m_iterationDepth > 0); }
96
97 void pushSwitch() { m_switchDepth++; }
98 void popSwitch() { m_switchDepth--; }
99 bool inSwitch() const { return (m_switchDepth > 0); }
100
101 void mark();
102
103 // This is a workaround to avoid accessing the global variables for these identifiers in
104 // important property lookup functions, to avoid taking PIC branches in Mach-O binaries
105 const CommonIdentifiers& propertyNames() const { return *m_propertyNames; }
106
107 LocalStorageEntry* localStorage() { return m_localStorageBuffer; }
108 void updateLocalStorage();
109
110 private:
111 ExecState(Interpreter* interp, JSGlobalObject* glob, JSObject* thisV,
112 FunctionBodyNode* currentBody, CodeType type = GlobalCode,
113 ExecState* callingExecState = 0, FunctionImp* function = 0, const List* args = 0);
114 ~ExecState();
115
116 // ExecStates are always stack-allocated, and the garbage collector
117 // marks the stack, so we don't need to protect the objects below from GC.
118
119 Interpreter* m_interpreter;
120 JSValue* m_exception;
121 CommonIdentifiers* m_propertyNames;
122
123 ExecState* m_callingExecState;
124 ExecState* m_savedExecState;
125 FunctionBodyNode* m_currentBody;
126
127 FunctionImp* m_function;
128 const List* m_arguments;
129 JSObject* m_activation;
130 LocalStorageEntry* m_localStorageBuffer;
131
132 ScopeChain scope;
133 JSObject* m_variable;
134 JSObject* m_thisVal;
135
136 LabelStack ls;
137 int m_iterationDepth;
138 int m_switchDepth;
139 CodeType m_codeType;
140 };
141
142} // namespace KJS
143
144#endif // ExecState_H
Note: See TracBrowser for help on using the repository browser.