summaryrefslogtreecommitdiffstats
path: root/js/src/builtin/Intl.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-04-25 11:16:14 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-04-25 11:16:14 +0200
commitb069dabc91b7e0f5f8d161cdbe598276a21d6d68 (patch)
tree346fcbdbeeb30e7276c7639477d8903a9f719726 /js/src/builtin/Intl.js
parent9349f7f29e108da8ddb8684dd9e70201895db1b4 (diff)
downloadUXP-b069dabc91b7e0f5f8d161cdbe598276a21d6d68.tar
UXP-b069dabc91b7e0f5f8d161cdbe598276a21d6d68.tar.gz
UXP-b069dabc91b7e0f5f8d161cdbe598276a21d6d68.tar.lz
UXP-b069dabc91b7e0f5f8d161cdbe598276a21d6d68.tar.xz
UXP-b069dabc91b7e0f5f8d161cdbe598276a21d6d68.zip
Avoid calling slice in self-hosted code. DiD
This time without unrelated/incomplete pluralforms junk.
Diffstat (limited to 'js/src/builtin/Intl.js')
-rw-r--r--js/src/builtin/Intl.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/js/src/builtin/Intl.js b/js/src/builtin/Intl.js
index 493062c1c..509168d7a 100644
--- a/js/src/builtin/Intl.js
+++ b/js/src/builtin/Intl.js
@@ -432,7 +432,7 @@ function CanonicalizeLanguageTag(locale) {
subtags[i] = subtag;
i++;
}
- var normal = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, 0, i), "-");
+ var normal = ArrayJoinRange(subtags, "-", 0, i);
// Extension sequences are sorted by their singleton characters.
// "u-ca-chinese-t-zh-latn" -> "t-zh-latn-u-ca-chinese"
@@ -442,7 +442,7 @@ function CanonicalizeLanguageTag(locale) {
i++;
while (i < subtags.length && subtags[i].length > 1)
i++;
- var extension = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, extensionStart, i), "-");
+ var extension = ArrayJoinRange(subtags, "-", extensionStart, i);
callFunction(std_Array_push, extensions, extension);
}
callFunction(std_Array_sort, extensions);
@@ -450,7 +450,7 @@ function CanonicalizeLanguageTag(locale) {
// Private use sequences are left as is. "x-private"
var privateUse = "";
if (i < subtags.length)
- privateUse = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, i), "-");
+ privateUse = ArrayJoinRange(subtags, "-", i);
// Put everything back together.
var canonical = normal;
@@ -467,6 +467,24 @@ function CanonicalizeLanguageTag(locale) {
return canonical;
}
+/**
+ * Joins the array elements in the given range with the supplied separator.
+ */
+function ArrayJoinRange(array, separator, from, to = array.length) {
+ assert(typeof separator === "string", "|separator| is a string value");
+ assert(typeof from === "number", "|from| is a number value");
+ assert(typeof to === "number", "|to| is a number value");
+ assert(0 <= from && from <= to && to <= array.length, "|from| and |to| form a valid range");
+
+ if (from === to)
+ return "";
+
+ var result = array[from];
+ for (var i = from + 1; i < to; i++) {
+ result += separator + array[i];
+ }
+ return result;
+}
function localeContainsNoUnicodeExtensions(locale) {
// No "-u-", no possible Unicode extension.