/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef builtin_intl_ListFormat_h #define builtin_intl_ListFormat_h #include #include #include "js/Class.h" #include "js/TypeDecls.h" #include "js/Value.h" #include "vm/NativeObject.h" #include "vm/StringType.h" namespace mozilla::intl { class ListFormat; } // namespace mozilla::intl namespace js::intl { struct ListFormatOptions; class ListFormatObject : public NativeObject { public: static const JSClass class_; static const JSClass& protoClass_; JS_DEFINE_TYPED_SLOT(0, LOCALE, Object, String, Undefined); JS_DEFINE_TYPED_SLOT(1, OPTIONS, Int32, Undefined); JS_DEFINE_TYPED_SLOT(2, LIST_FORMAT_SLOT, Private, Undefined); static constexpr uint32_t SLOT_COUNT = 3; // Estimated memory use for UListFormatter (see IcuMemoryUsage). static constexpr size_t EstimatedMemoryUse = 24; bool isLocaleResolved() const { return getFixedSlotTyped(LOCALE).isString(); } JSObject* getRequestedLocales() const { const auto& slot = getFixedSlotTyped(LOCALE); if (slot.isUndefined()) { return nullptr; } return &slot.toObject(); } void setRequestedLocales(JSObject* requestedLocales) { setFixedSlotTyped(LOCALE, JS::ObjectValue(*requestedLocales)); } JSLinearString* getLocale() const { const auto& slot = getFixedSlotTyped(LOCALE); if (slot.isUndefined()) { return nullptr; } return &slot.toString()->asLinear(); } void setLocale(JSLinearString* locale) { setFixedSlotTyped(LOCALE, JS::StringValue(locale)); } ListFormatOptions getOptions() const; void setOptions(const ListFormatOptions& options); mozilla::intl::ListFormat* getListFormatSlot() const { const auto& slot = getFixedSlotTyped(LIST_FORMAT_SLOT); if (slot.isUndefined()) { return nullptr; } return static_cast(slot.toPrivate()); } void setListFormatSlot(mozilla::intl::ListFormat* format) { setFixedSlotTyped(LIST_FORMAT_SLOT, JS::PrivateValue(format)); } private: static const JSClassOps classOps_; static const ClassSpec classSpec_; static void finalize(JS::GCContext* gcx, JSObject* obj); }; } // namespace js::intl #endif /* builtin_intl_ListFormat_h */