Ignore:
Timestamp:
Dec 5, 2007, 6:31:41 PM (17 years ago)
Author:
[email protected]
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):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/JSGlobalObject.h

    r28415 r28468  
    22/*
    33 *  Copyright (C) 2007 Eric Seidel <[email protected]>
    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
Note: See TracChangeset for help on using the changeset viewer.