diff --git a/frontend_tests/node_tests/util.js b/frontend_tests/node_tests/util.js index 74673c660c..039b7c783a 100644 --- a/frontend_tests/node_tests/util.js +++ b/frontend_tests/node_tests/util.js @@ -135,6 +135,14 @@ var _ = global._; } }()); +(function test_dumb_strcmp() { + Intl.Collator = undefined; + var strcmp = util.make_strcmp(); + assert.equal(strcmp('a', 'b'), -1); + assert.equal(strcmp('c', 'c'), 0); + assert.equal(strcmp('z', 'y'), 1); +}()); + (function test_is_mobile() { global.window.navigator = { userAgent: "Android" }; assert(util.is_mobile()); diff --git a/static/js/util.js b/static/js/util.js index 167871611f..0644cefbfb 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -138,7 +138,7 @@ exports.rtrim = function (str) { // doesn't support the ECMAScript Internationalization API // Specification, do a dumb string comparison because // String.localeCompare is really slow. -exports.strcmp = (function () { +exports.make_strcmp = function () { try { var collator = new Intl.Collator(); return collator.compare; @@ -149,7 +149,8 @@ exports.strcmp = (function () { return function util_strcmp(a, b) { return (a < b ? -1 : (a > b ? 1 : 0)); }; -}()); +}; +exports.strcmp = exports.make_strcmp(); exports.escape_regexp = function (string) { // code from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions