src/jdk/nashorn/internal/objects/NativeString.java

Print this page

        

@@ -35,11 +35,10 @@
 import java.lang.invoke.MethodHandles;
 import java.text.Collator;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.regex.Pattern;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
 import jdk.nashorn.internal.objects.annotations.Function;
 import jdk.nashorn.internal.objects.annotations.Getter;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;

@@ -604,11 +603,11 @@
 
         final NativeRegExp nativeRegExp;
         if (string instanceof NativeRegExp) {
             nativeRegExp = (NativeRegExp) string;
         } else {
-            nativeRegExp = new NativeRegExp(Pattern.compile(JSType.toString(string), Pattern.LITERAL));
+            nativeRegExp = NativeRegExp.flatRegExp(JSType.toString(string));
         }
 
         if (replacement instanceof ScriptFunction) {
             return nativeRegExp.replace(str, "", (ScriptFunction)replacement);
         }

@@ -693,11 +692,11 @@
             return ((NativeRegExp) separator).split(str, lim);
         }
 
         // when separator is a string, it has to be treated as a
         // literal search string to be used for splitting.
-        return new NativeRegExp(Pattern.compile(JSType.toString(separator), Pattern.LITERAL)).split(str, lim);
+        return NativeRegExp.flatRegExp(JSType.toString(separator)).split(str, lim);
     }
 
     /**
      * ECMA B.2.3 String.prototype.substr (start, length)
      *