Changeset 26715 in webkit


Ignore:
Timestamp:
Oct 17, 2007, 2:01:27 PM (18 years ago)
Author:
ggaren
Message:

Reviewed by Darin Adler.


Merged DeclaredFunctionImp into FunctionImp (the base class) because
the distinction between the two was unused.


Removed codeType() from FunctionImp because FunctionImp and its
subclasses all returned FunctionCode, so it was unused, practically
speaking.


Removed a different codeType() from GlobalFuncImp because it was unused.
(Perhaps it was vestigial from a time when GlobalFuncImp used to
inherit from FunctionImp.)

  • bindings/runtime_method.cpp:
  • bindings/runtime_method.h:
  • kjs/function.cpp: (KJS::): (KJS::FunctionImp::FunctionImp): (KJS::FunctionImp::callAsFunction): (KJS::FunctionImp::construct): (KJS::FunctionImp::execute): (KJS::FunctionImp::processVarDecls):
  • kjs/function.h: (KJS::FunctionImp::implementsConstruct): (KJS::FunctionImp::scope):
  • kjs/function_object.cpp: (FunctionProtoFunc::callAsFunction): (FunctionObjectImp::construct):
  • kjs/nodes.cpp: (FuncDeclNode::processFuncDecl): (FuncExprNode::evaluate):
