interpreter.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _KJS_INTERPRETER_H_
00026 #define _KJS_INTERPRETER_H_
00027
00028 #include "value.h"
00029 #include "object.h"
00030 #include "types.h"
00031
00032 namespace KJS {
00033
00034 class ContextImp;
00035 class InterpreterImp;
00036
00049 enum CodeType {
00050 GlobalCode = 0,
00051 EvalCode = 1,
00052 FunctionCode = 2
00053 };
00054
00073 class KJS_EXPORT Context {
00074 public:
00075 Context(ContextImp *i) : rep(i) { }
00076
00077 ContextImp *imp() const { return rep; }
00078
00086 const ScopeChain &scopeChain() const;
00087
00094 Object variableObject() const;
00095
00111 Object thisValue() const;
00112
00121 const Context callingContext() const;
00122
00127 CodeType codeType() const;
00128
00133 int sourceId() const;
00134
00138 int curStmtFirstLine() const;
00139
00143 int curStmtLastLine() const;
00144
00148 Object function() const;
00149
00153 Identifier functionName() const;
00154
00158 List args() const;
00159
00160 private:
00161 ContextImp *rep;
00162 };
00163
00164 bool operator==(const Context &c1, const Context &c2);
00165 bool operator!=(const Context &c1, const Context &c2);
00166
00173 class KJS_EXPORT Interpreter {
00174 public:
00191 Interpreter(const Object &global);
00196 Interpreter();
00197 virtual ~Interpreter();
00198
00203 Object &globalObject() const;
00204
00205 void initGlobalObject();
00206
00207 static void lock();
00208 static void unlock();
00209
00221 ExecState *globalExec();
00222
00231 bool checkSyntax(const UString &code, int *errLine, UString *errMsg);
00232
00239 bool checkSyntax(const UString &code);
00240
00256 Completion evaluate(const UString &code, const Value &thisV = Value());
00257
00264 InterpreterImp *imp();
00265
00274 Object builtinObject() const;
00275
00279 Object builtinFunction() const;
00280
00284 Object builtinArray() const;
00285
00289 Object builtinBoolean() const;
00290
00294 Object builtinString() const;
00295
00299 Object builtinNumber() const;
00300
00304 Object builtinDate() const;
00305
00309 Object builtinRegExp() const;
00310
00314 Object builtinError() const;
00315
00319 Object builtinObjectPrototype() const;
00320
00324 Object builtinFunctionPrototype() const;
00325
00329 Object builtinArrayPrototype() const;
00330
00334 Object builtinBooleanPrototype() const;
00335
00339 Object builtinStringPrototype() const;
00340
00344 Object builtinNumberPrototype() const;
00345
00349 Object builtinDatePrototype() const;
00350
00354 Object builtinRegExpPrototype() const;
00355
00359 Object builtinErrorPrototype() const;
00360
00364 Object builtinEvalError() const;
00365 Object builtinRangeError() const;
00366 Object builtinReferenceError() const;
00367 Object builtinSyntaxError() const;
00368 Object builtinTypeError() const;
00369 Object builtinURIError() const;
00370
00371 Object builtinEvalErrorPrototype() const;
00372 Object builtinRangeErrorPrototype() const;
00373 Object builtinReferenceErrorPrototype() const;
00374 Object builtinSyntaxErrorPrototype() const;
00375 Object builtinTypeErrorPrototype() const;
00376 Object builtinURIErrorPrototype() const;
00377
00378 enum CompatMode { NativeMode, IECompat, NetscapeCompat };
00385 void setCompatMode(CompatMode mode);
00386 CompatMode compatMode() const;
00387
00392 static bool collect();
00393
00398 virtual void mark() {}
00399
00406 virtual int rtti() { return 0; }
00407
00408 #ifdef KJS_DEBUG_MEM
00409
00412 static void finalCheck();
00413 #endif
00414 private:
00415 InterpreterImp *rep;
00416
00422 Interpreter(const Interpreter&);
00423
00429 Interpreter operator=(const Interpreter&);
00430 protected:
00431 virtual void virtual_hook( int id, void* data );
00432 };
00433
00439 class KJS_EXPORT ExecState {
00440 friend class InterpreterImp;
00441 friend class FunctionImp;
00442 friend class GlobalFuncImp;
00443 friend class TryNode;
00444 friend class VarDeclNode;
00445 friend class FuncDeclNode;
00446 public:
00452
00453 Interpreter *dynamicInterpreter() const { return _interpreter; }
00454
00455
00456 Interpreter *interpreter() const { return dynamicInterpreter(); }
00457
00464 Interpreter *lexicalInterpreter() const;
00465
00471 Context context() const { return _context; }
00472
00473 void setException(const Value &e);
00474 void clearException();
00475 Value exception() const { return _exception; }
00476
00477 bool hadException();
00478
00479
00480
00481
00482 static void requestTerminate() { terminate_request = true; }
00483
00484
00485
00486 static bool (*confirmTerminate)();
00487 private:
00488 ExecState(Interpreter *interp, ContextImp *con)
00489 : _interpreter(interp), _context(con) { }
00490 Interpreter *_interpreter;
00491 ContextImp *_context;
00492 Value _exception;
00493 static bool terminate_request;
00494 };
00495
00496 }
00497
00498 #endif // _KJS_INTERPRETER_H_
|