Ignore:
Timestamp:
Jun 12, 2006, 11:08:52 PM (19 years ago)
Author:
ggaren
Message:

JavaScriptCore:

Reviewed by TimO, Maciej.


  • Merged InterpreterImp code into Interpreter, which implements all interpreter functionality now. This is part of my continuing quest to create an external notion of JS "execution context" that is unified and simple -- something to replace the mix of Context, ContextImp, ExecState, Interpreter, InterpreterImp, and JSRun.


All tests pass. Leaks test has not regressed from its baseline ~207 leaks
with ~3460 leaked nodes.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/NP_jsobject.cpp:
  • bindings/objc/WebScriptObject.mm: (+[WebScriptObject throwException:]):
  • bindings/runtime_root.cpp:
  • bindings/runtime_root.h:
  • kjs/Context.cpp: (KJS::Context::Context):
  • kjs/ExecState.cpp: Added. (KJS::ExecState::lexicalInterpreter):
  • kjs/ExecState.h: Added. (KJS::ExecState::dynamicInterpreter):
  • kjs/SavedBuiltins.h: Added.
  • kjs/bool_object.cpp: (BooleanPrototype::BooleanPrototype):
  • kjs/collector.cpp: (KJS::Collector::collect): (KJS::Collector::numInterpreters):
  • kjs/context.h:
  • kjs/debugger.cpp: (Debugger::attach): (Debugger::detach):
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp: (KJS::interpreterMap): (KJS::Interpreter::Interpreter): (KJS::Interpreter::init): (KJS::Interpreter::~Interpreter): (KJS::Interpreter::globalObject): (KJS::Interpreter::initGlobalObject): (KJS::Interpreter::globalExec): (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate): (KJS::Interpreter::builtinObject): (KJS::Interpreter::builtinFunction): (KJS::Interpreter::builtinArray): (KJS::Interpreter::builtinBoolean): (KJS::Interpreter::builtinString): (KJS::Interpreter::builtinNumber): (KJS::Interpreter::builtinDate): (KJS::Interpreter::builtinRegExp): (KJS::Interpreter::builtinError): (KJS::Interpreter::builtinObjectPrototype): (KJS::Interpreter::builtinFunctionPrototype): (KJS::Interpreter::builtinArrayPrototype): (KJS::Interpreter::builtinBooleanPrototype): (KJS::Interpreter::builtinStringPrototype): (KJS::Interpreter::builtinNumberPrototype): (KJS::Interpreter::builtinDatePrototype): (KJS::Interpreter::builtinRegExpPrototype): (KJS::Interpreter::builtinErrorPrototype): (KJS::Interpreter::builtinEvalError): (KJS::Interpreter::builtinRangeError): (KJS::Interpreter::builtinReferenceError): (KJS::Interpreter::builtinSyntaxError): (KJS::Interpreter::builtinTypeError): (KJS::Interpreter::builtinURIError): (KJS::Interpreter::builtinEvalErrorPrototype): (KJS::Interpreter::builtinRangeErrorPrototype): (KJS::Interpreter::builtinReferenceErrorPrototype): (KJS::Interpreter::builtinSyntaxErrorPrototype): (KJS::Interpreter::builtinTypeErrorPrototype): (KJS::Interpreter::builtinURIErrorPrototype): (KJS::Interpreter::mark): (KJS::Interpreter::interpreterWithGlobalObject): (KJS::Interpreter::saveBuiltins): (KJS::Interpreter::restoreBuiltins):
  • kjs/interpreter.h: (KJS::Interpreter::setCompatMode): (KJS::Interpreter::compatMode): (KJS::Interpreter::firstInterpreter): (KJS::Interpreter::nextInterpreter): (KJS::Interpreter::prevInterpreter): (KJS::Interpreter::debugger): (KJS::Interpreter::setDebugger): (KJS::Interpreter::setContext): (KJS::Interpreter::context):
  • kjs/nodes.cpp: (StatementNode::hitStatement): (RegExpNode::evaluate):
  • kjs/protect.h:

JavaScriptGlue:

Reviewed by TimO, Maciej.


  • JSGlue part of merging InterpreterImp into Interpreter.


