Changeset 34659 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Jun 19, 2008, 10:29:29 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r34607 r34659 41 41 const ClassInfo StringObject::info = { "String", 0, 0, 0 }; 42 42 43 StringObject::StringObject( JSObject *proto)43 StringObject::StringObject(ExecState* exec, JSObject* proto) 44 44 : JSWrapperObject(proto) 45 45 { 46 setInternalValue(jsString( ""));47 } 48 49 StringObject::StringObject(JSObject *proto, JSString* string)46 setInternalValue(jsString(exec, "")); 47 } 48 49 StringObject::StringObject(JSObject* proto, JSString* string) 50 50 : JSWrapperObject(proto) 51 51 { … … 53 53 } 54 54 55 StringObject::StringObject( JSObject *proto, const UString &string)55 StringObject::StringObject(ExecState* exec, JSObject* proto, const UString& string) 56 56 : JSWrapperObject(proto) 57 57 { 58 setInternalValue(jsString( string));58 setInternalValue(jsString(exec, string)); 59 59 } 60 60 … … 136 136 // ECMA 15.5.4 137 137 StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto) 138 : StringObject( objProto)138 : StringObject(exec, objProto) 139 139 { 140 140 // The constructor will be added later, after StringConstructor has been built 141 putDirect(exec->propertyNames().length, jsNumber( 0), DontDelete | ReadOnly | DontEnum);141 putDirect(exec->propertyNames().length, jsNumber(exec, 0), DontDelete | ReadOnly | DontEnum); 142 142 } 143 143 … … 315 315 args.append(jsUndefined()); 316 316 else 317 args.append(jsString( source.substr(matchStart, matchLen)));317 args.append(jsString(exec, source.substr(matchStart, matchLen))); 318 318 } 319 319 320 args.append(jsNumber( completeMatchStart));320 args.append(jsNumber(exec, completeMatchStart)); 321 321 args.append(sourceVal); 322 322 … … 352 352 return sourceVal; 353 353 354 return jsString( result);354 return jsString(exec, result); 355 355 } 356 356 … … 366 366 ArgList args; 367 367 368 args.append(jsString( source.substr(matchPos, matchLen)));369 args.append(jsNumber( matchPos));368 args.append(jsString(exec, source.substr(matchPos, matchLen))); 369 args.append(jsNumber(exec, matchPos)); 370 370 args.append(sourceVal); 371 371 … … 373 373 } 374 374 375 return jsString( source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));375 return jsString(exec, source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen)); 376 376 } 377 377 … … 405 405 else 406 406 u = ""; 407 return jsString( u);407 return jsString(exec, u); 408 408 } 409 409 … … 419 419 double dpos = a0->toInteger(exec); 420 420 if (dpos >= 0 && dpos < len) 421 result = jsNumber( s[static_cast<int>(dpos)]);421 result = jsNumber(exec, s[static_cast<int>(dpos)]); 422 422 else 423 result = jsNaN( );423 result = jsNaN(exec); 424 424 return result; 425 425 } … … 434 434 s += (*it)->toString(exec); 435 435 } 436 return jsString( s);436 return jsString(exec, s); 437 437 } 438 438 … … 451 451 else if (dpos > len) 452 452 dpos = len; 453 return jsNumber( s.find(u2, static_cast<int>(dpos)));453 return jsNumber(exec, s.find(u2, static_cast<int>(dpos))); 454 454 } 455 455 … … 469 469 else if (!(dpos <= len)) // true for NaN 470 470 dpos = len; 471 return jsNumber( s.rfind(u2, static_cast<int>(dpos)));471 return jsNumber(exec, s.rfind(u2, static_cast<int>(dpos))); 472 472 } 473 473 … … 508 508 int lastIndex = 0; 509 509 while (pos >= 0) { 510 list.append(jsString( u.substr(pos, matchLength)));510 list.append(jsString(exec, u.substr(pos, matchLength))); 511 511 lastIndex = pos; 512 512 pos += matchLength == 0 ? 1 : matchLength; … … 550 550 int matchLength; 551 551 regExpObj->performMatch(reg.get(), u, 0, pos, matchLength); 552 return jsNumber( pos);552 return jsNumber(exec, pos); 553 553 } 554 554 … … 560 560 JSString* sVal = thisObj->inherits(&StringObject::info) ? 561 561 static_cast<StringObject*>(thisObj)->internalValue() : 562 static_cast<JSString*>(jsString( s));562 static_cast<JSString*>(jsString(exec, s)); 563 563 564 564 JSValue* a0 = args[0]; … … 587 587 if (to > len) 588 588 to = len; 589 return jsString( s.substr(static_cast<int>(from), static_cast<int>(to - from)));590 } 591 592 return jsString( "");589 return jsString(exec, s.substr(static_cast<int>(from), static_cast<int>(to - from))); 590 } 591 592 return jsString(exec, ""); 593 593 } 594 594 … … 613 613 if (u.isEmpty() && reg->match(u, 0) >= 0) { 614 614 // empty string matched by regexp -> empty array 615 res->put(exec, exec->propertyNames().length, jsNumber( 0));615 res->put(exec, exec->propertyNames().length, jsNumber(exec, 0)); 616 616 return result; 617 617 } … … 625 625 pos = mpos + (mlen == 0 ? 1 : mlen); 626 626 if (mpos != p0 || mlen) { 627 res->put(exec,i, jsString( u.substr(p0, mpos-p0)));627 res->put(exec,i, jsString(exec, u.substr(p0, mpos-p0))); 628 628 p0 = mpos + mlen; 629 629 i++; … … 634 634 res->put(exec, i++, jsUndefined()); 635 635 else 636 res->put(exec, i++, jsString( u.substr(spos, ovector[si * 2 + 1] - spos)));636 res->put(exec, i++, jsString(exec, u.substr(spos, ovector[si * 2 + 1] - spos))); 637 637 } 638 638 } … … 642 642 if (u.isEmpty()) { 643 643 // empty separator matches empty string -> empty array 644 res->put(exec, exec->propertyNames().length, jsNumber( 0));644 res->put(exec, exec->propertyNames().length, jsNumber(exec, 0)); 645 645 return result; 646 646 } else { 647 647 while (static_cast<uint32_t>(i) != limit && i < u.size()-1) 648 res->put(exec, i++, jsString( u.substr(p0++, 1)));648 res->put(exec, i++, jsString(exec, u.substr(p0++, 1))); 649 649 } 650 650 } else { 651 651 while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) { 652 res->put(exec, i, jsString( u.substr(p0, pos-p0)));652 res->put(exec, i, jsString(exec, u.substr(p0, pos - p0))); 653 653 p0 = pos + u2.size(); 654 654 i++; … … 658 658 // add remaining string, if any 659 659 if (static_cast<uint32_t>(i) != limit) 660 res->put(exec, i++, jsString( u.substr(p0)));661 res->put(exec, exec->propertyNames().length, jsNumber( i));660 res->put(exec, i++, jsString(exec, u.substr(p0))); 661 res->put(exec, exec->propertyNames().length, jsNumber(exec, i)); 662 662 return result; 663 663 } … … 675 675 double length = a1->isUndefined() ? len : a1->toInteger(exec); 676 676 if (start >= len) 677 return jsString( "");677 return jsString(exec, ""); 678 678 if (length < 0) 679 return jsString( "");679 return jsString(exec, ""); 680 680 if (start < 0) { 681 681 start += len; … … 685 685 if (length > len) 686 686 length = len; 687 return jsString( s.substr(static_cast<int>(start), static_cast<int>(length)));687 return jsString(exec, s.substr(static_cast<int>(start), static_cast<int>(length))); 688 688 } 689 689 … … 718 718 start = temp; 719 719 } 720 return jsString( s.substr((int)start, (int)end-(int)start));720 return jsString(exec, s.substr((int)start, (int)end-(int)start)); 721 721 } 722 722 … … 728 728 JSString* sVal = thisObj->inherits(&StringObject::info) 729 729 ? static_cast<StringObject*>(thisObj)->internalValue() 730 : static_cast<JSString*>(jsString( s));730 : static_cast<JSString*>(jsString(exec, s)); 731 731 int ssize = s.size(); 732 732 if (!ssize) … … 743 743 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 744 744 return sVal; 745 return jsString( UString(buffer.releaseBuffer(), length, false));745 return jsString(exec, UString(buffer.releaseBuffer(), length, false)); 746 746 } 747 747 … … 753 753 JSString* sVal = thisObj->inherits(&StringObject::info) 754 754 ? static_cast<StringObject*>(thisObj)->internalValue() 755 : static_cast<JSString*>(jsString( s));755 : static_cast<JSString*>(jsString(exec, s)); 756 756 int ssize = s.size(); 757 757 if (!ssize) … … 768 768 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 769 769 return sVal; 770 return jsString( UString(buffer.releaseBuffer(), length, false));770 return jsString(exec, UString(buffer.releaseBuffer(), length, false)); 771 771 } 772 772 … … 779 779 JSString* sVal = thisObj->inherits(&StringObject::info) 780 780 ? static_cast<StringObject*>(thisObj)->internalValue() 781 : static_cast<JSString*>(jsString( s));781 : static_cast<JSString*>(jsString(exec, s)); 782 782 int ssize = s.size(); 783 783 if (!ssize) … … 794 794 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 795 795 return sVal; 796 return jsString( UString(buffer.releaseBuffer(), length, false));796 return jsString(exec, UString(buffer.releaseBuffer(), length, false)); 797 797 } 798 798 … … 804 804 JSString* sVal = thisObj->inherits(&StringObject::info) 805 805 ? static_cast<StringObject*>(thisObj)->internalValue() 806 : static_cast<JSString*>(jsString( s));806 : static_cast<JSString*>(jsString(exec, s)); 807 807 int ssize = s.size(); 808 808 if (!ssize) … … 819 819 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0) 820 820 return sVal; 821 return jsString( UString(buffer.releaseBuffer(), length, false));821 return jsString(exec, UString(buffer.releaseBuffer(), length, false)); 822 822 } 823 823 … … 825 825 { 826 826 if (args.size() < 1) 827 return jsNumber( 0);828 829 // This optimizes the common case that thisObj is a StringObject 830 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 831 JSValue* a0 = args[0]; 832 return jsNumber( localeCompare(s, a0->toString(exec)));827 return jsNumber(exec, 0); 828 829 // This optimizes the common case that thisObj is a StringObject 830 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 831 JSValue* a0 = args[0]; 832 return jsNumber(exec, localeCompare(s, a0->toString(exec))); 833 833 } 834 834 … … 837 837 // This optimizes the common case that thisObj is a StringObject 838 838 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 839 return jsString( "<big>" + s + "</big>");839 return jsString(exec, "<big>" + s + "</big>"); 840 840 } 841 841 … … 844 844 // This optimizes the common case that thisObj is a StringObject 845 845 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 846 return jsString( "<small>" + s + "</small>");846 return jsString(exec, "<small>" + s + "</small>"); 847 847 } 848 848 … … 851 851 // This optimizes the common case that thisObj is a StringObject 852 852 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 853 return jsString( "<blink>" + s + "</blink>");853 return jsString(exec, "<blink>" + s + "</blink>"); 854 854 } 855 855 … … 858 858 // This optimizes the common case that thisObj is a StringObject 859 859 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 860 return jsString( "<b>" + s + "</b>");860 return jsString(exec, "<b>" + s + "</b>"); 861 861 } 862 862 … … 865 865 // This optimizes the common case that thisObj is a StringObject 866 866 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 867 return jsString( "<tt>" + s + "</tt>");867 return jsString(exec, "<tt>" + s + "</tt>"); 868 868 } 869 869 … … 872 872 // This optimizes the common case that thisObj is a StringObject 873 873 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 874 return jsString( "<i>" + s + "</i>");874 return jsString(exec, "<i>" + s + "</i>"); 875 875 } 876 876 … … 879 879 // This optimizes the common case that thisObj is a StringObject 880 880 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 881 return jsString( "<strike>" + s + "</strike>");881 return jsString(exec, "<strike>" + s + "</strike>"); 882 882 } 883 883 … … 886 886 // This optimizes the common case that thisObj is a StringObject 887 887 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 888 return jsString( "<sub>" + s + "</sub>");888 return jsString(exec, "<sub>" + s + "</sub>"); 889 889 } 890 890 … … 893 893 // This optimizes the common case that thisObj is a StringObject 894 894 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 895 return jsString( "<sup>" + s + "</sup>");895 return jsString(exec, "<sup>" + s + "</sup>"); 896 896 } 897 897 … … 901 901 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 902 902 JSValue* a0 = args[0]; 903 return jsString( "<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");903 return jsString(exec, "<font color=\"" + a0->toString(exec) + "\">" + s + "</font>"); 904 904 } 905 905 … … 909 909 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 910 910 JSValue* a0 = args[0]; 911 return jsString( "<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");911 return jsString(exec, "<font size=\"" + a0->toString(exec) + "\">" + s + "</font>"); 912 912 } 913 913 … … 917 917 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 918 918 JSValue* a0 = args[0]; 919 return jsString( "<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");919 return jsString(exec, "<a name=\"" + a0->toString(exec) + "\">" + s + "</a>"); 920 920 } 921 921 … … 925 925 UString s = thisObj->inherits(&StringObject::info) ? static_cast<StringObject*>(thisObj)->internalValue()->value() : thisObj->toString(exec); 926 926 JSValue* a0 = args[0]; 927 return jsString( "<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");927 return jsString(exec, "<a href=\"" + a0->toString(exec) + "\">" + s + "</a>"); 928 928 } 929 929 … … 936 936 putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly); 937 937 938 putDirectFunction(new StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);938 putDirectFunction(new (exec) StringConstructorFunction(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum); 939 939 940 940 // no. of arguments for constructor 941 putDirect(exec->propertyNames().length, jsNumber( 1), ReadOnly|DontDelete|DontEnum);941 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum); 942 942 } 943 943 … … 949 949 950 950 // ECMA 15.5.2 951 JSObject *StringConstructor::construct(ExecState *exec, const ArgList &args)952 { 953 JSObject *proto = exec->lexicalGlobalObject()->stringPrototype();954 if ( args.size() == 0)955 return new StringObject(proto);956 return new StringObject(proto, args[0]->toString(exec));951 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 957 } 958 958 … … 961 961 { 962 962 if (args.isEmpty()) 963 return jsString( "");963 return jsString(exec, ""); 964 964 else { 965 965 JSValue *v = args[0]; 966 return jsString( v->toString(exec));966 return jsString(exec, v->toString(exec)); 967 967 } 968 968 } … … 974 974 : InternalFunction(funcProto, name) 975 975 { 976 putDirect(exec->propertyNames().length, jsNumber( 1), DontDelete|ReadOnly|DontEnum);976 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete|ReadOnly|DontEnum); 977 977 } 978 978 … … 992 992 s = ""; 993 993 994 return jsString( s);994 return jsString(exec, s); 995 995 } 996 996
Note:
See TracChangeset
for help on using the changeset viewer.