| 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_Collator_h |
| 8 |
#define builtin_intl_Collator_h |
| 9 |
|
| 10 |
#include <stdint.h> |
| 11 |
|
| 12 |
#include "builtin/SelfHostingDefines.h" |
| 13 |
#include "js/Class.h" |
| 14 |
#include "vm/NativeObject.h" |
| 15 |
|
| 16 |
namespace mozilla::intl { |
| 17 |
class Collator; |
| 18 |
} |
| 19 |
|
| 20 |
namespace js { |
| 21 |
|
| 22 |
/******************** Collator ********************/ |
| 23 |
|
| 24 |
class CollatorObject : public NativeObject { |
| 25 |
public: |
| 26 |
static const JSClass class_; |
| 27 |
static const JSClass& protoClass_; |
| 28 |
|
| 29 |
static constexpr uint32_t INTERNALS_SLOT = 0; |
| 30 |
static constexpr uint32_t INTL_COLLATOR_SLOT = 1; |
| 31 |
static constexpr uint32_t SLOT_COUNT = 2; |
| 32 |
|
| 33 |
static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT, |
| 34 |
"INTERNALS_SLOT must match self-hosting define for internals " |
| 35 |
"object slot"); |
| 36 |
|
| 37 |
// Estimated memory use for UCollator (see IcuMemoryUsage). |
| 38 |
static constexpr size_t EstimatedMemoryUse = 1128; |
| 39 |
|
| 40 |
mozilla::intl::Collator* getCollator() const { |
| 41 |
const auto& slot = getFixedSlot(INTL_COLLATOR_SLOT); |
| 42 |
if (slot.isUndefined()) { |
| 43 |
return nullptr; |
| 44 |
} |
| 45 |
return static_cast<mozilla::intl::Collator*>(slot.toPrivate()); |
| 46 |
} |
| 47 |
|
| 48 |
void setCollator(mozilla::intl::Collator* collator) { |
| 49 |
setFixedSlot(INTL_COLLATOR_SLOT, PrivateValue(collator)); |
| 50 |
} |
| 51 |
|
| 52 |
private: |
| 53 |
static const JSClassOps classOps_; |
| 54 |
static const ClassSpec classSpec_; |
| 55 |
|
| 56 |
static void finalize(JS::GCContext* gcx, JSObject* obj); |
| 57 |
}; |
| 58 |
|
| 59 |
/** |
| 60 |
* Returns a new instance of the standard built-in Collator constructor. |
| 61 |
* |
| 62 |
* Usage: collator = intl_Collator(locales, options) |
| 63 |
*/ |
| 64 |
[[nodiscard]] extern bool intl_Collator(JSContext* cx, unsigned argc, |
| 65 |
JS::Value* vp); |
| 66 |
|
| 67 |
/** |
| 68 |
* Returns an array with the collation type identifiers per Unicode |
| 69 |
* Technical Standard 35, Unicode Locale Data Markup Language, for the |
| 70 |
* collations supported for the given locale. "standard" and "search" are |
| 71 |
* excluded. |
| 72 |
* |
| 73 |
* Usage: collations = intl_availableCollations(locale) |
| 74 |
*/ |
| 75 |
[[nodiscard]] extern bool intl_availableCollations(JSContext* cx, unsigned argc, |
| 76 |
JS::Value* vp); |
| 77 |
|
| 78 |
/** |
| 79 |
* Compares x and y (which must be String values), and returns a number less |
| 80 |
* than 0 if x < y, 0 if x = y, or a number greater than 0 if x > y according |
| 81 |
* to the sort order for the locale and collation options of the given |
| 82 |
* Collator. |
| 83 |
* |
| 84 |
* Spec: ECMAScript Internationalization API Specification, 10.3.2. |
| 85 |
* |
| 86 |
* Usage: result = intl_CompareStrings(collator, x, y) |
| 87 |
*/ |
| 88 |
[[nodiscard]] extern bool intl_CompareStrings(JSContext* cx, unsigned argc, |
| 89 |
JS::Value* vp); |
| 90 |
|
| 91 |
/** |
| 92 |
* Returns true if the given locale sorts upper-case before lower-case |
| 93 |
* characters. |
| 94 |
* |
| 95 |
* Usage: result = intl_isUpperCaseFirst(locale) |
| 96 |
*/ |
| 97 |
[[nodiscard]] extern bool intl_isUpperCaseFirst(JSContext* cx, unsigned argc, |
| 98 |
JS::Value* vp); |
| 99 |
|
| 100 |
/** |
| 101 |
* Returns true if the given locale ignores punctuation by default. |
| 102 |
* |
| 103 |
* Usage: result = intl_isIgnorePunctuation(locale) |
| 104 |
*/ |
| 105 |
[[nodiscard]] extern bool intl_isIgnorePunctuation(JSContext* cx, unsigned argc, |
| 106 |
JS::Value* vp); |
| 107 |
|
| 108 |
} // namespace js |
| 109 |
|
| 110 |
#endif /* builtin_intl_Collator_h */ |