kjs Library API Documentation

interpreter.h

00001 // -*- c-basic-offset: 2 -*- 00002 /* 00003 * This file is part of the KDE libraries 00004 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) 00005 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 00006 * Copyright (C) 2003 Apple Computer, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Library General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Library General Public License 00019 * along with this library; see the file COPYING.LIB. If not, write to 00020 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 * Boston, MA 02111-1307, USA. 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 * request for ending execution with an exception 00468 */ 00469 static void requestTerminate() { terminate_request = true; } 00470 /* 00471 * optional confirmation for ending execution after requestTerminate() 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 } // namespace 00484 00485 #endif // _KJS_INTERPRETER_H_
KDE Logo
This file is part of the documentation for kjs Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:22:14 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003