webengine/osswebengine/JavaScriptCore/kjs/ExecState.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  *  This file is part of the KDE libraries
       
     3  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
       
     4  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
       
     5  *  Copyright (C) 2003 Apple Computer, Inc.
       
     6  *
       
     7  *  This library is free software; you can redistribute it and/or
       
     8  *  modify it under the terms of the GNU Library General Public
       
     9  *  License as published by the Free Software Foundation; either
       
    10  *  version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  *  This library is distributed in the hope that it will be useful,
       
    13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  *  Library General Public License for more details.
       
    16  *
       
    17  *  You should have received a copy of the GNU Library General Public License
       
    18  *  along with this library; see the file COPYING.LIB.  If not, write to
       
    19  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    20  *  Boston, MA 02110-1301, USA.
       
    21  *
       
    22  */
       
    23 
       
    24 #ifndef ExecState_H
       
    25 #define ExecState_H
       
    26 
       
    27 #include "value.h"
       
    28 #include "types.h"
       
    29 #include "CommonIdentifiers.h"
       
    30 
       
    31 namespace KJS {
       
    32     class Context;
       
    33     class Interpreter;
       
    34     
       
    35     class Interpreter;
       
    36     class FunctionImp;
       
    37     class GlobalFuncImp;
       
    38     
       
    39   /**
       
    40    * Represents the current state of script execution. This object allows you
       
    41    * obtain a handle the interpreter that is currently executing the script,
       
    42    * and also the current execution context.
       
    43    */
       
    44   class ExecState {
       
    45     friend class Interpreter;
       
    46     friend class FunctionImp;
       
    47     friend class GlobalFuncImp;
       
    48   public:
       
    49     /**
       
    50      * Returns the interpreter associated with this execution state
       
    51      *
       
    52      * @return The interpreter executing the script
       
    53      */
       
    54     Interpreter* dynamicInterpreter() const { return m_interpreter; }
       
    55 
       
    56     /**
       
    57      * Returns the interpreter associated with the current scope's
       
    58      * global object
       
    59      *
       
    60      * @return The interpreter currently in scope
       
    61      */
       
    62     IMPORT Interpreter* lexicalInterpreter() const;
       
    63 
       
    64     /**
       
    65      * Returns the execution context associated with this execution state
       
    66      *
       
    67      * @return The current execution state context
       
    68      */
       
    69     Context* context() const { return m_context; }
       
    70 
       
    71     void setException(JSValue* e) { m_exception = e; }
       
    72     void clearException() { m_exception = 0; }
       
    73     JSValue* exception() const { return m_exception; }
       
    74     JSValue** exceptionSlot() { return &m_exception; }
       
    75     bool hadException() const { return !!m_exception; }
       
    76 
       
    77     // This is a workaround to avoid accessing the global variables for these identifiers in
       
    78     // important property lookup functions, to avoid taking PIC branches in Mach-O binaries
       
    79     const CommonIdentifiers& propertyNames() const { return *m_propertyNames; }
       
    80 
       
    81   private:
       
    82     ExecState(Interpreter* interp, Context* con)
       
    83         : m_interpreter(interp)
       
    84         , m_context(con)
       
    85         , m_exception(0)
       
    86         , m_propertyNames(CommonIdentifiers::shared())
       
    87     { 
       
    88     }
       
    89     Interpreter* m_interpreter;
       
    90     Context* m_context;
       
    91     JSValue* m_exception;
       
    92     CommonIdentifiers* m_propertyNames;
       
    93   };
       
    94 
       
    95 } // namespace KJS
       
    96 
       
    97 #endif // ExecState_H