Mon, 27 May 2013 20:41:34 +0530
8015352: "i".toUpperCase() => currently returns "İ", but should be "I" (with Turkish locale)
Reviewed-by: jlaskey, lagergren
1.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java Mon May 27 13:12:11 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java Mon May 27 20:41:34 2013 +0530 1.3 @@ -38,6 +38,7 @@ 1.4 import java.util.Arrays; 1.5 import java.util.LinkedList; 1.6 import java.util.List; 1.7 +import java.util.Locale; 1.8 import jdk.internal.dynalink.CallSiteDescriptor; 1.9 import jdk.internal.dynalink.linker.GuardedInvocation; 1.10 import jdk.internal.dynalink.linker.LinkRequest; 1.11 @@ -997,7 +998,7 @@ 1.12 */ 1.13 @Function(attributes = Attribute.NOT_ENUMERABLE) 1.14 public static Object toLowerCase(final Object self) { 1.15 - return checkObjectToString(self).toLowerCase(); 1.16 + return checkObjectToString(self).toLowerCase(Locale.ROOT); 1.17 } 1.18 1.19 /** 1.20 @@ -1017,7 +1018,7 @@ 1.21 */ 1.22 @Function(attributes = Attribute.NOT_ENUMERABLE) 1.23 public static Object toUpperCase(final Object self) { 1.24 - return checkObjectToString(self).toUpperCase(); 1.25 + return checkObjectToString(self).toUpperCase(Locale.ROOT); 1.26 } 1.27 1.28 /**
2.1 --- a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java Mon May 27 13:12:11 2013 +0200 2.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java Mon May 27 20:41:34 2013 +0530 2.3 @@ -262,14 +262,19 @@ 2.4 } 2.5 this._callsite_flags = callSiteFlags; 2.6 2.7 - final Option<?> option = options.get("timezone"); 2.8 - if (option != null) { 2.9 - this._timezone = (TimeZone)option.getValue(); 2.10 + final Option<?> timezoneOption = options.get("timezone"); 2.11 + if (timezoneOption != null) { 2.12 + this._timezone = (TimeZone)timezoneOption.getValue(); 2.13 } else { 2.14 this._timezone = TimeZone.getDefault(); 2.15 } 2.16 2.17 - this._locale = Locale.getDefault(); 2.18 + final Option<?> localeOption = options.get("locale"); 2.19 + if (localeOption != null) { 2.20 + this._locale = (Locale)localeOption.getValue(); 2.21 + } else { 2.22 + this._locale = Locale.getDefault(); 2.23 + } 2.24 } 2.25 2.26 /**
3.1 --- a/src/jdk/nashorn/internal/runtime/options/OptionTemplate.java Mon May 27 13:12:11 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/runtime/options/OptionTemplate.java Mon May 27 20:41:34 2013 +0530 3.3 @@ -152,6 +152,9 @@ 3.4 case "timezone": 3.5 this.defaultValue = TimeZone.getDefault().getID(); 3.6 break; 3.7 + case "locale": 3.8 + this.defaultValue = Locale.getDefault().toLanguageTag(); 3.9 + break; 3.10 default: 3.11 break; 3.12 }
4.1 --- a/src/jdk/nashorn/internal/runtime/options/Options.java Mon May 27 13:12:11 2013 +0200 4.2 +++ b/src/jdk/nashorn/internal/runtime/options/Options.java Mon May 27 20:41:34 2013 +0530 4.3 @@ -499,6 +499,8 @@ 4.4 case "timezone": 4.5 // default value "TimeZone.getDefault()" 4.6 return new Option<>(TimeZone.getTimeZone(value)); 4.7 + case "locale": 4.8 + return new Option<>(Locale.forLanguageTag(value)); 4.9 case "keyvalues": 4.10 return new KeyValueOption(value); 4.11 case "log":
5.1 --- a/src/jdk/nashorn/internal/runtime/resources/Options.properties Mon May 27 13:12:11 2013 +0200 5.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties Mon May 27 20:41:34 2013 +0530 5.3 @@ -332,6 +332,15 @@ 5.4 type=TimeZone \ 5.5 } 5.6 5.7 +nashorn.option.locale = { \ 5.8 + name="--locale", \ 5.9 + short_name="-l", \ 5.10 + is_undocumented=true, \ 5.11 + params="<locale>", \ 5.12 + desc="Set Locale for script execution.", \ 5.13 + type=Locale \ 5.14 +} 5.15 + 5.16 nashorn.option.trace.callsites = { \ 5.17 name="--trace-callsites", \ 5.18 short_name="-tcs", \
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/script/basic/JDK-8015352.js Mon May 27 20:41:34 2013 +0530 6.3 @@ -0,0 +1,46 @@ 6.4 +/* 6.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/** 6.28 + * JDK-8015352: "i".toUpperCase() => currently returns "İ", but should be "I" (with Turkish locale) 6.29 + * 6.30 + * @test 6.31 + * @option --locale=tr-TR 6.32 + * @run 6.33 + */ 6.34 + 6.35 +if ("i".toUpperCase() != "I") { 6.36 + fail("'i'.toUpperCase() is not 'I'"); 6.37 +} 6.38 + 6.39 +if ("i".toUpperCase() == "i".toLocaleUpperCase()) { 6.40 + fail("'i'.toUpperCase() == 'i'.toLocaleUpperCase()"); 6.41 +} 6.42 + 6.43 +if ("I".toLowerCase() != "i") { 6.44 + fail("'I'.toLowerCase() is not 'i'"); 6.45 +} 6.46 + 6.47 +if ("I".toLowerCase() == "I".toLocaleLowerCase()) { 6.48 + fail("'i'.toLowerCase() == 'i'.toLocaleLowerCase()"); 6.49 +}