Bug 1484420 - Move locale-related functions into js/public/LocaleSensitive.h that isn't #include'd in jsapi.h. r=anba
authorJeff Walden <jwalden@mit.edu>
Mon, 20 Aug 2018 17:11:32 -0500
changeset 487790 9f92f288b60876c75fddfddb2eba8ff685ed2b78
parent 487789 3c5aa35fa3d2674821a481ee46e67805b2e6b057
child 487791 4cd236eff0af42029e5ff209e46c9384aa2c9c3c
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanba
bugs1484420
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1484420 - Move locale-related functions into js/public/LocaleSensitive.h that isn't #include'd in jsapi.h. r=anba
dom/workers/RuntimeService.cpp
dom/workers/WorkerPrivate.cpp
js/public/LocaleSensitive.h
js/src/builtin/String.cpp
js/src/builtin/TestingFunctions.cpp
js/src/jsapi-tests/testDateToLocaleString.cpp
js/src/jsapi-tests/testIntlAvailableLocales.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsnum.cpp
js/src/jspubtd.h
js/src/moz.build
js/src/vm/Runtime.h
js/xpconnect/src/XPCLocale.cpp
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -24,16 +24,17 @@
 #include "nsIURI.h"
 #include "nsIXULRuntime.h"
 #include "nsPIDOMWindow.h"
 
 #include <algorithm>
 #include "mozilla/ipc/BackgroundChild.h"
 #include "GeckoProfiler.h"
 #include "jsfriendapi.h"
+#include "js/LocaleSensitive.h"
 #include "mozilla/AbstractThread.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/CycleCollectedJSContext.h"
 #include "mozilla/CycleCollectedJSRuntime.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WorkerPrivate.h"
 
+#include "js/LocaleSensitive.h"
 #include "js/MemoryMetrics.h"
 #include "MessageEventRunnable.h"
 #include "mozilla/ScopeExit.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/dom/BlobURLProtocolHandler.h"
 #include "mozilla/dom/ClientManager.h"
 #include "mozilla/dom/ClientSource.h"
 #include "mozilla/dom/ClientState.h"
