Changeset 34754 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Jun 23, 2008, 10:23:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r34659 r34754 22 22 #include "config.h" 23 23 #include "string_object.h" 24 #include "string_object.lut.h"25 24 26 25 #include "JSWrapperObject.h" … … 37 36 namespace KJS { 38 37 38 static JSValue* stringProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&); 39 static JSValue* stringProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&); 40 static JSValue* stringProtoFuncCharAt(ExecState*, JSObject*, JSValue*, const ArgList&); 41 static JSValue* stringProtoFuncCharCodeAt(ExecState*, JSObject*, JSValue*, const ArgList&); 42 static JSValue* stringProtoFuncConcat(ExecState*, JSObject*, JSValue*, const ArgList&); 43 static JSValue* stringProtoFuncIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&); 44 static JSValue* stringProtoFuncLastIndexOf(ExecState*, JSObject*, JSValue*, const ArgList&); 45 static JSValue* stringProtoFuncMatch(ExecState*, JSObject*, JSValue*, const ArgList&); 46 static JSValue* stringProtoFuncReplace(ExecState*, JSObject*, JSValue*, const ArgList&); 47 static JSValue* stringProtoFuncSearch(ExecState*, JSObject*, JSValue*, const ArgList&); 48 static JSValue* stringProtoFuncSlice(ExecState*, JSObject*, JSValue*, const ArgList&); 49 static JSValue* stringProtoFuncSplit(ExecState*, JSObject*, JSValue*, const ArgList&); 50 static JSValue* stringProtoFuncSubstr(ExecState*, JSObject*, JSValue*, const ArgList&); 51 static JSValue* stringProtoFuncSubstring(ExecState*, JSObject*, JSValue*, const ArgList&); 52 static JSValue* stringProtoFuncToLowerCase(ExecState*, JSObject*, JSValue*, const ArgList&); 53 static JSValue* stringProtoFuncToUpperCase(ExecState*, JSObject*, JSValue*, const ArgList&); 54 static JSValue* stringProtoFuncToLocaleLowerCase(ExecState*, JSObject*, JSValue*, const ArgList&); 55 static JSValue* stringProtoFuncToLocaleUpperCase(ExecState*, JSObject*, JSValue*, const ArgList&); 56 static JSValue* stringProtoFuncLocaleCompare(ExecState*, JSObject*, JSValue*, const ArgList&); 57 58 static JSValue* stringProtoFuncBig(ExecState*, JSObject*, JSValue*, const ArgList&); 59 static JSValue* stringProtoFuncSmall(ExecState*, JSObject*, JSValue*, const ArgList&); 60 static JSValue* stringProtoFuncBlink(ExecState*, JSObject*, JSValue*, const ArgList&); 61 static JSValue* stringProtoFuncBold(ExecState*, JSObject*, JSValue*, const ArgList&); 62 static JSValue* stringProtoFuncFixed(ExecState*, JSObject*, JSValue*, const ArgList&); 63 static JSValue* stringProtoFuncItalics(ExecState*, JSObject*, JSValue*, const ArgList&); 64 static JSValue* stringProtoFuncStrike(ExecState*, JSObject*, JSValue*, const ArgList&); 65 static JSValue* stringProtoFuncSub(ExecState*, JSObject*, JSValue*, const ArgList&); 66 static JSValue* stringProtoFuncSup(ExecState*, JSObject*, JSValue*, const ArgList&); 67 static JSValue* stringProtoFuncFontcolor(ExecState*, JSObject*, JSValue*, const ArgList&); 68 static JSValue* stringProtoFuncFontsize(ExecState*, JSObject*, JSValue*, const ArgList&); 69 static JSValue* stringProtoFuncAnchor(ExecState*, JSObject*, JSValue*, const ArgList&); 70 static JSValue* stringProtoFuncLink(ExecState*, JSObject*, JSValue*, const ArgList&); 71 72 } 73 74 #include "string_object.lut.h" 75 76 namespace KJS { 77 39 78 // ------------------------------ StringObject ---------------------------- 40 79 … … 99 138 /* Source for string_object.lut.h 100 139 @begin stringTable 26 101 toString &stringProtoFuncToString DontEnum|Function 0102 valueOf &stringProtoFuncValueOf DontEnum|Function 0103 charAt &stringProtoFuncCharAt DontEnum|Function 1104 charCodeAt &stringProtoFuncCharCodeAt DontEnum|Function 1105 concat &stringProtoFuncConcat DontEnum|Function 1106 indexOf &stringProtoFuncIndexOf DontEnum|Function 1107 lastIndexOf &stringProtoFuncLastIndexOf DontEnum|Function 1108 match &stringProtoFuncMatch DontEnum|Function 1109 replace &stringProtoFuncReplace DontEnum|Function 2110 search &stringProtoFuncSearch DontEnum|Function 1111 slice &stringProtoFuncSlice DontEnum|Function 2112 split &stringProtoFuncSplit DontEnum|Function 2113 substr &stringProtoFuncSubstr DontEnum|Function 2114 substring &stringProtoFuncSubstring DontEnum|Function 2115 toLowerCase &stringProtoFuncToLowerCase DontEnum|Function 0116 toUpperCase &stringProtoFuncToUpperCase DontEnum|Function 0117 toLocaleLowerCase &stringProtoFuncToLocaleLowerCase DontEnum|Function 0118 toLocaleUpperCase &stringProtoFuncToLocaleUpperCase DontEnum|Function 0119 localeCompare &stringProtoFuncLocaleCompare DontEnum|Function 1120 121 big &stringProtoFuncBig DontEnum|Function 0122 small &stringProtoFuncSmall DontEnum|Function 0123 blink &stringProtoFuncBlink DontEnum|Function 0124 bold &stringProtoFuncBold DontEnum|Function 0125 fixed &stringProtoFuncFixed DontEnum|Function 0126 italics &stringProtoFuncItalics DontEnum|Function 0127 strike &stringProtoFuncStrike DontEnum|Function 0128 sub &stringProtoFuncSub DontEnum|Function 0129 sup &stringProtoFuncSup DontEnum|Function 0130 fontcolor &stringProtoFuncFontcolor DontEnum|Function 1131 fontsize &stringProtoFuncFontsize DontEnum|Function 1132 anchor &stringProtoFuncAnchor DontEnum|Function 1133 link &stringProtoFuncLink DontEnum|Function 1140 toString stringProtoFuncToString DontEnum|Function 0 141 valueOf stringProtoFuncValueOf DontEnum|Function 0 142 charAt stringProtoFuncCharAt DontEnum|Function 1 143 charCodeAt stringProtoFuncCharCodeAt DontEnum|Function 1 144 concat stringProtoFuncConcat DontEnum|Function 1 145 indexOf stringProtoFuncIndexOf DontEnum|Function 1 146 lastIndexOf stringProtoFuncLastIndexOf DontEnum|Function 1 147 match stringProtoFuncMatch DontEnum|Function 1 148 replace stringProtoFuncReplace DontEnum|Function 2 149 search stringProtoFuncSearch DontEnum|Function 1 150 slice stringProtoFuncSlice DontEnum|Function 2 151 split stringProtoFuncSplit DontEnum|Function 2 152 substr stringProtoFuncSubstr DontEnum|Function 2 153 substring stringProtoFuncSubstring DontEnum|Function 2 154 toLowerCase stringProtoFuncToLowerCase DontEnum|Function 0 155 toUpperCase stringProtoFuncToUpperCase DontEnum|Function 0 156 toLocaleLowerCase stringProtoFuncToLocaleLowerCase DontEnum|Function 0 157 toLocaleUpperCase stringProtoFuncToLocaleUpperCase DontEnum|Function 0 158 localeCompare stringProtoFuncLocaleCompare DontEnum|Function 1 159 160 big stringProtoFuncBig DontEnum|Function 0 161 small stringProtoFuncSmall DontEnum|Function 0 162 blink stringProtoFuncBlink DontEnum|Function 0 163 bold stringProtoFuncBold DontEnum|Function 0 164 fixed stringProtoFuncFixed DontEnum|Function 0 165 italics stringProtoFuncItalics DontEnum|Function 0 166 strike stringProtoFuncStrike DontEnum|Function 0 167 sub stringProtoFuncSub DontEnum|Function 0 168 sup stringProtoFuncSup DontEnum|Function 0 169 fontcolor stringProtoFuncFontcolor DontEnum|Function 1 170 fontsize stringProtoFuncFontsize DontEnum|Function 1 171 anchor stringProtoFuncAnchor DontEnum|Function 1 172 link stringProtoFuncLink DontEnum|Function 1 134 173 @end 135 174 */ … … 268 307 { 269 308 UString source = sourceVal->value(); 270 JSObject *replacementFunction = 0;309 CallData callData; 271 310 UString replacementString; 272 311 273 if (replacement->isObject() && replacement->toObject(exec)->implementsCall()) 274 replacementFunction = replacement->toObject(exec); 275 else 312 CallType callType = replacement->getCallData(callData); 313 if (callType == CallTypeNone) 276 314 replacementString = replacement->toString(exec); 277 315 … … 304 342 305 343 UString substitutedReplacement; 306 if ( replacementFunction) {344 if (callType != CallTypeNone) { 307 345 int completeMatchStart = ovector[0]; 308 346 ArgList args; … … 321 359 args.append(sourceVal); 322 360 323 substitutedReplacement = replacementFunction->callAsFunction(exec, exec->globalThisValue(), args)->toString(exec);361 substitutedReplacement = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec); 324 362 } else 325 363 substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg); … … 363 401 return sourceVal; 364 402 365 if ( replacementFunction) {403 if (callType != CallTypeNone) { 366 404 ArgList args; 367 405 … … 370 408 args.append(sourceVal); 371 409 372 replacementString = replacementFunction->callAsFunction(exec, exec->globalThisValue(), args)->toString(exec);410 replacementString = call(exec, replacement, callType, callData, exec->globalThisValue(), args)->toString(exec); 373 411 } 374 412 … … 376 414 } 377 415 378 JSValue* stringProtoFuncToString(ExecState* exec, JSObject* thisObj, const ArgList&)379 { 380 if (!this Obj->inherits(&StringObject::info))416 JSValue* stringProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 417 { 418 if (!thisValue->isObject(&StringObject::info)) 381 419 return throwError(exec, TypeError); 382 420 383 return static_cast<StringObject*>(this Obj)->internalValue();384 } 385 386 JSValue* stringProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const ArgList&)387 { 388 if (!this Obj->inherits(&StringObject::info))421 return static_cast<StringObject*>(thisValue)->internalValue(); 422 } 423 424 JSValue* stringProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 425 { 426 if (!thisValue->isObject(&StringObject::info)) 389 427 return throwError(exec, TypeError); 390 428 391 return static_cast<StringObject*>(this Obj)->internalValue();392 } 393 394 JSValue* stringProtoFuncCharAt(ExecState* exec, JSObject* thisObj, const ArgList& args)395 { 396 // This optimizes the common case that thisObj is a StringObject 397 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);429 return static_cast<StringObject*>(thisValue)->internalValue(); 430 } 431 432 JSValue* stringProtoFuncCharAt(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 433 { 434 // This optimizes the common case that thisObj is a StringObject 435 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 398 436 int len = s.size(); 399 437 … … 408 446 } 409 447 410 JSValue* stringProtoFuncCharCodeAt(ExecState* exec, JSObject* thisObj, const ArgList& args)411 { 412 // This optimizes the common case that thisObj is a StringObject 413 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);448 JSValue* stringProtoFuncCharCodeAt(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 449 { 450 // This optimizes the common case that thisObj is a StringObject 451 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 414 452 int len = s.size(); 415 453 … … 425 463 } 426 464 427 JSValue* stringProtoFuncConcat(ExecState* exec, JSObject* thisObj, const ArgList& args)428 { 429 // This optimizes the common case that thisObj is a StringObject 430 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);465 JSValue* stringProtoFuncConcat(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 466 { 467 // This optimizes the common case that thisObj is a StringObject 468 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 431 469 432 470 ArgList::const_iterator end = args.end(); … … 437 475 } 438 476 439 JSValue* stringProtoFuncIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)440 { 441 // This optimizes the common case that thisObj is a StringObject 442 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);477 JSValue* stringProtoFuncIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 478 { 479 // This optimizes the common case that thisObj is a StringObject 480 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 443 481 int len = s.size(); 444 482 … … 454 492 } 455 493 456 JSValue* stringProtoFuncLastIndexOf(ExecState* exec, JSObject* thisObj, const ArgList& args)457 { 458 // This optimizes the common case that thisObj is a StringObject 459 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);494 JSValue* stringProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 495 { 496 // This optimizes the common case that thisObj is a StringObject 497 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 460 498 int len = s.size(); 461 499 … … 472 510 } 473 511 474 JSValue* stringProtoFuncMatch(ExecState* exec, JSObject* thisObj, const ArgList& args)475 { 476 // This optimizes the common case that thisObj is a StringObject 477 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);512 JSValue* stringProtoFuncMatch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 513 { 514 // This optimizes the common case that thisObj is a StringObject 515 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 478 516 479 517 JSValue* a0 = args[0]; … … 521 559 result = jsNull(); 522 560 } else { 523 result = exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);561 result = constructArray(exec, list); 524 562 } 525 563 } … … 527 565 } 528 566 529 JSValue* stringProtoFuncSearch(ExecState* exec, JSObject* thisObj, const ArgList& args)530 { 531 // This optimizes the common case that thisObj is a StringObject 532 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);567 JSValue* stringProtoFuncSearch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 568 { 569 // This optimizes the common case that thisObj is a StringObject 570 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 533 571 534 572 JSValue* a0 = args[0]; … … 553 591 } 554 592 555 JSValue* stringProtoFuncReplace(ExecState* exec, JSObject* thisObj, const ArgList& args)556 { 557 // This optimizes the common case that thisObj is a StringObject 558 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);559 560 JSString* sVal = this Obj->inherits(&StringObject::info) ?561 static_cast<StringObject*>(this Obj)->internalValue() :593 JSValue* stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 594 { 595 // This optimizes the common case that thisObj is a StringObject 596 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 597 598 JSString* sVal = thisValue->isObject(&StringObject::info) ? 599 static_cast<StringObject*>(thisValue)->internalValue() : 562 600 static_cast<JSString*>(jsString(exec, s)); 563 601 … … 568 606 } 569 607 570 JSValue* stringProtoFuncSlice(ExecState* exec, JSObject* thisObj, const ArgList& args)571 { 572 // This optimizes the common case that thisObj is a StringObject 573 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);608 JSValue* stringProtoFuncSlice(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 609 { 610 // This optimizes the common case that thisObj is a StringObject 611 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 574 612 int len = s.size(); 575 613 … … 593 631 } 594 632 595 JSValue* stringProtoFuncSplit(ExecState* exec, JSObject* thisObj, const ArgList& args)596 { 597 // This optimizes the common case that thisObj is a StringObject 598 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);633 JSValue* stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 634 { 635 // This optimizes the common case that thisObj is a StringObject 636 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 599 637 600 638 JSValue* a0 = args[0]; 601 639 JSValue* a1 = args[1]; 602 640 603 JSObject *constructor = exec->lexicalGlobalObject()->arrayConstructor(); 604 JSObject* res = static_cast<JSObject*>(constructor->construct(exec, exec->emptyList())); 641 JSObject* res = constructEmptyArray(exec); 605 642 JSValue* result = res; 606 643 UString u = s; … … 663 700 } 664 701 665 JSValue* stringProtoFuncSubstr(ExecState* exec, JSObject* thisObj, const ArgList& args)666 { 667 // This optimizes the common case that thisObj is a StringObject 668 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);702 JSValue* stringProtoFuncSubstr(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 703 { 704 // This optimizes the common case that thisObj is a StringObject 705 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 669 706 int len = s.size(); 670 707 … … 688 725 } 689 726 690 JSValue* stringProtoFuncSubstring(ExecState* exec, JSObject* thisObj, const ArgList& args)691 { 692 // This optimizes the common case that thisObj is a StringObject 693 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);727 JSValue* stringProtoFuncSubstring(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 728 { 729 // This optimizes the common case that thisObj is a StringObject 730 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 694 731 int len = s.size(); 695 732 … … 721 758 } 722 759 723 JSValue* stringProtoFuncToLowerCase(ExecState* exec, JSObject* thisObj, const ArgList&)724 { 725 // This optimizes the common case that thisObj is a StringObject 726 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);760 JSValue* stringProtoFuncToLowerCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 761 { 762 // This optimizes the common case that thisObj is a StringObject 763 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 727 764 728 JSString* sVal = this Obj->inherits(&StringObject::info)729 ? static_cast<StringObject*>(this Obj)->internalValue()765 JSString* sVal = thisValue->isObject(&StringObject::info) 766 ? static_cast<StringObject*>(thisValue)->internalValue() 730 767 : static_cast<JSString*>(jsString(exec, s)); 731 768 int ssize = s.size(); … … 746 783 } 747 784 748 JSValue* stringProtoFuncToUpperCase(ExecState* exec, JSObject* thisObj, const ArgList&)749 { 750 // This optimizes the common case that thisObj is a StringObject 751 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);752 753 JSString* sVal = this Obj->inherits(&StringObject::info)754 ? static_cast<StringObject*>(this Obj)->internalValue()785 JSValue* stringProtoFuncToUpperCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 786 { 787 // This optimizes the common case that thisObj is a StringObject 788 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 789 790 JSString* sVal = thisValue->isObject(&StringObject::info) 791 ? static_cast<StringObject*>(thisValue)->internalValue() 755 792 : static_cast<JSString*>(jsString(exec, s)); 756 793 int ssize = s.size(); … … 771 808 } 772 809 773 JSValue* stringProtoFuncToLocaleLowerCase(ExecState* exec, JSObject* thisObj, const ArgList&)774 { 775 // This optimizes the common case that thisObj is a StringObject 776 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);810 JSValue* stringProtoFuncToLocaleLowerCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 811 { 812 // This optimizes the common case that thisObj is a StringObject 813 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 777 814 778 815 // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented. 779 JSString* sVal = this Obj->inherits(&StringObject::info)780 ? static_cast<StringObject*>(this Obj)->internalValue()816 JSString* sVal = thisValue->isObject(&StringObject::info) 817 ? static_cast<StringObject*>(thisValue)->internalValue() 781 818 : static_cast<JSString*>(jsString(exec, s)); 782 819 int ssize = s.size(); … … 797 834 } 798 835 799 JSValue* stringProtoFuncToLocaleUpperCase(ExecState* exec, JSObject* thisObj, const ArgList&)800 { 801 // This optimizes the common case that thisObj is a StringObject 802 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);803 804 JSString* sVal = this Obj->inherits(&StringObject::info)805 ? static_cast<StringObject*>(this Obj)->internalValue()836 JSValue* stringProtoFuncToLocaleUpperCase(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 837 { 838 // This optimizes the common case that thisObj is a StringObject 839 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 840 841 JSString* sVal = thisValue->isObject(&StringObject::info) 842 ? static_cast<StringObject*>(thisValue)->internalValue() 806 843 : static_cast<JSString*>(jsString(exec, s)); 807 844 int ssize = s.size(); … … 822 859 } 823 860 824 JSValue* stringProtoFuncLocaleCompare(ExecState* exec, JSObject* thisObj, const ArgList& args)861 JSValue* stringProtoFuncLocaleCompare(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 825 862 { 826 863 if (args.size() < 1) … … 828 865 829 866 // This optimizes the common case that thisObj is a StringObject 830 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);867 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 831 868 JSValue* a0 = args[0]; 832 869 return jsNumber(exec, localeCompare(s, a0->toString(exec))); 833 870 } 834 871 835 JSValue* stringProtoFuncBig(ExecState* exec, JSObject* thisObj, const ArgList&)836 { 837 // This optimizes the common case that thisObj is a StringObject 838 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);872 JSValue* stringProtoFuncBig(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 873 { 874 // This optimizes the common case that thisObj is a StringObject 875 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 839 876 return jsString(exec, "<big>" + s + "</big>"); 840 877 } 841 878 842 JSValue* stringProtoFuncSmall(ExecState* exec, JSObject* thisObj, const ArgList&)843 { 844 // This optimizes the common case that thisObj is a StringObject 845 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);879 JSValue* stringProtoFuncSmall(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 880 { 881 // This optimizes the common case that thisObj is a StringObject 882 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 846 883 return jsString(exec, "<small>" + s + "</small>"); 847 884 } 848 885 849 JSValue* stringProtoFuncBlink(ExecState* exec, JSObject* thisObj, const ArgList&)850 { 851 // This optimizes the common case that thisObj is a StringObject 852 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);886 JSValue* stringProtoFuncBlink(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 887 { 888 // This optimizes the common case that thisObj is a StringObject 889 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 853 890 return jsString(exec, "<blink>" + s + "</blink>"); 854 891 } 855 892 856 JSValue* stringProtoFuncBold(ExecState* exec, JSObject* thisObj, const ArgList&)857 { 858 // This optimizes the common case that thisObj is a StringObject 859 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);893 JSValue* stringProtoFuncBold(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 894 { 895 // This optimizes the common case that thisObj is a StringObject 896 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 860 897 return jsString(exec, "<b>" + s + "</b>"); 861 898 } 862 899 863 JSValue* stringProtoFuncFixed(ExecState* exec, JSObject* thisObj, const ArgList&)864 { 865 // This optimizes the common case that thisObj is a StringObject 866 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);900 JSValue* stringProtoFuncFixed(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 901 { 902 // This optimizes the common case that thisObj is a StringObject 903 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 867 904 return jsString(exec, "<tt>" + s + "</tt>"); 868 905 } 869 906 870 JSValue* stringProtoFuncItalics(ExecState* exec, JSObject* thisObj, const ArgList&)871 { 872 // This optimizes the common case that thisObj is a StringObject 873 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);907 JSValue* stringProtoFuncItalics(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 908 { 909 // This optimizes the common case that thisObj is a StringObject 910 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 874 911 return jsString(exec, "<i>" + s + "</i>"); 875 912 } 876 913 877 JSValue* stringProtoFuncStrike(ExecState* exec, JSObject* thisObj, const ArgList&)878 { 879 // This optimizes the common case that thisObj is a StringObject 880 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);914 JSValue* stringProtoFuncStrike(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 915 { 916 // This optimizes the common case that thisObj is a StringObject 917 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 881 918 return jsString(exec, "<strike>" + s + "</strike>"); 882 919 } 883 920 884 JSValue* stringProtoFuncSub(ExecState* exec, JSObject* thisObj, const ArgList&)885 { 886 // This optimizes the common case that thisObj is a StringObject 887 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);921 JSValue* stringProtoFuncSub(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 922 { 923 // This optimizes the common case that thisObj is a StringObject 924 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 888 925 return jsString(exec, "<sub>" + s + "</sub>"); 889 926 } 890 927 891 JSValue* stringProtoFuncSup(ExecState* exec, JSObject* thisObj, const ArgList&)892 { 893 // This optimizes the common case that thisObj is a StringObject 894 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);928 JSValue* stringProtoFuncSup(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&) 929 { 930 // This optimizes the common case that thisObj is a StringObject 931 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 895 932 return jsString(exec, "<sup>" + s + "</sup>"); 896 933 } 897 934 898 JSValue* stringProtoFuncFontcolor(ExecState* exec, JSObject* thisObj, const ArgList& args)899 { 900 // This optimizes the common case that thisObj is a StringObject 901 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);935 JSValue* stringProtoFuncFontcolor(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 936 { 937 // This optimizes the common case that thisObj is a StringObject 938 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 902 939 JSValue* a0 = args[0]; 903 940 return jsString(exec, "<font color=\"" + a0->toString(exec) + "\">" + s + "</font>"); 904 941 } 905 942 906 JSValue* stringProtoFuncFontsize(ExecState* exec, JSObject* thisObj, const ArgList& args)907 { 908 // This optimizes the common case that thisObj is a StringObject 909 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);943 JSValue* stringProtoFuncFontsize(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 944 { 945 // This optimizes the common case that thisObj is a StringObject 946 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 910 947 JSValue* a0 = args[0]; 911 948 return jsString(exec, "<font size=\"" + a0->toString(exec) + "\">" + s + "</font>"); 912 949 } 913 950 914 JSValue* stringProtoFuncAnchor(ExecState* exec, JSObject* thisObj, const ArgList& args)915 { 916 // This optimizes the common case that thisObj is a StringObject 917 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);951 JSValue* stringProtoFuncAnchor(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 952 { 953 // This optimizes the common case that thisObj is a StringObject 954 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 918 955 JSValue* a0 = args[0]; 919 956 return jsString(exec, "<a name=\"" + a0->toString(exec) + "\">" + s + "</a>"); 920 957 } 921 958 922 JSValue* stringProtoFuncLink(ExecState* exec, JSObject* thisObj, const ArgList& args)923 { 924 // This optimizes the common case that thisObj is a StringObject 925 UString s = this Obj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec);959 JSValue* stringProtoFuncLink(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) 960 { 961 // This optimizes the common case that thisObj is a StringObject 962 UString s = thisValue->isObject(&StringObject::info) ? static_cast<StringObject*>(thisValue)->internalValue()->value() : thisValue->toThisObject(exec)->toString(exec); 926 963 JSValue* a0 = args[0]; 927 964 return jsString(exec, "<a href=\"" + a0->toString(exec) + "\">" + s + "</a>"); … … 929 966 930 967 // ------------------------------ StringConstructor ------------------------------ 968 969 static JSValue* stringFromCharCode(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 970 { 971 UString s; 972 if (args.size()) { 973 UChar* buf = static_cast<UChar*>(fastMalloc(args.size() * sizeof(UChar))); 974 UChar* p = buf; 975 ArgList::const_iterator end = args.end(); 976 for (ArgList::const_iterator it = args.begin(); it != end; ++it) 977 *p++ = static_cast<UChar>((*it)->toUInt32(exec)); 978 s = UString(buf, args.size(), false); 979 } else 980 s = ""; 981 982 return jsString(exec, s); 983 } 931 984 932 985 StringConstructor::StringConstructor(ExecState* exec, FunctionPrototype* funcProto, StringPrototype* stringProto) … … 934 987 { 935 988 // ECMA 15.5.3.1 String.prototype 936 putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly); 937 938 putDirectFunction(new (exec) StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum); 989 putDirect(exec->propertyNames().prototype, stringProto, ReadOnly | DontEnum | DontDelete); 990 991 // ECMA 15.5.3.2 fromCharCode() 992 putDirectFunction(new (exec) PrototypeFunction(exec, funcProto, 1, exec->propertyNames().fromCharCode, stringFromCharCode), DontEnum); 939 993 940 994 // no. of arguments for constructor 941 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum); 942 } 943 944 945 ConstructType StringConstructor::getConstructData(ConstructData&) 946 { 995 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); 996 } 997 998 // ECMA 15.5.2 999 static JSObject* constructWithStringConstructor(ExecState* exec, JSObject*, const ArgList& args) 1000 { 1001 JSObject* prototype = exec->lexicalGlobalObject()->stringPrototype(); 1002 if (args.isEmpty()) 1003 return new (exec) StringObject(exec, prototype); 1004 return new (exec) StringObject(exec, prototype, args[0]->toString(exec)); 1005 } 1006 1007 ConstructType StringConstructor::getConstructData(ConstructData& constructData) 1008 { 1009 constructData.native.function = constructWithStringConstructor; 947 1010 return ConstructTypeNative; 948 1011 } 949 1012 950 // ECMA 15.5.2951 JSObject* StringConstructor::construct(ExecState* exec, const ArgList& args)952 {953 JSObject* proto = exec->lexicalGlobalObject()->stringPrototype();954 if (!args.size())955 return new (exec) StringObject(exec, proto);956 return new (exec) StringObject(exec, proto, args[0]->toString(exec));957 }958 959 1013 // ECMA 15.5.1 960 JSValue *StringConstructor::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const ArgList &args) 961 { 962 if (args.isEmpty()) 963 return jsString(exec, ""); 964 else { 965 JSValue *v = args[0]; 966 return jsString(exec, v->toString(exec)); 967 } 968 } 969 970 // ------------------------------ StringConstructorFunction -------------------------- 971 972 // ECMA 15.5.3.2 fromCharCode() 973 StringConstructorFunction::StringConstructorFunction(ExecState* exec, FunctionPrototype* funcProto, const Identifier& name) 974 : InternalFunction(funcProto, name) 975 { 976 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete|ReadOnly|DontEnum); 977 } 978 979 JSValue *StringConstructorFunction::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const ArgList &args) 980 { 981 UString s; 982 if (args.size()) { 983 UChar *buf = static_cast<UChar *>(fastMalloc(args.size() * sizeof(UChar))); 984 UChar *p = buf; 985 ArgList::const_iterator end = args.end(); 986 for (ArgList::const_iterator it = args.begin(); it != end; ++it) { 987 unsigned short u = static_cast<unsigned short>((*it)->toUInt32(exec)); 988 *p++ = UChar(u); 989 } 990 s = UString(buf, args.size(), false); 991 } else 992 s = ""; 993 994 return jsString(exec, s); 1014 static JSValue* callStringConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args) 1015 { 1016 if (args.isEmpty()) 1017 return jsString(exec, ""); 1018 return jsString(exec, args[0]->toString(exec)); 1019 } 1020 1021 CallType StringConstructor::getCallData(CallData& callData) 1022 { 1023 callData.native.function = callStringConstructor; 1024 return CallTypeNative; 995 1025 } 996 1026
Note:
See TracChangeset
for help on using the changeset viewer.