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 | #include "JSGlobalData.h"
|
---|
27 | #include "ScopeChain.h"
|
---|
28 |
|
---|
29 | namespace JSC {
|
---|
30 |
|
---|
31 | class EvalNode;
|
---|
32 | class FunctionBodyNode;
|
---|
33 | class JSValue;
|
---|
34 | class GlobalFuncImp;
|
---|
35 | class Interpreter;
|
---|
36 | class JSGlobalObject;
|
---|
37 | class JSVariableObject;
|
---|
38 | class Machine;
|
---|
39 | class ProgramNode;
|
---|
40 | class Register;
|
---|
41 | class RegisterFile;
|
---|
42 | class ScopeNode;
|
---|
43 |
|
---|
44 | struct Instruction;
|
---|
45 |
|
---|
46 | // Represents the current state of script execution.
|
---|
47 | // Passed as the first argument to most functions.
|
---|
48 | class ExecState : Noncopyable {
|
---|
49 | #if ENABLE(CTI)
|
---|
50 | friend class CTI;
|
---|
51 | #endif
|
---|
52 | friend class Machine;
|
---|
53 | friend class DebuggerCallFrame;
|
---|
54 | public:
|
---|
55 | ExecState(JSGlobalObject*, JSObject* globalThisValue, ScopeChainNode* globalScopeChain);
|
---|
56 |
|
---|
57 | // Global object in which execution began.
|
---|
58 | JSGlobalObject* dynamicGlobalObject() const { return m_globalObject; }
|
---|
59 |
|
---|
60 | // Global object in which the current script was defined. (Can differ
|
---|
61 | // from dynamicGlobalObject() during function calls across frames.)
|
---|
62 | JSGlobalObject* lexicalGlobalObject() const
|
---|
63 | {
|
---|
64 | return m_scopeChain->globalObject();
|
---|
65 | }
|
---|
66 |
|
---|
67 | JSObject* globalThisValue() const { return m_scopeChain->globalThisObject(); }
|
---|
68 |
|
---|
69 | // Exception propogation.
|
---|
70 | void setException(JSValue* exception) { m_exception = exception; }
|
---|
71 | void clearException() { m_exception = 0; }
|
---|
72 | JSValue* exception() const { return m_exception; }
|
---|
73 | JSValue** exceptionSlot() { return &m_exception; }
|
---|
74 | bool hadException() const { return !!m_exception; }
|
---|
75 | #if ENABLE(CTI)
|
---|
76 | void setCTIReturnAddress(void* ctiRA) { m_ctiReturnAddress = ctiRA; }
|
---|
77 | void* ctiReturnAddress() const { return m_ctiReturnAddress; }
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | JSGlobalData& globalData() { return *m_globalData; }
|
---|
81 |
|
---|
82 | IdentifierTable* identifierTable() { return m_globalData->identifierTable; }
|
---|
83 | const CommonIdentifiers& propertyNames() const { return *m_globalData->propertyNames; }
|
---|
84 | const ArgList& emptyList() const { return *m_globalData->emptyList; }
|
---|
85 | Lexer* lexer() { return m_globalData->lexer; }
|
---|
86 | Parser* parser() { return m_globalData->parser; }
|
---|
87 | Machine* machine() const { return m_globalData->machine; }
|
---|
88 | static const HashTable* arrayTable(ExecState* exec) { return exec->m_globalData->arrayTable; }
|
---|
89 | static const HashTable* dateTable(ExecState* exec) { return exec->m_globalData->dateTable; }
|
---|
90 | static const HashTable* mathTable(ExecState* exec) { return exec->m_globalData->mathTable; }
|
---|
91 | static const HashTable* numberTable(ExecState* exec) { return exec->m_globalData->numberTable; }
|
---|
92 | static const HashTable* regExpTable(ExecState* exec) { return exec->m_globalData->regExpTable; }
|
---|
93 | static const HashTable* regExpConstructorTable(ExecState* exec) { return exec->m_globalData->regExpConstructorTable; }
|
---|
94 | static const HashTable* stringTable(ExecState* exec) { return exec->m_globalData->stringTable; }
|
---|
95 |
|
---|
96 | Heap* heap() const { return m_globalData->heap; }
|
---|
97 |
|
---|
98 | private:
|
---|
99 | // Default constructor required for gcc 3.
|
---|
100 | ExecState() { }
|
---|
101 |
|
---|
102 | ExecState(ExecState*, RegisterFile*, ScopeChainNode*, Register* callFrame);
|
---|
103 |
|
---|
104 | bool isGlobalObject(JSObject*) const;
|
---|
105 |
|
---|
106 | JSGlobalObject* m_globalObject;
|
---|
107 | JSObject* m_globalThisValue;
|
---|
108 |
|
---|
109 | JSValue* m_exception;
|
---|
110 | #if ENABLE(CTI)
|
---|
111 | void* m_ctiReturnAddress;
|
---|
112 | #endif
|
---|
113 | JSGlobalData* m_globalData;
|
---|
114 |
|
---|
115 | // These values are controlled by the machine.
|
---|
116 | ExecState* m_prev;
|
---|
117 | RegisterFile* m_registerFile;
|
---|
118 | ScopeChainNode* m_scopeChain;
|
---|
119 | Register* m_callFrame; // The most recent call frame.
|
---|
120 | };
|
---|
121 |
|
---|
122 | enum CodeType { GlobalCode, EvalCode, FunctionCode };
|
---|
123 |
|
---|
124 | } // namespace JSC
|
---|
125 |
|
---|
126 | #endif // ExecState_h
|
---|