Changeset 53062 in webkit


Ignore:
Timestamp:
Jan 10, 2010 8:55:26 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-10 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Darin Adler.

RegExp.prototype.toString returns "" for empty regular expressions
https://bugs.webkit.org/show_bug.cgi?id=33319

"" starts a single-line comment, hence "/(?:)/" should be used, according to ECMA.

  • runtime/RegExpPrototype.cpp: (JSC::regExpProtoFuncToString):
  • tests/mozilla/ecma_2/RegExp/properties-001.js: (AddRegExpCases):
  • tests/mozilla/js1_2/regexp/toString.js: Update relevant Mozilla tests (Mozilla has had this behavior since November 2003).

2010-01-10 Kent Hansen <kent.hansen@nokia.com>

Reviewed by Darin Adler.

RegExp.prototype.toString returns "" for empty regular expressions
https://bugs.webkit.org/show_bug.cgi?id=33319

Add new test cases and adapt existing ones.

  • fast/js/kde/RegExp-expected.txt:
  • fast/js/kde/script-tests/RegExp.js:
  • fast/js/regexp-compile-expected.txt:
  • fast/js/script-tests/regexp-compile.js:
  • fast/regex/non-pattern-characters-expected.txt:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r53061 r53062  
     12010-01-10  Kent Hansen  <kent.hansen@nokia.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        RegExp.prototype.toString returns "//" for empty regular expressions
     6        https://bugs.webkit.org/show_bug.cgi?id=33319
     7
     8        "//" starts a single-line comment, hence "/(?:)/" should be used, according to ECMA.
     9
     10        * runtime/RegExpPrototype.cpp:
     11        (JSC::regExpProtoFuncToString):
     12
     13        * tests/mozilla/ecma_2/RegExp/properties-001.js:
     14        (AddRegExpCases):
     15        * tests/mozilla/js1_2/regexp/toString.js:
     16        Update relevant Mozilla tests (Mozilla has had this behavior since November 2003).
     17
    1182010-01-10  Darin Adler  <darin@apple.com>
    219
  • trunk/JavaScriptCore/runtime/RegExpPrototype.cpp

    r52984 r53062  
    115115    if (asRegExpObject(thisValue)->get(exec, exec->propertyNames().multiline).toBoolean(exec))
    116116        postfix[index] = 'm';
    117    
    118     return jsNontrivialString(exec, makeString("/", asRegExpObject(thisValue)->get(exec, exec->propertyNames().source).toString(exec), postfix));
     117    UString source = asRegExpObject(thisValue)->get(exec, exec->propertyNames().source).toString(exec);
     118    // If source is empty, use "/(?:)/" to avoid colliding with comment syntax
     119    return jsNontrivialString(exec, makeString("/", source.size() ? source : UString("(?:)"), postfix));
    119120}
    120121
  • trunk/JavaScriptCore/tests/mozilla/ecma_2/RegExp/properties-001.js

    r17862 r53062  
    5757                 re.source );
    5858
     59/*
     60 * http://bugzilla.mozilla.org/show_bug.cgi?id=225550 changed
     61 * the behavior of toString() and toSource() on empty regexps.
     62 * So branch if |s| is the empty string -
     63 */
     64    var S = s? s : '(?:)';
     65
    5966    AddTestCase( re + ".toString()",
    60                  "/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
     67                 "/" + S +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
    6168                 re.toString() );
    6269
  • trunk/JavaScriptCore/tests/mozilla/js1_2/regexp/toString.js

    r53061 r53062  
    4242        var re = new RegExp();
    4343        testcases[count++] = new TestCase ( SECTION, "var re = new RegExp(); re.toString()",
    44                                             '//', re.toString());
     44                                            '/(?:)/', re.toString());
    4545
    4646    // re = /.+/; re.toString();
  • trunk/LayoutTests/ChangeLog

    r53060 r53062  
     12010-01-10  Kent Hansen  <kent.hansen@nokia.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        RegExp.prototype.toString returns "//" for empty regular expressions
     6        https://bugs.webkit.org/show_bug.cgi?id=33319
     7
     8        Add new test cases and adapt existing ones.
     9
     10        * fast/js/kde/RegExp-expected.txt:
     11        * fast/js/kde/script-tests/RegExp.js:
     12        * fast/js/regexp-compile-expected.txt:
     13        * fast/js/script-tests/regexp-compile.js:
     14        * fast/regex/non-pattern-characters-expected.txt:
     15
    1162010-01-10  Robert Hogan  <robert@roberthogan.net>
    217
  • trunk/LayoutTests/fast/js/kde/RegExp-expected.txt

    r52984 r53062  
    9393FAIL Object.prototype.toString.apply(RegExp.prototype) should be [object RegExp]. Was [object RegExpPrototype].
    9494PASS typeof RegExp.prototype.toString() is 'string'
     95PASS new RegExp().toString() is '/(?:)/'
     96PASS (new RegExp('(?:)')).source is '(?:)'
     97PASS /(?:)/.toString() is '/(?:)/'
     98PASS /(?:)/.source is '(?:)'
    9599Done.
    96100PASS successfullyParsed is true
  • trunk/LayoutTests/fast/js/kde/script-tests/RegExp.js

    r52984 r53062  
    149149shouldBe("typeof RegExp.prototype.toString()", "'string'");
    150150
     151// Empty regular expressions have string representation /(?:)/
     152shouldBe("new RegExp().toString()", "'/(?:)/'");
     153shouldBe("(new RegExp('(?:)')).source", "'(?:)'");
     154shouldBe("/(?:)/.toString()", "'/(?:)/'");
     155shouldBe("/(?:)/.source", "'(?:)'");
     156
    151157debug("Done.");
    152158successfullyParsed = true
  • trunk/LayoutTests/fast/js/regexp-compile-expected.txt

    r52984 r53062  
    2020PASS re.toString() is '/undefined/'
    2121PASS re.toString() is '/null/'
    22 PASS re.toString() is '//'
     22PASS re.toString() is '/(?:)/'
    2323PASS re.toString() is '/z/'
    2424PASS re.lastIndex is 0
  • trunk/LayoutTests/fast/js/script-tests/regexp-compile.js

    r52984 r53062  
    3939
    4040re.compile();
    41 shouldBe("re.toString()", "'//'"); // /(?:)/ in Firefox
     41shouldBe("re.toString()", "'/(?:)/'");
    4242
    4343re.compile("z", undefined);
  • trunk/LayoutTests/fast/regex/non-pattern-characters-expected.txt

    r52984 r53062  
    157157PASS regexp.lastIndex is 2
    158158
    159 Testing regexp: //gm
     159Testing regexp: /(?:)/gm
    160160PASS regexp.test('') is true
    161161PASS regexp.lastIndex is 0
Note: See TracChangeset for help on using the changeset viewer.