Since there's now a kjs forwarding header, I moved all forwarding
headers into a "ForwardingHeaders" directory, like in WebCore.

  • ForwardingHeaders: Added.
  • ForwardingHeaders/kjs: Added.
  • ForwardingHeaders/kjs/ExecState.h: Added.
  • ForwardingHeaders/wtf: Added.
  • JavaScriptGlue.xcodeproj/project.pbxproj:
  • config.h:
  • wtf: Removed.
  • wtf/AlwaysInline.h: Removed.
  • wtf/Assertions.h: Removed.
  • wtf/FastMalloc.h: Removed.
  • wtf/Forward.h: Removed.
  • wtf/HashCountedSet.h: Removed.
  • wtf/HashSet.h: Removed.
  • wtf/Noncopyable.h: Removed.
  • wtf/OwnArrayPtr.h: Removed.
  • wtf/OwnPtr.h: Removed.
  • wtf/PassRefPtr.h: Removed.
  • wtf/Platform.h: Removed.
  • wtf/RefPtr.h: Removed.
  • wtf/Vector.h: Removed.

WebCore:

Reviewed by TimO, Maciej.

  • WebCore part of merging InterpreterImp into Interpreter. No test because there's no behavior change.


A substantive change here is that ScriptInterpreter::mark must now chain to
Interpreter::mark, since Interpreter needs to mark the things that
InterpreterImp used to mark.


  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/kjs_binding.cpp:
  • bindings/js/kjs_window.cpp: (KJS::Window::put):
  • bridge/mac/WebCoreFrameBridge.mm:
  • bridge/mac/WebCoreScriptDebugger.mm: (-[WebCoreScriptCallFrame evaluateWebScript:]):
  • kwq/KWQPageState.mm:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r14799 r14834  
    2626#include "interpreter.h"
    2727
     28#include "SavedBuiltins.h"
     29#include "array_object.h"
     30#include "bool_object.h"
     31#include "collector.h"
     32#include "context.h"
     33#include "date_object.h"
     34#include "debugger.h"
     35#include "error_object.h"
     36#include "function_object.h"
     37#include "internal.h"
     38#include "math_object.h"
     39#include "nodes.h"
     40#include "number_object.h"
     41#include "object.h"
     42#include "object_object.h"
     43#include "operations.h"
     44#include "regexp_object.h"
     45#include "string_object.h"
     46#include "types.h"
     47#include "value.h"
     48
     49#if PLATFORM(MAC)
     50#include "runtime.h"
     51#endif
     52
    2853#include <assert.h>
    2954#include <math.h>
    3055#include <stdio.h>
    3156
    32 #include "collector.h"
    33 #include "context.h"
    34 #include "error_object.h"
    35 #include "internal.h"
    36 #include "nodes.h"
    37 #include "object.h"
    38 #include "operations.h"
    39 #include "types.h"
    40 #include "value.h"
    41 
    42 #if PLATFORM(MAC)
    43 #include "runtime.h"
     57namespace KJS {
     58
     59Interpreter* Interpreter::s_hook = 0;
     60   
     61typedef HashMap<JSObject*, Interpreter*> InterpreterMap;
     62static inline InterpreterMap &interpreterMap()
     63{
     64    static InterpreterMap* map = new InterpreterMap;
     65    return* map;
     66}
     67   
     68Interpreter::Interpreter(JSObject* globalObject)
     69    : m_globalExec(this, 0)
     70    , m_globalObject(globalObject)
     71    , m_argumentsPropertyName(&argumentsPropertyName)
     72    , m_specialPrototypePropertyName(&specialPrototypePropertyName)
     73{
     74    init();
     75}
     76
     77Interpreter::Interpreter()
     78    : m_globalExec(this, 0)
     79    , m_globalObject(new JSObject())
     80    , m_argumentsPropertyName(&argumentsPropertyName)
     81    , m_specialPrototypePropertyName(&specialPrototypePropertyName)
     82{
     83    init();
     84}
     85
     86void Interpreter::init()
     87{
     88    JSLock lock;
     89
     90    m_recursion = 0;
     91    m_debugger= 0;
     92    m_context = 0;
     93    m_compatMode = NativeMode;
     94
     95    interpreterMap().set(m_globalObject, this);
     96
     97    if (s_hook) {
     98        prev = s_hook;
     99        next = s_hook->next;
     100        s_hook->next->prev = this;
     101        s_hook->next = this;
     102    } else {
     103        // This is the first interpreter
     104        s_hook = next = prev = this;
     105    }
     106   
     107    initGlobalObject();
     108}
     109
     110Interpreter::~Interpreter()
     111{
     112    JSLock lock;
     113   
     114    if (m_debugger)
     115        m_debugger->detach(this);
     116
     117    next->prev = prev;
     118    prev->next = next;
     119    s_hook = next;
     120    if (s_hook == this)
     121    {
     122        // This was the last interpreter
     123        s_hook = 0;
     124    }
     125   
     126    interpreterMap().remove(m_globalObject);
     127}
     128
     129JSObject* Interpreter::globalObject() const
     130{
     131  return m_globalObject;
     132}
     133
     134void Interpreter::initGlobalObject()
     135{
     136    Identifier::init();
     137
     138    FunctionPrototype *funcProto = new FunctionPrototype(&m_globalExec);
     139    m_FunctionPrototype = funcProto;
     140    ObjectPrototype *objProto = new ObjectPrototype(&m_globalExec, funcProto);
     141    m_ObjectPrototype = objProto;
     142    funcProto->setPrototype(m_ObjectPrototype);
     143   
     144    ArrayPrototype *arrayProto = new ArrayPrototype(&m_globalExec, objProto);
     145    m_ArrayPrototype = arrayProto;
     146    StringPrototype *stringProto = new StringPrototype(&m_globalExec, objProto);
     147    m_StringPrototype = stringProto;
     148    BooleanPrototype *booleanProto = new BooleanPrototype(&m_globalExec, objProto, funcProto);
     149    m_BooleanPrototype = booleanProto;
     150    NumberPrototype *numberProto = new NumberPrototype(&m_globalExec, objProto, funcProto);
     151    m_NumberPrototype = numberProto;
     152    DatePrototype *dateProto = new DatePrototype(&m_globalExec, objProto);
     153    m_DatePrototype = dateProto;
     154    RegExpPrototype *regexpProto = new RegExpPrototype(&m_globalExec, objProto, funcProto);
     155    m_RegExpPrototype = regexpProto;
     156    ErrorPrototype *errorProto = new ErrorPrototype(&m_globalExec, objProto, funcProto);
     157    m_ErrorPrototype = errorProto;
     158   
     159    JSObject* o = m_globalObject;
     160    while (o->prototype()->isObject())
     161        o = static_cast<JSObject*>(o->prototype());
     162    o->setPrototype(m_ObjectPrototype);
     163   
     164    // Constructors (Object, Array, etc.)
     165    m_Object = new ObjectObjectImp(&m_globalExec, objProto, funcProto);
     166    m_Function = new FunctionObjectImp(&m_globalExec, funcProto);
     167    m_Array = new ArrayObjectImp(&m_globalExec, funcProto, arrayProto);
     168    m_String = new StringObjectImp(&m_globalExec, funcProto, stringProto);
     169    m_Boolean = new BooleanObjectImp(&m_globalExec, funcProto, booleanProto);
     170    m_Number = new NumberObjectImp(&m_globalExec, funcProto, numberProto);
     171    m_Date = new DateObjectImp(&m_globalExec, funcProto, dateProto);
     172    m_RegExp = new RegExpObjectImp(&m_globalExec, funcProto, regexpProto);
     173    m_Error = new ErrorObjectImp(&m_globalExec, funcProto, errorProto);
     174   
     175    // Error object prototypes
     176    m_EvalErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, EvalError, "EvalError", "EvalError");
     177    m_RangeErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, RangeError, "RangeError", "RangeError");
     178    m_ReferenceErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, ReferenceError, "ReferenceError", "ReferenceError");
     179    m_SyntaxErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, SyntaxError, "SyntaxError", "SyntaxError");
     180    m_TypeErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, TypeError, "TypeError", "TypeError");
     181    m_UriErrorPrototype = new NativeErrorPrototype(&m_globalExec, errorProto, URIError, "URIError", "URIError");
     182   
     183    // Error objects
     184    m_EvalError = new NativeErrorImp(&m_globalExec, funcProto, m_EvalErrorPrototype);
     185    m_RangeError = new NativeErrorImp(&m_globalExec, funcProto, m_RangeErrorPrototype);
     186    m_ReferenceError = new NativeErrorImp(&m_globalExec, funcProto, m_ReferenceErrorPrototype);
     187    m_SyntaxError = new NativeErrorImp(&m_globalExec, funcProto, m_SyntaxErrorPrototype);
     188    m_TypeError = new NativeErrorImp(&m_globalExec, funcProto, m_TypeErrorPrototype);
     189    m_UriError = new NativeErrorImp(&m_globalExec, funcProto, m_UriErrorPrototype);
     190   
     191    // ECMA 15.3.4.1
     192    funcProto->put(&m_globalExec, constructorPropertyName, m_Function, DontEnum);
     193   
     194    m_globalObject->put(&m_globalExec, "Object", m_Object, DontEnum);
     195    m_globalObject->put(&m_globalExec, "Function", m_Function, DontEnum);
     196    m_globalObject->put(&m_globalExec, "Array", m_Array, DontEnum);
     197    m_globalObject->put(&m_globalExec, "Boolean", m_Boolean, DontEnum);
     198    m_globalObject->put(&m_globalExec, "String", m_String, DontEnum);
     199    m_globalObject->put(&m_globalExec, "Number", m_Number, DontEnum);
     200    m_globalObject->put(&m_globalExec, "Date", m_Date, DontEnum);
     201    m_globalObject->put(&m_globalExec, "RegExp", m_RegExp, DontEnum);
     202    m_globalObject->put(&m_globalExec, "Error", m_Error, DontEnum);
     203    // Using Internal for those to have something != 0
     204    // (see kjs_window). Maybe DontEnum would be ok too ?
     205    m_globalObject->put(&m_globalExec, "EvalError",m_EvalError, Internal);
     206    m_globalObject->put(&m_globalExec, "RangeError",m_RangeError, Internal);
     207    m_globalObject->put(&m_globalExec, "ReferenceError",m_ReferenceError, Internal);
     208    m_globalObject->put(&m_globalExec, "SyntaxError",m_SyntaxError, Internal);
     209    m_globalObject->put(&m_globalExec, "TypeError",m_TypeError, Internal);
     210    m_globalObject->put(&m_globalExec, "URIError",m_UriError, Internal);
     211   
     212    // Set the constructorPropertyName property of all builtin constructors
     213    objProto->put(&m_globalExec, constructorPropertyName, m_Object, DontEnum | DontDelete | ReadOnly);
     214    funcProto->put(&m_globalExec, constructorPropertyName, m_Function, DontEnum | DontDelete | ReadOnly);
     215    arrayProto->put(&m_globalExec, constructorPropertyName, m_Array, DontEnum | DontDelete | ReadOnly);
     216    booleanProto->put(&m_globalExec, constructorPropertyName, m_Boolean, DontEnum | DontDelete | ReadOnly);
     217    stringProto->put(&m_globalExec, constructorPropertyName, m_String, DontEnum | DontDelete | ReadOnly);
     218    numberProto->put(&m_globalExec, constructorPropertyName, m_Number, DontEnum | DontDelete | ReadOnly);
     219    dateProto->put(&m_globalExec, constructorPropertyName, m_Date, DontEnum | DontDelete | ReadOnly);
     220    regexpProto->put(&m_globalExec, constructorPropertyName, m_RegExp, DontEnum | DontDelete | ReadOnly);
     221    errorProto->put(&m_globalExec, constructorPropertyName, m_Error, DontEnum | DontDelete | ReadOnly);
     222    m_EvalErrorPrototype->put(&m_globalExec, constructorPropertyName, m_EvalError, DontEnum | DontDelete | ReadOnly);
     223    m_RangeErrorPrototype->put(&m_globalExec, constructorPropertyName, m_RangeError, DontEnum | DontDelete | ReadOnly);
     224    m_ReferenceErrorPrototype->put(&m_globalExec, constructorPropertyName, m_ReferenceError, DontEnum | DontDelete | ReadOnly);
     225    m_SyntaxErrorPrototype->put(&m_globalExec, constructorPropertyName, m_SyntaxError, DontEnum | DontDelete | ReadOnly);
     226    m_TypeErrorPrototype->put(&m_globalExec, constructorPropertyName, m_TypeError, DontEnum | DontDelete | ReadOnly);
     227    m_UriErrorPrototype->put(&m_globalExec, constructorPropertyName, m_UriError, DontEnum | DontDelete | ReadOnly);
     228   
     229    // built-in values
     230    m_globalObject->put(&m_globalExec, "NaN",        jsNaN(), DontEnum|DontDelete);
     231    m_globalObject->put(&m_globalExec, "Infinity",   jsNumber(Inf), DontEnum|DontDelete);
     232    m_globalObject->put(&m_globalExec, "undefined",  jsUndefined(), DontEnum|DontDelete);
     233   
     234    // built-in functions
     235    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
     236    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
     237    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
     238    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
     239    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
     240    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
     241    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
     242    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
     243    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
     244    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
     245    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
     246#ifndef NDEBUG
     247    m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, funcProto, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
    44248#endif
    45 
    46 namespace KJS {
    47 
    48 // ------------------------------ Interpreter ----------------------------------
    49 
    50 Interpreter::Interpreter(JSObject *global)
    51   : rep(0)
    52   , m_argumentsPropertyName(&argumentsPropertyName)
    53   , m_specialPrototypePropertyName(&specialPrototypePropertyName)
    54 {
    55   rep = new InterpreterImp(this, global);
    56 }
    57 
    58 Interpreter::Interpreter()
    59   : rep(0)
    60   , m_argumentsPropertyName(&argumentsPropertyName)
    61   , m_specialPrototypePropertyName(&specialPrototypePropertyName)
    62 {
    63   rep = new InterpreterImp(this, new JSObject);
    64 }
    65 
    66 Interpreter::~Interpreter()
    67 {
    68   delete rep;
    69 }
    70 
    71 JSObject *Interpreter::globalObject() const
    72 {
    73   return rep->globalObject();
    74 }
    75 
    76 void Interpreter::initGlobalObject()
    77 {
    78   rep->initGlobalObject();
    79 }
    80 
    81 ExecState *Interpreter::globalExec()
    82 {
    83   return rep->globalExec();
     249   
     250    // built-in objects
     251    m_globalObject->put(&m_globalExec, "Math", new MathObjectImp(&m_globalExec, objProto), DontEnum);
     252}
     253
     254ExecState* Interpreter::globalExec()
     255{
     256  return &m_globalExec;
    84257}
    85258
    86259bool Interpreter::checkSyntax(const UString &code)
    87260{
    88   return rep->checkSyntax(code);
     261    JSLock lock;
     262   
     263    // Parser::parse() returns 0 in a syntax error occurs
     264    RefPtr<ProgramNode> progNode = Parser::parse(UString(), 0, code.data(), code.size(), 0, 0, 0);
     265    return progNode;
    89266}
    90267
     
    96273Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
    97274{
    98     Completion comp = rep->evaluate(code, codeLength, thisV, sourceURL, startingLineNumber);
    99 
    100     if (shouldPrintExceptions() && comp.complType() == Throw) {
     275    JSLock lock;
     276   
     277    // prevent against infinite recursion
     278    if (m_recursion >= 20)
     279        return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep"));
     280   
     281    // parse the source code
     282    int sid;
     283    int errLine;
     284    UString errMsg;
     285    RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, &sid, &errLine, &errMsg);
     286   
     287    // notify debugger that source has been parsed
     288    if (m_debugger) {
     289        bool cont = m_debugger->sourceParsed(&m_globalExec, sid, sourceURL, UString(code, codeLength), errLine);
     290        if (!cont)
     291            return Completion(Break);
     292    }
     293   
     294    // no program node means a syntax error occurred
     295    if (!progNode)
     296        return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, &sourceURL));
     297   
     298    m_globalExec.clearException();
     299   
     300    m_recursion++;
     301   
     302    JSObject* globalObj = m_globalObject;
     303    JSObject* thisObj = globalObj;
     304   
     305    // "this" must be an object... use same rules as Function.prototype.apply()
     306    if (thisV && !thisV->isUndefinedOrNull())
     307        thisObj = thisV->toObject(&m_globalExec);
     308   
     309    Completion res;
     310    if (m_globalExec.hadException())
     311        // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it
     312        res = Completion(Throw, m_globalExec.exception());
     313    else {
     314        // execute the code
     315        Context ctx(globalObj, this, thisObj, progNode.get());
     316        ExecState newExec(this, &ctx);
     317        progNode->processVarDecls(&newExec);
     318        res = progNode->execute(&newExec);
     319    }
     320   
     321    m_recursion--;
     322   
     323    if (shouldPrintExceptions() && res.complType() == Throw) {
    101324        JSLock lock;
    102         ExecState *exec = rep->globalExec();
     325        ExecState* exec = globalExec();
    103326        CString f = sourceURL.UTF8String();
    104         CString message = comp.value()->toObject(exec)->toString(exec).UTF8String();
    105         int line = comp.value()->toObject(exec)->get(exec, "line")->toUInt32(exec);
     327        CString message = res.value()->toObject(exec)->toString(exec).UTF8String();
     328        int line = res.value()->toObject(exec)->get(exec, "line")->toUInt32(exec);
    106329#if PLATFORM(WIN_OS)
    107330        printf("%s line %d: %s\n", f.c_str(), line, message.c_str());
     
    111334    }
    112335
    113     return comp;
     336    return res;
    114337}
    115338
    116339JSObject *Interpreter::builtinObject() const
    117340{
    118   return rep->builtinObject();
     341  return m_Object;
    119342}
    120343
    121344JSObject *Interpreter::builtinFunction() const
    122345{
    123   return rep->builtinFunction();
     346  return m_Function;
    124347}
    125348
    126349JSObject *Interpreter::builtinArray() const
    127350{
    128   return rep->builtinArray();
     351  return m_Array;
    129352}
    130353
    131354JSObject *Interpreter::builtinBoolean() const
    132355{
    133   return rep->builtinBoolean();
     356  return m_Boolean;
    134357}
    135358
    136359JSObject *Interpreter::builtinString() const
    137360{
    138   return rep->builtinString();
     361  return m_String;
    139362}
    140363
    141364JSObject *Interpreter::builtinNumber() const
    142365{
    143   return rep->builtinNumber();
     366  return m_Number;
    144367}
    145368
    146369JSObject *Interpreter::builtinDate() const
    147370{
    148   return rep->builtinDate();
     371  return m_Date;
    149372}
    150373
    151374JSObject *Interpreter::builtinRegExp() const
    152375{
    153   return rep->builtinRegExp();
     376  return m_RegExp;
    154377}
    155378
    156379JSObject *Interpreter::builtinError() const
    157380{
    158   return rep->builtinError();
     381  return m_Error;
    159382}
    160383
    161384JSObject *Interpreter::builtinObjectPrototype() const
    162385{
    163   return rep->builtinObjectPrototype();
     386  return m_ObjectPrototype;
    164387}
    165388
    166389JSObject *Interpreter::builtinFunctionPrototype() const
    167390{
    168   return rep->builtinFunctionPrototype();
     391  return m_FunctionPrototype;
    169392}
    170393
    171394JSObject *Interpreter::builtinArrayPrototype() const
    172395{
    173   return rep->builtinArrayPrototype();
     396  return m_ArrayPrototype;
    174397}
    175398
    176399JSObject *Interpreter::builtinBooleanPrototype() const
    177400{
    178   return rep->builtinBooleanPrototype();
     401  return m_BooleanPrototype;
    179402}
    180403
    181404JSObject *Interpreter::builtinStringPrototype() const
    182405{
    183   return rep->builtinStringPrototype();
     406  return m_StringPrototype;
    184407}
    185408
    186409JSObject *Interpreter::builtinNumberPrototype() const
    187410{
    188   return rep->builtinNumberPrototype();
     411  return m_NumberPrototype;
    189412}
    190413
    191414JSObject *Interpreter::builtinDatePrototype() const
    192415{
    193   return rep->builtinDatePrototype();
     416  return m_DatePrototype;
    194417}
    195418
    196419JSObject *Interpreter::builtinRegExpPrototype() const
    197420{
    198   return rep->builtinRegExpPrototype();
     421  return m_RegExpPrototype;
    199422}
    200423
    201424JSObject *Interpreter::builtinErrorPrototype() const
    202425{
    203   return rep->builtinErrorPrototype();
     426  return m_ErrorPrototype;
    204427}
    205428
    206429JSObject *Interpreter::builtinEvalError() const
    207430{
    208   return rep->builtinEvalError();
     431  return m_EvalError;
    209432}
    210433
    211434JSObject *Interpreter::builtinRangeError() const
    212435{
    213   return rep->builtinRangeError();
     436  return m_RangeError;
    214437}
    215438
    216439JSObject *Interpreter::builtinReferenceError() const
    217440{
    218   return rep->builtinReferenceError();
     441  return m_ReferenceError;
    219442}
    220443
    221444JSObject *Interpreter::builtinSyntaxError() const
    222445{
    223   return rep->builtinSyntaxError();
     446  return m_SyntaxError;
    224447}
    225448
    226449JSObject *Interpreter::builtinTypeError() const
    227450{
    228   return rep->builtinTypeError();
     451  return m_TypeError;
    229452}
    230453
    231454JSObject *Interpreter::builtinURIError() const
    232455{
    233   return rep->builtinURIError();
     456  return m_UriError;
    234457}
    235458
    236459JSObject *Interpreter::builtinEvalErrorPrototype() const
    237460{
    238   return rep->builtinEvalErrorPrototype();
     461  return m_EvalErrorPrototype;
    239462}
    240463
    241464JSObject *Interpreter::builtinRangeErrorPrototype() const
    242465{
    243   return rep->builtinRangeErrorPrototype();
     466  return m_RangeErrorPrototype;
    244467}
    245468
    246469JSObject *Interpreter::builtinReferenceErrorPrototype() const
    247470{
    248   return rep->builtinReferenceErrorPrototype();
     471  return m_ReferenceErrorPrototype;
    249472}
    250473
    251474JSObject *Interpreter::builtinSyntaxErrorPrototype() const
    252475{
    253   return rep->builtinSyntaxErrorPrototype();
     476  return m_SyntaxErrorPrototype;
    254477}
    255478
    256479JSObject *Interpreter::builtinTypeErrorPrototype() const
    257480{
    258   return rep->builtinTypeErrorPrototype();
     481  return m_TypeErrorPrototype;
    259482}
    260483
    261484JSObject *Interpreter::builtinURIErrorPrototype() const
    262485{
    263   return rep->builtinURIErrorPrototype();
    264 }
    265 
    266 void Interpreter::setCompatMode(CompatMode mode)
    267 {
    268   rep->setCompatMode(mode);
    269 }
    270 
    271 Interpreter::CompatMode Interpreter::compatMode() const
    272 {
    273   return rep->compatMode();
     486  return m_UriErrorPrototype;
    274487}
    275488
     
    281494void Interpreter::mark(bool)
    282495{
     496    if (m_context)
     497        m_context->mark();
     498    if (m_globalObject && !m_globalObject->marked())
     499        m_globalObject->mark();
     500    if (m_globalExec.exception() && !m_globalExec.exception()->marked())
     501        m_globalExec.exception()->mark();
     502}
     503
     504Interpreter* Interpreter::interpreterWithGlobalObject(JSObject* globalObject)
     505{
     506    return interpreterMap().get(globalObject);
    283507}
    284508
     
    317541#endif
    318542
    319 void Interpreter::saveBuiltins (SavedBuiltins &builtins) const
    320 {
    321   rep->saveBuiltins(builtins);
    322 }
    323 
    324 void Interpreter::restoreBuiltins (const SavedBuiltins &builtins)
    325 {
    326   rep->restoreBuiltins(builtins);
     543void Interpreter::saveBuiltins (SavedBuiltins& builtins) const
     544{
     545    if (!builtins._internal)
     546        builtins._internal = new SavedBuiltinsInternal;
     547   
     548    builtins._internal->m_Object = m_Object;
     549    builtins._internal->m_Function = m_Function;
     550    builtins._internal->m_Array = m_Array;
     551    builtins._internal->m_Boolean = m_Boolean;
     552    builtins._internal->m_String = m_String;
     553    builtins._internal->m_Number = m_Number;
     554    builtins._internal->m_Date = m_Date;
     555    builtins._internal->m_RegExp = m_RegExp;
     556    builtins._internal->m_Error = m_Error;
     557   
     558    builtins._internal->m_ObjectPrototype = m_ObjectPrototype;
     559    builtins._internal->m_FunctionPrototype = m_FunctionPrototype;
     560    builtins._internal->m_ArrayPrototype = m_ArrayPrototype;
     561    builtins._internal->m_BooleanPrototype = m_BooleanPrototype;
     562    builtins._internal->m_StringPrototype = m_StringPrototype;
     563    builtins._internal->m_NumberPrototype = m_NumberPrototype;
     564    builtins._internal->m_DatePrototype = m_DatePrototype;
     565    builtins._internal->m_RegExpPrototype = m_RegExpPrototype;
     566    builtins._internal->m_ErrorPrototype = m_ErrorPrototype;
     567   
     568    builtins._internal->m_EvalError = m_EvalError;
     569    builtins._internal->m_RangeError = m_RangeError;
     570    builtins._internal->m_ReferenceError = m_ReferenceError;
     571    builtins._internal->m_SyntaxError = m_SyntaxError;
     572    builtins._internal->m_TypeError = m_TypeError;
     573    builtins._internal->m_UriError = m_UriError;
     574   
     575    builtins._internal->m_EvalErrorPrototype = m_EvalErrorPrototype;
     576    builtins._internal->m_RangeErrorPrototype = m_RangeErrorPrototype;
     577    builtins._internal->m_ReferenceErrorPrototype = m_ReferenceErrorPrototype;
     578    builtins._internal->m_SyntaxErrorPrototype = m_SyntaxErrorPrototype;
     579    builtins._internal->m_TypeErrorPrototype = m_TypeErrorPrototype;
     580    builtins._internal->m_UriErrorPrototype = m_UriErrorPrototype;
     581}
     582
     583void Interpreter::restoreBuiltins (const SavedBuiltins& builtins)
     584{
     585    if (!builtins._internal)
     586        return;
     587
     588    m_Object = builtins._internal->m_Object;
     589    m_Function = builtins._internal->m_Function;
     590    m_Array = builtins._internal->m_Array;
     591    m_Boolean = builtins._internal->m_Boolean;
     592    m_String = builtins._internal->m_String;
     593    m_Number = builtins._internal->m_Number;
     594    m_Date = builtins._internal->m_Date;
     595    m_RegExp = builtins._internal->m_RegExp;
     596    m_Error = builtins._internal->m_Error;
     597   
     598    m_ObjectPrototype = builtins._internal->m_ObjectPrototype;
     599    m_FunctionPrototype = builtins._internal->m_FunctionPrototype;
     600    m_ArrayPrototype = builtins._internal->m_ArrayPrototype;
     601    m_BooleanPrototype = builtins._internal->m_BooleanPrototype;
     602    m_StringPrototype = builtins._internal->m_StringPrototype;
     603    m_NumberPrototype = builtins._internal->m_NumberPrototype;
     604    m_DatePrototype = builtins._internal->m_DatePrototype;
     605    m_RegExpPrototype = builtins._internal->m_RegExpPrototype;
     606    m_ErrorPrototype = builtins._internal->m_ErrorPrototype;
     607   
     608    m_EvalError = builtins._internal->m_EvalError;
     609    m_RangeError = builtins._internal->m_RangeError;
     610    m_ReferenceError = builtins._internal->m_ReferenceError;
     611    m_SyntaxError = builtins._internal->m_SyntaxError;
     612    m_TypeError = builtins._internal->m_TypeError;
     613    m_UriError = builtins._internal->m_UriError;
     614   
     615    m_EvalErrorPrototype = builtins._internal->m_EvalErrorPrototype;
     616    m_RangeErrorPrototype = builtins._internal->m_RangeErrorPrototype;
     617    m_ReferenceErrorPrototype = builtins._internal->m_ReferenceErrorPrototype;
     618    m_SyntaxErrorPrototype = builtins._internal->m_SyntaxErrorPrototype;
     619    m_TypeErrorPrototype = builtins._internal->m_TypeErrorPrototype;
     620    m_UriErrorPrototype = builtins._internal->m_UriErrorPrototype;
    327621}
    328622
     
    337631}
    338632
    339 Interpreter *ExecState::lexicalInterpreter() const
    340 {
    341   if (!m_context)
    342     return dynamicInterpreter();
    343 
    344   InterpreterImp *result = InterpreterImp::interpreterWithGlobalObject(m_context->scopeChain().bottom());
    345 
    346   if (!result)
    347     return dynamicInterpreter();
    348 
    349   return result->interpreter();
    350 }
    351 
    352 }
     633}
Note: See TracChangeset for help on using the changeset viewer.