Debian Codegraph @

js/src/builtin/intl/DisplayNames.h

raw
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/. */
6
7 #ifndef builtin_intl_DisplayNames_h
8 #define builtin_intl_DisplayNames_h
9
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include "jstypes.h"
14 #include "NamespaceImports.h"
15
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"
21
22 struct JS_PUBLIC_API JSContext;
23
24 namespace mozilla::intl {
25 class DisplayNames;
26 }
27
28 namespace js {
29 struct ClassSpec;
30
31 class DisplayNamesObject : public NativeObject {
32 public:
33 static const JSClass class_;
34 static const JSClass& protoClass_;
35
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;
39
40 static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
41 "INTERNALS_SLOT must match self-hosting define for internals "
42 "object slot");
43
44 // Estimated memory use for ULocaleDisplayNames (see IcuMemoryUsage).
45 static constexpr size_t EstimatedMemoryUse = 1238;
46
47 mozilla::intl::DisplayNames* getDisplayNames() const {
48 const auto& slot = getFixedSlot(LOCALE_DISPLAY_NAMES_SLOT);
49 if (slot.isUndefined()) {
50 return nullptr;
51 }
52 return static_cast<mozilla::intl::DisplayNames*>(slot.toPrivate());
53 }
54
55 void setDisplayNames(mozilla::intl::DisplayNames* displayNames) {
56 setFixedSlot(LOCALE_DISPLAY_NAMES_SLOT, PrivateValue(displayNames));
57 }
58
59 private:
60 static const JSClassOps classOps_;
61 static const ClassSpec classSpec_;
62
63 static void finalize(JS::GCContext* gcx, JSObject* obj);
64 };
65
66 /**
67 * Return the display name for the requested code or undefined if no applicable
68 * display name was found.
69 *
70 * Usage: result = intl_ComputeDisplayName(displayNames, locale, calendar,
71 * style, languageDisplay, fallback,
72 * type, code)
73 */
74 [[nodiscard]] extern bool intl_ComputeDisplayName(JSContext* cx, unsigned argc,
75 Value* vp);
76
77 } // namespace js
78
79 #endif /* builtin_intl_DisplayNames_h */