1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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/. */
7 #ifndef builtin_intl_DisplayNames_h
8 #define builtin_intl_DisplayNames_h
14 #include "NamespaceImports.h"
16 #include "builtin/SelfHostingDefines.h"
17 #include "js/Class.h" // JSClass, JSClassOps, js::ClassSpec
18 #include "js/TypeDecls.h"
20 #include "vm/NativeObject.h"
22 struct JS_PUBLIC_API JSContext
;
24 namespace mozilla::intl
{
31 class DisplayNamesObject
: public NativeObject
{
33 static const JSClass class_
;
34 static const JSClass
& protoClass_
;
36 static constexpr uint32_t INTERNALS_SLOT
= 0;
37 static constexpr uint32_t LOCALE_DISPLAY_NAMES_SLOT
= 1;
38 static constexpr uint32_t SLOT_COUNT
= 3;
40 static_assert(INTERNALS_SLOT
== INTL_INTERNALS_OBJECT_SLOT
,
41 "INTERNALS_SLOT must match self-hosting define for internals "
44 // Estimated memory use for ULocaleDisplayNames (see IcuMemoryUsage).
45 static constexpr size_t EstimatedMemoryUse
= 1238;
47 mozilla::intl::DisplayNames
* getDisplayNames() const {
48 const auto& slot
= getFixedSlot(LOCALE_DISPLAY_NAMES_SLOT
);
49 if (slot
.isUndefined()) {
52 return static_cast<mozilla::intl::DisplayNames
*>(slot
.toPrivate());
55 void setDisplayNames(mozilla::intl::DisplayNames
* displayNames
) {
56 setFixedSlot(LOCALE_DISPLAY_NAMES_SLOT
, PrivateValue(displayNames
));
60 static const JSClassOps classOps_
;
61 static const ClassSpec classSpec_
;
63 static void finalize(JS::GCContext
* gcx
, JSObject
* obj
);
67 * Return the display name for the requested code or undefined if no applicable
68 * display name was found.
70 * Usage: result = intl_ComputeDisplayName(displayNames, locale, calendar,
71 * style, languageDisplay, fallback,
74 [[nodiscard
]] extern bool intl_ComputeDisplayName(JSContext
* cx
, unsigned argc
,
79 #endif /* builtin_intl_DisplayNames_h */