changeset 296:343fd0450802

8015352: "i".toUpperCase() => currently returns "?", but should be "I" (with Turkish locale) Reviewed-by: jlaskey, lagergren
author sundar
date Mon, 27 May 2013 20:41:34 +0530
parents 910fd2849c4c
children e6193dcfe36c
files src/jdk/nashorn/internal/objects/NativeString.java src/jdk/nashorn/internal/runtime/ScriptEnvironment.java src/jdk/nashorn/internal/runtime/options/OptionTemplate.java src/jdk/nashorn/internal/runtime/options/Options.java src/jdk/nashorn/internal/runtime/resources/Options.properties test/script/basic/JDK-8015352.js
diffstat 6 files changed, 72 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/objects/NativeString.java	Mon May 27 13:12:11 2013 +0200
+++ b/src/jdk/nashorn/internal/objects/NativeString.java	Mon May 27 20:41:34 2013 +0530
@@ -38,6 +38,7 @@
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.linker.GuardedInvocation;
 import jdk.internal.dynalink.linker.LinkRequest;
@@ -997,7 +998,7 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object toLowerCase(final Object self) {
-        return checkObjectToString(self).toLowerCase();
+        return checkObjectToString(self).toLowerCase(Locale.ROOT);
     }
 
     /**
@@ -1017,7 +1018,7 @@
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE)
     public static Object toUpperCase(final Object self) {
-        return checkObjectToString(self).toUpperCase();
+        return checkObjectToString(self).toUpperCase(Locale.ROOT);
     }
 
     /**
--- a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Mon May 27 13:12:11 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Mon May 27 20:41:34 2013 +0530
@@ -262,14 +262,19 @@
         }
         this._callsite_flags = callSiteFlags;
 
-        final Option<?> option = options.get("timezone");
-        if (option != null) {
-            this._timezone = (TimeZone)option.getValue();
+        final Option<?> timezoneOption = options.get("timezone");
+        if (timezoneOption != null) {
+            this._timezone = (TimeZone)timezoneOption.getValue();
         } else {
             this._timezone  = TimeZone.getDefault();
         }
 
-        this._locale = Locale.getDefault();
+        final Option<?> localeOption = options.get("locale");
+        if (localeOption != null) {
+            this._locale = (Locale)localeOption.getValue();
+        } else {
+            this._locale = Locale.getDefault();
+        }
     }
 
     /**
--- a/src/jdk/nashorn/internal/runtime/options/OptionTemplate.java	Mon May 27 13:12:11 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/options/OptionTemplate.java	Mon May 27 20:41:34 2013 +0530
@@ -152,6 +152,9 @@
         case "timezone":
             this.defaultValue = TimeZone.getDefault().getID();
             break;
+        case "locale":
+            this.defaultValue = Locale.getDefault().toLanguageTag();
+            break;
         default:
             break;
         }
--- a/src/jdk/nashorn/internal/runtime/options/Options.java	Mon May 27 13:12:11 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/options/Options.java	Mon May 27 20:41:34 2013 +0530
@@ -499,6 +499,8 @@
         case "timezone":
             // default value "TimeZone.getDefault()"
             return new Option<>(TimeZone.getTimeZone(value));
+        case "locale":
+            return new Option<>(Locale.forLanguageTag(value));
         case "keyvalues":
             return new KeyValueOption(value);
         case "log":
--- a/src/jdk/nashorn/internal/runtime/resources/Options.properties	Mon May 27 13:12:11 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties	Mon May 27 20:41:34 2013 +0530
@@ -332,6 +332,15 @@
     type=TimeZone                              \
 }
 
+nashorn.option.locale = {                    \
+    name="--locale",                         \
+    short_name="-l",                         \
+    is_undocumented=true,                    \
+    params="<locale>",                       \
+    desc="Set Locale for script execution.", \
+    type=Locale                              \
+}
+
 nashorn.option.trace.callsites = {                                              \
     name="--trace-callsites",                                                   \
     short_name="-tcs",                                                          \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8015352.js	Mon May 27 20:41:34 2013 +0530
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8015352: "i".toUpperCase() => currently returns "İ", but should be "I" (with Turkish locale)
+ *
+ * @test
+ * @option --locale=tr-TR
+ * @run
+ */
+
+if ("i".toUpperCase() != "I") {
+    fail("'i'.toUpperCase() is not 'I'");
+}
+
+if ("i".toUpperCase() == "i".toLocaleUpperCase()) {
+    fail("'i'.toUpperCase() == 'i'.toLocaleUpperCase()");
+}
+
+if ("I".toLowerCase() != "i") {
+    fail("'I'.toLowerCase() is not 'i'");
+}
+
+if ("I".toLowerCase() == "I".toLocaleLowerCase()) {
+    fail("'i'.toLowerCase() == 'i'.toLocaleLowerCase()");
+}