Changeset 27097 in webkit for trunk/JavaScriptCore/kjs/ExecState.h
- Timestamp:
- Oct 26, 2007, 1:32:40 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ExecState.h
r20759 r27097 1 // -*- mode: c++; c-basic-offset: 4 -*- 1 2 /* 2 * This file is part of the KDE libraries3 3 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 4 4 * Copyright (C) 2001 Peter Kelly ([email protected]) 5 * Copyright (C) 2003 Apple Computer, Inc.5 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 28 28 #include "types.h" 29 29 #include "CommonIdentifiers.h" 30 31 namespace KJS { 32 class Context; 33 class Interpreter; 34 30 #include "LabelStack.h" 31 #include "scope_chain.h" 32 33 namespace KJS { 34 35 enum CodeType { 36 GlobalCode, 37 EvalCode, 38 FunctionCode, 39 }; 40 41 class ExecState; 42 class JSGlobalObject; 43 class ScopeChain; 35 44 class Interpreter; 36 45 class FunctionImp; 37 46 class GlobalFuncImp; 38 39 /** 40 * Represents the current state of script execution. This object allows you 41 * obtain a handle the interpreter that is currently executing the script, 42 * and also the current execution context. 43 */ 44 class ExecState { 45 friend class Interpreter; 46 friend class FunctionImp; 47 friend class GlobalFuncImp; 48 public: 47 class FunctionBodyNode; 48 49 49 /** 50 * Returns the interpreter associated with this execution state50 * @short Execution context. 51 51 * 52 * @return The interpreter executing the script 52 * Represents an execution context, as specified by section 10 of the ECMA 53 * spec. 54 * 55 * An execution context contains information about the current state of the 56 * script - the scope for variable lookup, the value of "this", etc. A new 57 * execution context is entered whenever global code is executed (e.g. with 58 * Interpreter::evaluate()), a function is called (see 59 * Object::call()), or the builtin "eval" function is executed. 60 * 61 * Most inheritable functions in the KJS api take a ExecState pointer as 62 * their first parameter. This can be used to obtain a handle to the current 63 * execution context. 53 64 */ 54 Interpreter* dynamicInterpreter() const { return m_interpreter; } 55 65 class Context { 66 public: 67 Context(JSGlobalObject*, Interpreter*, JSObject* thisV, 68 FunctionBodyNode* currentBody, CodeType type = GlobalCode, 69 Context* callingContext = 0, FunctionImp* function = 0, const List* args = 0); 70 ~Context(); 71 72 /** 73 * Returns the scope chain for this execution context. This is used for 74 * variable lookup, with the list being searched from start to end until a 75 * variable is found. 76 * 77 * @return The execution context's scope chain 78 */ 79 const ScopeChain& scopeChain() const { return scope; } 80 81 /** 82 * Returns the variable object for the execution context. This contains a 83 * property for each variable declared in the execution context. 84 * 85 * @return The execution context's variable object 86 */ 87 JSObject* variableObject() const { return m_variable; } 88 void setVariableObject(JSObject* v) { m_variable = v; } 89 90 /** 91 * Returns the "this" value for the execution context. This is the value 92 * returned when a script references the special variable "this". It should 93 * always be an Object, unless application-specific code has passed in a 94 * different type. 95 * 96 * The object that is used as the "this" value depends on the type of 97 * execution context - for global contexts, the global object is used. For 98 * function objewcts, the value is given by the caller (e.g. in the case of 99 * obj.func(), obj would be the "this" value). For code executed by the 100 * built-in "eval" function, the this value is the same as the calling 101 * context. 102 * 103 * @return The execution context's "this" value 104 */ 105 JSObject* thisValue() const { return m_thisVal; } 106 107 /** 108 * Returns the context from which the current context was invoked. For 109 * global code this will be a null context (i.e. one for which 110 * isNull() returns true). You should check isNull() on the returned 111 * value before calling any of it's methods. 112 * 113 * @return The calling execution context 114 */ 115 Context* callingContext() { return m_callingContext; } 116 117 JSObject* activationObject() { return m_activation; } 118 CodeType codeType() { return m_codeType; } 119 FunctionBodyNode* currentBody() { return m_currentBody; } 120 FunctionImp* function() const { return m_function; } 121 const List* arguments() const { return m_arguments; } 122 123 void pushScope(JSObject* s) { scope.push(s); } 124 void popScope() { scope.pop(); } 125 LabelStack* seenLabels() { return &ls; } 126 127 void pushIteration() { m_iterationDepth++; } 128 void popIteration() { m_iterationDepth--; } 129 bool inIteration() const { return (m_iterationDepth > 0); } 130 131 void pushSwitch() { m_switchDepth++; } 132 void popSwitch() { m_switchDepth--; } 133 bool inSwitch() const { return (m_switchDepth > 0); } 134 135 void mark(); 136 137 void setExecState(ExecState* exec) { m_execState = exec; } 138 ExecState* execState() { return m_execState; } 139 140 private: 141 // Contexts are always stack-allocated, and the garbage collector 142 // marks the stack, so we don't need to protect the objects below from GC. 143 144 Interpreter* m_interpreter; 145 Context* m_callingContext; 146 Context* m_savedContext; 147 FunctionBodyNode* m_currentBody; 148 ExecState* m_execState; 149 150 FunctionImp* m_function; 151 const List* m_arguments; 152 JSObject* m_activation; 153 154 ScopeChain scope; 155 JSObject* m_variable; 156 JSObject* m_thisVal; 157 158 LabelStack ls; 159 int m_iterationDepth; 160 int m_switchDepth; 161 CodeType m_codeType; 162 }; 163 164 56 165 /** 57 * Returns the interpreter associated with the current scope's 58 * global object 59 * 60 * @return The interpreter currently in scope 166 * Represents the current state of script execution. This object allows you 167 * obtain a handle the interpreter that is currently executing the script, 168 * and also the current execution context. 61 169 */ 62 Interpreter* lexicalInterpreter() const; 63 64 /** 65 * Returns the execution context associated with this execution state 66 * 67 * @return The current execution state context 68 */ 69 Context* context() const { return m_context; } 70 71 void setException(JSValue* e) { m_exception = e; } 72 void clearException() { m_exception = 0; } 73 JSValue* exception() const { return m_exception; } 74 JSValue** exceptionSlot() { return &m_exception; } 75 bool hadException() const { return !!m_exception; } 76 77 // This is a workaround to avoid accessing the global variables for these identifiers in 78 // important property lookup functions, to avoid taking PIC branches in Mach-O binaries 79 const CommonIdentifiers& propertyNames() const { return *m_propertyNames; } 80 81 private: 82 ExecState(Interpreter* interp, Context* con) 83 : m_interpreter(interp) 84 , m_context(con) 85 , m_exception(0) 86 , m_propertyNames(CommonIdentifiers::shared()) 87 { 88 } 89 Interpreter* m_interpreter; 90 Context* m_context; 91 JSValue* m_exception; 92 CommonIdentifiers* m_propertyNames; 93 }; 170 class ExecState { 171 friend class Interpreter; 172 friend class FunctionImp; 173 friend class GlobalFuncImp; 174 public: 175 /** 176 * Returns the interpreter associated with this execution state 177 * 178 * @return The interpreter executing the script 179 */ 180 Interpreter* dynamicInterpreter() const { return m_interpreter; } 181 182 /** 183 * Returns the interpreter associated with the current scope's 184 * global object 185 * 186 * @return The interpreter currently in scope 187 */ 188 Interpreter* lexicalInterpreter() const; 189 190 /** 191 * Returns the execution context associated with this execution state 192 * 193 * @return The current execution state context 194 */ 195 Context* context() const { return m_context; } 196 197 void setException(JSValue* e) { m_exception = e; } 198 void clearException() { m_exception = 0; } 199 JSValue* exception() const { return m_exception; } 200 JSValue** exceptionSlot() { return &m_exception; } 201 bool hadException() const { return !!m_exception; } 202 203 // This is a workaround to avoid accessing the global variables for these identifiers in 204 // important property lookup functions, to avoid taking PIC branches in Mach-O binaries 205 const CommonIdentifiers& propertyNames() const { return *m_propertyNames; } 206 207 private: 208 ExecState(Interpreter* interp, Context* con) 209 : m_interpreter(interp) 210 , m_context(con) 211 , m_exception(0) 212 , m_propertyNames(CommonIdentifiers::shared()) 213 { 214 } 215 Interpreter* m_interpreter; 216 Context* m_context; 217 JSValue* m_exception; 218 CommonIdentifiers* m_propertyNames; 219 }; 94 220 95 221 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.