new file mode 100644
--- /dev/null
+++ b/js/public/LocaleSensitive.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Functions and structures related to locale-sensitive behavior, including
+ * exposure of the default locale (used by operations like toLocaleString).
+ */
+
+#ifndef js_LocaleSensitive_h
+#define js_LocaleSensitive_h
+
+#include "jstypes.h" // JS_PUBLIC_API
+
+#include "js/RootingAPI.h" // JS::Handle, JS::MutableHandle
+#include "js/Utility.h" // JS::UniqueChars
+
+struct JSContext;
+struct JSRuntime;
+class JSString;
+
+namespace JS { union Value; }
+
+/**
+ * Set the default locale for the ECMAScript Internationalization API
+ * (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat, and others that will
+ * arise as time passes).  (Note that the Internationalization API encourages
+ * clients to specify their own locales; this default locale is only used when
+ * no locale is specified, e.g. calling a toLocaleString function without
+ * passing a locale argument to it.)
+ *
+ * The locale string remains owned by the caller.
+ */
+extern JS_PUBLIC_API(bool)
+JS_SetDefaultLocale(JSRuntime* rt, const char* locale);
+
+/**
+ * Return a copy of the default locale for the ECMAScript Internationalization
+ * API (and for various ECMAScript functions that will invoke it).  The locale
+ * is retrieved from the |JSRuntime| that corresponds to |cx|.
+ *
+ * XXX Bug 1483961 means it's difficult to interpret the meaning of a null
+ *     return value for the time being, and we should fix this!
+ */
+extern JS_PUBLIC_API(JS::UniqueChars)
+JS_GetDefaultLocale(JSContext* cx);
+
+/** Reset the default locale to OS defaults. */
+extern JS_PUBLIC_API(void)
+JS_ResetDefaultLocale(JSRuntime* rt);
+
+using JSLocaleToUpperCase =
+    bool (*)(JSContext* cx, JS::Handle<JSString*> src, JS::MutableHandle<JS::Value> rval);
+
+using JSLocaleToLowerCase =
+    bool (*)(JSContext* cx, JS::Handle<JSString*> src, JS::MutableHandle<JS::Value> rval);
+
+using JSLocaleCompare =
+    bool (*)(JSContext* cx, JS::Handle<JSString*> src1, JS::Handle<JSString*> src2,
+             JS::MutableHandle<JS::Value> rval);
+
+using JSLocaleToUnicode =
+    bool (*)(JSContext* cx, const char* src, JS::MutableHandle<JS::Value> rval);
+
+/**
+ * A suite of locale-specific string conversion and error message callbacks
+ * used to implement locale-sensitive behaviors (such as those performed by
+ * the various toLocaleString and toLocale{Date,Time}String functions).
+ *
+ * If SpiderMonkey is compiled --with-intl-api, then #if EXPOSE_INTL_API.  In
+ * this case, SpiderMonkey itself will implement ECMA-402-compliant behavior by
+ * calling on ICU, and none of the fields in this struct will ever be used.
+ * (You'll still be able to call the get/set-callbacks functions; they just
+ * won't affect JavaScript semantics.)
+ */
+struct JSLocaleCallbacks
+{
+    JSLocaleToUpperCase localeToUpperCase;
+    JSLocaleToLowerCase localeToLowerCase;
+    JSLocaleCompare localeCompare;
+    JSLocaleToUnicode localeToUnicode;
+};
+
+/**
+ * Set locale callbacks to be used in builds not compiled --with-intl-api.
+ * |callbacks| must persist as long as the |JSRuntime|.  Pass |nullptr| to
+ * restore default behavior.
+ */
+extern JS_PUBLIC_API(void)
+JS_SetLocaleCallbacks(JSRuntime* rt, const JSLocaleCallbacks* callbacks);
+
+/**
+ * Return the current locale callbacks, which may be nullptr.
+ */
+extern JS_PUBLIC_API(const JSLocaleCallbacks*)
+JS_GetLocaleCallbacks(JSRuntime* rt);
+
+#endif /* js_LocaleSensitive_h */
--- a/js/src/builtin/String.cpp
+++ b/js/src/builtin/String.cpp
@@ -26,16 +26,19 @@
 
 #include "builtin/Array.h"
 #include "builtin/Boolean.h"
 #include "builtin/intl/CommonFunctions.h"
 #include "builtin/intl/ICUStubs.h"
 #include "builtin/RegExp.h"
 #include "jit/InlinableNatives.h"
 #include "js/Conversions.h"
+#if !EXPOSE_INTL_API
+#include "js/LocaleSensitive.h"
+#endif
 #include "js/StableStringChars.h"
 #include "js/UniquePtr.h"
 #if ENABLE_INTL_API
 # include "unicode/uchar.h"
 # include "unicode/unorm2.h"
 #endif
 #include "util/StringBuffer.h"
 #include "util/Unicode.h"
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -39,16 +39,17 @@
 #endif
 #include "gc/Heap.h"
 #include "jit/BaselineJIT.h"
 #include "jit/InlinableNatives.h"
 #include "jit/JitRealm.h"
 #include "js/AutoByteString.h"
 #include "js/Debug.h"
 #include "js/HashTable.h"
+#include "js/LocaleSensitive.h"
 #include "js/StableStringChars.h"
 #include "js/StructuredClone.h"
 #include "js/UbiNode.h"
 #include "js/UbiNodeBreadthFirst.h"
 #include "js/UbiNodeShortestPaths.h"
 #include "js/UniquePtr.h"
 #include "js/Vector.h"
 #include "js/Wrapper.h"
