Changeset 17483 in webkit for trunk/JavaScriptCore/kjs/function.cpp
- Timestamp:
- Oct 31, 2006, 10:16:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function.cpp
r17372 r17483 52 52 public: 53 53 Parameter() {}; 54 Parameter(const Identifier &n) : name(n) { }54 Parameter(const Identifier& n) : name(n) { } 55 55 Identifier name; 56 56 }; 57 57 58 FunctionImp::FunctionImp(ExecState *exec, const Identifier &n, FunctionBodyNode* b)58 FunctionImp::FunctionImp(ExecState* exec, const Identifier& n, FunctionBodyNode* b) 59 59 : InternalFunctionImp(static_cast<FunctionPrototype*> 60 60 (exec->lexicalInterpreter()->builtinFunctionPrototype()), n) … … 73 73 } 74 74 75 JSValue *FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)76 { 77 JSObject *globalObj = exec->dynamicInterpreter()->globalObject();75 JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 76 { 77 JSObject* globalObj = exec->dynamicInterpreter()->globalObject(); 78 78 79 79 // enter a new execution context … … 90 90 processVarDecls(&newExec); 91 91 92 Debugger *dbg = exec->dynamicInterpreter()->debugger();92 Debugger* dbg = exec->dynamicInterpreter()->debugger(); 93 93 int sid = -1; 94 94 int lineno = -1; … … 150 150 } 151 151 152 void FunctionImp::addParameter(const Identifier &n)152 void FunctionImp::addParameter(const Identifier& n) 153 153 { 154 154 if (!parameters) … … 176 176 177 177 // ECMA 10.1.3q 178 void FunctionImp::processParameters(ExecState *exec, const List &args)178 void FunctionImp::processParameters(ExecState* exec, const List& args) 179 179 { 180 180 if (!parameters) … … 191 191 ListIterator it = args.begin(); 192 192 193 JSValue *v = *it;193 JSValue * v = *it; 194 194 for (size_t i = 0; i < parameters->size(); ++i) { 195 195 if (it != args.end()) { … … 215 215 } 216 216 217 JSValue *FunctionImp::argumentsGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)218 { 219 FunctionImp *thisObj = static_cast<FunctionImp*>(slot.slotBase());220 Context *context = exec->m_context;217 JSValue* FunctionImp::argumentsGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) 218 { 219 FunctionImp* thisObj = static_cast<FunctionImp*>(slot.slotBase()); 220 Context* context = exec->m_context; 221 221 while (context) { 222 222 if (context->function() == thisObj) { 223 return static_cast<ActivationImp 223 return static_cast<ActivationImp*>(context->activationObject())->get(exec, propertyName); 224 224 } 225 225 context = context->callingContext(); … … 228 228 } 229 229 230 JSValue *FunctionImp::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot) 231 { 232 FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase()); 230 JSValue* FunctionImp::callerGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot& slot) 231 { 232 FunctionImp* thisObj = static_cast<FunctionImp* >(slot.slotBase()); 233 Context* context = exec->m_context; 234 while (context) { 235 if (context->function() == thisObj) 236 return (context->callingContext()->function()) ? context->callingContext()->function() : jsNull(); 237 238 context = context->callingContext(); 239 } 240 return jsNull(); 241 } 242 243 JSValue* FunctionImp::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot) 244 { 245 FunctionImp* thisObj = static_cast<FunctionImp*>(slot.slotBase()); 233 246 return jsNumber(thisObj->parameters ? thisObj->parameters->size() : 0); 234 247 } 235 248 236 bool FunctionImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)249 bool FunctionImp::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 237 250 { 238 251 // Find the arguments from the closest context. … … 241 254 return true; 242 255 } 243 256 244 257 // Compute length of parameters. 245 258 if (propertyName == lengthPropertyName) { … … 247 260 return true; 248 261 } 249 262 263 if (propertyName == callerPropertyName) { 264 slot.setCustom(this, callerGetter); 265 return true; 266 } 267 250 268 return InternalFunctionImp::getOwnPropertySlot(exec, propertyName, slot); 251 269 } 252 270 253 void FunctionImp::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)271 void FunctionImp::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) 254 272 { 255 273 if (propertyName == exec->dynamicInterpreter()->argumentsIdentifier() || propertyName == lengthPropertyName) … … 258 276 } 259 277 260 bool FunctionImp::deleteProperty(ExecState *exec, const Identifier &propertyName)278 bool FunctionImp::deleteProperty(ExecState* exec, const Identifier& propertyName) 261 279 { 262 280 if (propertyName == exec->dynamicInterpreter()->argumentsIdentifier() || propertyName == lengthPropertyName) … … 295 313 const ClassInfo DeclaredFunctionImp::info = {"Function", &FunctionImp::info, 0, 0}; 296 314 297 DeclaredFunctionImp::DeclaredFunctionImp(ExecState *exec, const Identifier &n,298 FunctionBodyNode *b, const ScopeChain &sc)315 DeclaredFunctionImp::DeclaredFunctionImp(ExecState* exec, const Identifier& n, 316 FunctionBodyNode* b, const ScopeChain& sc) 299 317 : FunctionImp(exec, n, b) 300 318 { … … 308 326 309 327 // ECMA 13.2.2 [[Construct]] 310 JSObject *DeclaredFunctionImp::construct(ExecState *exec, const List &args)311 { 312 JSObject *proto;313 JSValue *p = get(exec,prototypePropertyName);328 JSObject* DeclaredFunctionImp::construct(ExecState* exec, const List& args) 329 { 330 JSObject* proto; 331 JSValue* p = get(exec,prototypePropertyName); 314 332 if (p->isObject()) 315 333 proto = static_cast<JSObject*>(p); … … 317 335 proto = exec->lexicalInterpreter()->builtinObjectPrototype(); 318 336 319 JSObject *obj(new JSObject(proto));320 321 JSValue *res = call(exec,obj,args);337 JSObject* obj(new JSObject(proto)); 338 339 JSValue* res = call(exec,obj,args); 322 340 323 341 if (res->isObject()) 324 return static_cast<JSObject 342 return static_cast<JSObject*>(res); 325 343 else 326 344 return obj; 327 345 } 328 346 329 Completion DeclaredFunctionImp::execute(ExecState *exec)347 Completion DeclaredFunctionImp::execute(ExecState* exec) 330 348 { 331 349 Completion result = body->execute(exec); … … 336 354 } 337 355 338 void DeclaredFunctionImp::processVarDecls(ExecState *exec)356 void DeclaredFunctionImp::processVarDecls(ExecState* exec) 339 357 { 340 358 body->processVarDecls(exec); … … 352 370 // isn't stored in the activation object. 353 371 354 IndexToNameMap::IndexToNameMap(FunctionImp *func, const List &args)372 IndexToNameMap::IndexToNameMap(FunctionImp* func, const List& args) 355 373 { 356 374 _map = new Identifier[args.size()]; … … 367 385 } 368 386 369 bool IndexToNameMap::isMapped(const Identifier &index) const387 bool IndexToNameMap::isMapped(const Identifier& index) const 370 388 { 371 389 bool indexIsNumber; … … 384 402 } 385 403 386 void IndexToNameMap::unMap(const Identifier &index)404 void IndexToNameMap::unMap(const Identifier& index) 387 405 { 388 406 bool indexIsNumber; … … 399 417 } 400 418 401 Identifier& IndexToNameMap::operator[](const Identifier &index)419 Identifier& IndexToNameMap::operator[](const Identifier& index) 402 420 { 403 421 bool indexIsNumber; … … 414 432 415 433 // ECMA 10.1.8 416 Arguments::Arguments(ExecState *exec, FunctionImp *func, const List &args, ActivationImp *act)434 Arguments::Arguments(ExecState* exec, FunctionImp* func, const List& args, ActivationImp* act) 417 435 : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), 418 436 _activationObject(act), … … 438 456 } 439 457 440 JSValue *Arguments::mappedIndexGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)441 { 442 Arguments *thisObj = static_cast<Arguments*>(slot.slotBase());458 JSValue* Arguments::mappedIndexGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot) 459 { 460 Arguments* thisObj = static_cast<Arguments*>(slot.slotBase()); 443 461 return thisObj->_activationObject->get(exec, thisObj->indexToNameMap[propertyName]); 444 462 } 445 463 446 bool Arguments::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)464 bool Arguments::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 447 465 { 448 466 if (indexToNameMap.isMapped(propertyName)) { … … 454 472 } 455 473 456 void Arguments::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)474 void Arguments::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) 457 475 { 458 476 if (indexToNameMap.isMapped(propertyName)) { … … 463 481 } 464 482 465 bool Arguments::deleteProperty(ExecState *exec, const Identifier &propertyName)483 bool Arguments::deleteProperty(ExecState* exec, const Identifier& propertyName) 466 484 { 467 485 if (indexToNameMap.isMapped(propertyName)) { … … 478 496 479 497 // ECMA 10.1.6 480 ActivationImp::ActivationImp(FunctionImp *function, const List &arguments)498 ActivationImp::ActivationImp(FunctionImp* function, const List& arguments) 481 499 : _function(function), _arguments(true), _argumentsObject(0) 482 500 { … … 485 503 } 486 504 487 JSValue *ActivationImp::argumentsGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot& slot)488 { 489 ActivationImp *thisObj = static_cast<ActivationImp*>(slot.slotBase());505 JSValue* ActivationImp::argumentsGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot& slot) 506 { 507 ActivationImp* thisObj = static_cast<ActivationImp*>(slot.slotBase()); 490 508 491 509 // default: return builtin arguments array … … 501 519 } 502 520 503 bool ActivationImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)521 bool ActivationImp::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 504 522 { 505 523 // do this first so property map arguments property wins over the below … … 507 525 // and we don't want to support __proto__ 508 526 509 if (JSValue **location = getDirectLocation(propertyName)) {527 if (JSValue** location = getDirectLocation(propertyName)) { 510 528 slot.setValueSlot(this, location); 511 529 return true; … … 520 538 } 521 539 522 bool ActivationImp::deleteProperty(ExecState *exec, const Identifier &propertyName)540 bool ActivationImp::deleteProperty(ExecState* exec, const Identifier& propertyName) 523 541 { 524 542 if (propertyName == exec->dynamicInterpreter()->argumentsIdentifier()) … … 546 564 } 547 565 548 void ActivationImp::createArgumentsObject(ExecState *exec) const549 { 550 _argumentsObject = new Arguments(exec, _function, _arguments, const_cast<ActivationImp 566 void ActivationImp::createArgumentsObject(ExecState* exec) const 567 { 568 _argumentsObject = new Arguments(exec, _function, _arguments, const_cast<ActivationImp*>(this)); 551 569 } 552 570 … … 566 584 } 567 585 568 static JSValue *encode(ExecState *exec, const List &args, const char *do_not_escape)586 static JSValue* encode(ExecState* exec, const List& args, const char* do_not_escape) 569 587 { 570 588 UString r = "", s, str = args[0]->toString(exec); 571 589 CString cstr = str.UTF8String(); 572 const char *p = cstr.c_str();590 const char* p = cstr.c_str(); 573 591 for (size_t k = 0; k < cstr.size(); k++, p++) { 574 592 char c = *p; … … 584 602 } 585 603 586 static JSValue *decode(ExecState *exec, const List &args, const char *do_not_unescape, bool strict)604 static JSValue* decode(ExecState* exec, const List& args, const char* do_not_unescape, bool strict) 587 605 { 588 606 UString s = "", str = args[0]->toString(exec); 589 607 int k = 0, len = str.size(); 590 const UChar *d = str.data();608 const UChar* d = str.data(); 591 609 UChar u; 592 610 while (k < len) { 593 const UChar *p = d + k;611 const UChar* p = d + k; 594 612 UChar c = *p; 595 613 if (c == '%') { … … 603 621 sequence[0] = b0; 604 622 for (int i = 1; i < sequenceLen; ++i) { 605 const UChar *q = p + i * 3;623 const UChar* q = p + i * 3; 606 624 if (q[0] == '%' && isxdigit(q[1].uc) && isxdigit(q[2].uc)) 607 625 sequence[i] = Lexer::convertHex(q[1].uc, q[2].uc); … … 684 702 } 685 703 686 static double parseInt(const UString &s, int radix)704 static double parseInt(const UString& s, int radix) 687 705 { 688 706 int length = s.size(); … … 734 752 } 735 753 736 static double parseFloat(const UString &s)754 static double parseFloat(const UString& s) 737 755 { 738 756 // Check for 0x prefix here, because toDouble allows it, but we must treat it as 0. … … 753 771 } 754 772 755 JSValue *GlobalFuncImp::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const List &args)756 { 757 JSValue *res = jsUndefined();773 JSValue* GlobalFuncImp::callAsFunction(ExecState* exec, JSObject* /*thisObj*/, const List& args) 774 { 775 JSValue* res = jsUndefined(); 758 776 759 777 static const char do_not_escape[] = … … 778 796 switch (id) { 779 797 case Eval: { // eval() 780 JSValue *x = args[0];798 JSValue* x = args[0]; 781 799 if (!x->isString()) 782 800 return x; … … 789 807 RefPtr<ProgramNode> progNode(Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg)); 790 808 791 Debugger *dbg = exec->dynamicInterpreter()->debugger();809 Debugger* dbg = exec->dynamicInterpreter()->debugger(); 792 810 if (dbg) { 793 811 bool cont = dbg->sourceParsed(exec, sid, UString(), s, 0, errLine, errMsg); … … 801 819 802 820 // enter a new execution context 803 JSObject *thisVal = static_cast<JSObject*>(exec->context()->thisValue());821 JSObject* thisVal = static_cast<JSObject*>(exec->context()->thisValue()); 804 822 Context ctx(exec->dynamicInterpreter()->globalObject(), 805 823 exec->dynamicInterpreter(), … … 858 876 { 859 877 UString r = "", s, str = args[0]->toString(exec); 860 const UChar *c = str.data();878 const UChar* c = str.data(); 861 879 for (int k = 0; k < str.size(); k++, c++) { 862 880 int u = c->uc; … … 882 900 int k = 0, len = str.size(); 883 901 while (k < len) { 884 const UChar *c = str.data() + k;902 const UChar* c = str.data() + k; 885 903 UChar u; 886 904 if (*c == UChar('%') && k <= len - 6 && *(c+1) == UChar('u')) {
Note:
See TracChangeset
for help on using the changeset viewer.