[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

oliver at apple.com oliver at apple.com
Thu Oct 29 20:42:56 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit e602fc65a588348a48f350e62de86d11dee8067d
Author: oliver at apple.com <oliver at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Oct 11 03:47:01 2009 +0000

    Support for String.trim(), String.trimLeft() and String.trimRight() methods
    https://bugs.webkit.org/show_bug.cgi?id=26590
    
    Reviewed by Maciej Stachowiak.
    
    Implement trim, trimLeft, and trimRight
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49423 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index c33168e..9ca0b04 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,21 @@
+2009-10-10  Oliver Hunt  <oliver at apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Support for String.trim(), String.trimLeft() and String.trimRight() methods
+        https://bugs.webkit.org/show_bug.cgi?id=26590
+
+        Implement trim, trimLeft, and trimRight
+
+        * runtime/StringPrototype.cpp:
+        (JSC::isTrimWhitespace):
+           Our normal string whitespace function does not include U+200B which
+           is needed for compatibility with mozilla's implementation of trim.
+           U+200B does not appear to be expected according to spec, however I am
+           choosing to be lax, and match mozilla behavior so have added this
+           exception.
+        (JSC::trimString):
+
 2009-10-09  Geoffrey Garen  <ggaren at apple.com>
 
         Reviewed by Oliver Hunt.
diff --git a/JavaScriptCore/runtime/StringPrototype.cpp b/JavaScriptCore/runtime/StringPrototype.cpp
index 181f40e..a0713b8 100644
--- a/JavaScriptCore/runtime/StringPrototype.cpp
+++ b/JavaScriptCore/runtime/StringPrototype.cpp
@@ -25,6 +25,7 @@
 #include "CachedCall.h"
 #include "Error.h"
 #include "Executable.h"
+#include "JSGlobalObjectFunctions.h"
 #include "JSArray.h"
 #include "JSFunction.h"
 #include "ObjectPrototype.h"
@@ -72,6 +73,10 @@ static JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState*, JSObject*, JSVa
 static JSValue JSC_HOST_CALL stringProtoFuncAnchor(ExecState*, JSObject*, JSValue, const ArgList&);
 static JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState*, JSObject*, JSValue, const ArgList&);
 
+static JSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState*, JSObject*, JSValue, const ArgList&);
+static JSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState*, JSObject*, JSValue, const ArgList&);
+static JSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState*, JSObject*, JSValue, const ArgList&);
+
 }
 
 #include "StringPrototype.lut.h"
@@ -117,6 +122,9 @@ const ClassInfo StringPrototype::info = { "String", &StringObject::info, 0, Exec
     fontsize              stringProtoFuncFontsize          DontEnum|Function       1
     anchor                stringProtoFuncAnchor            DontEnum|Function       1
     link                  stringProtoFuncLink              DontEnum|Function       1
+    trim                  stringProtoFuncTrim              DontEnum|Function       0
+    trimLeft              stringProtoFuncTrimLeft          DontEnum|Function       0
+    trimRight             stringProtoFuncTrimRight         DontEnum|Function       0
 @end
 */
 
@@ -899,4 +907,51 @@ JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec, JSObject*, JSValue th
     return jsNontrivialString(exec, UString(buffer, bufferSize, false));
 }
 
