interpreter.h
00001 
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 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 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 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     Interpreter *interpreter() const { return _interpreter; }
00453 
00459     Context context() const { return _context; }
00460 
00461     void setException(const Value &e);
00462     void clearException();
00463     Value exception() const { return _exception; }
00464     bool hadException();
00465 
00466     
00467 
00468 
00469     static void requestTerminate() { terminate_request = true; }
00470     
00471 
00472 
00473     static bool (*confirmTerminate)();
00474   private:
00475     ExecState(Interpreter *interp, ContextImp *con)
00476         : _interpreter(interp), _context(con) { }
00477     Interpreter *_interpreter;
00478     ContextImp *_context;
00479     Value _exception;
00480     static bool terminate_request;
00481   };
00482 
00483 } 
00484 
00485 #endif // _KJS_INTERPRETER_H_
 
This file is part of the documentation for kjs Library Version 3.2.0.