Changeset 14799 in webkit for trunk/JavaScriptCore/kjs/context.h


Ignore:
Timestamp:
Jun 9, 2006, 8:57:13 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Eric (yay!).


  • Removed Context wrapper for ContextImp, renamed ContextImp to Context, split Context into its own file -- Context.cpp -- renamed _var to m_var, change ' *' to '* '.
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/Context.cpp: Added. (KJS::Context::Context): (KJS::Context::~Context): (KJS::Context::mark):
  • kjs/context.h: (KJS::Context::scopeChain): (KJS::Context::variableObject): (KJS::Context::setVariableObject): (KJS::Context::thisValue): (KJS::Context::callingContext): (KJS::Context::activationObject): (KJS::Context::currentBody): (KJS::Context::function): (KJS::Context::arguments): (KJS::Context::pushScope): (KJS::Context::seenLabels):
  • kjs/function.cpp: (KJS::FunctionImp::callAsFunction): (KJS::FunctionImp::processParameters): (KJS::FunctionImp::argumentsGetter): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/internal.cpp: (KJS::InterpreterImp::evaluate):
  • kjs/internal.h: (KJS::InterpreterImp::setContext): (KJS::InterpreterImp::context):
  • kjs/interpreter.cpp:
  • kjs/interpreter.h: (KJS::ExecState::context): (KJS::ExecState::ExecState):
  • kjs/nodes.cpp: (currentSourceId): (currentSourceURL): (ThisNode::evaluate): (ResolveNode::evaluate): (FunctionCallResolveNode::evaluate): (PostfixResolveNode::evaluate): (DeleteResolveNode::evaluate): (TypeOfResolveNode::evaluate): (PrefixResolveNode::evaluate): (AssignResolveNode::evaluate): (VarDeclNode::evaluate): (VarDeclNode::processVarDecls): (DoWhileNode::execute): (WhileNode::execute): (ForNode::execute): (ForInNode::execute): (ContinueNode::execute): (BreakNode::execute): (ReturnNode::execute): (WithNode::execute): (SwitchNode::execute): (LabelNode::execute): (TryNode::execute): (FuncDeclNode::processFuncDecl): (FuncExprNode::evaluate):
File:
1 edited

