Changeset 14834 in webkit for trunk/JavaScriptCore/kjs/ExecState.h
- Timestamp:
- Jun 12, 2006, 11:08:52 PM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ExecState.h
r14827 r14834 22 22 */ 23 23 24 #ifndef _KJS_INTERPRETER_H_25 #define _KJS_INTERPRETER_H_24 #ifndef ExecState_H 25 #define ExecState_H 26 26 27 27 #include "value.h" … … 29 29 30 30 namespace KJS { 31 32 class Context; 33 class InterpreterImp; 34 class RuntimeMethod; 35 class ScopeChain; 36 37 namespace Bindings { 38 class RootObject; 39 } 40 41 class SavedBuiltinsInternal; 42 43 class SavedBuiltins { 44 friend class InterpreterImp; 45 public: 46 SavedBuiltins(); 47 ~SavedBuiltins(); 48 private: 49 SavedBuiltinsInternal *_internal; 50 }; 51 52 /** 53 * Interpreter objects can be used to evaluate ECMAScript code. Each 54 * interpreter has a global object which is used for the purposes of code 55 * evaluation, and also provides access to built-in properties such as 56 * " Object" and "Number". 57 */ 58 class Interpreter { 59 public: 60 /** 61 * Creates a new interpreter. The supplied object will be used as the global 62 * object for all scripts executed with this interpreter. During 63 * constuction, all the standard properties such as "Object" and "Number" 64 * will be added to the global object. 65 * 66 * Note: You should not use the same global object for multiple 67 * interpreters. 68 * 69 * This is due do the fact that the built-in properties are set in the 70 * constructor, and if these objects have been modified from another 71 * interpreter (e.g. a script modifying String.prototype), the changes will 72 * be overridden. 73 * 74 * @param global The object to use as the global object for this interpreter 75 */ 76 Interpreter(JSObject *global); 77 /** 78 * Creates a new interpreter. A global object will be created and 79 * initialized with the standard global properties. 80 */ 81 Interpreter(); 82 virtual ~Interpreter(); 83 84 /** 85 * Returns the object that is used as the global object during all script 86 * execution performed by this interpreter 87 */ 88 JSObject *globalObject() const; 89 90 void initGlobalObject(); 91 92 /** 93 * Returns the execution state object which can be used to execute 94 * scripts using this interpreter at a the "global" level, i.e. one 95 * with a execution context that has the global object as the "this" 96 * value, and who's scope chain contains only the global object. 97 * 98 * Note: this pointer remains constant for the life of the interpreter 99 * and should not be manually deleted. 100 * 101 * @return The interpreter global execution state object 102 */ 103 virtual ExecState *globalExec(); 104 105 /** 106 * Parses the supplied ECMAScript code and checks for syntax errors. 107 * 108 * @param code The code to check 109 * @return true if there were no syntax errors in the code, otherwise false 110 */ 111 bool checkSyntax(const UString &code); 112 113 /** 114 * Evaluates the supplied ECMAScript code. 115 * 116 * Since this method returns a Completion, you should check the type of 117 * completion to detect an error or before attempting to access the returned 118 * value. For example, if an error occurs during script execution and is not 119 * caught by the script, the completion type will be Throw. 120 * 121 * If the supplied code is invalid, a SyntaxError will be thrown. 122 * 123 * @param code The code to evaluate 124 * @param thisV The value to pass in as the "this" value for the script 125 * execution. This should either be jsNull() or an Object. 126 * @return A completion object representing the result of the execution. 127 */ 128 Completion evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0); 129 Completion evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0); 130 131 /** 132 * @internal 133 * 134 * Returns the implementation object associated with this interpreter. 135 * Only useful for internal KJS operations. 136 */ 137 InterpreterImp *imp() const { return rep; } 138 139 /** 140 * Returns the builtin "Object" object. This is the object that was set 141 * as a property of the global object during construction; if the property 142 * is replaced by script code, this method will still return the original 143 * object. 144 * 145 * @return The builtin "Object" object 146 */ 147 JSObject *builtinObject() const; 148 149 /** 150 * Returns the builtin "Function" object. 151 */ 152 JSObject *builtinFunction() const; 153 154 /** 155 * Returns the builtin "Array" object. 156 */ 157 JSObject *builtinArray() const; 158 159 /** 160 * Returns the builtin "Boolean" object. 161 */ 162 JSObject *builtinBoolean() const; 163 164 /** 165 * Returns the builtin "String" object. 166 */ 167 JSObject *builtinString() const; 168 169 /** 170 * Returns the builtin "Number" object. 171 */ 172 JSObject *builtinNumber() const; 173 174 /** 175 * Returns the builtin "Date" object. 176 */ 177 JSObject *builtinDate() const; 178 179 /** 180 * Returns the builtin "RegExp" object. 181 */ 182 JSObject *builtinRegExp() const; 183 184 /** 185 * Returns the builtin "Error" object. 186 */ 187 JSObject *builtinError() const; 188 189 /** 190 * Returns the builtin "Object.prototype" object. 191 */ 192 JSObject *builtinObjectPrototype() const; 193 194 /** 195 * Returns the builtin "Function.prototype" object. 196 */ 197 JSObject *builtinFunctionPrototype() const; 198 199 /** 200 * Returns the builtin "Array.prototype" object. 201 */ 202 JSObject *builtinArrayPrototype() const; 203 204 /** 205 * Returns the builtin "Boolean.prototype" object. 206 */ 207 JSObject *builtinBooleanPrototype() const; 208 209 /** 210 * Returns the builtin "String.prototype" object. 211 */ 212 JSObject *builtinStringPrototype() const; 213 214 /** 215 * Returns the builtin "Number.prototype" object. 216 */ 217 JSObject *builtinNumberPrototype() const; 218 219 /** 220 * Returns the builtin "Date.prototype" object. 221 */ 222 JSObject *builtinDatePrototype() const; 223 224 /** 225 * Returns the builtin "RegExp.prototype" object. 226 */ 227 JSObject *builtinRegExpPrototype() const; 228 229 /** 230 * Returns the builtin "Error.prototype" object. 231 */ 232 JSObject *builtinErrorPrototype() const; 233 234 /** 235 * The initial value of "Error" global property 236 */ 237 JSObject *builtinEvalError() const; 238 JSObject *builtinRangeError() const; 239 JSObject *builtinReferenceError() const; 240 JSObject *builtinSyntaxError() const; 241 JSObject *builtinTypeError() const; 242 JSObject *builtinURIError() const; 243 244 JSObject *builtinEvalErrorPrototype() const; 245 JSObject *builtinRangeErrorPrototype() const; 246 JSObject *builtinReferenceErrorPrototype() const; 247 JSObject *builtinSyntaxErrorPrototype() const; 248 JSObject *builtinTypeErrorPrototype() const; 249 JSObject *builtinURIErrorPrototype() const; 250 251 enum CompatMode { NativeMode, IECompat, NetscapeCompat }; 252 /** 253 * Call this to enable a compatibility mode with another browser. 254 * (by default konqueror is in "native mode"). 255 * Currently, in KJS, this only changes the behavior of Date::getYear() 256 * which returns the full year under IE. 257 */ 258 void setCompatMode(CompatMode mode); 259 CompatMode compatMode() const; 260 261 /** 262 * Run the garbage collection. Returns true when at least one object 263 * was collected; false otherwise. 264 */ 265 static bool collect(); 266 267 /** 268 * Called by InterpreterImp during the mark phase of the garbage collector 269 * Default implementation does nothing, this exist for classes that reimplement Interpreter. 270 */ 271 virtual void mark(bool currentThreadIsMainThread); 272 273 /** 274 * Provides a way to distinguish derived classes. 275 * Only useful if you reimplement Interpreter and if different kind of 276 * interpreters are created in the same process. 277 * The base class returns 0, the ECMA-bindings interpreter returns 1. 278 */ 279 virtual int rtti() { return 0; } 280 281 #ifdef KJS_DEBUG_MEM 282 /** 283 * @internal 284 */ 285 static void finalCheck(); 286 #endif 287 288 static bool shouldPrintExceptions(); 289 static void setShouldPrintExceptions(bool); 290 291 void saveBuiltins (SavedBuiltins &) const; 292 void restoreBuiltins (const SavedBuiltins &); 293 294 /** 295 * Determine if the value is a global object (for any interpreter). This may 296 * be difficult to determine for multiple uses of JSC in a process that are 297 * logically independent of each other. In the case of WebCore, this method 298 * is used to determine if an object is the Window object so we can perform 299 * security checks. 300 */ 301 virtual bool isGlobalObject(JSValue*) { return false; } 31 class Context; 302 32 303 /**304 * Find the interpreter for a particular global object. This should really305 * be a static method, but we can't do that is C++. Again, as with isGlobalObject()306 * implementation really need to know about all instances of Interpreter307 * created in an application to correctly implement this method. The only308 * override of this method is currently in WebCore.309 */310 virtual Interpreter* interpreterForGlobalObject(const JSValue*) { return 0; }311 312 /**313 * Determine if the it is 'safe' to execute code in the target interpreter from an314 * object that originated in this interpreter. This check is used to enforce WebCore315 * cross frame security rules. In particular, attempts to access 'bound' objects are316 * not allowed unless isSafeScript returns true.317 */318 virtual bool isSafeScript(const Interpreter*) { return true; }319 320 #if PLATFORM(MAC)321 virtual void *createLanguageInstanceForValue(ExecState*, int language, JSObject* value, const Bindings::RootObject* origin, const Bindings::RootObject* current);322 #endif323 324 // This is a workaround to avoid accessing the global variables for these identifiers in325 // important property lookup functions, to avoid taking PIC branches in Mach-O binaries326 const Identifier& argumentsIdentifier() { return *m_argumentsPropertyName; }327 const Identifier& specialPrototypeIdentifier() { return *m_specialPrototypePropertyName; }328 329 private:330 InterpreterImp *rep;331 332 const Identifier *m_argumentsPropertyName;333 const Identifier *m_specialPrototypePropertyName;334 335 /**336 * This constructor is not implemented, in order to prevent337 * copy-construction of Interpreter objects. You should always pass around338 * pointers to an interpreter instance instead.339 */340 Interpreter(const Interpreter&);341 342 /**343 * This constructor is not implemented, in order to prevent assignment of344 * Interpreter objects. You should always pass around pointers to an345 * interpreter instance instead.346 */347 Interpreter operator=(const Interpreter&);348 };349 350 33 /** 351 34 * Represents the current state of script execution. This object allows you 352 35 * obtain a handle the interpreter that is currently executing the script, 353 * and also the current execution statecontext.36 * and also the current execution context. 354 37 */ 355 38 class ExecState { 356 friend class Interpreter Imp;39 friend class Interpreter; 357 40 friend class FunctionImp; 358 41 friend class RuntimeMethodImp; … … 364 47 * @return The interpreter executing the script 365 48 */ 366 Interpreter *dynamicInterpreter() const { return m_interpreter; }49 Interpreter* dynamicInterpreter() const { return m_interpreter; } 367 50 368 51 /** … … 372 55 * @return The interpreter currently in scope 373 56 */ 374 Interpreter *lexicalInterpreter() const;57 Interpreter* lexicalInterpreter() const; 375 58 376 59 /** … … 398 81 }; 399 82 400 } // namespace 83 } // namespace KJS 401 84 402 #endif // _KJS_INTERPRETER_H_85 #endif // ExecState_H
Note:
See TracChangeset
for help on using the changeset viewer.