Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=8 sts=4 et sw=4 tw=99:
3 : * This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef builtin_Intl_h
8 : #define builtin_Intl_h
9 :
10 : #include "mozilla/HashFunctions.h"
11 : #include "mozilla/MemoryReporting.h"
12 :
13 : #include "jsalloc.h"
14 : #include "NamespaceImports.h"
15 :
16 : #include "builtin/SelfHostingDefines.h"
17 : #include "js/Class.h"
18 : #include "js/GCAPI.h"
19 : #include "js/GCHashTable.h"
20 : #include "vm/NativeObject.h"
21 :
22 : class JSLinearString;
23 :
24 : /*
25 : * The Intl module specified by standard ECMA-402,
26 : * ECMAScript Internationalization API Specification.
27 : */
28 :
29 : namespace js {
30 :
31 : class FreeOp;
32 :
33 : /**
34 : * Initializes the Intl Object and its standard built-in properties.
35 : * Spec: ECMAScript Internationalization API Specification, 8.0, 8.1
36 : */
37 : extern JSObject*
38 : InitIntlClass(JSContext* cx, HandleObject obj);
39 :
40 : /**
41 : * Stores Intl data which can be shared across compartments (but not contexts).
42 : *
43 : * Used for data which is expensive when computed repeatedly or is not
44 : * available through ICU.
45 : */
46 4 : class SharedIntlData
47 : {
48 0 : struct LinearStringLookup
49 : {
50 : union {
51 : const JS::Latin1Char* latin1Chars;
52 : const char16_t* twoByteChars;
53 : };
54 : bool isLatin1;
55 : size_t length;
56 : JS::AutoCheckCannotGC nogc;
57 : HashNumber hash = 0;
58 :
59 0 : explicit LinearStringLookup(JSLinearString* string)
60 0 : : isLatin1(string->hasLatin1Chars()), length(string->length())
61 : {
62 0 : if (isLatin1)
63 0 : latin1Chars = string->latin1Chars(nogc);
64 : else
65 0 : twoByteChars = string->twoByteChars(nogc);
66 0 : }
67 : };
68 :
69 : private:
70 : /**
71 : * Information tracking the set of the supported time zone names, derived
72 : * from the IANA time zone database <https://www.iana.org/time-zones>.
73 : *
74 : * There are two kinds of IANA time zone names: Zone and Link (denoted as
75 : * such in database source files). Zone names are the canonical, preferred
76 : * name for a time zone, e.g. Asia/Kolkata. Link names simply refer to
77 : * target Zone names for their meaning, e.g. Asia/Calcutta targets
78 : * Asia/Kolkata. That a name is a Link doesn't *necessarily* reflect a
79 : * sense of deprecation: some Link names also exist partly for convenience,
80 : * e.g. UTC and GMT as Link names targeting the Zone name Etc/UTC.
81 : *
82 : * Two data sources determine the time zone names we support: those ICU
83 : * supports and IANA's zone information.
84 : *
85 : * Unfortunately the names ICU and IANA support, and their Link
86 : * relationships from name to target, aren't identical, so we can't simply
87 : * implicitly trust ICU's name handling. We must perform various
88 : * preprocessing of user-provided zone names and post-processing of
89 : * ICU-provided zone names to implement ECMA-402's IANA-consistent behavior.
90 : *
91 : * Also see <https://ssl.icu-project.org/trac/ticket/12044> and
92 : * <http://unicode.org/cldr/trac/ticket/9892>.
93 : */
94 :
95 : using TimeZoneName = JSAtom*;
96 :
97 : struct TimeZoneHasher
98 : {
99 0 : struct Lookup : LinearStringLookup
100 : {
101 : explicit Lookup(JSLinearString* timeZone);
102 : };
103 :
104 0 : static js::HashNumber hash(const Lookup& lookup) { return lookup.hash; }
105 : static bool match(TimeZoneName key, const Lookup& lookup);
106 : };
107 :
108 : using TimeZoneSet = js::GCHashSet<TimeZoneName,
109 : TimeZoneHasher,
110 : js::SystemAllocPolicy>;
111 :
112 : using TimeZoneMap = js::GCHashMap<TimeZoneName,
113 : TimeZoneName,
114 : TimeZoneHasher,
115 : js::SystemAllocPolicy>;
116 :
117 : /**
118 : * As a threshold matter, available time zones are those time zones ICU
119 : * supports, via ucal_openTimeZones. But ICU supports additional non-IANA
120 : * time zones described in intl/icu/source/tools/tzcode/icuzones (listed in
121 : * IntlTimeZoneData.cpp's |legacyICUTimeZones|) for its own backwards
122 : * compatibility purposes. This set consists of ICU's supported time zones,
123 : * minus all backwards-compatibility time zones.
124 : */
125 : TimeZoneSet availableTimeZones;
126 :
127 : /**
128 : * IANA treats some time zone names as Zones, that ICU instead treats as
129 : * Links. For example, IANA considers "America/Indiana/Indianapolis" to be
130 : * a Zone and "America/Fort_Wayne" a Link that targets it, but ICU
131 : * considers the former a Link that targets "America/Indianapolis" (which
132 : * IANA treats as a Link).
133 : *
134 : * ECMA-402 requires that we respect IANA data, so if we're asked to
135 : * canonicalize a time zone name in this set, we must *not* return ICU's
136 : * canonicalization.
137 : */
138 : TimeZoneSet ianaZonesTreatedAsLinksByICU;
139 :
140 : /**
141 : * IANA treats some time zone names as Links to one target, that ICU
142 : * instead treats as either Zones, or Links to different targets. An
143 : * example of the former is "Asia/Calcutta, which IANA assigns the target
144 : * "Asia/Kolkata" but ICU considers its own Zone. An example of the latter
145 : * is "America/Virgin", which IANA assigns the target
146 : * "America/Port_of_Spain" but ICU assigns the target "America/St_Thomas".
147 : *
148 : * ECMA-402 requires that we respect IANA data, so if we're asked to
149 : * canonicalize a time zone name that's a key in this map, we *must* return
150 : * the corresponding value and *must not* return ICU's canonicalization.
151 : */
152 : TimeZoneMap ianaLinksCanonicalizedDifferentlyByICU;
153 :
154 : bool timeZoneDataInitialized = false;
155 :
156 : /**
157 : * Precomputes the available time zone names, because it's too expensive to
158 : * call ucal_openTimeZones() repeatedly.
159 : */
160 : bool ensureTimeZones(JSContext* cx);
161 :
162 : public:
163 : /**
164 : * Returns the validated time zone name in |result|. If the input time zone
165 : * isn't a valid IANA time zone name, |result| remains unchanged.
166 : */
167 : bool validateTimeZoneName(JSContext* cx, JS::HandleString timeZone,
168 : MutableHandleAtom result);
169 :
170 : /**
171 : * Returns the canonical time zone name in |result|. If no canonical name
172 : * was found, |result| remains unchanged.
173 : *
174 : * This method only handles time zones which are canonicalized differently
175 : * by ICU when compared to IANA.
176 : */
177 : bool tryCanonicalizeTimeZoneConsistentWithIANA(JSContext* cx, JS::HandleString timeZone,
178 : MutableHandleAtom result);
179 :
180 : private:
181 : /**
182 : * The case first parameter (BCP47 key "kf") allows to switch the order of
183 : * upper- and lower-case characters. ICU doesn't directly provide an API
184 : * to query the default case first value of a given locale, but instead
185 : * requires to instantiate a collator object and then query the case first
186 : * attribute (UCOL_CASE_FIRST).
187 : * To avoid instantiating an additional collator object whenever we need
188 : * to retrieve the default case first value of a specific locale, we
189 : * compute the default case first value for every supported locale only
190 : * once and then keep a list of all locales which don't use the default
191 : * case first setting.
192 : * There is almost no difference between lower-case first and when case
193 : * first is disabled (UCOL_LOWER_FIRST resp. UCOL_OFF), so we only need to
194 : * track locales which use upper-case first as their default setting.
195 : */
196 :
197 : using Locale = JSAtom*;
198 :
199 : struct LocaleHasher
200 : {
201 0 : struct Lookup : LinearStringLookup
202 : {
203 : explicit Lookup(JSLinearString* locale);
204 : };
205 :
206 0 : static js::HashNumber hash(const Lookup& lookup) { return lookup.hash; }
207 : static bool match(Locale key, const Lookup& lookup);
208 : };
209 :
210 : using LocaleSet = js::GCHashSet<Locale,
211 : LocaleHasher,
212 : js::SystemAllocPolicy>;
213 :
214 : LocaleSet upperCaseFirstLocales;
215 :
216 : bool upperCaseFirstInitialized = false;
217 :
218 : /**
219 : * Precomputes the available locales which use upper-case first sorting.
220 : */
221 : bool ensureUpperCaseFirstLocales(JSContext* cx);
222 :
223 : public:
224 : /**
225 : * Sets |isUpperFirst| to true if |locale| sorts upper-case characters
226 : * before lower-case characters.
227 : */
228 : bool isUpperCaseFirst(JSContext* cx, JS::HandleString locale, bool* isUpperFirst);
229 :
230 : public:
231 : void destroyInstance();
232 :
233 : void trace(JSTracer* trc);
234 :
235 : size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
236 : };
237 :
238 : /*
239 : * The following functions are for use by self-hosted code.
240 : */
241 :
242 :
243 : /******************** Collator ********************/
244 :
245 : class CollatorObject : public NativeObject
246 : {
247 : public:
248 : static const Class class_;
249 :
250 : static constexpr uint32_t INTERNALS_SLOT = 0;
251 : static constexpr uint32_t UCOLLATOR_SLOT = 1;
252 : static constexpr uint32_t SLOT_COUNT = 2;
253 :
254 : static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
255 : "INTERNALS_SLOT must match self-hosting define for internals object slot");
256 :
257 : private:
258 : static const ClassOps classOps_;
259 :
260 : static void finalize(FreeOp* fop, JSObject* obj);
261 : };
262 :
263 : /**
264 : * Returns a new instance of the standard built-in Collator constructor.
265 : * Self-hosted code cannot cache this constructor (as it does for others in
266 : * Utilities.js) because it is initialized after self-hosted code is compiled.
267 : *
268 : * Usage: collator = intl_Collator(locales, options)
269 : */
270 : extern MOZ_MUST_USE bool
271 : intl_Collator(JSContext* cx, unsigned argc, Value* vp);
272 :
273 : /**
274 : * Returns an object indicating the supported locales for collation
275 : * by having a true-valued property for each such locale with the
276 : * canonicalized language tag as the property name. The object has no
277 : * prototype.
278 : *
279 : * Usage: availableLocales = intl_Collator_availableLocales()
280 : */
281 : extern MOZ_MUST_USE bool
282 : intl_Collator_availableLocales(JSContext* cx, unsigned argc, Value* vp);
283 :
284 : /**
285 : * Returns an array with the collation type identifiers per Unicode
286 : * Technical Standard 35, Unicode Locale Data Markup Language, for the
287 : * collations supported for the given locale. "standard" and "search" are
288 : * excluded.
289 : *
290 : * Usage: collations = intl_availableCollations(locale)
291 : */
292 : extern MOZ_MUST_USE bool
293 : intl_availableCollations(JSContext* cx, unsigned argc, Value* vp);
294 :
295 : /**
296 : * Compares x and y (which must be String values), and returns a number less
297 : * than 0 if x < y, 0 if x = y, or a number greater than 0 if x > y according
298 : * to the sort order for the locale and collation options of the given
299 : * Collator.
300 : *
301 : * Spec: ECMAScript Internationalization API Specification, 10.3.2.
302 : *
303 : * Usage: result = intl_CompareStrings(collator, x, y)
304 : */
305 : extern MOZ_MUST_USE bool
306 : intl_CompareStrings(JSContext* cx, unsigned argc, Value* vp);
307 :
308 : /**
309 : * Returns true if the given locale sorts upper-case before lower-case
310 : * characters.
311 : *
312 : * Usage: result = intl_isUpperCaseFirst(locale)
313 : */
314 : extern MOZ_MUST_USE bool
315 : intl_isUpperCaseFirst(JSContext* cx, unsigned argc, Value* vp);
316 :
317 :
318 : /******************** NumberFormat ********************/
319 :
320 : class NumberFormatObject : public NativeObject
321 : {
322 : public:
323 : static const Class class_;
324 :
325 : static constexpr uint32_t INTERNALS_SLOT = 0;
326 : static constexpr uint32_t UNUMBER_FORMAT_SLOT = 1;
327 : static constexpr uint32_t SLOT_COUNT = 2;
328 :
329 : static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
330 : "INTERNALS_SLOT must match self-hosting define for internals object slot");
331 :
332 : private:
333 : static const ClassOps classOps_;
334 :
335 : static void finalize(FreeOp* fop, JSObject* obj);
336 : };
337 :
338 : /**
339 : * Returns a new instance of the standard built-in NumberFormat constructor.
340 : * Self-hosted code cannot cache this constructor (as it does for others in
341 : * Utilities.js) because it is initialized after self-hosted code is compiled.
342 : *
343 : * Usage: numberFormat = intl_NumberFormat(locales, options)
344 : */
345 : extern MOZ_MUST_USE bool
346 : intl_NumberFormat(JSContext* cx, unsigned argc, Value* vp);
347 :
348 : /**
349 : * Returns an object indicating the supported locales for number formatting
350 : * by having a true-valued property for each such locale with the
351 : * canonicalized language tag as the property name. The object has no
352 : * prototype.
353 : *
354 : * Usage: availableLocales = intl_NumberFormat_availableLocales()
355 : */
356 : extern MOZ_MUST_USE bool
357 : intl_NumberFormat_availableLocales(JSContext* cx, unsigned argc, Value* vp);
358 :
359 : /**
360 : * Returns the numbering system type identifier per Unicode
361 : * Technical Standard 35, Unicode Locale Data Markup Language, for the
362 : * default numbering system for the given locale.
363 : *
364 : * Usage: defaultNumberingSystem = intl_numberingSystem(locale)
365 : */
366 : extern MOZ_MUST_USE bool
367 : intl_numberingSystem(JSContext* cx, unsigned argc, Value* vp);
368 :
369 : /**
370 : * Returns a string representing the number x according to the effective
371 : * locale and the formatting options of the given NumberFormat.
372 : *
373 : * Spec: ECMAScript Internationalization API Specification, 11.3.2.
374 : *
375 : * Usage: formatted = intl_FormatNumber(numberFormat, x, formatToParts)
376 : */
377 : extern MOZ_MUST_USE bool
378 : intl_FormatNumber(JSContext* cx, unsigned argc, Value* vp);
379 :
380 :
381 : /******************** DateTimeFormat ********************/
382 :
383 : class DateTimeFormatObject : public NativeObject
384 : {
385 : public:
386 : static const Class class_;
387 :
388 : static constexpr uint32_t INTERNALS_SLOT = 0;
389 : static constexpr uint32_t UDATE_FORMAT_SLOT = 1;
390 : static constexpr uint32_t SLOT_COUNT = 2;
391 :
392 : static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
393 : "INTERNALS_SLOT must match self-hosting define for internals object slot");
394 :
395 : private:
396 : static const ClassOps classOps_;
397 :
398 : static void finalize(FreeOp* fop, JSObject* obj);
399 : };
400 :
401 : /**
402 : * Returns a new instance of the standard built-in DateTimeFormat constructor.
403 : * Self-hosted code cannot cache this constructor (as it does for others in
404 : * Utilities.js) because it is initialized after self-hosted code is compiled.
405 : *
406 : * Usage: dateTimeFormat = intl_DateTimeFormat(locales, options)
407 : */
408 : extern MOZ_MUST_USE bool
409 : intl_DateTimeFormat(JSContext* cx, unsigned argc, Value* vp);
410 :
411 : /**
412 : * Returns an object indicating the supported locales for date and time
413 : * formatting by having a true-valued property for each such locale with the
414 : * canonicalized language tag as the property name. The object has no
415 : * prototype.
416 : *
417 : * Usage: availableLocales = intl_DateTimeFormat_availableLocales()
418 : */
419 : extern MOZ_MUST_USE bool
420 : intl_DateTimeFormat_availableLocales(JSContext* cx, unsigned argc, Value* vp);
421 :
422 : /**
423 : * Returns an array with the calendar type identifiers per Unicode
424 : * Technical Standard 35, Unicode Locale Data Markup Language, for the
425 : * supported calendars for the given locale. The default calendar is
426 : * element 0.
427 : *
428 : * Usage: calendars = intl_availableCalendars(locale)
429 : */
430 : extern MOZ_MUST_USE bool
431 : intl_availableCalendars(JSContext* cx, unsigned argc, Value* vp);
432 :
433 : /**
434 : * Returns the calendar type identifier per Unicode Technical Standard 35,
435 : * Unicode Locale Data Markup Language, for the default calendar for the given
436 : * locale.
437 : *
438 : * Usage: calendar = intl_defaultCalendar(locale)
439 : */
440 : extern MOZ_MUST_USE bool
441 : intl_defaultCalendar(JSContext* cx, unsigned argc, Value* vp);
442 :
443 : /**
444 : * 6.4.1 IsValidTimeZoneName ( timeZone )
445 : *
446 : * Verifies that the given string is a valid time zone name. If it is a valid
447 : * time zone name, its IANA time zone name is returned. Otherwise returns null.
448 : *
449 : * ES2017 Intl draft rev 4a23f407336d382ed5e3471200c690c9b020b5f3
450 : *
451 : * Usage: ianaTimeZone = intl_IsValidTimeZoneName(timeZone)
452 : */
453 : extern MOZ_MUST_USE bool
454 : intl_IsValidTimeZoneName(JSContext* cx, unsigned argc, Value* vp);
455 :
456 : /**
457 : * Return the canonicalized time zone name. Canonicalization resolves link
458 : * names to their target time zones.
459 : *
460 : * Usage: ianaTimeZone = intl_canonicalizeTimeZone(timeZone)
461 : */
462 : extern MOZ_MUST_USE bool
463 : intl_canonicalizeTimeZone(JSContext* cx, unsigned argc, Value* vp);
464 :
465 : /**
466 : * Return the default time zone name. The time zone name is not canonicalized.
467 : *
468 : * Usage: icuDefaultTimeZone = intl_defaultTimeZone()
469 : */
470 : extern MOZ_MUST_USE bool
471 : intl_defaultTimeZone(JSContext* cx, unsigned argc, Value* vp);
472 :
473 : /**
474 : * Return the raw offset from GMT in milliseconds for the default time zone.
475 : *
476 : * Usage: defaultTimeZoneOffset = intl_defaultTimeZoneOffset()
477 : */
478 : extern MOZ_MUST_USE bool
479 : intl_defaultTimeZoneOffset(JSContext* cx, unsigned argc, Value* vp);
480 :
481 : /**
482 : * Return a pattern in the date-time format pattern language of Unicode
483 : * Technical Standard 35, Unicode Locale Data Markup Language, for the
484 : * best-fit date-time format pattern corresponding to skeleton for the
485 : * given locale.
486 : *
487 : * Usage: pattern = intl_patternForSkeleton(locale, skeleton)
488 : */
489 : extern MOZ_MUST_USE bool
490 : intl_patternForSkeleton(JSContext* cx, unsigned argc, Value* vp);
491 :
492 : /**
493 : * Return a pattern in the date-time format pattern language of Unicode
494 : * Technical Standard 35, Unicode Locale Data Markup Language, for the
495 : * best-fit date-time style for the given locale.
496 : * The function takes four arguments:
497 : *
498 : * locale
499 : * BCP47 compliant locale string
500 : * dateStyle
501 : * A string with values: full or long or medium or short, or `undefined`
502 : * timeStyle
503 : * A string with values: full or long or medium or short, or `undefined`
504 : * timeZone
505 : * IANA time zone name
506 : *
507 : * Date and time style categories map to CLDR time/date standard
508 : * format patterns.
509 : *
510 : * For the definition of a pattern string, see LDML 4.8:
511 : * http://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns
512 : *
513 : * If `undefined` is passed to `dateStyle` or `timeStyle`, the respective
514 : * portions of the pattern will not be included in the result.
515 : *
516 : * Usage: pattern = intl_patternForStyle(locale, dateStyle, timeStyle, timeZone)
517 : */
518 : extern MOZ_MUST_USE bool
519 : intl_patternForStyle(JSContext* cx, unsigned argc, Value* vp);
520 :
521 : /**
522 : * Returns a String value representing x (which must be a Number value)
523 : * according to the effective locale and the formatting options of the
524 : * given DateTimeFormat.
525 : *
526 : * Spec: ECMAScript Internationalization API Specification, 12.3.2.
527 : *
528 : * Usage: formatted = intl_FormatDateTime(dateTimeFormat, x, formatToParts)
529 : */
530 : extern MOZ_MUST_USE bool
531 : intl_FormatDateTime(JSContext* cx, unsigned argc, Value* vp);
532 :
533 :
534 : /******************** PluralRules ********************/
535 :
536 : class PluralRulesObject : public NativeObject
537 : {
538 : public:
539 : static const Class class_;
540 :
541 : static constexpr uint32_t INTERNALS_SLOT = 0;
542 : static constexpr uint32_t UPLURAL_RULES_SLOT = 1;
543 : static constexpr uint32_t SLOT_COUNT = 2;
544 :
545 : static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
546 : "INTERNALS_SLOT must match self-hosting define for internals object slot");
547 :
548 : private:
549 : static const ClassOps classOps_;
550 :
551 : static void finalize(FreeOp* fop, JSObject* obj);
552 : };
553 :
554 : /**
555 : * Returns an object indicating the supported locales for plural rules
556 : * by having a true-valued property for each such locale with the
557 : * canonicalized language tag as the property name. The object has no
558 : * prototype.
559 : *
560 : * Usage: availableLocales = intl_PluralRules_availableLocales()
561 : */
562 : extern MOZ_MUST_USE bool
563 : intl_PluralRules_availableLocales(JSContext* cx, unsigned argc, Value* vp);
564 :
565 : /**
566 : * Returns a plural rule for the number x according to the effective
567 : * locale and the formatting options of the given PluralRules.
568 : *
569 : * A plural rule is a grammatical category that expresses count distinctions
570 : * (such as "one", "two", "few" etc.).
571 : *
572 : * Usage: rule = intl_SelectPluralRule(pluralRules, x)
573 : */
574 : extern MOZ_MUST_USE bool
575 : intl_SelectPluralRule(JSContext* cx, unsigned argc, Value* vp);
576 :
577 : /**
578 : * Returns an array of plural rules categories for a given
579 : * locale and type.
580 : *
581 : * Usage: categories = intl_GetPluralCategories(locale, type)
582 : *
583 : * Example:
584 : *
585 : * intl_getPluralCategories('pl', 'cardinal'); // ['one', 'few', 'many', 'other']
586 : */
587 : extern MOZ_MUST_USE bool
588 : intl_GetPluralCategories(JSContext* cx, unsigned argc, Value* vp);
589 :
590 :
591 : /******************** Intl ********************/
592 :
593 : /**
594 : * Returns a plain object with calendar information for a single valid locale
595 : * (callers must perform this validation). The object will have these
596 : * properties:
597 : *
598 : * firstDayOfWeek
599 : * an integer in the range 1=Sunday to 7=Saturday indicating the day
600 : * considered the first day of the week in calendars, e.g. 1 for en-US,
601 : * 2 for en-GB, 1 for bn-IN
602 : * minDays
603 : * an integer in the range of 1 to 7 indicating the minimum number
604 : * of days required in the first week of the year, e.g. 1 for en-US, 4 for de
605 : * weekendStart
606 : * an integer in the range 1=Sunday to 7=Saturday indicating the day
607 : * considered the beginning of a weekend, e.g. 7 for en-US, 7 for en-GB,
608 : * 1 for bn-IN
609 : * weekendEnd
610 : * an integer in the range 1=Sunday to 7=Saturday indicating the day
611 : * considered the end of a weekend, e.g. 1 for en-US, 1 for en-GB,
612 : * 1 for bn-IN (note that "weekend" is *not* necessarily two days)
613 : *
614 : * NOTE: "calendar" and "locale" properties are *not* added to the object.
615 : */
616 : extern MOZ_MUST_USE bool
617 : intl_GetCalendarInfo(JSContext* cx, unsigned argc, Value* vp);
618 :
619 : /**
620 : * Returns a plain object with locale information for a single valid locale
621 : * (callers must perform this validation). The object will have these
622 : * properties:
623 : *
624 : * direction
625 : * a string with a value "ltr" for left-to-right locale, and "rtl" for
626 : * right-to-left locale.
627 : * locale
628 : * a BCP47 compilant locale string for the resolved locale.
629 : */
630 : extern MOZ_MUST_USE bool
631 : intl_GetLocaleInfo(JSContext* cx, unsigned argc, Value* vp);
632 :
633 : /**
634 : * Returns an Array with CLDR-based fields display names.
635 : * The function takes three arguments:
636 : *
637 : * locale
638 : * BCP47 compliant locale string
639 : * style
640 : * A string with values: long or short or narrow
641 : * keys
642 : * An array or path-like strings that identify keys to be returned
643 : * At the moment the following types of keys are supported:
644 : *
645 : * 'dates/fields/{year|month|week|day}'
646 : * 'dates/gregorian/months/{january|...|december}'
647 : * 'dates/gregorian/weekdays/{sunday|...|saturday}'
648 : * 'dates/gregorian/dayperiods/{am|pm}'
649 : *
650 : * Example:
651 : *
652 : * let info = intl_ComputeDisplayNames(
653 : * 'en-US',
654 : * 'long',
655 : * [
656 : * 'dates/fields/year',
657 : * 'dates/gregorian/months/january',
658 : * 'dates/gregorian/weekdays/monday',
659 : * 'dates/gregorian/dayperiods/am',
660 : * ]
661 : * );
662 : *
663 : * Returned value:
664 : *
665 : * [
666 : * 'year',
667 : * 'January',
668 : * 'Monday',
669 : * 'AM'
670 : * ]
671 : */
672 : extern MOZ_MUST_USE bool
673 : intl_ComputeDisplayNames(JSContext* cx, unsigned argc, Value* vp);
674 :
675 :
676 : /******************** String ********************/
677 :
678 : /**
679 : * Returns the input string converted to lower case based on the language
680 : * specific case mappings for the input locale.
681 : *
682 : * Usage: lowerCase = intl_toLocaleLowerCase(string, locale)
683 : */
684 : extern MOZ_MUST_USE bool
685 : intl_toLocaleLowerCase(JSContext* cx, unsigned argc, Value* vp);
686 :
687 : /**
688 : * Returns the input string converted to upper case based on the language
689 : * specific case mappings for the input locale.
690 : *
691 : * Usage: upperCase = intl_toLocaleUpperCase(string, locale)
692 : */
693 : extern MOZ_MUST_USE bool
694 : intl_toLocaleUpperCase(JSContext* cx, unsigned argc, Value* vp);
695 :
696 :
697 : } // namespace js
698 :
699 : #endif /* builtin_Intl_h */
|