--- a/js/src/jsapi-tests/testDateToLocaleString.cpp
+++ b/js/src/jsapi-tests/testDateToLocaleString.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "js/LocaleSensitive.h"
 #include "jsapi-tests/tests.h"
 
 BEGIN_TEST(testDateToLocaleString)
 {
     JSRuntime* rt = JS_GetRuntime(cx);
 
     // This test should only attempt to run if we have Intl support: necessary
     // to properly assume that changes to the default locale will predictably
--- a/js/src/jsapi-tests/testIntlAvailableLocales.cpp
+++ b/js/src/jsapi-tests/testIntlAvailableLocales.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "js/LocaleSensitive.h"
 #include "jsapi-tests/tests.h"
 
 BEGIN_TEST(testIntlAvailableLocales)
 {
     JSRuntime* rt = JS_GetRuntime(cx);
 
     // This test should only attempt to run if we have Intl support.
     JS::Rooted<JS::Value> haveIntl(cx);
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -56,16 +56,17 @@
 #include "jit/JitCommon.h"
 #include "jit/JitSpewer.h"
 #include "js/AutoByteString.h"
 #include "js/CharacterEncoding.h"
 #include "js/Conversions.h"
 #include "js/Date.h"
 #include "js/Initialization.h"
 #include "js/JSON.h"
+#include "js/LocaleSensitive.h"
 #include "js/Proxy.h"
 #include "js/SliceBudget.h"
 #include "js/StableStringChars.h"
 #include "js/StructuredClone.h"
 #include "js/Utility.h"
 #include "js/Wrapper.h"
 #include "util/StringBuffer.h"
 #include "util/Text.h"
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -218,29 +218,16 @@ enum class PromiseRejectionHandlingState
 
 } /* namespace JS */
 
 typedef void
 (* JSPromiseRejectionTrackerCallback)(JSContext* cx, JS::HandleObject promise,
                                       JS::PromiseRejectionHandlingState state,
                                       void* data);
 
-typedef bool
-(* JSLocaleToUpperCase)(JSContext* cx, JS::HandleString src, JS::MutableHandleValue rval);
-
-typedef bool
-(* JSLocaleToLowerCase)(JSContext* cx, JS::HandleString src, JS::MutableHandleValue rval);
-
-typedef bool
-(* JSLocaleCompare)(JSContext* cx, JS::HandleString src1, JS::HandleString src2,
-                    JS::MutableHandleValue rval);
-
-typedef bool
-(* JSLocaleToUnicode)(JSContext* cx, const char* src, JS::MutableHandleValue rval);
-
 /**
  * Callback used to ask the embedding for the cross compartment wrapper handler
  * that implements the desired prolicy for this kind of object in the
  * destination compartment. |obj| is the object to be wrapped. If |existing| is
  * non-nullptr, it will point to an existing wrapper object that should be
  * re-used if possible. |existing| is guaranteed to be a cross-compartment
  * wrapper with a lazily-defined prototype and the correct global. It is
  * guaranteed not to wrap a function.
@@ -4720,65 +4707,16 @@ PropertySpecNameEqualsId(const char* nam
  */
 JS_PUBLIC_API(bool)
 PropertySpecNameToPermanentId(JSContext* cx, const char* name, jsid* idp);
 
 } /* namespace JS */
 
 /************************************************************************/
 
