Changeset 10084 in webkit for trunk/JavaScriptCore/kjs/function_object.cpp
- Timestamp:
- Aug 7, 2005, 9:07:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function_object.cpp
r9929 r10084 41 41 : InternalFunctionImp(0) 42 42 { 43 Value protect(this); 44 putDirect(lengthPropertyName, NumberImp::zero(), DontDelete|ReadOnly|DontEnum); 43 putDirect(lengthPropertyName, jsZero(), DontDelete|ReadOnly|DontEnum); 45 44 putDirect(toStringPropertyName, new FunctionProtoFuncImp(exec, this, FunctionProtoFuncImp::ToString, 0), DontEnum); 46 45 static const Identifier applyPropertyName("apply"); … … 60 59 61 60 // ECMA 15.3.4 62 Value FunctionPrototypeImp::call(ExecState */*exec*/, Object &/*thisObj*/, const List &/*args*/)61 ValueImp *FunctionPrototypeImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/) 63 62 { 64 63 return Undefined(); … … 71 70 : InternalFunctionImp(funcProto), id(i) 72 71 { 73 Value protect(this);74 72 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum); 75 73 } … … 81 79 } 82 80 83 Value FunctionProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)84 { 85 Value result;81 ValueImp *FunctionProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) 82 { 83 ValueImp *result = NULL; 86 84 87 85 switch (id) { 88 86 case ToString: { 89 87 // ### also make this work for internal functions 90 if ( thisObj.isNull() || !thisObj.inherits(&InternalFunctionImp::info)) {88 if (!thisObj || !thisObj->inherits(&InternalFunctionImp::info)) { 91 89 #ifndef NDEBUG 92 90 fprintf(stderr,"attempted toString() call on null or non-function object\n"); 93 91 #endif 94 Object 92 ObjectImp *err = Error::create(exec,TypeError); 95 93 exec->setException(err); 96 94 return err; 97 95 } 98 if (thisObj .inherits(&DeclaredFunctionImp::info)) {96 if (thisObj->inherits(&DeclaredFunctionImp::info)) { 99 97 DeclaredFunctionImp *fi = static_cast<DeclaredFunctionImp*> 100 (thisObj .imp());98 (thisObj); 101 99 return String("function " + fi->name().ustring() + "(" + 102 100 fi->parameterString() + ") " + fi->body->toString()); 103 } else if (thisObj .inherits(&FunctionImp::info) &&104 !static_cast<FunctionImp*>(thisObj .imp())->name().isNull()) {105 result = String("function " + static_cast<FunctionImp*>(thisObj .imp())->name().ustring() + "()");101 } else if (thisObj->inherits(&FunctionImp::info) && 102 !static_cast<FunctionImp*>(thisObj)->name().isNull()) { 103 result = String("function " + static_cast<FunctionImp*>(thisObj)->name().ustring() + "()"); 106 104 } 107 105 else { … … 111 109 break; 112 110 case Apply: { 113 Value 114 Value 115 Object 116 117 if (!func .implementsCall()) {118 Object 111 ValueImp *thisArg = args[0]; 112 ValueImp *argArray = args[1]; 113 ObjectImp *func = thisObj; 114 115 if (!func->implementsCall()) { 116 ObjectImp *err = Error::create(exec,TypeError); 119 117 exec->setException(err); 120 118 return err; 121 119 } 122 120 123 Object 124 if (thisArg .isA(NullType) || thisArg.isA(UndefinedType))121 ObjectImp *applyThis; 122 if (thisArg->isUndefinedOrNull()) 125 123 applyThis = exec->dynamicInterpreter()->globalObject(); 126 124 else 127 applyThis = thisArg .toObject(exec);125 applyThis = thisArg->toObject(exec); 128 126 129 127 List applyArgs; 130 if (!argArray .isA(NullType) && !argArray.isA(UndefinedType)) {131 if (argArray .isA(ObjectType) &&132 ( Object::dynamicCast(argArray).inherits(&ArrayInstanceImp::info) ||133 Object::dynamicCast(argArray).inherits(&ArgumentsImp::info))) {134 135 Object argArrayObj = Object::dynamicCast(argArray);136 unsigned int length = argArrayObj .get(exec,lengthPropertyName).toUInt32(exec);128 if (!argArray->isUndefinedOrNull()) { 129 if (argArray->isObject() && 130 (static_cast<ObjectImp *>(argArray)->inherits(&ArrayInstanceImp::info) || 131 static_cast<ObjectImp *>(argArray)->inherits(&ArgumentsImp::info))) { 132 133 ObjectImp *argArrayObj = static_cast<ObjectImp *>(argArray); 134 unsigned int length = argArrayObj->get(exec,lengthPropertyName)->toUInt32(exec); 137 135 for (unsigned int i = 0; i < length; i++) 138 applyArgs.append(argArrayObj .get(exec,i));136 applyArgs.append(argArrayObj->get(exec,i)); 139 137 } 140 138 else { 141 Object 139 ObjectImp *err = Error::create(exec,TypeError); 142 140 exec->setException(err); 143 141 return err; 144 142 } 145 143 } 146 result = func .call(exec,applyThis,applyArgs);144 result = func->call(exec,applyThis,applyArgs); 147 145 } 148 146 break; 149 147 case Call: { 150 Value 151 Object 152 153 if (!func .implementsCall()) {154 Object 148 ValueImp *thisArg = args[0]; 149 ObjectImp *func = thisObj; 150 151 if (!func->implementsCall()) { 152 ObjectImp *err = Error::create(exec,TypeError); 155 153 exec->setException(err); 156 154 return err; 157 155 } 158 156 159 Object 160 if (thisArg .isA(NullType) || thisArg.isA(UndefinedType))157 ObjectImp *callThis; 158 if (thisArg->isUndefinedOrNull()) 161 159 callThis = exec->dynamicInterpreter()->globalObject(); 162 160 else 163 callThis = thisArg .toObject(exec);164 165 result = func .call(exec,callThis,args.copyTail());161 callThis = thisArg->toObject(exec); 162 163 result = func->call(exec,callThis,args.copyTail()); 166 164 } 167 165 break; … … 176 174 : InternalFunctionImp(funcProto) 177 175 { 178 Value protect(this);179 176 putDirect(prototypePropertyName, funcProto, DontEnum|DontDelete|ReadOnly); 180 177 181 178 // no. of arguments for constructor 182 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);179 putDirect(lengthPropertyName, jsOne(), ReadOnly|DontDelete|DontEnum); 183 180 } 184 181 … … 193 190 194 191 // ECMA 15.3.2 The Function Constructor 195 Object 192 ObjectImp *FunctionObjectImp::construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber) 196 193 { 197 194 UString p(""); … … 201 198 body = ""; 202 199 } else if (argsSize == 1) { 203 body = args[0] .toString(exec);200 body = args[0]->toString(exec); 204 201 } else { 205 p = args[0] .toString(exec);202 p = args[0]->toString(exec); 206 203 for (int k = 1; k < argsSize - 1; k++) 207 p += "," + args[k] .toString(exec);208 body = args[argsSize-1] .toString(exec);204 p += "," + args[k]->toString(exec); 205 body = args[argsSize-1]->toString(exec); 209 206 } 210 207 … … 222 219 if (!cont) { 223 220 dbg->imp()->abort(); 224 return Object(new ObjectImp());221 return new ObjectImp(); 225 222 } 226 223 } … … 228 225 // no program node == syntax error - throw a syntax error 229 226 if (!progNode) { 230 Object 227 ObjectImp *err = Error::create(exec,SyntaxError,errMsg.ascii(),errLine); 231 228 // we can't return a Completion(Throw) here, so just set the exception 232 229 // and return it … … 236 233 237 234 ScopeChain scopeChain; 238 scopeChain.push(exec->dynamicInterpreter()->globalObject() .imp());235 scopeChain.push(exec->dynamicInterpreter()->globalObject()); 239 236 FunctionBodyNode *bodyNode = progNode; 240 237 241 238 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, 242 239 scopeChain); 243 Object ret(fimp); // protect from GC244 240 245 241 // parse parameter list. throw syntax error on illegal identifiers … … 272 268 } // else error 273 269 } 274 Object 270 ObjectImp *err = Error::create(exec,SyntaxError, 275 271 I18N_NOOP("Syntax error in parameter list"), 276 272 -1); … … 281 277 List consArgs; 282 278 283 Object 284 Object prototype = objCons.construct(exec,List::empty());285 prototype .put(exec, constructorPropertyName, Value(fimp), DontEnum|DontDelete|ReadOnly);279 ObjectImp *objCons = exec->lexicalInterpreter()->builtinObject(); 280 ObjectImp *prototype = objCons->construct(exec,List::empty()); 281 prototype->put(exec, constructorPropertyName, fimp, DontEnum|DontDelete|ReadOnly); 286 282 fimp->put(exec, prototypePropertyName, prototype, DontEnum|DontDelete|ReadOnly); 287 return ret;283 return fimp; 288 284 } 289 285 290 286 // ECMA 15.3.2 The Function Constructor 291 Object 287 ObjectImp *FunctionObjectImp::construct(ExecState *exec, const List &args) 292 288 { 293 289 return FunctionObjectImp::construct(exec, args, UString(), 0); … … 301 297 302 298 // ECMA 15.3.1 The Function Constructor Called as a Function 303 Value FunctionObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)299 ValueImp *FunctionObjectImp::callAsFunction(ExecState *exec, ObjectImp */*thisObj*/, const List &args) 304 300 { 305 301 return construct(exec,args);
Note:
See TracChangeset
for help on using the changeset viewer.