Debian Codegraph @

js/src/builtin/intl/Locale.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_Locale_h
8 #define builtin_intl_Locale_h
9
10 #include <stdint.h>
11
12 #include "js/Class.h"
13 #include "vm/NativeObject.h"
14
15 namespace js {
16
17 class LocaleObject : public NativeObject {
18 public:
19 static const JSClass class_;
20 static const JSClass& protoClass_;
21
22 static constexpr uint32_t LANGUAGE_TAG_SLOT = 0;
23 static constexpr uint32_t BASENAME_SLOT = 1;
24 static constexpr uint32_t UNICODE_EXTENSION_SLOT = 2;
25 static constexpr uint32_t SLOT_COUNT = 3;
26
27 /**
28 * Returns the complete language tag, including any extensions and privateuse
29 * subtags.
30 */
31 JSString* languageTag() const {
32 return getFixedSlot(LANGUAGE_TAG_SLOT).toString();
33 }
34
35 /**
36 * Returns the basename subtags, i.e. excluding any extensions and privateuse
37 * subtags.
38 */
39 JSString* baseName() const { return getFixedSlot(BASENAME_SLOT).toString(); }
40
41 const Value& unicodeExtension() const {
42 return getFixedSlot(UNICODE_EXTENSION_SLOT);
43 }
44
45 private:
46 static const ClassSpec classSpec_;
47 };
48
49 [[nodiscard]] extern bool intl_ValidateAndCanonicalizeLanguageTag(JSContext* cx,
50 unsigned argc,
51 Value* vp);
52
53 [[nodiscard]] extern bool intl_TryValidateAndCanonicalizeLanguageTag(
54 JSContext* cx, unsigned argc, Value* vp);
55
56 [[nodiscard]] extern bool intl_ValidateAndCanonicalizeUnicodeExtensionType(
57 JSContext* cx, unsigned argc, Value* vp);
58
59 } // namespace js
60
61 #endif /* builtin_intl_Locale_h */