tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ListFormat.h (2123B)


      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 <stdint.h>
     11 
     12 #include "builtin/SelfHostingDefines.h"
     13 #include "js/Class.h"
     14 #include "js/TypeDecls.h"
     15 #include "vm/NativeObject.h"
     16 
     17 namespace mozilla::intl {
     18 class ListFormat;
     19 }  // namespace mozilla::intl
     20 
     21 namespace js {
     22 
     23 class ListFormatObject : public NativeObject {
     24 public:
     25  static const JSClass class_;
     26  static const JSClass& protoClass_;
     27 
     28  static constexpr uint32_t INTERNALS_SLOT = 0;
     29  static constexpr uint32_t LIST_FORMAT_SLOT = 1;
     30  static constexpr uint32_t SLOT_COUNT = 2;
     31 
     32  static_assert(INTERNALS_SLOT == INTL_INTERNALS_OBJECT_SLOT,
     33                "INTERNALS_SLOT must match self-hosting define for internals "
     34                "object slot");
     35 
     36  // Estimated memory use for UListFormatter (see IcuMemoryUsage).
     37  static constexpr size_t EstimatedMemoryUse = 24;
     38 
     39  mozilla::intl::ListFormat* getListFormatSlot() const {
     40    const auto& slot = getFixedSlot(LIST_FORMAT_SLOT);
     41    if (slot.isUndefined()) {
     42      return nullptr;
     43    }
     44    return static_cast<mozilla::intl::ListFormat*>(slot.toPrivate());
     45  }
     46 
     47  void setListFormatSlot(mozilla::intl::ListFormat* format) {
     48    setFixedSlot(LIST_FORMAT_SLOT, PrivateValue(format));
     49  }
     50 
     51 private:
     52  static const JSClassOps classOps_;
     53  static const ClassSpec classSpec_;
     54 
     55  static void finalize(JS::GCContext* gcx, JSObject* obj);
     56 };
     57 
     58 /**
     59 * Returns a string representing the array of string values |list| according to
     60 * the effective locale and the formatting options of the given ListFormat.
     61 *
     62 * Usage: formatted = intl_FormatList(listFormat, list, formatToParts)
     63 */
     64 [[nodiscard]] extern bool intl_FormatList(JSContext* cx, unsigned argc,
     65                                          Value* vp);
     66 
     67 }  // namespace js
     68 
     69 #endif /* builtin_intl_ListFormat_h */