• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
interpreter.h
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
5  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6  * Copyright (C) 2003 Apple Computer, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #ifndef _KJS_INTERPRETER_H_
26 #define _KJS_INTERPRETER_H_
27 
28 #include "value.h"
29 #include "object.h"
30 #include "types.h"
31 
32 namespace KJS {
33 
34  class ContextImp;
35  class InterpreterImp;
36 
49  enum CodeType {
50  GlobalCode = 0,
51  EvalCode = 1,
52  FunctionCode = 2
53  };
54 
73  class KJS_EXPORT Context {
74  public:
75  Context(ContextImp *i) : rep(i) { }
76 
77  ContextImp *imp() const { return rep; }
78 
86  const ScopeChain &scopeChain() const;
87 
94  Object variableObject() const;
95 
111  Object thisValue() const;
112 
121  const Context callingContext() const;
122 
127  CodeType codeType() const;
128 
133  int sourceId() const;
134 
138  int curStmtFirstLine() const;
139 
143  int curStmtLastLine() const;
144 
148  Object function() const;
149 
153  Identifier functionName() const;
154 
158  List args() const;
159 
160  private:
161  ContextImp *rep;
162  };
163 
164  bool operator==(const Context &c1, const Context &c2);
165  bool operator!=(const Context &c1, const Context &c2);
166 
173  class KJS_EXPORT Interpreter {
174  public:
191  Interpreter(const Object &global);
196  Interpreter();
197  virtual ~Interpreter();
198 
203  Object &globalObject() const;
204 
205  void initGlobalObject();
206 
207  static void lock();
208  static void unlock();
209 
221  ExecState *globalExec();
222 
231  bool checkSyntax(const UString &code, int *errLine, UString *errMsg);
232 
239  bool checkSyntax(const UString &code);
240 
256  Completion evaluate(const UString &code, const Value &thisV = Value());
257 
264  InterpreterImp *imp();
265 
274  Object builtinObject() const;
275 
279  Object builtinFunction() const;
280 
284  Object builtinArray() const;
285 
289  Object builtinBoolean() const;
290 
294  Object builtinString() const;
295 
299  Object builtinNumber() const;
300 
304  Object builtinDate() const;
305 
309  Object builtinRegExp() const;
310 
314  Object builtinError() const;
315 
319  Object builtinObjectPrototype() const;
320 
324  Object builtinFunctionPrototype() const;
325 
329  Object builtinArrayPrototype() const;
330 
334  Object builtinBooleanPrototype() const;
335 
339  Object builtinStringPrototype() const;
340 
344  Object builtinNumberPrototype() const;
345 
349  Object builtinDatePrototype() const;
350 
354  Object builtinRegExpPrototype() const;
355 
359  Object builtinErrorPrototype() const;
360 
364  Object builtinEvalError() const;
365  Object builtinRangeError() const;
366  Object builtinReferenceError() const;
367  Object builtinSyntaxError() const;
368  Object builtinTypeError() const;
369  Object builtinURIError() const;
370 
371  Object builtinEvalErrorPrototype() const;
372  Object builtinRangeErrorPrototype() const;
373  Object builtinReferenceErrorPrototype() const;
374  Object builtinSyntaxErrorPrototype() const;
375  Object builtinTypeErrorPrototype() const;
376  Object builtinURIErrorPrototype() const;
377 
378  enum CompatMode { NativeMode, IECompat, NetscapeCompat };
385  void setCompatMode(CompatMode mode);
386  CompatMode compatMode() const;
387 
392  static bool collect();
393 
398  virtual void mark() {}
399 
406  virtual int rtti() { return 0; }
407 
408 #ifdef KJS_DEBUG_MEM
409 
412  static void finalCheck();
413 #endif
414  private:
415  InterpreterImp *rep;
416 
422  Interpreter(const Interpreter&);
423 
429  Interpreter operator=(const Interpreter&);
430  protected:
431  virtual void virtual_hook( int id, void* data );
432  };
433 
439  class KJS_EXPORT ExecState {
440  friend class InterpreterImp;
441  friend class FunctionImp;
442  friend class GlobalFuncImp;
443  friend class TryNode;
444  friend class VarDeclNode;
445  friend class FuncDeclNode;
446  public:
452  // ### make non-const or provide an overload pair
453  Interpreter *dynamicInterpreter() const { return _interpreter; }
454 
455  // for compatibility
456  Interpreter *interpreter() const { return dynamicInterpreter(); }
457 
464  Interpreter *lexicalInterpreter() const;
465 
471  Context context() const { return _context; }
472 
473  void setException(const Value &e);
474  void clearException();
475  Value exception() const { return _exception; }
476  // ### make const
477  bool hadException();
478 
479  /*
480  * request for ending execution with an exception
481  */
482  static void requestTerminate() { terminate_request = true; }
483  /*
484  * optional confirmation for ending execution after requestTerminate()
485  */
486  static bool (*confirmTerminate)();
487  private:
488  ExecState(Interpreter *interp, ContextImp *con)
489  : _interpreter(interp), _context(con) { }
490  Interpreter *_interpreter;
491  ContextImp *_context;
492  Value _exception;
493  static bool terminate_request;
494  };
495 
496 } // namespace
497 
498 #endif // _KJS_INTERPRETER_H_
KJS::Value
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents...
Definition: value.h:168
KJS::Interpreter::mark
virtual void mark()
Called by InterpreterImp during the mark phase of the garbage collector Default implementation does n...
Definition: interpreter.h:398
KJS::ScopeChain
A scope chain object.
Definition: scope_chain.h:47
KJS::ContextImp
Execution context.
Definition: context.h:35
KJS::ExecState::dynamicInterpreter
Interpreter * dynamicInterpreter() const
Returns the interpreter associated with this execution state.
Definition: interpreter.h:453
KJS::Interpreter
Interpreter objects can be used to evaluate ECMAScript code.
Definition: interpreter.h:173
KJS::Object
Represents an Object.
Definition: object.h:82
KJS::Interpreter::rtti
virtual int rtti()
Provides a way to distinguish derived classes.
Definition: interpreter.h:406
KJS::Context
Represents an execution context, as specified by section 10 of the ECMA spec.
Definition: interpreter.h:73
KJS::FunctionImp
Implementation class for functions implemented in JS.
Definition: internal.h:390
KJS::UString
Unicode string class.
Definition: ustring.h:190
KJS
Definition: array_instance.h:28
KJS::Completion
Completion objects are used to convey the return status and value from functions. ...
Definition: completion.h:49
KJS::List
Native list type.
Definition: list.h:48
KJS::ExecState::context
Context context() const
Returns the execution context associated with this execution state.
Definition: interpreter.h:471
KJS::ExecState
Represents the current state of script execution.
Definition: interpreter.h:439
KJS::Identifier
Represents an Identifier for a Javascript object.
Definition: identifier.h:32

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kjs by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |