[gjs: 16/25] engine: Remove locale callbacks



commit 9f7a5ba597957be7f2e699625fbd6595e79da682
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Nov 9 14:33:10 2019 -0800

    engine: Remove locale callbacks
    
    Since SpiderMonkey 68, the locale callbacks are only ever called if
    SpiderMonkey was compiled without the Intl API. Instead, SpiderMonkey
    uses libicu to provide this behaviour.
    
    Since we do already require a version with the Intl API enabled, there's
    no point in providing these callbacks any longer.

 gjs/engine.cpp                   | 83 ----------------------------------------
 installed-tests/js/meson.build   |  1 -
 installed-tests/js/testLocale.js | 41 --------------------
 installed-tests/js/testself.js   |  6 +++
 4 files changed, 6 insertions(+), 125 deletions(-)
---
diff --git a/gjs/engine.cpp b/gjs/engine.cpp
index 6d7ad940..422d89b2 100644
--- a/gjs/engine.cpp
+++ b/gjs/engine.cpp
@@ -45,88 +45,6 @@
 #include "gjs/jsapi-util.h"
 #include "util/log.h"
 
-/* Implementations of locale-specific operations; these are used
- * in the implementation of String.localeCompare(), Date.toLocaleDateString(),
- * and so forth. We take the straight-forward approach of converting
- * to UTF-8, using the appropriate GLib functions, and converting
- * back if necessary.
- */
-GJS_JSAPI_RETURN_CONVENTION
-static bool
-gjs_locale_to_upper_case (JSContext *context,
-                          JS::HandleString src,
-                          JS::MutableHandleValue retval)
-{
-    JS::UniqueChars utf8(JS_EncodeStringToUTF8(context, src));
-    if (!utf8)
-        return false;
-
-    GjsAutoChar upper_case_utf8 = g_utf8_strup(utf8.get(), -1);
-    return gjs_string_from_utf8(context, upper_case_utf8, retval);
-}
-
-GJS_JSAPI_RETURN_CONVENTION
-static bool
-gjs_locale_to_lower_case (JSContext *context,
-                          JS::HandleString src,
-                          JS::MutableHandleValue retval)
-{
-    JS::UniqueChars utf8(JS_EncodeStringToUTF8(context, src));
-    if (!utf8)
-        return false;
-
-    GjsAutoChar lower_case_utf8 = g_utf8_strdown(utf8.get(), -1);
-    return gjs_string_from_utf8(context, lower_case_utf8, retval);
-}
-
-GJS_JSAPI_RETURN_CONVENTION
-static bool
-gjs_locale_compare (JSContext *context,
-                    JS::HandleString src_1,
-                    JS::HandleString src_2,
-                    JS::MutableHandleValue retval)
-{
-    JS::UniqueChars utf8_1(JS_EncodeStringToUTF8(context, src_1));
-    if (!utf8_1)
-        return false;
-
-    JS::UniqueChars utf8_2(JS_EncodeStringToUTF8(context, src_2));
-    if (!utf8_2)
-        return false;
-
-    retval.setInt32(g_utf8_collate(utf8_1.get(), utf8_2.get()));
-
-    return true;
-}
-
-GJS_JSAPI_RETURN_CONVENTION
-static bool
-gjs_locale_to_unicode (JSContext  *context,
-                       const char *src,
-                       JS::MutableHandleValue retval)
-{
-    GError *error = NULL;
-
-    GjsAutoChar utf8 = g_locale_to_utf8(src, -1, NULL, NULL, &error);
-    if (!utf8) {
-        gjs_throw(context,
-                  "Failed to convert locale string to UTF8: %s",
-                  error->message);
-        g_error_free(error);
-        return false;
-    }
-
-    return gjs_string_from_utf8(context, utf8, retval);
-}
-
-static JSLocaleCallbacks gjs_locale_callbacks =
-{
-    gjs_locale_to_upper_case,
-    gjs_locale_to_lower_case,
-    gjs_locale_compare,
-    gjs_locale_to_unicode
-};
-
 static void gjs_finalize_callback(JSFreeOp*, JSFinalizeStatus status,
                                   void* data) {
     auto* gjs = static_cast<GjsContextPrivate*>(data);
@@ -319,7 +237,6 @@ JSContext* gjs_create_js_context(GjsContextPrivate* uninitialized_gjs) {
 
     JS_AddFinalizeCallback(cx, gjs_finalize_callback, uninitialized_gjs);
     JS_SetGCCallback(cx, on_garbage_collect, uninitialized_gjs);
-    JS_SetLocaleCallbacks(JS_GetRuntime(cx), &gjs_locale_callbacks);
     JS::SetWarningReporter(cx, gjs_warning_reporter);
     JS::SetGetIncumbentGlobalCallback(cx, gjs_get_import_global);
     JS::SetEnqueuePromiseJobCallback(cx, on_enqueue_promise_job,
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 4261f3ba..5d64e78d 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -105,7 +105,6 @@ jasmine_tests = [
     'LegacyByteArray',
     'LegacyClass',
     'LegacyGObject',
-    'Locale',
     'Mainloop',
     'Namespace',
     'Package',
diff --git a/installed-tests/js/testself.js b/installed-tests/js/testself.js
index 40b611b6..6f748a4b 100644
--- a/installed-tests/js/testself.js
+++ b/installed-tests/js/testself.js
@@ -30,3 +30,9 @@ describe('Test harness internal consistency', function () {
         expect(() => true).not.toThrow();
     });
 });
+
+describe('SpiderMonkey features check', function () {
+    it('Intl API was compiled into SpiderMonkey', function () {
+        expect(Intl).toBeDefined();
+    });
+});


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]