Ignore:
Timestamp:
Jan 26, 2008, 10:55:52 AM (17 years ago)
Author:
Darin Adler
Message:

Reviewed by Eric Seidel.

  • JavaScriptCore.exp: Export the GlobalExecState constructor instead of the global flavor of the ExecState constructor. It'd probably be cleaner to not export either one, but JSGlobalObject inlines the code that constructs the ExecState. If we changed that, we could remove this export.
  • JavaScriptCore.xcodeproj/project.pbxproj: Re-sorted a few things and put the new source files into the kjs group rather than at the top level.
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState): Marked inline and updated for data member name changes. This is now only for use for the derived classes. Also removed code that sets the unused m_savedExec data member for the global case. That data member is only used for the other two types. (KJS::ExecState::~ExecState): Marked inline and removed all the code. The derived class destructors now inclde the appropriate code. (KJS::ExecState::lexicalGlobalObject): Removed unneeded special case for an empty scope chain. The bottom function already returns 0 for that case, so the general case code handles it fine. Also changed to use data members directly rather than calling functions. (KJS::GlobalExecState::GlobalExecState): Added. Calls through to the base class constructor. (KJS::GlobalExecState::~GlobalExecState): Added. (KJS::InterpreterExecState::InterpreterExecState): Added. Moved code to manipulate activeExecStates here since we don't want to have to check for the special case of globalExec. (KJS::InterpreterExecState::~InterpreterExecState): Added. (KJS::EvalExecState::EvalExecState): Added. (KJS::EvalExecState::~EvalExecState): Added. (KJS::FunctionExecState::FunctionExecState): Added. (KJS::FunctionExecState::~FunctionExecState): Added.
  • kjs/ExecState.h: Tweaked the header, includes, and declarations a bit. Made ExecState inherit from Noncopyable. Reformatted some comments and made them a bit more brief. Rearranged declarations a little bit and removed unused savedExec function. Changed seenLabels function to return a reference rather than a pointer. Made constructors and destructor protected, and also did the same with all data members. Renamed m_thisVal to m_thisValue and ls to m_labelStack. Added three new derived classes for each of the types of ExecState. The primary goal here was to remove a branch from the code in the destructor, but it's also clearer than overloading the arguments to the ExecState constructor.
  • kjs/JSGlobalObject.cpp: (KJS::getCurrentTime): Fixed formatting. (KJS::JSGlobalObject::pushActivation): Removed parentheses that don't make the expression clearer -- other similar sites didn't have these parentheses, even the one a couple lines earlier that sets stackEntry. (KJS::JSGlobalObject::tearOffActivation): Got rid of unneeded static_cast (I think I mentioned this during patch review) and used an early exit so that the entire contents of the function aren't nested inside an if statement. Also removed the check of codeType, instead checking Activation for 0. For now, I kept the codeType check, but inside an assertion.
  • kjs/JSGlobalObject.h: Changed type of globalExec to GlobalExecState.
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): Changed type to FunctionExecState. (KJS::GlobalFuncImp::callAsFunction): Changed type to EvalExecState.
  • kjs/interpreter.cpp: (KJS::Interpreter::evaluate): Changed type to GlobalExecState.
  • kjs/nodes.cpp: (KJS::ContinueNode::execute): Changed code since seenLabels() returns a reference now instead of a pointer. (KJS::BreakNode::execute): Ditto. (KJS::LabelNode::execute): Ditto.
File:
1 edited

