interpreter.h
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2003 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef _KJS_INTERPRETER_H_
#define _KJS_INTERPRETER_H_
#include "value.h"
#include "object.h"
#include "types.h"
namespace KJS {
class ContextImp;
class InterpreterImp;
enum CodeType {
GlobalCode = 0,
EvalCode = 1,
FunctionCode = 2
};
class KJS_EXPORT Context {
public:
Context(ContextImp *i) : rep(i) { }
ContextImp *imp() const { return rep; }
const ScopeChain &scopeChain() const;
Object variableObject() const;
Object thisValue() const;
const Context callingContext() const;
CodeType codeType() const;
int sourceId() const;
int curStmtFirstLine() const;
int curStmtLastLine() const;
Object function() const;
Identifier functionName() const;
List args() const;
private:
ContextImp *rep;
};
bool operator==(const Context &c1, const Context &c2);
bool operator!=(const Context &c1, const Context &c2);
class KJS_EXPORT Interpreter {
public:
Interpreter(const Object &global);
Interpreter();
virtual ~Interpreter();
Object &globalObject() const;
void initGlobalObject();
static void lock();
static void unlock();
ExecState *globalExec();
bool checkSyntax(const UString &code, int *errLine, UString *errMsg);
bool checkSyntax(const UString &code);
Completion evaluate(const UString &code, const Value &thisV = Value());
InterpreterImp *imp();
Object builtinObject() const;
Object builtinFunction() const;
Object builtinArray() const;
Object builtinBoolean() const;
Object builtinString() const;
Object builtinNumber() const;
Object builtinDate() const;
Object builtinRegExp() const;
Object builtinError() const;
Object builtinObjectPrototype() const;
Object builtinFunctionPrototype() const;
Object builtinArrayPrototype() const;
Object builtinBooleanPrototype() const;
Object builtinStringPrototype() const;
Object builtinNumberPrototype() const;
Object builtinDatePrototype() const;
Object builtinRegExpPrototype() const;
Object builtinErrorPrototype() const;
Object builtinEvalError() const;
Object builtinRangeError() const;
Object builtinReferenceError() const;
Object builtinSyntaxError() const;
Object builtinTypeError() const;
Object builtinURIError() const;
Object builtinEvalErrorPrototype() const;
Object builtinRangeErrorPrototype() const;
Object builtinReferenceErrorPrototype() const;
Object builtinSyntaxErrorPrototype() const;
Object builtinTypeErrorPrototype() const;
Object builtinURIErrorPrototype() const;
enum CompatMode { NativeMode, IECompat, NetscapeCompat };
void setCompatMode(CompatMode mode);
CompatMode compatMode() const;
static bool collect();
virtual void mark() {}
virtual int rtti() { return 0; }
#ifdef KJS_DEBUG_MEM
static void finalCheck();
#endif
private:
InterpreterImp *rep;
Interpreter(const Interpreter&);
Interpreter operator=(const Interpreter&);
protected:
virtual void virtual_hook( int id, void* data );
};
class KJS_EXPORT ExecState {
friend class InterpreterImp;
friend class FunctionImp;
friend class GlobalFuncImp;
friend class TryNode;
friend class VarDeclNode;
friend class FuncDeclNode;
public:
// ### make non-const or provide an overload pair
Interpreter *dynamicInterpreter() const { return _interpreter; }
// for compatibility
Interpreter *interpreter() const { return dynamicInterpreter(); }
Interpreter *lexicalInterpreter() const;
Context context() const { return _context; }
void setException(const Value &e);
void clearException();
Value exception() const { return _exception; }
// ### make const
bool hadException();
/*
* request for ending execution with an exception
*/
static void requestTerminate() { terminate_request = true; }
/*
* optional confirmation for ending execution after requestTerminate()
*/
static bool (*confirmTerminate)();
private:
ExecState(Interpreter *interp, ContextImp *con)
: _interpreter(interp), _context(con) { }
Interpreter *_interpreter;
ContextImp *_context;
Value _exception;
static bool terminate_request;
};
} // namespace
#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::ExecState::dynamicInterpreter
Interpreter * dynamicInterpreter() const
Returns the interpreter associated with this execution state.
Definition: interpreter.h:453
KJS::ScopeChain
A scope chain object.
Definition: scope_chain.h:47
KJS::ContextImp
Execution context.
Definition: context.h:35
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:189
KJS::ExecState::context
Context context() const
Returns the execution context associated with this execution state.
Definition: interpreter.h:471
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
Represents the current state of script execution.
Definition: interpreter.h:439
KJS::Identifier
Represents an Identifier for a Javascript object.
Definition: identifier.h:32

KDE Home | KDE Accessibility Home | Description of Access Keys