From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- js/src/builtin/intl/CommonFunctions.h | 109 ++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 js/src/builtin/intl/CommonFunctions.h (limited to 'js/src/builtin/intl/CommonFunctions.h') diff --git a/js/src/builtin/intl/CommonFunctions.h b/js/src/builtin/intl/CommonFunctions.h new file mode 100644 index 0000000000..cf7fd4038d --- /dev/null +++ b/js/src/builtin/intl/CommonFunctions.h @@ -0,0 +1,109 @@ +/* -*- 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/. */ + +#ifndef builtin_intl_CommonFunctions_h +#define builtin_intl_CommonFunctions_h + +#include +#include + +#include "js/RootingAPI.h" +#include "js/Utility.h" + +namespace mozilla::intl { +enum class ICUError : uint8_t; +} + +namespace js { + +class PropertyName; + +namespace intl { + +/** + * Initialize a new Intl.* object using the named self-hosted function. + */ +extern bool InitializeObject(JSContext* cx, JS::Handle obj, + JS::Handle initializer, + JS::Handle locales, + JS::Handle options); + +enum class DateTimeFormatOptions { + Standard, + EnableMozExtensions, +}; + +/** + * Initialize an existing object as an Intl.DateTimeFormat object. + */ +extern bool InitializeDateTimeFormatObject( + JSContext* cx, JS::Handle obj, JS::Handle thisValue, + JS::Handle locales, JS::Handle options, + JS::Handle required, JS::Handle defaults, + DateTimeFormatOptions dtfOptions, JS::MutableHandle result); + +/** + * Initialize an existing object as an Intl.NumberFormat object. + */ +extern bool InitializeNumberFormatObject(JSContext* cx, + JS::Handle obj, + JS::Handle thisValue, + JS::Handle locales, + JS::Handle options, + JS::MutableHandle result); + +/** + * Returns the object holding the internal properties for obj. + */ +extern JSObject* GetInternalsObject(JSContext* cx, JS::Handle obj); + +/** Report an Intl internal error not directly tied to a spec step. */ +extern void ReportInternalError(JSContext* cx); + +/** Report an Intl internal error not directly tied to a spec step. */ +extern void ReportInternalError(JSContext* cx, mozilla::intl::ICUError error); + +/** + * The last-ditch locale is used if none of the available locales satisfies a + * request. "en-GB" is used based on the assumptions that English is the most + * common second language, that both en-GB and en-US are normally available in + * an implementation, and that en-GB is more representative of the English used + * in other locales. + */ +static inline const char* LastDitchLocale() { return "en-GB"; } + +/** + * Certain old, commonly-used language tags that lack a script, are expected to + * nonetheless imply one. This object maps these old-style tags to modern + * equivalents. + */ +struct OldStyleLanguageTagMapping { + const char* const oldStyle; + const char* const modernStyle; + + // Provide a constructor to catch missing initializers in the mappings array. + constexpr OldStyleLanguageTagMapping(const char* oldStyle, + const char* modernStyle) + : oldStyle(oldStyle), modernStyle(modernStyle) {} +}; + +extern const OldStyleLanguageTagMapping oldStyleLanguageTagMappings[5]; + +extern JS::UniqueChars EncodeLocale(JSContext* cx, JSString* locale); + +// The inline capacity we use for a Vector. Use this to ensure that +// our uses of ICU string functions, below and elsewhere, will try to fill the +// buffer's entire inline capacity before growing it and heap-allocating. +constexpr size_t INITIAL_CHAR_BUFFER_SIZE = 32; + +void AddICUCellMemory(JSObject* obj, size_t nbytes); + +void RemoveICUCellMemory(JS::GCContext* gcx, JSObject* obj, size_t nbytes); +} // namespace intl + +} // namespace js + +#endif /* builtin_intl_CommonFunctions_h */ -- cgit v1.2.3