+enum {
+    TrimLeft = 1,
+    TrimRight = 2
+};
+
+static inline bool isTrimWhitespace(UChar c)
+{
+    return isStrWhiteSpace(c) || c == 0x200b;
+}
+
+static inline JSValue trimString(ExecState* exec, JSValue thisValue, int trimKind)
+{
+    UString str = thisValue.toThisString(exec);
+    int left = 0;
+    if (trimKind & TrimLeft) {
+        while (left < str.size() && isTrimWhitespace(str[left]))
+            left++;
+    }
+    int right = str.size();
+    if (trimKind & TrimRight) {
+        while (right > left && isTrimWhitespace(str[right - 1]))
+            right--;
+    }
+
+    // Don't gc allocate a new string if we don't have to.
+    if (left == 0 && right == str.size() && thisValue.isString())
+        return thisValue;
+
+    return jsString(exec, str.substr(left, right - left));
+}
+
+JSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
+{
+    return trimString(exec, thisValue, TrimLeft | TrimRight);
+}
+
+JSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
+{
+    return trimString(exec, thisValue, TrimLeft);
+}
+
+JSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState* exec, JSObject*, JSValue thisValue, const ArgList&)
+{
+    return trimString(exec, thisValue, TrimRight);
+}
+    
+    
 } // namespace JSC
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index d5d8a53..daba6f0 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2009-10-10  Oliver Hunt  <oliver at apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Support for String.trim(), String.trimLeft() and String.trimRight() methods
+        https://bugs.webkit.org/show_bug.cgi?id=26590
+
+        Add tests for trim, trimLeft, and trimRight
+
+        * fast/js/script-tests/string-trim.js: Added.
+        * fast/js/string-trim-expected.txt: Added.
+        * fast/js/string-trim.html: Added.
+
 2009-10-10  Ryosuke Niwa  <rniwa at webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/fast/js/script-tests/string-trim.js b/LayoutTests/fast/js/script-tests/string-trim.js
