Bug 1885489 - Part 5: Add SnapshotIterator::readInt32(). r=iain
[gecko.git] / js / src / builtin / intl / DisplayNames.h
blob9fd6c63a628461fda639c1b2a744264611229c71
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
10 #include <stddef.h>
11 #include <stdint.h>
13 #include "jstypes.h"
14 #include "NamespaceImports.h"
16 #include "builtin/SelfHostingDefines.h"
17 #include "js/Class.h" // JSClass, JSClassOps, js::ClassSpec
18 #include "js/TypeDecls.h"
19 #include "js/Value.h"
20 #include "vm/NativeObject.h"
22 struct JS_PUBLIC_API JSContext;
24 namespace mozilla::intl {
25 class DisplayNames;
28 namespace js {
29 struct ClassSpec;
31 class DisplayNamesObject : public NativeObject {
32 public:
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 "
42 "object slot");
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()) {
50 return nullptr;
52 return static_cast<mozilla::intl::DisplayNames*>(slot.toPrivate());
55 void setDisplayNames(mozilla::intl::DisplayNames* displayNames) {
56 setFixedSlot(LOCALE_DISPLAY_NAMES_SLOT, PrivateValue(displayNames));
59 private:
60 static const JSClassOps classOps_;
61 static const ClassSpec classSpec_;
63 static void finalize(JS::GCContext* gcx, JSObject* obj);
66 /**
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,
72 * type, code)
74 [[nodiscard]] extern bool intl_ComputeDisplayName(JSContext* cx, unsigned argc,
75 Value* vp);
77 } // namespace js
79 #endif /* builtin_intl_DisplayNames_h */