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

Print this page




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.objects;
  27 
  28 import static jdk.nashorn.internal.lookup.Lookup.MH;
  29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  30 import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt;
  31 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
  32 import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow;
  33 
  34 import java.lang.invoke.MethodHandle;
  35 import java.lang.invoke.MethodHandles;
  36 import java.text.Collator;
  37 import java.util.ArrayList;
  38 import java.util.Arrays;
  39 import java.util.LinkedList;
  40 import java.util.List;

  41 import jdk.internal.dynalink.CallSiteDescriptor;
  42 import jdk.internal.dynalink.linker.GuardedInvocation;
  43 import jdk.internal.dynalink.linker.LinkRequest;
  44 import jdk.nashorn.internal.lookup.MethodHandleFactory;
  45 import jdk.nashorn.internal.objects.annotations.Attribute;
  46 import jdk.nashorn.internal.objects.annotations.Constructor;
  47 import jdk.nashorn.internal.objects.annotations.Function;
  48 import jdk.nashorn.internal.objects.annotations.Getter;
  49 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  50 import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
  51 import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
  52 import jdk.nashorn.internal.objects.annotations.Where;
  53 import jdk.nashorn.internal.runtime.ConsString;
  54 import jdk.nashorn.internal.runtime.JSType;
  55 import jdk.nashorn.internal.runtime.ScriptFunction;
  56 import jdk.nashorn.internal.runtime.ScriptObject;
  57 import jdk.nashorn.internal.runtime.ScriptRuntime;
  58 import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
  59 import jdk.nashorn.internal.runtime.linker.NashornGuards;
  60 import jdk.nashorn.internal.runtime.linker.PrimitiveLookup;


 980     /**
 981      * ECMA 15.5.4.15 String.prototype.substring (start, end) specialized for double start and end parameters
 982      *
 983      * @param self  self reference
 984      * @param start start position of substring
 985      * @param end   end position of substring
 986      * @return substring given start and end indexes
 987      */
 988     @SpecializedFunction
 989     public static String substring(final Object self, final double start, final double end) {
 990         return substring(self, (int)start, (int)end);
 991     }
 992 
 993     /**
 994      * ECMA 15.5.4.16 String.prototype.toLowerCase ( )
 995      * @param self self reference
 996      * @return string to lower case
 997      */
 998     @Function(attributes = Attribute.NOT_ENUMERABLE)
 999     public static Object toLowerCase(final Object self) {
1000         return checkObjectToString(self).toLowerCase();
1001     }
1002 
1003     /**
1004      * ECMA 15.5.4.17 String.prototype.toLocaleLowerCase ( )
1005      * @param self self reference
1006      * @return string to locale sensitive lower case
1007      */
1008     @Function(attributes = Attribute.NOT_ENUMERABLE)
1009     public static Object toLocaleLowerCase(final Object self) {
1010         return checkObjectToString(self).toLowerCase(Global.getEnv()._locale);
1011     }
1012 
1013     /**
1014      * ECMA 15.5.4.18 String.prototype.toUpperCase ( )
1015      * @param self self reference
1016      * @return string to upper case
1017      */
1018     @Function(attributes = Attribute.NOT_ENUMERABLE)
1019     public static Object toUpperCase(final Object self) {
1020         return checkObjectToString(self).toUpperCase();
1021     }
1022 
1023     /**
1024      * ECMA 15.5.4.19 String.prototype.toLocaleUpperCase ( )
1025      * @param self self reference
1026      * @return string to locale sensitive upper case
1027      */
1028     @Function(attributes = Attribute.NOT_ENUMERABLE)
1029     public static Object toLocaleUpperCase(final Object self) {
1030         return checkObjectToString(self).toUpperCase(Global.getEnv()._locale);
1031     }
1032 
1033     /**
1034      * ECMA 15.5.4.20 String.prototype.trim ( )
1035      * @param self self reference
1036      * @return string trimmed from whitespace
1037      */
1038     @Function(attributes = Attribute.NOT_ENUMERABLE)
1039     public static Object trim(final Object self) {
1040 




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.objects;
  27 
  28 import static jdk.nashorn.internal.lookup.Lookup.MH;
  29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
  30 import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt;
  31 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
  32 import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow;
  33 
  34 import java.lang.invoke.MethodHandle;
  35 import java.lang.invoke.MethodHandles;
  36 import java.text.Collator;
  37 import java.util.ArrayList;
  38 import java.util.Arrays;
  39 import java.util.LinkedList;
  40 import java.util.List;
  41 import java.util.Locale;
  42 import jdk.internal.dynalink.CallSiteDescriptor;
  43 import jdk.internal.dynalink.linker.GuardedInvocation;
  44 import jdk.internal.dynalink.linker.LinkRequest;
  45 import jdk.nashorn.internal.lookup.MethodHandleFactory;
  46 import jdk.nashorn.internal.objects.annotations.Attribute;
  47 import jdk.nashorn.internal.objects.annotations.Constructor;
  48 import jdk.nashorn.internal.objects.annotations.Function;
  49 import jdk.nashorn.internal.objects.annotations.Getter;
  50 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  51 import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
  52 import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
  53 import jdk.nashorn.internal.objects.annotations.Where;
  54 import jdk.nashorn.internal.runtime.ConsString;
  55 import jdk.nashorn.internal.runtime.JSType;
  56 import jdk.nashorn.internal.runtime.ScriptFunction;
  57 import jdk.nashorn.internal.runtime.ScriptObject;
  58 import jdk.nashorn.internal.runtime.ScriptRuntime;
  59 import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
  60 import jdk.nashorn.internal.runtime.linker.NashornGuards;
  61 import jdk.nashorn.internal.runtime.linker.PrimitiveLookup;


 981     /**
 982      * ECMA 15.5.4.15 String.prototype.substring (start, end) specialized for double start and end parameters
 983      *
 984      * @param self  self reference
 985      * @param start start position of substring
 986      * @param end   end position of substring
 987      * @return substring given start and end indexes
 988      */
 989     @SpecializedFunction
 990     public static String substring(final Object self, final double start, final double end) {
 991         return substring(self, (int)start, (int)end);
 992     }
 993 
 994     /**
 995      * ECMA 15.5.4.16 String.prototype.toLowerCase ( )
 996      * @param self self reference
 997      * @return string to lower case
 998      */
 999     @Function(attributes = Attribute.NOT_ENUMERABLE)
1000     public static Object toLowerCase(final Object self) {
1001         return checkObjectToString(self).toLowerCase(Locale.ROOT);
1002     }
1003 
1004     /**
1005      * ECMA 15.5.4.17 String.prototype.toLocaleLowerCase ( )
1006      * @param self self reference
1007      * @return string to locale sensitive lower case
1008      */
1009     @Function(attributes = Attribute.NOT_ENUMERABLE)
1010     public static Object toLocaleLowerCase(final Object self) {
1011         return checkObjectToString(self).toLowerCase(Global.getEnv()._locale);
1012     }
1013 
1014     /**
1015      * ECMA 15.5.4.18 String.prototype.toUpperCase ( )
1016      * @param self self reference
1017      * @return string to upper case
1018      */
1019     @Function(attributes = Attribute.NOT_ENUMERABLE)
1020     public static Object toUpperCase(final Object self) {
1021         return checkObjectToString(self).toUpperCase(Locale.ROOT);
1022     }
1023 
1024     /**
1025      * ECMA 15.5.4.19 String.prototype.toLocaleUpperCase ( )
1026      * @param self self reference
1027      * @return string to locale sensitive upper case
1028      */
1029     @Function(attributes = Attribute.NOT_ENUMERABLE)
1030     public static Object toLocaleUpperCase(final Object self) {
1031         return checkObjectToString(self).toUpperCase(Global.getEnv()._locale);
1032     }
1033 
1034     /**
1035      * ECMA 15.5.4.20 String.prototype.trim ( )
1036      * @param self self reference
1037      * @return string trimmed from whitespace
1038      */
1039     @Function(attributes = Attribute.NOT_ENUMERABLE)
1040     public static Object trim(final Object self) {
1041