Changeset 49423 in webkit
- Timestamp:
- Oct 10, 2009 8:47:01 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r49409 r49423 1 2009-10-10 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Maciej Stachowiak. 4 5 Support for String.trim(), String.trimLeft() and String.trimRight() methods 6 https://bugs.webkit.org/show_bug.cgi?id=26590 7 8 Implement trim, trimLeft, and trimRight 9 10 * runtime/StringPrototype.cpp: 11 (JSC::isTrimWhitespace): 12 Our normal string whitespace function does not include U+200B which 13 is needed for compatibility with mozilla's implementation of trim. 14 U+200B does not appear to be expected according to spec, however I am 15 choosing to be lax, and match mozilla behavior so have added this 16 exception. 17 (JSC::trimString): 18 1 19 2009-10-09 Geoffrey Garen <ggaren@apple.com> 2 20 -
trunk/JavaScriptCore/runtime/StringPrototype.cpp
r49371 r49423 26 26 #include "Error.h" 27 27 #include "Executable.h" 28 #include "JSGlobalObjectFunctions.h" 28 29 #include "JSArray.h" 29 30 #include "JSFunction.h" … … 72 73 static JSValue JSC_HOST_CALL stringProtoFuncAnchor(ExecState*, JSObject*, JSValue, const ArgList&); 73 74 static JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState*, JSObject*, JSValue, const ArgList&); 75 76 static JSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState*, JSObject*, JSValue, const ArgList&); 77 static JSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState*, JSObject*, JSValue, const ArgList&); 78 static JSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState*, JSObject*, JSValue, const ArgList&); 74 79 75 80 } … … 118 123 anchor stringProtoFuncAnchor DontEnum|Function 1 119 124 link stringProtoFuncLink DontEnum|Function 1 125 trim stringProtoFuncTrim DontEnum|Function 0 126 trimLeft stringProtoFuncTrimLeft DontEnum|Function 0 127 trimRight stringProtoFuncTrimRight DontEnum|Function 0 120 128 @end 121 129 */ … … 900 908 } 901 909 910 enum { 911 TrimLeft = 1, 912 TrimRight = 2 913 }; 914 915 static inline bool isTrimWhitespace(UChar c) 916 { 917 return isStrWhiteSpace(c) || c == 0x200b; 918 } 919 920 static inline JSValue trimString(ExecState* exec, JSValue thisValue, int trimKind) 921 { 922 UString str = thisValue.toThisString(exec); 923 int left = 0; 924 if (trimKind & TrimLeft) { 925 while (left < str.size() && isTrimWhitespace(str[left])) 926 left++; 927 } 928 int right = str.size(); 929 if (trimKind & TrimRight) { 930 while (right > left && isTrimWhitespace(str[right - 1])) 931 right--; 932 } 933 934 // Don't gc allocate a new string if we don't have to. 935 if (left == 0 && right == str.size() && thisValue.isString()) 936 return thisValue; 937 938 return jsString(exec, str.substr(left, right - left)); 939 } 940 941 JSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) 942 { 943 return trimString(exec, thisValue, TrimLeft | TrimRight); 944 } 945 946 JSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) 947 { 948 return trimString(exec, thisValue, TrimLeft); 949 } 950 951 JSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&) 952 { 953 return trimString(exec, thisValue, TrimRight); 954 } 955 956 902 957 } // namespace JSC -
trunk/LayoutTests/ChangeLog
r49422 r49423 1 2009-10-10 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Maciej Stachowiak. 4 5 Support for String.trim(), String.trimLeft() and String.trimRight() methods 6 https://bugs.webkit.org/show_bug.cgi?id=26590 7 8 Add tests for trim, trimLeft, and trimRight 9 10 * fast/js/script-tests/string-trim.js: Added. 11 * fast/js/string-trim-expected.txt: Added. 12 * fast/js/string-trim.html: Added. 13 1 14 2009-10-10 Ryosuke Niwa <rniwa@webkit.org> 2 15
Note: See TracChangeset
for help on using the changeset viewer.