Changeset 33038 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- May 12, 2008, 12:12:31 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r32807 r33038 41 41 const ClassInfo StringInstance::info = { "String", 0, 0, 0 }; 42 42 43 StringInstance::StringInstance( ExecState* exec, JSObject*proto)43 StringInstance::StringInstance(JSObject *proto) 44 44 : JSWrapperObject(proto) 45 45 { 46 setInternalValue(jsString( exec,""));46 setInternalValue(jsString("")); 47 47 } 48 48 … … 53 53 } 54 54 55 StringInstance::StringInstance( ExecState* exec, JSObject*proto, const UString &string)55 StringInstance::StringInstance(JSObject *proto, const UString &string) 56 56 : JSWrapperObject(proto) 57 57 { 58 setInternalValue(jsString( exec,string));59 } 60 61 JSValue * StringInstance::lengthGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot&slot)62 { 63 return jsNumber( exec,static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().size());64 } 65 66 JSValue* StringInstance::indexGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot& slot)67 { 68 return jsString( exec,static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().substr(slot.index(), 1));69 } 70 71 static JSValue* stringInstanceNumericPropertyGetter(ExecState* exec, JSObject*, unsigned index, const PropertySlot& slot)72 { 73 return jsString( exec,static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().substr(index, 1));58 setInternalValue(jsString(string)); 59 } 60 61 JSValue *StringInstance::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot) 62 { 63 return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().size()); 64 } 65 66 JSValue* StringInstance::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot) 67 { 68 return jsString(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().substr(slot.index(), 1)); 69 } 70 71 static JSValue* stringInstanceNumericPropertyGetter(ExecState*, JSObject*, unsigned index, const PropertySlot& slot) 72 { 73 return jsString(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().substr(index, 1)); 74 74 } 75 75 … … 166 166 // ECMA 15.5.4 167 167 StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto) 168 : StringInstance( exec,objProto)168 : StringInstance(objProto) 169 169 { 170 170 // The constructor will be added later, after StringObjectImp has been built 171 putDirect(exec->propertyNames().length, jsNumber( exec,0), DontDelete | ReadOnly | DontEnum);171 putDirect(exec->propertyNames().length, jsNumber(0), DontDelete | ReadOnly | DontEnum); 172 172 } 173 173 … … 345 345 args.append(jsUndefined()); 346 346 else 347 args.append(jsString( exec,source.substr(matchStart, matchLen)));347 args.append(jsString(source.substr(matchStart, matchLen))); 348 348 } 349 349 350 args.append(jsNumber( exec,completeMatchStart));350 args.append(jsNumber(completeMatchStart)); 351 351 args.append(sourceVal); 352 352 … … 382 382 return sourceVal; 383 383 384 return jsString( exec,result);384 return jsString(result); 385 385 } 386 386 … … 396 396 List args; 397 397 398 args.append(jsString( exec,source.substr(matchPos, matchLen)));399 args.append(jsNumber( exec,matchPos));398 args.append(jsString(source.substr(matchPos, matchLen))); 399 args.append(jsNumber(matchPos)); 400 400 args.append(sourceVal); 401 401 … … 403 403 } 404 404 405 return jsString( exec,source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));405 return jsString(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen)); 406 406 } 407 407 … … 435 435 else 436 436 u = ""; 437 return jsString( exec,u);437 return jsString(u); 438 438 } 439 439 … … 449 449 double dpos = a0->toInteger(exec); 450 450 if (dpos >= 0 && dpos < len) 451 result = jsNumber( exec,s[static_cast<int>(dpos)]);451 result = jsNumber(s[static_cast<int>(dpos)]); 452 452 else 453 result = jsNaN( exec);453 result = jsNaN(); 454 454 return result; 455 455 } … … 464 464 s += (*it)->toString(exec); 465 465 } 466 return jsString( exec,s);466 return jsString(s); 467 467 } 468 468 … … 481 481 else if (dpos > len) 482 482 dpos = len; 483 return jsNumber( exec,s.find(u2, static_cast<int>(dpos)));483 return jsNumber(s.find(u2, static_cast<int>(dpos))); 484 484 } 485 485 … … 499 499 else if (!(dpos <= len)) // true for NaN 500 500 dpos = len; 501 return jsNumber( exec,s.rfind(u2, static_cast<int>(dpos)));501 return jsNumber(s.rfind(u2, static_cast<int>(dpos))); 502 502 } 503 503 … … 538 538 int lastIndex = 0; 539 539 while (pos >= 0) { 540 list.append(jsString( exec,u.substr(pos, matchLength)));540 list.append(jsString(u.substr(pos, matchLength))); 541 541 lastIndex = pos; 542 542 pos += matchLength == 0 ? 1 : matchLength; … … 580 580 int matchLength; 581 581 regExpObj->performMatch(reg.get(), u, 0, pos, matchLength); 582 return jsNumber( exec,pos);582 return jsNumber(pos); 583 583 } 584 584 … … 590 590 StringImp* sVal = thisObj->inherits(&StringInstance::info) ? 591 591 static_cast<StringInstance*>(thisObj)->internalValue() : 592 static_cast<StringImp*>(jsString( exec,s));592 static_cast<StringImp*>(jsString(s)); 593 593 594 594 JSValue* a0 = args[0]; … … 617 617 if (to > len) 618 618 to = len; 619 return jsString( exec,s.substr(static_cast<int>(from), static_cast<int>(to - from)));620 } 621 622 return jsString( exec,"");619 return jsString(s.substr(static_cast<int>(from), static_cast<int>(to - from))); 620 } 621 622 return jsString(""); 623 623 } 624 624 … … 643 643 if (u.isEmpty() && reg->match(u, 0) >= 0) { 644 644 // empty string matched by regexp -> empty array 645 res->put(exec, exec->propertyNames().length, jsNumber( exec,0));645 res->put(exec, exec->propertyNames().length, jsNumber(0)); 646 646 return result; 647 647 } … … 655 655 pos = mpos + (mlen == 0 ? 1 : mlen); 656 656 if (mpos != p0 || mlen) { 657 res->put(exec,i, jsString( exec,u.substr(p0, mpos-p0)));657 res->put(exec,i, jsString(u.substr(p0, mpos-p0))); 658 658 p0 = mpos + mlen; 659 659 i++; … … 664 664 res->put(exec, i++, jsUndefined()); 665 665 else 666 res->put(exec, i++, jsString( exec,u.substr(spos, ovector[si * 2 + 1] - spos)));666 res->put(exec, i++, jsString(u.substr(spos, ovector[si * 2 + 1] - spos))); 667 667 } 668 668 } … … 672 672 if (u.isEmpty()) { 673 673 // empty separator matches empty string -> empty array 674 res->put(exec, exec->propertyNames().length, jsNumber( exec,0));674 res->put(exec, exec->propertyNames().length, jsNumber(0)); 675 675 return result; 676 676 } else { 677 677 while (static_cast<uint32_t>(i) != limit && i < u.size()-1) 678 res->put(exec, i++, jsString( exec,u.substr(p0++, 1)));678 res->put(exec, i++, jsString(u.substr(p0++, 1))); 679 679 } 680 680 } else { 681 681 while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) { 682 res->put(exec, i, jsString( exec, u.substr(p0, pos -p0)));682 res->put(exec, i, jsString(u.substr(p0, pos-p0))); 683 683 p0 = pos + u2.size(); 684 684 i++; … … 688 688 // add remaining string, if any 689 689 if (static_cast<uint32_t>(i) != limit) 690 res->put(exec, i++, jsString( exec,u.substr(p0)));691 res->put(exec, exec->propertyNames().length, jsNumber( exec,i));690 res->put(exec, i++, jsString(u.substr(p0))); 691 res->put(exec, exec->propertyNames().length, jsNumber(i)); 692 692 return result; 693 693 } … … 705 705 double length = a1->isUndefined() ? len : a1->toInteger(exec); 706 706 if (start >= len) 707 return jsString( exec,"");707 return jsString(""); 708 708 if (length < 0) 709 return jsString( exec,"");709 return jsString(""); 710 710 if (start < 0) { 711 711 start += len; … … 715 715 if (length > len) 716 716 length = len; 717 return jsString( exec,s.substr(static_cast<int>(start), static_cast<int>(length)));717 return jsString(s.substr(static_cast<int>(start), static_cast<int>(length))); 718 718 } 719 719 … … 748 748 start = temp; 749 749 } 750 return jsString( exec,s.substr((int)start, (int)end-(int)start));750 return jsString(s.substr((int)start, (int)end-(int)start)); 751 751 } 752 752 … … 758 758 StringImp* sVal = thisObj->inherits(&StringInstance::info) 759 759 ? static_cast<StringInstance*>(thisObj)->internalValue() 760 : static_cast<StringImp*>(jsString( exec,s));760 : static_cast<StringImp*>(jsString(s)); 761 761 int ssize = s.size(); 762 762 if (!ssize) … … 773 773 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 774 774 return sVal; 775 return jsString( exec,UString(buffer.releaseBuffer(), length, false));775 return jsString(UString(buffer.releaseBuffer(), length, false)); 776 776 } 777 777 … … 783 783 StringImp* sVal = thisObj->inherits(&StringInstance::info) 784 784 ? static_cast<StringInstance*>(thisObj)->internalValue() 785 : static_cast<StringImp*>(jsString( exec,s));785 : static_cast<StringImp*>(jsString(s)); 786 786 int ssize = s.size(); 787 787 if (!ssize) … … 798 798 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 799 799 return sVal; 800 return jsString( exec,UString(buffer.releaseBuffer(), length, false));800 return jsString(UString(buffer.releaseBuffer(), length, false)); 801 801 } 802 802 … … 809 809 StringImp* sVal = thisObj->inherits(&StringInstance::info) 810 810 ? static_cast<StringInstance*>(thisObj)->internalValue() 811 : static_cast<StringImp*>(jsString( exec,s));811 : static_cast<StringImp*>(jsString(s)); 812 812 int ssize = s.size(); 813 813 if (!ssize) … … 824 824 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 825 825 return sVal; 826 return jsString( exec,UString(buffer.releaseBuffer(), length, false));826 return jsString(UString(buffer.releaseBuffer(), length, false)); 827 827 } 828 828 … … 834 834 StringImp* sVal = thisObj->inherits(&StringInstance::info) 835 835 ? static_cast<StringInstance*>(thisObj)->internalValue() 836 : static_cast<StringImp*>(jsString( exec,s));836 : static_cast<StringImp*>(jsString(s)); 837 837 int ssize = s.size(); 838 838 if (!ssize) … … 849 849 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 850 850 return sVal; 851 return jsString( exec,UString(buffer.releaseBuffer(), length, false));851 return jsString(UString(buffer.releaseBuffer(), length, false)); 852 852 } 853 853 … … 855 855 { 856 856 if (args.size() < 1) 857 return jsNumber( exec,0);858 859 // This optimizes the common case that thisObj is a StringInstance 860 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 861 JSValue* a0 = args[0]; 862 return jsNumber( exec,localeCompare(s, a0->toString(exec)));857 return jsNumber(0); 858 859 // This optimizes the common case that thisObj is a StringInstance 860 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 861 JSValue* a0 = args[0]; 862 return jsNumber(localeCompare(s, a0->toString(exec))); 863 863 } 864 864 … … 867 867 // This optimizes the common case that thisObj is a StringInstance 868 868 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 869 return jsString( exec,"<big>" + s + "</big>");869 return jsString("<big>" + s + "</big>"); 870 870 } 871 871 … … 874 874 // This optimizes the common case that thisObj is a StringInstance 875 875 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 876 return jsString( exec,"<small>" + s + "</small>");876 return jsString("<small>" + s + "</small>"); 877 877 } 878 878 … … 881 881 // This optimizes the common case that thisObj is a StringInstance 882 882 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 883 return jsString( exec,"<blink>" + s + "</blink>");883 return jsString("<blink>" + s + "</blink>"); 884 884 } 885 885 … … 888 888 // This optimizes the common case that thisObj is a StringInstance 889 889 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 890 return jsString( exec,"<b>" + s + "</b>");890 return jsString("<b>" + s + "</b>"); 891 891 } 892 892 … … 895 895 // This optimizes the common case that thisObj is a StringInstance 896 896 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 897 return jsString( exec,"<tt>" + s + "</tt>");897 return jsString("<tt>" + s + "</tt>"); 898 898 } 899 899 … … 902 902 // This optimizes the common case that thisObj is a StringInstance 903 903 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 904 return jsString( exec,"<i>" + s + "</i>");904 return jsString("<i>" + s + "</i>"); 905 905 } 906 906 … … 909 909 // This optimizes the common case that thisObj is a StringInstance 910 910 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 911 return jsString( exec,"<strike>" + s + "</strike>");911 return jsString("<strike>" + s + "</strike>"); 912 912 } 913 913 … … 916 916 // This optimizes the common case that thisObj is a StringInstance 917 917 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 918 return jsString( exec,"<sub>" + s + "</sub>");918 return jsString("<sub>" + s + "</sub>"); 919 919 } 920 920 … … 923 923 // This optimizes the common case that thisObj is a StringInstance 924 924 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 925 return jsString( exec,"<sup>" + s + "</sup>");925 return jsString("<sup>" + s + "</sup>"); 926 926 } 927 927 … … 931 931 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 932 932 JSValue* a0 = args[0]; 933 return jsString( exec,"<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");933 return jsString("<font color=\"" + a0->toString(exec) + "\">" + s + "</font>"); 934 934 } 935 935 … … 939 939 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 940 940 JSValue* a0 = args[0]; 941 return jsString( exec,"<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");941 return jsString("<font size=\"" + a0->toString(exec) + "\">" + s + "</font>"); 942 942 } 943 943 … … 947 947 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 948 948 JSValue* a0 = args[0]; 949 return jsString( exec,"<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");949 return jsString("<a name=\"" + a0->toString(exec) + "\">" + s + "</a>"); 950 950 } 951 951 … … 955 955 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 956 956 JSValue* a0 = args[0]; 957 return jsString( exec,"<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");957 return jsString("<a href=\"" + a0->toString(exec) + "\">" + s + "</a>"); 958 958 } 959 959 … … 966 966 putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly); 967 967 968 putDirectFunction(new (exec)StringObjectFuncImp(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);968 putDirectFunction(new StringObjectFuncImp(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum); 969 969 970 970 // no. of arguments for constructor 971 putDirect(exec->propertyNames().length, jsNumber( exec,1), ReadOnly|DontDelete|DontEnum);971 putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum); 972 972 } 973 973 … … 983 983 JSObject *proto = exec->lexicalGlobalObject()->stringPrototype(); 984 984 if (args.size() == 0) 985 return new (exec) StringInstance(exec,proto);986 return new (exec) StringInstance(exec,proto, args[0]->toString(exec));985 return new StringInstance(proto); 986 return new StringInstance(proto, args[0]->toString(exec)); 987 987 } 988 988 … … 991 991 { 992 992 if (args.isEmpty()) 993 return jsString( exec,"");993 return jsString(""); 994 994 else { 995 995 JSValue *v = args[0]; 996 return jsString( exec,v->toString(exec));996 return jsString(v->toString(exec)); 997 997 } 998 998 } … … 1004 1004 : InternalFunctionImp(funcProto, name) 1005 1005 { 1006 putDirect(exec->propertyNames().length, jsNumber( exec,1), DontDelete|ReadOnly|DontEnum);1006 putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum); 1007 1007 } 1008 1008 … … 1022 1022 s = ""; 1023 1023 1024 return jsString( exec,s);1024 return jsString(s); 1025 1025 } 1026 1026
Note:
See TracChangeset
for help on using the changeset viewer.