Merge

Wed, 17 Apr 2013 21:50:54 -0700

author
lana
date
Wed, 17 Apr 2013 21:50:54 -0700
changeset 198
cba329ce5efe
parent 184
002ad9d6735f
parent 197
44d8612e29b0
child 199
774aeaa89bc1

Merge

     1.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java	Tue Apr 16 15:00:54 2013 -0700
     1.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java	Wed Apr 17 21:50:54 2013 -0700
     1.3 @@ -210,42 +210,10 @@
     1.4      }
     1.5  
     1.6      private static ClassLoader getAppClassLoader() {
     1.7 -        if (System.getSecurityManager() == null) {
     1.8 -            return Thread.currentThread().getContextClassLoader();
     1.9 -        }
    1.10 -
    1.11 -        // Try to determine the caller class loader. Use that if it can be
    1.12 -        // found. If not, use the class loader of nashorn itself as the
    1.13 -        // "application" class loader for scripts.
    1.14 -
    1.15 -        // User could have called ScriptEngineFactory.getScriptEngine()
    1.16 -        //
    1.17 -        // <caller>
    1.18 -        //  <factory.getScriptEngine()>
    1.19 -        //   <factory.getAppClassLoader()>
    1.20 -        //    <Reflection.getCallerClass()>
    1.21 -        //
    1.22 -        // or used one of the getEngineByABC methods of ScriptEngineManager.
    1.23 -        //
    1.24 -        // <caller>
    1.25 -        //  <ScriptEngineManager.getEngineByName()>
    1.26 -        //   <factory.getScriptEngine()>
    1.27 -        //    <factory.getAppClassLoader()>
    1.28 -        //     <Reflection.getCallerClass()>
    1.29 -
    1.30 -        // So, stack depth is 3 or 4 (recall it is zero based). We try
    1.31 -        // stack depths 3, 4 and look for non-bootstrap caller.
    1.32 -        Class<?> caller = null;
    1.33 -        for (int depth = 3; depth < 5; depth++) {
    1.34 -            caller = Reflection.getCallerClass(depth);
    1.35 -            if (caller != null && caller.getClassLoader() != null) {
    1.36 -                // found a non-bootstrap caller
    1.37 -                break;
    1.38 -            }
    1.39 -        }
    1.40 -
    1.41 -        final ClassLoader ccl = (caller == null)? null : caller.getClassLoader();
    1.42 -        // if caller loader is null, then use nashorn's own loader
    1.43 +        // Revisit: script engine implementation needs the capability to
    1.44 +        // find the class loader of the context in which the script engine
    1.45 +        // is running so that classes will be found and loaded properly
    1.46 +        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    1.47          return (ccl == null)? NashornScriptEngineFactory.class.getClassLoader() : ccl;
    1.48      }
    1.49  }
     2.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java	Tue Apr 16 15:00:54 2013 -0700
     2.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java	Wed Apr 17 21:50:54 2013 -0700
     2.3 @@ -76,7 +76,7 @@
     2.4  
     2.5      private static final MethodHandle REDUCE_CALLBACK_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class,
     2.6              Object.class, Undefined.class, Object.class, Object.class, int.class, Object.class);
     2.7 -    private static final MethodHandle CALL_CMP                = Bootstrap.createDynamicInvoker("dyn:call", int.class,
     2.8 +    private static final MethodHandle CALL_CMP                = Bootstrap.createDynamicInvoker("dyn:call", double.class,
     2.9              ScriptFunction.class, Object.class, Object.class, Object.class);
    2.10  
    2.11      private static final InvokeByName TO_LOCALE_STRING = new InvokeByName("toLocaleString", ScriptObject.class, String.class);
    2.12 @@ -793,11 +793,15 @@
    2.13      }
    2.14  
    2.15      private static ScriptFunction compareFunction(final Object comparefn) {
    2.16 -        try {
    2.17 -            return (ScriptFunction)comparefn;
    2.18 -        } catch (final ClassCastException e) {
    2.19 -            return null; //undefined or null
    2.20 +        if (comparefn == ScriptRuntime.UNDEFINED) {
    2.21 +            return null;
    2.22          }
    2.23 +
    2.24 +        if (! (comparefn instanceof ScriptFunction)) {
    2.25 +            throw typeError("not.a.function", ScriptRuntime.safeToString(comparefn));
    2.26 +        }
    2.27 +
    2.28 +        return (ScriptFunction)comparefn;
    2.29      }
    2.30  
    2.31      private static Object[] sort(final Object[] array, final Object comparefn) {
    2.32 @@ -819,7 +823,7 @@
    2.33  
    2.34                  if (cmp != null) {
    2.35                      try {
    2.36 -                        return (int)CALL_CMP.invokeExact(cmp, cmpThis, x, y);
    2.37 +                        return (int)Math.signum((double)CALL_CMP.invokeExact(cmp, cmpThis, x, y));
    2.38                      } catch (final RuntimeException | Error e) {
    2.39                          throw e;
    2.40                      } catch (final Throwable t) {
     3.1 --- a/src/jdk/nashorn/internal/runtime/Context.java	Tue Apr 16 15:00:54 2013 -0700
     3.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java	Wed Apr 17 21:50:54 2013 -0700
     3.3 @@ -56,6 +56,7 @@
     3.4  import jdk.nashorn.internal.parser.Parser;
     3.5  import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
     3.6  import jdk.nashorn.internal.runtime.options.Options;
     3.7 +import sun.reflect.CallerSensitive;
     3.8  import sun.reflect.Reflection;
     3.9  
    3.10  /**
    3.11 @@ -113,11 +114,12 @@
    3.12       * Get the current global scope
    3.13       * @return the current global scope
    3.14       */
    3.15 +    @CallerSensitive
    3.16      public static ScriptObject getGlobal() {
    3.17          final SecurityManager sm = System.getSecurityManager();
    3.18          if (sm != null) {
    3.19              // skip getCallerClass and getGlobal and get to the real caller
    3.20 -            Class<?> caller = Reflection.getCallerClass(2);
    3.21 +            Class<?> caller = Reflection.getCallerClass();
    3.22              ClassLoader callerLoader = caller.getClassLoader();
    3.23  
    3.24              // Allow this method only for nashorn's own classes, objects
     4.1 --- a/src/jdk/nashorn/internal/runtime/regexp/RegExpFactory.java	Tue Apr 16 15:00:54 2013 -0700
     4.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/RegExpFactory.java	Wed Apr 17 21:50:54 2013 -0700
     4.3 @@ -40,7 +40,7 @@
     4.4      private final static String JONI = "joni";
     4.5  
     4.6      static {
     4.7 -        final String impl = Options.getStringProperty("nashorn.regexp.impl", JDK);
     4.8 +        final String impl = Options.getStringProperty("nashorn.regexp.impl", JONI);
     4.9          switch (impl) {
    4.10              case JONI:
    4.11                  instance = new JoniRegExp.Factory();
     5.1 --- a/src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java	Tue Apr 16 15:00:54 2013 -0700
     5.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java	Wed Apr 17 21:50:54 2013 -0700
     5.3 @@ -47,9 +47,6 @@
     5.4       */
     5.5      private final StringBuilder sb;
     5.6  
     5.7 -    /** Is this the special case of a regexp that never matches anything */
     5.8 -    private boolean neverMatches;
     5.9 -
    5.10      /** Expected token table */
    5.11      private final Map<Character, Integer> expected = new HashMap<>();
    5.12  
    5.13 @@ -99,24 +96,17 @@
    5.14      }
    5.15  
    5.16      private void processForwardReferences() {
    5.17 -        if (neverMatches()) {
    5.18 -            return;
    5.19 -        }
    5.20  
    5.21          Iterator<Integer> iterator = forwardReferences.descendingIterator();
    5.22          while (iterator.hasNext()) {
    5.23              final int pos = iterator.next();
    5.24              final int num = iterator.next();
    5.25              if (num > caps.size()) {
    5.26 -                // Non-existing reference should never match, if smaller than 8 convert to octal escape
    5.27 -                // to be compatible with other engines.
    5.28 -                if (num < 8) {
    5.29 -                    String escape = "\\x0" + num;
    5.30 -                    sb.insert(pos, escape);
    5.31 -                } else {
    5.32 -                    neverMatches = true;
    5.33 -                    break;
    5.34 -                }
    5.35 +                // Non-existing backreference. If the number begins with a valid octal convert it to
    5.36 +                // Unicode escape and append the rest to a literal character sequence.
    5.37 +                final StringBuilder buffer = new StringBuilder();
    5.38 +                octalOrLiteral(Integer.toString(num), buffer);
    5.39 +                sb.insert(pos, buffer);
    5.40              }
    5.41          }
    5.42  
    5.43 @@ -140,9 +130,6 @@
    5.44          }
    5.45  
    5.46          scanner.processForwardReferences();
    5.47 -        if (scanner.neverMatches()) {
    5.48 -            return null; // never matches
    5.49 -        }
    5.50  
    5.51          // Throw syntax error unless we parsed the entire JavaScript regexp without syntax errors
    5.52          if (scanner.position != string.length()) {
    5.53 @@ -151,16 +138,6 @@
    5.54          }
    5.55  
    5.56          return scanner;
    5.57 -     }
    5.58 -
    5.59 -    /**
    5.60 -     * Does this regexp ever match anything? Use of e.g. [], which is legal in JavaScript,
    5.61 -     * is an example where we never match
    5.62 -     *
    5.63 -     * @return boolean
    5.64 -     */
    5.65 -    private boolean neverMatches() {
    5.66 -        return neverMatches;
    5.67      }
    5.68  
    5.69      final StringBuilder getStringBuilder() {
    5.70 @@ -282,23 +259,16 @@
    5.71          }
    5.72  
    5.73          if (atom()) {
    5.74 -            boolean emptyCharacterClass = false;
    5.75 +            // Check for character classes that never or always match
    5.76              if (sb.toString().endsWith("[]")) {
    5.77 -                emptyCharacterClass = true;
    5.78 +                sb.setLength(sb.length() - 1);
    5.79 +                sb.append("^\\s\\S]");
    5.80              } else if (sb.toString().endsWith("[^]")) {
    5.81                  sb.setLength(sb.length() - 2);
    5.82                  sb.append("\\s\\S]");
    5.83              }
    5.84  
    5.85 -            boolean quantifier = quantifier();
    5.86 -
    5.87 -            if (emptyCharacterClass) {
    5.88 -                if (!quantifier) {
    5.89 -                    neverMatches = true; //never matches ever.
    5.90 -                }
    5.91 -                // Note: we could check if quantifier has min zero to mark empty character class as dead.
    5.92 -            }
    5.93 -
    5.94 +            quantifier();
    5.95              return true;
    5.96          }
    5.97  
    5.98 @@ -626,13 +596,14 @@
    5.99       *      ABCDEFGHIJKLMNOPQRSTUVWXYZ
   5.100       */
   5.101      private boolean controlLetter() {
   5.102 -        final char c = Character.toUpperCase(ch0);
   5.103 -        if (c >= 'A' && c <= 'Z') {
   5.104 +        // To match other engines we also accept '0'..'9' and '_' as control letters inside a character class.
   5.105 +        if ((ch0 >= 'A' && ch0 <= 'Z') || (ch0 >= 'a' && ch0 <= 'z')
   5.106 +                || (inCharClass && (isDecimalDigit(ch0) || ch0 == '_'))) {
   5.107              // for some reason java regexps don't like control characters on the
   5.108              // form "\\ca".match([string with ascii 1 at char0]). Translating
   5.109              // them to unicode does it though.
   5.110              sb.setLength(sb.length() - 1);
   5.111 -            unicode(c - 'A' + 1);
   5.112 +            unicode(ch0 % 32, sb);
   5.113              skip(1);
   5.114              return true;
   5.115          }
   5.116 @@ -651,14 +622,7 @@
   5.117          }
   5.118          // ES 5.1 A.7 requires "not IdentifierPart" here but all major engines accept any character here.
   5.119          if (ch0 == 'c') {
   5.120 -            // Ignore invalid control letter escape if within a character class
   5.121 -            if (inCharClass && ch1 != ']') {
   5.122 -                sb.setLength(sb.length() - 1);
   5.123 -                skip(2);
   5.124 -                return true;
   5.125 -            } else {
   5.126 -                sb.append('\\'); // Treat invalid \c control sequence as \\c
   5.127 -            }
   5.128 +            sb.append('\\'); // Treat invalid \c control sequence as \\c
   5.129          } else if (NON_IDENT_ESCAPES.indexOf(ch0) == -1) {
   5.130              sb.setLength(sb.length() - 1);
   5.131          }
   5.132 @@ -673,7 +637,7 @@
   5.133          final int startIn  = position;
   5.134          final int startOut = sb.length();
   5.135  
   5.136 -        if (ch0 == '0' && !isDecimalDigit(ch1)) {
   5.137 +        if (ch0 == '0' && !isOctalDigit(ch1)) {
   5.138              skip(1);
   5.139              //  DecimalEscape :: 0. If i is zero, return the EscapeValue consisting of a <NUL> character (Unicodevalue0000);
   5.140              sb.append("\u0000");
   5.141 @@ -681,50 +645,56 @@
   5.142          }
   5.143  
   5.144          if (isDecimalDigit(ch0)) {
   5.145 -            final int num = ch0 - '0';
   5.146  
   5.147 -            // Single digit escape, treat as backreference.
   5.148 -            if (!isDecimalDigit(ch1)) {
   5.149 -                if (num <= caps.size() && caps.get(num - 1).getNegativeLookaheadLevel() > 0) {
   5.150 -                    //  Captures that live inside a negative lookahead are dead after the
   5.151 -                    //  lookahead and will be undefined if referenced from outside.
   5.152 -                    if (caps.get(num - 1).getNegativeLookaheadLevel() > negativeLookaheadLevel) {
   5.153 -                        sb.setLength(sb.length() - 1);
   5.154 -                    } else {
   5.155 -                        sb.append(ch0);
   5.156 +            if (ch0 == '0') {
   5.157 +                // We know this is an octal escape.
   5.158 +                if (inCharClass) {
   5.159 +                    // Convert octal escape to unicode escape if inside character class.
   5.160 +                    int octalValue = 0;
   5.161 +                    while (isOctalDigit(ch0)) {
   5.162 +                        octalValue = octalValue * 8 + ch0 - '0';
   5.163 +                        skip(1);
   5.164                      }
   5.165 -                    skip(1);
   5.166 -                    return true;
   5.167 -                } else if (num > caps.size()) {
   5.168 -                    // Forward reference to a capture group. Forward references are always undefined so we
   5.169 -                    // can omit it from the output buffer. Additionally, if the capture group does not exist
   5.170 -                    // the whole regexp becomes invalid, so register the reference for later processing.
   5.171 -                    sb.setLength(sb.length() - 1);
   5.172 -                    forwardReferences.add(num);
   5.173 -                    forwardReferences.add(sb.length());
   5.174 -                    skip(1);
   5.175 -                    return true;
   5.176 +
   5.177 +                    unicode(octalValue, sb);
   5.178 +
   5.179 +                } else {
   5.180 +                    // Copy decimal escape as-is
   5.181 +                    decimalDigits();
   5.182                  }
   5.183 -            }
   5.184 -
   5.185 -            if (inCharClass) {
   5.186 -                // Convert octal escape to unicode escape if inside character class.
   5.187 -                StringBuilder digit = new StringBuilder(4);
   5.188 +            } else {
   5.189 +                // This should be a backreference, but could also be an octal escape or even a literal string.
   5.190 +                int decimalValue = 0;
   5.191                  while (isDecimalDigit(ch0)) {
   5.192 -                    digit.append(ch0);
   5.193 +                    decimalValue = decimalValue * 10 + ch0 - '0';
   5.194                      skip(1);
   5.195                  }
   5.196  
   5.197 -                int value = Integer.parseInt(digit.toString(), 8); //throws exception that leads to SyntaxError if not octal
   5.198 -                if (value > 0xff) {
   5.199 -                    throw new NumberFormatException(digit.toString());
   5.200 +                if (inCharClass) {
   5.201 +                    // No backreferences in character classes. Encode as unicode escape or literal char sequence
   5.202 +                    sb.setLength(sb.length() - 1);
   5.203 +                    octalOrLiteral(Integer.toString(decimalValue), sb);
   5.204 +
   5.205 +                } else if (decimalValue <= caps.size() && caps.get(decimalValue - 1).getNegativeLookaheadLevel() > 0) {
   5.206 +                    //  Captures that live inside a negative lookahead are dead after the
   5.207 +                    //  lookahead and will be undefined if referenced from outside.
   5.208 +                    if (caps.get(decimalValue - 1).getNegativeLookaheadLevel() > negativeLookaheadLevel) {
   5.209 +                        sb.setLength(sb.length() - 1);
   5.210 +                    } else {
   5.211 +                        sb.append(decimalValue);
   5.212 +                    }
   5.213 +                } else if (decimalValue > caps.size()) {
   5.214 +                    // Forward reference to a capture group. Forward references are always undefined so we can omit
   5.215 +                    // it from the output buffer. However, if the target capture does not exist, we need to rewrite
   5.216 +                    // the reference as hex escape or literal string, so register the reference for later processing.
   5.217 +                    sb.setLength(sb.length() - 1);
   5.218 +                    forwardReferences.add(decimalValue);
   5.219 +                    forwardReferences.add(sb.length());
   5.220 +                } else {
   5.221 +                    // Append as backreference
   5.222 +                    sb.append(decimalValue);
   5.223                  }
   5.224  
   5.225 -                unicode(value);
   5.226 -
   5.227 -            } else {
   5.228 -                // Copy decimal escape as-is
   5.229 -                decimalDigits();
   5.230              }
   5.231              return true;
   5.232          }
   5.233 @@ -904,7 +874,6 @@
   5.234          switch (ch0) {
   5.235          case ']':
   5.236          case '-':
   5.237 -        case '\0':
   5.238              return false;
   5.239  
   5.240          case '[':
   5.241 @@ -965,13 +934,41 @@
   5.242          return true;
   5.243      }
   5.244  
   5.245 -    private void unicode(final int value) {
   5.246 +    private void unicode(final int value, final StringBuilder buffer) {
   5.247          final String hex = Integer.toHexString(value);
   5.248 -        sb.append('u');
   5.249 +        buffer.append('u');
   5.250          for (int i = 0; i < 4 - hex.length(); i++) {
   5.251 -            sb.append('0');
   5.252 +            buffer.append('0');
   5.253          }
   5.254 -        sb.append(hex);
   5.255 +        buffer.append(hex);
   5.256 +    }
   5.257 +
   5.258 +    // Convert what would have been a backreference into a unicode escape, or a number literal, or both.
   5.259 +    private void octalOrLiteral(final String numberLiteral, final StringBuilder buffer) {
   5.260 +        final int length = numberLiteral.length();
   5.261 +        int octalValue = 0;
   5.262 +        int pos = 0;
   5.263 +        // Maximum value for octal escape is 0377 (255) so we stop the loop at 32
   5.264 +        while (pos < length && octalValue < 0x20) {
   5.265 +            final char ch = numberLiteral.charAt(pos);
   5.266 +            if (isOctalDigit(ch)) {
   5.267 +                octalValue = octalValue * 8 + ch - '0';
   5.268 +            } else {
   5.269 +                break;
   5.270 +            }
   5.271 +            pos++;
   5.272 +        }
   5.273 +        if (octalValue > 0) {
   5.274 +            buffer.append('\\');
   5.275 +            unicode(octalValue, buffer);
   5.276 +            buffer.append(numberLiteral.substring(pos));
   5.277 +        } else {
   5.278 +            buffer.append(numberLiteral);
   5.279 +        }
   5.280 +    }
   5.281 +
   5.282 +    private static boolean isOctalDigit(final char ch) {
   5.283 +        return ch >= '0' && ch <= '7';
   5.284      }
   5.285  
   5.286      private static boolean isDecimalDigit(final char ch) {
     6.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java	Tue Apr 16 15:00:54 2013 -0700
     6.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Analyser.java	Wed Apr 17 21:50:54 2013 -0700
     6.3 @@ -156,9 +156,6 @@
     6.4  
     6.5          env.memNodes = null;
     6.6  
     6.7 -        new ArrayCompiler(this).compile();
     6.8 -        //new AsmCompiler(this).compile();
     6.9 -
    6.10          if (regex.numRepeat != 0 || regex.btMemEnd != 0) {
    6.11              regex.stackPopLevel = StackPopLevel.ALL;
    6.12          } else {
     7.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java	Tue Apr 16 15:00:54 2013 -0700
     7.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java	Wed Apr 17 21:50:54 2013 -0700
     7.3 @@ -55,8 +55,9 @@
     7.4      int[]repeatRangeLo;
     7.5      int[]repeatRangeHi;
     7.6  
     7.7 -    public WarnCallback warnings;
     7.8 -    public MatcherFactory factory;
     7.9 +    WarnCallback warnings;
    7.10 +    MatcherFactory factory;
    7.11 +    private Analyser analyser;
    7.12  
    7.13      int options;
    7.14      int userOptions;
    7.15 @@ -140,19 +141,33 @@
    7.16          this.caseFoldFlag = caseFoldFlag;
    7.17          this.warnings = warnings;
    7.18  
    7.19 -        new Analyser(new ScanEnvironment(this, syntax), chars, p, end).compile();
    7.20 +        this.analyser = new Analyser(new ScanEnvironment(this, syntax), chars, p, end);
    7.21 +        this.analyser.compile();
    7.22  
    7.23          this.warnings = null;
    7.24      }
    7.25  
    7.26 +    public void compile() {
    7.27 +        if (factory == null && analyser != null) {
    7.28 +            Compiler compiler = new ArrayCompiler(analyser);
    7.29 +            analyser = null; // only do this once
    7.30 +            compiler.compile();
    7.31 +        }
    7.32 +    }
    7.33 +
    7.34      public Matcher matcher(char[] chars) {
    7.35          return matcher(chars, 0, chars.length);
    7.36      }
    7.37  
    7.38      public Matcher matcher(char[] chars, int p, int end) {
    7.39 +        compile();
    7.40          return factory.create(this, chars, p, end);
    7.41      }
    7.42  
    7.43 +    public WarnCallback getWarnings() {
    7.44 +        return warnings;
    7.45 +    }
    7.46 +
    7.47      public int numberOfCaptures() {
    7.48          return numMem;
    7.49      }
     8.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java	Tue Apr 16 15:00:54 2013 -0700
     8.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/ast/QuantifierNode.java	Wed Apr 17 21:50:54 2013 -0700
     8.3 @@ -231,12 +231,12 @@
     8.4                          break;
     8.5  
     8.6                      case DEL:
     8.7 -                        env.reg.warnings.warn(new String(chars, p, end) +
     8.8 +                        env.reg.getWarnings().warn(new String(chars, p, end) +
     8.9                                  " redundant nested repeat operator");
    8.10                          break;
    8.11  
    8.12                      default:
    8.13 -                        env.reg.warnings.warn(new String(chars, p, end) +
    8.14 +                        env.reg.getWarnings().warn(new String(chars, p, end) +
    8.15                                  " nested repeat operator " + Reduce.PopularQStr[targetQNum] +
    8.16                                  " and " + Reduce.PopularQStr[nestQNum] + " was replaced with '" +
    8.17                                  Reduce.ReduceQStr[Reduce.REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/script/basic/JDK-8011714.js	Wed Apr 17 21:50:54 2013 -0700
     9.3 @@ -0,0 +1,68 @@
     9.4 +/*
     9.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/**
    9.28 + * JDK-8011714: Regexp decimal escape handling still not correct
    9.29 + *
    9.30 + * @test
    9.31 + * @run
    9.32 + */
    9.33 +
    9.34 +// \0 should be interpreted as <NUL> character here
    9.35 +print(/\08/.test("\x008"));
    9.36 +print(/[\08]/.test("8"));
    9.37 +print(/[\08]/.test("\x00"));
    9.38 +
    9.39 +// Can't be converted to octal thus encoded as literal char sequence
    9.40 +print(/\8/.exec("\\8"));
    9.41 +print(/[\8]/.exec("\\"));
    9.42 +print(/[\8]/.exec("8"));
    9.43 +
    9.44 +// 0471 is too high for an octal escape so it is \047 outside a character class
    9.45 +// and \\471 inside a character class
    9.46 +print(/\471/.exec("\x271"));
    9.47 +print(/[\471]/.exec("1"));
    9.48 +print(/[\471]/.exec("\x27"));
    9.49 +
    9.50 +// 0366 is a valid octal escape (246)
    9.51 +print(/\366/.test("\xf6"));
    9.52 +print(/[\366]/.test("\xf6"));
    9.53 +print(/[\366]/.test("\xf6"));
    9.54 +
    9.55 +// more tests for conversion of invalid backreferences to octal escapes or literals
    9.56 +print(/(a)(b)(c)(d)\4/.exec("abcdd"));
    9.57 +print(/(a)(b)(c)(d)\4x/.exec("abcddx"));
    9.58 +print(/(a)(b)(c)(d)\47/.exec("abcdd7"));
    9.59 +print(/(a)(b)(c)(d)\47/.exec("abcd\x27"));
    9.60 +print(/(a)(b)(c)(d)\47xyz/.exec("abcd\x27xyz"));
    9.61 +print(/(a)(b)(c)(d)[\47]/.exec("abcd\x27"));
    9.62 +print(/(a)(b)(c)(d)[\47]xyz/.exec("abcd\x27xyz"));
    9.63 +print(/(a)(b)(c)(d)\48/.exec("abcd\x048"));
    9.64 +print(/(a)(b)(c)(d)\48xyz/.exec("abcd\x048xyz"));
    9.65 +print(/(a)(b)(c)(d)[\48]/.exec("abcd\x04"));
    9.66 +print(/(a)(b)(c)(d)[\48]xyz/.exec("abcd\x04xyz"));
    9.67 +print(/(a)(b)(c)(d)\84/.exec("abcd84"));
    9.68 +print(/(a)(b)(c)(d)\84xyz/.exec("abcd84xyz"));
    9.69 +print(/(a)(b)(c)(d)[\84]/.exec("abcd8"));
    9.70 +print(/(a)(b)(c)(d)[\84]xyz/.exec("abcd8xyz"));
    9.71 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/script/basic/JDK-8011714.js.EXPECTED	Wed Apr 17 21:50:54 2013 -0700
    10.3 @@ -0,0 +1,27 @@
    10.4 +true
    10.5 +true
    10.6 +true
    10.7 +8
    10.8 +null
    10.9 +8
   10.10 +'1
   10.11 +1
   10.12 +'
   10.13 +true
   10.14 +true
   10.15 +true
   10.16 +abcdd,a,b,c,d
   10.17 +abcddx,a,b,c,d
   10.18 +null
   10.19 +abcd',a,b,c,d
   10.20 +abcd'xyz,a,b,c,d
   10.21 +abcd',a,b,c,d
   10.22 +abcd'xyz,a,b,c,d
   10.23 +abcd8,a,b,c,d
   10.24 +abcd8xyz,a,b,c,d
   10.25 +abcd,a,b,c,d
   10.26 +abcdxyz,a,b,c,d
   10.27 +abcd84,a,b,c,d
   10.28 +abcd84xyz,a,b,c,d
   10.29 +abcd8,a,b,c,d
   10.30 +abcd8xyz,a,b,c,d
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/script/basic/JDK-8011749.js	Wed Apr 17 21:50:54 2013 -0700
    11.3 @@ -0,0 +1,38 @@
    11.4 +/*
    11.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.23 + * or visit www.oracle.com if you need additional information or have any
   11.24 + * questions.
   11.25 + */
   11.26 +
   11.27 +/**
   11.28 + * JDK-8011749: Bugs with empty character class handling
   11.29 + *
   11.30 + * @test
   11.31 + * @run
   11.32 + */
   11.33 +
   11.34 +// empty class in alternative
   11.35 +print(/[]|[^]/.exec("a"));
   11.36 +print(/[]|[]/.test("a"));
   11.37 +print(/[]|[]|[a]/.exec("a"));
   11.38 +
   11.39 +// empty class in negative lookahead
   11.40 +print(/(?![])/.test(""));
   11.41 +print(/(?![])./.exec("a"));
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/script/basic/JDK-8011749.js.EXPECTED	Wed Apr 17 21:50:54 2013 -0700
    12.3 @@ -0,0 +1,5 @@
    12.4 +a
    12.5 +false
    12.6 +a
    12.7 +true
    12.8 +a
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/script/basic/JDK-8011756.js	Wed Apr 17 21:50:54 2013 -0700
    13.3 @@ -0,0 +1,59 @@
    13.4 +/*
    13.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + * 
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + * 
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + * 
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + * 
   13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.23 + * or visit www.oracle.com if you need additional information or have any
   13.24 + * questions.
   13.25 + */
   13.26 +
   13.27 +/**
   13.28 + * JDK-8011756: Wrong characters supported in RegExp \c escape
   13.29 + *
   13.30 + * @test
   13.31 + * @run
   13.32 + */
   13.33 +
   13.34 +
   13.35 +// Invalid control letters should be escaped:
   13.36 +print(/\cı/.test("\x09"));
   13.37 +print(/\cı/.test("\\cı"));
   13.38 +
   13.39 +print(/\cſ/.test("\x13"));
   13.40 +print(/\cſ/.test("\\cſ"));
   13.41 +
   13.42 +print(/[\cſ]/.test("\x13"));
   13.43 +print(/[\cſ]/.test("\\"));
   13.44 +print(/[\cſ]/.test("c"));
   13.45 +print(/[\cſ]/.test("ſ"));
   13.46 +
   13.47 +print(/[\c#]/.test("\\"));
   13.48 +print(/[\c#]/.test("c"));
   13.49 +print(/[\c#]/.test("#"));
   13.50 +
   13.51 +// The characters that are supported by other engines are '0'-'9', '_':
   13.52 +print(/[\c0]/.test("\x10"));
   13.53 +print(/[\c1]/.test("\x11"));
   13.54 +print(/[\c2]/.test("\x12"));
   13.55 +print(/[\c3]/.test("\x13"));
   13.56 +print(/[\c4]/.test("\x14"));
   13.57 +print(/[\c5]/.test("\x15"));
   13.58 +print(/[\c6]/.test("\x16"));
   13.59 +print(/[\c7]/.test("\x17"));
   13.60 +print(/[\c8]/.test("\x18"));
   13.61 +print(/[\c9]/.test("\x19"));
   13.62 +print(/[\c_]/.test("\x1F"));
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/script/basic/JDK-8011756.js.EXPECTED	Wed Apr 17 21:50:54 2013 -0700
    14.3 @@ -0,0 +1,22 @@
    14.4 +false
    14.5 +true
    14.6 +false
    14.7 +true
    14.8 +false
    14.9 +true
   14.10 +true
   14.11 +true
   14.12 +true
   14.13 +true
   14.14 +true
   14.15 +true
   14.16 +true
   14.17 +true
   14.18 +true
   14.19 +true
   14.20 +true
   14.21 +true
   14.22 +true
   14.23 +true
   14.24 +true
   14.25 +true
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/script/basic/JDK-8011960.js	Wed Apr 17 21:50:54 2013 -0700
    15.3 @@ -0,0 +1,53 @@
    15.4 +/*
    15.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 + * 
    15.8 + * This code is free software; you can redistribute it and/or modify it
    15.9 + * under the terms of the GNU General Public License version 2 only, as
   15.10 + * published by the Free Software Foundation.
   15.11 + * 
   15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.15 + * version 2 for more details (a copy is included in the LICENSE file that
   15.16 + * accompanied this code).
   15.17 + * 
   15.18 + * You should have received a copy of the GNU General Public License version
   15.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.21 + * 
   15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   15.23 + * or visit www.oracle.com if you need additional information or have any
   15.24 + * questions.
   15.25 + */
   15.26 +
   15.27 +/**
   15.28 + * JDK-8011960: [2,1].sort(null) should throw TypeError
   15.29 + *
   15.30 + * @test
   15.31 + * @run
   15.32 + */
   15.33 +
   15.34 +function check(func) {
   15.35 +    try {
   15.36 +        [2,1].sort(func);
   15.37 +        fail("should have thrown TypeError for :" + func);
   15.38 +    } catch (e) {
   15.39 +        if (! (e instanceof TypeError)) {
   15.40 +            fail("TypeError not thrown for sort comparefn: " + func);
   15.41 +        }
   15.42 +    }
   15.43 +}
   15.44 +
   15.45 +// should not result in TypeError for undefined
   15.46 +[1, 2].sort(undefined);
   15.47 +
   15.48 +// TypeError for null
   15.49 +check(null);
   15.50 +
   15.51 +// should result in TypeError other non-callable params
   15.52 +check(32);
   15.53 +check("foo");
   15.54 +check(false);
   15.55 +check({});
   15.56 +check([]);
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/script/basic/JDK-8011974.js	Wed Apr 17 21:50:54 2013 -0700
    16.3 @@ -0,0 +1,39 @@
    16.4 +/*
    16.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + * 
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.
   16.11 + * 
   16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.15 + * version 2 for more details (a copy is included in the LICENSE file that
   16.16 + * accompanied this code).
   16.17 + * 
   16.18 + * You should have received a copy of the GNU General Public License version
   16.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.21 + * 
   16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.23 + * or visit www.oracle.com if you need additional information or have any
   16.24 + * questions.
   16.25 + */
   16.26 +
   16.27 +/**
   16.28 + * JDK-8011974: Comparator function returning negative and positive Infinity does not work as expected with Array.prototype.sort
   16.29 + *
   16.30 + * @test
   16.31 + * @run
   16.32 + */
   16.33 +
   16.34 +function compare(x, y) {
   16.35 +    return x < y? -Infinity : (x > y? Infinity: 0)
   16.36 +}
   16.37 +
   16.38 +var sorted =  [5, 4, 3, 2, 1].sort(compare);
   16.39 +
   16.40 +if (sorted + '' != "1,2,3,4,5") {
   16.41 +    fail("Array.prototype.sort does not work when compare returns +/-Infinity");
   16.42 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/script/basic/JDK-8011980.js	Wed Apr 17 21:50:54 2013 -0700
    17.3 @@ -0,0 +1,34 @@
    17.4 +/*
    17.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.
   17.11 + *
   17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.15 + * version 2 for more details (a copy is included in the LICENSE file that
   17.16 + * accompanied this code).
   17.17 + *
   17.18 + * You should have received a copy of the GNU General Public License version
   17.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.21 + *
   17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.23 + * or visit www.oracle.com if you need additional information or have any
   17.24 + * questions.
   17.25 + */
   17.26 +
   17.27 +/**
   17.28 + * JDK-8011980: Allow NUL character in character class
   17.29 + *
   17.30 + * @test
   17.31 + * @run
   17.32 + */
   17.33 +
   17.34 +print(RegExp("\0").test("\0"));
   17.35 +print(RegExp("[\0]").test("\0"));
   17.36 +print(RegExp("[\x00]").test("\0"));
   17.37 +print(RegExp("[\u0000]").test("\0"));
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/script/basic/JDK-8011980.js.EXPECTED	Wed Apr 17 21:50:54 2013 -0700
    18.3 @@ -0,0 +1,4 @@
    18.4 +true
    18.5 +true
    18.6 +true
    18.7 +true

mercurial