Changeset 91284 in webkit
- Timestamp:
- Jul 19, 2011 12:16:28 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r91277 r91284 1 2011-07-19 Gavin Barraclough <barraclough@apple.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=64677 4 Fix bugs in String.prototype this handling. 5 6 Reviewed by Oliver Hunt. 7 8 * fast/js/script-tests/string-prototype-properties.js: Added. 9 * fast/js/string-prototype-properties-expected.txt: Added. 10 * fast/js/string-prototype-properties.html: Added. 11 - Added layout test for string prototype functions with undefined/number as this value. 12 1 13 2011-07-19 Robert Hogan <robert@webkit.org> 2 14 -
trunk/Source/JavaScriptCore/ChangeLog
r91280 r91284 1 2011-07-19 Gavin Barraclough <barraclough@apple.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=64677 4 Fix bugs in String.prototype this handling. 5 6 Reviewed by Oliver Hunt. 7 8 undefined/null this values should throw TypeErrors, not convert to 9 the global object, and primitive values should not be converted via 10 object types. 11 12 * runtime/StringPrototype.cpp: 13 (JSC::stringProtoFuncReplace): 14 (JSC::stringProtoFuncCharAt): 15 (JSC::stringProtoFuncCharCodeAt): 16 (JSC::stringProtoFuncIndexOf): 17 (JSC::stringProtoFuncLastIndexOf): 18 (JSC::stringProtoFuncMatch): 19 (JSC::stringProtoFuncSearch): 20 (JSC::stringProtoFuncSlice): 21 (JSC::stringProtoFuncSplit): 22 (JSC::stringProtoFuncSubstr): 23 (JSC::stringProtoFuncSubstring): 24 (JSC::stringProtoFuncToLowerCase): 25 (JSC::stringProtoFuncToUpperCase): 26 (JSC::stringProtoFuncLocaleCompare): 27 (JSC::stringProtoFuncBig): 28 (JSC::stringProtoFuncSmall): 29 (JSC::stringProtoFuncBlink): 30 (JSC::stringProtoFuncBold): 31 (JSC::stringProtoFuncFixed): 32 (JSC::stringProtoFuncItalics): 33 (JSC::stringProtoFuncStrike): 34 (JSC::stringProtoFuncSub): 35 (JSC::stringProtoFuncSup): 36 (JSC::stringProtoFuncFontcolor): 37 (JSC::stringProtoFuncFontsize): 38 (JSC::stringProtoFuncAnchor): 39 (JSC::stringProtoFuncLink): 40 (JSC::trimString): 41 - These methods should throw if this value is undefined, 42 convert ToString directly, not via ToObject. 43 1 44 2011-07-19 Filip Pizlo <fpizlo@apple.com> 2 45 -
trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp
r91194 r91284 298 298 { 299 299 JSValue thisValue = exec->hostThisValue(); 300 JSString* sourceVal = thisValue.toThisJSString(exec); 300 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 301 return throwVMTypeError(exec); 302 JSString* sourceVal = thisValue.isString() ? asString(thisValue) : jsString(exec, thisValue.toString(exec)); 301 303 JSValue pattern = exec->argument(0); 302 304 JSValue replacement = exec->argument(1); … … 488 490 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 489 491 return throwVMTypeError(exec); 490 UString s = thisValue.to ThisString(exec);492 UString s = thisValue.toString(exec); 491 493 unsigned len = s.length(); 492 494 JSValue a0 = exec->argument(0); … … 508 510 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 509 511 return throwVMTypeError(exec); 510 UString s = thisValue.to ThisString(exec);512 UString s = thisValue.toString(exec); 511 513 unsigned len = s.length(); 512 514 JSValue a0 = exec->argument(0); … … 542 544 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 543 545 return throwVMTypeError(exec); 544 UString s = thisValue.to ThisString(exec);546 UString s = thisValue.toString(exec); 545 547 int len = s.length(); 546 548 … … 573 575 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 574 576 return throwVMTypeError(exec); 575 UString s = thisValue.to ThisString(exec);577 UString s = thisValue.toString(exec); 576 578 int len = s.length(); 577 579 … … 602 604 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 603 605 return throwVMTypeError(exec); 604 UString s = thisValue.to ThisString(exec);606 UString s = thisValue.toString(exec); 605 607 JSGlobalData* globalData = &exec->globalData(); 606 608 … … 651 653 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 652 654 return throwVMTypeError(exec); 653 UString s = thisValue.to ThisString(exec);655 UString s = thisValue.toString(exec); 654 656 JSGlobalData* globalData = &exec->globalData(); 655 657 … … 679 681 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 680 682 return throwVMTypeError(exec); 681 UString s = thisValue.to ThisString(exec);683 UString s = thisValue.toString(exec); 682 684 int len = s.length(); 683 685 … … 706 708 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 707 709 return throwVMTypeError(exec); 708 UString s = thisValue.to ThisString(exec);710 UString s = thisValue.toString(exec); 709 711 JSGlobalData* globalData = &exec->globalData(); 710 712 … … 770 772 { 771 773 JSValue thisValue = exec->hostThisValue(); 772 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible773 return throwVMTypeError(exec);774 774 unsigned len; 775 775 JSString* jsString = 0; … … 778 778 jsString = static_cast<JSString*>(thisValue.asCell()); 779 779 len = jsString->length(); 780 } else if (thisValue.isUndefinedOrNull()) { 781 // CheckObjectCoercible 782 return throwVMTypeError(exec); 780 783 } else { 781 uString = thisValue.toThisObject(exec)->toString(exec); 784 uString = thisValue.toString(exec); 785 if (exec->hadException()) 786 return JSValue::encode(jsUndefined()); 782 787 len = uString.length(); 783 788 } … … 807 812 { 808 813 JSValue thisValue = exec->hostThisValue(); 809 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible810 return throwVMTypeError(exec);811 814 int len; 812 815 JSString* jsString = 0; … … 815 818 jsString = static_cast<JSString*>(thisValue.asCell()); 816 819 len = jsString->length(); 820 } else if (thisValue.isUndefinedOrNull()) { 821 // CheckObjectCoercible 822 return throwVMTypeError(exec); 817 823 } else { 818 uString = thisValue.toThisObject(exec)->toString(exec); 824 uString = thisValue.toString(exec); 825 if (exec->hadException()) 826 return JSValue::encode(jsUndefined()); 819 827 len = uString.length(); 820 828 } … … 855 863 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 856 864 return throwVMTypeError(exec); 857 JSString* sVal = thisValue. toThisJSString(exec);865 JSString* sVal = thisValue.isString() ? asString(thisValue) : jsString(exec, thisValue.toString(exec)); 858 866 const UString& s = sVal->value(exec); 859 867 … … 895 903 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 896 904 return throwVMTypeError(exec); 897 JSString* sVal = thisValue. toThisJSString(exec);905 JSString* sVal = thisValue.isString() ? asString(thisValue) : jsString(exec, thisValue.toString(exec)); 898 906 const UString& s = sVal->value(exec); 899 907 … … 938 946 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 939 947 return throwVMTypeError(exec); 940 941 UString s = thisValue.toThisString(exec); 948 UString s = thisValue.toString(exec); 949 942 950 JSValue a0 = exec->argument(0); 943 951 return JSValue::encode(jsNumber(localeCompare(s, a0.toString(exec)))); … … 947 955 { 948 956 JSValue thisValue = exec->hostThisValue(); 949 UString s = thisValue.toThisString(exec); 957 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 958 return throwVMTypeError(exec); 959 UString s = thisValue.toString(exec); 950 960 return JSValue::encode(jsMakeNontrivialString(exec, "<big>", s, "</big>")); 951 961 } … … 954 964 { 955 965 JSValue thisValue = exec->hostThisValue(); 956 UString s = thisValue.toThisString(exec); 966 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 967 return throwVMTypeError(exec); 968 UString s = thisValue.toString(exec); 957 969 return JSValue::encode(jsMakeNontrivialString(exec, "<small>", s, "</small>")); 958 970 } … … 961 973 { 962 974 JSValue thisValue = exec->hostThisValue(); 963 UString s = thisValue.toThisString(exec); 975 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 976 return throwVMTypeError(exec); 977 UString s = thisValue.toString(exec); 964 978 return JSValue::encode(jsMakeNontrivialString(exec, "<blink>", s, "</blink>")); 965 979 } … … 968 982 { 969 983 JSValue thisValue = exec->hostThisValue(); 970 UString s = thisValue.toThisString(exec); 984 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 985 return throwVMTypeError(exec); 986 UString s = thisValue.toString(exec); 971 987 return JSValue::encode(jsMakeNontrivialString(exec, "<b>", s, "</b>")); 972 988 } … … 975 991 { 976 992 JSValue thisValue = exec->hostThisValue(); 977 UString s = thisValue.toThisString(exec); 993 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 994 return throwVMTypeError(exec); 995 UString s = thisValue.toString(exec); 978 996 return JSValue::encode(jsMakeNontrivialString(exec, "<tt>", s, "</tt>")); 979 997 } … … 982 1000 { 983 1001 JSValue thisValue = exec->hostThisValue(); 984 UString s = thisValue.toThisString(exec); 1002 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1003 return throwVMTypeError(exec); 1004 UString s = thisValue.toString(exec); 985 1005 return JSValue::encode(jsMakeNontrivialString(exec, "<i>", s, "</i>")); 986 1006 } … … 989 1009 { 990 1010 JSValue thisValue = exec->hostThisValue(); 991 UString s = thisValue.toThisString(exec); 1011 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1012 return throwVMTypeError(exec); 1013 UString s = thisValue.toString(exec); 992 1014 return JSValue::encode(jsMakeNontrivialString(exec, "<strike>", s, "</strike>")); 993 1015 } … … 996 1018 { 997 1019 JSValue thisValue = exec->hostThisValue(); 998 UString s = thisValue.toThisString(exec); 1020 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1021 return throwVMTypeError(exec); 1022 UString s = thisValue.toString(exec); 999 1023 return JSValue::encode(jsMakeNontrivialString(exec, "<sub>", s, "</sub>")); 1000 1024 } … … 1003 1027 { 1004 1028 JSValue thisValue = exec->hostThisValue(); 1005 UString s = thisValue.toThisString(exec); 1029 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1030 return throwVMTypeError(exec); 1031 UString s = thisValue.toString(exec); 1006 1032 return JSValue::encode(jsMakeNontrivialString(exec, "<sup>", s, "</sup>")); 1007 1033 } … … 1010 1036 { 1011 1037 JSValue thisValue = exec->hostThisValue(); 1012 UString s = thisValue.toThisString(exec); 1038 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1039 return throwVMTypeError(exec); 1040 UString s = thisValue.toString(exec); 1013 1041 JSValue a0 = exec->argument(0); 1014 1042 return JSValue::encode(jsMakeNontrivialString(exec, "<font color=\"", a0.toString(exec), "\">", s, "</font>")); … … 1018 1046 { 1019 1047 JSValue thisValue = exec->hostThisValue(); 1020 UString s = thisValue.toThisString(exec); 1048 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1049 return throwVMTypeError(exec); 1050 UString s = thisValue.toString(exec); 1021 1051 JSValue a0 = exec->argument(0); 1022 1052 … … 1061 1091 { 1062 1092 JSValue thisValue = exec->hostThisValue(); 1063 UString s = thisValue.toThisString(exec); 1093 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1094 return throwVMTypeError(exec); 1095 UString s = thisValue.toString(exec); 1064 1096 JSValue a0 = exec->argument(0); 1065 1097 return JSValue::encode(jsMakeNontrivialString(exec, "<a name=\"", a0.toString(exec), "\">", s, "</a>")); … … 1069 1101 { 1070 1102 JSValue thisValue = exec->hostThisValue(); 1071 UString s = thisValue.toThisString(exec); 1103 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1104 return throwVMTypeError(exec); 1105 UString s = thisValue.toString(exec); 1072 1106 JSValue a0 = exec->argument(0); 1073 1107 UString linkText = a0.toString(exec); … … 1114 1148 if (thisValue.isUndefinedOrNull()) // CheckObjectCoercible 1115 1149 return throwTypeError(exec); 1116 UString str = thisValue.to ThisString(exec);1150 UString str = thisValue.toString(exec); 1117 1151 unsigned left = 0; 1118 1152 if (trimKind & TrimLeft) {
Note: See TracChangeset
for help on using the changeset viewer.