Legend:

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

    r29710 r29810  
    33 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    44 *  Copyright (C) 2001 Peter Kelly ([email protected])
    5  *  Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
     5 *  Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
    66 *
    77 *  This library is free software; you can redistribute it and/or
     
    2222 */
    2323
    24 #ifndef ExecState_H
    25 #define ExecState_H
     24#ifndef ExecState_h
     25#define ExecState_h
    2626
    2727#include "LabelStack.h"
    2828#include "LocalStorage.h"
     29#include "completion.h"
     30#include "list.h"
    2931#include "scope_chain.h"
    30 #include "types.h"
    3132
    3233namespace KJS  {
    3334
    34     enum CodeType {
    35         GlobalCode,
    36         EvalCode,
    37         FunctionCode,
    38     };
    39    
    4035    class ActivationImp;
    4136    class CommonIdentifiers;
     
    4843    class JSVariableObject;
    4944    class ProgramNode;
    50     class ScopeChain;
    5145    class ScopeNode;
    52     struct LocalStorageEntry;
     46   
     47    enum CodeType { GlobalCode, EvalCode, FunctionCode };
    5348   
    5449    typedef Vector<ExecState*, 16> ExecStateStack;
    5550
    56     /**
    57      * Represents the current state of script execution. This is
    58      * passed as the first argument to most functions.
    59      */
    60     class ExecState {
    61         friend class Interpreter;
    62         friend class FunctionImp;
    63         friend class GlobalFuncImp;
    64     public:
    65         /**
    66          * Returns the global object that was in scope when the current script started executing.
    67          */
     51    // Represents the current state of script execution.
     52    // Passed as the first argument to most functions.
     53    class ExecState : Noncopyable {
     54    public:
     55        // Global object that was in scope when the current script started executing.
    6856        JSGlobalObject* dynamicGlobalObject() const { return m_globalObject; }
    6957       
    70         /**
    71          * Returns the global object that was in scope when the current body of code was defined.
    72          */
     58        // Global object that was in scope when the current body of code was defined.
    7359        JSGlobalObject* lexicalGlobalObject() const;
    7460               
     
    8066       
    8167        const ScopeChain& scopeChain() const { return m_scopeChain; }
     68        void pushScope(JSObject* s) { m_scopeChain.push(s); }
     69        void popScope() { m_scopeChain.pop(); }
    8270        void replaceScopeChainTop(JSObject* o) { m_scopeChain.replaceTop(o); }
    8371       
     
    8573        void setVariableObject(JSVariableObject* v) { m_variableObject = v; }
    8674       
    87         JSObject* thisValue() const { return m_thisVal; }
     75        JSObject* thisValue() const { return m_thisValue; }
    8876       
    8977        ExecState* callingExecState() { return m_callingExec; }
     
    9684        const List* arguments() const { return m_arguments; }
    9785       
    98         void pushScope(JSObject* s) { m_scopeChain.push(s); }
    99         void popScope() { m_scopeChain.pop(); }
    100         LabelStack* seenLabels() { return &ls; }
     86        LabelStack& seenLabels() { return m_labelStack; }
    10187       
    10288        void pushIteration() { m_iterationDepth++; }
     
    178164        }
    179165
     166        static void markActiveExecStates();
     167        static ExecStateStack& activeExecStates();
     168
     169    protected:
    180170        ExecState(JSGlobalObject*);
    181171        ExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*);
     
    185175        ~ExecState();
    186176
    187         static void markActiveExecStates();
    188         static ExecStateStack& activeExecStates();
    189 
    190     private:
    191177        // ExecStates are always stack-allocated, and the garbage collector
    192178        // marks the stack, so we don't need to protect the objects below from GC.
     
    208194        ScopeChain m_scopeChain;
    209195        JSVariableObject* m_variableObject;
    210         JSObject* m_thisVal;
    211        
    212         LabelStack ls;
     196        JSObject* m_thisValue;
     197       
     198        LabelStack m_labelStack;
    213199        int m_iterationDepth;
    214200        int m_switchDepth;
     
    219205    };
    220206
     207    class GlobalExecState : public ExecState {
     208    public:
     209        GlobalExecState(JSGlobalObject*);
     210        ~GlobalExecState();
     211    };
     212
     213    class InterpreterExecState : public ExecState {
     214    public:
     215        InterpreterExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*);
     216        ~InterpreterExecState();
     217    };
     218
     219    class EvalExecState : public ExecState {
     220    public:
     221        EvalExecState(JSGlobalObject*, EvalNode*, ExecState* callingExecState);
     222        ~EvalExecState();
     223    };
     224
     225    class FunctionExecState : public ExecState {
     226    public:
     227        FunctionExecState(JSGlobalObject*, JSObject* thisObject, FunctionBodyNode*,
     228            ExecState* callingExecState, FunctionImp*, const List& args);
     229        ~FunctionExecState();
     230    };
     231
    221232} // namespace KJS
    222233
    223 #endif // ExecState_H
     234#endif // ExecState_h
Note: See TracChangeset for help on using the changeset viewer.