Legend:

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

    r13821 r14799  
    44 *  Copyright (C) 1999-2001 Harri Porten ([email protected])
    55 *  Copyright (C) 2001 Peter Kelly ([email protected])
    6  *  Copyright (C) 2003 Apple Computer, Inc.
     6 *  Copyright (C) 2003, 2006 Apple Computer, Inc.
    77 *
    88 *  This library is free software; you can redistribute it and/or
     
    2323 */
    2424
    25 #ifndef KJS_CONTEXT_H
    26 #define KJS_CONTEXT_H
     25#ifndef KJS_Context_h
     26#define KJS_Context_h
    2727
    2828#include "function.h"
     
    3030namespace KJS  {
    3131
    32   /**
     32  /** 
    3333   * @short Execution context.
    34    */
    35   class ContextImp {
     34   *
     35   * Represents an execution context, as specified by section 10 of the ECMA
     36   * spec.
     37   *
     38   * An execution context contains information about the current state of the
     39   * script - the scope for variable lookup, the value of "this", etc. A new
     40   * execution context is entered whenever global code is executed (e.g. with
     41   * Interpreter::evaluate()), a function is called (see
     42   * Object::call()), or the builtin "eval" function is executed.
     43   *
     44   * Most inheritable functions in the KJS api take a ExecState pointer as
     45   * their first parameter. This can be used to obtain a handle to the current
     46   * execution context.
     47   */   
     48  class Context {
    3649  public:
    37     ContextImp(JSObject* global, InterpreterImp*, JSObject* thisV, FunctionBodyNode* currentBody,
    38                CodeType type = GlobalCode, ContextImp* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
    39     ~ContextImp();
     50    Context(JSObject* global, InterpreterImp*, JSObject* thisV,
     51            FunctionBodyNode* currentBody, CodeType type = GlobalCode,
     52            Context* callingContext = 0, FunctionImp* function = 0, const List* args = 0);
     53    ~Context();
    4054
     55    /**
     56     * Returns the scope chain for this execution context. This is used for
     57     * variable lookup, with the list being searched from start to end until a
     58     * variable is found.
     59     *
     60     * @return The execution context's scope chain
     61     */
     62    const ScopeChain& scopeChain() const { return scope; }
     63
     64    /**
     65     * Returns the variable object for the execution context. This contains a
     66     * property for each variable declared in the execution context.
     67     *
     68     * @return The execution context's variable object
     69     */
     70    JSObject* variableObject() const { return m_variable; }
     71    void setVariableObject(JSObject* v) { m_variable = v; }
     72
     73    /**
     74     * Returns the "this" value for the execution context. This is the value
     75     * returned when a script references the special variable "this". It should
     76     * always be an Object, unless application-specific code has passed in a
     77     * different type.
     78     *
     79     * The object that is used as the "this" value depends on the type of
     80     * execution context - for global contexts, the global object is used. For
     81     * function objewcts, the value is given by the caller (e.g. in the case of
     82     * obj.func(), obj would be the "this" value). For code executed by the
     83     * built-in "eval" function, the this value is the same as the calling
     84     * context.
     85     *
     86     * @return The execution context's "this" value
     87     */
     88    JSObject* thisValue() const { return m_thisVal; }
     89
     90    /**
     91     * Returns the context from which the current context was invoked. For
     92     * global code this will be a null context (i.e. one for which
     93     * isNull() returns true). You should check isNull() on the returned
     94     * value before calling any of it's methods.
     95     *
     96     * @return The calling execution context
     97     */
     98    Context* callingContext() { return m_callingContext; }
     99   
     100    JSObject* activationObject() { return m_activation; }
     101    CodeType codeType() { return m_codeType; }
    41102    FunctionBodyNode* currentBody() { return m_currentBody; }
     103    FunctionImp* function() const { return m_function; }
     104    const List* arguments() const { return m_arguments; }
    42105
    43     const ScopeChain &scopeChain() const { return scope; }
    44     CodeType codeType() { return m_codeType; }
    45     JSObject *variableObject() const { return variable; }
    46     void setVariableObject(JSObject *v) { variable = v; }
    47     JSObject *thisValue() const { return thisVal; }
    48     ContextImp *callingContext() { return _callingContext; }
    49     JSObject *activationObject() { return activation; }
    50     FunctionImp *function() const { return _function; }
    51     const List *arguments() const { return _arguments; }
    52 
    53     void pushScope(JSObject *s) { scope.push(s); }
     106    void pushScope(JSObject* s) { scope.push(s); }
    54107    void popScope() { scope.pop(); }
    55     LabelStack *seenLabels() { return &ls; }
    56 
     108    LabelStack* seenLabels() { return &ls; }
    57109
    58110    void pushIteration() { m_iterationDepth++; }
     
    67119
    68120  private:
    69     InterpreterImp *_interpreter;
    70     ContextImp *_callingContext;
     121    // Contexts are always stack-allocated, and the garbage collector
     122    // marks the stack, so we don't need to protect the objects below from GC.
     123
     124    InterpreterImp* m_interpreter;
     125    Context* m_callingContext;
    71126    FunctionBodyNode* m_currentBody;
    72127
    73     FunctionImp *_function;
    74     const List *_arguments;
    75     // because ContextImp is always allocated on the stack,
    76     // there is no need to protect various pointers from conservative
    77     // GC since they will be caught by the conservative sweep anyway!
    78     JSObject *activation;
     128    FunctionImp* m_function;
     129    const List* m_arguments;
     130    JSObject* m_activation;
    79131   
    80132    ScopeChain scope;
    81     JSObject *variable;
    82     JSObject *thisVal;
     133    JSObject* m_variable;
     134    JSObject* m_thisVal;
    83135
    84136    LabelStack ls;
Note: See TracChangeset for help on using the changeset viewer.