-/**
- * The default locale for the ECMAScript Internationalization API
- * (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat).
- * Note that the Internationalization API encourages clients to
- * specify their own locales.
- * The locale string remains owned by the caller.
- */
-extern JS_PUBLIC_API(bool)
-JS_SetDefaultLocale(JSRuntime* rt, const char* locale);
-
-/**
- * Look up the default locale for the ECMAScript Internationalization API.
- * NB: The locale information is retrieved from cx's runtime.
- */
-extern JS_PUBLIC_API(JS::UniqueChars)
-JS_GetDefaultLocale(JSContext* cx);
-
-/**
- * Reset the default locale to OS defaults.
- */
-extern JS_PUBLIC_API(void)
-JS_ResetDefaultLocale(JSRuntime* rt);
-
-/**
- * Locale specific string conversion and error message callbacks.
- */
-struct JSLocaleCallbacks {
-    JSLocaleToUpperCase     localeToUpperCase; // not used #if EXPOSE_INTL_API
-    JSLocaleToLowerCase     localeToLowerCase; // not used #if EXPOSE_INTL_API
-    JSLocaleCompare         localeCompare; // not used #if EXPOSE_INTL_API
-    JSLocaleToUnicode       localeToUnicode;
-};
-
-/**
- * Establish locale callbacks. The pointer must persist as long as the
- * JSContext.  Passing nullptr restores the default behaviour.
- */
-extern JS_PUBLIC_API(void)
-JS_SetLocaleCallbacks(JSRuntime* rt, const JSLocaleCallbacks* callbacks);
-
-/**
- * Return the address of the current locale callbacks struct, which may
- * be nullptr.
- */
-extern JS_PUBLIC_API(const JSLocaleCallbacks*)
-JS_GetLocaleCallbacks(JSRuntime* rt);
-
-/************************************************************************/
-
 /*
  * Error reporting.
  *
  * There are four encoding variants for the error reporting API:
  *   UTF-8
  *     JSAPI's default encoding for error handling.  Use this when the encoding
  *     of the error message, format string, and arguments is UTF-8.
  *   ASCII
--- a/js/src/jsnum.cpp
+++ b/js/src/jsnum.cpp
@@ -23,16 +23,19 @@
 #include <math.h>
 #include <string.h>
 
 #include "jstypes.h"
 
 #include "builtin/String.h"
 #include "double-conversion/double-conversion.h"
 #include "js/Conversions.h"
+#if !EXPOSE_INTL_API
+#include "js/LocaleSensitive.h"
+#endif
 #include "util/DoubleToString.h"
 #include "util/StringBuffer.h"
 #ifdef ENABLE_BIGINT
 #include "vm/BigIntType.h"
 #endif
 #include "vm/GlobalObject.h"
 #include "vm/JSAtom.h"
 #include "vm/JSContext.h"
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -63,17 +63,16 @@ enum JSProtoKey {
     JSProto_LIMIT
 };
 
 /* Struct forward declarations. */
 struct JSClass;
 class JSErrorReport;
 struct JSExceptionState;
 struct JSFunctionSpec;
-struct JSLocaleCallbacks;
 struct JSPrincipals;
 struct JSPropertySpec;
 struct JSSecurityCallbacks;
 struct JSStructuredCloneCallbacks;
 struct JSStructuredCloneReader;
 struct JSStructuredCloneWriter;
 class JS_PUBLIC_API(JSTracer);
 
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -139,16 +139,17 @@ EXPORTS.js += [
     '../public/GCPolicyAPI.h',
     '../public/GCVariant.h',
     '../public/GCVector.h',
     '../public/HashTable.h',
     '../public/HeapAPI.h',
     '../public/Id.h',
     '../public/Initialization.h',
     '../public/JSON.h',
+    '../public/LocaleSensitive.h',
     '../public/MemoryFunctions.h',
     '../public/MemoryMetrics.h',
     '../public/Principals.h',
     '../public/Printf.h',
     '../public/ProfilingFrameIterator.h',
     '../public/ProfilingStack.h',
     '../public/ProtoKey.h',
     '../public/Proxy.h',
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -64,16 +64,17 @@ class TraceLoggerThread;
 
 namespace gc {
 class AutoHeapSession;
 }
 
 } // namespace js
 
 struct DtoaState;
+struct JSLocaleCallbacks;
 
 #ifdef JS_SIMULATOR_ARM64
 namespace vixl {
 class Simulator;
 }
 #endif
 
 namespace js {
--- a/js/xpconnect/src/XPCLocale.cpp
+++ b/js/xpconnect/src/XPCLocale.cpp
@@ -1,29 +1,27 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Assertions.h"
 
-#include "jsapi.h"
+#include "js/LocaleSensitive.h"
 
-#include "nsJSUtils.h"
 #include "nsIObserver.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/CycleCollectedJSContext.h"
 #include "mozilla/intl/LocaleService.h"
 #include "mozilla/Preferences.h"
 
 #include "xpcpublic.h"
 
-using namespace JS;
 using namespace mozilla;
 using mozilla::intl::LocaleService;
 
 class XPCLocaleObserver : public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER