Changeset 28468 in webkit


Ignore:
Timestamp:
Dec 5, 2007 6:31:41 PM (16 years ago)
Author:
ggaren@apple.com
Message:

JavaScriptCore:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and
functions accessing data members from Interpreter to JSGlobalObject.
Changed Interpreter member functions to static functions.


This resolves a bug in global object bootstrapping, where the global
ExecState could be used when uninitialized.


This is a big change, but it's mostly code motion and renaming.


Layout and JS tests, and testjsglue and testapi, pass. SunSpider reports
a .7% regression, but Shark sees no difference related to this patch,
and SunSpider reported a .7% speedup from an earlier step in this
refactoring, so I think it's fair to call that a wash.

JavaScriptGlue:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject. Replaced JSInterpreter
subclass with JSGlobalObject subclass.


  • JSRun.cpp: (JSRun::JSRun): (JSRun::Evaluate): (JSRun::CheckSyntax):
  • JSRun.h: (JSGlueGlobalObject::JSGlueGlobalObject):
  • JSUtils.cpp: (KJSValueToCFTypeInternal):
  • JSValueWrapper.cpp: (getThreadGlobalExecState):

WebCore:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject. Changed Interpreter
member functions to static functions. Same for the subclass,
ScriptInterpreter.


This is a big change, but it's mostly code motion and renaming.

WebKit/mac:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject.


  • WebView/WebFrame.mm: (-[WebFrame _attachScriptDebugger]):

WebKit/win:

Reviewed by Darin Adler.

Third step in refactoring JSGlobalObject: Moved data members and data
member access from Interpreter to JSGlobalObject.


  • WebFrame.cpp: (WebFrame::globalContext): (WebFrame::attachScriptDebugger): (WebFrame::windowObjectCleared):
  • WebScriptDebugger.cpp: (WebScriptDebugger::WebScriptDebugger):
