Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8011086 Specification fails (outside test262)
  3. JDK-8011394

RegExp.prototype.test() does not call valueOf on lastIndex property as per the spec.

    XMLWordPrintable

Details

    • Sub-task
    • Status: Closed
    • P4
    • Resolution: Fixed
    • None
    • 8
    • core-libs
    • None
    • b86
    • generic
    • generic
    • Verified

    Description


      (re = RegExp(), re.lastIndex = {valueOf:function(){print("lastIndex"); return 0}}, re.test(""))
      => should print "lastIndex"

      ECMA 15.10.6.2 RegExp.prototype.exec(string)

      Steps 5 to 7 are as follows:

      4. Let lastIndex be the result of calling the [[Get]] internal method of R with argument "lastIndex"..

      5. Let i be the value of ToInteger(lastIndex).

      6. Let global be the result of calling the [[Get]] internal method of R with argument "global".

      7. If global is false, then let i = 0

      Nashorn code avoids [[Get]] on "lastIndex" when global is false - which prevents valueOf side-effect call.
      The following diff fixes the issue:

      diff -r 82fed56d8dce src/jdk/nashorn/internal/objects/NativeRegExp.java
      --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Apr 03 20:17:05 2013 +0530
      +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Apr 03 21:59:29 2013 +0530
      @@ -523,8 +523,11 @@
           }
       
           private RegExpResult execInner(final String string) {
      + int start = getLastIndex();
      + if (! regexp.isGlobal()) {
      + start = 0;
      + }
       
      - final int start = regexp.isGlobal() ? getLastIndex() : 0;
               if (start < 0 || start > string.length()) {
                   setLastIndex(0);
                   return null;


      Attachments

        Activity

          People

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: