Source code

Revision control

Other Tools

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_ListFormat_h
8
#define builtin_intl_ListFormat_h
9
10
#include "mozilla/Attributes.h"
11
12
#include <stdint.h>
13
14
#include "builtin/SelfHostingDefines.h"
15
#include "js/Class.h"
16
#include "js/RootingAPI.h"
17
#include "vm/NativeObject.h"
18
19
class JSFreeOp;
20
struct UListFormatter;
21
22
namespace js {
23
24
class ListFormatObject : 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 ULIST_FORMATTER_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 UListFormatter.
38
static constexpr size_t EstimatedMemoryUse = 24;
39
40
UListFormatter* getListFormatter() const {
41
const auto& slot = getFixedSlot(ULIST_FORMATTER_SLOT);
42
if (slot.isUndefined()) {
43
return nullptr;
44
}
45
return static_cast<UListFormatter*>(slot.toPrivate());
46
}
47
48
void setListFormatter(UListFormatter* formatter) {
49
setFixedSlot(ULIST_FORMATTER_SLOT, PrivateValue(formatter));
50
}
51
52
private:
53
static const JSClassOps classOps_;
54
static const ClassSpec classSpec_;
55
56
static void finalize(JSFreeOp* fop, JSObject* obj);
57
};
58
59
/**
60
* Returns a string representing the array of string values |list| according to
61
* the effective locale and the formatting options of the given ListFormat.
62
*
63
* Usage: formatted = intl_FormatList(listFormat, list, formatToParts)
64
*/
65
extern MOZ_MUST_USE bool intl_FormatList(JSContext* cx, unsigned argc,
66
Value* vp);
67
68
} // namespace js
69
70
#endif /* builtin_intl_ListFormat_h */