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/interpreter.h

    r28328 r28468  
    11/*
    2  *  This file is part of the KDE libraries
    32 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    43 *  Copyright (C) 2001 Peter Kelly ([email protected])
    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
Note: See TracChangeset for help on using the changeset viewer.