Logo Search packages:      
Sourcecode: osb-jscore version File versions  Download package

interpreter.cpp

// -*- 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., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *
 */

#include "value.h"
#include "object.h"
#include "types.h"
#include "interpreter.h"

#include <assert.h>
#include <math.h>
#include <stdio.h>

#include "internal.h"
#include "collector.h"
#include "operations.h"
#include "error_object.h"
#include "nodes.h"
#include "context.h"

using namespace KJS;

// ------------------------------ Context --------------------------------------

00045 const ScopeChain &Context::scopeChain() const
{
  return rep->scopeChain();
}

00050 Object Context::variableObject() const
{
  return rep->variableObject();
}

00055 Object Context::thisValue() const
{
  return rep->thisValue();
}

00060 const Context Context::callingContext() const
{
  return rep->callingContext();
}

// ------------------------------ Interpreter ----------------------------------

00067 Interpreter::Interpreter(const Object &global) : rep(0)
{
  rep = new InterpreterImp(this,global);
}

00072 Interpreter::Interpreter()
{
  Object global(new ObjectImp());
  rep = new InterpreterImp(this,global);
}

Interpreter::~Interpreter()
{
  delete rep;
}

00083 Object &Interpreter::globalObject() const
{
  return rep->globalObject();
}

void Interpreter::initGlobalObject()
{
  rep->initGlobalObject();
}

void Interpreter::lock()
{
  InterpreterImp::lock();
}

void Interpreter::unlock()
{
  InterpreterImp::unlock();
}

int Interpreter::lockCount()
{
  return InterpreterImp::lockCount();
}

00108 ExecState *Interpreter::globalExec()
{
  return rep->globalExec();
}

00113 bool Interpreter::checkSyntax(const UString &code)
{
  return rep->checkSyntax(code);
}

Completion Interpreter::evaluate(const UString &code, const Value &thisV, const UString &)
{
  return evaluate(UString(), 0, code, thisV);
}

00123 Completion Interpreter::evaluate(const UString &sourceURL, int startingLineNumber, const UString &code, const Value &thisV)
{
  Completion comp = rep->evaluate(code,thisV, sourceURL, startingLineNumber);

#if APPLE_CHANGES
  if (shouldPrintExceptions() && comp.complType() == Throw) {
    lock();
    ExecState *exec = rep->globalExec();
    char *f = strdup(sourceURL.ascii());
    const char *message = comp.value().toObject(exec).toString(exec).ascii();
    printf("%s:%s\n", f, message);
    free(f);
    unlock();
  }
#endif

  return comp;
}

00142 InterpreterImp *Interpreter::imp()
{
  return rep;
}

00147 Object Interpreter::builtinObject() const
{
  return rep->builtinObject();
}

00152 Object Interpreter::builtinFunction() const
{
  return rep->builtinFunction();
}

00157 Object Interpreter::builtinArray() const
{
  return rep->builtinArray();
}

00162 Object Interpreter::builtinBoolean() const
{
  return rep->builtinBoolean();
}

00167 Object Interpreter::builtinString() const
{
  return rep->builtinString();
}

00172 Object Interpreter::builtinNumber() const
{
  return rep->builtinNumber();
}

00177 Object Interpreter::builtinDate() const
{
  return rep->builtinDate();
}

00182 Object Interpreter::builtinRegExp() const
{
  return rep->builtinRegExp();
}

00187 Object Interpreter::builtinError() const
{
  return rep->builtinError();
}

00192 Object Interpreter::builtinObjectPrototype() const
{
  return rep->builtinObjectPrototype();
}

00197 Object Interpreter::builtinFunctionPrototype() const
{
  return rep->builtinFunctionPrototype();
}

00202 Object Interpreter::builtinArrayPrototype() const
{
  return rep->builtinArrayPrototype();
}

00207 Object Interpreter::builtinBooleanPrototype() const
{
  return rep->builtinBooleanPrototype();
}

00212 Object Interpreter::builtinStringPrototype() const
{
  return rep->builtinStringPrototype();
}

00217 Object Interpreter::builtinNumberPrototype() const
{
  return rep->builtinNumberPrototype();
}

00222 Object Interpreter::builtinDatePrototype() const
{
  return rep->builtinDatePrototype();
}

00227 Object Interpreter::builtinRegExpPrototype() const
{
  return rep->builtinRegExpPrototype();
}

00232 Object Interpreter::builtinErrorPrototype() const
{
  return rep->builtinErrorPrototype();
}

00237 Object Interpreter::builtinEvalError() const
{
  return rep->builtinEvalError();
}

Object Interpreter::builtinRangeError() const
{
  return rep->builtinRangeError();
}

Object Interpreter::builtinReferenceError() const
{
  return rep->builtinReferenceError();
}

Object Interpreter::builtinSyntaxError() const
{
  return rep->builtinSyntaxError();
}

Object Interpreter::builtinTypeError() const
{
  return rep->builtinTypeError();
}

Object Interpreter::builtinURIError() const
{
  return rep->builtinURIError();
}

Object Interpreter::builtinEvalErrorPrototype() const
{
  return rep->builtinEvalErrorPrototype();
}

Object Interpreter::builtinRangeErrorPrototype() const
{
  return rep->builtinRangeErrorPrototype();
}

Object Interpreter::builtinReferenceErrorPrototype() const
{
  return rep->builtinReferenceErrorPrototype();
}

Object Interpreter::builtinSyntaxErrorPrototype() const
{
  return rep->builtinSyntaxErrorPrototype();
}

Object Interpreter::builtinTypeErrorPrototype() const
{
  return rep->builtinTypeErrorPrototype();
}

Object Interpreter::builtinURIErrorPrototype() const
{
  return rep->builtinURIErrorPrototype();
}

00297 void Interpreter::setCompatMode(CompatMode mode)
{
  rep->setCompatMode(mode);
}

Interpreter::CompatMode Interpreter::compatMode() const
{
  return rep->compatMode();
}

#ifdef KJS_DEBUG_MEM
#include "lexer.h"
void Interpreter::finalCheck()
{
  fprintf(stderr,"Interpreter::finalCheck()\n");
  // Garbage collect - as many times as necessary
  // (we could delete an object which was holding another object, so
  // the deref() will happen too late for deleting the impl of the 2nd object).
  while( Collector::collect() )
    ;

  Node::finalCheck();
  Collector::finalCheck();
  Lexer::globalClear();
  UString::globalClear();
}
#endif

#if APPLE_CHANGES
static bool printExceptions = false;

bool Interpreter::shouldPrintExceptions()
{
  return printExceptions;
}

void Interpreter::setShouldPrintExceptions(bool print)
{
  printExceptions = print;
}
#endif

void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
{
  rep->saveBuiltins(builtins);
}

void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
{
  rep->restoreBuiltins(builtins);
}

SavedBuiltins::SavedBuiltins() : 
  _internal(0)
{
}

SavedBuiltins::~SavedBuiltins()
{
  delete _internal;
}


void Interpreter::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }


00364 Interpreter *ExecState::lexicalInterpreter() const
{
  if (!_context) {
    return dynamicInterpreter();
  }

  InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(_context->scopeChain().bottom());

  if (!result) {
    return dynamicInterpreter();
  }

  return result->interpreter();
}

Generated by  Doxygen 1.6.0   Back to index