Changeset 28468 in webkit for trunk/JavaScriptCore/kjs/interpreter.h
- Timestamp:
- Dec 5, 2007, 6:31:41 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/interpreter.h
r28328 r28468 1 1 /* 2 * This file is part of the KDE libraries3 2 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 4 3 * Copyright (C) 2001 Peter Kelly ([email protected]) 5 * Copyright (C) 2003 Apple Computer, Inc.4 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved. 6 5 * 7 6 * This library is free software; you can redistribute it and/or … … 22 21 */ 23 22 24 #ifndef _KJS_INTERPRETER_H_ 25 #define _KJS_INTERPRETER_H_ 26 27 #include "ExecState.h" 28 #include "protect.h" 29 #include "types.h" 30 #include "value.h" 31 #include <wtf/RefCounted.h> 23 #ifndef KJS_Interpreter_h 24 #define KJS_Interpreter_h 32 25 33 26 namespace KJS { 34 27 35 class ArrayObjectImp; 36 class ArrayPrototype; 37 class BooleanObjectImp; 38 class BooleanPrototype; 39 class DateObjectImp; 40 class DatePrototype; 41 class Debugger; 42 class ErrorObjectImp; 43 class ErrorPrototype; 44 class EvalError; 45 class EvalErrorPrototype; 46 class FunctionObjectImp; 47 class FunctionPrototype; 48 class JSGlobalObject; 49 class NativeErrorImp; 50 class NativeErrorPrototype; 51 class NumberObjectImp; 52 class NumberPrototype; 53 class ObjectObjectImp; 54 class ObjectPrototype; 55 class RangeError; 56 class RangeErrorPrototype; 57 class ReferenceError; 58 class ReferenceError; 59 class ReferenceErrorPrototype; 60 class RegExpObjectImp; 61 class RegExpPrototype; 62 class RuntimeMethod; 63 class SavedBuiltins; 64 class ScopeChain; 65 class StringObjectImp; 66 class StringPrototype; 67 class SyntaxErrorPrototype; 68 class TypeError; 69 class TypeErrorPrototype; 70 class UriError; 71 class UriErrorPrototype; 28 class Completion; 29 class ExecState; 30 class JSValue; 31 class UString; 32 33 struct UChar; 72 34 73 /**74 * Interpreter objects can be used to evaluate ECMAScript code. Each75 * interpreter has a global object which is used for the purposes of code76 * evaluation, and also provides access to built-in properties such as77 * " Object" and "Number".78 */79 35 class Interpreter { 80 friend class Collector;81 friend class JSGlobalObject;82 83 36 public: 84 /**85 * Creates a new interpreter. The global object must be set via setGlobalObject86 * before code is executed with this interpreter.87 */88 Interpreter();89 ~Interpreter();90 91 /**92 * Set the interpreter's global object. The supplied object will be used as the global93 * object for all scripts executed with this interpreter. During94 * construction, all the standard properties such as "Object" and "Number"95 * will be added to the global object.96 *97 * Note: You should not use the same global object for multiple98 * interpreters.99 *100 * This is due do the fact that the built-in properties are set in the101 * constructor, and if these objects have been modified from another102 * interpreter (e.g. a script modifying String.prototype), the changes will103 * be overridden.104 *105 * @param The object to use as the global object for this interpreter106 */107 void setGlobalObject(JSGlobalObject*);108 109 /**110 * Resets the global object's default properties and adds the default object111 * prototype to its prototype chain.112 */113 void resetGlobalObjectProperties();114 115 /**116 * Returns the object that is used as the global object during all script117 * execution performed by this interpreter118 */119 JSGlobalObject* globalObject() const;120 121 37 /** 122 38 * Parses the supplied ECMAScript code and checks for syntax errors. … … 126 42 * otherwise a throw completion with the syntax error as its value. 127 43 */ 128 Completion checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code);129 Completion checkSyntax(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength);44 static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code); 45 static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength); 130 46 131 47 /** … … 144 60 * @return A completion object representing the result of the execution. 145 61 */ 146 Completion evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0); 147 Completion evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0); 148 149 /** 150 * Returns the builtin "Object" object. This is the object that was set 151 * as a property of the global object during construction; if the property 152 * is replaced by script code, this method will still return the original 153 * object. 154 * 155 * @return The builtin "Object" object 156 */ 157 JSObject *builtinObject() const; 158 159 /** 160 * Returns the builtin "Function" object. 161 */ 162 JSObject *builtinFunction() const; 163 164 /** 165 * Returns the builtin "Array" object. 166 */ 167 JSObject *builtinArray() const; 168 169 /** 170 * Returns the builtin "Boolean" object. 171 */ 172 JSObject *builtinBoolean() const; 173 174 /** 175 * Returns the builtin "String" object. 176 */ 177 JSObject *builtinString() const; 178 179 /** 180 * Returns the builtin "Number" object. 181 */ 182 JSObject *builtinNumber() const; 183 184 /** 185 * Returns the builtin "Date" object. 186 */ 187 JSObject *builtinDate() const; 188 189 /** 190 * Returns the builtin "RegExp" object. 191 */ 192 RegExpObjectImp* builtinRegExp() const { return m_RegExp; } 193 194 /** 195 * Returns the builtin "Error" object. 196 */ 197 JSObject *builtinError() const; 198 199 /** 200 * Returns the builtin "Object.prototype" object. 201 */ 202 JSObject *builtinObjectPrototype() const; 203 204 /** 205 * Returns the builtin "Function.prototype" object. 206 */ 207 JSObject *builtinFunctionPrototype() const; 208 209 /** 210 * Returns the builtin "Array.prototype" object. 211 */ 212 JSObject *builtinArrayPrototype() const; 213 214 /** 215 * Returns the builtin "Boolean.prototype" object. 216 */ 217 JSObject *builtinBooleanPrototype() const; 218 219 /** 220 * Returns the builtin "String.prototype" object. 221 */ 222 JSObject *builtinStringPrototype() const; 223 224 /** 225 * Returns the builtin "Number.prototype" object. 226 */ 227 JSObject *builtinNumberPrototype() const; 228 229 /** 230 * Returns the builtin "Date.prototype" object. 231 */ 232 JSObject *builtinDatePrototype() const; 233 234 /** 235 * Returns the builtin "RegExp.prototype" object. 236 */ 237 JSObject *builtinRegExpPrototype() const; 238 239 /** 240 * Returns the builtin "Error.prototype" object. 241 */ 242 JSObject *builtinErrorPrototype() const; 243 244 /** 245 * The initial value of "Error" global property 246 */ 247 JSObject *builtinEvalError() const; 248 JSObject *builtinRangeError() const; 249 JSObject *builtinReferenceError() const; 250 JSObject *builtinSyntaxError() const; 251 JSObject *builtinTypeError() const; 252 JSObject *builtinURIError() const; 253 254 JSObject *builtinEvalErrorPrototype() const; 255 JSObject *builtinRangeErrorPrototype() const; 256 JSObject *builtinReferenceErrorPrototype() const; 257 JSObject *builtinSyntaxErrorPrototype() const; 258 JSObject *builtinTypeErrorPrototype() const; 259 JSObject *builtinURIErrorPrototype() const; 260 261 enum CompatMode { NativeMode, IECompat, NetscapeCompat }; 262 /** 263 * Call this to enable a compatibility mode with another browser. 264 * (by default konqueror is in "native mode"). 265 * Currently, in KJS, this only changes the behavior of Date::getYear() 266 * which returns the full year under IE. 267 */ 268 void setCompatMode(CompatMode mode) { m_compatMode = mode; } 269 CompatMode compatMode() const { return m_compatMode; } 62 static Completion evaluate(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0); 63 static Completion evaluate(ExecState*, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0); 270 64 271 65 static bool shouldPrintExceptions(); 272 66 static void setShouldPrintExceptions(bool); 273 274 void saveBuiltins (SavedBuiltins&) const;275 void restoreBuiltins (const SavedBuiltins&);276 277 // Chained list of interpreters (ring)278 static Interpreter* firstInterpreter() { return s_hook; }279 Interpreter* nextInterpreter() const { return next; }280 Interpreter* prevInterpreter() const { return prev; }281 282 Debugger* debugger() const { return m_debugger; }283 void setDebugger(Debugger* d) { m_debugger = d; }284 285 void setCurrentExec(ExecState* exec) { m_currentExec = exec; }286 ExecState* currentExec() const { return m_currentExec; }287 288 void setTimeoutTime(unsigned timeoutTime) { m_timeoutTime = timeoutTime; }289 290 void startTimeoutCheck();291 void stopTimeoutCheck();292 293 bool timedOut();294 295 ExecState m_globalExec; // This is temporarily public to help with bootstrapping.296 297 protected:298 unsigned m_timeoutTime;299 300 private:301 void init();302 303 void createObjectsForGlobalObjectProperties();304 void setGlobalObjectProperties();305 306 void resetTimeoutCheck();307 bool checkTimeout();308 309 // Uncopyable310 Interpreter(const Interpreter&);311 Interpreter operator=(const Interpreter&);312 313 ExecState* m_currentExec;314 JSGlobalObject* m_globalObject;315 316 // Chained list of interpreters (ring) - for collector317 static Interpreter* s_hook;318 Interpreter *next, *prev;319 320 int m_recursion;321 322 Debugger* m_debugger;323 CompatMode m_compatMode;324 325 unsigned m_timeAtLastCheckTimeout;326 unsigned m_timeExecuting;327 unsigned m_timeoutCheckCount;328 329 unsigned m_tickCount;330 unsigned m_ticksUntilNextTimeoutCheck;331 332 333 ObjectObjectImp* m_Object;334 FunctionObjectImp* m_Function;335 ArrayObjectImp* m_Array;336 BooleanObjectImp* m_Boolean;337 StringObjectImp* m_String;338 NumberObjectImp* m_Number;339 DateObjectImp* m_Date;340 RegExpObjectImp* m_RegExp;341 ErrorObjectImp* m_Error;342 343 ObjectPrototype* m_ObjectPrototype;344 FunctionPrototype* m_FunctionPrototype;345 ArrayPrototype* m_ArrayPrototype;346 BooleanPrototype* m_BooleanPrototype;347 StringPrototype* m_StringPrototype;348 NumberPrototype* m_NumberPrototype;349 DatePrototype* m_DatePrototype;350 RegExpPrototype* m_RegExpPrototype;351 ErrorPrototype* m_ErrorPrototype;352 353 NativeErrorImp* m_EvalError;354 NativeErrorImp* m_RangeError;355 NativeErrorImp* m_ReferenceError;356 NativeErrorImp* m_SyntaxError;357 NativeErrorImp* m_TypeError;358 NativeErrorImp* m_UriError;359 360 NativeErrorPrototype* m_EvalErrorPrototype;361 NativeErrorPrototype* m_RangeErrorPrototype;362 NativeErrorPrototype* m_ReferenceErrorPrototype;363 NativeErrorPrototype* m_SyntaxErrorPrototype;364 NativeErrorPrototype* m_TypeErrorPrototype;365 NativeErrorPrototype* m_UriErrorPrototype;366 67 }; 367 68 368 inline bool Interpreter::timedOut() 369 { 370 m_tickCount++; 371 372 if (m_tickCount != m_ticksUntilNextTimeoutCheck) 373 return false; 374 375 return checkTimeout(); 376 } 377 378 } // namespace 69 } // namespace KJS 379 70 380 #endif // _KJS_INTERPRETER_H_71 #endif // KJS_Interpreter_h
Note:
See TracChangeset
for help on using the changeset viewer.