Location:
trunk
Files:
5 added
109 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSBase.cpp

    r27730 r28468  
    2626
    2727#include "config.h"
    28 
    29 #include <wtf/Platform.h>
    3028#include "JSBase.h"
    3129
    3230#include "APICast.h"
    33 
    3431#include <kjs/ExecState.h>
     32#include <kjs/JSGlobalObject.h>
     33#include <kjs/JSLock.h>
    3534#include <kjs/interpreter.h>
    36 #include <kjs/JSLock.h>
    3735#include <kjs/object.h>
    3836
     
    4745    UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
    4846    // Interpreter::evaluate sets "this" to the global object if it is NULL
    49     Completion completion = exec->dynamicInterpreter()->evaluate(UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
     47    Completion completion = Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
    5048
    5149    if (completion.complType() == Throw) {
     
    6967    UString::Rep* scriptRep = toJS(script);
    7068    UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
    71     Completion completion = exec->dynamicInterpreter()->checkSyntax(UString(sourceURLRep), startingLineNumber, UString(scriptRep));
     69    Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep));
    7270    if (completion.complType() == Throw) {
    7371        if (exception)
  • trunk/JavaScriptCore/API/JSCallbackConstructor.cpp

    r27730 r28468  
    11// -*- mode: c++; c-basic-offset: 4 -*-
    22/*
    3  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    2626
    2727#include "config.h"
    28 
    29 #include <wtf/Platform.h>
    3028#include "JSCallbackConstructor.h"
    3129
    3230#include "APICast.h"
     31#include <kjs/JSGlobalObject.h>
     32#include <kjs/object_object.h>
    3333#include <wtf/Vector.h>
    3434
     
    3838
    3939JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
    40     : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())
     40    : JSObject(exec->lexicalGlobalObject()->objectPrototype())
    4141    , m_class(jsClass)
    4242    , m_callback(callback)
  • trunk/JavaScriptCore/API/JSCallbackFunction.cpp

    r27730 r28468  
    3232#include "function.h"
    3333#include "function_object.h"
     34#include <kjs/JSGlobalObject.h>
    3435#include <wtf/Vector.h>
    3536
     
    3940
    4041JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name)
    41     : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
     42    : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name)
    4243    , m_callback(callback)
    4344{
  • trunk/JavaScriptCore/API/JSCallbackObject.h

    r27885 r28468  
    4040public:
    4141    JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype, void* data);
    42     JSCallbackObject(JSClassRef, JSValue* prototype, void* data);
     42    JSCallbackObject(JSClassRef);
    4343    virtual ~JSCallbackObject();
    44 
    45     void init(ExecState*);
    4644
    4745    virtual UString className() const;
     
    7775
    7876    bool inherits(JSClassRef) const;
    79 
     77   
    8078private:
    81     JSCallbackObject(); // prevent default construction
    82     JSCallbackObject(const JSCallbackObject&);
    83 
     79    void init(ExecState*);
    8480   
    8581    static JSValue* cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
  • trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r27885 r28468  
    4848}
    4949
    50 template <class Base>
    51 JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass, JSValue* prototype, void* data)
    52     : Base(prototype)
    53     , m_privateData(data)
     50// Global object constructor. FIXME: Move this into a JSGlobalCallbackObject subclass.
     51template <class Base>
     52JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass)
     53    : m_privateData(0)
    5454    , m_class(JSClassRetain(jsClass))
    5555{
     56    ASSERT(Base::isGlobalObject());
     57    init(static_cast<JSGlobalObject*>(this)->globalExec());
    5658}
    5759
  • trunk/JavaScriptCore/API/JSClassRef.cpp

    r27763 r28468  
    11// -*- mode: c++; c-basic-offset: 4 -*-
    22/*
    3  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
     3 * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    2626
    2727#include "config.h"
    28 #include <wtf/Platform.h>
     28#include "JSClassRef.h"
     29
    2930#include "APICast.h"
    3031#include "JSCallbackObject.h"
    31 #include "JSClassRef.h"
    3232#include "JSObjectRef.h"
    33 #include "identifier.h"
     33#include <kjs/JSGlobalObject.h>
     34#include <kjs/identifier.h>
     35#include <kjs/object_object.h>
    3436
    3537using namespace KJS;
     
    156158            parentPrototype = parentClass->prototype(ctx); // can be null
    157159        if (!parentPrototype)
    158             parentPrototype = exec->dynamicInterpreter()->builtinObjectPrototype();
     160            parentPrototype = exec->dynamicGlobalObject()->objectPrototype();
    159161        cachedPrototype = new JSCallbackObject<JSObject>(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction
    160162    }
  • trunk/JavaScriptCore/API/JSClassRef.h

    r27776 r28468  
    3434#include <kjs/ustring.h>
    3535#include <wtf/HashMap.h>
     36#include <wtf/RefCounted.h>
    3637
    3738struct StaticValueEntry {
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r28328 r28468  
    3333#include "JSGlobalObject.h"
    3434#include "completion.h"
    35 #include "interpreter.h"
    3635#include "object.h"
    3736#include <wtf/Platform.h>
     
    4342    JSLock lock;
    4443
    45     Interpreter* interpreter = new Interpreter();
    46     ExecState* globalExec = &interpreter->m_globalExec;
    47     JSGlobalContextRef ctx = toGlobalRef(globalExec);
     44    if (!globalObjectClass) {
     45        JSGlobalObject* globalObject = new JSGlobalObject;
     46        return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
     47    }
    4848
    49      if (globalObjectClass) {
    50         // FIXME: ctx is not fully initialized yet, so this call to prototype() might return an object with a garbage pointer in its prototype chain.
    51         JSObject* prototype = globalObjectClass->prototype(ctx);
    52         JSCallbackObject<JSGlobalObject>* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass, prototype ? prototype : jsNull(), 0);
    53         interpreter->setGlobalObject(globalObject);
    54         globalObject->init(globalExec);
    55     } else
    56         interpreter->setGlobalObject(new JSGlobalObject());
    57 
     49    JSGlobalObject* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass);
     50    JSGlobalContextRef ctx = toGlobalRef(globalObject->globalExec());
     51    JSValue* prototype = globalObjectClass->prototype(ctx);
     52    if (!prototype)
     53        prototype = jsNull();
     54    globalObject->reset(prototype);
    5855    return JSGlobalContextRetain(ctx);
    5956}
     
    6360    JSLock lock;
    6461    ExecState* exec = toJS(ctx);
    65     gcProtect(exec->dynamicInterpreter()->globalObject());
     62    gcProtect(exec->dynamicGlobalObject());
    6663    return ctx;
    6764}
     
    7168    JSLock lock;
    7269    ExecState* exec = toJS(ctx);
    73     gcUnprotect(exec->dynamicInterpreter()->globalObject());
     70    gcUnprotect(exec->dynamicGlobalObject());
    7471}
    7572
     
    7774{
    7875    ExecState* exec = toJS(ctx);
    79     return toRef(exec->dynamicInterpreter()->globalObject());
     76    return toRef(exec->dynamicGlobalObject());
    8077}
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r27763 r28468  
    3737#include "JSGlobalObject.h"
    3838
     39#include "PropertyNameArray.h"
     40#include "function.h"
     41#include "function_object.h"
    3942#include "identifier.h"
    40 #include "function.h"
    4143#include "internal.h"
    4244#include "object.h"
    43 #include "PropertyNameArray.h"
     45#include "object_object.h"
    4446
    4547using namespace KJS;
     
    7476
    7577    if (!jsClass)
    76         return toRef(new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())); // slightly more efficient
     78        return toRef(new JSObject(exec->lexicalGlobalObject()->objectPrototype())); // slightly more efficient
    7779
    7880    JSValue* jsPrototype = jsClass->prototype(ctx);
    7981    if (!jsPrototype)
    80         jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype();
     82        jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
    8183
    8284    return toRef(new JSCallbackObject<JSObject>(exec, jsClass, jsPrototype, data));
     
    99101    JSValue* jsPrototype = jsClass
    100102        ? jsClass->prototype(ctx)
    101         : exec->dynamicInterpreter()->builtinObjectPrototype();
     103        : exec->dynamicGlobalObject()->objectPrototype();
    102104   
    103105    JSObject* constructor = new JSCallbackConstructor(exec, jsClass, callAsConstructor);
     
    121123    args.append(jsString(UString(bodyRep)));
    122124
    123     JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
     125    JSObject* result = exec->dynamicGlobalObject()->functionConstructor()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
    124126    if (exec->hadException()) {
    125127        if (exception)
     
    275277
    276278    if (!jsThisObject)
    277         jsThisObject = exec->dynamicInterpreter()->globalObject();
     279        jsThisObject = exec->dynamicGlobalObject();
    278280   
    279281    List argList;
  • trunk/JavaScriptCore/ChangeLog

    r28463 r28468  
     12007-12-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Third step in refactoring JSGlobalObject: Moved data members and
     6        functions accessing data members from Interpreter to JSGlobalObject.
     7        Changed Interpreter member functions to static functions.
     8       
     9        This resolves a bug in global object bootstrapping, where the global
     10        ExecState could be used when uninitialized.
     11       
     12        This is a big change, but it's mostly code motion and renaming.
     13       
     14        Layout and JS tests, and testjsglue and testapi, pass. SunSpider reports
     15        a .7% regression, but Shark sees no difference related to this patch,
     16        and SunSpider reported a .7% speedup from an earlier step in this
     17        refactoring, so I think it's fair to call that a wash.
     18
    1192007-12-05  Geoffrey Garen  <ggaren@apple.com>
    220
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r28328 r28468  
    113113__ZN3KJS10throwErrorEPNS_9ExecStateENS_9ErrorTypeE
    114114__ZN3KJS10throwErrorEPNS_9ExecStateENS_9ErrorTypeEPKc
    115 __ZN3KJS11Interpreter11checkSyntaxERKNS_7UStringEiPKNS_5UCharEi
    116 __ZN3KJS11Interpreter11checkSyntaxERKNS_7UStringEiS3_
    117 __ZN3KJS11Interpreter15restoreBuiltinsERKNS_13SavedBuiltinsE
    118 __ZN3KJS11Interpreter15setGlobalObjectEPNS_14JSGlobalObjectE
    119 __ZN3KJS11Interpreter16stopTimeoutCheckEv
    120 __ZN3KJS11Interpreter17startTimeoutCheckEv
     115__ZN3KJS11Interpreter11checkSyntaxEPNS_9ExecStateERKNS_7UStringEiPKNS_5UCharEi
    121116__ZN3KJS11Interpreter21shouldPrintExceptionsEv
    122117__ZN3KJS11Interpreter24setShouldPrintExceptionsEb
    123 __ZN3KJS11Interpreter27resetGlobalObjectPropertiesEv
    124 __ZN3KJS11Interpreter6s_hookE
    125 __ZN3KJS11Interpreter8evaluateERKNS_7UStringEiPKNS_5UCharEiPNS_7JSValueE
    126 __ZN3KJS11Interpreter8evaluateERKNS_7UStringEiS3_PNS_7JSValueE
    127 __ZN3KJS11InterpreterC1Ev
    128 __ZN3KJS11InterpreterC2Ev
    129 __ZN3KJS11InterpreterD1Ev
    130 __ZN3KJS11InterpreterD2Ev
     118__ZN3KJS11Interpreter8evaluateEPNS_9ExecStateERKNS_7UStringEiPKNS_5UCharEiPNS_7JSValueE
     119__ZN3KJS11Interpreter8evaluateEPNS_9ExecStateERKNS_7UStringEiS5_PNS_7JSValueE
    131120__ZN3KJS11JSImmediate4typeEPKNS_7JSValueE
    132121__ZN3KJS11JSImmediate8toObjectEPKNS_7JSValueEPNS_9ExecStateE
     
    140129__ZN3KJS12jsNumberCellEd
    141130__ZN3KJS13ArrayInstance4infoE
    142 __ZN3KJS13SavedBuiltinsC1Ev
    143 __ZN3KJS13SavedBuiltinsD1Ev
    144131__ZN3KJS13jsOwnedStringERKNS_7UStringE
    145132__ZN3KJS14JSGlobalObject10globalExecEv
     133__ZN3KJS14JSGlobalObject15restoreBuiltinsERKNS_13SavedBuiltinsE
     134__ZN3KJS14JSGlobalObject16stopTimeoutCheckEv
     135__ZN3KJS14JSGlobalObject17startTimeoutCheckEv
     136__ZN3KJS14JSGlobalObject4initEv
    146137__ZN3KJS14JSGlobalObject4markEv
     138__ZN3KJS14JSGlobalObject5resetEPNS_7JSValueE
     139__ZN3KJS14JSGlobalObject6s_headE
     140__ZN3KJS14JSGlobalObjectD2Ev
    147141__ZN3KJS14StringInstance14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
    148142__ZN3KJS14StringInstance16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE
     
    193187__ZN3KJS8Bindings23convertObjcValueToValueEPNS_9ExecStateEPvNS0_13ObjcValueTypeEPNS0_10RootObjectE
    194188__ZN3KJS8Bindings23convertValueToObjcValueEPNS_9ExecStateEPNS_7JSValueENS0_13ObjcValueTypeE
     189__ZN3KJS8Bindings24findProtectingRootObjectEPNS_8JSObjectE
    195190__ZN3KJS8Bindings8Instance18didExecuteFunctionEv
    196191__ZN3KJS8Bindings8Instance21setDidExecuteFunctionEPFvPNS_9ExecStateEPNS_8JSObjectEE
    197192__ZN3KJS8Bindings8Instance32createBindingForLanguageInstanceENS1_15BindingLanguageEPvN3WTF10PassRefPtrINS0_10RootObjectEEE
    198193__ZN3KJS8Debugger12sourceUnusedEPNS_9ExecStateEi
    199 __ZN3KJS8Debugger6attachEPNS_11InterpreterE
     194__ZN3KJS8Debugger6attachEPNS_14JSGlobalObjectE
    200195__ZN3KJS8Debugger9exceptionEPNS_9ExecStateEiiPNS_7JSValueE
    201196__ZN3KJS8DebuggerC2Ev
     
    220215__ZN3KJS8jsStringEPKc
    221216__ZN3KJS8jsStringERKNS_7UStringE
    222 __ZN3KJS9Collector15numInterpretersEv
    223217__ZN3KJS9Collector15recordExtraCostEm
     218__ZN3KJS9Collector16numGlobalObjectsEv
    224219__ZN3KJS9Collector19numProtectedObjectsEv
    225220__ZN3KJS9Collector20rootObjectTypeCountsEv
     
    229224__ZN3KJS9Collector7protectEPNS_7JSValueE
    230225__ZN3KJS9Collector9unprotectEPNS_7JSValueE
     226__ZN3KJS9ExecStateD1Ev
    231227__ZN3KJSeqERKNS_7UStringEPKc
    232228__ZN3WTF10fastCallocEmm
     
    235231__ZN3WTF16fastZeroedMallocEm
    236232__ZN3WTF8fastFreeEPv
    237 __ZNK3KJS11Interpreter12builtinArrayEv
    238 __ZNK3KJS11Interpreter12globalObjectEv
    239 __ZNK3KJS11Interpreter12saveBuiltinsERNS_13SavedBuiltinsE
    240 __ZNK3KJS11Interpreter15builtinFunctionEv
    241 __ZNK3KJS11Interpreter22builtinObjectPrototypeEv
    242 __ZNK3KJS11Interpreter22builtinStringPrototypeEv
    243 __ZNK3KJS11Interpreter24builtinFunctionPrototypeEv
    244233__ZNK3KJS11PropertyMap3getERKNS_10IdentifierE
    245234__ZNK3KJS11PropertyMap4saveERNS_15SavedPropertiesE
    246235__ZNK3KJS12DateInstance7getTimeERdRi
    247236__ZNK3KJS13ArrayInstance7getItemEj
     237__ZNK3KJS14JSGlobalObject12saveBuiltinsERNS_13SavedBuiltinsE
    248238__ZNK3KJS19InternalFunctionImp14implementsCallEv
    249239__ZNK3KJS19InternalFunctionImp21implementsHasInstanceEv
     
    267257__ZNK3KJS7UString8toUInt32EPb
    268258__ZNK3KJS7UString8toUInt32EPbb
    269 __ZNK3KJS8Bindings10RootObject11interpreterEv
    270259__ZNK3KJS8Bindings10RootObject12globalObjectEv
    271260__ZNK3KJS8Bindings8Instance10rootObjectEv
     
    285274__ZNK3KJS8JSObject9classNameEv
    286275__ZNK3KJS8JSObject9toBooleanEPNS_9ExecStateE
    287 __ZNK3KJS9ExecState18lexicalInterpreterEv
     276__ZNK3KJS9ExecState19lexicalGlobalObjectEv
    288277__ZTVN3KJS14JSGlobalObjectE
    289278__ZTVN3KJS14StringInstanceE
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r28434 r28468  
    166166                932F5B700822A1C700736975 /* runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B0870056468730080E486 /* runtime.h */; settings = {ATTRIBUTES = (Private, ); }; };
    167167                932F5B710822A1C700736975 /* jni_runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = 511B0876056468BB0080E486 /* jni_runtime.h */; };
    168                 932F5B720822A1C700736975 /* bool_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 704FD35305697E6D003DBED9 /* bool_object.h */; };
     168                932F5B720822A1C700736975 /* bool_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 704FD35305697E6D003DBED9 /* bool_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
    169169                932F5B730822A1C700736975 /* runtime_object.h in Headers */ = {isa = PBXBuildFile; fileRef = 70B16A270569A10900DB756D /* runtime_object.h */; settings = {ATTRIBUTES = (Private, ); }; };
    170170                932F5B740822A1C700736975 /* jni_class.h in Headers */ = {isa = PBXBuildFile; fileRef = 517D52DD056BF2F6003851BD /* jni_class.h */; };
  • trunk/JavaScriptCore/bindings/NP_jsobject.cpp

    r28328 r28468  
    3333#include "PropertyNameArray.h"
    3434#include "c_utility.h"
     35#include "interpreter.h"
    3536#include "npruntime_impl.h"
    3637#include "npruntime_priv.h"
     
    128129        List argList;
    129130        getListFromVariantArgs(exec, args, argCount, rootObject, argList);
    130         rootObject->interpreter()->startTimeoutCheck();
     131        rootObject->globalObject()->startTimeoutCheck();
    131132        JSValue *resultV = funcImp->call (exec, funcImp, argList);
    132         rootObject->interpreter()->stopTimeoutCheck();
     133        rootObject->globalObject()->stopTimeoutCheck();
    133134
    134135        // Convert and return the result of the function call.
     
    184185        List argList;
    185186        getListFromVariantArgs(exec, args, argCount, rootObject, argList);
    186         rootObject->interpreter()->startTimeoutCheck();
     187        rootObject->globalObject()->startTimeoutCheck();
    187188        JSValue *resultV = funcImp->call (exec, thisObj, argList);
    188         rootObject->interpreter()->stopTimeoutCheck();
     189        rootObject->globalObject()->stopTimeoutCheck();
    189190
    190191        // Convert and return the result of the function call.
     
    218219        unsigned int UTF16Length;
    219220        convertNPStringToUTF16(s, &scriptString, &UTF16Length); // requires free() of returned memory
    220         rootObject->interpreter()->startTimeoutCheck();
    221         Completion completion = rootObject->interpreter()->evaluate(UString(), 0, UString((const UChar*)scriptString,UTF16Length));
    222         rootObject->interpreter()->stopTimeoutCheck();
     221        rootObject->globalObject()->startTimeoutCheck();
     222        Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), UString(), 0, UString(reinterpret_cast<const UChar*>(scriptString), UTF16Length));
     223        rootObject->globalObject()->stopTimeoutCheck();
    223224        ComplType type = completion.complType();
    224225       
  • trunk/JavaScriptCore/bindings/c/c_utility.cpp

    r27810 r28468  
    116116            }
    117117        } else {
    118             Interpreter* originInterpreter = exec->dynamicInterpreter();
    119             RootObject* originRootObject = findRootObject(originInterpreter);
     118            JSGlobalObject* originGlobalObject = exec->dynamicGlobalObject();
     119            RootObject* originRootObject = findRootObject(originGlobalObject);
    120120
    121             Interpreter* interpreter = 0;
     121            JSGlobalObject* globalObject = 0;
    122122            if (object->isGlobalObject())
    123                 interpreter = static_cast<JSGlobalObject*>(object)->interpreter();
     123                globalObject = static_cast<JSGlobalObject*>(object);
    124124
    125             if (!interpreter)
    126                 interpreter = originInterpreter;
     125            if (!globalObject)
     126                globalObject = originGlobalObject;
    127127
    128             RootObject* rootObject = findRootObject(interpreter);
     128            RootObject* rootObject = findRootObject(globalObject);
    129129            if (rootObject) {
    130130                NPObject* npObject = _NPN_CreateScriptObject(0, object, originRootObject, rootObject);
  • trunk/JavaScriptCore/bindings/jni/jni_jsobject.cpp

    r28328 r28468  
    8080        else {
    8181            JSObject *imp = jlong_to_impptr(nativeHandle);
    82             if (!findRootObject(imp)) {
     82            if (!findProtectingRootObject(imp)) {
    8383                fprintf (stderr, "%s:%d:  Attempt to access JavaScript from destroyed applet, type %d.\n", __FILE__, __LINE__, context->type);
    8484                return result;
     
    148148   
    149149    ASSERT(_imp);
    150     _rootObject = findRootObject(_imp);
     150    _rootObject = findProtectingRootObject(_imp);
    151151    ASSERT(_rootObject);
    152152}
     
    179179    List argList;
    180180    getListFromJArray(args, argList);
    181     rootObject->interpreter()->startTimeoutCheck();
     181    rootObject->globalObject()->startTimeoutCheck();
    182182    JSValue *result = funcImp->call(exec, thisObj, argList);
    183     rootObject->interpreter()->stopTimeoutCheck();
     183    rootObject->globalObject()->stopTimeoutCheck();
    184184
    185185    return convertValueToJObject(result);
     
    199199        return 0;
    200200
    201     rootObject->interpreter()->startTimeoutCheck();
    202     Completion completion = rootObject->interpreter()->evaluate(UString(), 0, JavaString(script).ustring(),thisObj);
    203     rootObject->interpreter()->stopTimeoutCheck();
     201    rootObject->globalObject()->startTimeoutCheck();
     202    Completion completion = Interpreter::evaluate(rootObject->globalObject()->globalExec(), UString(), 0, JavaString(script).ustring(),thisObj);
     203    rootObject->globalObject()->stopTimeoutCheck();
    204204    ComplType type = completion.complType();
    205205   
     
    327327        return nativeHandle;
    328328
    329     if (findRootObject(jlong_to_impptr(nativeHandle)))
     329    if (findProtectingRootObject(jlong_to_impptr(nativeHandle)))
    330330        return nativeHandle;
    331331
     
    340340    // JavaJSObject::convertValueToJObject().
    341341    if (rootObject) {
    342         JSObject* globalObject = rootObject->interpreter()->globalObject();
     342        JSObject* globalObject = rootObject->globalObject();
    343343        // We call gcProtect here to get the object into the root object's "protect set" which
    344344        // is used to test if a native handle is valid as well as getting the root object given the handle.
  • trunk/JavaScriptCore/bindings/jni/jni_utility.cpp

    r24059 r28468  
    2727#include "jni_utility.h"
    2828
    29 #include "interpreter.h"
    3029#include "list.h"
    3130#include "jni_runtime.h"
  • trunk/JavaScriptCore/bindings/objc/objc_runtime.mm

    r27413 r28468  
    124124static id convertValueToObjcObject(ExecState* exec, JSValue* value)
    125125{
    126     RefPtr<RootObject> rootObject = findRootObject(exec->dynamicInterpreter());
     126    RefPtr<RootObject> rootObject = findRootObject(exec->dynamicGlobalObject());
    127127    if (!rootObject)
    128128        return nil;
  • trunk/JavaScriptCore/bindings/objc/objc_utility.mm

    r27022 r28468  
    138138            JSLock lock;
    139139           
    140             Interpreter *originInterpreter = exec->dynamicInterpreter();
    141             RootObject* originRootObject = findRootObject(originInterpreter);
    142 
    143             Interpreter *interpreter = 0;
     140            JSGlobalObject *originGlobalObject = exec->dynamicGlobalObject();
     141            RootObject* originRootObject = findRootObject(originGlobalObject);
     142
     143            JSGlobalObject* globalObject = 0;
    144144            if (value->isObject() && static_cast<JSObject*>(value)->isGlobalObject())
    145                 interpreter = static_cast<JSGlobalObject*>(value)->interpreter();
    146 
    147             if (!interpreter)
    148                 interpreter = originInterpreter;
     145                globalObject = static_cast<JSGlobalObject*>(value);
     146
     147            if (!globalObject)
     148                globalObject = originGlobalObject;
    149149               
    150             RootObject* rootObject = findRootObject(interpreter);
     150            RootObject* rootObject = findRootObject(globalObject);
    151151            result.objectValue =  rootObject
    152152                ? [webScriptObjectClass() _convertValueToObjcValue:value originRootObject:originRootObject rootObject:rootObject]
  • trunk/JavaScriptCore/bindings/runtime_array.cpp

    r27413 r28468  
    2727#include "runtime_array.h"
    2828
     29#include "JSGlobalObject.h"
     30#include "array_object.h"
     31
    2932using namespace KJS;
    3033
     
    3235
    3336RuntimeArray::RuntimeArray(ExecState *exec, Bindings::Array *a)
    34     : JSObject(exec->lexicalInterpreter()->builtinArrayPrototype())
     37    : JSObject(exec->lexicalGlobalObject()->arrayPrototype())
    3538    , _array(a)
    3639{
  • trunk/JavaScriptCore/bindings/runtime_method.cpp

    r27097 r28468  
    2828
    2929#include "ExecState.h"
     30#include "JSGlobalObject.h"
    3031#include "runtime_object.h"
    3132#include "function_object.h"
     
    3536
    3637RuntimeMethod::RuntimeMethod(ExecState *exec, const Identifier &ident, Bindings::MethodList &m)
    37     : InternalFunctionImp (static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), ident)
     38    : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), ident)
    3839    , _methodList(new MethodList(m))
    3940{
  • trunk/JavaScriptCore/bindings/runtime_root.cpp

    r28328 r28468  
    5151// fix them by adding a JSObject to RootObject dictionary.
    5252
    53 RootObject* findRootObject(JSObject* jsObject)
     53RootObject* findProtectingRootObject(JSObject* jsObject)
    5454{
    5555    RootObjectSet::const_iterator end = rootObjectSet()->end();
     
    6161}
    6262
    63 RootObject* findRootObject(Interpreter* interpreter)
     63RootObject* findRootObject(JSGlobalObject* globalObject)
    6464{
    6565    RootObjectSet::const_iterator end = rootObjectSet()->end();
    6666    for (RootObjectSet::const_iterator it = rootObjectSet()->begin(); it != end; ++it) {
    67         if ((*it)->interpreter() == interpreter)
     67        if ((*it)->globalObject() == globalObject)
    6868            return *it;
    6969    }
     
    281281}
    282282
    283 Interpreter* RootObject::interpreter() const
    284 {
    285     ASSERT(m_isValid);
    286     return m_globalObject->interpreter();
    287 }
    288 
    289283JSGlobalObject* RootObject::globalObject() const
    290284{
  • trunk/JavaScriptCore/bindings/runtime_root.h

    r28328 r28468  
    4949typedef HashCountedSet<JSObject*> ProtectCountSet;
    5050
    51 extern RootObject* findRootObject(JSObject*);
    52 extern RootObject* findRootObject(Interpreter*);
     51extern RootObject* findProtectingRootObject(JSObject*);
     52extern RootObject* findRootObject(JSGlobalObject*);
    5353
    5454class RootObject : public RefCounted<RootObject> {
     
    6868
    6969    const void* nativeHandle() const;
    70     Interpreter* interpreter() const;
    7170    JSGlobalObject* globalObject() const;
    7271
  • trunk/JavaScriptCore/kjs/ExecState.cpp

    r28110 r28468  
    3232namespace KJS {
    3333
    34 
    3534// ECMA 10.2
    36 ExecState::ExecState(Interpreter* interpreter, JSGlobalObject* globalObject, JSObject* thisV,
    37                      FunctionBodyNode* currentBody, CodeType type, ExecState* callingExec,
     35ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisV,
     36                     FunctionBodyNode* currentBody, CodeType type, ExecState* callingExec, ExecState* currentExec,
    3837                     FunctionImp* func, const List* args)
    39     : m_interpreter(interpreter)
     38    : m_globalObject(globalObject)
    4039    , m_exception(0)
    4140    , m_propertyNames(CommonIdentifiers::shared())
    42     , m_savedExecState(interpreter->currentExec())
     41    , m_callingExec(callingExec)
     42    , m_savedExec(currentExec)
    4343    , m_currentBody(currentBody)
    4444    , m_function(func)
     
    4646    , m_iterationDepth(0)
    4747    , m_switchDepth(0)
     48    , m_codeType(type)
    4849{
    49     m_codeType = type;
    50     m_callingExecState = callingExec;
    51    
    5250    // create and initialize activation object (ECMA 10.1.6)
    5351    if (type == FunctionCode) {
     
    6260    switch(type) {
    6361    case EvalCode:
    64         if (m_callingExecState) {
    65             m_scopeChain = m_callingExecState->scopeChain();
    66             m_variable = m_callingExecState->variableObject();
    67             m_thisVal = m_callingExecState->thisValue();
     62        if (m_callingExec) {
     63            m_scopeChain = m_callingExec->scopeChain();
     64            m_variable = m_callingExec->variableObject();
     65            m_thisVal = m_callingExec->thisValue();
    6866            break;
    6967        } // else same as GlobalCode
    7068    case GlobalCode:
    71         if (globalObject)
    72             setGlobalObject(globalObject);
     69        m_scopeChain.push(globalObject);
     70        m_thisVal = globalObject;
    7371        break;
    7472    case FunctionCode:
     
    8179
    8280    if (currentBody)
    83         m_interpreter->setCurrentExec(this);
     81        m_globalObject->setCurrentExec(this);
    8482}
    8583
    8684ExecState::~ExecState()
    8785{
    88     m_interpreter->setCurrentExec(m_savedExecState);
     86    m_globalObject->setCurrentExec(m_savedExec);
    8987}
    9088
    9189void ExecState::mark()
    9290{
    93     for (ExecState* exec = this; exec; exec = exec->m_callingExecState)
     91    for (ExecState* exec = this; exec; exec = exec->m_callingExec)
    9492        exec->m_scopeChain.mark();
    9593}
    9694
    97 void ExecState::setGlobalObject(JSGlobalObject* globalObject)
    98 {
    99     m_scopeChain.clear();
    100     m_scopeChain.push(globalObject);
    101     m_thisVal = static_cast<JSObject*>(globalObject);
    102 }
    103 
    104 Interpreter* ExecState::lexicalInterpreter() const
     95JSGlobalObject* ExecState::lexicalGlobalObject() const
    10596{
    10697    if (scopeChain().isEmpty())
    107         return dynamicInterpreter();
     98        return dynamicGlobalObject();
    10899   
    109100    JSObject* object = scopeChain().bottom();
    110101    if (object && object->isGlobalObject())
    111         return static_cast<JSGlobalObject*>(object)->interpreter();
     102        return static_cast<JSGlobalObject*>(object);
    112103
    113     return dynamicInterpreter();
     104    return dynamicGlobalObject();
    114105}
    115106   
  • trunk/JavaScriptCore/kjs/ExecState.h

    r28110 r28468  
    5757    public:
    5858        /**
    59          * Returns the interpreter currently running code
     59         * Returns the global object that was in scope when the current script started executing.
    6060         */
    61         Interpreter* dynamicInterpreter() const { return m_interpreter; }
     61        JSGlobalObject* dynamicGlobalObject() const { return m_globalObject; }
    6262       
    6363        /**
    64          * Returns the interpreter associated with the current scope's global object
     64         * Returns the global object that was in scope when the current body of code was defined.
    6565         */
    66         Interpreter* lexicalInterpreter() const;
     66        JSGlobalObject* lexicalGlobalObject() const;
    6767               
    6868        void setException(JSValue* e) { m_exception = e; }
     
    7979        JSObject* thisValue() const { return m_thisVal; }
    8080       
    81         ExecState* callingExecState() { return m_callingExecState; }
     81        ExecState* callingExecState() { return m_callingExec; }
    8282       
    8383        JSObject* activationObject() { return m_activation; }
     
    9999        bool inSwitch() const { return (m_switchDepth > 0); }
    100100
    101         void setGlobalObject(JSGlobalObject*);
    102        
    103101        void mark();
    104102       
     
    110108        void updateLocalStorage();
    111109   
    112     private:
    113         ExecState(Interpreter* interp, JSGlobalObject* glob, JSObject* thisV,
     110    public:
     111        ExecState(JSGlobalObject* glob, JSObject* thisV,
    114112                  FunctionBodyNode* currentBody, CodeType type = GlobalCode,
    115                   ExecState* callingExecState = 0, FunctionImp* function = 0, const List* args = 0);
     113                  ExecState* callingExecState = 0, ExecState* currentExec = 0,
     114                  FunctionImp* function = 0, const List* args = 0);
    116115        ~ExecState();
    117116
     117    private:
    118118        // ExecStates are always stack-allocated, and the garbage collector
    119119        // marks the stack, so we don't need to protect the objects below from GC.
    120120
    121         Interpreter* m_interpreter;
     121        JSGlobalObject* m_globalObject;
    122122        JSValue* m_exception;
    123123        CommonIdentifiers* m_propertyNames;
    124124
    125         ExecState* m_callingExecState;
    126         ExecState* m_savedExecState;
     125        ExecState* m_callingExec;
     126        ExecState* m_savedExec;
    127127        FunctionBodyNode* m_currentBody;
    128128       
  • trunk/JavaScriptCore/kjs/JSGlobalObject.cpp

    r28328 r28468  
    3030#include "JSGlobalObject.h"
    3131
    32 #include "object_object.h"
    33 #include "function_object.h"
     32#include "SavedBuiltins.h"
    3433#include "array_object.h"
    3534#include "bool_object.h"
     35#include "date_object.h"
     36#include "debugger.h"
     37#include "error_object.h"
     38#include "function_object.h"
     39#include "math_object.h"
     40#include "number_object.h"
     41#include "object_object.h"
     42#include "regexp_object.h"
    3643#include "string_object.h"
    37 #include "number_object.h"
    38 #include "date_object.h"
    39 #include "regexp_object.h"
    40 #include "error_object.h"
    4144
    4245namespace KJS {
     46
     47// Default number of ticks before a timeout check should be done.
     48static const int initialTickCountThreshold = 255;
     49
     50// Preferred number of milliseconds between each timeout check
     51static const int preferredScriptCheckTimeInterval = 1000;
    4352
    4453static inline void markIfNeeded(JSValue* v)
     
    4756        v->mark();
    4857}
     58   
     59// Returns the current time in milliseconds
     60// It doesn't matter what "current time" is here, just as long as
     61// it's possible to measure the time difference correctly.
     62static inline unsigned getCurrentTime() {
     63#if HAVE(SYS_TIME_H)
     64    struct timeval tv;
     65    gettimeofday(&tv, 0);
     66    return tv.tv_sec * 1000 + tv.tv_usec / 1000;
     67#elif PLATFORM(QT)
     68    QDateTime t = QDateTime::currentDateTime();
     69    return t.toTime_t() * 1000 + t.time().msec();
     70#elif PLATFORM(WIN_OS)
     71    return timeGetTime();
     72#else
     73#error Platform does not have getCurrentTime function
     74#endif
     75}
     76
     77JSGlobalObject* JSGlobalObject::s_head = 0;
     78
     79JSGlobalObject::~JSGlobalObject()
     80{
     81    ASSERT(JSLock::currentThreadIsHoldingLock());
     82
     83    if (d->debugger)
     84        d->debugger->detach(this);
     85
     86    d->next->d->prev = d->prev;
     87    d->prev->d->next = d->next;
     88    s_head = d->next;
     89    if (s_head == this)
     90        s_head = 0;
     91}
     92
     93void JSGlobalObject::init()
     94{
     95    ASSERT(JSLock::currentThreadIsHoldingLock());
     96
     97    d.reset(new JSGlobalObjectData(this));
     98
     99    if (s_head) {
     100        d->prev = s_head;
     101        d->next = s_head->d->next;
     102        s_head->d->next->d->prev = this;
     103        s_head->d->next = this;
     104    } else
     105        s_head = d->next = d->prev = this;
     106
     107    d->compatMode = NativeMode;
     108
     109    resetTimeoutCheck();
     110    d->timeoutTime = 0;
     111    d->timeoutCheckCount = 0;
     112
     113    d->currentExec = 0;
     114    d->recursion = 0;
     115    d->debugger = 0;
     116   
     117    reset(prototype());
     118}
     119
     120static inline JSObject* lastInPrototypeChain(JSObject* object)
     121{
     122    JSObject* o = object;
     123    while (o->prototype()->isObject())
     124        o = static_cast<JSObject*>(o->prototype());
     125    return o;
     126}
     127
     128void JSGlobalObject::reset(JSValue* prototype)
     129{
     130    // Clear before inititalizing, to avoid marking uninitialized (dangerous) or
     131    // stale (wasteful) pointers during possible garbage collection while creating
     132    // new objects below.
     133
     134    ExecState* exec = &d->globalExec;
     135
     136    // Prototypes
     137    d->functionPrototype = 0;
     138    d->objectPrototype = 0;
     139
     140    d->arrayPrototype = 0;
     141    d->stringPrototype = 0;
     142    d->booleanPrototype = 0;
     143    d->numberPrototype = 0;
     144    d->datePrototype = 0;
     145    d->regExpPrototype = 0;
     146    d->errorPrototype = 0;
     147   
     148    d->evalErrorPrototype = 0;
     149    d->rangeErrorPrototype = 0;
     150    d->referenceErrorPrototype = 0;
     151    d->syntaxErrorPrototype = 0;
     152    d->typeErrorPrototype = 0;
     153    d->URIErrorPrototype = 0;
     154
     155    // Constructors
     156    d->objectConstructor = 0;
     157    d->functionConstructor = 0;
     158    d->arrayConstructor = 0;
     159    d->stringConstructor = 0;
     160    d->booleanConstructor = 0;
     161    d->numberConstructor = 0;
     162    d->dateConstructor = 0;
     163    d->regExpConstructor = 0;
     164    d->errorConstructor = 0;
     165   
     166    d->evalErrorConstructor = 0;
     167    d->rangeErrorConstructor = 0;
     168    d->referenceErrorConstructor = 0;
     169    d->syntaxErrorConstructor = 0;
     170    d->typeErrorConstructor = 0;
     171    d->URIErrorConstructor = 0;
     172
     173    // Prototypes
     174    d->functionPrototype = new FunctionPrototype(exec);
     175    d->objectPrototype = new ObjectPrototype(exec, d->functionPrototype);
     176    d->functionPrototype->setPrototype(d->objectPrototype);
     177
     178    d->arrayPrototype = new ArrayPrototype(exec, d->objectPrototype);
     179    d->stringPrototype = new StringPrototype(exec, d->objectPrototype);
     180    d->booleanPrototype = new BooleanPrototype(exec, d->objectPrototype, d->functionPrototype);
     181    d->numberPrototype = new NumberPrototype(exec, d->objectPrototype, d->functionPrototype);
     182    d->datePrototype = new DatePrototype(exec, d->objectPrototype);
     183    d->regExpPrototype = new RegExpPrototype(exec, d->objectPrototype, d->functionPrototype);;
     184    d->errorPrototype = new ErrorPrototype(exec, d->objectPrototype, d->functionPrototype);
     185   
     186    d->evalErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, EvalError, "EvalError", "EvalError");
     187    d->rangeErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, RangeError, "RangeError", "RangeError");
     188    d->referenceErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, ReferenceError, "ReferenceError", "ReferenceError");
     189    d->syntaxErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, SyntaxError, "SyntaxError", "SyntaxError");
     190    d->typeErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, TypeError, "TypeError", "TypeError");
     191    d->URIErrorPrototype = new NativeErrorPrototype(exec, d->errorPrototype, URIError, "URIError", "URIError");
     192
     193    // Constructors
     194    d->objectConstructor = new ObjectObjectImp(exec, d->objectPrototype, d->functionPrototype);
     195    d->functionConstructor = new FunctionObjectImp(exec, d->functionPrototype);
     196    d->arrayConstructor = new ArrayObjectImp(exec, d->functionPrototype, d->arrayPrototype);
     197    d->stringConstructor = new StringObjectImp(exec, d->functionPrototype, d->stringPrototype);
     198    d->booleanConstructor = new BooleanObjectImp(exec, d->functionPrototype, d->booleanPrototype);
     199    d->numberConstructor = new NumberObjectImp(exec, d->functionPrototype, d->numberPrototype);
     200    d->dateConstructor = new DateObjectImp(exec, d->functionPrototype, d->datePrototype);
     201    d->regExpConstructor = new RegExpObjectImp(exec, d->functionPrototype, d->regExpPrototype);
     202    d->errorConstructor = new ErrorObjectImp(exec, d->functionPrototype, d->errorPrototype);
     203   
     204    d->evalErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->evalErrorPrototype);
     205    d->rangeErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->rangeErrorPrototype);
     206    d->referenceErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->referenceErrorPrototype);
     207    d->syntaxErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->syntaxErrorPrototype);
     208    d->typeErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->typeErrorPrototype);
     209    d->URIErrorConstructor = new NativeErrorImp(exec, d->functionPrototype, d->URIErrorPrototype);
     210   
     211    d->functionPrototype->put(exec, exec->propertyNames().constructor, d->functionConstructor, DontEnum);
     212
     213    d->objectPrototype->put(exec, exec->propertyNames().constructor, d->objectConstructor, DontEnum | DontDelete | ReadOnly);
     214    d->functionPrototype->put(exec, exec->propertyNames().constructor, d->functionConstructor, DontEnum | DontDelete | ReadOnly);
     215    d->arrayPrototype->put(exec, exec->propertyNames().constructor, d->arrayConstructor, DontEnum | DontDelete | ReadOnly);
     216    d->booleanPrototype->put(exec, exec->propertyNames().constructor, d->booleanConstructor, DontEnum | DontDelete | ReadOnly);
     217    d->stringPrototype->put(exec, exec->propertyNames().constructor, d->stringConstructor, DontEnum | DontDelete | ReadOnly);
     218    d->numberPrototype->put(exec, exec->propertyNames().constructor, d->numberConstructor, DontEnum | DontDelete | ReadOnly);
     219    d->datePrototype->put(exec, exec->propertyNames().constructor, d->dateConstructor, DontEnum | DontDelete | ReadOnly);
     220    d->regExpPrototype->put(exec, exec->propertyNames().constructor, d->regExpConstructor, DontEnum | DontDelete | ReadOnly);
     221    d->errorPrototype->put(exec, exec->propertyNames().constructor, d->errorConstructor, DontEnum | DontDelete | ReadOnly);
     222    d->evalErrorPrototype->put(exec, exec->propertyNames().constructor, d->evalErrorConstructor, DontEnum | DontDelete | ReadOnly);
     223    d->rangeErrorPrototype->put(exec, exec->propertyNames().constructor, d->rangeErrorConstructor, DontEnum | DontDelete | ReadOnly);
     224    d->referenceErrorPrototype->put(exec, exec->propertyNames().constructor, d->referenceErrorConstructor, DontEnum | DontDelete | ReadOnly);
     225    d->syntaxErrorPrototype->put(exec, exec->propertyNames().constructor, d->syntaxErrorConstructor, DontEnum | DontDelete | ReadOnly);
     226    d->typeErrorPrototype->put(exec, exec->propertyNames().constructor, d->typeErrorConstructor, DontEnum | DontDelete | ReadOnly);
     227    d->URIErrorPrototype->put(exec, exec->propertyNames().constructor, d->URIErrorConstructor, DontEnum | DontDelete | ReadOnly);
     228
     229    // Set global constructors
     230
     231    // FIXME: kjs_window.cpp checks Internal/DontEnum as a performance hack, to
     232    // see that these values can be put directly without a check for override
     233    // properties.
     234
     235    // FIXME: These properties should be handled by a static hash table.
     236
     237    putDirect("Object", d->objectConstructor, DontEnum);
     238    putDirect("Function", d->functionConstructor, DontEnum);
     239    putDirect("Array", d->arrayConstructor, DontEnum);
     240    putDirect("Boolean", d->booleanConstructor, DontEnum);
     241    putDirect("String", d->stringConstructor, DontEnum);
     242    putDirect("Number", d->numberConstructor, DontEnum);
     243    putDirect("Date", d->dateConstructor, DontEnum);
     244    putDirect("RegExp", d->regExpConstructor, DontEnum);
     245    putDirect("Error", d->errorConstructor, DontEnum);
     246    putDirect("EvalError", d->evalErrorConstructor, Internal);
     247    putDirect("RangeError", d->rangeErrorConstructor, Internal);
     248    putDirect("ReferenceError", d->referenceErrorConstructor, Internal);
     249    putDirect("SyntaxError", d->syntaxErrorConstructor, Internal);
     250    putDirect("TypeError", d->typeErrorConstructor, Internal);
     251    putDirect("URIError", d->URIErrorConstructor, Internal);
     252
     253    // Set global values.
     254
     255    putDirect("Math", new MathObjectImp(exec, d->objectPrototype), DontEnum);
     256
     257    putDirect("NaN", jsNaN(), DontEnum | DontDelete);
     258    putDirect("Infinity", jsNumber(Inf), DontEnum | DontDelete);
     259    putDirect("undefined", jsUndefined(), DontEnum | DontDelete);
     260
     261    // Set global functions.
     262
     263    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
     264    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
     265    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
     266    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
     267    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
     268    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
     269    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
     270    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
     271    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
     272    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
     273    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
     274#ifndef NDEBUG
     275    putDirectFunction(new GlobalFuncImp(exec, d->functionPrototype, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
     276#endif
     277
     278    // Set prototype, and also insert the object prototype at the end of the chain.
     279
     280    setPrototype(prototype);
     281    lastInPrototypeChain(this)->setPrototype(d->objectPrototype);
     282}
     283
     284void JSGlobalObject::startTimeoutCheck()
     285{
     286    if (!d->timeoutCheckCount)
     287        resetTimeoutCheck();
     288   
     289    ++d->timeoutCheckCount;
     290}
     291
     292void JSGlobalObject::stopTimeoutCheck()
     293{
     294    --d->timeoutCheckCount;
     295}
     296
     297void JSGlobalObject::resetTimeoutCheck()
     298{
     299    d->tickCount = 0;
     300    d->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
     301    d->timeAtLastCheckTimeout = 0;
     302    d->timeExecuting = 0;
     303}
     304
     305bool JSGlobalObject::checkTimeout()
     306{   
     307    d->tickCount = 0;
     308   
     309    unsigned currentTime = getCurrentTime();
     310
     311    if (!d->timeAtLastCheckTimeout) {
     312        // Suspicious amount of looping in a script -- start timing it
     313        d->timeAtLastCheckTimeout = currentTime;
     314        return false;
     315    }
     316
     317    unsigned timeDiff = currentTime - d->timeAtLastCheckTimeout;
     318
     319    if (timeDiff == 0)
     320        timeDiff = 1;
     321   
     322    d->timeExecuting += timeDiff;
     323    d->timeAtLastCheckTimeout = currentTime;
     324   
     325    // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in
     326    // preferredScriptCheckTimeInterval
     327    d->ticksUntilNextTimeoutCheck = (unsigned)((float)preferredScriptCheckTimeInterval / timeDiff) * d->ticksUntilNextTimeoutCheck;
     328
     329    // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
     330    // preferred script check time interval.
     331    if (d->ticksUntilNextTimeoutCheck == 0)
     332        d->ticksUntilNextTimeoutCheck = initialTickCountThreshold;
     333
     334    if (d->timeoutTime && d->timeExecuting > d->timeoutTime) {
     335        if (shouldInterruptScript())
     336            return true;
     337       
     338        resetTimeoutCheck();
     339    }
     340   
     341    return false;
     342}
     343
     344void JSGlobalObject::saveBuiltins(SavedBuiltins& builtins) const
     345{
     346    if (!builtins._internal)
     347        builtins._internal = new SavedBuiltinsInternal;
     348
     349    builtins._internal->objectConstructor = d->objectConstructor;
     350    builtins._internal->functionConstructor = d->functionConstructor;
     351    builtins._internal->arrayConstructor = d->arrayConstructor;
     352    builtins._internal->booleanConstructor = d->booleanConstructor;
     353    builtins._internal->stringConstructor = d->stringConstructor;
     354    builtins._internal->numberConstructor = d->numberConstructor;
     355    builtins._internal->dateConstructor = d->dateConstructor;
     356    builtins._internal->regExpConstructor = d->regExpConstructor;
     357    builtins._internal->errorConstructor = d->errorConstructor;
     358    builtins._internal->evalErrorConstructor = d->evalErrorConstructor;
     359    builtins._internal->rangeErrorConstructor = d->rangeErrorConstructor;
     360    builtins._internal->referenceErrorConstructor = d->referenceErrorConstructor;
     361    builtins._internal->syntaxErrorConstructor = d->syntaxErrorConstructor;
     362    builtins._internal->typeErrorConstructor = d->typeErrorConstructor;
     363    builtins._internal->URIErrorConstructor = d->URIErrorConstructor;
     364   
     365    builtins._internal->objectPrototype = d->objectPrototype;
     366    builtins._internal->functionPrototype = d->functionPrototype;
     367    builtins._internal->arrayPrototype = d->arrayPrototype;
     368    builtins._internal->booleanPrototype = d->booleanPrototype;
     369    builtins._internal->stringPrototype = d->stringPrototype;
     370    builtins._internal->numberPrototype = d->numberPrototype;
     371    builtins._internal->datePrototype = d->datePrototype;
     372    builtins._internal->regExpPrototype = d->regExpPrototype;
     373    builtins._internal->errorPrototype = d->errorPrototype;
     374    builtins._internal->evalErrorPrototype = d->evalErrorPrototype;
     375    builtins._internal->rangeErrorPrototype = d->rangeErrorPrototype;
     376    builtins._internal->referenceErrorPrototype = d->referenceErrorPrototype;
     377    builtins._internal->syntaxErrorPrototype = d->syntaxErrorPrototype;
     378    builtins._internal->typeErrorPrototype = d->typeErrorPrototype;
     379    builtins._internal->URIErrorPrototype = d->URIErrorPrototype;
     380}
     381
     382void JSGlobalObject::restoreBuiltins(const SavedBuiltins& builtins)
     383{
     384    if (!builtins._internal)
     385        return;
     386
     387    d->objectConstructor = builtins._internal->objectConstructor;
     388    d->functionConstructor = builtins._internal->functionConstructor;
     389    d->arrayConstructor = builtins._internal->arrayConstructor;
     390    d->booleanConstructor = builtins._internal->booleanConstructor;
     391    d->stringConstructor = builtins._internal->stringConstructor;
     392    d->numberConstructor = builtins._internal->numberConstructor;
     393    d->dateConstructor = builtins._internal->dateConstructor;
     394    d->regExpConstructor = builtins._internal->regExpConstructor;
     395    d->errorConstructor = builtins._internal->errorConstructor;
     396    d->evalErrorConstructor = builtins._internal->evalErrorConstructor;
     397    d->rangeErrorConstructor = builtins._internal->rangeErrorConstructor;
     398    d->referenceErrorConstructor = builtins._internal->referenceErrorConstructor;
     399    d->syntaxErrorConstructor = builtins._internal->syntaxErrorConstructor;
     400    d->typeErrorConstructor = builtins._internal->typeErrorConstructor;
     401    d->URIErrorConstructor = builtins._internal->URIErrorConstructor;
     402
     403    d->objectPrototype = builtins._internal->objectPrototype;
     404    d->functionPrototype = builtins._internal->functionPrototype;
     405    d->arrayPrototype = builtins._internal->arrayPrototype;
     406    d->booleanPrototype = builtins._internal->booleanPrototype;
     407    d->stringPrototype = builtins._internal->stringPrototype;
     408    d->numberPrototype = builtins._internal->numberPrototype;
     409    d->datePrototype = builtins._internal->datePrototype;
     410    d->regExpPrototype = builtins._internal->regExpPrototype;
     411    d->errorPrototype = builtins._internal->errorPrototype;
     412    d->evalErrorPrototype = builtins._internal->evalErrorPrototype;
     413    d->rangeErrorPrototype = builtins._internal->rangeErrorPrototype;
     414    d->referenceErrorPrototype = builtins._internal->referenceErrorPrototype;
     415    d->syntaxErrorPrototype = builtins._internal->syntaxErrorPrototype;
     416    d->typeErrorPrototype = builtins._internal->typeErrorPrototype;
     417    d->URIErrorPrototype = builtins._internal->URIErrorPrototype;
     418}
    49419
    50420void JSGlobalObject::mark()
     
    52422    JSObject::mark();
    53423
    54     if (m_interpreter->m_currentExec)
    55         m_interpreter->m_currentExec->mark();
    56 
    57     markIfNeeded(m_interpreter->m_globalExec.exception());
    58 
    59     markIfNeeded(m_interpreter->m_Object);
    60     markIfNeeded(m_interpreter->m_Function);
    61     markIfNeeded(m_interpreter->m_Array);
    62     markIfNeeded(m_interpreter->m_Boolean);
    63     markIfNeeded(m_interpreter->m_String);
    64     markIfNeeded(m_interpreter->m_Number);
    65     markIfNeeded(m_interpreter->m_Date);
    66     markIfNeeded(m_interpreter->m_RegExp);
    67     markIfNeeded(m_interpreter->m_Error);
    68    
    69     markIfNeeded(m_interpreter->m_ObjectPrototype);
    70     markIfNeeded(m_interpreter->m_FunctionPrototype);
    71     markIfNeeded(m_interpreter->m_ArrayPrototype);
    72     markIfNeeded(m_interpreter->m_BooleanPrototype);
    73     markIfNeeded(m_interpreter->m_StringPrototype);
    74     markIfNeeded(m_interpreter->m_NumberPrototype);
    75     markIfNeeded(m_interpreter->m_DatePrototype);
    76     markIfNeeded(m_interpreter->m_RegExpPrototype);
    77     markIfNeeded(m_interpreter->m_ErrorPrototype);
    78    
    79     markIfNeeded(m_interpreter->m_EvalError);
    80     markIfNeeded(m_interpreter->m_RangeError);
    81     markIfNeeded(m_interpreter->m_ReferenceError);
    82     markIfNeeded(m_interpreter->m_SyntaxError);
    83     markIfNeeded(m_interpreter->m_TypeError);
    84     markIfNeeded(m_interpreter->m_UriError);
    85    
    86     markIfNeeded(m_interpreter->m_EvalErrorPrototype);
    87     markIfNeeded(m_interpreter->m_RangeErrorPrototype);
    88     markIfNeeded(m_interpreter->m_ReferenceErrorPrototype);
    89     markIfNeeded(m_interpreter->m_SyntaxErrorPrototype);
    90     markIfNeeded(m_interpreter->m_TypeErrorPrototype);
    91     markIfNeeded(m_interpreter->m_UriErrorPrototype);
     424    if (d->currentExec)
     425        d->currentExec->mark();
     426
     427    markIfNeeded(d->globalExec.exception());
     428
     429    markIfNeeded(d->objectConstructor);
     430    markIfNeeded(d->functionConstructor);
     431    markIfNeeded(d->arrayConstructor);
     432    markIfNeeded(d->booleanConstructor);
     433    markIfNeeded(d->stringConstructor);
     434    markIfNeeded(d->numberConstructor);
     435    markIfNeeded(d->dateConstructor);
     436    markIfNeeded(d->regExpConstructor);
     437    markIfNeeded(d->errorConstructor);
     438    markIfNeeded(d->evalErrorConstructor);
     439    markIfNeeded(d->rangeErrorConstructor);
     440    markIfNeeded(d->referenceErrorConstructor);
     441    markIfNeeded(d->syntaxErrorConstructor);
     442    markIfNeeded(d->typeErrorConstructor);
     443    markIfNeeded(d->URIErrorConstructor);
     444   
     445    markIfNeeded(d->objectPrototype);
     446    markIfNeeded(d->functionPrototype);
     447    markIfNeeded(d->arrayPrototype);
     448    markIfNeeded(d->booleanPrototype);
     449    markIfNeeded(d->stringPrototype);
     450    markIfNeeded(d->numberPrototype);
     451    markIfNeeded(d->datePrototype);
     452    markIfNeeded(d->regExpPrototype);
     453    markIfNeeded(d->errorPrototype);
     454    markIfNeeded(d->evalErrorPrototype);
     455    markIfNeeded(d->rangeErrorPrototype);
     456    markIfNeeded(d->referenceErrorPrototype);
     457    markIfNeeded(d->syntaxErrorPrototype);
     458    markIfNeeded(d->typeErrorPrototype);
     459    markIfNeeded(d->URIErrorPrototype);
    92460}
    93461
    94462ExecState* JSGlobalObject::globalExec()
    95463{
    96     return &m_interpreter->m_globalExec;
     464    return &d->globalExec;
    97465}
    98466
  • trunk/JavaScriptCore/kjs/JSGlobalObject.h

    r28415 r28468  
    22/*
    33 *  Copyright (C) 2007 Eric Seidel <eric@webkit.org>
    4  *  Copyright (C) 2007 Apple Ince. All rights reserved.
     4 *  Copyright (C) 2007 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    2828namespace KJS {
    2929
    30     class Interpreter;
     30    class ArrayObjectImp;
     31    class ArrayPrototype;
     32    class BooleanObjectImp;
     33    class BooleanPrototype;
     34    class DateObjectImp;
     35    class DatePrototype;
     36    class Debugger;
     37    class ErrorObjectImp;
     38    class ErrorPrototype;
     39    class EvalError;
     40    class EvalErrorPrototype;
     41    class FunctionObjectImp;
     42    class FunctionPrototype;
     43    class JSGlobalObject;
     44    class NativeErrorImp;
     45    class NativeErrorPrototype;
     46    class NumberObjectImp;
     47    class NumberPrototype;
     48    class ObjectObjectImp;
     49    class ObjectPrototype;
     50    class RangeError;
     51    class RangeErrorPrototype;
     52    class ReferenceError;
     53    class ReferenceError;
     54    class ReferenceErrorPrototype;
     55    class RegExpObjectImp;
     56    class RegExpPrototype;
     57    class RuntimeMethod;
     58    class SavedBuiltins;
     59    class ScopeChain;
     60    class StringObjectImp;
     61    class StringPrototype;
     62    class SyntaxErrorPrototype;
     63    class TypeError;
     64    class TypeErrorPrototype;
     65    class UriError;
     66    class UriErrorPrototype;
     67
     68    enum CompatMode { NativeMode, IECompat, NetscapeCompat };
    3169
    3270    class JSGlobalObject : public JSObject {
     71    protected:
     72        struct JSGlobalObjectData {
     73            JSGlobalObjectData(JSGlobalObject* globalObject)
     74                : globalExec(globalObject, globalObject, 0)
     75            {
     76            }
     77
     78            JSGlobalObject* next;
     79            JSGlobalObject* prev;
     80
     81            Debugger* debugger;
     82            CompatMode compatMode;
     83
     84            ExecState globalExec;
     85            ExecState* currentExec;
     86            int recursion;
     87
     88            unsigned timeoutTime;
     89            unsigned timeAtLastCheckTimeout;
     90            unsigned timeExecuting;
     91            unsigned timeoutCheckCount;
     92            unsigned tickCount;
     93            unsigned ticksUntilNextTimeoutCheck;
     94
     95            ObjectObjectImp* objectConstructor;
     96            FunctionObjectImp* functionConstructor;
     97            ArrayObjectImp* arrayConstructor;
     98            BooleanObjectImp* booleanConstructor;
     99            StringObjectImp* stringConstructor;
     100            NumberObjectImp* numberConstructor;
     101            DateObjectImp* dateConstructor;
     102            RegExpObjectImp* regExpConstructor;
     103            ErrorObjectImp* errorConstructor;
     104            NativeErrorImp* evalErrorConstructor;
     105            NativeErrorImp* rangeErrorConstructor;
     106            NativeErrorImp* referenceErrorConstructor;
     107            NativeErrorImp* syntaxErrorConstructor;
     108            NativeErrorImp* typeErrorConstructor;
     109            NativeErrorImp* URIErrorConstructor;
     110
     111            ObjectPrototype* objectPrototype;
     112            FunctionPrototype* functionPrototype;
     113            ArrayPrototype* arrayPrototype;
     114            BooleanPrototype* booleanPrototype;
     115            StringPrototype* stringPrototype;
     116            NumberPrototype* numberPrototype;
     117            DatePrototype* datePrototype;
     118            RegExpPrototype* regExpPrototype;
     119            ErrorPrototype* errorPrototype;
     120            NativeErrorPrototype* evalErrorPrototype;
     121            NativeErrorPrototype* rangeErrorPrototype;
     122            NativeErrorPrototype* referenceErrorPrototype;
     123            NativeErrorPrototype* syntaxErrorPrototype;
     124            NativeErrorPrototype* typeErrorPrototype;
     125            NativeErrorPrototype* URIErrorPrototype;
     126        };
     127
    33128    public:
    34         JSGlobalObject() { }
    35         JSGlobalObject(JSValue* proto) : JSObject(proto) { }
    36 
    37         Interpreter* interpreter() const { return m_interpreter.get(); }
    38         void setInterpreter(std::auto_ptr<Interpreter> i) { m_interpreter = i; }
     129        JSGlobalObject()
     130        {
     131            init();
     132        }
     133
     134    protected:
     135        JSGlobalObject(JSValue* proto)
     136            : JSObject(proto)
     137        {
     138            init();
     139        }
     140
     141    public:
     142        virtual ~JSGlobalObject();
     143
     144        // Linked list of all global objects.
     145        static JSGlobalObject* head() { return s_head; }
     146        JSGlobalObject* next() { return d->next; }
     147
     148        // Resets the global object to contain only built-in properties, sets
     149        // the global object's prototype to "prototype," then adds the
     150        // default object prototype to the tail of the global object's
     151        // prototype chain.
     152        void reset(JSValue* prototype);
     153
     154        // The following accessors return pristine values, even if a script
     155        // replaces the global object's associated property.
     156
     157        ObjectObjectImp* objectConstructor() const { return d->objectConstructor; }
     158        FunctionObjectImp* functionConstructor() const { return d->functionConstructor; }
     159        ArrayObjectImp* arrayConstructor() const { return d->arrayConstructor; }
     160        BooleanObjectImp* booleanConstructor() const { return d->booleanConstructor; }
     161        StringObjectImp* stringConstructor() const{ return d->stringConstructor; }
     162        NumberObjectImp* numberConstructor() const{ return d->numberConstructor; }
     163        DateObjectImp* dateConstructor() const{ return d->dateConstructor; }
     164        RegExpObjectImp* regExpConstructor() const { return d->regExpConstructor; }
     165        ErrorObjectImp* errorConstructor() const { return d->errorConstructor; }
     166        NativeErrorImp* evalErrorConstructor() const { return d->evalErrorConstructor; }
     167        NativeErrorImp* rangeErrorConstructor() const { return d->rangeErrorConstructor; }
     168        NativeErrorImp* referenceErrorConstructor() const { return d->referenceErrorConstructor; }
     169        NativeErrorImp* syntaxErrorConstructor() const { return d->syntaxErrorConstructor; }
     170        NativeErrorImp* typeErrorConstructor() const { return d->typeErrorConstructor; }
     171        NativeErrorImp* URIErrorConstructor() const { return d->URIErrorConstructor; }
     172
     173        ObjectPrototype* objectPrototype() const { return d->objectPrototype; }
     174        FunctionPrototype* functionPrototype() const { return d->functionPrototype; }
     175        ArrayPrototype* arrayPrototype() const { return d->arrayPrototype; }
     176        BooleanPrototype* booleanPrototype() const { return d->booleanPrototype; }
     177        StringPrototype* stringPrototype() const { return d->stringPrototype; }
     178        NumberPrototype* numberPrototype() const { return d->numberPrototype; }
     179        DatePrototype* datePrototype() const { return d->datePrototype; }
     180        RegExpPrototype* regExpPrototype() const { return d->regExpPrototype; }
     181        ErrorPrototype* errorPrototype() const { return d->errorPrototype; }
     182        NativeErrorPrototype* evalErrorPrototype() const { return d->evalErrorPrototype; }
     183        NativeErrorPrototype* rangeErrorPrototype() const { return d->rangeErrorPrototype; }
     184        NativeErrorPrototype* referenceErrorPrototype() const { return d->referenceErrorPrototype; }
     185        NativeErrorPrototype* syntaxErrorPrototype() const { return d->syntaxErrorPrototype; }
     186        NativeErrorPrototype* typeErrorPrototype() const { return d->typeErrorPrototype; }
     187        NativeErrorPrototype* URIErrorPrototype() const { return d->URIErrorPrototype; }
     188
     189        void saveBuiltins(SavedBuiltins&) const;
     190        void restoreBuiltins(const SavedBuiltins&);
     191
     192        void setTimeoutTime(unsigned timeoutTime) { d->timeoutTime = timeoutTime; }
     193        void startTimeoutCheck();
     194        void stopTimeoutCheck();
     195        bool timedOut();
     196
     197        Debugger* debugger() const { return d->debugger; }
     198        void setDebugger(Debugger* debugger) { d->debugger = debugger; }
     199
     200        void setCurrentExec(ExecState* exec) { d->currentExec = exec; }
     201        ExecState* currentExec() const { return d->currentExec; }
     202
     203        // FIXME: Let's just pick one compatible behavior and go with it.
     204        void setCompatMode(CompatMode mode) { d->compatMode = mode; }
     205        CompatMode compatMode() const { return d->compatMode; }
     206       
     207        int recursion() { return d->recursion; }
     208        void incRecursion() { ++d->recursion; }
     209        void decRecursion() { --d->recursion; }
    39210
    40211        virtual void mark();
     
    48219        virtual bool isSafeScript(const JSGlobalObject*) const { return true; }
    49220
     221    protected:
     222        std::auto_ptr<JSGlobalObjectData> d;
     223
    50224    private:
    51         std::auto_ptr<Interpreter> m_interpreter;
     225        void init();
     226
     227        bool checkTimeout();
     228        void resetTimeoutCheck();
     229
     230        static JSGlobalObject* s_head;
    52231    };
    53232
     233    inline bool JSGlobalObject::timedOut()
     234    {
     235        d->tickCount++;
     236
     237        if (d->tickCount != d->ticksUntilNextTimeoutCheck)
     238            return false;
     239
     240        return checkTimeout();
     241    }
     242
    54243} // namespace KJS
    55244
  • trunk/JavaScriptCore/kjs/JSImmediate.cpp

    r26688 r28468  
    3737        List args;
    3838        args.append(const_cast<JSValue *>(v));
    39         return exec->lexicalInterpreter()->builtinBoolean()->construct(exec, args);
     39        return exec->lexicalGlobalObject()->booleanConstructor()->construct(exec, args);
    4040    } else {
    4141        ASSERT(isNumber(v));
    4242        List args;
    4343        args.append(const_cast<JSValue *>(v));
    44         return exec->lexicalInterpreter()->builtinNumber()->construct(exec, args);
     44        return exec->lexicalGlobalObject()->numberConstructor()->construct(exec, args);
    4545    }
    4646}
  • trunk/JavaScriptCore/kjs/JSLock.h

    r20351 r28468  
    2121 */
    2222
    23 #ifndef KJS_INTERPRETER_LOCK_H
    24 #define KJS_INTERPRETER_LOCK_H
     23#ifndef KJS_JSLock_h
     24#define KJS_JSLock_h
    2525
    2626#include <wtf/Assertions.h>
     
    7979} // namespace
    8080
    81 #endif // KJS_INTERPRETER_LOCK_H
     81#endif // KJS_JSLock_h
  • trunk/JavaScriptCore/kjs/SavedBuiltins.h

    r19901 r28468  
    2727
    2828#include "protect.h"
     29#include "object_object.h"
     30#include "string_object.h"
     31#include "error_object.h"
     32#include "regexp_object.h"
     33#include "array_object.h"
     34#include "bool_object.h"
     35#include "date_object.h"
     36#include "number_object.h"
     37#include "math_object.h"
    2938
    3039namespace KJS {
    3140   
    32 class SavedBuiltinsInternal;
     41struct SavedBuiltinsInternal {
     42    ProtectedPtr<ObjectObjectImp> objectConstructor;
     43    ProtectedPtr<FunctionObjectImp> functionConstructor;
     44    ProtectedPtr<ArrayObjectImp> arrayConstructor;
     45    ProtectedPtr<BooleanObjectImp> booleanConstructor;
     46    ProtectedPtr<StringObjectImp> stringConstructor;
     47    ProtectedPtr<NumberObjectImp> numberConstructor;
     48    ProtectedPtr<DateObjectImp> dateConstructor;
     49    ProtectedPtr<RegExpObjectImp> regExpConstructor;
     50    ProtectedPtr<ErrorObjectImp> errorConstructor;
     51    ProtectedPtr<NativeErrorImp> evalErrorConstructor;
     52    ProtectedPtr<NativeErrorImp> rangeErrorConstructor;
     53    ProtectedPtr<NativeErrorImp> referenceErrorConstructor;
     54    ProtectedPtr<NativeErrorImp> syntaxErrorConstructor;
     55    ProtectedPtr<NativeErrorImp> typeErrorConstructor;
     56    ProtectedPtr<NativeErrorImp> URIErrorConstructor;
     57   
     58    ProtectedPtr<ObjectPrototype> objectPrototype;
     59    ProtectedPtr<FunctionPrototype> functionPrototype;
     60    ProtectedPtr<ArrayPrototype> arrayPrototype;
     61    ProtectedPtr<BooleanPrototype> booleanPrototype;
     62    ProtectedPtr<StringPrototype> stringPrototype;
     63    ProtectedPtr<NumberPrototype> numberPrototype;
     64    ProtectedPtr<DatePrototype> datePrototype;
     65    ProtectedPtr<RegExpPrototype> regExpPrototype;
     66    ProtectedPtr<ErrorPrototype> errorPrototype;
     67    ProtectedPtr<NativeErrorPrototype> evalErrorPrototype;
     68    ProtectedPtr<NativeErrorPrototype> rangeErrorPrototype;
     69    ProtectedPtr<NativeErrorPrototype> referenceErrorPrototype;
     70    ProtectedPtr<NativeErrorPrototype> syntaxErrorPrototype;
     71    ProtectedPtr<NativeErrorPrototype> typeErrorPrototype;
     72    ProtectedPtr<NativeErrorPrototype> URIErrorPrototype;
     73};
    3374
    3475class SavedBuiltins {
    35     friend class Interpreter;
     76    friend class JSGlobalObject;
    3677public:
    37     SavedBuiltins();
    38     ~SavedBuiltins();
     78    SavedBuiltins()
     79        : _internal(0)
     80    {
     81    }
     82
     83    ~SavedBuiltins()
     84    {
     85        delete _internal;
     86    }
     87
    3988private:
    40     SavedBuiltinsInternal *_internal;
    41 };
    42 
    43 class SavedBuiltinsInternal {
    44     friend class Interpreter;
    45 private:
    46     ProtectedPtr<ObjectObjectImp> m_Object;
    47     ProtectedPtr<FunctionObjectImp> m_Function;
    48     ProtectedPtr<ArrayObjectImp> m_Array;
    49     ProtectedPtr<BooleanObjectImp> m_Boolean;
    50     ProtectedPtr<StringObjectImp> m_String;
    51     ProtectedPtr<NumberObjectImp> m_Number;
    52     ProtectedPtr<DateObjectImp> m_Date;
    53     ProtectedPtr<RegExpObjectImp> m_RegExp;
    54     ProtectedPtr<ErrorObjectImp> m_Error;
    55    
    56     ProtectedPtr<ObjectPrototype> m_ObjectPrototype;
    57     ProtectedPtr<FunctionPrototype> m_FunctionPrototype;
    58     ProtectedPtr<ArrayPrototype> m_ArrayPrototype;
    59     ProtectedPtr<BooleanPrototype> m_BooleanPrototype;
    60     ProtectedPtr<StringPrototype> m_StringPrototype;
    61     ProtectedPtr<NumberPrototype> m_NumberPrototype;
    62     ProtectedPtr<DatePrototype> m_DatePrototype;
    63     ProtectedPtr<RegExpPrototype> m_RegExpPrototype;
    64     ProtectedPtr<ErrorPrototype> m_ErrorPrototype;
    65    
    66     ProtectedPtr<NativeErrorImp> m_EvalError;
    67     ProtectedPtr<NativeErrorImp> m_RangeError;
    68     ProtectedPtr<NativeErrorImp> m_ReferenceError;
    69     ProtectedPtr<NativeErrorImp> m_SyntaxError;
    70     ProtectedPtr<NativeErrorImp> m_TypeError;
    71     ProtectedPtr<NativeErrorImp> m_UriError;
    72    
    73     ProtectedPtr<NativeErrorPrototype> m_EvalErrorPrototype;
    74     ProtectedPtr<NativeErrorPrototype> m_RangeErrorPrototype;
    75     ProtectedPtr<NativeErrorPrototype> m_ReferenceErrorPrototype;
    76     ProtectedPtr<NativeErrorPrototype> m_SyntaxErrorPrototype;
    77     ProtectedPtr<NativeErrorPrototype> m_TypeErrorPrototype;
    78     ProtectedPtr<NativeErrorPrototype> m_UriErrorPrototype;
     89    SavedBuiltinsInternal* _internal;
    7990};
    8091
  • trunk/JavaScriptCore/kjs/array_instance.cpp

    r28346 r28468  
    484484        : exec(e)
    485485        , compareFunction(cf)
    486         , globalObject(e->dynamicInterpreter()->globalObject())
     486        , globalObject(e->dynamicGlobalObject())
    487487    {
    488488    }
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r27608 r28468  
    226226JSValue* ArrayProtoFuncConcat::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    227227{
    228     JSObject* arr = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
     228    JSObject* arr = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty()));
    229229    int n = 0;
    230230    JSValue *curArg = thisObj;
     
    334334
    335335    // We return a new array
    336     JSObject *resObj = static_cast<JSObject *>(exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty()));
     336    JSObject *resObj = static_cast<JSObject *>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec,List::empty()));
    337337    JSValue* result = resObj;
    338338    double begin = args[0]->toInteger(exec);
     
    421421                l.append(jObj);
    422422                l.append(minObj);
    423                 cmp = sortFunction->call(exec, exec->dynamicInterpreter()->globalObject(), l)->toNumber(exec);
     423                cmp = sortFunction->call(exec, exec->dynamicGlobalObject(), l)->toNumber(exec);
    424424            } else {
    425425              cmp = (jObj->toString(exec) < minObj->toString(exec)) ? -1 : 1;
     
    450450{
    451451    // 15.4.4.12 - oh boy this is huge
    452     JSObject *resObj = static_cast<JSObject *>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
     452    JSObject *resObj = static_cast<JSObject *>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty()));
    453453    JSValue* result = resObj;
    454454    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     
    527527        return throwError(exec, TypeError);
    528528   
    529     JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
    530     JSObject *resultArray = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
     529    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
     530    JSObject *resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty()));
    531531
    532532    unsigned filterIndex = 0;
     
    560560        return throwError(exec, TypeError);
    561561   
    562     JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
     562    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
    563563
    564564    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     
    566566    List mapArgs;
    567567    mapArgs.append(jsNumber(length));
    568     JSObject* resultArray = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinArray()->construct(exec, mapArgs));
     568    JSObject* resultArray = static_cast<JSObject*>(exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, mapArgs));
    569569
    570570    for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
     
    600600        return throwError(exec, TypeError);
    601601   
    602     JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
     602    JSObject *applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
    603603   
    604604    JSValue* result = jsBoolean(true);
     
    635635        return throwError(exec, TypeError);
    636636
    637     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
     637    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
    638638
    639639    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
     
    660660        return throwError(exec, TypeError);
    661661
    662     JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicInterpreter()->globalObject() :  args[1]->toObject(exec);
     662    JSObject* applyThis = args[1]->isUndefinedOrNull() ? exec->dynamicGlobalObject() :  args[1]->toObject(exec);
    663663
    664664    JSValue* result = jsBoolean(false);
     
    770770    if (n != args[0]->toNumber(exec))
    771771      return throwError(exec, RangeError, "Array size is not a small enough positive integer.");
    772     return new ArrayInstance(exec->lexicalInterpreter()->builtinArrayPrototype(), n);
     772    return new ArrayInstance(exec->lexicalGlobalObject()->arrayPrototype(), n);
    773773  }
    774774
    775775  // otherwise the array is constructed with the arguments in it
    776   return new ArrayInstance(exec->lexicalInterpreter()->builtinArrayPrototype(), args);
     776  return new ArrayInstance(exec->lexicalGlobalObject()->arrayPrototype(), args);
    777777}
    778778
  • trunk/JavaScriptCore/kjs/bool_object.cpp

    r28110 r28468  
    4646  : BooleanInstance(objectProto)
    4747{
    48   // The constructor will be added later by Interpreter::Interpreter()
    49 
    5048  putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, exec->propertyNames().toString), DontEnum);
    5149  putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, exec->propertyNames().valueOf),  DontEnum);
     
    102100JSObject *BooleanObjectImp::construct(ExecState *exec, const List &args)
    103101{
    104   BooleanInstance *obj(new BooleanInstance(exec->lexicalInterpreter()->builtinBooleanPrototype()));
     102  BooleanInstance *obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype()));
    105103
    106104  bool b;
  • trunk/JavaScriptCore/kjs/collector.cpp

    r28329 r28468  
    963963  bool newMemoryFull = (numLiveObjects >= KJS_MEM_LIMIT);
    964964  if (newMemoryFull && newMemoryFull != memoryFull)
    965       reportOutOfMemoryToAllInterpreters();
     965      reportOutOfMemoryToAllExecStates();
    966966  memoryFull = newMemoryFull;
    967967
     
    974974}
    975975
    976 size_t Collector::numInterpreters()
     976size_t Collector::numGlobalObjects()
    977977{
    978978  size_t count = 0;
    979   if (Interpreter::s_hook) {
    980     Interpreter* scr = Interpreter::s_hook;
     979  if (JSGlobalObject::head()) {
     980    JSGlobalObject* o = JSGlobalObject::head();
    981981    do {
    982982      ++count;
    983       scr = scr->next;
    984     } while (scr != Interpreter::s_hook);
     983      o = o->next();
     984    } while (o != JSGlobalObject::head());
    985985  }
    986986  return count;
     
    10421042}
    10431043
    1044 void Collector::reportOutOfMemoryToAllInterpreters()
    1045 {
    1046     if (!Interpreter::s_hook)
     1044void Collector::reportOutOfMemoryToAllExecStates()
     1045{
     1046    JSGlobalObject* o = JSGlobalObject::head();
     1047    if (!o)
    10471048        return;
    10481049   
    1049     Interpreter* interpreter = Interpreter::s_hook;
    10501050    do {
    1051         ExecState* exec = interpreter->currentExec() ? interpreter->currentExec() : interpreter->globalObject()->globalExec();
    1052        
     1051        ExecState* exec = o->currentExec() ? o->currentExec() : o->globalExec();
    10531052        exec->setException(Error::create(exec, GeneralError, "Out of memory"));
    1054        
    1055         interpreter = interpreter->next;
    1056     } while(interpreter != Interpreter::s_hook);
     1053        o = o->next();
     1054    } while(o != JSGlobalObject::head());
    10571055}
    10581056
  • trunk/JavaScriptCore/kjs/collector.h

    r28110 r28468  
    5555    static void collectOnMainThreadOnly(JSValue*);
    5656
    57     static size_t numInterpreters();
     57    static size_t numGlobalObjects();
    5858    static size_t numProtectedObjects();
    5959    static HashCountedSet<const char*>* rootObjectTypeCounts();
     
    8888    static size_t mainThreadOnlyObjectCount;
    8989    static bool memoryFull;
    90     static void reportOutOfMemoryToAllInterpreters();
     90    static void reportOutOfMemoryToAllExecStates();
    9191  };
    9292
  • trunk/JavaScriptCore/kjs/date_object.cpp

    r27947 r28468  
    503503  }
    504504 
    505   DateInstance *ret = new DateInstance(exec->lexicalInterpreter()->builtinDatePrototype());
     505  DateInstance *ret = new DateInstance(exec->lexicalGlobalObject()->datePrototype());
    506506  ret->setInternalValue(jsNumber(timeClip(value)));
    507507  return ret;
     
    18071807
    18081808    // IE returns the full year even in getYear.
    1809     if (exec->dynamicInterpreter()->compatMode() == Interpreter::IECompat)
     1809    if (exec->dynamicGlobalObject()->compatMode() == IECompat)
    18101810        return jsNumber(1900 + t.year);
    18111811    return jsNumber(t.year);
  • trunk/JavaScriptCore/kjs/debugger.cpp

    r17372 r28468  
    3232
    3333namespace KJS {
    34   struct AttachedInterpreter
     34  struct AttachedGlobalObject
    3535  {
    3636  public:
    37     AttachedInterpreter(Interpreter *i, AttachedInterpreter *ai) : interp(i), next(ai) { ++Debugger::debuggersPresent; }
    38     ~AttachedInterpreter() { --Debugger::debuggersPresent; }
    39     Interpreter *interp;
    40     AttachedInterpreter *next;
     37    AttachedGlobalObject(JSGlobalObject* o, AttachedGlobalObject* ai) : globalObj(o), next(ai) { ++Debugger::debuggersPresent; }
     38    ~AttachedGlobalObject() { --Debugger::debuggersPresent; }
     39    JSGlobalObject* globalObj;
     40    AttachedGlobalObject* next;
    4141  };
    4242
     
    5656}
    5757
    58 void Debugger::attach(Interpreter* interp)
     58void Debugger::attach(JSGlobalObject* globalObject)
    5959{
    60   Debugger *other = interp->debugger();
     60  Debugger* other = globalObject->debugger();
    6161  if (other == this)
    6262    return;
    6363  if (other)
    64     other->detach(interp);
    65   interp->setDebugger(this);
    66   rep->interps = new AttachedInterpreter(interp, rep->interps);
     64    other->detach(globalObject);
     65  globalObject->setDebugger(this);
     66  rep->globalObjects = new AttachedGlobalObject(globalObject, rep->globalObjects);
    6767}
    6868
    69 void Debugger::detach(Interpreter* interp)
     69void Debugger::detach(JSGlobalObject* globalObj)
    7070{
    71   // iterate the addresses where AttachedInterpreter pointers are stored
     71  // iterate the addresses where AttachedGlobalObject pointers are stored
    7272  // so we can unlink items from the list
    73   AttachedInterpreter **p = &rep->interps;
    74   AttachedInterpreter *q;
     73  AttachedGlobalObject **p = &rep->globalObjects;
     74  AttachedGlobalObject *q;
    7575  while ((q = *p)) {
    76     if (!interp || q->interp == interp) {
     76    if (!globalObj || q->globalObj == globalObj) {
    7777      *p = q->next;
    78       q->interp->setDebugger(0);
     78      q->globalObj->setDebugger(0);
    7979      delete q;
    8080    } else
     
    8282  }
    8383
    84   if (interp)
    85     latestExceptions.remove(interp);
     84  if (globalObj)
     85    latestExceptions.remove(globalObj);
    8686  else
    8787    latestExceptions.clear();
     
    9090bool Debugger::hasHandledException(ExecState *exec, JSValue *exception)
    9191{
    92     if (latestExceptions.get(exec->dynamicInterpreter()).get() == exception)
     92    if (latestExceptions.get(exec->dynamicGlobalObject()).get() == exception)
    9393        return true;
    9494
    95     latestExceptions.set(exec->dynamicInterpreter(), exception);
     95    latestExceptions.set(exec->dynamicGlobalObject(), exception);
    9696    return false;
    9797}
  • trunk/JavaScriptCore/kjs/debugger.h

    r15593 r28468  
    3030
    3131  class DebuggerImp;
    32   class Interpreter;
    3332  class ExecState;
    3433  class JSObject;
     
    5958
    6059    /**
    61      * Destroys the debugger. If the debugger is attached to any interpreters,
     60     * Destroys the debugger. If the debugger is attached to any global objects,
    6261     * it is automatically detached.
    6362     */
     
    6766
    6867    /**
    69      * Attaches the debugger to specified interpreter. This will cause this
    70      * object to receive notification of events from the interpreter.
    71      *
    72      * If the interpreter is deleted, the debugger will automatically be
    73      * detached.
    74      *
    75      * Note: only one debugger can be attached to an interpreter at a time.
    76      * Attaching another debugger to the same interpreter will cause the
    77      * original debugger to be detached from that interpreter.
    78      *
    79      * @param interp The interpreter to attach to
     68     * Attaches the debugger to specified global object. This will cause this
     69     * object to receive notification of events during execution.
     70     *
     71     * If the global object is deleted, it will detach the debugger.
     72     *
     73     * Note: only one debugger can be attached to a global object at a time.
     74     * Attaching another debugger to the same global object will cause the
     75     * original debugger to be detached.
     76     *
     77     * @param The global object to attach to.
    8078     *
    8179     * @see detach()
    8280     */
    83     void attach(Interpreter *interp);
    84 
    85     /**
    86      * Detach the debugger from an interpreter
    87      *
    88      * @param interp The interpreter to detach from. If 0, the debugger will be
    89      * detached from all interpreters to which it is attached.
     81    void attach(JSGlobalObject*);
     82
     83    /**
     84     * Detach the debugger from a global object.
     85     *
     86     * @param The global object to detach from. If 0, the debugger will be
     87     * detached from all global objects to which it is attached.
    9088     *
    9189     * @see attach()
    9290     */
    93     void detach(Interpreter *interp);
     91    void detach(JSGlobalObject*);
    9492
    9593    /**
     
    216214  private:
    217215    DebuggerImp *rep;
    218     HashMap<Interpreter*, ProtectedPtr<JSValue> > latestExceptions;
     216    HashMap<JSGlobalObject*, ProtectedPtr<JSValue> > latestExceptions;
    219217
    220218  public:
  • trunk/JavaScriptCore/kjs/error_object.cpp

    r28110 r28468  
    2525#include "object.h"
    2626#include "types.h"
    27 #include "interpreter.h"
    2827#include "operations.h"
    2928#include "error_object.h"
     
    9998JSObject* ErrorObjectImp::construct(ExecState* exec, const List &args)
    10099{
    101   JSObject* proto = static_cast<JSObject*>(exec->lexicalInterpreter()->builtinErrorPrototype());
     100  JSObject* proto = static_cast<JSObject*>(exec->lexicalGlobalObject()->errorPrototype());
    102101  JSObject* imp = new ErrorInstance(proto);
    103102  JSObject* obj(imp);
  • trunk/JavaScriptCore/kjs/function.cpp

    r28458 r28468  
    5656
    5757FunctionImp::FunctionImp(ExecState* exec, const Identifier& name, FunctionBodyNode* b, const ScopeChain& sc)
    58   : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
     58  : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name)
    5959  , body(b)
    6060  , _scope(sc)
     
    7070JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    7171{
    72   JSGlobalObject* globalObj = exec->dynamicInterpreter()->globalObject();
    73 
    7472  // enter a new execution context
    75   ExecState newExec(exec->dynamicInterpreter(), globalObj, thisObj, body.get(),
    76                     FunctionCode, exec, this, &args);
     73  ExecState newExec(exec->dynamicGlobalObject(), thisObj, body.get(), FunctionCode, exec, exec->dynamicGlobalObject()->currentExec(), this, &args);
    7774  if (exec->hadException())
    7875    newExec.setException(exec->exception());
     
    205202    proto = static_cast<JSObject*>(p);
    206203  else
    207     proto = exec->lexicalInterpreter()->builtinObjectPrototype();
     204    proto = exec->lexicalGlobalObject()->objectPrototype();
    208205
    209206  JSObject* obj(new JSObject(proto));
     
    300297// ECMA 10.1.8
    301298Arguments::Arguments(ExecState* exec, FunctionImp* func, const List& args, ActivationImp* act)
    302 : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()),
     299: JSObject(exec->lexicalGlobalObject()->objectPrototype()),
    303300_activationObject(act),
    304301indexToNameMap(func, args)
     
    745742        RefPtr<ProgramNode> progNode(parser().parseProgram(UString(), 0, s.data(), s.size(), &sourceId, &errLine, &errMsg));
    746743
    747         Debugger* dbg = exec->dynamicInterpreter()->debugger();
     744        Debugger* dbg = exec->dynamicGlobalObject()->debugger();
    748745        if (dbg) {
    749746          bool cont = dbg->sourceParsed(exec, sourceId, UString(), s, 0, errLine, errMsg);
     
    756753          return throwError(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
    757754
    758         bool switchGlobal = thisObj && thisObj != exec->dynamicInterpreter()->globalObject();
    759          
     755        bool switchGlobal = thisObj && thisObj != exec->dynamicGlobalObject() && thisObj->isGlobalObject();
     756
    760757        // enter a new execution context
    761         Interpreter* interpreter = switchGlobal ? static_cast<JSGlobalObject*>(thisObj)->interpreter() : exec->dynamicInterpreter();
     758        JSGlobalObject* globalObject = switchGlobal ? static_cast<JSGlobalObject*>(thisObj) : exec->dynamicGlobalObject();
    762759        JSObject* thisVal = static_cast<JSObject*>(exec->thisValue());
    763         ExecState newExec(interpreter, interpreter->globalObject(), thisVal, progNode.get(), EvalCode, exec);
     760        ExecState newExec(globalObject, thisVal, progNode.get(), EvalCode, exec, globalObject->currentExec());
    764761        if (exec->hadException())
    765762            newExec.setException(exec->exception());
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r27842 r28468  
    104104    JSObject *applyThis;
    105105    if (thisArg->isUndefinedOrNull())
    106       applyThis = exec->dynamicInterpreter()->globalObject();
     106      applyThis = exec->dynamicGlobalObject();
    107107    else
    108108      applyThis = thisArg->toObject(exec);
     
    134134    JSObject *callThis;
    135135    if (thisArg->isUndefinedOrNull())
    136       callThis = exec->dynamicInterpreter()->globalObject();
     136      callThis = exec->dynamicGlobalObject();
    137137    else
    138138      callThis = thisArg->toObject(exec);
     
    192192
    193193  // notify debugger that source has been parsed
    194   Debugger *dbg = exec->dynamicInterpreter()->debugger();
     194  Debugger *dbg = exec->dynamicGlobalObject()->debugger();
    195195  if (dbg) {
    196196    // send empty sourceURL to indicate constructed code
     
    209209
    210210  ScopeChain scopeChain;
    211   scopeChain.push(exec->lexicalInterpreter()->globalObject());
     211  scopeChain.push(exec->lexicalGlobalObject());
    212212
    213213  FunctionImp* fimp = new FunctionImp(exec, functionName, functionBody.get(), scopeChain);
     
    246246  List consArgs;
    247247
    248   JSObject* objCons = exec->lexicalInterpreter()->builtinObject();
     248  JSObject* objCons = exec->lexicalGlobalObject()->objectConstructor();
    249249  JSObject* prototype = objCons->construct(exec,List::empty());
    250250  prototype->put(exec, exec->propertyNames().constructor, fimp, DontEnum|DontDelete|ReadOnly);
  • trunk/JavaScriptCore/kjs/grammar.y

    r27842 r28468  
    2929#include "object.h"
    3030#include "types.h"
    31 #include "interpreter.h"
    3231#include "nodes.h"
    3332#include "lexer.h"
  • trunk/JavaScriptCore/kjs/internal.cpp

    r28110 r28468  
    8181JSObject* StringImp::toObject(ExecState *exec) const
    8282{
    83     return new StringInstance(exec->lexicalInterpreter()->builtinStringPrototype(), const_cast<StringImp*>(this));
     83    return new StringInstance(exec->lexicalGlobalObject()->stringPrototype(), const_cast<StringImp*>(this));
    8484}
    8585
     
    119119  List args;
    120120  args.append(const_cast<NumberImp*>(this));
    121   return static_cast<JSObject *>(exec->lexicalInterpreter()->builtinNumber()->construct(exec,args));
     121  return static_cast<JSObject *>(exec->lexicalGlobalObject()->numberConstructor()->construct(exec,args));
    122122}
    123123
  • trunk/JavaScriptCore/kjs/internal.h

    r27695 r28468  
    2626
    2727#include "JSType.h"
    28 #include "interpreter.h"
    2928#include "object.h"
    3029#include "protect.h"
     
    9998  // ---------------------------------------------------------------------------
    10099
    101   struct AttachedInterpreter;
     100  struct AttachedGlobalObject;
    102101  class DebuggerImp {
    103102  public:
    104103
    105104    DebuggerImp() {
    106       interps = 0;
     105      globalObjects = 0;
    107106      isAborted = false;
    108107    }
     
    111110    bool aborted() const { return isAborted; }
    112111
    113     AttachedInterpreter *interps;
     112    AttachedGlobalObject* globalObjects;
    114113    bool isAborted;
    115114  };
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r28328 r28468  
    44 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    55 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    6  *  Copyright (C) 2003 Apple Computer, Inc.
     6 *  Copyright (C) 2003, 2007 Apple Inc.
    77 *
    88 *  This library is free software; you can redistribute it and/or
     
    6767namespace KJS {
    6868
    69 // Default number of ticks before a timeout check should be done.
    70 static const int initialTickCountThreshold = 255;
    71 
    72 // Preferred number of milliseconds between each timeout check
    73 static const int preferredScriptCheckTimeInterval = 1000;
    74 
    75 Interpreter* Interpreter::s_hook = 0;
    76    
    77 typedef HashMap<JSObject*, Interpreter*> InterpreterMap;
    78 static inline InterpreterMap &interpreterMap()
     69Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code)
    7970{
    80     static InterpreterMap* map = new InterpreterMap;
    81     return* map;
     71    return checkSyntax(exec, sourceURL, startingLineNumber, code.data(), code.size());
    8272}
    8373
    84 Interpreter::Interpreter()
    85     : m_globalExec(this, 0, 0, 0)
    86     , m_currentExec(0)
    87     , m_globalObject(0)
    88 {
    89     init();
    90 }
    91 
    92 void Interpreter::init()
    93 {
    94     JSLock lock;
    95 
    96     m_timeoutTime = 0;
    97     m_recursion = 0;
    98     m_debugger= 0;
    99 
    100     resetTimeoutCheck();
    101     m_timeoutCheckCount = 0;
    102    
    103     m_compatMode = NativeMode;
    104 
    105     if (s_hook) {
    106         prev = s_hook;
    107         next = s_hook->next;
    108         s_hook->next->prev = this;
    109         s_hook->next = this;
    110     } else {
    111         // This is the first interpreter
    112         s_hook = next = prev = this;
    113     }
    114 
    115     createObjectsForGlobalObjectProperties();
    116 }
    117 
    118 Interpreter::~Interpreter()
    119 {
    120     JSLock lock;
    121    
    122     if (m_debugger)
    123         m_debugger->detach(this);
    124 
    125     next->prev = prev;
    126     prev->next = next;
    127     s_hook = next;
    128     if (s_hook == this) {
    129         // This was the last interpreter
    130         s_hook = 0;
    131     }
    132 }
    133 
    134 JSGlobalObject* Interpreter::globalObject() const
    135 {
    136     // Now that we delay setting of the global object, people retrieving it before it is set may be in for a nasty surprise
    137     ASSERT(m_globalObject);
    138     return m_globalObject;
    139 }
    140 
    141 void Interpreter::setGlobalObject(JSGlobalObject* globalObject)
    142 {
    143     ASSERT(!m_globalObject);
    144     ASSERT(globalObject);
    145     m_globalObject = globalObject;
    146     m_globalExec.setGlobalObject(globalObject);
    147 
    148     setGlobalObjectProperties();
    149 }
    150 
    151 void Interpreter::resetGlobalObjectProperties()
    152 {
    153     ASSERT(m_globalObject);
    154     createObjectsForGlobalObjectProperties();
    155     setGlobalObjectProperties();
    156 }
    157 
    158 void Interpreter::createObjectsForGlobalObjectProperties()
    159 {
    160     // Clear before inititalizing, to avoid marking uninitialized (dangerous) or
    161     // stale (wasteful) pointers during initialization.
    162    
    163     // Prototypes
    164     m_FunctionPrototype = 0;
    165     m_ObjectPrototype = 0;
    166 
    167     m_ArrayPrototype = 0;
    168     m_StringPrototype = 0;
    169     m_BooleanPrototype = 0;
    170     m_NumberPrototype = 0;
    171     m_DatePrototype = 0;
    172     m_RegExpPrototype = 0;
    173     m_ErrorPrototype = 0;
    174    
    175     m_EvalErrorPrototype = 0;
    176     m_RangeErrorPrototype = 0;
    177     m_ReferenceErrorPrototype = 0;
    178     m_SyntaxErrorPrototype = 0;
    179     m_TypeErrorPrototype = 0;
    180     m_UriErrorPrototype = 0;
    181 
    182     // Constructors
    183     m_Object = 0;
    184     m_Function = 0;
    185     m_Array = 0;
    186     m_String = 0;
    187     m_Boolean = 0;
    188     m_Number = 0;
    189     m_Date = 0;
    190     m_RegExp = 0;
    191     m_Error = 0;
    192    
    193     m_EvalError = 0;
    194     m_RangeError = 0;
    195     m_ReferenceError = 0;
    196     m_SyntaxError = 0;
    197     m_TypeError = 0;
    198     m_UriError = 0;
    199 
    200     // Prototypes
    201     m_FunctionPrototype = new FunctionPrototype(&m_globalExec);
    202     m_ObjectPrototype = new ObjectPrototype(&m_globalExec, m_FunctionPrototype);
    203     m_FunctionPrototype->setPrototype(m_ObjectPrototype);
    204    
    205     m_ArrayPrototype = new ArrayPrototype(&m_globalExec, m_ObjectPrototype);
    206     m_StringPrototype = new StringPrototype(&m_globalExec, m_ObjectPrototype);
    207     m_BooleanPrototype = new BooleanPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
    208     m_NumberPrototype = new NumberPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
    209     m_DatePrototype = new DatePrototype(&m_globalExec, m_ObjectPrototype);
    210     m_RegExpPrototype = new RegExpPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);;
    211     m_ErrorPrototype = new ErrorPrototype(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
    212    
    213     m_EvalErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, EvalError, "EvalError", "EvalError");
    214     m_RangeErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, RangeError, "RangeError", "RangeError");
    215     m_ReferenceErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, ReferenceError, "ReferenceError", "ReferenceError");
    216     m_SyntaxErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, SyntaxError, "SyntaxError", "SyntaxError");
    217     m_TypeErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, TypeError, "TypeError", "TypeError");
    218     m_UriErrorPrototype = new NativeErrorPrototype(&m_globalExec, m_ErrorPrototype, URIError, "URIError", "URIError");
    219 
    220     // Constructors
    221     m_Object = new ObjectObjectImp(&m_globalExec, m_ObjectPrototype, m_FunctionPrototype);
    222     m_Function = new FunctionObjectImp(&m_globalExec, m_FunctionPrototype);
    223     m_Array = new ArrayObjectImp(&m_globalExec, m_FunctionPrototype, m_ArrayPrototype);
    224     m_String = new StringObjectImp(&m_globalExec, m_FunctionPrototype, m_StringPrototype);
    225     m_Boolean = new BooleanObjectImp(&m_globalExec, m_FunctionPrototype, m_BooleanPrototype);
    226     m_Number = new NumberObjectImp(&m_globalExec, m_FunctionPrototype, m_NumberPrototype);
    227     m_Date = new DateObjectImp(&m_globalExec, m_FunctionPrototype, m_DatePrototype);
    228     m_RegExp = new RegExpObjectImp(&m_globalExec, m_FunctionPrototype, m_RegExpPrototype);
    229     m_Error = new ErrorObjectImp(&m_globalExec, m_FunctionPrototype, m_ErrorPrototype);
    230    
    231     m_EvalError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_EvalErrorPrototype);
    232     m_RangeError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_RangeErrorPrototype);
    233     m_ReferenceError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_ReferenceErrorPrototype);
    234     m_SyntaxError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_SyntaxErrorPrototype);
    235     m_TypeError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_TypeErrorPrototype);
    236     m_UriError = new NativeErrorImp(&m_globalExec, m_FunctionPrototype, m_UriErrorPrototype);
    237    
    238     m_FunctionPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Function, DontEnum);
    239     m_ObjectPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Object, DontEnum | DontDelete | ReadOnly);
    240     m_FunctionPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Function, DontEnum | DontDelete | ReadOnly);
    241     m_ArrayPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Array, DontEnum | DontDelete | ReadOnly);
    242     m_BooleanPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Boolean, DontEnum | DontDelete | ReadOnly);
    243     m_StringPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_String, DontEnum | DontDelete | ReadOnly);
    244     m_NumberPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Number, DontEnum | DontDelete | ReadOnly);
    245     m_DatePrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Date, DontEnum | DontDelete | ReadOnly);
    246     m_RegExpPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_RegExp, DontEnum | DontDelete | ReadOnly);
    247     m_ErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_Error, DontEnum | DontDelete | ReadOnly);
    248     m_EvalErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_EvalError, DontEnum | DontDelete | ReadOnly);
    249     m_RangeErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_RangeError, DontEnum | DontDelete | ReadOnly);
    250     m_ReferenceErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_ReferenceError, DontEnum | DontDelete | ReadOnly);
    251     m_SyntaxErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_SyntaxError, DontEnum | DontDelete | ReadOnly);
    252     m_TypeErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_TypeError, DontEnum | DontDelete | ReadOnly);
    253     m_UriErrorPrototype->put(&m_globalExec, m_globalExec.propertyNames().constructor, m_UriError, DontEnum | DontDelete | ReadOnly);
    254 }
    255 
    256 void Interpreter::setGlobalObjectProperties()
    257 {
    258     ASSERT(m_globalObject);
    259     m_globalObject->setInterpreter(std::auto_ptr<Interpreter>(this));
    260 
    261     // Set global object prototype
    262     JSObject* o = m_globalObject;
    263     while (o->prototype()->isObject())
    264         o = static_cast<JSObject*>(o->prototype());
    265     o->setPrototype(m_ObjectPrototype);
    266 
    267     // Set global constructors
    268     // FIXME: kjs_window.cpp checks Internal/DontEnum as a performance hack, to
    269     // see that these values can be put directly without a check for override
    270     // properties.
    271     // FIXME: These properties should be handled by JSGlobalObject
    272     m_globalObject->putDirect("Object", m_Object, DontEnum);
    273     m_globalObject->putDirect("Function", m_Function, DontEnum);
    274     m_globalObject->putDirect("Array", m_Array, DontEnum);
    275     m_globalObject->putDirect("Boolean", m_Boolean, DontEnum);
    276     m_globalObject->putDirect("String", m_String, DontEnum);
    277     m_globalObject->putDirect("Number", m_Number, DontEnum);
    278     m_globalObject->putDirect("Date", m_Date, DontEnum);
    279     m_globalObject->putDirect("RegExp", m_RegExp, DontEnum);
    280     m_globalObject->putDirect("Error", m_Error, DontEnum);
    281     m_globalObject->putDirect("EvalError",m_EvalError, Internal);
    282     m_globalObject->putDirect("RangeError",m_RangeError, Internal);
    283     m_globalObject->putDirect("ReferenceError",m_ReferenceError, Internal);
    284     m_globalObject->putDirect("SyntaxError",m_SyntaxError, Internal);
    285     m_globalObject->putDirect("TypeError",m_TypeError, Internal);
    286     m_globalObject->putDirect("URIError",m_UriError, Internal);
    287 
    288     // Set global values
    289     m_globalObject->putDirect("Math", new MathObjectImp(&m_globalExec, m_ObjectPrototype), DontEnum);
    290     m_globalObject->putDirect("NaN", jsNaN(), DontEnum|DontDelete);
    291     m_globalObject->putDirect("Infinity", jsNumber(Inf), DontEnum|DontDelete);
    292     m_globalObject->putDirect("undefined", jsUndefined(), DontEnum|DontDelete);
    293    
    294     // Set global functions
    295     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::Eval, 1, "eval"), DontEnum);
    296     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::ParseInt, 2, "parseInt"), DontEnum);
    297     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::ParseFloat, 1, "parseFloat"), DontEnum);
    298     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::IsNaN, 1, "isNaN"), DontEnum);
    299     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::IsFinite, 1, "isFinite"), DontEnum);
    300     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::Escape, 1, "escape"), DontEnum);
    301     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::UnEscape, 1, "unescape"), DontEnum);
    302     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::DecodeURI, 1, "decodeURI"), DontEnum);
    303     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::DecodeURIComponent, 1, "decodeURIComponent"), DontEnum);
    304     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::EncodeURI, 1, "encodeURI"), DontEnum);
    305     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::EncodeURIComponent, 1, "encodeURIComponent"), DontEnum);
    306 #ifndef NDEBUG
    307     m_globalObject->putDirectFunction(new GlobalFuncImp(&m_globalExec, m_FunctionPrototype, GlobalFuncImp::KJSPrint, 1, "kjsprint"), DontEnum);
    308 #endif
    309 }
    310 
    311 Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code)
    312 {
    313     return checkSyntax(sourceURL, startingLineNumber, code.data(), code.size());
    314 }
    315 
    316 Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)
     74Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)
    31775{
    31876    JSLock lock;
     
    32280    RefPtr<ProgramNode> progNode = parser().parseProgram(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg);
    32381    if (!progNode)
    324         return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, 0, sourceURL));
     82        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
    32583    return Completion(Normal);
    32684}
    32785
    328 Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
     86Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
    32987{
    330     return evaluate(sourceURL, startingLineNumber, code.data(), code.size(), thisV);
     88    return evaluate(exec, sourceURL, startingLineNumber, code.data(), code.size(), thisV);
    33189}
    33290
    333 Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
     91Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
    33492{
    33593    JSLock lock;
    33694   
    337     // prevent against infinite recursion
    338     if (m_recursion >= 20)
    339         return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep"));
     95    JSGlobalObject* globalObject = exec->dynamicGlobalObject();
     96
     97    if (globalObject->recursion() >= 20)
     98        return Completion(Throw, Error::create(exec, GeneralError, "Recursion too deep"));
    34099   
    341100    // parse the source code
     
    346105   
    347106    // notify debugger that source has been parsed
    348     if (m_debugger) {
    349         bool cont = m_debugger->sourceParsed(&m_globalExec, sourceId, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);
     107    if (globalObject->debugger()) {
     108        bool cont = globalObject->debugger()->sourceParsed(exec, sourceId, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);
    350109        if (!cont)
    351110            return Completion(Break);
     
    354113    // no program node means a syntax error occurred
    355114    if (!progNode)
    356         return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
     115        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
    357116   
    358     m_globalExec.clearException();
     117    exec->clearException();
    359118   
    360     m_recursion++;
     119    globalObject->incRecursion();
    361120   
    362     JSGlobalObject* globalObj = m_globalObject;
    363     JSObject* thisObj = globalObj;
     121    JSObject* thisObj = globalObject;
    364122   
    365123    // "this" must be an object... use same rules as Function.prototype.apply()
    366124    if (thisV && !thisV->isUndefinedOrNull())
    367         thisObj = thisV->toObject(&m_globalExec);
     125        thisObj = thisV->toObject(exec);
    368126   
    369127    Completion res;
    370     if (m_globalExec.hadException())
     128    if (exec->hadException())
    371129        // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it
    372         res = Completion(Throw, m_globalExec.exception());
     130        res = Completion(Throw, exec->exception());
    373131    else {
    374132        // execute the code
    375         ExecState newExec(this, globalObj, thisObj, progNode.get());
     133        ExecState newExec(globalObject, thisObj, progNode.get());
    376134        res = progNode->execute(&newExec);
    377135    }
    378136   
    379     m_recursion--;
     137    globalObject->decRecursion();
    380138   
    381139    if (shouldPrintExceptions() && res.complType() == Throw) {
    382140        JSLock lock;
    383         ExecState* exec = m_globalObject->globalExec();
     141        ExecState* exec = globalObject->globalExec();
    384142        CString f = sourceURL.UTF8String();
    385143        CString message = res.value()->toObject(exec)->toString(exec).UTF8String();
     
    393151
    394152    return res;
    395 }
    396 
    397 JSObject *Interpreter::builtinObject() const
    398 {
    399   return m_Object;
    400 }
    401 
    402 JSObject *Interpreter::builtinFunction() const
    403 {
    404   return m_Function;
    405 }
    406 
    407 JSObject *Interpreter::builtinArray() const
    408 {
    409   return m_Array;
    410 }
    411 
    412 JSObject *Interpreter::builtinBoolean() const
    413 {
    414   return m_Boolean;
    415 }
    416 
    417 JSObject *Interpreter::builtinString() const
    418 {
    419   return m_String;
    420 }
    421 
    422 JSObject *Interpreter::builtinNumber() const
    423 {
    424   return m_Number;
    425 }
    426 
    427 JSObject *Interpreter::builtinDate() const
    428 {
    429   return m_Date;
    430 }
    431 
    432 JSObject *Interpreter::builtinError() const
    433 {
    434   return m_Error;
    435 }
    436 
    437 JSObject *Interpreter::builtinObjectPrototype() const
    438 {
    439   return m_ObjectPrototype;
    440 }
    441 
    442 JSObject *Interpreter::builtinFunctionPrototype() const
    443 {
    444   return m_FunctionPrototype;
    445 }
    446 
    447 JSObject *Interpreter::builtinArrayPrototype() const
    448 {
    449   return m_ArrayPrototype;
    450 }
    451 
    452 JSObject *Interpreter::builtinBooleanPrototype() const
    453 {
    454   return m_BooleanPrototype;
    455 }
    456 
    457 JSObject *Interpreter::builtinStringPrototype() const
    458 {
    459   return m_StringPrototype;
    460 }
    461 
    462 JSObject *Interpreter::builtinNumberPrototype() const
    463 {
    464   return m_NumberPrototype;
    465 }
    466 
    467 JSObject *Interpreter::builtinDatePrototype() const
    468 {
    469   return m_DatePrototype;
    470 }
    471 
    472 JSObject *Interpreter::builtinRegExpPrototype() const
    473 {
    474   return m_RegExpPrototype;
    475 }
    476 
    477 JSObject *Interpreter::builtinErrorPrototype() const
    478 {
    479   return m_ErrorPrototype;
    480 }
    481 
    482 JSObject *Interpreter::builtinEvalError() const
    483 {
    484   return m_EvalError;
    485 }
    486 
    487 JSObject *Interpreter::builtinRangeError() const
    488 {
    489   return m_RangeError;
    490 }
    491 
    492 JSObject *Interpreter::builtinReferenceError() const
    493 {
    494   return m_ReferenceError;
    495 }
    496 
    497 JSObject *Interpreter::builtinSyntaxError() const
    498 {
    499   return m_SyntaxError;
    500 }
    501 
    502 JSObject *Interpreter::builtinTypeError() const
    503 {
    504   return m_TypeError;
    505 }
    506 
    507 JSObject *Interpreter::builtinURIError() const
    508 {
    509   return m_UriError;
    510 }
    511 
    512 JSObject *Interpreter::builtinEvalErrorPrototype() const
    513 {
    514   return m_EvalErrorPrototype;
    515 }
    516 
    517 JSObject *Interpreter::builtinRangeErrorPrototype() const
    518 {
    519   return m_RangeErrorPrototype;
    520 }
    521 
    522 JSObject *Interpreter::builtinReferenceErrorPrototype() const
    523 {
    524   return m_ReferenceErrorPrototype;
    525 }
    526 
    527 JSObject *Interpreter::builtinSyntaxErrorPrototype() const
    528 {
    529   return m_SyntaxErrorPrototype;
    530 }
    531 
    532 JSObject *Interpreter::builtinTypeErrorPrototype() const
    533 {
    534   return m_TypeErrorPrototype;
    535 }
    536 
    537 JSObject *Interpreter::builtinURIErrorPrototype() const
    538 {
    539   return m_UriErrorPrototype;
    540153}
    541154
     
    552165}
    553166
    554 void Interpreter::saveBuiltins (SavedBuiltins& builtins) const
    555 {
    556     if (!builtins._internal)
    557         builtins._internal = new SavedBuiltinsInternal;
    558    
    559     builtins._internal->m_Object = m_Object;
    560     builtins._internal->m_Function = m_Function;
    561     builtins._internal->m_Array = m_Array;
    562     builtins._internal->m_Boolean = m_Boolean;
    563     builtins._internal->m_String = m_String;
    564     builtins._internal->m_Number = m_Number;
    565     builtins._internal->m_Date = m_Date;
    566     builtins._internal->m_RegExp = m_RegExp;
    567     builtins._internal->m_Error = m_Error;
    568    
    569     builtins._internal->m_ObjectPrototype = m_ObjectPrototype;
    570     builtins._internal->m_FunctionPrototype = m_FunctionPrototype;
    571     builtins._internal->m_ArrayPrototype = m_ArrayPrototype;
    572     builtins._internal->m_BooleanPrototype = m_BooleanPrototype;
    573     builtins._internal->m_StringPrototype = m_StringPrototype;
    574     builtins._internal->m_NumberPrototype = m_NumberPrototype;
    575     builtins._internal->m_DatePrototype = m_DatePrototype;
    576     builtins._internal->m_RegExpPrototype = m_RegExpPrototype;
    577     builtins._internal->m_ErrorPrototype = m_ErrorPrototype;
    578    
    579     builtins._internal->m_EvalError = m_EvalError;
    580     builtins._internal->m_RangeError = m_RangeError;
    581     builtins._internal->m_ReferenceError = m_ReferenceError;
    582     builtins._internal->m_SyntaxError = m_SyntaxError;
    583     builtins._internal->m_TypeError = m_TypeError;
    584     builtins._internal->m_UriError = m_UriError;
    585    
    586     builtins._internal->m_EvalErrorPrototype = m_EvalErrorPrototype;
    587     builtins._internal->m_RangeErrorPrototype = m_RangeErrorPrototype;
    588     builtins._internal->m_ReferenceErrorPrototype = m_ReferenceErrorPrototype;
    589     builtins._internal->m_SyntaxErrorPrototype = m_SyntaxErrorPrototype;
    590     builtins._internal->m_TypeErrorPrototype = m_TypeErrorPrototype;
    591     builtins._internal->m_UriErrorPrototype = m_UriErrorPrototype;
    592 }
    593 
    594 void Interpreter::restoreBuiltins (const SavedBuiltins& builtins)
    595 {
    596     if (!builtins._internal)
    597         return;
    598 
    599     m_Object = builtins._internal->m_Object;
    600     m_Function = builtins._internal->m_Function;
    601     m_Array = builtins._internal->m_Array;
    602     m_Boolean = builtins._internal->m_Boolean;
    603     m_String = builtins._internal->m_String;
    604     m_Number = builtins._internal->m_Number;
    605     m_Date = builtins._internal->m_Date;
    606     m_RegExp = builtins._internal->m_RegExp;
    607     m_Error = builtins._internal->m_Error;
    608    
    609     m_ObjectPrototype = builtins._internal->m_ObjectPrototype;
    610     m_FunctionPrototype = builtins._internal->m_FunctionPrototype;
    611     m_ArrayPrototype = builtins._internal->m_ArrayPrototype;
    612     m_BooleanPrototype = builtins._internal->m_BooleanPrototype;
    613     m_StringPrototype = builtins._internal->m_StringPrototype;
    614     m_NumberPrototype = builtins._internal->m_NumberPrototype;
    615     m_DatePrototype = builtins._internal->m_DatePrototype;
    616     m_RegExpPrototype = builtins._internal->m_RegExpPrototype;
    617     m_ErrorPrototype = builtins._internal->m_ErrorPrototype;
    618    
    619     m_EvalError = builtins._internal->m_EvalError;
    620     m_RangeError = builtins._internal->m_RangeError;
    621     m_ReferenceError = builtins._internal->m_ReferenceError;
    622     m_SyntaxError = builtins._internal->m_SyntaxError;
    623     m_TypeError = builtins._internal->m_TypeError;
    624     m_UriError = builtins._internal->m_UriError;
    625    
    626     m_EvalErrorPrototype = builtins._internal->m_EvalErrorPrototype;
    627     m_RangeErrorPrototype = builtins._internal->m_RangeErrorPrototype;
    628     m_ReferenceErrorPrototype = builtins._internal->m_ReferenceErrorPrototype;
    629     m_SyntaxErrorPrototype = builtins._internal->m_SyntaxErrorPrototype;
    630     m_TypeErrorPrototype = builtins._internal->m_TypeErrorPrototype;
    631     m_UriErrorPrototype = builtins._internal->m_UriErrorPrototype;
    632 }
    633 
    634 void Interpreter::startTimeoutCheck()
    635 {
    636     if (m_timeoutCheckCount == 0)
    637         resetTimeoutCheck();
    638    
    639     m_timeoutCheckCount++;
    640 }
    641 
    642 void Interpreter::stopTimeoutCheck()
    643 {
    644     m_timeoutCheckCount--;
    645 }
    646 
    647 void Interpreter::resetTimeoutCheck()
    648 {
    649     m_tickCount = 0;
    650     m_ticksUntilNextTimeoutCheck = initialTickCountThreshold;
    651     m_timeAtLastCheckTimeout = 0;
    652     m_timeExecuting = 0;
    653 }
    654 
    655 // Returns the current time in milliseconds
    656 // It doesn't matter what "current time" is here, just as long as
    657 // it's possible to measure the time difference correctly.
    658 static inline unsigned getCurrentTime() {
    659 #if HAVE(SYS_TIME_H)
    660     struct timeval tv;
    661     gettimeofday(&tv, 0);
    662     return tv.tv_sec * 1000 + tv.tv_usec / 1000;
    663 #elif PLATFORM(QT)
    664     QDateTime t = QDateTime::currentDateTime();
    665     return t.toTime_t() * 1000 + t.time().msec();
    666 #elif PLATFORM(WIN_OS)
    667     return timeGetTime();
    668 #else
    669 #error Platform does not have getCurrentTime function
    670 #endif
    671 }
    672 
    673 bool Interpreter::checkTimeout()
    674 {   
    675     m_tickCount = 0;
    676    
    677     unsigned currentTime = getCurrentTime();
    678 
    679     if (!m_timeAtLastCheckTimeout) {
    680         // Suspicious amount of looping in a script -- start timing it
    681         m_timeAtLastCheckTimeout = currentTime;
    682         return false;
    683     }
    684 
    685     unsigned timeDiff = currentTime - m_timeAtLastCheckTimeout;
    686 
    687     if (timeDiff == 0)
    688         timeDiff = 1;
    689    
    690     m_timeExecuting += timeDiff;
    691     m_timeAtLastCheckTimeout = currentTime;
    692    
    693     // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in
    694     // preferredScriptCheckTimeInterval
    695     m_ticksUntilNextTimeoutCheck = (unsigned)((float)preferredScriptCheckTimeInterval / timeDiff) * m_ticksUntilNextTimeoutCheck;
    696 
    697     // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the
    698     // preferred script check time interval.
    699     if (m_ticksUntilNextTimeoutCheck == 0)
    700         m_ticksUntilNextTimeoutCheck = initialTickCountThreshold;
    701 
    702     if (m_timeoutTime && m_timeExecuting > m_timeoutTime) {
    703         if (m_globalObject->shouldInterruptScript())
    704             return true;
    705        
    706         resetTimeoutCheck();
    707     }
    708    
    709     return false;
    710 }
    711 
    712 
    713 SavedBuiltins::SavedBuiltins() :
    714   _internal(0)
    715 {
    716 }
    717 
    718 SavedBuiltins::~SavedBuiltins()
    719 {
    720   delete _internal;
    721 }
    722 
    723 }
     167} // namespace KJS
  • trunk/JavaScriptCore/kjs/interpreter.h

    r28328 r28468  
    11/*
    2  *  This file is part of the KDE libraries
    32 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    43 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    5  *  Copyright (C) 2003 Apple Computer, Inc.
     4 *  Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
    65 *
    76 *  This library is free software; you can redistribute it and/or
     
    2221 */
    2322
    24 #ifndef _KJS_INTERPRETER_H_
    25 #define _KJS_INTERPRETER_H_
    26 
    27 #include "ExecState.h"
    28 #include "protect.h"
    29 #include "types.h"
    30 #include "value.h"
    31 #include <wtf/RefCounted.h>
     23#ifndef KJS_Interpreter_h
     24#define KJS_Interpreter_h
    3225
    3326namespace KJS {
    3427
    35   class ArrayObjectImp;
    36   class ArrayPrototype;
    37   class BooleanObjectImp;
    38   class BooleanPrototype;
    39   class DateObjectImp;
    40   class DatePrototype;
    41   class Debugger;
    42   class ErrorObjectImp;
    43   class ErrorPrototype;
    44   class EvalError;
    45   class EvalErrorPrototype;
    46   class FunctionObjectImp;
    47   class FunctionPrototype;
    48   class JSGlobalObject;
    49   class NativeErrorImp;
    50   class NativeErrorPrototype;
    51   class NumberObjectImp;
    52   class NumberPrototype;
    53   class ObjectObjectImp;
    54   class ObjectPrototype;
    55   class RangeError;
    56   class RangeErrorPrototype;
    57   class ReferenceError;
    58   class ReferenceError;
    59   class ReferenceErrorPrototype;
    60   class RegExpObjectImp;
    61   class RegExpPrototype;
    62   class RuntimeMethod;
    63   class SavedBuiltins;
    64   class ScopeChain;
    65   class StringObjectImp;
    66   class StringPrototype;
    67   class SyntaxErrorPrototype;
    68   class TypeError;
    69   class TypeErrorPrototype;
    70   class UriError;
    71   class UriErrorPrototype;
     28  class Completion;
     29  class ExecState;
     30  class JSValue;
     31  class UString;
     32
     33  struct UChar;
    7234 
    73   /**
    74    * Interpreter objects can be used to evaluate ECMAScript code. Each
    75    * interpreter has a global object which is used for the purposes of code
    76    * evaluation, and also provides access to built-in properties such as
    77    * " Object" and "Number".
    78    */
    7935  class Interpreter {
    80     friend class Collector;
    81     friend class JSGlobalObject;
    82 
    8336  public:
    84     /**
    85      * Creates a new interpreter. The global object must be set via setGlobalObject
    86      * before code is executed with this interpreter.
    87      */
    88     Interpreter();
    89     ~Interpreter();
    90 
    91     /**
    92      * Set the interpreter's global object. The supplied object will be used as the global
    93      * object for all scripts executed with this interpreter. During
    94      * construction, all the standard properties such as "Object" and "Number"
    95      * will be added to the global object.
    96      *
    97      * Note: You should not use the same global object for multiple
    98      * interpreters.
    99      *
    100      * This is due do the fact that the built-in properties are set in the
    101      * constructor, and if these objects have been modified from another
    102      * interpreter (e.g. a script modifying String.prototype), the changes will
    103      * be overridden.
    104      *
    105      * @param The object to use as the global object for this interpreter
    106      */
    107     void setGlobalObject(JSGlobalObject*);
    108 
    109     /**
    110      * Resets the global object's default properties and adds the default object
    111      * prototype to its prototype chain.
    112      */
    113     void resetGlobalObjectProperties();
    114 
    115     /**
    116      * Returns the object that is used as the global object during all script
    117      * execution performed by this interpreter
    118      */
    119     JSGlobalObject* globalObject() const;
    120 
    12137    /**
    12238     * Parses the supplied ECMAScript code and checks for syntax errors.
     
    12642     * otherwise a throw completion with the syntax error as its value.
    12743     */
    128     Completion checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code);
    129     Completion checkSyntax(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength);
     44    static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code);
     45    static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength);
    13046
    13147    /**
     
    14460     * @return A completion object representing the result of the execution.
    14561     */
    146     Completion evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0);
    147     Completion evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0);
    148 
    149     /**
    150      * Returns the builtin "Object" object. This is the object that was set
    151      * as a property of the global object during construction; if the property
    152      * is replaced by script code, this method will still return the original
    153      * object.
    154      *
    155      * @return The builtin "Object" object
    156      */
    157     JSObject *builtinObject() const;
    158 
    159     /**
    160      * Returns the builtin "Function" object.
    161      */
    162     JSObject *builtinFunction() const;
    163 
    164     /**
    165      * Returns the builtin "Array" object.
    166      */
    167     JSObject *builtinArray() const;
    168 
    169     /**
    170      * Returns the builtin "Boolean" object.
    171      */
    172     JSObject *builtinBoolean() const;
    173 
    174     /**
    175      * Returns the builtin "String" object.
    176      */
    177     JSObject *builtinString() const;
    178 
    179     /**
    180      * Returns the builtin "Number" object.
    181      */
    182     JSObject *builtinNumber() const;
    183 
    184     /**
    185      * Returns the builtin "Date" object.
    186      */
    187     JSObject *builtinDate() const;
    188 
    189     /**
    190      * Returns the builtin "RegExp" object.
    191      */
    192     RegExpObjectImp* builtinRegExp() const { return m_RegExp; }
    193 
    194     /**
    195      * Returns the builtin "Error" object.
    196      */
    197     JSObject *builtinError() const;
    198 
    199     /**
    200      * Returns the builtin "Object.prototype" object.
    201      */
    202     JSObject *builtinObjectPrototype() const;
    203 
    204     /**
    205      * Returns the builtin "Function.prototype" object.
    206      */
    207     JSObject *builtinFunctionPrototype() const;
    208 
    209     /**
    210      * Returns the builtin "Array.prototype" object.
    211      */
    212     JSObject *builtinArrayPrototype() const;
    213 
    214     /**
    215      * Returns the builtin "Boolean.prototype" object.
    216      */
    217     JSObject *builtinBooleanPrototype() const;
    218 
    219     /**
    220      * Returns the builtin "String.prototype" object.
    221      */
    222     JSObject *builtinStringPrototype() const;
    223 
    224     /**
    225      * Returns the builtin "Number.prototype" object.
    226      */
    227     JSObject *builtinNumberPrototype() const;
    228 
    229     /**
    230      * Returns the builtin "Date.prototype" object.
    231      */
    232     JSObject *builtinDatePrototype() const;
    233 
    234     /**
    235      * Returns the builtin "RegExp.prototype" object.
    236      */
    237     JSObject *builtinRegExpPrototype() const;
    238 
    239     /**
    240      * Returns the builtin "Error.prototype" object.
    241      */
    242     JSObject *builtinErrorPrototype() const;
    243 
    244     /**
    245      * The initial value of "Error" global property
    246      */
    247     JSObject *builtinEvalError() const;
    248     JSObject *builtinRangeError() const;
    249     JSObject *builtinReferenceError() const;
    250     JSObject *builtinSyntaxError() const;
    251     JSObject *builtinTypeError() const;
    252     JSObject *builtinURIError() const;
    253 
    254     JSObject *builtinEvalErrorPrototype() const;
    255     JSObject *builtinRangeErrorPrototype() const;
    256     JSObject *builtinReferenceErrorPrototype() const;
    257     JSObject *builtinSyntaxErrorPrototype() const;
    258     JSObject *builtinTypeErrorPrototype() const;
    259     JSObject *builtinURIErrorPrototype() const;
    260 
    261     enum CompatMode { NativeMode, IECompat, NetscapeCompat };
    262     /**
    263      * Call this to enable a compatibility mode with another browser.
    264      * (by default konqueror is in "native mode").
    265      * Currently, in KJS, this only changes the behavior of Date::getYear()
    266      * which returns the full year under IE.
    267      */
    268     void setCompatMode(CompatMode mode) { m_compatMode = mode; }
    269     CompatMode compatMode() const { return m_compatMode; }
     62    static Completion evaluate(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0);
     63    static Completion evaluate(ExecState*, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV = 0);
    27064   
    27165    static bool shouldPrintExceptions();
    27266    static void setShouldPrintExceptions(bool);
    273 
    274     void saveBuiltins (SavedBuiltins&) const;
    275     void restoreBuiltins (const SavedBuiltins&);
    276    
    277     // Chained list of interpreters (ring)
    278     static Interpreter* firstInterpreter() { return s_hook; }
    279     Interpreter* nextInterpreter() const { return next; }
    280     Interpreter* prevInterpreter() const { return prev; }
    281 
    282     Debugger* debugger() const { return m_debugger; }
    283     void setDebugger(Debugger* d) { m_debugger = d; }
    284    
    285     void setCurrentExec(ExecState* exec) { m_currentExec = exec; }
    286     ExecState* currentExec() const { return m_currentExec; }
    287        
    288     void setTimeoutTime(unsigned timeoutTime) { m_timeoutTime = timeoutTime; }
    289 
    290     void startTimeoutCheck();
    291     void stopTimeoutCheck();
    292    
    293     bool timedOut();
    294    
    295     ExecState m_globalExec; // This is temporarily public to help with bootstrapping.
    296 
    297 protected:
    298     unsigned m_timeoutTime;
    299 
    300 private:
    301     void init();
    302 
    303     void createObjectsForGlobalObjectProperties();
    304     void setGlobalObjectProperties();
    305 
    306     void resetTimeoutCheck();
    307     bool checkTimeout();
    308 
    309     // Uncopyable
    310     Interpreter(const Interpreter&);
    311     Interpreter operator=(const Interpreter&);
    312    
    313     ExecState* m_currentExec;
    314     JSGlobalObject* m_globalObject;
    315 
    316     // Chained list of interpreters (ring) - for collector
    317     static Interpreter* s_hook;
    318     Interpreter *next, *prev;
    319    
    320     int m_recursion;
    321    
    322     Debugger* m_debugger;
    323     CompatMode m_compatMode;
    324 
    325     unsigned m_timeAtLastCheckTimeout;
    326     unsigned m_timeExecuting;
    327     unsigned m_timeoutCheckCount;
    328    
    329     unsigned m_tickCount;
    330     unsigned m_ticksUntilNextTimeoutCheck;
    331 
    332 
    333     ObjectObjectImp* m_Object;
    334     FunctionObjectImp* m_Function;
    335     ArrayObjectImp* m_Array;
    336     BooleanObjectImp* m_Boolean;
    337     StringObjectImp* m_String;
    338     NumberObjectImp* m_Number;
    339     DateObjectImp* m_Date;
    340     RegExpObjectImp* m_RegExp;
    341     ErrorObjectImp* m_Error;
    342    
    343     ObjectPrototype* m_ObjectPrototype;
    344     FunctionPrototype* m_FunctionPrototype;
    345     ArrayPrototype* m_ArrayPrototype;
    346     BooleanPrototype* m_BooleanPrototype;
    347     StringPrototype* m_StringPrototype;
    348     NumberPrototype* m_NumberPrototype;
    349     DatePrototype* m_DatePrototype;
    350     RegExpPrototype* m_RegExpPrototype;
    351     ErrorPrototype* m_ErrorPrototype;
    352    
    353     NativeErrorImp* m_EvalError;
    354     NativeErrorImp* m_RangeError;
    355     NativeErrorImp* m_ReferenceError;
    356     NativeErrorImp* m_SyntaxError;
    357     NativeErrorImp* m_TypeError;
    358     NativeErrorImp* m_UriError;
    359    
    360     NativeErrorPrototype* m_EvalErrorPrototype;
    361     NativeErrorPrototype* m_RangeErrorPrototype;
    362     NativeErrorPrototype* m_ReferenceErrorPrototype;
    363     NativeErrorPrototype* m_SyntaxErrorPrototype;
    364     NativeErrorPrototype* m_TypeErrorPrototype;
    365     NativeErrorPrototype* m_UriErrorPrototype;
    36667  };
    36768
    368   inline bool Interpreter::timedOut()
    369   {
    370       m_tickCount++;
    371      
    372       if (m_tickCount != m_ticksUntilNextTimeoutCheck)
    373           return false;
    374      
    375       return checkTimeout();
    376   }
    377  
    378 } // namespace
     69} // namespace KJS
    37970
    380 #endif // _KJS_INTERPRETER_H_
     71#endif // KJS_Interpreter_h
  • trunk/JavaScriptCore/kjs/lexer.cpp

    r27861 r28468  
    2626
    2727#include "function.h"
    28 #include "interpreter.h"
    2928#include "nodes.h"
    3029#include <ctype.h>
  • trunk/JavaScriptCore/kjs/lookup.h

    r27609 r28468  
    2626#include "function.h"
    2727#include "identifier.h"
    28 #include "interpreter.h"
    2928#include "JSGlobalObject.h"
    3029#include "object.h"
     
    269268  /**
    270269   * This template method retrieves or create an object that is unique
    271    * (for a given interpreter) The first time this is called (for a given
     270   * (for a given global object) The first time this is called (for a given
    272271   * property name), the Object will be constructed, and set as a property
    273    * of the interpreter's global object. Later calls will simply retrieve
    274    * that cached object. Note that the object constructor must take 1 argument, exec.
     272   * of the global object. Later calls will simply retrieve that cached object.
     273   * Note that the object constructor must take 1 argument, exec.
    275274   */
    276275  template <class ClassCtor>
    277276  inline JSObject* cacheGlobalObject(ExecState* exec, const Identifier& propertyName)
    278277  {
    279     JSGlobalObject* globalObject = exec->lexicalInterpreter()->globalObject();
     278    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    280279    JSValue* obj = globalObject->getDirect(propertyName);
    281280    if (obj) {
     
    316315    bool getOwnPropertySlot(KJS::ExecState* , const KJS::Identifier&, KJS::PropertySlot&); \
    317316    ClassPrototype(KJS::ExecState* exec) \
    318       : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) { } \
     317      : KJS::JSObject(exec->lexicalGlobalObject()->objectPrototype()) { } \
    319318    \
    320319  };
     
    352351        } \
    353352        ClassFunction(KJS::ExecState* exec, int len, const KJS::Identifier& name) \
    354             : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name) \
     353            : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalGlobalObject()->functionPrototype()), name) \
    355354        { \
    356355            put(exec, exec->propertyNames().length, KJS::jsNumber(len), KJS::DontDelete | KJS::ReadOnly | KJS::DontEnum); \
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r28458 r28468  
    360360        }
    361361    }
    362     Debugger* dbg = exec->dynamicInterpreter()->debugger();
     362    Debugger* dbg = exec->dynamicGlobalObject()->debugger();
    363363    if (dbg && !dbg->hasHandledException(exec, exceptionValue)) {
    364364        bool cont = dbg->exception(exec, currentSourceId(exec), m_line, exceptionValue);
     
    393393bool StatementNode::hitStatement(ExecState* exec)
    394394{
    395   Debugger *dbg = exec->dynamicInterpreter()->debugger();
     395  Debugger *dbg = exec->dynamicGlobalObject()->debugger();
    396396  if (dbg)
    397397    return dbg->atStatement(exec, currentSourceId(exec), firstLine(), lastLine());
     
    491491JSValue* RegExpNode::evaluate(ExecState* exec)
    492492{
    493     return exec->lexicalInterpreter()->builtinRegExp()->createRegExpImp(exec, m_regExp);
     493    return exec->lexicalGlobalObject()->regExpConstructor()->createRegExpImp(exec, m_regExp);
    494494}
    495495
     
    615615JSValue *ElementNode::evaluate(ExecState *exec)
    616616{
    617   JSObject *array = exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty());
     617  JSObject *array = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, List::empty());
    618618  int length = 0;
    619619  for (ElementNode *n = this; n; n = n->next.get()) {
     
    646646    length = opt ? array->get(exec, exec->propertyNames().length)->toInt32(exec) : 0;
    647647  } else {
    648     JSValue *newArr = exec->lexicalInterpreter()->builtinArray()->construct(exec,List::empty());
     648    JSValue *newArr = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec,List::empty());
    649649    array = static_cast<JSObject*>(newArr);
    650650    length = 0;
     
    671671    return list->evaluate(exec);
    672672
    673   return exec->lexicalInterpreter()->builtinObject()->construct(exec,List::empty());
     673  return exec->lexicalGlobalObject()->objectConstructor()->construct(exec,List::empty());
    674674}
    675675
     
    686686JSValue *PropertyListNode::evaluate(ExecState *exec)
    687687{
    688   JSObject *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
     688  JSObject *obj = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, List::empty());
    689689 
    690690  for (PropertyListNode *p = this; p; p = p->next.get()) {
     
    946946  KJS_CHECKEXCEPTIONVALUE
    947947
    948   JSObject *thisObj =  exec->dynamicInterpreter()->globalObject();
     948  JSObject *thisObj =  exec->dynamicGlobalObject();
    949949
    950950  return func->call(exec, thisObj, argList);
     
    10011001      // that in host objects you always get a valid object for this.
    10021002      if (thisObj->isActivation())
    1003         thisObj = exec->dynamicInterpreter()->globalObject();
     1003        thisObj = exec->dynamicGlobalObject();
    10041004
    10051005      return func->call(exec, thisObj, argList);
     
    10621062    KJS_CHECKEXCEPTIONVALUE
    10631063
    1064     return func->call(exec, exec->dynamicInterpreter()->globalObject(), argList);
     1064    return func->call(exec, exec->dynamicGlobalObject(), argList);
    10651065}
    10661066
     
    37843784        exec->popIteration();
    37853785
    3786         if (exec->dynamicInterpreter()->timedOut())
     3786        if (exec->dynamicGlobalObject()->timedOut())
    37873787            return Completion(Interrupted);
    37883788
     
    38373837        exec->popIteration();
    38383838
    3839         if (exec->dynamicInterpreter()->timedOut())
     3839        if (exec->dynamicGlobalObject()->timedOut())
    38403840            return Completion(Interrupted);
    38413841   
     
    39033903        }
    39043904
    3905         if (exec->dynamicInterpreter()->timedOut())
     3905        if (exec->dynamicGlobalObject()->timedOut())
    39063906            return Completion(Interrupted);
    39073907
     
    45814581    processDeclarations(exec);
    45824582
    4583     if (Debugger* dbg = exec->dynamicInterpreter()->debugger()) {
     4583    if (Debugger* dbg = exec->dynamicGlobalObject()->debugger()) {
    45844584        if (!dbg->callEvent(exec, sourceId(), lineNo(), exec->function(), *exec->arguments())) {
    45854585            dbg->imp()->abort();
     
    45904590    Completion completion = BlockNode::execute(exec);
    45914591   
    4592     if (Debugger* dbg = exec->dynamicInterpreter()->debugger()) {
     4592    if (Debugger* dbg = exec->dynamicGlobalObject()->debugger()) {
    45934593        if (completion.complType() == Throw)
    45944594            exec->setException(completion.value());
     
    46214621  FunctionImp *func = new FunctionImp(exec, ident, body.get(), exec->scopeChain());
    46224622
    4623   JSObject *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
     4623  JSObject *proto = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, List::empty());
    46244624  proto->put(exec, exec->propertyNames().constructor, func, ReadOnly | DontDelete | DontEnum);
    46254625  func->put(exec, exec->propertyNames().prototype, proto, Internal|DontDelete);
     
    46574657
    46584658  FunctionImp* func = new FunctionImp(exec, ident, body.get(), exec->scopeChain());
    4659   JSObject* proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
     4659  JSObject* proto = exec->lexicalGlobalObject()->objectConstructor()->construct(exec, List::empty());
    46604660  proto->put(exec, exec->propertyNames().constructor, func, ReadOnly | DontDelete | DontEnum);
    46614661  func->put(exec, exec->propertyNames().prototype, proto, Internal | DontDelete);
  • trunk/JavaScriptCore/kjs/number_object.cpp

    r27413 r28468  
    464464JSObject *NumberObjectImp::construct(ExecState *exec, const List &args)
    465465{
    466   JSObject *proto = exec->lexicalInterpreter()->builtinNumberPrototype();
     466  JSObject *proto = exec->lexicalGlobalObject()->numberPrototype();
    467467  NumberInstance *obj(new NumberInstance(proto));
    468468
  • trunk/JavaScriptCore/kjs/object.cpp

    r28110 r28468  
    6969
    7070#if KJS_MAX_STACK > 0
    71   static int depth = 0; // sum of all concurrent interpreters
     71  static int depth = 0; // sum of all extant function calls
    7272
    7373#if JAVASCRIPT_CALL_TRACING
     
    366366{
    367367  /* Prefer String for Date objects */
    368   if ((hint == StringType) || (hint != StringType) && (hint != NumberType) && (_proto == exec->lexicalInterpreter()->builtinDatePrototype())) {
     368  if ((hint == StringType) || (hint != NumberType && _proto == exec->lexicalGlobalObject()->datePrototype())) {
    369369    if (JSValue* v = tryGetAndCallProperty(exec, this, exec->propertyNames().toString))
    370370      return v;
     
    600600  switch (errtype) {
    601601  case EvalError:
    602     cons = exec->lexicalInterpreter()->builtinEvalError();
     602    cons = exec->lexicalGlobalObject()->evalErrorConstructor();
    603603    break;
    604604  case RangeError:
    605     cons = exec->lexicalInterpreter()->builtinRangeError();
     605    cons = exec->lexicalGlobalObject()->rangeErrorConstructor();
    606606    break;
    607607  case ReferenceError:
    608     cons = exec->lexicalInterpreter()->builtinReferenceError();
     608    cons = exec->lexicalGlobalObject()->referenceErrorConstructor();
    609609    break;
    610610  case SyntaxError:
    611     cons = exec->lexicalInterpreter()->builtinSyntaxError();
     611    cons = exec->lexicalGlobalObject()->syntaxErrorConstructor();
    612612    break;
    613613  case TypeError:
    614     cons = exec->lexicalInterpreter()->builtinTypeError();
     614    cons = exec->lexicalGlobalObject()->typeErrorConstructor();
    615615    break;
    616616  case URIError:
    617     cons = exec->lexicalInterpreter()->builtinURIError();
     617    cons = exec->lexicalGlobalObject()->URIErrorConstructor();
    618618    break;
    619619  default:
    620     cons = exec->lexicalInterpreter()->builtinError();
     620    cons = exec->lexicalGlobalObject()->errorConstructor();
    621621    break;
    622622  }
  • trunk/JavaScriptCore/kjs/object.h

    r28110 r28468  
    2626#define KJS_OBJECT_H
    2727
     28#include "CommonIdentifiers.h"
     29#include "ExecState.h"
    2830#include "JSType.h"
    29 #include "CommonIdentifiers.h"
    30 #include "interpreter.h"
     31#include "list.h"
    3132#include "property_map.h"
    3233#include "property_slot.h"
  • trunk/JavaScriptCore/kjs/object_object.cpp

    r20310 r28468  
    182182  case NullType:
    183183  case UndefinedType:
    184       return new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype());
     184      return new JSObject(exec->lexicalGlobalObject()->objectPrototype());
    185185  default:
    186186      ASSERT_NOT_REACHED();
  • trunk/JavaScriptCore/kjs/regexp.h

    r27777 r28468  
    2424
    2525#include "ustring.h"
    26 #include <pcre.h>
     26#include <pcre/pcre.h>
    2727#include <sys/types.h>
    2828#include <wtf/OwnArrayPtr.h>
  • trunk/JavaScriptCore/kjs/regexp_object.cpp

    r27702 r28468  
    2626#include "error_object.h"
    2727#include "internal.h"
    28 #include "interpreter.h"
    2928#include "object.h"
    3029#include "operations.h"
     
    187186bool RegExpImp::match(ExecState* exec, const List& args)
    188187{
    189     RegExpObjectImp* regExpObj = exec->lexicalInterpreter()->builtinRegExp();
     188    RegExpObjectImp* regExpObj = exec->lexicalGlobalObject()->regExpConstructor();
    190189
    191190    UString input;
     
    231230{
    232231    return match(exec, args)
    233         ? exec->lexicalInterpreter()->builtinRegExp()->arrayOfMatches(exec)
     232        ? exec->lexicalGlobalObject()->regExpConstructor()->arrayOfMatches(exec)
    234233        :  jsNull();
    235234}
     
    322321{
    323322  unsigned lastNumSubpatterns = d->lastNumSubPatterns;
    324   ArrayInstance* arr = new ArrayInstance(exec->lexicalInterpreter()->builtinArrayPrototype(), lastNumSubpatterns + 1);
     323  ArrayInstance* arr = new ArrayInstance(exec->lexicalGlobalObject()->arrayPrototype(), lastNumSubpatterns + 1);
    325324  for (unsigned i = 0; i <= lastNumSubpatterns; ++i) {
    326325    int start = d->lastOvector[2 * i];
     
    456455{
    457456    return regExp->isValid()
    458         ? new RegExpImp(static_cast<RegExpPrototype*>(exec->lexicalInterpreter()->builtinRegExpPrototype()), regExp)
     457        ? new RegExpImp(static_cast<RegExpPrototype*>(exec->lexicalGlobalObject()->regExpPrototype()), regExp)
    459458        : throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
    460459}
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r28110 r28468  
    334334    bool global = reg->global();
    335335
    336     RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
     336    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
    337337
    338338    int lastIndex = 0;
     
    375375          args.append(sourceVal);
    376376
    377           substitutedReplacement = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
     377          substitutedReplacement = replacementFunction->call(exec, exec->dynamicGlobalObject(),
    378378                                                             args)->toString(exec);
    379379      } else
     
    425425      args.append(sourceVal);
    426426     
    427       replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
     427      replacementString = replacementFunction->call(exec, exec->dynamicGlobalObject(),
    428428                                                    args)->toString(exec);
    429429  }
     
    549549      reg = tmpReg = new RegExp(a0->toString(exec));
    550550    }
    551     RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
     551    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
    552552    int pos;
    553553    int matchLength;
     
    578578        result = jsNull();
    579579      } else {
    580         result = exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
     580        result = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);
    581581      }
    582582    }
     
    605605      reg = tmpReg = new RegExp(a0->toString(exec));
    606606    }
    607     RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
     607    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalGlobalObject()->regExpConstructor());
    608608    int pos;
    609609    int matchLength;
     
    661661    JSValue* a1 = args[1];
    662662
    663     JSObject *constructor = exec->lexicalInterpreter()->builtinArray();
     663    JSObject *constructor = exec->lexicalGlobalObject()->arrayConstructor();
    664664    JSObject *res = static_cast<JSObject *>(constructor->construct(exec,List::empty()));
    665665    JSValue* result = res;
     
    10191019JSObject *StringObjectImp::construct(ExecState *exec, const List &args)
    10201020{
    1021   JSObject *proto = exec->lexicalInterpreter()->builtinStringPrototype();
     1021  JSObject *proto = exec->lexicalGlobalObject()->stringPrototype();
    10221022  if (args.size() == 0)
    10231023    return new StringInstance(proto);
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r28328 r28468  
    2828#include "Parser.h"
    2929#include "collector.h"
     30#include "interpreter.h"
    3031#include "nodes.h"
    3132#include "object.h"
     
    165166
    166167      stopWatch.start();
    167       exec->dynamicInterpreter()->evaluate(fileName, 0, script.data());
     168      Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), fileName, 0, script.data());
    168169      stopWatch.stop();
    169170     
     
    177178        return throwError(exec, GeneralError, "Could not open file.");
    178179
    179       exec->dynamicInterpreter()->evaluate(fileName, 0, script.data());
     180      Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), fileName, 0, script.data());
    180181
    181182      return jsUndefined();
     
    225226{
    226227  GlobalImp* global = new GlobalImp;
    227   Interpreter* interp = new Interpreter;
    228   interp->setGlobalObject(global); // global now owns interp.
    229228
    230229  // add debug() function
     
    276275      prettyPrintScript(fileName, script);
    277276    else {
    278       Completion completion = globalObject->interpreter()->evaluate(fileName, 0, script.data());
     277      Completion completion = Interpreter::evaluate(globalObject->globalExec(), fileName, 0, script.data());
    279278      success = success && completion.complType() != Throw;
    280279    }
  • trunk/JavaScriptGlue/ChangeLog

    r28328 r28468  
     12007-12-04  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Third step in refactoring JSGlobalObject: Moved data members and data
     6        member access from Interpreter to JSGlobalObject. Replaced JSInterpreter
     7        subclass with JSGlobalObject subclass.
     8       
     9        * JSRun.cpp:
     10        (JSRun::JSRun):
     11        (JSRun::Evaluate):
     12        (JSRun::CheckSyntax):
     13        * JSRun.h:
     14        (JSGlueGlobalObject::JSGlueGlobalObject):
     15        * JSUtils.cpp:
     16        (KJSValueToCFTypeInternal):
     17        * JSValueWrapper.cpp:
     18        (getThreadGlobalExecState):
     19
    1202007-12-02  Geoffrey Garen  <ggaren@apple.com>
    221
  • trunk/JavaScriptGlue/JSRun.cpp

    r28328 r28468  
    3333    :   JSBase(kJSRunTypeID),
    3434        fSource(CFStringToUString(source)),
    35         fGlobalObject(new JSGlobalObject()),
     35        fGlobalObject(new JSGlueGlobalObject(inFlags)),
    3636        fFlags(inFlags)
    3737{
    38     Interpreter* interpreter = new JSInterpreter(fGlobalObject, inFlags);
    39     interpreter->setGlobalObject(fGlobalObject); // fGlobalObject now owns interpreter
    4038}
    4139
     
    6159Completion JSRun::Evaluate()
    6260{
    63     return fGlobalObject->interpreter()->evaluate(UString(), 0, fSource.data(), fSource.size());
     61    return Interpreter::evaluate(fGlobalObject->globalExec(), UString(), 0, fSource.data(), fSource.size());
    6462}
    6563
    6664bool JSRun::CheckSyntax()
    6765{
    68     return fGlobalObject->interpreter()->checkSyntax(UString(), 0, fSource.data(), fSource.size()).complType() != Throw;
     66    return Interpreter::checkSyntax(fGlobalObject->globalExec(), UString(), 0, fSource.data(), fSource.size()).complType() != Throw;
    6967}
  • trunk/JavaScriptGlue/JSRun.h

    r28328 r28468  
    3333#include "JSUtils.h"
    3434
    35 class JSInterpreter : public Interpreter {
     35class JSGlueGlobalObject : public JSGlobalObject {
    3636    public:
    37         JSInterpreter(JSGlobalObject *global, JSFlags flags) : fJSFlags(flags) { setGlobalObject(global); }
    38         JSInterpreter(JSGlobalObject *global) : fJSFlags(kJSFlagNone) { setGlobalObject(global); }
    39         JSInterpreter() : fJSFlags(kJSFlagNone) { }
     37        JSGlueGlobalObject(JSFlags flags) : fJSFlags(flags) { }
     38        JSGlueGlobalObject() : fJSFlags(kJSFlagNone) { }
    4039        JSFlags Flags() const { return fJSFlags; }
    4140
  • trunk/JavaScriptGlue/JSUtils.cpp

    r28082 r28468  
    274274                    {
    275275                        isArray = true;
    276                         JSInterpreter* intrepreter = (JSInterpreter*)exec->dynamicInterpreter();
    277                         if (intrepreter && (intrepreter->Flags() & kJSFlagConvertAssociativeArray)) {
     276                        JSGlueGlobalObject* globalObject = static_cast<JSGlueGlobalObject*>(exec->dynamicGlobalObject());
     277                        if (globalObject && (globalObject->Flags() & kJSFlagConvertAssociativeArray)) {
    278278                            PropertyNameArray propNames;
    279279                            object->getPropertyNames(exec, propNames);
  • trunk/JavaScriptGlue/JSValueWrapper.cpp

    r28328 r28468  
    8080    JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(pthread_getspecific(globalObjectKey));
    8181    if (!globalObject) {
    82         globalObject = new JSGlobalObject;
    83         Interpreter* interpreter = new JSInterpreter;
    84         interpreter->setGlobalObject(globalObject); // globalObject now owns interpreter
    85        
     82        globalObject = new JSGlueGlobalObject;
    8683        gcProtect(globalObject);
    8784        pthread_setspecific(globalObjectKey, globalObject);
  • trunk/WebCore/ChangeLog

    r28464 r28468  
     12007-12-04  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Third step in refactoring JSGlobalObject: Moved data members and data
     6        member access from Interpreter to JSGlobalObject. Changed Interpreter
     7        member functions to static functions. Same for the subclass,
     8        ScriptInterpreter.
     9       
     10        This is a big change, but it's mostly code motion and renaming.
     11       
    1122007-12-05  Darin Adler  <darin@apple.com>
    213
  • trunk/WebCore/WebCore.base.exp

    r28330 r28468  
    473473__ZN7WebCore8IntPointC1ERK8_NSPoint
    474474__ZN7WebCore8KJSProxy10initScriptEv
    475 __ZN7WebCore8KJSProxy11interpreterEv
    476475__ZN7WebCore8Settings14setJavaEnabledEb
    477476__ZN7WebCore8Settings16setUsesPageCacheEb
  • trunk/WebCore/bindings/js/JSCSSRuleCustom.cpp

    r21896 r28468  
    4949        return KJS::jsNull();
    5050
    51     KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
    52     KJS::DOMObject* ret = interp->getDOMObject(rule);
     51    KJS::DOMObject* ret = KJS::ScriptInterpreter::getDOMObject(rule);
    5352
    5453    if (ret)
     
    7978    }
    8079
    81     interp->putDOMObject(rule, ret);
     80    KJS::ScriptInterpreter::putDOMObject(rule, ret);
    8281    return ret;
    8382}
  • trunk/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp

    r25619 r28468  
    108108    // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute.
    109109    if (propertyName == "filter")
    110         return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalInterpreter()->builtinStringPrototype(), thisObj->impl()->getPropertyValue(prop));
     110        return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(), thisObj->impl()->getPropertyValue(prop));
    111111
    112112    return jsString(thisObj->impl()->getPropertyValue(prop));
  • trunk/WebCore/bindings/js/JSCSSValueCustom.cpp

    r26400 r28468  
    4848        return KJS::jsNull();
    4949
    50     KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
    51     KJS::DOMObject* ret = interp->getDOMObject(value);
     50    KJS::DOMObject* ret = KJS::ScriptInterpreter::getDOMObject(value);
    5251
    5352    if (ret)
     
    6766        ret = new JSCSSValue(exec, value);
    6867
    69     interp->putDOMObject(value, ret);
     68    KJS::ScriptInterpreter::putDOMObject(value, ret);
    7069    return ret;
    7170}
  • trunk/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp

    r28328 r28468  
    5555    if (!proxy)
    5656        return;
    57        
    58     ScriptInterpreter* interpreter = proxy->interpreter();
    59     ExecState* exec = proxy->globalObject()->globalExec();
     57
     58    JSGlobalObject* globalObject = proxy->globalObject();
     59    ExecState* exec = globalObject->globalExec();
    6060       
    6161    KJS::JSLock lock;
     
    8080    args.append(toJS(exec, resultSet));
    8181       
    82     interpreter->startTimeoutCheck();
     82    globalObject->startTimeoutCheck();
    8383    if (handleEventFunc)
    8484        handleEventFunc->call(exec, m_callback, args);
    8585    else
    8686        m_callback->call(exec, m_callback, args);
    87     interpreter->stopTimeoutCheck();
     87    globalObject->stopTimeoutCheck();
    8888       
    8989    if (exec->hadException()) {
  • trunk/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp

    r28328 r28468  
    5656        return true;
    5757       
    58     ExecState* exec = proxy->globalObject()->globalExec();
    59     ScriptInterpreter* interpreter = proxy->interpreter();
     58    JSGlobalObject* globalObject = proxy->globalObject();
     59    ExecState* exec = globalObject->globalExec();
    6060       
    6161    KJS::JSLock lock;
     
    8181       
    8282    JSValue *result;
    83     interpreter->startTimeoutCheck();
     83    globalObject->startTimeoutCheck();
    8484    if (handleEventFunc)
    8585        result = handleEventFunc->call(exec, m_callback, args);
    8686    else
    8787        result = m_callback->call(exec, m_callback, args);
    88     interpreter->stopTimeoutCheck();
     88    globalObject->stopTimeoutCheck();
    8989       
    9090    if (exec->hadException()) {
  • trunk/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp

    r28328 r28468  
    5555        return;
    5656       
    57     ExecState* exec = proxy->globalObject()->globalExec();
    58     ScriptInterpreter* interpreter = proxy->interpreter();
     57    JSGlobalObject* globalObject = proxy->globalObject();
     58    ExecState* exec = globalObject->globalExec();
    5959       
    6060    KJS::JSLock lock;
     
    7878    args.append(toJS(exec, transaction));
    7979
    80     interpreter->startTimeoutCheck();
     80    globalObject->startTimeoutCheck();
    8181    if (handleEventFunc)
    8282        handleEventFunc->call(exec, m_callback, args);
    8383    else
    8484        m_callback->call(exec, m_callback, args);
    85     interpreter->stopTimeoutCheck();
     85    globalObject->stopTimeoutCheck();
    8686       
    8787    if (exec->hadException()) {
  • trunk/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp

    r28328 r28468  
    5555        return true;
    5656       
    57     ExecState* exec = proxy->globalObject()->globalExec();
    58     ScriptInterpreter* interpreter = proxy->interpreter();
     57    JSGlobalObject* globalObject = proxy->globalObject();
     58    ExecState* exec = globalObject->globalExec();
    5959       
    6060    KJS::JSLock lock;
     
    7979
    8080    JSValue *result;
    81     interpreter->startTimeoutCheck();
     81    globalObject->startTimeoutCheck();
    8282    if (handleEventFunc)
    8383        result = handleEventFunc->call(exec, m_callback, args);
    8484    else
    8585        result = m_callback->call(exec, m_callback, args);
    86     interpreter->stopTimeoutCheck();
     86    globalObject->stopTimeoutCheck();
    8787       
    8888    if (exec->hadException()) {
  • trunk/WebCore/bindings/js/JSCustomVoidCallback.cpp

    r28328 r28468  
    5757        return;
    5858       
    59     ExecState* exec = proxy->globalObject()->globalExec();
    60     ScriptInterpreter* interpreter = proxy->interpreter();
     59    JSGlobalObject* globalObject = proxy->globalObject();
     60    ExecState* exec = globalObject->globalExec();
    6161       
    6262    KJS::JSLock lock;
     
    7979    List args;
    8080   
    81     interpreter->startTimeoutCheck();
     81    globalObject->startTimeoutCheck();
    8282    if (handleEventFunc)
    8383        handleEventFunc->call(exec, m_callback, args);
    8484    else
    8585        m_callback->call(exec, m_callback, args);
    86     interpreter->stopTimeoutCheck();
     86    globalObject->stopTimeoutCheck();
    8787       
    8888    if (exec->hadException()) {
  • trunk/WebCore/bindings/js/JSCustomXPathNSResolver.cpp

    r28328 r28468  
    8080    JSLock lock;
    8181
    82     ExecState* exec = proxy->globalObject()->globalExec();
    83     ScriptInterpreter* interpreter = proxy->interpreter();
    84 
     82    JSGlobalObject* globalObject = proxy->globalObject();
     83    ExecState* exec = globalObject->globalExec();
     84       
    8585    JSValue* lookupNamespaceURIFuncValue = m_customResolver->get(exec, "lookupNamespaceURI");
    8686    JSObject* lookupNamespaceURIFunc = 0;
     
    105105    String result;
    106106    JSValue* retval;
    107     interpreter->startTimeoutCheck();
     107    globalObject->startTimeoutCheck();
    108108    if (lookupNamespaceURIFunc)
    109109        retval = lookupNamespaceURIFunc->call(exec, m_customResolver, args);
    110110    else
    111111        retval = m_customResolver->call(exec, m_customResolver, args);
    112     interpreter->stopTimeoutCheck();
     112    globalObject->stopTimeoutCheck();
    113113
    114114    if (exec->hadException()) {
  • trunk/WebCore/bindings/js/JSDOMExceptionConstructor.cpp

    r27413 r28468  
    2828
    2929#include "ExceptionCode.h"
     30#include <kjs/object_object.h>
    3031
    3132#include "JSDOMExceptionConstructor.lut.h"
     
    5960JSDOMExceptionConstructor::JSDOMExceptionConstructor(ExecState* exec)
    6061{
    61     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     62    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    6263}
    6364
  • trunk/WebCore/bindings/js/JSDocumentCustom.cpp

    r28110 r28468  
    2121#include "JSDocument.h"
    2222
     23#include "DOMWindow.h"
    2324#include "Document.h"
    2425#include "Frame.h"
    2526#include "FrameLoader.h"
    2627#include "HTMLDocument.h"
     28#include "JSDOMWindow.h"
    2729#include "JSHTMLDocument.h"
    2830#include "kjs_binding.h"
    29 #include "kjs_window.h"
     31#include "kjs_proxy.h"
    3032
    3133#if ENABLE(SVG)
     
    6567    // IE and Mozilla both resolve the URL relative to the source frame,
    6668    // not the target frame.
    67     Frame* activeFrame = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->frame();
     69    Frame* activeFrame = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl()->frame();
    6870    if (activeFrame)
    6971        str = activeFrame->document()->completeURL(str);
    7072
    71     bool userGesture = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->wasRunByUserGesture();
     73    bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
    7274    frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture);
    7375}
     
    7880        return jsNull();
    7981
    80     ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
    81     JSDocument* ret =  static_cast<JSDocument*>(interp->getDOMObject(doc));
     82    JSDocument* ret = static_cast<JSDocument*>(ScriptInterpreter::getDOMObject(doc));
    8283    if (ret)
    8384        return ret;
     
    104105    }
    105106
    106     interp->putDOMObject(doc, ret);
     107    ScriptInterpreter::putDOMObject(doc, ret);
    107108
    108109    return ret;
  • trunk/WebCore/bindings/js/JSEventCustom.cpp

    r27277 r28468  
    5050#include "kjs_events.h"
    5151
     52using namespace KJS;
     53
    5254namespace WebCore {
    5355
    54 KJS::JSValue* JSEvent::clipboardData(KJS::ExecState* exec) const
     56JSValue* JSEvent::clipboardData(ExecState* exec) const
    5557{
    56     return impl()->isClipboardEvent() ? toJS(exec, impl()->clipboardData()) : KJS::jsUndefined();
     58    return impl()->isClipboardEvent() ? toJS(exec, impl()->clipboardData()) : jsUndefined();
    5759}
    5860
    59 KJS::JSValue* toJS(KJS::ExecState* exec, Event* event)
     61JSValue* toJS(ExecState* exec, Event* event)
    6062{
    61     KJS::JSLock lock;
     63    JSLock lock;
    6264
    6365    if (!event)
    64         return KJS::jsNull();
     66        return jsNull();
    6567
    66     KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
    6768
    68     KJS::DOMObject* ret = interp->getDOMObject(event);
     69    DOMObject* ret = ScriptInterpreter::getDOMObject(event);
    6970    if (ret)
    7071        return ret;
     
    8990        ret = new JSEvent(exec, event);
    9091
    91     interp->putDOMObject(event, ret);
     92    ScriptInterpreter::putDOMObject(event, ret);
    9293    return ret;
    9394}
  • trunk/WebCore/bindings/js/JSHTMLAudioElementConstructor.cpp

    r27277 r28468  
    4141    : m_doc(d)
    4242{
    43     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     43    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    4444    put(exec, exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
    4545}
  • trunk/WebCore/bindings/js/JSHTMLCollectionCustom.cpp

    r28327 r28468  
    3333#include <wtf/Vector.h>
    3434
     35using namespace KJS;
     36
    3537namespace WebCore {
    3638
    37 static KJS::JSValue* getNamedItems(KJS::ExecState* exec, HTMLCollection* impl, const KJS::Identifier& propertyName)
     39static JSValue* getNamedItems(ExecState* exec, HTMLCollection* impl, const Identifier& propertyName)
    3840{
    3941    Vector<RefPtr<Node> > namedItems;
     
    4143
    4244    if (namedItems.isEmpty())
    43         return KJS::jsUndefined();
     45        return jsUndefined();
    4446
    4547    if (namedItems.size() == 1)
     
    5153// HTMLCollections are strange objects, they support both get and call,
    5254// so that document.forms.item(0) and document.forms(0) both work.
    53 KJS::JSValue* JSHTMLCollection::callAsFunction(KJS::ExecState* exec, KJS::JSObject*, const KJS::List& args)
     55JSValue* JSHTMLCollection::callAsFunction(ExecState* exec, JSObject*, const List& args)
    5456{
    5557    if (args.size() < 1)
    56         return KJS::jsUndefined();
     58        return jsUndefined();
    5759
    5860    // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
     
    6466        // Support for document.all(<index>) etc.
    6567        bool ok;
    66         KJS::UString string = args[0]->toString(exec);
     68        UString string = args[0]->toString(exec);
    6769        unsigned index = string.toUInt32(&ok, false);
    6870        if (ok)
     
    7072
    7173        // Support for document.images('<name>') etc.
    72         return getNamedItems(exec, collection, KJS::Identifier(string));
     74        return getNamedItems(exec, collection, Identifier(string));
    7375    }
    7476
    7577    // The second arg, if set, is the index of the item we want
    7678    bool ok;
    77     KJS::UString string = args[0]->toString(exec);
     79    UString string = args[0]->toString(exec);
    7880    unsigned index = args[1]->toString(exec).toUInt32(&ok, false);
    7981    if (ok) {
     
    8890    }
    8991
    90     return KJS::jsUndefined();
     92    return jsUndefined();
    9193}
    9294
     
    9698}
    9799
    98 bool JSHTMLCollection::canGetItemsForName(KJS::ExecState* exec, HTMLCollection* thisObj, const KJS::Identifier& propertyName)
     100bool JSHTMLCollection::canGetItemsForName(ExecState* exec, HTMLCollection* thisObj, const Identifier& propertyName)
    99101{
    100102    return !getNamedItems(exec, thisObj, propertyName)->isUndefined();
    101103}
    102104
    103 KJS::JSValue* JSHTMLCollection::nameGetter(KJS::ExecState* exec, KJS::JSObject* originalObject, const KJS::Identifier& propertyName, const KJS::PropertySlot& slot)
     105JSValue* JSHTMLCollection::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
    104106{
    105107    JSHTMLCollection* thisObj = static_cast<JSHTMLCollection*>(slot.slotBase());
     
    107109}
    108110
    109 KJS::JSValue* JSHTMLCollection::item(KJS::ExecState* exec, const KJS::List& args)
     111JSValue* JSHTMLCollection::item(ExecState* exec, const List& args)
    110112{
    111113    bool ok;
     
    113115    if (ok)
    114116        return toJS(exec, impl()->item(index));
    115     return getNamedItems(exec, impl(), KJS::Identifier(args[0]->toString(exec)));
     117    return getNamedItems(exec, impl(), Identifier(args[0]->toString(exec)));
    116118}
    117119
    118 KJS::JSValue* JSHTMLCollection::namedItem(KJS::ExecState* exec, const KJS::List& args)
     120JSValue* JSHTMLCollection::namedItem(ExecState* exec, const List& args)
    119121{
    120     return getNamedItems(exec, impl(), KJS::Identifier(args[0]->toString(exec)));
     122    return getNamedItems(exec, impl(), Identifier(args[0]->toString(exec)));
    121123}
    122124
    123 KJS::JSValue* toJS(KJS::ExecState* exec, HTMLCollection* collection)
     125JSValue* toJS(ExecState* exec, HTMLCollection* collection)
    124126{
    125127    if (!collection)
    126         return KJS::jsNull();
     128        return jsNull();
    127129
    128     KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
    129     KJS::DOMObject* ret = interp->getDOMObject(collection);
     130    DOMObject* ret = ScriptInterpreter::getDOMObject(collection);
    130131
    131132    if (ret)
     
    144145    }
    145146
    146     interp->putDOMObject(collection, ret);
     147    ScriptInterpreter::putDOMObject(collection, ret);
    147148    return ret;
    148149}
  • trunk/WebCore/bindings/js/JSHTMLOptionElementConstructor.cpp

    r25754 r28468  
    3333    : m_doc(d)
    3434{
    35     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     35    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    3636    put(exec, exec->propertyNames().length, jsNumber(4), ReadOnly|DontDelete|DontEnum);
    3737}
  • trunk/WebCore/bindings/js/JSNamedNodesCollection.cpp

    r27413 r28468  
    4444    : m_nodes(nodes)
    4545{
    46     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     46    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    4747}
    4848
  • trunk/WebCore/bindings/js/JSNodeCustom.cpp

    r28110 r28468  
    6161#endif
    6262
     63using namespace KJS;
     64
    6365namespace WebCore {
    6466
    6567typedef int ExpectionCode;
    6668
    67 KJS::JSValue* JSNode::insertBefore(KJS::ExecState* exec, const KJS::List& args)
     69JSValue* JSNode::insertBefore(ExecState* exec, const List& args)
    6870{
    6971    ExceptionCode ec = 0;
    7072    bool ok = impl()->insertBefore(toNode(args[0]), toNode(args[1]), ec);
    71     KJS::setDOMException(exec, ec);
     73    setDOMException(exec, ec);
    7274    if (ok)
    7375        return args[0];
    74     return KJS::jsNull();
    75 }
    76 
    77 KJS::JSValue* JSNode::replaceChild(KJS::ExecState* exec, const KJS::List& args)
     76    return jsNull();
     77}
     78
     79JSValue* JSNode::replaceChild(ExecState* exec, const List& args)
    7880{
    7981    ExceptionCode ec = 0;
    8082    bool ok = impl()->replaceChild(toNode(args[0]), toNode(args[1]), ec);
    81     KJS::setDOMException(exec, ec);
     83    setDOMException(exec, ec);
    8284    if (ok)
    8385        return args[1];
    84     return KJS::jsNull();
    85 }
    86 
    87 KJS::JSValue* JSNode::removeChild(KJS::ExecState* exec, const KJS::List& args)
     86    return jsNull();
     87}
     88
     89JSValue* JSNode::removeChild(ExecState* exec, const List& args)
    8890{
    8991    ExceptionCode ec = 0;
    9092    bool ok = impl()->removeChild(toNode(args[0]), ec);
    91     KJS::setDOMException(exec, ec);
     93    setDOMException(exec, ec);
    9294    if (ok)
    9395        return args[0];
    94     return KJS::jsNull();
    95 }
    96 
    97 KJS::JSValue* JSNode::appendChild(KJS::ExecState* exec, const KJS::List& args)
     96    return jsNull();
     97}
     98
     99JSValue* JSNode::appendChild(ExecState* exec, const List& args)
    98100{
    99101    ExceptionCode ec = 0;
    100102    bool ok = impl()->appendChild(toNode(args[0]), ec);
    101     KJS::setDOMException(exec, ec);
     103    setDOMException(exec, ec);
    102104    if (ok)
    103105        return args[0];
    104     return KJS::jsNull();
     106    return jsNull();
    105107}
    106108
     
    134136    root->m_inSubtreeMark = true;
    135137    for (Node* nodeToMark = root; nodeToMark; nodeToMark = nodeToMark->traverseNextNode()) {
    136         JSNode* wrapper = KJS::ScriptInterpreter::getDOMNodeForDocument(m_impl->document(), nodeToMark);
     138        JSNode* wrapper = ScriptInterpreter::getDOMNodeForDocument(m_impl->document(), nodeToMark);
    137139        if (wrapper) {
    138140            if (!wrapper->marked())
     
    154156}
    155157
    156 KJS::JSValue* toJS(KJS::ExecState* exec, PassRefPtr<Node> n)
     158JSValue* toJS(ExecState* exec, PassRefPtr<Node> n)
    157159{
    158160    Node* node = n.get();
    159161    if (!node)
    160         return KJS::jsNull();
    161 
    162     KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
     162        return jsNull();
     163
    163164    Document* doc = node->document();
    164     JSNode* ret = interp->getDOMNodeForDocument(doc, node);
     165    JSNode* ret = ScriptInterpreter::getDOMNodeForDocument(doc, node);
    165166    if (ret)
    166167        return ret;
     
    214215    }
    215216
    216     interp->putDOMNodeForDocument(doc, node, ret);
     217    ScriptInterpreter::putDOMNodeForDocument(doc, node, ret);
    217218
    218219    return ret;
  • trunk/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp

    r26787 r28468  
    5151    }
    5252
    53     JSObject* object = new JSObject(exec->lexicalInterpreter()->builtinObjectPrototype());
     53    JSObject* object = new JSObject(exec->lexicalGlobalObject()->objectPrototype());
    5454
    5555    unsigned numColumns = m_impl->columnNames().size();
  • trunk/WebCore/bindings/js/JSStyleSheetCustom.cpp

    r21911 r28468  
    3131#include "StyleSheet.h"
    3232
     33using namespace KJS;
     34
    3335namespace WebCore {
    3436
    35 KJS::JSValue* toJS(KJS::ExecState* exec, StyleSheet* styleSheet)
     37JSValue* toJS(ExecState* exec, StyleSheet* styleSheet)
    3638{
    3739    if (!styleSheet)
    38         return KJS::jsNull();
     40        return jsNull();
    3941
    40     KJS::ScriptInterpreter* interp = static_cast<KJS::ScriptInterpreter*>(exec->dynamicInterpreter());
    41     KJS::DOMObject* ret = interp->getDOMObject(styleSheet);
     42    DOMObject* ret = ScriptInterpreter::getDOMObject(styleSheet);
    4243    if (ret)
    4344        return ret;
     
    4849        ret = new JSStyleSheet(exec, styleSheet);
    4950
    50     interp->putDOMObject(styleSheet, ret);
     51    ScriptInterpreter::putDOMObject(styleSheet, ret);
    5152    return ret;
    5253}
  • trunk/WebCore/bindings/js/JSXMLHttpRequest.cpp

    r28110 r28468  
    6262    : doc(d)
    6363{
    64     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     64    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    6565    putDirect(exec->propertyNames().prototype, JSXMLHttpRequestPrototype::self(exec), None);
    6666}
  • trunk/WebCore/bindings/js/JSXSLTProcessor.cpp

    r27608 r28468  
    187187XSLTProcessorConstructorImp::XSLTProcessorConstructorImp(ExecState *exec)
    188188{
    189     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     189    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    190190    putDirect(exec->propertyNames().prototype, XSLTProcessorPrototype::self(exec), None);
    191191}
  • trunk/WebCore/bindings/js/kjs_binding.cpp

    r28328 r28468  
    138138}
    139139
    140 ScriptInterpreter::ScriptInterpreter(JSGlobalObject* global, Frame* frame)
    141     : m_frame(frame)
    142     , m_currentEvent(0)
    143     , m_inlineCode(false)
    144     , m_timerCallback(false)
    145 {
    146     setGlobalObject(global);
    147     // Time in milliseconds before the script timeout handler kicks in.
    148     setTimeoutTime(10000);
    149 }
    150 
    151140DOMObject* ScriptInterpreter::getDOMObject(void* objectHandle)
    152141{
     
    243232        addWrapper(wrapper);
    244233    }
    245 }
    246 
    247 bool ScriptInterpreter::wasRunByUserGesture() const
    248 {
    249     if (m_currentEvent) {
    250         const AtomicString& type = m_currentEvent->type();
    251         bool eventOk = ( // mouse events
    252             type == clickEvent || type == mousedownEvent ||
    253             type == mouseupEvent || type == dblclickEvent ||
    254             // keyboard events
    255             type == keydownEvent || type == keypressEvent ||
    256             type == keyupEvent ||
    257             // other accepted events
    258             type == selectEvent || type == changeEvent ||
    259             type == focusEvent || type == blurEvent ||
    260             type == submitEvent);
    261         if (eventOk)
    262             return true;
    263     } else { // no event
    264         if (m_inlineCode && !m_timerCallback)
    265             // This is the <a href="javascript:window.open('...')> case -> we let it through
    266             return true;
    267         // This is the <script>window.open(...)</script> case or a timer callback -> block it
    268     }
    269     return false;
    270234}
    271235
  • trunk/WebCore/bindings/js/kjs_binding.h

    r28328 r28468  
    2525
    2626#include <kjs/function.h>
     27#include <kjs/interpreter.h>
    2728#include <kjs/lookup.h>
    2829#include <wtf/Noncopyable.h>
     
    6667    };
    6768
    68     /**
    69      * We inherit from Interpreter, to save a pointer to the HTML part
    70      * that the interpreter runs for.
    71      * The interpreter also stores the DOM object -> KJS::DOMObject cache.
    72      */
    7369    class ScriptInterpreter : public Interpreter {
    7470    public:
    75         ScriptInterpreter(JSGlobalObject*, WebCore::Frame*);
    76 
    7771        static DOMObject* getDOMObject(void* objectHandle);
    7872        static void putDOMObject(void* objectHandle, DOMObject*);
     
    8579        static void updateDOMNodeDocument(WebCore::Node*, WebCore::Document* oldDoc, WebCore::Document* newDoc);
    8680        static void markDOMNodesForDocument(WebCore::Document*);
    87 
    88         WebCore::Frame* frame() const { return m_frame; }
    89 
    90         /**
    91          * Set the event that is triggering the execution of a script, if any
    92          */
    93         void setCurrentEvent(WebCore::Event* event) { m_currentEvent = event; }
    94         void setInlineCode(bool inlineCode) { m_inlineCode = inlineCode; }
    95         void setProcessingTimerCallback(bool timerCallback) { m_timerCallback = timerCallback; }
    96 
    97         /**
    98          * "Smart" window.open policy
    99          */
    100         bool wasRunByUserGesture() const;
    101 
    102         WebCore::Event* getCurrentEvent() const { return m_currentEvent; }
    103 
    104     private:
    105    
    106         WebCore::Frame* m_frame;
    107         WebCore::Event* m_currentEvent;
    108         bool m_inlineCode;
    109         bool m_timerCallback;
    11081    };
    11182
     
    11788        if (!domObj)
    11889            return jsNull();
    119         ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
    120         if (DOMObject* ret = interp->getDOMObject(domObj))
     90        if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
    12191            return ret;
    12292        DOMObject* ret = new KJSDOMObj(exec, domObj);
    123         interp->putDOMObject(domObj, ret);
     93        ScriptInterpreter::putDOMObject(domObj, ret);
    12494        return ret;
    12595    }
     
    133103        if (!domObj)
    134104            return jsNull();
    135         ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
    136         if (DOMObject* ret = interp->getDOMObject(domObj))
     105        if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
    137106            return ret;
    138107        DOMObject* ret = new KJSDOMObj(exec, domObj, context);
    139         interp->putDOMObject(domObj, ret);
     108        ScriptInterpreter::putDOMObject(domObj, ret);
    140109        return ret;
    141110    }
  • trunk/WebCore/bindings/js/kjs_css.cpp

    r27413 r28468  
    4848    : m_color(color)
    4949{
    50     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     50    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    5151}
    5252
  • trunk/WebCore/bindings/js/kjs_dom.cpp

    r26816 r28468  
    6363
    6464  // Check to see if the currently executing interpreter is allowed to access the specified node
    65   KJS::Window* win = KJS::Window::retrieveWindow(n->document()->frame());
     65  Window* win = Window::retrieveWindow(n->document()->frame());
    6666  return win && win->isSafeScript(exec);
    6767}
     
    8383        return toJS(exec, node);
    8484
    85     XMLHttpRequest* xhr = target->toXMLHttpRequest();
    86     if (xhr) {
     85    if (XMLHttpRequest* xhr = target->toXMLHttpRequest())
    8786        // XMLHttpRequest is always created via JS, so we don't need to use cacheDOMObject() here.
    88         ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
    89         return interp->getDOMObject(xhr);
    90     }
     87        return ScriptInterpreter::getDOMObject(xhr);
    9188
    9289    // There are two kinds of EventTargets: EventTargetNode and XMLHttpRequest.
  • trunk/WebCore/bindings/js/kjs_events.cpp

    r28328 r28468  
    3939#include "kjs_proxy.h"
    4040#include "kjs_window.h"
     41#include <kjs/array_object.h>
     42#include <kjs/function_object.h>
    4143
    4244#include "kjs_events.lut.h"
     
    8082    JSLock lock;
    8183
    82     ScriptInterpreter* interpreter = proxy->interpreter();
    83     ExecState* exec = proxy->globalObject()->globalExec();
     84    JSGlobalObject* globalObject = proxy->globalObject();
     85    ExecState* exec = globalObject->globalExec();
    8486
    8587    JSValue* handleEventFuncValue = listener->get(exec, "handleEvent");
     
    9799        args.append(toJS(exec, event));
    98100
    99         // Set the event we're handling in the KJS::Window object
    100101        window->setCurrentEvent(event);
    101         // ... and in the interpreter
    102         interpreter->setCurrentEvent(event);
    103102
    104103        JSValue* retval;
    105104        if (handleEventFunc) {
    106             interpreter->startTimeoutCheck();
     105            globalObject->startTimeoutCheck();
    107106            retval = handleEventFunc->call(exec, listener, args);
    108107        } else {
     
    112111            else
    113112                thisObj = static_cast<JSObject*>(toJS(exec, event->currentTarget()));
    114             interpreter->startTimeoutCheck();
     113            globalObject->startTimeoutCheck();
    115114            retval = listener->call(exec, thisObj, args);
    116115        }
    117         interpreter->stopTimeoutCheck();
     116        globalObject->stopTimeoutCheck();
    118117
    119118        window->setCurrentEvent(0);
    120         interpreter->setCurrentEvent(0);
    121119
    122120        if (exec->hadException()) {
     
    297295
    298296    if (proxy) {
    299         ScriptInterpreter* interpreter = proxy->interpreter();
    300297        ExecState* exec = proxy->globalObject()->globalExec();
    301298
    302299        JSLock lock;
    303         JSObject* constr = interpreter->builtinFunction();
     300        JSObject* constr = proxy->globalObject()->functionConstructor();
    304301        List args;
    305302
     
    406403                for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it)
    407404                    list.append(jsString(UString(*it)));
    408                 return exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
     405                return exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);
    409406            }
    410407        }
  • trunk/WebCore/bindings/js/kjs_events.h

    r28110 r28468  
    2626#include "kjs_dom.h"
    2727#include "kjs_html.h"
    28 
     28#include <kjs/protect.h>
    2929
    3030namespace KJS {
  • trunk/WebCore/bindings/js/kjs_html.cpp

    r28328 r28468  
    3737    : m_doc(doc)
    3838{
    39     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     39    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    4040}
    4141
  • trunk/WebCore/bindings/js/kjs_navigator.cpp

    r27608 r28468  
    2626#include "AtomicString.h"
    2727#include "CookieJar.h"
     28#include "DOMWindow.h"
    2829#include "Document.h"
    2930#include "Frame.h"
     
    3334#include "PlugInInfoStore.h"
    3435#include "Settings.h"
     36#include "kjs_window.h"
     37#include <kjs/object_object.h>
    3538
    3639#ifndef WEBCORE_NAVIGATOR_PLATFORM
     
    176179    : m_frame(f)
    177180{
    178     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     181    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    179182}
    180183
     
    249252PluginBase::PluginBase(ExecState *exec)
    250253{
    251     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     254    setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    252255
    253256    cachePluginDataIfNecessary();
     
    513516        return jsString(m_info->desc);
    514517    case EnabledPlugin: {
    515         ScriptInterpreter *interpreter = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter());
    516         Frame *frame = interpreter->frame();
     518        Frame* frame = Window::retrieveActive(exec)->impl()->frame();
    517519        ASSERT(frame);
    518520        Settings* settings = frame->settings();
  • trunk/WebCore/bindings/js/kjs_proxy.cpp

    r28328 r28468  
    2424#include "Chrome.h"
    2525#include "Document.h"
     26#include "Event.h"
     27#include "EventNames.h"
    2628#include "Frame.h"
    2729#include "FrameLoader.h"
     
    3941
    4042using namespace KJS;
     43using namespace WebCore::EventNames;
    4144
    4245namespace WebCore {
     
    4548    : m_frame(frame)
    4649    , m_handlerLineno(0)
     50    , m_processingTimerCallback(0)
     51    , m_processingInlineCode(0)
    4752{
    4853}
     
    5055KJSProxy::~KJSProxy()
    5156{
    52     // Check for <rdar://problem/4876466>. In theory, no JS should be executing
    53     // in our interpreter.
    54     ASSERT(!m_globalObject || !m_globalObject->interpreter()->currentExec());
     57    // Check for <rdar://problem/4876466>. In theory, no JS should be executing now.
     58    ASSERT(!m_globalObject || !m_globalObject->currentExec());
    5559   
    5660    if (m_globalObject) {
    5761        m_globalObject = 0;
    5862   
    59         // It's likely that destroying the interpreter has created a lot of garbage.
     63        // It's likely that releasing the global object has created a lot of garbage.
    6064        gcController().garbageCollectSoon();
    6165    }
     
    7276    // expected value in all cases.
    7377    // See smart window.open policy for where this is used.
    74     bool inlineCode = filename.isNull();
    75 
    76     ScriptInterpreter* interpreter = static_cast<ScriptInterpreter*>(m_globalObject->interpreter());
    7778    ExecState* exec = m_globalObject->globalExec();
    78 
    79     interpreter->setInlineCode(inlineCode);
     79    m_processingInlineCode = filename.isNull();
    8080
    8181    JSLock lock;
     
    8787    JSValue* thisNode = Window::retrieve(m_frame);
    8888 
    89     interpreter->startTimeoutCheck();
    90     Completion comp = interpreter->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
    91     interpreter->stopTimeoutCheck();
     89    m_globalObject->startTimeoutCheck();
     90    Completion comp = Interpreter::evaluate(exec, filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
     91    m_globalObject->stopTimeoutCheck();
    9292 
    93     if (comp.complType() == Normal || comp.complType() == ReturnValue)
     93    if (comp.complType() == Normal || comp.complType() == ReturnValue) {
     94        m_processingInlineCode = false;
    9495        return comp.value();
     96    }
    9597
    9698    if (comp.complType() == Throw) {
     
    102104    }
    103105
     106    m_processingInlineCode = false;
    104107    return 0;
    105108}
    106109
    107 void KJSProxy::clear() {
    108   // clear resources allocated by the interpreter, and make it ready to be used by another page
    109   // We have to keep it, so that the Window object for the frame remains the same.
    110   // (we used to delete and re-create it, previously)
    111   if (m_globalObject)
    112     m_globalObject->clear();
     110void KJSProxy::clear()
     111{
     112    // clear resources allocated by the global object, and make it ready to be used by another page
     113    // We have to keep it, so that the Window object for the frame remains the same.
     114    // (we used to delete and re-create it, previously)
     115    if (m_globalObject)
     116        m_globalObject->clear();
    113117}
    114118
     
    135139  // e.g. an image load or mouse move. Once the event has been dispatched, it is forgotten
    136140  // by the DOM implementation and so does not need to be cached still by the interpreter
    137   if (!m_globalObject)
    138     return;
    139   static_cast<ScriptInterpreter*>(m_globalObject->interpreter())->forgetDOMObject(event);
    140 }
    141 
    142 ScriptInterpreter* KJSProxy::interpreter()
    143 {
    144     initScriptIfNeeded();
    145     return static_cast<ScriptInterpreter*>(m_globalObject->interpreter());
     141  ScriptInterpreter::forgetDOMObject(event);
    146142}
    147143
    148144void KJSProxy::initScript()
    149145{
    150   if (m_globalObject)
    151     return;
    152 
    153   // Build the global object - which is a Window instance
    154   JSLock lock;
    155  
    156   m_globalObject = new JSDOMWindow(m_frame->domWindow());
    157   ScriptInterpreter* interpreter = new ScriptInterpreter(m_globalObject, m_frame); // m_globalObject now owns interpreter
    158 
    159   String userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->URL() : KURL());
    160   if (userAgent.find("Microsoft") >= 0 || userAgent.find("MSIE") >= 0)
    161     interpreter->setCompatMode(Interpreter::IECompat);
    162   else
    163     // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
    164     if (userAgent.find("Mozilla") >= 0 && userAgent.find("compatible") == -1)
    165       interpreter->setCompatMode(Interpreter::NetscapeCompat);
    166 
    167   m_frame->loader()->dispatchWindowObjectAvailable();
     146    if (m_globalObject)
     147        return;
     148
     149    JSLock lock;
     150
     151    m_globalObject = new JSDOMWindow(m_frame->domWindow());
     152
     153    // FIXME: We can get rid of this (and eliminate compatMode entirely).
     154    String userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->URL() : KURL());
     155    if (userAgent.find("Microsoft") >= 0 || userAgent.find("MSIE") >= 0)
     156        m_globalObject->setCompatMode(IECompat);
     157    else {
     158        // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
     159        if (userAgent.find("Mozilla") >= 0 && userAgent.find("compatible") == -1)
     160            m_globalObject->setCompatMode(NetscapeCompat);
     161    }
     162
     163    m_frame->loader()->dispatchWindowObjectAvailable();
    168164}
    169165   
     
    177173}
    178174
     175bool KJSProxy::processingUserGesture() const
     176{
     177    if (!m_globalObject)
     178        return false;
     179
     180    if (Event* event = m_globalObject->currentEvent()) {
     181        const AtomicString& type = event->type();
     182        if ( // mouse events
     183            type == clickEvent || type == mousedownEvent ||
     184            type == mouseupEvent || type == dblclickEvent ||
     185            // keyboard events
     186            type == keydownEvent || type == keypressEvent ||
     187            type == keyupEvent ||
     188            // other accepted events
     189            type == selectEvent || type == changeEvent ||
     190            type == focusEvent || type == blurEvent ||
     191            type == submitEvent)
     192            return true;
     193    } else { // no event
     194        if (m_processingInlineCode && !m_processingTimerCallback) {
     195            // This is the <a href="javascript:window.open('...')> case -> we let it through
     196            return true;
     197        }
     198        // This is the <script>window.open(...)</script> case or a timer callback -> block it
     199    }
     200    return false;
     201}
     202
    179203} // namespace WebCore
  • trunk/WebCore/bindings/js/kjs_proxy.h

    r28328 r28468  
    2929    class JSGlobalObject;
    3030    class JSValue;
    31     class ScriptInterpreter;
    3231}
    3332
     
    4039class String;
    4140
    42 // FIXME: Rename this class to JSController and merge functions from
    43 // ScriptInterpreter into it.
     41// FIXME: Rename this class to JSController and the Frame function to javaScript().
    4442
    4543class KJSProxy {
     
    4846    ~KJSProxy();
    4947
    50     bool haveInterpreter() const { return m_globalObject; }
    51     KJS::ScriptInterpreter* interpreter();
    52     KJS::JSGlobalObject* globalObject()
     48    bool haveGlobalObject() const { return m_globalObject; }
     49    JSDOMWindow* globalObject()
    5350    {
    5451        initScriptIfNeeded();
     
    6764    void clearDocumentWrapper();
    6865
     66    void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; }
     67    bool processingUserGesture() const;
     68
    6969private:
    7070    void initScriptIfNeeded()
     
    7878    Frame* m_frame;
    7979    int m_handlerLineno;
     80   
     81    bool m_processingTimerCallback;
     82    bool m_processingInlineCode;
    8083};
    8184
  • trunk/WebCore/bindings/js/kjs_window.cpp

    r28415 r28468  
    223223    // the non-thread-safe WebCore structures it references.
    224224    Collector::collectOnMainThreadOnly(this);
     225
     226    // Time in milliseconds before the script timeout handler kicks in.
     227    setTimeoutTime(10000);
    225228}
    226229
     
    260263Window *Window::retrieveActive(ExecState *exec)
    261264{
    262     JSValue *imp = exec->dynamicInterpreter()->globalObject();
     265    JSValue *imp = exec->dynamicGlobalObject();
    263266    ASSERT(imp);
    264267    return static_cast<Window*>(imp);
     
    294297    if (!frame)
    295298        return false;
    296     if (static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->wasRunByUserGesture())
     299    if (window->impl()->frame()->scriptProxy()->processingUserGesture());
    297300        return true;
    298301    Settings* settings = frame->settings();
     
    390393    if (!url.startsWith("javascript:", false) || newWindow->isSafeScript(exec)) {
    391394        String completedURL = url.isEmpty() ? url : activeFrame->document()->completeURL(url);
    392         bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     395        bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
    393396       
    394397        if (created) {
     
    727730        DeprecatedString dstUrl = p->loader()->completeURL(DeprecatedString(value->toString(exec))).url();
    728731        if (!dstUrl.startsWith("javascript:", false) || isSafeScript(exec)) {
    729           bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     732          bool userGesture = p->scriptProxy()->processingUserGesture();
    730733          // We want a new history item if this JS was called via a user gesture
    731734          impl()->frame()->loader()->scheduleLocationChange(dstUrl, p->loader()->outgoingReferrer(), false, userGesture);
     
    935938  if (!frame)
    936939    return false;
    937   Frame* activeFrame = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter())->frame();
     940  Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
    938941  if (!activeFrame)
    939942    return false;
     
    10661069  clearProperties();
    10671070  clearHelperObjectProperties();
    1068   setPrototype(JSDOMWindowPrototype::self()); // clear the prototype
    10691071
    10701072  // Now recreate a working global object for the next URL that will use us; but only if we haven't been
    10711073  // disconnected yet
    10721074  if (Frame* frame = impl()->frame())
    1073     frame->scriptProxy()->interpreter()->resetGlobalObjectProperties();
     1075    frame->scriptProxy()->globalObject()->reset(JSDOMWindowPrototype::self());
    10741076
    10751077  // there's likely to be lots of garbage now
     
    10801082{
    10811083  d->m_evt = evt;
     1084}
     1085
     1086Event* Window::currentEvent()
     1087{
     1088    return d->m_evt;
    10821089}
    10831090
     
    13571364        const Window* window = Window::retrieveWindow(frame);
    13581365        if (!completedURL.isEmpty() && (!completedURL.startsWith("javascript:", false) || (window && window->isSafeScript(exec)))) {
    1359             bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     1366            bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
    13601367            frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture);
    13611368        }
     
    16821689        return;
    16831690
    1684     ScriptInterpreter* interpreter = scriptProxy->interpreter();
    1685 
    1686     interpreter->setProcessingTimerCallback(true);
     1691    Window* globalObject = scriptProxy->globalObject();
     1692
     1693    scriptProxy->setProcessingTimerCallback(true);
    16871694
    16881695    if (JSValue* func = m_func.get()) {
     
    16901697        if (func->isObject() && static_cast<JSObject*>(func)->implementsCall()) {
    16911698            ExecState* exec = window->globalExec();
    1692             ASSERT(window == interpreter->globalObject());
     1699            ASSERT(window == globalObject);
    16931700           
    16941701            List args;
     
    16981705            }
    16991706
    1700             interpreter->startTimeoutCheck();
     1707            globalObject->startTimeoutCheck();
    17011708            static_cast<JSObject*>(func)->call(exec, window, args);
    1702             interpreter->stopTimeoutCheck();
     1709            globalObject->stopTimeoutCheck();
    17031710            if (exec->hadException()) {
    17041711                JSObject* exception = exec->exception()->toObject(exec);
     
    17231730        doc->updateRendering();
    17241731 
    1725     interpreter->setProcessingTimerCallback(false);
     1732    scriptProxy->setProcessingTimerCallback(false);
    17261733}
    17271734
     
    20322039  Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
    20332040  if (!url.url().startsWith("javascript:", false) || sameDomainAccess) {
    2034     bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     2041    bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
    20352042    m_frame->loader()->scheduleLocationChange(url.url(), activeFrame->loader()->outgoingReferrer(), false, userGesture);
    20362043  }
     
    20532060      const Window* window = Window::retrieveWindow(frame);
    20542061      if (!str.startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
    2055         bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     2062        bool userGesture = p->scriptProxy()->processingUserGesture();
    20562063        frame->loader()->scheduleLocationChange(p->loader()->completeURL(str).url(), p->loader()->outgoingReferrer(), true, userGesture);
    20572064      }
     
    20752082
    20762083    if (!frame->loader()->url().url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
    2077       bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     2084      bool userGesture = Window::retrieveActive(exec)->impl()->frame()->scriptProxy()->processingUserGesture();
    20782085      frame->loader()->scheduleRefresh(userGesture);
    20792086    }
     
    20972104        DeprecatedString dstUrl = p->loader()->completeURL(DeprecatedString(args[0]->toString(exec))).url();
    20982105        if (!dstUrl.startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
    2099             bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
     2106            bool userGesture = p->scriptProxy()->processingUserGesture();
    21002107            // We want a new history item if this JS was called via a user gesture
    21012108            frame->loader()->scheduleLocationChange(dstUrl, p->loader()->outgoingReferrer(), false, userGesture);
  • trunk/WebCore/bindings/js/kjs_window.h

    r28415 r28468  
    2323#include "PlatformString.h"
    2424#include "kjs_binding.h"
     25#include <kjs/protect.h>
    2526#include <wtf/HashMap.h>
    2627#include <wtf/OwnPtr.h>
     
    106107    static bool isSafeScript(const JSGlobalObject *origin, const JSGlobalObject *target);
    107108    virtual bool isSafeScript(const JSGlobalObject* other) const { return Window::isSafeScript(this, other); }
     109    bool isSafeScript(ExecState*) const;
    108110
    109111    Location* location() const;
     
    123125    void clear();
    124126
    125     // Set the current "event" object
    126127    void setCurrentEvent(WebCore::Event*);
     128    WebCore::Event* currentEvent();
    127129
    128130    // Set a place to put a dialog return value when the window is cleared.
     
    142144    virtual ExecState* globalExec();
    143145    virtual bool shouldInterruptScript() const;
    144     bool isSafeScript(ExecState*) const;
    145146
    146147    enum {
  • trunk/WebCore/bindings/objc/WebScriptObject.mm

    r28328 r28468  
    3737#import <JavaScriptCore/APICast.h>
    3838#import <JavaScriptCore/JSGlobalObject.h>
     39#import <JavaScriptCore/interpreter.h>
    3940
    4041using namespace KJS;
     
    250251    JSLock lock;
    251252   
    252     Interpreter *first, *interp = Interpreter::firstInterpreter();
     253    JSGlobalObject* head = JSGlobalObject::head();
    253254
    254255    // This code assumes that we only ever have one running interpreter.  A
     
    256257    // in the future we may have the ability to run multiple interpreters,
    257258    // in which case this will have to change.
    258     first = interp;
     259    JSGlobalObject* o = head;
    259260    do {
    260         if (!interp)
     261        if (!o)
    261262            return NO;
    262263
    263264        // If the interpreter has a current exec state, we set the exception.
    264         if (ExecState* exec = interp->currentExec()) {
     265        if (ExecState* exec = o->currentExec()) {
    265266            throwError(exec, GeneralError, exceptionMessage);
    266267            return YES;
    267268        }
    268         interp = interp->nextInterpreter();
    269     } while (interp != first);
     269        o = o->next();
     270    } while (o != head);
    270271   
    271272    return NO;
     
    310311        return nil;
    311312
    312     [self _rootObject]->interpreter()->startTimeoutCheck();
     313    [self _rootObject]->globalObject()->startTimeoutCheck();
    313314    JSValue *result = funcImp->call(exec, [self _imp], argList);
    314     [self _rootObject]->interpreter()->stopTimeoutCheck();
     315    [self _rootObject]->globalObject()->stopTimeoutCheck();
    315316
    316317    if (exec->hadException()) {
     
    339340    JSLock lock;
    340341   
    341     [self _rootObject]->interpreter()->startTimeoutCheck();
    342     Completion completion = [self _rootObject]->interpreter()->evaluate(UString(), 0, String(script));
    343     [self _rootObject]->interpreter()->stopTimeoutCheck();
     342    [self _rootObject]->globalObject()->startTimeoutCheck();
     343    Completion completion = Interpreter::evaluate([self _rootObject]->globalObject()->globalExec(), UString(), 0, String(script));
     344    [self _rootObject]->globalObject()->stopTimeoutCheck();
    344345    ComplType type = completion.complType();
    345346   
     
    496497    JSLock lock;
    497498   
    498     if (ExecState* exec = [self _rootObject]->interpreter()->currentExec()) {
     499    if (ExecState* exec = [self _rootObject]->globalObject()->currentExec()) {
    499500        throwError(exec, GeneralError, description);
    500501    } else
  • trunk/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r28327 r28468  
    297297        } else {
    298298            push(@headerContent, "#include \"kjs_binding.h\"\n");
     299            push(@headerContent, "#include <kjs/JSGlobalObject.h>\n");
     300            push(@headerContent, "#include <kjs/object_object.h>\n");
    299301        }
    300302    }
     
    541543            push(@headerContent, "        : KJS::JSObject(${parentClassName}Prototype::self(exec)) { }\n");
    542544        } else {
    543             push(@headerContent, "        : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) { }\n");
     545            push(@headerContent, "        : KJS::JSObject(exec->lexicalGlobalObject()->objectPrototype()) { }\n");
    544546        }
    545547    }
     
    17471749    ${className}Constructor(ExecState* exec)
    17481750    {
    1749         setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
     1751        setPrototype(exec->lexicalGlobalObject()->objectPrototype());
    17501752        putDirect(exec->propertyNames().prototype, ${protoClassName}::self(exec), None);
    17511753    }
     
    18001802
    18011803    ${name}(KJS::ExecState* exec, int len, const KJS::Identifier& name)
    1802         : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
     1804        : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalGlobalObject()->functionPrototype()), name)
    18031805    {
    18041806        put(exec, exec->propertyNames().length, KJS::jsNumber(len), KJS::DontDelete | KJS::ReadOnly | KJS::DontEnum);
  • trunk/WebCore/bridge/JavaScriptStatistics.cpp

    r20332 r28468  
    5555{
    5656    JSLock lock;
    57     return Collector::numInterpreters();
     57    return Collector::numGlobalObjects();
    5858}
    5959
  • trunk/WebCore/bridge/mac/WebCoreScriptDebugger.mm

    r28328 r28468  
    3535#import "WebCoreObjCExtras.h"
    3636#import "WebScriptObjectPrivate.h"
     37#import <JavaScriptCore/ExecState.h>
     38#import <JavaScriptCore/JSGlobalObject.h>
    3739#import <JavaScriptCore/debugger.h>
    38 #import <JavaScriptCore/ExecState.h>
    3940#import <JavaScriptCore/function.h>
    40 #import <JavaScriptCore/JSGlobalObject.h>
     41#import <JavaScriptCore/interpreter.h>
    4142
    4243using namespace KJS;
     
    8384  public:
    8485    // constructor
    85     WebCoreScriptDebuggerImp(WebCoreScriptDebugger *objc, Interpreter *interp) : _objc(objc) {
     86    WebCoreScriptDebuggerImp(WebCoreScriptDebugger *objc, JSGlobalObject* globalObject) : _objc(objc) {
    8687        _nested = true;
    87         _current = [_objc _enterFrame:interp->globalObject()->globalExec()];
    88         attach(interp);
     88        _current = [_objc _enterFrame:globalObject->globalExec()];
     89        attach(globalObject);
    8990        [[_objc delegate] enteredFrame:_current sourceId:-1 line:-1];
    9091        _nested = false;
     
    144145//
    145146// The WebCoreScriptDebugger has two faces, one for Objective-C (this class), and another (WebCoreScriptDebuggerImp)
    146 // for C++.  The ObjC side creates the C++ side, which does the real work of attaching to the interpreter and
     147// for C++.  The ObjC side creates the C++ side, which does the real work of attaching to the global object and
    147148// forwarding the KJS debugger callbacks to the delegate.
    148149
     
    161162        _delegate   = delegate;
    162163        _globalObj = [_delegate globalObject];
    163         _debugger  = new WebCoreScriptDebuggerImp(self, [_globalObj _rootObject]->interpreter());
     164        _debugger  = new WebCoreScriptDebuggerImp(self, [_globalObj _rootObject]->globalObject());
    164165    }
    165166    return self;
     
    333334// method of the same name, due to the treatment of exceptions.
    334335
     336// FIXME: If "script" contains var declarations, the machinery to handle local variables
     337// efficiently in JavaScriptCore will not work properly. This could lead to crashes or
     338// incorrect variable values. So this is not appropriate for evaluating arbitrary script.
    335339- (id)evaluateWebScript:(NSString *)script
    336340{
     
    339343    UString code = String(script);
    340344
    341     ExecState   *state   = _state;
    342     Interpreter *interp  = state->dynamicInterpreter();
    343     JSObject   *globObj = interp->globalObject();
     345    ExecState* state = _state;
     346    JSGlobalObject* globalObject = state->dynamicGlobalObject();
    344347
    345348    // find "eval"
    346349    JSObject *eval = NULL;
    347350    if (state->currentBody()) {  // "eval" won't work without context (i.e. at global scope)
    348         JSValue *v = globObj->get(state, "eval");
     351        JSValue *v = globalObject->get(state, "eval");
    349352        if (v->isObject() && static_cast<JSObject *>(v)->implementsCall())
    350353            eval = static_cast<JSObject *>(v);
    351354        else
    352355            // no "eval" - fallback operates on global exec state
    353             state = interp->globalObject()->globalExec();
     356            state = globalObject->globalExec();
    354357    }
    355358
     
    365368    } else
    366369        // no "eval", or no context (i.e. global scope) - use global fallback
    367         result = interp->evaluate(UString(), 0, code.data(), code.size(), globObj).value();
     370        result = Interpreter::evaluate(state, UString(), 0, code.data(), code.size(), globalObject).value();
    368371
    369372    if (state->hadException())
  • trunk/WebCore/history/CachedPage.cpp

    r27277 r28468  
    8282    , m_windowProperties(new SavedProperties)
    8383    , m_locationProperties(new SavedProperties)
    84     , m_interpreterBuiltins(new SavedBuiltins)
     84    , m_windowBuiltins(new SavedBuiltins)
    8585{
    8686#ifndef NDEBUG
     
    9999
    100100    if (proxy && window) {
    101         proxy->interpreter()->saveBuiltins(*m_interpreterBuiltins.get());
     101        proxy->globalObject()->saveBuiltins(*m_windowBuiltins.get());
    102102        window->saveProperties(*m_windowProperties.get());
    103103        window->location()->saveProperties(*m_locationProperties.get());
     
    133133
    134134    if (proxy && window) {
    135         proxy->interpreter()->restoreBuiltins(*m_interpreterBuiltins.get());
     135        proxy->globalObject()->restoreBuiltins(*m_windowBuiltins.get());
    136136        window->restoreProperties(*m_windowProperties.get());
    137137        window->location()->restoreProperties(*m_locationProperties.get());
     
    187187    m_windowProperties.clear();
    188188    m_locationProperties.clear();
    189     m_interpreterBuiltins.clear();
     189    m_windowBuiltins.clear();
    190190    m_pausedTimeouts.clear();
    191191
  • trunk/WebCore/history/CachedPage.h

    r27776 r28468  
    8787    OwnPtr<KJS::SavedProperties> m_windowProperties;
    8888    OwnPtr<KJS::SavedProperties> m_locationProperties;
    89     OwnPtr<KJS::SavedBuiltins> m_interpreterBuiltins;
     89    OwnPtr<KJS::SavedBuiltins> m_windowBuiltins;
    9090    OwnPtr<KJS::PausedTimeouts> m_pausedTimeouts;
    9191       
  • trunk/WebCore/loader/FrameLoader.cpp

    r28464 r28468  
    17231723
    17241724    if (rootFrame->scriptProxy())
    1725         return rootFrame->scriptProxy()->interpreter()->wasRunByUserGesture();
     1725        return rootFrame->scriptProxy()->processingUserGesture();
    17261726
    17271727    return true; // If JavaScript is disabled, a user gesture must have initiated the navigation
     
    45364536{
    45374537    Settings* settings = m_frame->settings();
    4538     if (!settings || !settings->isJavaScriptEnabled() || !m_frame->scriptProxy()->haveInterpreter())
     4538    if (!settings || !settings->isJavaScriptEnabled() || !m_frame->scriptProxy()->haveGlobalObject())
    45394539        return;
    45404540
  • trunk/WebCore/page/Frame.cpp

    r28411 r28468  
    195195#endif
    196196
    197     if (d->m_jscript && d->m_jscript->haveInterpreter())
     197    if (d->m_jscript && d->m_jscript->haveGlobalObject())
    198198        static_cast<KJS::Window*>(d->m_jscript->globalObject())->disconnectFrame();
    199199
     
    18181818
    18191819    // This will stop any JS timers
    1820     if (d->m_jscript && d->m_jscript->haveInterpreter())
     1820    if (d->m_jscript && d->m_jscript->haveGlobalObject())
    18211821        if (KJS::Window* w = KJS::Window::retrieveWindow(this))
    18221822            w->disconnectFrame();
  • trunk/WebKit/mac/ChangeLog

    r28446 r28468  
     12007-12-04  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Third step in refactoring JSGlobalObject: Moved data members and data
     6        member access from Interpreter to JSGlobalObject.
     7       
     8        * WebView/WebFrame.mm:
     9        (-[WebFrame _attachScriptDebugger]):
     10
    1112007-12-04  Kevin McCullough  <kmccullough@apple.com>
    212
  • trunk/WebKit/mac/WebView/WebFrame.mm

    r28328 r28468  
    367367- (void)_attachScriptDebugger
    368368{
    369     if (!_private->scriptDebugger && core(self)->scriptProxy()->haveInterpreter())
     369    if (!_private->scriptDebugger && core(self)->scriptProxy()->haveGlobalObject())
    370370        _private->scriptDebugger = [[WebScriptDebugger alloc] initWithWebFrame:self];
    371371}
  • trunk/WebKit/win/ChangeLog

    r28466 r28468  
     12007-12-04  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Third step in refactoring JSGlobalObject: Moved data members and data
     6        member access from Interpreter to JSGlobalObject.
     7       
     8        * WebFrame.cpp:
     9        (WebFrame::globalContext):
     10        (WebFrame::attachScriptDebugger):
     11        (WebFrame::windowObjectCleared):
     12        * WebScriptDebugger.cpp:
     13        (WebScriptDebugger::WebScriptDebugger):
     14
    1152007-12-05  Steve Falkenburg  <sfalken@apple.com>
    216
  • trunk/WebKit/win/WebFrame.cpp

    r28405 r28468  
    768768void WebFrame::attachScriptDebugger()
    769769{
    770     if (!m_scriptDebugger && core(this)->scriptProxy()->haveInterpreter())
     770    if (!m_scriptDebugger && core(this)->scriptProxy()->haveGlobalObject())
    771771        m_scriptDebugger.set(new WebScriptDebugger(this));
    772772}
  • trunk/WebKit/win/WebScriptDebugger.cpp

    r28413 r28468  
    5757        return;
    5858
    59     Interpreter* interp(proxy->interpreter());
    60     attach(interp);
     59    JSGlobalObject* globalObject = proxy->globalObject();
     60    attach(globalObject);
    6161
    6262    m_frame->webView(&m_webView);
    6363    ASSERT(m_webView);
    6464
    65     callEvent(proxy->globalObject()->globalExec(), -1, -1, 0, List());
     65    callEvent(globalObject->globalExec(), -1, -1, 0, List());
    6666    m_callingServer = false;
    6767}
Note: See TracChangeset for help on using the changeset viewer.