Changeset 26715 in webkit
- Timestamp:
- Oct 17, 2007, 2:01:27 PM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r26707 r26715 1 2007-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 1 35 2007-10-17 Adam Roben <[email protected]> 2 36 -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r26697 r26715 218 218 935AF46E09E9D9DB00ACD1D8 /* UnusedParam.h in Headers */ = {isa = PBXBuildFile; fileRef = 935AF46B09E9D9DB00ACD1D8 /* UnusedParam.h */; }; 219 219 935F69FE08245057003D1A45 /* dftables.c in Sources */ = {isa = PBXBuildFile; fileRef = 6541720E039E08B90058BFEB /* dftables.c */; }; 220 220 937013480CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.c in Sources */ = {isa = PBXBuildFile; fileRef = 937013470CA97E0E00FA14D3 /* pcre_ucp_searchfuncs.c */; settings = {COMPILER_FLAGS = "-Wno-sign-compare"; }; }; 221 221 938C4F6A0CA06BC700D9310A /* ASCIICType.h in Headers */ = {isa = PBXBuildFile; fileRef = 938C4F690CA06BC700D9310A /* ASCIICType.h */; settings = {ATTRIBUTES = (Private, ); }; }; 222 222 938C4F6C0CA06BCE00D9310A /* DisallowCType.h in Headers */ = {isa = PBXBuildFile; fileRef = 938C4F6B0CA06BCE00D9310A /* DisallowCType.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1366 1366 isa = PBXProject; 1367 1367 buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject "JavaScriptCore" */; 1368 compatibilityVersion = "Xcode 2.4"; 1368 1369 hasScannedForEncodings = 1; 1369 1370 mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */; -
trunk/JavaScriptCore/bindings/runtime_method.cpp
r23538 r26715 93 93 } 94 94 95 CodeType RuntimeMethod::codeType() const96 {97 return FunctionCode;98 }99 100 95 Completion RuntimeMethod::execute(ExecState*) 101 96 { -
trunk/JavaScriptCore/bindings/runtime_method.h
r23538 r26715 43 43 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); 44 44 45 virtual CodeType codeType() const;46 47 45 virtual Completion execute(ExecState *exec); 48 46 -
trunk/JavaScriptCore/kjs/function.cpp
r26690 r26715 49 49 // ----------------------------- FunctionImp ---------------------------------- 50 50 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) 51 const ClassInfo FunctionImp::info = { "Function", &InternalFunctionImp::info, 0, 0 }; 52 53 FunctionImp::FunctionImp(ExecState* exec, const Identifier& name, FunctionBodyNode* b, const ScopeChain& sc) 54 : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name) 56 55 , body(b) 56 , _scope(sc) 57 57 { 58 58 } … … 64 64 } 65 65 66 FunctionImp::~FunctionImp()67 {68 }69 70 66 JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 71 67 { … … 74 70 // enter a new execution context 75 71 Context ctx(globalObj, exec->dynamicInterpreter(), thisObj, body.get(), 76 codeType(), exec->context(), this, &args);72 FunctionCode, exec->context(), this, &args); 77 73 ExecState newExec(exec->dynamicInterpreter(), &ctx); 78 74 if (exec->hadException()) … … 80 76 ctx.setExecState(&newExec); 81 77 82 // assign user supplied arguments to parameters83 78 passInParameters(&newExec, args); 84 // add variable declarations (initialized to undefined)85 79 processVarDecls(&newExec); 86 80 … … 89 83 int lineno = -1; 90 84 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(); 95 87 96 88 bool cont = dbg->callEvent(&newExec,sid,lineno,this,args); … … 113 105 114 106 if (dbg) { 115 if (inherits(&DeclaredFunctionImp::info)) 116 lineno = static_cast<DeclaredFunctionImp*>(this)->body->lastLine(); 107 lineno = body->lastLine(); 117 108 118 109 if (comp.complType() == Throw) … … 147 138 variable->put(exec, parameters[i], args[i], DontDelete); 148 139 } 149 }150 151 void FunctionImp::processVarDecls(ExecState*)152 {153 140 } 154 141 … … 256 243 } 257 244 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() const271 {272 return true;273 }274 275 245 // ECMA 13.2.2 [[Construct]] 276 JSObject* DeclaredFunctionImp::construct(ExecState* exec, const List& args)246 JSObject* FunctionImp::construct(ExecState* exec, const List& args) 277 247 { 278 248 JSObject* proto; … … 293 263 } 294 264 295 Completion DeclaredFunctionImp::execute(ExecState* exec)265 Completion FunctionImp::execute(ExecState* exec) 296 266 { 297 267 Completion result = body->execute(exec); … … 302 272 } 303 273 304 void DeclaredFunctionImp::processVarDecls(ExecState* exec)274 void FunctionImp::processVarDecls(ExecState* exec) 305 275 { 306 276 body->processDeclarations(exec); … … 525 495 { 526 496 putDirect(exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum); 527 }528 529 CodeType GlobalFuncImp::codeType() const530 {531 return id == Eval ? EvalCode : codeType();532 497 } 533 498 -
trunk/JavaScriptCore/kjs/function.h
r26620 r26715 73 73 }; 74 74 75 /**76 * @short Implementation class for internal Functions.77 */78 75 class FunctionImp : public InternalFunctionImp { 79 76 friend class ActivationImp; 80 77 public: 81 FunctionImp(ExecState*, const Identifier& n, FunctionBodyNode* b); 82 virtual ~FunctionImp(); 78 FunctionImp(ExecState*, const Identifier& name, FunctionBodyNode*, const ScopeChain&); 83 79 84 80 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); … … 86 82 virtual bool deleteProperty(ExecState*, const Identifier& propertyName); 87 83 84 virtual bool implementsConstruct() const { return true; } 85 virtual JSObject* construct(ExecState*, const List& args); 86 88 87 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args); 88 Completion execute(ExecState*); 89 89 90 90 // Note: unlike body->paramName, this returns Identifier::null for parameters 91 91 // that will never get set, due to later param having the same name 92 92 Identifier getParameterName(int index); 93 virtual CodeType codeType() const = 0;94 95 virtual Completion execute(ExecState*) = 0;96 93 97 94 virtual const ClassInfo* classInfo() const { return &info; } … … 100 97 RefPtr<FunctionBodyNode> body; 101 98 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; } 128 100 const ScopeChain& scope() const { return _scope; } 129 void setScope(const ScopeChain& s) { _scope = s; }130 101 131 102 virtual void mark(); … … 139 110 140 111 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*); 160 113 }; 161 114 … … 223 176 GlobalFuncImp(ExecState*, FunctionPrototype*, int i, int len, const Identifier&); 224 177 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args); 225 virtual CodeType codeType() const;226 178 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape, 227 179 DecodeURI, DecodeURIComponent, EncodeURI, EncodeURIComponent -
trunk/JavaScriptCore/kjs/function_object.cpp
r26688 r26715 81 81 return throwError(exec, TypeError); 82 82 } 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); 85 85 return jsString("function " + fi->functionName().ustring() + "(" + 86 86 fi->body->paramString() + ") " + fi->body->toString()); … … 209 209 FunctionBodyNode *bodyNode = progNode.get(); 210 210 211 FunctionImp* fimp = new DeclaredFunctionImp(exec, functionName, bodyNode, scopeChain);211 FunctionImp* fimp = new FunctionImp(exec, functionName, bodyNode, scopeChain); 212 212 213 213 // parse parameter list. throw syntax error on illegal identifiers -
trunk/JavaScriptCore/kjs/nodes.cpp
r26689 r26715 2497 2497 2498 2498 // 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()); 2500 2500 2501 2501 JSObject *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); … … 2537 2537 } 2538 2538 2539 FunctionImp* func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain());2539 FunctionImp* func = new FunctionImp(exec, ident, body.get(), context->scopeChain()); 2540 2540 JSObject* proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 2541 2541 proto->put(exec, exec->propertyNames().constructor, func, ReadOnly | DontDelete | DontEnum);
Note:
See TracChangeset
for help on using the changeset viewer.