Location:
trunk/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r26707 r26715  
     12007-10-17  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Darin Adler.
     4       
     5        Merged DeclaredFunctionImp into FunctionImp (the base class) because
     6        the distinction between the two was unused.
     7       
     8        Removed codeType() from FunctionImp because FunctionImp and its
     9        subclasses all returned FunctionCode, so it was unused, practically
     10        speaking.
     11       
     12        Removed a different codeType() from GlobalFuncImp because it was unused.
     13        (Perhaps it was vestigial from a time when GlobalFuncImp used to
     14        inherit from FunctionImp.)
     15
     16        * bindings/runtime_method.cpp:
     17        * bindings/runtime_method.h:
     18        * kjs/function.cpp:
     19        (KJS::):
     20        (KJS::FunctionImp::FunctionImp):
     21        (KJS::FunctionImp::callAsFunction):
     22        (KJS::FunctionImp::construct):
     23        (KJS::FunctionImp::execute):
     24        (KJS::FunctionImp::processVarDecls):
     25        * kjs/function.h:
     26        (KJS::FunctionImp::implementsConstruct):
     27        (KJS::FunctionImp::scope):
     28        * kjs/function_object.cpp:
     29        (FunctionProtoFunc::callAsFunction):
     30        (FunctionObjectImp::construct):
     31        * kjs/nodes.cpp:
     32        (FuncDeclNode::processFuncDecl):
     33        (FuncExprNode::evaluate):
     34
    1352007-10-17  Adam Roben  <[email protected]>
    236
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r26697 r26715  
    218218                935AF46E09E9D9DB00ACD1D8 /* UnusedParam.h in Headers */ = {isa = PBXBuildFile; fileRef = 935AF46B09E9D9DB00ACD1D8 /* UnusedParam.h */; };
    219219                935F69FE08245057003D1A45 /* dftables.c in Sources */ = {isa = PBXBuildFile; fileRef = 6541720E039E08B90058BFEB /* dftables.c */; };
    220                 937013480CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.c in Sources */ = {isa = PBXBuildFile; fileRef = 937013470CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.c */; settings = {COMPILER_FLAGS = "-Wno-sign-compare"; }; };
     220                937013480CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.c in Sources */ = {isa = PBXBuildFile; fileRef = 937013470CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.c */; settings = {COMPILER_FLAGS = "-Wno-sign-compare"; }; };
    221221                938C4F6A0CA06BC700D9310A /* ASCIICType.h in Headers */ = {isa = PBXBuildFile; fileRef = 938C4F690CA06BC700D9310A /* ASCIICType.h */; settings = {ATTRIBUTES = (Private, ); }; };
    222222                938C4F6C0CA06BCE00D9310A /* DisallowCType.h in Headers */ = {isa = PBXBuildFile; fileRef = 938C4F6B0CA06BCE00D9310A /* DisallowCType.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    13661366                        isa = PBXProject;
    13671367                        buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject "JavaScriptCore" */;
     1368                        compatibilityVersion = "Xcode 2.4";
    13681369                        hasScannedForEncodings = 1;
    13691370                        mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */;
  • trunk/JavaScriptCore/bindings/runtime_method.cpp

    r23538 r26715  
    9393}
    9494
    95 CodeType RuntimeMethod::codeType() const
    96 {
    97     return FunctionCode;
    98 }
    99 
    10095Completion RuntimeMethod::execute(ExecState*)
    10196{
  • trunk/JavaScriptCore/bindings/runtime_method.h

    r23538 r26715  
    4343    virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
    4444
    45     virtual CodeType codeType() const;
    46    
    4745    virtual Completion execute(ExecState *exec);
    4846
  • trunk/JavaScriptCore/kjs/function.cpp

    r26690 r26715  
    4949// ----------------------------- FunctionImp ----------------------------------
    5050
    51 const ClassInfo FunctionImp::info = {"Function", &InternalFunctionImp::info, 0, 0};
    52 
    53 FunctionImp::FunctionImp(ExecState* exec, const Identifier& n, FunctionBodyNode* b)
    54   : InternalFunctionImp(static_cast<FunctionPrototype*>
    55                         (exec->lexicalInterpreter()->builtinFunctionPrototype()), n)
     51const ClassInfo FunctionImp::info = { "Function", &InternalFunctionImp::info, 0, 0 };
     52
     53FunctionImp::FunctionImp(ExecState* exec, const Identifier& name, FunctionBodyNode* b, const ScopeChain& sc)
     54  : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
    5655  , body(b)
     56  , _scope(sc)
    5757{
    5858}
     
    6464}
    6565
    66 FunctionImp::~FunctionImp()
    67 {
    68 }
    69 
    7066JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    7167{
     
    7470  // enter a new execution context
    7571  Context ctx(globalObj, exec->dynamicInterpreter(), thisObj, body.get(),
    76                  codeType(), exec->context(), this, &args);
     72                 FunctionCode, exec->context(), this, &args);
    7773  ExecState newExec(exec->dynamicInterpreter(), &ctx);
    7874  if (exec->hadException())
     
    8076  ctx.setExecState(&newExec);
    8177
    82   // assign user supplied arguments to parameters
    8378  passInParameters(&newExec, args);
    84   // add variable declarations (initialized to undefined)
    8579  processVarDecls(&newExec);
    8680
     
    8983  int lineno = -1;
    9084  if (dbg) {
    91     if (inherits(&DeclaredFunctionImp::info)) {
    92       sid = static_cast<DeclaredFunctionImp*>(this)->body->sourceId();
    93       lineno = static_cast<DeclaredFunctionImp*>(this)->body->firstLine();
    94     }
     85    sid = body->sourceId();
     86    lineno = body->firstLine();
    9587
    9688    bool cont = dbg->callEvent(&newExec,sid,lineno,this,args);
     
    113105
    114106  if (dbg) {
    115     if (inherits(&DeclaredFunctionImp::info))
    116       lineno = static_cast<DeclaredFunctionImp*>(this)->body->lastLine();
     107    lineno = body->lastLine();
    117108
    118109    if (comp.complType() == Throw)
     
    147138      variable->put(exec, parameters[i], args[i], DontDelete);
    148139    }
    149 }
    150 
    151 void FunctionImp::processVarDecls(ExecState*)
    152 {
    153140}
    154141
     
    256243}
    257244
    258 // ------------------------------ DeclaredFunctionImp --------------------------
    259 
    260 // ### is "Function" correct here?
    261 const ClassInfo DeclaredFunctionImp::info = {"Function", &FunctionImp::info, 0, 0};
    262 
    263 DeclaredFunctionImp::DeclaredFunctionImp(ExecState* exec, const Identifier& n,
    264                                          FunctionBodyNode* b, const ScopeChain& sc)
    265   : FunctionImp(exec, n, b)
    266 {
    267   setScope(sc);
    268 }
    269 
    270 bool DeclaredFunctionImp::implementsConstruct() const
    271 {
    272   return true;
    273 }
    274 
    275245// ECMA 13.2.2 [[Construct]]
    276 JSObject* DeclaredFunctionImp::construct(ExecState* exec, const List& args)
     246JSObject* FunctionImp::construct(ExecState* exec, const List& args)
    277247{
    278248  JSObject* proto;
     
    293263}
    294264
    295 Completion DeclaredFunctionImp::execute(ExecState* exec)
     265Completion FunctionImp::execute(ExecState* exec)
    296266{
    297267  Completion result = body->execute(exec);
     
    302272}
    303273
    304 void DeclaredFunctionImp::processVarDecls(ExecState* exec)
     274void FunctionImp::processVarDecls(ExecState* exec)
    305275{
    306276    body->processDeclarations(exec);
     
    525495{
    526496  putDirect(exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum);
    527 }
    528 
    529 CodeType GlobalFuncImp::codeType() const
    530 {
    531   return id == Eval ? EvalCode : codeType();
    532497}
    533498
  • trunk/JavaScriptCore/kjs/function.h

    r26620 r26715  
    7373  };
    7474
    75   /**
    76    * @short Implementation class for internal Functions.
    77    */
    7875  class FunctionImp : public InternalFunctionImp {
    7976    friend class ActivationImp;
    8077  public:
    81     FunctionImp(ExecState*, const Identifier& n, FunctionBodyNode* b);
    82     virtual ~FunctionImp();
     78    FunctionImp(ExecState*, const Identifier& name, FunctionBodyNode*, const ScopeChain&);
    8379
    8480    virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     
    8682    virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
    8783
     84    virtual bool implementsConstruct() const { return true; }
     85    virtual JSObject* construct(ExecState*, const List& args);
     86   
    8887    virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
     88    Completion execute(ExecState*);
    8989
    9090    // Note: unlike body->paramName, this returns Identifier::null for parameters
    9191    // that will never get set, due to later param having the same name
    9292    Identifier getParameterName(int index);
    93     virtual CodeType codeType() const = 0;
    94 
    95     virtual Completion execute(ExecState*) = 0;
    9693
    9794    virtual const ClassInfo* classInfo() const { return &info; }
     
    10097    RefPtr<FunctionBodyNode> body;
    10198
    102     /**
    103      * Returns the scope of this object. This is used when execution declared
    104      * functions - the execution context for the function is initialized with
    105      * extra object in it's scope. An example of this is functions declared
    106      * inside other functions:
    107      *
    108      * \code
    109      * function f() {
    110      *
    111      *   function b() {
    112      *     return prototype;
    113      *   }
    114      *
    115      *   var x = 4;
    116      *   // do some stuff
    117      * }
    118      * f.prototype = new String();
    119      * \endcode
    120      *
    121      * When the function f.b is executed, its scope will include properties of
    122      * f. So in the example above the return value of f.b() would be the new
    123      * String object that was assigned to f.prototype.
    124      *
    125      * @param exec The current execution state
    126      * @return The function's scope
    127      */
     99    void setScope(const ScopeChain& s) { _scope = s; }
    128100    const ScopeChain& scope() const { return _scope; }
    129     void setScope(const ScopeChain& s) { _scope = s; }
    130101
    131102    virtual void mark();
     
    139110
    140111    void passInParameters(ExecState*, const List&);
    141     virtual void processVarDecls(ExecState*);
    142   };
    143 
    144   class DeclaredFunctionImp : public FunctionImp {
    145   public:
    146     DeclaredFunctionImp(ExecState*, const Identifier& n,
    147                         FunctionBodyNode* b, const ScopeChain& sc);
    148 
    149     bool implementsConstruct() const;
    150     JSObject* construct(ExecState*, const List& args);
    151 
    152     virtual Completion execute(ExecState*);
    153     CodeType codeType() const { return FunctionCode; }
    154 
    155     virtual const ClassInfo* classInfo() const { return &info; }
    156     static const ClassInfo info;
    157 
    158   private:
    159     virtual void processVarDecls(ExecState*);
     112    void processVarDecls(ExecState*);
    160113  };
    161114
     
    223176    GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
    224177    virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
    225     virtual CodeType codeType() const;
    226178    enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape,
    227179           DecodeURI, DecodeURIComponent, EncodeURI, EncodeURIComponent
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r26688 r26715  
    8181      return throwError(exec, TypeError);
    8282    }
    83     if (thisObj->inherits(&DeclaredFunctionImp::info)) {
    84         DeclaredFunctionImp *fi = static_cast<DeclaredFunctionImp*>(thisObj);
     83    if (thisObj->inherits(&FunctionImp::info)) {
     84        FunctionImp *fi = static_cast<FunctionImp*>(thisObj);
    8585        return jsString("function " + fi->functionName().ustring() + "(" +
    8686                        fi->body->paramString() + ") " + fi->body->toString());
     
    209209  FunctionBodyNode *bodyNode = progNode.get();
    210210
    211   FunctionImp* fimp = new DeclaredFunctionImp(exec, functionName, bodyNode, scopeChain);
     211  FunctionImp* fimp = new FunctionImp(exec, functionName, bodyNode, scopeChain);
    212212 
    213213  // parse parameter list. throw syntax error on illegal identifiers
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r26689 r26715  
    24972497
    24982498  // TODO: let this be an object with [[Class]] property "Function"
    2499   FunctionImp *func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain());
     2499  FunctionImp *func = new FunctionImp(exec, ident, body.get(), context->scopeChain());
    25002500
    25012501  JSObject *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
     
    25372537  }
    25382538
    2539   FunctionImp* func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain());
     2539  FunctionImp* func = new FunctionImp(exec, ident, body.get(), context->scopeChain());
    25402540  JSObject* proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
    25412541  proto->put(exec, exec->propertyNames().constructor, func, ReadOnly | DontDelete | DontEnum);
Note: See TracChangeset for help on using the changeset viewer.