new file mode 100644
index 0000000..3175f30
--- /dev/null
+++ b/LayoutTests/fast/js/script-tests/string-trim.js
@@ -0,0 +1,73 @@
+description("This test checks String.trim(), String.trimLeft() and String.trimRight() methods.");
+
+//references to trim(), trimLeft() and trimRight() functions for testing Function's *.call() and *.apply() methods
+var trim            = String.prototype.trim;
+var trimLeft        = String.prototype.trimLeft;
+var trimRight       = String.prototype.trimRight;
+
+var testString      = 'foo bar';
+var trimString      = '';
+var leftTrimString  = '';
+var rightTrimString = '';
+var wsString        = '';
+
+var whitespace      = [
+    {s : '\u0009', t : 'HORIZONTAL TAB'},
+    {s : '\u000A', t : 'LINE FEED OR NEW LINE'},
+    {s : '\u000B', t : 'VERTICAL TAB'},
+    {s : '\u000C', t : 'FORMFEED'},
+    {s : '\u000D', t : 'CARRIAGE RETURN'},
+    {s : '\u0020', t : 'SPACE'},
+    {s : '\u00A0', t : 'NO-BREAK SPACE'},
+    {s : '\u2000', t : 'EN QUAD'},
+    {s : '\u2001', t : 'EM QUAD'},
+    {s : '\u2002', t : 'EN SPACE'},
+    {s : '\u2003', t : 'EM SPACE'},
+    {s : '\u2004', t : 'THREE-PER-EM SPACE'},
+    {s : '\u2005', t : 'FOUR-PER-EM SPACE'},
+    {s : '\u2006', t : 'SIX-PER-EM SPACE'},
+    {s : '\u2007', t : 'FIGURE SPACE'},
+    {s : '\u2008', t : 'PUNCTUATION SPACE'},
+    {s : '\u2009', t : 'THIN SPACE'},
+    {s : '\u200A', t : 'HAIR SPACE'},
+    {s : '\u3000', t : 'IDEOGRAPHIC SPACE'},
+    {s : '\u2028', t : 'LINE SEPARATOR'},
+    {s : '\u2029', t : 'PARAGRAPH SEPARATOR'},
+    {s : '\u200B', t : 'ZERO WIDTH SPACE (category Cf)'}
+];
+
+for (var i = 0; i < whitespace.length; i++) {
+    shouldBe("whitespace["+i+"].s.trim()", "''");
+    shouldBe("whitespace["+i+"].s.trimLeft()", "''");
+    shouldBe("whitespace["+i+"].s.trimRight()", "''");
+    wsString += whitespace[i].s;
+}
+
+trimString      = wsString   + testString + wsString;
+leftTrimString  = testString + wsString;   //trimmed from the left
+rightTrimString = wsString   + testString; //trimmed from the right
+    
+shouldBe("wsString.trim()",      "''");
+shouldBe("wsString.trimLeft()",  "''");
+shouldBe("wsString.trimRight()", "''");
+
+shouldBe("trimString.trim()",      "testString");
+shouldBe("trimString.trimLeft()",  "leftTrimString");
+shouldBe("trimString.trimRight()", "rightTrimString");
+
+shouldBe("leftTrimString.trim()",      "testString");
+shouldBe("leftTrimString.trimLeft()",  "leftTrimString");
+shouldBe("leftTrimString.trimRight()", "testString");
+    
+shouldBe("rightTrimString.trim()",      "testString");
+shouldBe("rightTrimString.trimLeft()",  "testString");
+shouldBe("rightTrimString.trimRight()", "rightTrimString");
+
+var testValues = ["0", "Infinity", "NaN", "true", "false", "({})", "({toString:function(){return 'wibble'}})", "['an','array']"];
+for (var i = 0; i < testValues.length; i++) {
+    shouldBe("trim.call("+testValues[i]+")", "'"+eval(testValues[i])+"'");
+    shouldBe("trimLeft.call("+testValues[i]+")", "'"+eval(testValues[i])+"'");
+    shouldBe("trimRight.call("+testValues[i]+")", "'"+eval(testValues[i])+"'");
+}
+var successfullyParsed = true;
+
diff --git a/LayoutTests/fast/js/string-trim-expected.txt b/LayoutTests/fast/js/string-trim-expected.txt
new file mode 100644
index 0000000..5c4a2ce
--- /dev/null
+++ b/LayoutTests/fast/js/string-trim-expected.txt
@@ -0,0 +1,111 @@
+This test checks String.trim(), String.trimLeft() and String.trimRight() methods.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS whitespace[0].s.trim() is ''
+PASS whitespace[0].s.trimLeft() is ''
+PASS whitespace[0].s.trimRight() is ''
+PASS whitespace[1].s.trim() is ''
+PASS whitespace[1].s.trimLeft() is ''
+PASS whitespace[1].s.trimRight() is ''
+PASS whitespace[2].s.trim() is ''
+PASS whitespace[2].s.trimLeft() is ''
+PASS whitespace[2].s.trimRight() is ''
+PASS whitespace[3].s.trim() is ''
+PASS whitespace[3].s.trimLeft() is ''
+PASS whitespace[3].s.trimRight() is ''
+PASS whitespace[4].s.trim() is ''
+PASS whitespace[4].s.trimLeft() is ''
+PASS whitespace[4].s.trimRight() is ''
+PASS whitespace[5].s.trim() is ''
+PASS whitespace[5].s.trimLeft() is ''
+PASS whitespace[5].s.trimRight() is ''
+PASS whitespace[6].s.trim() is ''
+PASS whitespace[6].s.trimLeft() is ''
+PASS whitespace[6].s.trimRight() is ''
+PASS whitespace[7].s.trim() is ''
+PASS whitespace[7].s.trimLeft() is ''
+PASS whitespace[7].s.trimRight() is ''
+PASS whitespace[8].s.trim() is ''
+PASS whitespace[8].s.trimLeft() is ''
+PASS whitespace[8].s.trimRight() is ''
+PASS whitespace[9].s.trim() is ''
+PASS whitespace[9].s.trimLeft() is ''
+PASS whitespace[9].s.trimRight() is ''
+PASS whitespace[10].s.trim() is ''
+PASS whitespace[10].s.trimLeft() is ''
+PASS whitespace[10].s.trimRight() is ''
+PASS whitespace[11].s.trim() is ''
+PASS whitespace[11].s.trimLeft() is ''
+PASS whitespace[11].s.trimRight() is ''
+PASS whitespace[12].s.trim() is ''
+PASS whitespace[12].s.trimLeft() is ''
+PASS whitespace[12].s.trimRight() is ''
+PASS whitespace[13].s.trim() is ''
+PASS whitespace[13].s.trimLeft() is ''
+PASS whitespace[13].s.trimRight() is ''
+PASS whitespace[14].s.trim() is ''
+PASS whitespace[14].s.trimLeft() is ''
+PASS whitespace[14].s.trimRight() is ''
+PASS whitespace[15].s.trim() is ''
+PASS whitespace[15].s.trimLeft() is ''
+PASS whitespace[15].s.trimRight() is ''
+PASS whitespace[16].s.trim() is ''
+PASS whitespace[16].s.trimLeft() is ''
+PASS whitespace[16].s.trimRight() is ''
+PASS whitespace[17].s.trim() is ''
+PASS whitespace[17].s.trimLeft() is ''
+PASS whitespace[17].s.trimRight() is ''
+PASS whitespace[18].s.trim() is ''
+PASS whitespace[18].s.trimLeft() is ''
+PASS whitespace[18].s.trimRight() is ''
+PASS whitespace[19].s.trim() is ''
+PASS whitespace[19].s.trimLeft() is ''
+PASS whitespace[19].s.trimRight() is ''
+PASS whitespace[20].s.trim() is ''
+PASS whitespace[20].s.trimLeft() is ''
+PASS whitespace[20].s.trimRight() is ''
+PASS whitespace[21].s.trim() is ''
+PASS whitespace[21].s.trimLeft() is ''
+PASS whitespace[21].s.trimRight() is ''
+PASS wsString.trim() is ''
+PASS wsString.trimLeft() is ''
+PASS wsString.trimRight() is ''
+PASS trimString.trim() is testString
+PASS trimString.trimLeft() is leftTrimString
+PASS trimString.trimRight() is rightTrimString
+PASS leftTrimString.trim() is testString
+PASS leftTrimString.trimLeft() is leftTrimString
+PASS leftTrimString.trimRight() is testString
+PASS rightTrimString.trim() is testString
+PASS rightTrimString.trimLeft() is testString
+PASS rightTrimString.trimRight() is rightTrimString
+PASS trim.call(0) is '0'
+PASS trimLeft.call(0) is '0'
+PASS trimRight.call(0) is '0'
+PASS trim.call(Infinity) is 'Infinity'
+PASS trimLeft.call(Infinity) is 'Infinity'
+PASS trimRight.call(Infinity) is 'Infinity'
+PASS trim.call(NaN) is 'NaN'
+PASS trimLeft.call(NaN) is 'NaN'
+PASS trimRight.call(NaN) is 'NaN'
+PASS trim.call(true) is 'true'
+PASS trimLeft.call(true) is 'true'
+PASS trimRight.call(true) is 'true'
+PASS trim.call(false) is 'false'
+PASS trimLeft.call(false) is 'false'
+PASS trimRight.call(false) is 'false'
+PASS trim.call(({})) is '[object Object]'
+PASS trimLeft.call(({})) is '[object Object]'
+PASS trimRight.call(({})) is '[object Object]'
+PASS trim.call(({toString:function(){return 'wibble'}})) is 'wibble'
+PASS trimLeft.call(({toString:function(){return 'wibble'}})) is 'wibble'
+PASS trimRight.call(({toString:function(){return 'wibble'}})) is 'wibble'
+PASS trim.call(['an','array']) is 'an,array'
+PASS trimLeft.call(['an','array']) is 'an,array'
+PASS trimRight.call(['an','array']) is 'an,array'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/string-trim.html b/LayoutTests/fast/js/string-trim.html
new file mode 100644
index 0000000..cb933b4
--- /dev/null
+++ b/LayoutTests/fast/js/string-trim.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/string-trim.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list