From 7e7461d1f306390ecc2e37d56885ec6ae3cf5ab0 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 3 Sep 2024 11:54:16 -0700 Subject: [PATCH] diplomatup --- Cargo.lock | 29 ++-- Cargo.toml | 8 +- ffi/capi/bindings/js/AnyCalendarKind.mjs | 91 ++++++---- ffi/capi/bindings/js/Bidi.mjs | 14 +- ffi/capi/bindings/js/BidiDirection.mjs | 40 +++-- ffi/capi/bindings/js/BidiParagraph.mjs | 2 +- ffi/capi/bindings/js/Calendar.mjs | 6 +- ffi/capi/bindings/js/CalendarError.mjs | 43 +++-- ffi/capi/bindings/js/CalendarParseError.mjs | 44 +++-- .../js/CanonicalCombiningClassMap.mjs | 2 +- ffi/capi/bindings/js/CanonicalComposition.mjs | 2 +- .../bindings/js/CanonicalDecomposition.mjs | 2 +- ffi/capi/bindings/js/CaseMapCloser.mjs | 6 +- ffi/capi/bindings/js/CaseMapper.mjs | 22 +-- ffi/capi/bindings/js/CodePointMapData16.mjs | 2 +- ffi/capi/bindings/js/CodePointMapData8.mjs | 20 +-- .../bindings/js/CodePointRangeIterator.mjs | 2 +- .../js/CodePointRangeIteratorResult.mjs | 13 +- ffi/capi/bindings/js/CodePointSetData.mjs | 138 ++++++++-------- ffi/capi/bindings/js/Collator.mjs | 8 +- .../bindings/js/CollatorAlternateHandling.mjs | 40 +++-- .../js/CollatorBackwardSecondLevel.mjs | 40 +++-- ffi/capi/bindings/js/CollatorCaseFirst.mjs | 43 +++-- ffi/capi/bindings/js/CollatorCaseLevel.mjs | 40 +++-- ffi/capi/bindings/js/CollatorMaxVariable.mjs | 44 +++-- ffi/capi/bindings/js/CollatorNumeric.mjs | 40 +++-- ffi/capi/bindings/js/CollatorOptions.mjs | 29 +++- .../bindings/js/CollatorResolvedOptions.mjs | 29 +++- ffi/capi/bindings/js/CollatorStrength.mjs | 47 ++++-- ffi/capi/bindings/js/ComposingNormalizer.mjs | 16 +- ffi/capi/bindings/js/CustomTimeZone.mjs | 20 +-- ffi/capi/bindings/js/DataError.mjs | 56 +++++-- ffi/capi/bindings/js/DataProvider.mjs | 6 +- ffi/capi/bindings/js/Date.mjs | 18 +- ffi/capi/bindings/js/DateFormatter.mjs | 10 +- ffi/capi/bindings/js/DateLength.mjs | 43 +++-- ffi/capi/bindings/js/DateTime.mjs | 18 +- ffi/capi/bindings/js/DateTimeFormatter.mjs | 6 +- ffi/capi/bindings/js/Decomposed.mjs | 10 ++ .../bindings/js/DecomposingNormalizer.mjs | 24 +-- ffi/capi/bindings/js/DisplayNamesFallback.mjs | 35 ++-- ffi/capi/bindings/js/DisplayNamesOptions.mjs | 17 +- ffi/capi/bindings/js/DisplayNamesStyle.mjs | 44 +++-- ffi/capi/bindings/js/Error.mjs | 93 +++++++---- ffi/capi/bindings/js/FixedDecimal.mjs | 8 +- .../bindings/js/FixedDecimalFormatter.mjs | 20 +-- .../js/FixedDecimalGroupingStrategy.mjs | 43 +++-- .../bindings/js/FixedDecimalParseError.mjs | 40 +++-- .../js/FixedDecimalRoundingIncrement.mjs | 43 +++-- .../bindings/js/FixedDecimalRoundingMode.mjs | 56 +++++-- ffi/capi/bindings/js/FixedDecimalSign.mjs | 40 +++-- .../bindings/js/FixedDecimalSignDisplay.mjs | 44 +++-- .../js/GeneralCategoryNameToMaskMapper.mjs | 10 +- .../bindings/js/GraphemeClusterSegmenter.mjs | 10 +- .../bindings/js/GregorianDateFormatter.mjs | 2 +- .../js/GregorianDateTimeFormatter.mjs | 2 +- .../js/GregorianZonedDateTimeFormatter.mjs | 4 +- ffi/capi/bindings/js/IsoDate.mjs | 10 +- ffi/capi/bindings/js/IsoDateTime.mjs | 10 +- ffi/capi/bindings/js/IsoTimeZoneFormat.mjs | 43 +++-- .../bindings/js/IsoTimeZoneMinuteDisplay.mjs | 35 ++-- ffi/capi/bindings/js/IsoTimeZoneOptions.mjs | 17 +- .../bindings/js/IsoTimeZoneSecondDisplay.mjs | 35 ++-- ffi/capi/bindings/js/IsoWeekday.mjs | 54 ++++-- ffi/capi/bindings/js/LanguageDisplay.mjs | 35 ++-- ffi/capi/bindings/js/LeadingAdjustment.mjs | 40 +++-- ffi/capi/bindings/js/LineBreakOptions.mjs | 17 +- ffi/capi/bindings/js/LineBreakStrictness.mjs | 43 +++-- ffi/capi/bindings/js/LineBreakWordOption.mjs | 40 +++-- ffi/capi/bindings/js/LineSegmenter.mjs | 20 +-- ffi/capi/bindings/js/ListFormatter.mjs | 10 +- ffi/capi/bindings/js/ListLength.mjs | 40 +++-- ffi/capi/bindings/js/Locale.mjs | 42 ++--- ffi/capi/bindings/js/LocaleCanonicalizer.mjs | 6 +- ffi/capi/bindings/js/LocaleDirection.mjs | 40 +++-- ffi/capi/bindings/js/LocaleDirectionality.mjs | 6 +- .../js/LocaleDisplayNamesFormatter.mjs | 2 +- ffi/capi/bindings/js/LocaleExpander.mjs | 10 +- ffi/capi/bindings/js/LocaleFallbackConfig.mjs | 11 +- .../bindings/js/LocaleFallbackPriority.mjs | 35 ++-- ffi/capi/bindings/js/LocaleFallbacker.mjs | 2 +- ffi/capi/bindings/js/LocaleParseError.mjs | 43 +++-- ffi/capi/bindings/js/MeasureUnitParser.mjs | 4 +- ffi/capi/bindings/js/MetazoneCalculator.mjs | 2 +- ffi/capi/bindings/js/PluralCategories.mjs | 14 ++ ffi/capi/bindings/js/PluralCategory.mjs | 53 ++++-- ffi/capi/bindings/js/PluralOperands.mjs | 6 +- ffi/capi/bindings/js/PluralRules.mjs | 6 +- .../js/PropertyValueNameToEnumMapper.mjs | 28 ++-- ffi/capi/bindings/js/RegionDisplayNames.mjs | 8 +- ffi/capi/bindings/js/ScriptWithExtensions.mjs | 2 +- ffi/capi/bindings/js/SegmenterWordType.mjs | 38 +++-- ffi/capi/bindings/js/SentenceSegmenter.mjs | 10 +- ffi/capi/bindings/js/Time.mjs | 10 +- ffi/capi/bindings/js/TimeFormatter.mjs | 2 +- ffi/capi/bindings/js/TimeLength.mjs | 43 +++-- ffi/capi/bindings/js/TimeZoneFormatter.mjs | 20 +-- ffi/capi/bindings/js/TimeZoneIdMapper.mjs | 18 +- ...meZoneIdMapperWithFastCanonicalization.mjs | 10 +- ffi/capi/bindings/js/TitlecaseMapper.mjs | 6 +- ffi/capi/bindings/js/TitlecaseOptions.mjs | 14 +- ffi/capi/bindings/js/TrailingCase.mjs | 35 ++-- ffi/capi/bindings/js/TransformResult.mjs | 35 ++-- ffi/capi/bindings/js/UnicodeSetData.mjs | 16 +- .../bindings/js/UnitsConverterFactory.mjs | 2 +- ffi/capi/bindings/js/WeekCalculator.mjs | 4 +- ffi/capi/bindings/js/WeekOf.mjs | 21 ++- ffi/capi/bindings/js/WeekRelativeUnit.mjs | 40 +++-- ffi/capi/bindings/js/WeekendContainsDay.mjs | 15 ++ .../bindings/js/WordBreakIteratorLatin1.mjs | 2 +- .../bindings/js/WordBreakIteratorUtf16.mjs | 2 +- .../bindings/js/WordBreakIteratorUtf8.mjs | 2 +- ffi/capi/bindings/js/WordSegmenter.mjs | 14 +- .../bindings/js/ZonedDateTimeFormatter.mjs | 8 +- ffi/capi/bindings/js/diplomat-runtime.mjs | 156 ++++++++++++++++-- tutorials/cpp/Cargo.lock | 21 +-- 116 files changed, 1943 insertions(+), 954 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66f430b1609..57f4756704b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,12 +252,6 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.6.0" @@ -619,7 +613,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=0183677b4bc25fc762ec06a4665c4f384998fb50#0183677b4bc25fc762ec06a4665c4f384998fb50" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "diplomat_core", "proc-macro2", @@ -649,7 +643,7 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.8.1" -source = "git+https://github.com/rust-diplomat/diplomat?rev=0183677b4bc25fc762ec06a4665c4f384998fb50#0183677b4bc25fc762ec06a4665c4f384998fb50" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "log", ] @@ -657,7 +651,7 @@ dependencies = [ [[package]] name = "diplomat-tool" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=0183677b4bc25fc762ec06a4665c4f384998fb50#0183677b4bc25fc762ec06a4665c4f384998fb50" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "askama", "clap", @@ -677,7 +671,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=0183677b4bc25fc762ec06a4665c4f384998fb50#0183677b4bc25fc762ec06a4665c4f384998fb50" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "displaydoc", "either", @@ -2223,16 +2217,23 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.8.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" +checksum = "cb4e75767fbc9d92b90e4d0c011f61358cde9513b31ef07ea3631b15ffc3b4fd" dependencies = [ - "bitflags 1.3.2", + "bitflags", "getopts", "memchr", + "pulldown-cmark-escape", "unicase", ] +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + [[package]] name = "quote" version = "1.0.36" @@ -2329,7 +2330,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 2.6.0", + "bitflags", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 82aa293face..dcb71dc9f0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -209,10 +209,10 @@ icu_benchmark_macros = { path = "tools/benchmark/macros" } # The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."` # Diplomat must be published preceding a new ICU4X release but may use git versions in between -diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "0183677b4bc25fc762ec06a4665c4f384998fb50" } -diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "0183677b4bc25fc762ec06a4665c4f384998fb50" } -diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "0183677b4bc25fc762ec06a4665c4f384998fb50" } -diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "0183677b4bc25fc762ec06a4665c4f384998fb50" } +diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "9e91151698bc5df511c42d95f57ea8133478b24e" } +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "9e91151698bc5df511c42d95f57ea8133478b24e" } +diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "9e91151698bc5df511c42d95f57ea8133478b24e" } +diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "9e91151698bc5df511c42d95f57ea8133478b24e" } # EXTERNAL DEPENDENCIES # diff --git a/ffi/capi/bindings/js/AnyCalendarKind.mjs b/ffi/capi/bindings/js/AnyCalendarKind.mjs index 56d2399c260..d3f22423eb1 100644 --- a/ffi/capi/bindings/js/AnyCalendarKind.mjs +++ b/ffi/capi/bindings/js/AnyCalendarKind.mjs @@ -11,7 +11,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class AnyCalendarKind { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Iso", 0], ["Gregorian", 1], ["Buddhist", 2], @@ -33,45 +33,76 @@ export class AnyCalendarKind { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return AnyCalendarKind.#objectValues[arguments[1]]; + } + if (value instanceof AnyCalendarKind) { - this.#value = value.value; - return; + return value; } - if (AnyCalendarKind.values.has(value)) { - this.#value = value; - return; + let intVal = AnyCalendarKind.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return AnyCalendarKind.#objectValues[intVal]; } throw TypeError(value + " is not a AnyCalendarKind and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...AnyCalendarKind.#values.keys()][this.#value]; } get ffiValue() { - return AnyCalendarKind.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16), + new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17), + ]; - static Iso = new AnyCalendarKind("Iso"); - static Gregorian = new AnyCalendarKind("Gregorian"); - static Buddhist = new AnyCalendarKind("Buddhist"); - static Japanese = new AnyCalendarKind("Japanese"); - static JapaneseExtended = new AnyCalendarKind("JapaneseExtended"); - static Ethiopian = new AnyCalendarKind("Ethiopian"); - static EthiopianAmeteAlem = new AnyCalendarKind("EthiopianAmeteAlem"); - static Indian = new AnyCalendarKind("Indian"); - static Coptic = new AnyCalendarKind("Coptic"); - static Dangi = new AnyCalendarKind("Dangi"); - static Chinese = new AnyCalendarKind("Chinese"); - static Hebrew = new AnyCalendarKind("Hebrew"); - static IslamicCivil = new AnyCalendarKind("IslamicCivil"); - static IslamicObservational = new AnyCalendarKind("IslamicObservational"); - static IslamicTabular = new AnyCalendarKind("IslamicTabular"); - static IslamicUmmAlQura = new AnyCalendarKind("IslamicUmmAlQura"); - static Persian = new AnyCalendarKind("Persian"); - static Roc = new AnyCalendarKind("Roc"); + static Iso = AnyCalendarKind.#objectValues[0]; + static Gregorian = AnyCalendarKind.#objectValues[1]; + static Buddhist = AnyCalendarKind.#objectValues[2]; + static Japanese = AnyCalendarKind.#objectValues[3]; + static JapaneseExtended = AnyCalendarKind.#objectValues[4]; + static Ethiopian = AnyCalendarKind.#objectValues[5]; + static EthiopianAmeteAlem = AnyCalendarKind.#objectValues[6]; + static Indian = AnyCalendarKind.#objectValues[7]; + static Coptic = AnyCalendarKind.#objectValues[8]; + static Dangi = AnyCalendarKind.#objectValues[9]; + static Chinese = AnyCalendarKind.#objectValues[10]; + static Hebrew = AnyCalendarKind.#objectValues[11]; + static IslamicCivil = AnyCalendarKind.#objectValues[12]; + static IslamicObservational = AnyCalendarKind.#objectValues[13]; + static IslamicTabular = AnyCalendarKind.#objectValues[14]; + static IslamicUmmAlQura = AnyCalendarKind.#objectValues[15]; + static Persian = AnyCalendarKind.#objectValues[16]; + static Roc = AnyCalendarKind.#objectValues[17]; static getForLocale(locale) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); @@ -82,7 +113,7 @@ export class AnyCalendarKind { if (!diplomatReceive.resultFlag) { return null; } - return AnyCalendarKind[Array.from(AnyCalendarKind.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + return new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); } finally { @@ -93,17 +124,17 @@ export class AnyCalendarKind { static getForBcp47(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_AnyCalendarKind_get_for_bcp47_mv1(diplomatReceive.buffer, ...sSlice); + const result = wasm.icu4x_AnyCalendarKind_get_for_bcp47_mv1(diplomatReceive.buffer, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { return null; } - return AnyCalendarKind[Array.from(AnyCalendarKind.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + return new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); } finally { diff --git a/ffi/capi/bindings/js/Bidi.mjs b/ffi/capi/bindings/js/Bidi.mjs index 365ec7d7937..008a07a1d1e 100644 --- a/ffi/capi/bindings/js/Bidi.mjs +++ b/ffi/capi/bindings/js/Bidi.mjs @@ -49,7 +49,7 @@ export class Bidi { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new Bidi(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -61,29 +61,29 @@ export class Bidi { } forText(text, defaultLevel) { - let functionGarbageCollector = new diplomatRuntime.GarbageCollector(); - const textSlice = [...functionGarbageCollector.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, text)).splat()]; + let functionGarbageCollectorGrip = new diplomatRuntime.GarbageCollectorGrip(); + const textSlice = functionGarbageCollectorGrip.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, text)); // This lifetime edge depends on lifetimes 'text let textEdges = [textSlice]; - const result = wasm.icu4x_Bidi_for_text_valid_utf8_mv1(this.ffiValue, ...textSlice, defaultLevel); + const result = wasm.icu4x_Bidi_for_text_valid_utf8_mv1(this.ffiValue, ...textSlice.splat(), defaultLevel); try { return new BidiInfo(diplomatRuntime.internalConstructor, result, [], textEdges); } finally { - functionGarbageCollector.garbageCollect(); + functionGarbageCollectorGrip.releaseToGarbageCollector(); } } reorderVisual(levels) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const levelsSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.slice(wasm, levels, "u8")).splat()]; + const levelsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.slice(wasm, levels, "u8")); - const result = wasm.icu4x_Bidi_reorder_visual_mv1(this.ffiValue, ...levelsSlice); + const result = wasm.icu4x_Bidi_reorder_visual_mv1(this.ffiValue, ...levelsSlice.splat()); try { return new ReorderedIndexMap(diplomatRuntime.internalConstructor, result, []); diff --git a/ffi/capi/bindings/js/BidiDirection.mjs b/ffi/capi/bindings/js/BidiDirection.mjs index 9238d80acb5..b62fdc39042 100644 --- a/ffi/capi/bindings/js/BidiDirection.mjs +++ b/ffi/capi/bindings/js/BidiDirection.mjs @@ -6,35 +6,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class BidiDirection { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Ltr", 0], ["Rtl", 1], ["Mixed", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return BidiDirection.#objectValues[arguments[1]]; + } + if (value instanceof BidiDirection) { - this.#value = value.value; - return; + return value; } - if (BidiDirection.values.has(value)) { - this.#value = value; - return; + let intVal = BidiDirection.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return BidiDirection.#objectValues[intVal]; } throw TypeError(value + " is not a BidiDirection and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...BidiDirection.#values.keys()][this.#value]; } get ffiValue() { - return BidiDirection.values.get(this.#value); + return this.#value; } - - static Ltr = new BidiDirection("Ltr"); - static Rtl = new BidiDirection("Rtl"); - static Mixed = new BidiDirection("Mixed"); + static #objectValues = [ + new BidiDirection(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new BidiDirection(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new BidiDirection(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Ltr = BidiDirection.#objectValues[0]; + static Rtl = BidiDirection.#objectValues[1]; + static Mixed = BidiDirection.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/BidiParagraph.mjs b/ffi/capi/bindings/js/BidiParagraph.mjs index 258cc95e089..981f901946b 100644 --- a/ffi/capi/bindings/js/BidiParagraph.mjs +++ b/ffi/capi/bindings/js/BidiParagraph.mjs @@ -55,7 +55,7 @@ export class BidiParagraph { const result = wasm.icu4x_BidiParagraph_direction_mv1(this.ffiValue); try { - return BidiDirection[Array.from(BidiDirection.values.keys())[result]]; + return new BidiDirection(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/Calendar.mjs b/ffi/capi/bindings/js/Calendar.mjs index ca45cc8772c..9a885b6c289 100644 --- a/ffi/capi/bindings/js/Calendar.mjs +++ b/ffi/capi/bindings/js/Calendar.mjs @@ -47,7 +47,7 @@ export class Calendar { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -65,7 +65,7 @@ export class Calendar { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new Calendar(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -80,7 +80,7 @@ export class Calendar { const result = wasm.icu4x_Calendar_kind_mv1(this.ffiValue); try { - return AnyCalendarKind[Array.from(AnyCalendarKind.values.keys())[result]]; + return new AnyCalendarKind(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/CalendarError.mjs b/ffi/capi/bindings/js/CalendarError.mjs index 5f9c98592a1..edc104ec830 100644 --- a/ffi/capi/bindings/js/CalendarError.mjs +++ b/ffi/capi/bindings/js/CalendarError.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CalendarError { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Unknown", 0], ["OutOfRange", 1], ["UnknownEra", 2], @@ -16,29 +16,46 @@ export class CalendarError { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CalendarError.#objectValues[arguments[1]]; + } + if (value instanceof CalendarError) { - this.#value = value.value; - return; + return value; } - if (CalendarError.values.has(value)) { - this.#value = value; - return; + let intVal = CalendarError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CalendarError.#objectValues[intVal]; } throw TypeError(value + " is not a CalendarError and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CalendarError.#values.keys()][this.#value]; } get ffiValue() { - return CalendarError.values.get(this.#value); + return this.#value; } - - static Unknown = new CalendarError("Unknown"); - static OutOfRange = new CalendarError("OutOfRange"); - static UnknownEra = new CalendarError("UnknownEra"); - static UnknownMonthCode = new CalendarError("UnknownMonthCode"); + static #objectValues = [ + new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Unknown = CalendarError.#objectValues[0]; + static OutOfRange = CalendarError.#objectValues[1]; + static UnknownEra = CalendarError.#objectValues[2]; + static UnknownMonthCode = CalendarError.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CalendarParseError.mjs b/ffi/capi/bindings/js/CalendarParseError.mjs index 8dd4c807909..e5a725da874 100644 --- a/ffi/capi/bindings/js/CalendarParseError.mjs +++ b/ffi/capi/bindings/js/CalendarParseError.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CalendarParseError { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Unknown", 0], ["InvalidSyntax", 1], ["OutOfRange", 2], @@ -17,30 +17,48 @@ export class CalendarParseError { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CalendarParseError.#objectValues[arguments[1]]; + } + if (value instanceof CalendarParseError) { - this.#value = value.value; - return; + return value; } - if (CalendarParseError.values.has(value)) { - this.#value = value; - return; + let intVal = CalendarParseError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CalendarParseError.#objectValues[intVal]; } throw TypeError(value + " is not a CalendarParseError and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CalendarParseError.#values.keys()][this.#value]; } get ffiValue() { - return CalendarParseError.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + ]; - static Unknown = new CalendarParseError("Unknown"); - static InvalidSyntax = new CalendarParseError("InvalidSyntax"); - static OutOfRange = new CalendarParseError("OutOfRange"); - static MissingFields = new CalendarParseError("MissingFields"); - static UnknownCalendar = new CalendarParseError("UnknownCalendar"); + static Unknown = CalendarParseError.#objectValues[0]; + static InvalidSyntax = CalendarParseError.#objectValues[1]; + static OutOfRange = CalendarParseError.#objectValues[2]; + static MissingFields = CalendarParseError.#objectValues[3]; + static UnknownCalendar = CalendarParseError.#objectValues[4]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs b/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs index d6e56ff7763..642750f5e53 100644 --- a/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs +++ b/ffi/capi/bindings/js/CanonicalCombiningClassMap.mjs @@ -47,7 +47,7 @@ export class CanonicalCombiningClassMap { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CanonicalCombiningClassMap(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/CanonicalComposition.mjs b/ffi/capi/bindings/js/CanonicalComposition.mjs index ab62c4c8d9e..2a18ad76350 100644 --- a/ffi/capi/bindings/js/CanonicalComposition.mjs +++ b/ffi/capi/bindings/js/CanonicalComposition.mjs @@ -49,7 +49,7 @@ export class CanonicalComposition { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CanonicalComposition(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/CanonicalDecomposition.mjs b/ffi/capi/bindings/js/CanonicalDecomposition.mjs index d3945badab5..5a9e4d8ea7e 100644 --- a/ffi/capi/bindings/js/CanonicalDecomposition.mjs +++ b/ffi/capi/bindings/js/CanonicalDecomposition.mjs @@ -50,7 +50,7 @@ export class CanonicalDecomposition { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CanonicalDecomposition(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/CaseMapCloser.mjs b/ffi/capi/bindings/js/CaseMapCloser.mjs index 48072ffc4e6..3f28e71af59 100644 --- a/ffi/capi/bindings/js/CaseMapCloser.mjs +++ b/ffi/capi/bindings/js/CaseMapCloser.mjs @@ -46,7 +46,7 @@ export class CaseMapCloser { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CaseMapCloser(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -67,9 +67,9 @@ export class CaseMapCloser { addStringCaseClosureTo(s, builder) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); - const result = wasm.icu4x_CaseMapCloser_add_string_case_closure_to_mv1(this.ffiValue, ...sSlice, builder.ffiValue); + const result = wasm.icu4x_CaseMapCloser_add_string_case_closure_to_mv1(this.ffiValue, ...sSlice.splat(), builder.ffiValue); try { return result; diff --git a/ffi/capi/bindings/js/CaseMapper.mjs b/ffi/capi/bindings/js/CaseMapper.mjs index 10443c58e8f..830bf7761ee 100644 --- a/ffi/capi/bindings/js/CaseMapper.mjs +++ b/ffi/capi/bindings/js/CaseMapper.mjs @@ -48,7 +48,7 @@ export class CaseMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CaseMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -62,10 +62,10 @@ export class CaseMapper { lowercase(s, locale) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_CaseMapper_lowercase_mv1(this.ffiValue, ...sSlice, locale.ffiValue, write.buffer); + wasm.icu4x_CaseMapper_lowercase_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, write.buffer); try { return write.readString8(); @@ -81,10 +81,10 @@ export class CaseMapper { uppercase(s, locale) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_CaseMapper_uppercase_mv1(this.ffiValue, ...sSlice, locale.ffiValue, write.buffer); + wasm.icu4x_CaseMapper_uppercase_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, write.buffer); try { return write.readString8(); @@ -100,10 +100,10 @@ export class CaseMapper { titlecaseSegmentWithOnlyCaseData(s, locale, options) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_CaseMapper_titlecase_segment_with_only_case_data_v1_mv1(this.ffiValue, ...sSlice, locale.ffiValue, ...options._intoFFI(functionCleanupArena, {}), write.buffer); + wasm.icu4x_CaseMapper_titlecase_segment_with_only_case_data_v1_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, ...options._intoFFI(functionCleanupArena, {}), write.buffer); try { return write.readString8(); @@ -119,10 +119,10 @@ export class CaseMapper { fold(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_CaseMapper_fold_mv1(this.ffiValue, ...sSlice, write.buffer); + wasm.icu4x_CaseMapper_fold_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); try { return write.readString8(); @@ -138,10 +138,10 @@ export class CaseMapper { foldTurkic(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_CaseMapper_fold_turkic_mv1(this.ffiValue, ...sSlice, write.buffer); + wasm.icu4x_CaseMapper_fold_turkic_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); try { return write.readString8(); diff --git a/ffi/capi/bindings/js/CodePointMapData16.mjs b/ffi/capi/bindings/js/CodePointMapData16.mjs index 390200c6748..4b957454ec9 100644 --- a/ffi/capi/bindings/js/CodePointMapData16.mjs +++ b/ffi/capi/bindings/js/CodePointMapData16.mjs @@ -101,7 +101,7 @@ export class CodePointMapData16 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData16(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/CodePointMapData8.mjs b/ffi/capi/bindings/js/CodePointMapData8.mjs index 9df34c635a5..8377eb1376f 100644 --- a/ffi/capi/bindings/js/CodePointMapData8.mjs +++ b/ffi/capi/bindings/js/CodePointMapData8.mjs @@ -124,7 +124,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -142,7 +142,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -160,7 +160,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -178,7 +178,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -196,7 +196,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -214,7 +214,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -232,7 +232,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -250,7 +250,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -268,7 +268,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -286,7 +286,7 @@ export class CodePointMapData8 { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointMapData8(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/CodePointRangeIterator.mjs b/ffi/capi/bindings/js/CodePointRangeIterator.mjs index a43e7dd05e1..0866b129161 100644 --- a/ffi/capi/bindings/js/CodePointRangeIterator.mjs +++ b/ffi/capi/bindings/js/CodePointRangeIterator.mjs @@ -43,7 +43,7 @@ export class CodePointRangeIterator { } next() { - const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, false); + const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 12, 4, false); const result = wasm.icu4x_CodePointRangeIterator_next_mv1(diplomatReceive.buffer, this.ffiValue); diff --git a/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs b/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs index c8adae51432..1cfe11be78d 100644 --- a/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs +++ b/ffi/capi/bindings/js/CodePointRangeIteratorResult.mjs @@ -45,7 +45,18 @@ export class CodePointRangeIteratorResult { functionCleanupArena, appendArrayMap ) { - return [this.#start, this.#end, this.#done] + return [this.#start, this.#end, this.#done, /* [3 x i8] padding */ 0, 0, 0 /* end padding */] + } + + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#start, Uint32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#end, Uint32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#done, Uint8Array); } // This struct contains borrowed fields, so this takes in a list of diff --git a/ffi/capi/bindings/js/CodePointSetData.mjs b/ffi/capi/bindings/js/CodePointSetData.mjs index 35ffec860c2..2832265b526 100644 --- a/ffi/capi/bindings/js/CodePointSetData.mjs +++ b/ffi/capi/bindings/js/CodePointSetData.mjs @@ -89,7 +89,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -107,7 +107,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -125,7 +125,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -143,7 +143,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -161,7 +161,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -179,7 +179,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -197,7 +197,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -215,7 +215,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -233,7 +233,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -251,7 +251,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -269,7 +269,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -287,7 +287,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -305,7 +305,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -323,7 +323,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -341,7 +341,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -359,7 +359,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -377,7 +377,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -395,7 +395,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -413,7 +413,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -431,7 +431,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -449,7 +449,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -467,7 +467,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -485,7 +485,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -503,7 +503,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -521,7 +521,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -539,7 +539,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -557,7 +557,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -575,7 +575,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -593,7 +593,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -611,7 +611,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -629,7 +629,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -647,7 +647,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -665,7 +665,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -683,7 +683,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -701,7 +701,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -719,7 +719,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -737,7 +737,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -755,7 +755,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -773,7 +773,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -791,7 +791,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -809,7 +809,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -827,7 +827,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -845,7 +845,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -863,7 +863,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -881,7 +881,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -899,7 +899,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -917,7 +917,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -935,7 +935,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -953,7 +953,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -971,7 +971,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -989,7 +989,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1007,7 +1007,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1025,7 +1025,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1043,7 +1043,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1061,7 +1061,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1079,7 +1079,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1097,7 +1097,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1115,7 +1115,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1133,7 +1133,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1151,7 +1151,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1169,7 +1169,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1187,7 +1187,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1205,7 +1205,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1223,7 +1223,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1241,7 +1241,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1259,7 +1259,7 @@ export class CodePointSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -1273,15 +1273,15 @@ export class CodePointSetData { static loadForEcma262(provider, propertyName) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const propertyNameSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, propertyName)).splat()]; + const propertyNameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, propertyName)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_CodePointSetData_load_for_ecma262_mv1(diplomatReceive.buffer, provider.ffiValue, ...propertyNameSlice); + const result = wasm.icu4x_CodePointSetData_load_for_ecma262_mv1(diplomatReceive.buffer, provider.ffiValue, ...propertyNameSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new CodePointSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/Collator.mjs b/ffi/capi/bindings/js/Collator.mjs index c1af9e01fe3..c5e8cfa8b9c 100644 --- a/ffi/capi/bindings/js/Collator.mjs +++ b/ffi/capi/bindings/js/Collator.mjs @@ -50,7 +50,7 @@ export class Collator { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new Collator(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -66,11 +66,11 @@ export class Collator { compare(left, right) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const leftSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, left)).splat()]; + const leftSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, left)); - const rightSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, right)).splat()]; + const rightSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, right)); - const result = wasm.icu4x_Collator_compare_utf16_mv1(this.ffiValue, ...leftSlice, ...rightSlice); + const result = wasm.icu4x_Collator_compare_utf16_mv1(this.ffiValue, ...leftSlice.splat(), ...rightSlice.splat()); try { return result; diff --git a/ffi/capi/bindings/js/CollatorAlternateHandling.mjs b/ffi/capi/bindings/js/CollatorAlternateHandling.mjs index 5e936b8e7fe..07a4696a1df 100644 --- a/ffi/capi/bindings/js/CollatorAlternateHandling.mjs +++ b/ffi/capi/bindings/js/CollatorAlternateHandling.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorAlternateHandling { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["NonIgnorable", 1], ["Shifted", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorAlternateHandling.#objectValues[arguments[1]]; + } + if (value instanceof CollatorAlternateHandling) { - this.#value = value.value; - return; + return value; } - if (CollatorAlternateHandling.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorAlternateHandling.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorAlternateHandling.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorAlternateHandling and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorAlternateHandling.#values.keys()][this.#value]; } get ffiValue() { - return CollatorAlternateHandling.values.get(this.#value); + return this.#value; } - - static Auto = new CollatorAlternateHandling("Auto"); - static NonIgnorable = new CollatorAlternateHandling("NonIgnorable"); - static Shifted = new CollatorAlternateHandling("Shifted"); + static #objectValues = [ + new CollatorAlternateHandling(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorAlternateHandling(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorAlternateHandling(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Auto = CollatorAlternateHandling.#objectValues[0]; + static NonIgnorable = CollatorAlternateHandling.#objectValues[1]; + static Shifted = CollatorAlternateHandling.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs b/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs index 0fd1442f65a..22f7b5f3252 100644 --- a/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs +++ b/ffi/capi/bindings/js/CollatorBackwardSecondLevel.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorBackwardSecondLevel { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Off", 1], ["On", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorBackwardSecondLevel.#objectValues[arguments[1]]; + } + if (value instanceof CollatorBackwardSecondLevel) { - this.#value = value.value; - return; + return value; } - if (CollatorBackwardSecondLevel.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorBackwardSecondLevel.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorBackwardSecondLevel.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorBackwardSecondLevel and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorBackwardSecondLevel.#values.keys()][this.#value]; } get ffiValue() { - return CollatorBackwardSecondLevel.values.get(this.#value); + return this.#value; } - - static Auto = new CollatorBackwardSecondLevel("Auto"); - static Off = new CollatorBackwardSecondLevel("Off"); - static On = new CollatorBackwardSecondLevel("On"); + static #objectValues = [ + new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Auto = CollatorBackwardSecondLevel.#objectValues[0]; + static Off = CollatorBackwardSecondLevel.#objectValues[1]; + static On = CollatorBackwardSecondLevel.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorCaseFirst.mjs b/ffi/capi/bindings/js/CollatorCaseFirst.mjs index 6d3aacd40c9..cbf63fb3122 100644 --- a/ffi/capi/bindings/js/CollatorCaseFirst.mjs +++ b/ffi/capi/bindings/js/CollatorCaseFirst.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorCaseFirst { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Off", 1], ["LowerFirst", 2], @@ -16,29 +16,46 @@ export class CollatorCaseFirst { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorCaseFirst.#objectValues[arguments[1]]; + } + if (value instanceof CollatorCaseFirst) { - this.#value = value.value; - return; + return value; } - if (CollatorCaseFirst.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorCaseFirst.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorCaseFirst.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorCaseFirst and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorCaseFirst.#values.keys()][this.#value]; } get ffiValue() { - return CollatorCaseFirst.values.get(this.#value); + return this.#value; } - - static Auto = new CollatorCaseFirst("Auto"); - static Off = new CollatorCaseFirst("Off"); - static LowerFirst = new CollatorCaseFirst("LowerFirst"); - static UpperFirst = new CollatorCaseFirst("UpperFirst"); + static #objectValues = [ + new CollatorCaseFirst(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorCaseFirst(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorCaseFirst(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new CollatorCaseFirst(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Auto = CollatorCaseFirst.#objectValues[0]; + static Off = CollatorCaseFirst.#objectValues[1]; + static LowerFirst = CollatorCaseFirst.#objectValues[2]; + static UpperFirst = CollatorCaseFirst.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorCaseLevel.mjs b/ffi/capi/bindings/js/CollatorCaseLevel.mjs index 7cbe4f2df4e..3f79763f9dd 100644 --- a/ffi/capi/bindings/js/CollatorCaseLevel.mjs +++ b/ffi/capi/bindings/js/CollatorCaseLevel.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorCaseLevel { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Off", 1], ["On", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorCaseLevel.#objectValues[arguments[1]]; + } + if (value instanceof CollatorCaseLevel) { - this.#value = value.value; - return; + return value; } - if (CollatorCaseLevel.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorCaseLevel.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorCaseLevel.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorCaseLevel and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorCaseLevel.#values.keys()][this.#value]; } get ffiValue() { - return CollatorCaseLevel.values.get(this.#value); + return this.#value; } - - static Auto = new CollatorCaseLevel("Auto"); - static Off = new CollatorCaseLevel("Off"); - static On = new CollatorCaseLevel("On"); + static #objectValues = [ + new CollatorCaseLevel(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorCaseLevel(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorCaseLevel(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Auto = CollatorCaseLevel.#objectValues[0]; + static Off = CollatorCaseLevel.#objectValues[1]; + static On = CollatorCaseLevel.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorMaxVariable.mjs b/ffi/capi/bindings/js/CollatorMaxVariable.mjs index 19b7175117d..f7c912ac4ec 100644 --- a/ffi/capi/bindings/js/CollatorMaxVariable.mjs +++ b/ffi/capi/bindings/js/CollatorMaxVariable.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorMaxVariable { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Space", 1], ["Punctuation", 2], @@ -17,30 +17,48 @@ export class CollatorMaxVariable { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorMaxVariable.#objectValues[arguments[1]]; + } + if (value instanceof CollatorMaxVariable) { - this.#value = value.value; - return; + return value; } - if (CollatorMaxVariable.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorMaxVariable.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorMaxVariable.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorMaxVariable and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorMaxVariable.#values.keys()][this.#value]; } get ffiValue() { - return CollatorMaxVariable.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new CollatorMaxVariable(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorMaxVariable(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorMaxVariable(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new CollatorMaxVariable(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new CollatorMaxVariable(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + ]; - static Auto = new CollatorMaxVariable("Auto"); - static Space = new CollatorMaxVariable("Space"); - static Punctuation = new CollatorMaxVariable("Punctuation"); - static Symbol = new CollatorMaxVariable("Symbol"); - static Currency = new CollatorMaxVariable("Currency"); + static Auto = CollatorMaxVariable.#objectValues[0]; + static Space = CollatorMaxVariable.#objectValues[1]; + static Punctuation = CollatorMaxVariable.#objectValues[2]; + static Symbol = CollatorMaxVariable.#objectValues[3]; + static Currency = CollatorMaxVariable.#objectValues[4]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorNumeric.mjs b/ffi/capi/bindings/js/CollatorNumeric.mjs index 2e03d2a6b17..ed5edc30ae1 100644 --- a/ffi/capi/bindings/js/CollatorNumeric.mjs +++ b/ffi/capi/bindings/js/CollatorNumeric.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorNumeric { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Off", 1], ["On", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorNumeric.#objectValues[arguments[1]]; + } + if (value instanceof CollatorNumeric) { - this.#value = value.value; - return; + return value; } - if (CollatorNumeric.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorNumeric.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorNumeric.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorNumeric and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorNumeric.#values.keys()][this.#value]; } get ffiValue() { - return CollatorNumeric.values.get(this.#value); + return this.#value; } - - static Auto = new CollatorNumeric("Auto"); - static Off = new CollatorNumeric("Off"); - static On = new CollatorNumeric("On"); + static #objectValues = [ + new CollatorNumeric(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorNumeric(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorNumeric(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Auto = CollatorNumeric.#objectValues[0]; + static Off = CollatorNumeric.#objectValues[1]; + static On = CollatorNumeric.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorOptions.mjs b/ffi/capi/bindings/js/CollatorOptions.mjs index ae0506979bf..72de18c9cbc 100644 --- a/ffi/capi/bindings/js/CollatorOptions.mjs +++ b/ffi/capi/bindings/js/CollatorOptions.mjs @@ -94,6 +94,21 @@ export class CollatorOptions { return [this.#strength.ffiValue, this.#alternateHandling.ffiValue, this.#caseFirst.ffiValue, this.#maxVariable.ffiValue, this.#caseLevel.ffiValue, this.#numeric.ffiValue, this.#backwardSecondLevel.ffiValue] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#strength.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#alternateHandling.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#caseFirst.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 12, this.#maxVariable.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 16, this.#caseLevel.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 20, this.#numeric.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 24, this.#backwardSecondLevel.ffiValue, Int32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. @@ -101,18 +116,18 @@ export class CollatorOptions { // should handle this when constructing edge arrays. #fromFFI(ptr) { const strengthDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#strength = CollatorStrength[Array.from(CollatorStrength.values.keys())[strengthDeref]]; + this.#strength = new CollatorStrength(diplomatRuntime.internalConstructor, strengthDeref); const alternateHandlingDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#alternateHandling = CollatorAlternateHandling[Array.from(CollatorAlternateHandling.values.keys())[alternateHandlingDeref]]; + this.#alternateHandling = new CollatorAlternateHandling(diplomatRuntime.internalConstructor, alternateHandlingDeref); const caseFirstDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); - this.#caseFirst = CollatorCaseFirst[Array.from(CollatorCaseFirst.values.keys())[caseFirstDeref]]; + this.#caseFirst = new CollatorCaseFirst(diplomatRuntime.internalConstructor, caseFirstDeref); const maxVariableDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12); - this.#maxVariable = CollatorMaxVariable[Array.from(CollatorMaxVariable.values.keys())[maxVariableDeref]]; + this.#maxVariable = new CollatorMaxVariable(diplomatRuntime.internalConstructor, maxVariableDeref); const caseLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 16); - this.#caseLevel = CollatorCaseLevel[Array.from(CollatorCaseLevel.values.keys())[caseLevelDeref]]; + this.#caseLevel = new CollatorCaseLevel(diplomatRuntime.internalConstructor, caseLevelDeref); const numericDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 20); - this.#numeric = CollatorNumeric[Array.from(CollatorNumeric.values.keys())[numericDeref]]; + this.#numeric = new CollatorNumeric(diplomatRuntime.internalConstructor, numericDeref); const backwardSecondLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 24); - this.#backwardSecondLevel = CollatorBackwardSecondLevel[Array.from(CollatorBackwardSecondLevel.values.keys())[backwardSecondLevelDeref]]; + this.#backwardSecondLevel = new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, backwardSecondLevelDeref); } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorResolvedOptions.mjs b/ffi/capi/bindings/js/CollatorResolvedOptions.mjs index 14b0254fff4..8300d504f73 100644 --- a/ffi/capi/bindings/js/CollatorResolvedOptions.mjs +++ b/ffi/capi/bindings/js/CollatorResolvedOptions.mjs @@ -73,6 +73,21 @@ export class CollatorResolvedOptions { return [this.#strength.ffiValue, this.#alternateHandling.ffiValue, this.#caseFirst.ffiValue, this.#maxVariable.ffiValue, this.#caseLevel.ffiValue, this.#numeric.ffiValue, this.#backwardSecondLevel.ffiValue] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#strength.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#alternateHandling.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#caseFirst.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 12, this.#maxVariable.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 16, this.#caseLevel.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 20, this.#numeric.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 24, this.#backwardSecondLevel.ffiValue, Int32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. @@ -80,18 +95,18 @@ export class CollatorResolvedOptions { // should handle this when constructing edge arrays. #fromFFI(ptr) { const strengthDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#strength = CollatorStrength[Array.from(CollatorStrength.values.keys())[strengthDeref]]; + this.#strength = new CollatorStrength(diplomatRuntime.internalConstructor, strengthDeref); const alternateHandlingDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#alternateHandling = CollatorAlternateHandling[Array.from(CollatorAlternateHandling.values.keys())[alternateHandlingDeref]]; + this.#alternateHandling = new CollatorAlternateHandling(diplomatRuntime.internalConstructor, alternateHandlingDeref); const caseFirstDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); - this.#caseFirst = CollatorCaseFirst[Array.from(CollatorCaseFirst.values.keys())[caseFirstDeref]]; + this.#caseFirst = new CollatorCaseFirst(diplomatRuntime.internalConstructor, caseFirstDeref); const maxVariableDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 12); - this.#maxVariable = CollatorMaxVariable[Array.from(CollatorMaxVariable.values.keys())[maxVariableDeref]]; + this.#maxVariable = new CollatorMaxVariable(diplomatRuntime.internalConstructor, maxVariableDeref); const caseLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 16); - this.#caseLevel = CollatorCaseLevel[Array.from(CollatorCaseLevel.values.keys())[caseLevelDeref]]; + this.#caseLevel = new CollatorCaseLevel(diplomatRuntime.internalConstructor, caseLevelDeref); const numericDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 20); - this.#numeric = CollatorNumeric[Array.from(CollatorNumeric.values.keys())[numericDeref]]; + this.#numeric = new CollatorNumeric(diplomatRuntime.internalConstructor, numericDeref); const backwardSecondLevelDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 24); - this.#backwardSecondLevel = CollatorBackwardSecondLevel[Array.from(CollatorBackwardSecondLevel.values.keys())[backwardSecondLevelDeref]]; + this.#backwardSecondLevel = new CollatorBackwardSecondLevel(diplomatRuntime.internalConstructor, backwardSecondLevelDeref); } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/CollatorStrength.mjs b/ffi/capi/bindings/js/CollatorStrength.mjs index c0edd2dca20..6b886f567e3 100644 --- a/ffi/capi/bindings/js/CollatorStrength.mjs +++ b/ffi/capi/bindings/js/CollatorStrength.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class CollatorStrength { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Primary", 1], ["Secondary", 2], @@ -18,31 +18,50 @@ export class CollatorStrength { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return CollatorStrength.#objectValues[arguments[1]]; + } + if (value instanceof CollatorStrength) { - this.#value = value.value; - return; + return value; } - if (CollatorStrength.values.has(value)) { - this.#value = value; - return; + let intVal = CollatorStrength.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return CollatorStrength.#objectValues[intVal]; } throw TypeError(value + " is not a CollatorStrength and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...CollatorStrength.#values.keys()][this.#value]; } get ffiValue() { - return CollatorStrength.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new CollatorStrength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new CollatorStrength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new CollatorStrength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new CollatorStrength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new CollatorStrength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + new CollatorStrength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + ]; - static Auto = new CollatorStrength("Auto"); - static Primary = new CollatorStrength("Primary"); - static Secondary = new CollatorStrength("Secondary"); - static Tertiary = new CollatorStrength("Tertiary"); - static Quaternary = new CollatorStrength("Quaternary"); - static Identical = new CollatorStrength("Identical"); + static Auto = CollatorStrength.#objectValues[0]; + static Primary = CollatorStrength.#objectValues[1]; + static Secondary = CollatorStrength.#objectValues[2]; + static Tertiary = CollatorStrength.#objectValues[3]; + static Quaternary = CollatorStrength.#objectValues[4]; + static Identical = CollatorStrength.#objectValues[5]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/ComposingNormalizer.mjs b/ffi/capi/bindings/js/ComposingNormalizer.mjs index 1f95a472a22..a2129f2da08 100644 --- a/ffi/capi/bindings/js/ComposingNormalizer.mjs +++ b/ffi/capi/bindings/js/ComposingNormalizer.mjs @@ -45,7 +45,7 @@ export class ComposingNormalizer { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new ComposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -63,7 +63,7 @@ export class ComposingNormalizer { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new ComposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -77,10 +77,10 @@ export class ComposingNormalizer { normalize(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_ComposingNormalizer_normalize_mv1(this.ffiValue, ...sSlice, write.buffer); + wasm.icu4x_ComposingNormalizer_normalize_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); try { return write.readString8(); @@ -96,9 +96,9 @@ export class ComposingNormalizer { isNormalized(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)); - const result = wasm.icu4x_ComposingNormalizer_is_normalized_utf16_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_ComposingNormalizer_is_normalized_utf16_mv1(this.ffiValue, ...sSlice.splat()); try { return result; @@ -112,9 +112,9 @@ export class ComposingNormalizer { isNormalizedUpTo(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)); - const result = wasm.icu4x_ComposingNormalizer_is_normalized_utf16_up_to_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_ComposingNormalizer_is_normalized_utf16_up_to_mv1(this.ffiValue, ...sSlice.splat()); try { return result; diff --git a/ffi/capi/bindings/js/CustomTimeZone.mjs b/ffi/capi/bindings/js/CustomTimeZone.mjs index b6a8de975eb..1dac95d5b2f 100644 --- a/ffi/capi/bindings/js/CustomTimeZone.mjs +++ b/ffi/capi/bindings/js/CustomTimeZone.mjs @@ -45,11 +45,11 @@ export class CustomTimeZone { static fromString(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_CustomTimeZone_from_string_mv1(diplomatReceive.buffer, ...sSlice); + const result = wasm.icu4x_CustomTimeZone_from_string_mv1(diplomatReceive.buffer, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { @@ -222,9 +222,9 @@ export class CustomTimeZone { trySetTimeZoneId(id) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const idSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)).splat()]; + const idSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)); - const result = wasm.icu4x_CustomTimeZone_try_set_time_zone_id_mv1(this.ffiValue, ...idSlice); + const result = wasm.icu4x_CustomTimeZone_try_set_time_zone_id_mv1(this.ffiValue, ...idSlice.splat()); try { if (result !== 1) { @@ -242,9 +242,9 @@ export class CustomTimeZone { trySetIanaTimeZoneId(mapper, id) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const idSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)).splat()]; + const idSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)); - const result = wasm.icu4x_CustomTimeZone_try_set_iana_time_zone_id_mv1(this.ffiValue, mapper.ffiValue, ...idSlice); + const result = wasm.icu4x_CustomTimeZone_try_set_iana_time_zone_id_mv1(this.ffiValue, mapper.ffiValue, ...idSlice.splat()); try { if (result !== 1) { @@ -283,9 +283,9 @@ export class CustomTimeZone { trySetMetazoneId(id) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const idSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)).splat()]; + const idSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)); - const result = wasm.icu4x_CustomTimeZone_try_set_metazone_id_mv1(this.ffiValue, ...idSlice); + const result = wasm.icu4x_CustomTimeZone_try_set_metazone_id_mv1(this.ffiValue, ...idSlice.splat()); try { if (result !== 1) { @@ -324,9 +324,9 @@ export class CustomTimeZone { trySetZoneVariant(id) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const idSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)).splat()]; + const idSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, id)); - const result = wasm.icu4x_CustomTimeZone_try_set_zone_variant_mv1(this.ffiValue, ...idSlice); + const result = wasm.icu4x_CustomTimeZone_try_set_zone_variant_mv1(this.ffiValue, ...idSlice.splat()); try { return result === 1; diff --git a/ffi/capi/bindings/js/DataError.mjs b/ffi/capi/bindings/js/DataError.mjs index c215292d8a5..4f681196140 100644 --- a/ffi/capi/bindings/js/DataError.mjs +++ b/ffi/capi/bindings/js/DataError.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class DataError { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Unknown", 0], ["MarkerNotFound", 1], ["IdentifierNotFound", 2], @@ -21,34 +21,56 @@ export class DataError { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return DataError.#objectValues[arguments[1]]; + } + if (value instanceof DataError) { - this.#value = value.value; - return; + return value; } - if (DataError.values.has(value)) { - this.#value = value; - return; + let intVal = DataError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return DataError.#objectValues[intVal]; } throw TypeError(value + " is not a DataError and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...DataError.#values.keys()][this.#value]; } get ffiValue() { - return DataError.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), + new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), + ]; - static Unknown = new DataError("Unknown"); - static MarkerNotFound = new DataError("MarkerNotFound"); - static IdentifierNotFound = new DataError("IdentifierNotFound"); - static InvalidRequest = new DataError("InvalidRequest"); - static InconsistentData = new DataError("InconsistentData"); - static Downcast = new DataError("Downcast"); - static Deserialize = new DataError("Deserialize"); - static Custom = new DataError("Custom"); - static Io = new DataError("Io"); + static Unknown = DataError.#objectValues[0]; + static MarkerNotFound = DataError.#objectValues[1]; + static IdentifierNotFound = DataError.#objectValues[2]; + static InvalidRequest = DataError.#objectValues[3]; + static InconsistentData = DataError.#objectValues[4]; + static Downcast = DataError.#objectValues[5]; + static Deserialize = DataError.#objectValues[6]; + static Custom = DataError.#objectValues[7]; + static Io = DataError.#objectValues[8]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DataProvider.mjs b/ffi/capi/bindings/js/DataProvider.mjs index 07adf06cf1a..fdedf0364b4 100644 --- a/ffi/capi/bindings/js/DataProvider.mjs +++ b/ffi/capi/bindings/js/DataProvider.mjs @@ -67,7 +67,7 @@ export class DataProvider { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } @@ -85,7 +85,7 @@ export class DataProvider { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } @@ -103,7 +103,7 @@ export class DataProvider { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } diff --git a/ffi/capi/bindings/js/Date.mjs b/ffi/capi/bindings/js/Date.mjs index 6b2b202d096..4d4c7e3b9ba 100644 --- a/ffi/capi/bindings/js/Date.mjs +++ b/ffi/capi/bindings/js/Date.mjs @@ -52,7 +52,7 @@ export class Date { try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new Date(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -66,17 +66,17 @@ export class Date { static fromCodesInCalendar(eraCode, year, monthCode, day, calendar) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const eraCodeSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, eraCode)).splat()]; + const eraCodeSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, eraCode)); - const monthCodeSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, monthCode)).splat()]; + const monthCodeSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, monthCode)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Date_from_codes_in_calendar_mv1(diplomatReceive.buffer, ...eraCodeSlice, year, ...monthCodeSlice, day, calendar.ffiValue); + const result = wasm.icu4x_Date_from_codes_in_calendar_mv1(diplomatReceive.buffer, ...eraCodeSlice.splat(), year, ...monthCodeSlice.splat(), day, calendar.ffiValue); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new Date(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -92,15 +92,15 @@ export class Date { static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const vSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)).splat()]; + const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Date_from_string_mv1(diplomatReceive.buffer, ...vSlice); + const result = wasm.icu4x_Date_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarParseError[Array.from(CalendarParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarParseError: ' + cause.value, { cause }); } return new Date(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -157,7 +157,7 @@ export class Date { const result = wasm.icu4x_Date_day_of_week_mv1(this.ffiValue); try { - return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + return new IsoWeekday(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/DateFormatter.mjs b/ffi/capi/bindings/js/DateFormatter.mjs index b349c69fe6e..a9fc88bb42e 100644 --- a/ffi/capi/bindings/js/DateFormatter.mjs +++ b/ffi/capi/bindings/js/DateFormatter.mjs @@ -54,7 +54,7 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new DateFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -74,7 +74,7 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); @@ -96,7 +96,7 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); @@ -118,7 +118,7 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); @@ -140,7 +140,7 @@ export class DateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); diff --git a/ffi/capi/bindings/js/DateLength.mjs b/ffi/capi/bindings/js/DateLength.mjs index a94fea9e501..48c533f0771 100644 --- a/ffi/capi/bindings/js/DateLength.mjs +++ b/ffi/capi/bindings/js/DateLength.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class DateLength { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Full", 0], ["Long", 1], ["Medium", 2], @@ -16,29 +16,46 @@ export class DateLength { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return DateLength.#objectValues[arguments[1]]; + } + if (value instanceof DateLength) { - this.#value = value.value; - return; + return value; } - if (DateLength.values.has(value)) { - this.#value = value; - return; + let intVal = DateLength.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return DateLength.#objectValues[intVal]; } throw TypeError(value + " is not a DateLength and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...DateLength.#values.keys()][this.#value]; } get ffiValue() { - return DateLength.values.get(this.#value); + return this.#value; } - - static Full = new DateLength("Full"); - static Long = new DateLength("Long"); - static Medium = new DateLength("Medium"); - static Short = new DateLength("Short"); + static #objectValues = [ + new DateLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new DateLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new DateLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new DateLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Full = DateLength.#objectValues[0]; + static Long = DateLength.#objectValues[1]; + static Medium = DateLength.#objectValues[2]; + static Short = DateLength.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DateTime.mjs b/ffi/capi/bindings/js/DateTime.mjs index ba3f2fa4c35..f752a42531e 100644 --- a/ffi/capi/bindings/js/DateTime.mjs +++ b/ffi/capi/bindings/js/DateTime.mjs @@ -54,7 +54,7 @@ export class DateTime { try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new DateTime(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -68,17 +68,17 @@ export class DateTime { static fromCodesInCalendar(eraCode, year, monthCode, day, hour, minute, second, nanosecond, calendar) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const eraCodeSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, eraCode)).splat()]; + const eraCodeSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, eraCode)); - const monthCodeSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, monthCode)).splat()]; + const monthCodeSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, monthCode)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_DateTime_from_codes_in_calendar_mv1(diplomatReceive.buffer, ...eraCodeSlice, year, ...monthCodeSlice, day, hour, minute, second, nanosecond, calendar.ffiValue); + const result = wasm.icu4x_DateTime_from_codes_in_calendar_mv1(diplomatReceive.buffer, ...eraCodeSlice.splat(), year, ...monthCodeSlice.splat(), day, hour, minute, second, nanosecond, calendar.ffiValue); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new DateTime(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -104,15 +104,15 @@ export class DateTime { static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const vSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)).splat()]; + const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_DateTime_from_string_mv1(diplomatReceive.buffer, ...vSlice); + const result = wasm.icu4x_DateTime_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarParseError[Array.from(CalendarParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarParseError: ' + cause.value, { cause }); } return new DateTime(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -229,7 +229,7 @@ export class DateTime { const result = wasm.icu4x_DateTime_day_of_week_mv1(this.ffiValue); try { - return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + return new IsoWeekday(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/DateTimeFormatter.mjs b/ffi/capi/bindings/js/DateTimeFormatter.mjs index dfcc17c084b..d74e635f69d 100644 --- a/ffi/capi/bindings/js/DateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/DateTimeFormatter.mjs @@ -53,7 +53,7 @@ export class DateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new DateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -73,7 +73,7 @@ export class DateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); @@ -95,7 +95,7 @@ export class DateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); diff --git a/ffi/capi/bindings/js/Decomposed.mjs b/ffi/capi/bindings/js/Decomposed.mjs index 59f4f585cbc..c156271ceb0 100644 --- a/ffi/capi/bindings/js/Decomposed.mjs +++ b/ffi/capi/bindings/js/Decomposed.mjs @@ -40,6 +40,16 @@ export class Decomposed { return [this.#first, this.#second] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#first, Uint32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#second, Uint32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. diff --git a/ffi/capi/bindings/js/DecomposingNormalizer.mjs b/ffi/capi/bindings/js/DecomposingNormalizer.mjs index 1910cf0b0d8..82b48428f05 100644 --- a/ffi/capi/bindings/js/DecomposingNormalizer.mjs +++ b/ffi/capi/bindings/js/DecomposingNormalizer.mjs @@ -45,7 +45,7 @@ export class DecomposingNormalizer { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new DecomposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -63,7 +63,7 @@ export class DecomposingNormalizer { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new DecomposingNormalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -77,10 +77,10 @@ export class DecomposingNormalizer { normalize(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_DecomposingNormalizer_normalize_mv1(this.ffiValue, ...sSlice, write.buffer); + wasm.icu4x_DecomposingNormalizer_normalize_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); try { return write.readString8(); @@ -96,9 +96,9 @@ export class DecomposingNormalizer { isNormalized(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); - const result = wasm.icu4x_DecomposingNormalizer_is_normalized_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_DecomposingNormalizer_is_normalized_mv1(this.ffiValue, ...sSlice.splat()); try { return result; @@ -112,9 +112,9 @@ export class DecomposingNormalizer { isNormalizedUtf16(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)); - const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_mv1(this.ffiValue, ...sSlice.splat()); try { return result; @@ -128,9 +128,9 @@ export class DecomposingNormalizer { isNormalizedUpTo(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); - const result = wasm.icu4x_DecomposingNormalizer_is_normalized_up_to_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_DecomposingNormalizer_is_normalized_up_to_mv1(this.ffiValue, ...sSlice.splat()); try { return result; @@ -144,9 +144,9 @@ export class DecomposingNormalizer { isNormalizedUtf16UpTo(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, s)); - const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_up_to_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_DecomposingNormalizer_is_normalized_utf16_up_to_mv1(this.ffiValue, ...sSlice.splat()); try { return result; diff --git a/ffi/capi/bindings/js/DisplayNamesFallback.mjs b/ffi/capi/bindings/js/DisplayNamesFallback.mjs index 54926f7f35d..92f107ef150 100644 --- a/ffi/capi/bindings/js/DisplayNamesFallback.mjs +++ b/ffi/capi/bindings/js/DisplayNamesFallback.mjs @@ -8,33 +8,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class DisplayNamesFallback { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Code", 0], ["None", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return DisplayNamesFallback.#objectValues[arguments[1]]; + } + if (value instanceof DisplayNamesFallback) { - this.#value = value.value; - return; + return value; } - if (DisplayNamesFallback.values.has(value)) { - this.#value = value; - return; + let intVal = DisplayNamesFallback.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return DisplayNamesFallback.#objectValues[intVal]; } throw TypeError(value + " is not a DisplayNamesFallback and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...DisplayNamesFallback.#values.keys()][this.#value]; } get ffiValue() { - return DisplayNamesFallback.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new DisplayNamesFallback(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new DisplayNamesFallback(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Code = new DisplayNamesFallback("Code"); - static None = new DisplayNamesFallback("None"); + static Code = DisplayNamesFallback.#objectValues[0]; + static None = DisplayNamesFallback.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesOptions.mjs b/ffi/capi/bindings/js/DisplayNamesOptions.mjs index 1999bb0190e..00885bf582d 100644 --- a/ffi/capi/bindings/js/DisplayNamesOptions.mjs +++ b/ffi/capi/bindings/js/DisplayNamesOptions.mjs @@ -54,6 +54,17 @@ export class DisplayNamesOptions { return [this.#style.ffiValue, this.#fallback.ffiValue, this.#languageDisplay.ffiValue] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#style.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#fallback.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#languageDisplay.ffiValue, Int32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. @@ -61,10 +72,10 @@ export class DisplayNamesOptions { // should handle this when constructing edge arrays. #fromFFI(ptr) { const styleDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#style = DisplayNamesStyle[Array.from(DisplayNamesStyle.values.keys())[styleDeref]]; + this.#style = new DisplayNamesStyle(diplomatRuntime.internalConstructor, styleDeref); const fallbackDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#fallback = DisplayNamesFallback[Array.from(DisplayNamesFallback.values.keys())[fallbackDeref]]; + this.#fallback = new DisplayNamesFallback(diplomatRuntime.internalConstructor, fallbackDeref); const languageDisplayDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); - this.#languageDisplay = LanguageDisplay[Array.from(LanguageDisplay.values.keys())[languageDisplayDeref]]; + this.#languageDisplay = new LanguageDisplay(diplomatRuntime.internalConstructor, languageDisplayDeref); } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/DisplayNamesStyle.mjs b/ffi/capi/bindings/js/DisplayNamesStyle.mjs index 52dfdc49c11..5b1aefebe05 100644 --- a/ffi/capi/bindings/js/DisplayNamesStyle.mjs +++ b/ffi/capi/bindings/js/DisplayNamesStyle.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class DisplayNamesStyle { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Narrow", 1], ["Short", 2], @@ -17,30 +17,48 @@ export class DisplayNamesStyle { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return DisplayNamesStyle.#objectValues[arguments[1]]; + } + if (value instanceof DisplayNamesStyle) { - this.#value = value.value; - return; + return value; } - if (DisplayNamesStyle.values.has(value)) { - this.#value = value; - return; + let intVal = DisplayNamesStyle.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return DisplayNamesStyle.#objectValues[intVal]; } throw TypeError(value + " is not a DisplayNamesStyle and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...DisplayNamesStyle.#values.keys()][this.#value]; } get ffiValue() { - return DisplayNamesStyle.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new DisplayNamesStyle(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + ]; - static Auto = new DisplayNamesStyle("Auto"); - static Narrow = new DisplayNamesStyle("Narrow"); - static Short = new DisplayNamesStyle("Short"); - static Long = new DisplayNamesStyle("Long"); - static Menu = new DisplayNamesStyle("Menu"); + static Auto = DisplayNamesStyle.#objectValues[0]; + static Narrow = DisplayNamesStyle.#objectValues[1]; + static Short = DisplayNamesStyle.#objectValues[2]; + static Long = DisplayNamesStyle.#objectValues[3]; + static Menu = DisplayNamesStyle.#objectValues[4]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/Error.mjs b/ffi/capi/bindings/js/Error.mjs index bfbc603bf05..551b4a79c54 100644 --- a/ffi/capi/bindings/js/Error.mjs +++ b/ffi/capi/bindings/js/Error.mjs @@ -10,7 +10,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class Error { #value = undefined; - static values = new Map([ + static #values = new Map([ ["UnknownError", 0], ["DataMissingDataMarkerError", 256], ["DataMissingLocaleError", 258], @@ -34,45 +34,82 @@ export class Error { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return Error.#objectValues[arguments[1]]; + } + if (value instanceof Error) { - this.#value = value.value; - return; + return value; } - if (Error.values.has(value)) { - this.#value = value; - return; + let intVal = Error.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return Error.#objectValues[intVal]; } throw TypeError(value + " is not a Error and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + for (let entry of Error.#values) { + if (entry[1] == this.#value) { + return entry[0]; + } + } } get ffiValue() { - return Error.values.get(this.#value); + return this.#value; } + static #objectValues = { + [0]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + [256]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 256), + [258]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 258), + [260]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 260), + [261]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 261), + [262]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 262), + [263]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 263), + [266]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 266), + [267]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 267), + [268]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 268), + [1026]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1026), + [2048]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2048), + [2049]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2049), + [2050]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2050), + [2051]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2051), + [2052]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2052), + [2053]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2053), + [2054]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2054), + [2055]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2055), + [2056]: new Error(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2056), + }; - static UnknownError = new Error("UnknownError"); - static DataMissingDataMarkerError = new Error("DataMissingDataMarkerError"); - static DataMissingLocaleError = new Error("DataMissingLocaleError"); - static DataNeedsLocaleError = new Error("DataNeedsLocaleError"); - static DataExtraneousLocaleError = new Error("DataExtraneousLocaleError"); - static DataFilteredResourceError = new Error("DataFilteredResourceError"); - static DataMismatchedTypeError = new Error("DataMismatchedTypeError"); - static DataCustomError = new Error("DataCustomError"); - static DataIoError = new Error("DataIoError"); - static DataUnavailableBufferFormatError = new Error("DataUnavailableBufferFormatError"); - static PropertyUnexpectedPropertyNameError = new Error("PropertyUnexpectedPropertyNameError"); - static DateTimePatternError = new Error("DateTimePatternError"); - static DateTimeMissingInputFieldError = new Error("DateTimeMissingInputFieldError"); - static DateTimeSkeletonError = new Error("DateTimeSkeletonError"); - static DateTimeUnsupportedFieldError = new Error("DateTimeUnsupportedFieldError"); - static DateTimeUnsupportedOptionsError = new Error("DateTimeUnsupportedOptionsError"); - static DateTimeMissingWeekdaySymbolError = new Error("DateTimeMissingWeekdaySymbolError"); - static DateTimeMissingMonthSymbolError = new Error("DateTimeMissingMonthSymbolError"); - static DateTimeFixedDecimalError = new Error("DateTimeFixedDecimalError"); - static DateTimeMismatchedCalendarError = new Error("DateTimeMismatchedCalendarError"); + static UnknownError = Error.#objectValues[0]; + static DataMissingDataMarkerError = Error.#objectValues[256]; + static DataMissingLocaleError = Error.#objectValues[258]; + static DataNeedsLocaleError = Error.#objectValues[260]; + static DataExtraneousLocaleError = Error.#objectValues[261]; + static DataFilteredResourceError = Error.#objectValues[262]; + static DataMismatchedTypeError = Error.#objectValues[263]; + static DataCustomError = Error.#objectValues[266]; + static DataIoError = Error.#objectValues[267]; + static DataUnavailableBufferFormatError = Error.#objectValues[268]; + static PropertyUnexpectedPropertyNameError = Error.#objectValues[1026]; + static DateTimePatternError = Error.#objectValues[2048]; + static DateTimeMissingInputFieldError = Error.#objectValues[2049]; + static DateTimeSkeletonError = Error.#objectValues[2050]; + static DateTimeUnsupportedFieldError = Error.#objectValues[2051]; + static DateTimeUnsupportedOptionsError = Error.#objectValues[2052]; + static DateTimeMissingWeekdaySymbolError = Error.#objectValues[2053]; + static DateTimeMissingMonthSymbolError = Error.#objectValues[2054]; + static DateTimeFixedDecimalError = Error.#objectValues[2055]; + static DateTimeMismatchedCalendarError = Error.#objectValues[2056]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimal.mjs b/ffi/capi/bindings/js/FixedDecimal.mjs index e14bb4f2ad1..f8ee07eedc8 100644 --- a/ffi/capi/bindings/js/FixedDecimal.mjs +++ b/ffi/capi/bindings/js/FixedDecimal.mjs @@ -119,15 +119,15 @@ export class FixedDecimal { static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const vSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)).splat()]; + const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_FixedDecimal_from_string_mv1(diplomatReceive.buffer, ...vSlice); + const result = wasm.icu4x_FixedDecimal_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = FixedDecimalParseError[Array.from(FixedDecimalParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new FixedDecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('FixedDecimalParseError: ' + cause.value, { cause }); } return new FixedDecimal(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -211,7 +211,7 @@ export class FixedDecimal { const result = wasm.icu4x_FixedDecimal_sign_mv1(this.ffiValue); try { - return FixedDecimalSign[Array.from(FixedDecimalSign.values.keys())[result]]; + return new FixedDecimalSign(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/FixedDecimalFormatter.mjs b/ffi/capi/bindings/js/FixedDecimalFormatter.mjs index 66b34ef6693..5c7a1b40174 100644 --- a/ffi/capi/bindings/js/FixedDecimalFormatter.mjs +++ b/ffi/capi/bindings/js/FixedDecimalFormatter.mjs @@ -50,7 +50,7 @@ export class FixedDecimalFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new FixedDecimalFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -64,27 +64,27 @@ export class FixedDecimalFormatter { static createWithManualData(plusSignPrefix, plusSignSuffix, minusSignPrefix, minusSignSuffix, decimalSeparator, groupingSeparator, primaryGroupSize, secondaryGroupSize, minGroupSize, digits, groupingStrategy) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const plusSignPrefixSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, plusSignPrefix)).splat()]; + const plusSignPrefixSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, plusSignPrefix)); - const plusSignSuffixSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, plusSignSuffix)).splat()]; + const plusSignSuffixSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, plusSignSuffix)); - const minusSignPrefixSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, minusSignPrefix)).splat()]; + const minusSignPrefixSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, minusSignPrefix)); - const minusSignSuffixSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, minusSignSuffix)).splat()]; + const minusSignSuffixSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, minusSignSuffix)); - const decimalSeparatorSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, decimalSeparator)).splat()]; + const decimalSeparatorSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, decimalSeparator)); - const groupingSeparatorSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, groupingSeparator)).splat()]; + const groupingSeparatorSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, groupingSeparator)); - const digitsSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.slice(wasm, digits, "u16")).splat()]; + const digitsSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.slice(wasm, digits, "u16")); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_FixedDecimalFormatter_create_with_manual_data_mv1(diplomatReceive.buffer, ...plusSignPrefixSlice, ...plusSignSuffixSlice, ...minusSignPrefixSlice, ...minusSignSuffixSlice, ...decimalSeparatorSlice, ...groupingSeparatorSlice, primaryGroupSize, secondaryGroupSize, minGroupSize, ...digitsSlice, groupingStrategy.ffiValue); + const result = wasm.icu4x_FixedDecimalFormatter_create_with_manual_data_mv1(diplomatReceive.buffer, ...plusSignPrefixSlice.splat(), ...plusSignSuffixSlice.splat(), ...minusSignPrefixSlice.splat(), ...minusSignSuffixSlice.splat(), ...decimalSeparatorSlice.splat(), ...groupingSeparatorSlice.splat(), primaryGroupSize, secondaryGroupSize, minGroupSize, ...digitsSlice.splat(), groupingStrategy.ffiValue); try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new FixedDecimalFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs b/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs index 66d7fe0ef64..1145454dd70 100644 --- a/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs +++ b/ffi/capi/bindings/js/FixedDecimalGroupingStrategy.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class FixedDecimalGroupingStrategy { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Never", 1], ["Always", 2], @@ -16,29 +16,46 @@ export class FixedDecimalGroupingStrategy { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return FixedDecimalGroupingStrategy.#objectValues[arguments[1]]; + } + if (value instanceof FixedDecimalGroupingStrategy) { - this.#value = value.value; - return; + return value; } - if (FixedDecimalGroupingStrategy.values.has(value)) { - this.#value = value; - return; + let intVal = FixedDecimalGroupingStrategy.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return FixedDecimalGroupingStrategy.#objectValues[intVal]; } throw TypeError(value + " is not a FixedDecimalGroupingStrategy and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...FixedDecimalGroupingStrategy.#values.keys()][this.#value]; } get ffiValue() { - return FixedDecimalGroupingStrategy.values.get(this.#value); + return this.#value; } - - static Auto = new FixedDecimalGroupingStrategy("Auto"); - static Never = new FixedDecimalGroupingStrategy("Never"); - static Always = new FixedDecimalGroupingStrategy("Always"); - static Min2 = new FixedDecimalGroupingStrategy("Min2"); + static #objectValues = [ + new FixedDecimalGroupingStrategy(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new FixedDecimalGroupingStrategy(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new FixedDecimalGroupingStrategy(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new FixedDecimalGroupingStrategy(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Auto = FixedDecimalGroupingStrategy.#objectValues[0]; + static Never = FixedDecimalGroupingStrategy.#objectValues[1]; + static Always = FixedDecimalGroupingStrategy.#objectValues[2]; + static Min2 = FixedDecimalGroupingStrategy.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalParseError.mjs b/ffi/capi/bindings/js/FixedDecimalParseError.mjs index 330276c1c71..37248c09408 100644 --- a/ffi/capi/bindings/js/FixedDecimalParseError.mjs +++ b/ffi/capi/bindings/js/FixedDecimalParseError.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class FixedDecimalParseError { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Unknown", 0], ["Limit", 1], ["Syntax", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return FixedDecimalParseError.#objectValues[arguments[1]]; + } + if (value instanceof FixedDecimalParseError) { - this.#value = value.value; - return; + return value; } - if (FixedDecimalParseError.values.has(value)) { - this.#value = value; - return; + let intVal = FixedDecimalParseError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return FixedDecimalParseError.#objectValues[intVal]; } throw TypeError(value + " is not a FixedDecimalParseError and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...FixedDecimalParseError.#values.keys()][this.#value]; } get ffiValue() { - return FixedDecimalParseError.values.get(this.#value); + return this.#value; } - - static Unknown = new FixedDecimalParseError("Unknown"); - static Limit = new FixedDecimalParseError("Limit"); - static Syntax = new FixedDecimalParseError("Syntax"); + static #objectValues = [ + new FixedDecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new FixedDecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new FixedDecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Unknown = FixedDecimalParseError.#objectValues[0]; + static Limit = FixedDecimalParseError.#objectValues[1]; + static Syntax = FixedDecimalParseError.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs b/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs index a9395cd40fd..76847d88892 100644 --- a/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs +++ b/ffi/capi/bindings/js/FixedDecimalRoundingIncrement.mjs @@ -10,7 +10,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class FixedDecimalRoundingIncrement { #value = undefined; - static values = new Map([ + static #values = new Map([ ["MultiplesOf1", 0], ["MultiplesOf2", 1], ["MultiplesOf5", 2], @@ -18,29 +18,46 @@ export class FixedDecimalRoundingIncrement { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return FixedDecimalRoundingIncrement.#objectValues[arguments[1]]; + } + if (value instanceof FixedDecimalRoundingIncrement) { - this.#value = value.value; - return; + return value; } - if (FixedDecimalRoundingIncrement.values.has(value)) { - this.#value = value; - return; + let intVal = FixedDecimalRoundingIncrement.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return FixedDecimalRoundingIncrement.#objectValues[intVal]; } throw TypeError(value + " is not a FixedDecimalRoundingIncrement and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...FixedDecimalRoundingIncrement.#values.keys()][this.#value]; } get ffiValue() { - return FixedDecimalRoundingIncrement.values.get(this.#value); + return this.#value; } - - static MultiplesOf1 = new FixedDecimalRoundingIncrement("MultiplesOf1"); - static MultiplesOf2 = new FixedDecimalRoundingIncrement("MultiplesOf2"); - static MultiplesOf5 = new FixedDecimalRoundingIncrement("MultiplesOf5"); - static MultiplesOf25 = new FixedDecimalRoundingIncrement("MultiplesOf25"); + static #objectValues = [ + new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new FixedDecimalRoundingIncrement(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static MultiplesOf1 = FixedDecimalRoundingIncrement.#objectValues[0]; + static MultiplesOf2 = FixedDecimalRoundingIncrement.#objectValues[1]; + static MultiplesOf5 = FixedDecimalRoundingIncrement.#objectValues[2]; + static MultiplesOf25 = FixedDecimalRoundingIncrement.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs b/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs index 8d3a40ae96c..109e5771d52 100644 --- a/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs +++ b/ffi/capi/bindings/js/FixedDecimalRoundingMode.mjs @@ -10,7 +10,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class FixedDecimalRoundingMode { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Ceil", 0], ["Expand", 1], ["Floor", 2], @@ -23,34 +23,56 @@ export class FixedDecimalRoundingMode { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return FixedDecimalRoundingMode.#objectValues[arguments[1]]; + } + if (value instanceof FixedDecimalRoundingMode) { - this.#value = value.value; - return; + return value; } - if (FixedDecimalRoundingMode.values.has(value)) { - this.#value = value; - return; + let intVal = FixedDecimalRoundingMode.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return FixedDecimalRoundingMode.#objectValues[intVal]; } throw TypeError(value + " is not a FixedDecimalRoundingMode and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...FixedDecimalRoundingMode.#values.keys()][this.#value]; } get ffiValue() { - return FixedDecimalRoundingMode.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), + new FixedDecimalRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), + ]; - static Ceil = new FixedDecimalRoundingMode("Ceil"); - static Expand = new FixedDecimalRoundingMode("Expand"); - static Floor = new FixedDecimalRoundingMode("Floor"); - static Trunc = new FixedDecimalRoundingMode("Trunc"); - static HalfCeil = new FixedDecimalRoundingMode("HalfCeil"); - static HalfExpand = new FixedDecimalRoundingMode("HalfExpand"); - static HalfFloor = new FixedDecimalRoundingMode("HalfFloor"); - static HalfTrunc = new FixedDecimalRoundingMode("HalfTrunc"); - static HalfEven = new FixedDecimalRoundingMode("HalfEven"); + static Ceil = FixedDecimalRoundingMode.#objectValues[0]; + static Expand = FixedDecimalRoundingMode.#objectValues[1]; + static Floor = FixedDecimalRoundingMode.#objectValues[2]; + static Trunc = FixedDecimalRoundingMode.#objectValues[3]; + static HalfCeil = FixedDecimalRoundingMode.#objectValues[4]; + static HalfExpand = FixedDecimalRoundingMode.#objectValues[5]; + static HalfFloor = FixedDecimalRoundingMode.#objectValues[6]; + static HalfTrunc = FixedDecimalRoundingMode.#objectValues[7]; + static HalfEven = FixedDecimalRoundingMode.#objectValues[8]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalSign.mjs b/ffi/capi/bindings/js/FixedDecimalSign.mjs index 29a3acf0937..4cabe049b7d 100644 --- a/ffi/capi/bindings/js/FixedDecimalSign.mjs +++ b/ffi/capi/bindings/js/FixedDecimalSign.mjs @@ -10,35 +10,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class FixedDecimalSign { #value = undefined; - static values = new Map([ + static #values = new Map([ ["None", 0], ["Negative", 1], ["Positive", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return FixedDecimalSign.#objectValues[arguments[1]]; + } + if (value instanceof FixedDecimalSign) { - this.#value = value.value; - return; + return value; } - if (FixedDecimalSign.values.has(value)) { - this.#value = value; - return; + let intVal = FixedDecimalSign.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return FixedDecimalSign.#objectValues[intVal]; } throw TypeError(value + " is not a FixedDecimalSign and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...FixedDecimalSign.#values.keys()][this.#value]; } get ffiValue() { - return FixedDecimalSign.values.get(this.#value); + return this.#value; } - - static None = new FixedDecimalSign("None"); - static Negative = new FixedDecimalSign("Negative"); - static Positive = new FixedDecimalSign("Positive"); + static #objectValues = [ + new FixedDecimalSign(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new FixedDecimalSign(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new FixedDecimalSign(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static None = FixedDecimalSign.#objectValues[0]; + static Negative = FixedDecimalSign.#objectValues[1]; + static Positive = FixedDecimalSign.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs b/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs index 528adbeca71..05affd504ce 100644 --- a/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs +++ b/ffi/capi/bindings/js/FixedDecimalSignDisplay.mjs @@ -10,7 +10,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class FixedDecimalSignDisplay { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["Never", 1], ["Always", 2], @@ -19,30 +19,48 @@ export class FixedDecimalSignDisplay { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return FixedDecimalSignDisplay.#objectValues[arguments[1]]; + } + if (value instanceof FixedDecimalSignDisplay) { - this.#value = value.value; - return; + return value; } - if (FixedDecimalSignDisplay.values.has(value)) { - this.#value = value; - return; + let intVal = FixedDecimalSignDisplay.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return FixedDecimalSignDisplay.#objectValues[intVal]; } throw TypeError(value + " is not a FixedDecimalSignDisplay and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...FixedDecimalSignDisplay.#values.keys()][this.#value]; } get ffiValue() { - return FixedDecimalSignDisplay.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new FixedDecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new FixedDecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new FixedDecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new FixedDecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new FixedDecimalSignDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + ]; - static Auto = new FixedDecimalSignDisplay("Auto"); - static Never = new FixedDecimalSignDisplay("Never"); - static Always = new FixedDecimalSignDisplay("Always"); - static ExceptZero = new FixedDecimalSignDisplay("ExceptZero"); - static Negative = new FixedDecimalSignDisplay("Negative"); + static Auto = FixedDecimalSignDisplay.#objectValues[0]; + static Never = FixedDecimalSignDisplay.#objectValues[1]; + static Always = FixedDecimalSignDisplay.#objectValues[2]; + static ExceptZero = FixedDecimalSignDisplay.#objectValues[3]; + static Negative = FixedDecimalSignDisplay.#objectValues[4]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs b/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs index 57b5e929485..11a3f6b7999 100644 --- a/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs +++ b/ffi/capi/bindings/js/GeneralCategoryNameToMaskMapper.mjs @@ -45,9 +45,9 @@ export class GeneralCategoryNameToMaskMapper { getStrict(name) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const nameSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)).splat()]; + const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); - const result = wasm.icu4x_GeneralCategoryNameToMaskMapper_get_strict_mv1(this.ffiValue, ...nameSlice); + const result = wasm.icu4x_GeneralCategoryNameToMaskMapper_get_strict_mv1(this.ffiValue, ...nameSlice.splat()); try { return result; @@ -61,9 +61,9 @@ export class GeneralCategoryNameToMaskMapper { getLoose(name) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const nameSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)).splat()]; + const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); - const result = wasm.icu4x_GeneralCategoryNameToMaskMapper_get_loose_mv1(this.ffiValue, ...nameSlice); + const result = wasm.icu4x_GeneralCategoryNameToMaskMapper_get_loose_mv1(this.ffiValue, ...nameSlice.splat()); try { return result; @@ -81,7 +81,7 @@ export class GeneralCategoryNameToMaskMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new GeneralCategoryNameToMaskMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs b/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs index 4090ab8e5dd..bf8b8930efb 100644 --- a/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs +++ b/ffi/capi/bindings/js/GraphemeClusterSegmenter.mjs @@ -49,7 +49,7 @@ export class GraphemeClusterSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new GraphemeClusterSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -61,20 +61,20 @@ export class GraphemeClusterSegmenter { } segment(input) { - let functionGarbageCollector = new diplomatRuntime.GarbageCollector(); - const inputSlice = [...functionGarbageCollector.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)).splat()]; + let functionGarbageCollectorGrip = new diplomatRuntime.GarbageCollectorGrip(); + const inputSlice = functionGarbageCollectorGrip.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)); // This lifetime edge depends on lifetimes 'a let aEdges = [this, inputSlice]; - const result = wasm.icu4x_GraphemeClusterSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice); + const result = wasm.icu4x_GraphemeClusterSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice.splat()); try { return new GraphemeClusterBreakIteratorUtf16(diplomatRuntime.internalConstructor, result, [], aEdges); } finally { - functionGarbageCollector.garbageCollect(); + functionGarbageCollectorGrip.releaseToGarbageCollector(); } } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/GregorianDateFormatter.mjs b/ffi/capi/bindings/js/GregorianDateFormatter.mjs index 87d9b8ba4ad..c7d7fd43be2 100644 --- a/ffi/capi/bindings/js/GregorianDateFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianDateFormatter.mjs @@ -52,7 +52,7 @@ export class GregorianDateFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new GregorianDateFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs b/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs index 62d48564d7b..21a7dbf0341 100644 --- a/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianDateTimeFormatter.mjs @@ -52,7 +52,7 @@ export class GregorianDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new GregorianDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs index 3e7394c447c..d2611d0ff87 100644 --- a/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/GregorianZonedDateTimeFormatter.mjs @@ -53,7 +53,7 @@ export class GregorianZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new GregorianZonedDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -73,7 +73,7 @@ export class GregorianZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new GregorianZonedDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/IsoDate.mjs b/ffi/capi/bindings/js/IsoDate.mjs index 21462140308..0a9976aa891 100644 --- a/ffi/capi/bindings/js/IsoDate.mjs +++ b/ffi/capi/bindings/js/IsoDate.mjs @@ -52,7 +52,7 @@ export class IsoDate { try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new IsoDate(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -66,15 +66,15 @@ export class IsoDate { static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const vSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)).splat()]; + const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_IsoDate_from_string_mv1(diplomatReceive.buffer, ...vSlice); + const result = wasm.icu4x_IsoDate_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarParseError[Array.from(CalendarParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarParseError: ' + cause.value, { cause }); } return new IsoDate(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -141,7 +141,7 @@ export class IsoDate { const result = wasm.icu4x_IsoDate_day_of_week_mv1(this.ffiValue); try { - return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + return new IsoWeekday(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/IsoDateTime.mjs b/ffi/capi/bindings/js/IsoDateTime.mjs index 55bb79d24cc..23942247692 100644 --- a/ffi/capi/bindings/js/IsoDateTime.mjs +++ b/ffi/capi/bindings/js/IsoDateTime.mjs @@ -54,7 +54,7 @@ export class IsoDateTime { try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new IsoDateTime(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -78,15 +78,15 @@ export class IsoDateTime { static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const vSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)).splat()]; + const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_IsoDateTime_from_string_mv1(diplomatReceive.buffer, ...vSlice); + const result = wasm.icu4x_IsoDateTime_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarParseError[Array.from(CalendarParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarParseError: ' + cause.value, { cause }); } return new IsoDateTime(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -233,7 +233,7 @@ export class IsoDateTime { const result = wasm.icu4x_IsoDateTime_day_of_week_mv1(this.ffiValue); try { - return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + return new IsoWeekday(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs b/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs index a9417760247..ebf8dac3061 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneFormat.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class IsoTimeZoneFormat { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Basic", 0], ["Extended", 1], ["UtcBasic", 2], @@ -16,29 +16,46 @@ export class IsoTimeZoneFormat { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return IsoTimeZoneFormat.#objectValues[arguments[1]]; + } + if (value instanceof IsoTimeZoneFormat) { - this.#value = value.value; - return; + return value; } - if (IsoTimeZoneFormat.values.has(value)) { - this.#value = value; - return; + let intVal = IsoTimeZoneFormat.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return IsoTimeZoneFormat.#objectValues[intVal]; } throw TypeError(value + " is not a IsoTimeZoneFormat and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...IsoTimeZoneFormat.#values.keys()][this.#value]; } get ffiValue() { - return IsoTimeZoneFormat.values.get(this.#value); + return this.#value; } - - static Basic = new IsoTimeZoneFormat("Basic"); - static Extended = new IsoTimeZoneFormat("Extended"); - static UtcBasic = new IsoTimeZoneFormat("UtcBasic"); - static UtcExtended = new IsoTimeZoneFormat("UtcExtended"); + static #objectValues = [ + new IsoTimeZoneFormat(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new IsoTimeZoneFormat(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new IsoTimeZoneFormat(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new IsoTimeZoneFormat(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Basic = IsoTimeZoneFormat.#objectValues[0]; + static Extended = IsoTimeZoneFormat.#objectValues[1]; + static UtcBasic = IsoTimeZoneFormat.#objectValues[2]; + static UtcExtended = IsoTimeZoneFormat.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs b/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs index def6d05cc8c..375ea1b0295 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneMinuteDisplay.mjs @@ -8,33 +8,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class IsoTimeZoneMinuteDisplay { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Required", 0], ["Optional", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return IsoTimeZoneMinuteDisplay.#objectValues[arguments[1]]; + } + if (value instanceof IsoTimeZoneMinuteDisplay) { - this.#value = value.value; - return; + return value; } - if (IsoTimeZoneMinuteDisplay.values.has(value)) { - this.#value = value; - return; + let intVal = IsoTimeZoneMinuteDisplay.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return IsoTimeZoneMinuteDisplay.#objectValues[intVal]; } throw TypeError(value + " is not a IsoTimeZoneMinuteDisplay and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...IsoTimeZoneMinuteDisplay.#values.keys()][this.#value]; } get ffiValue() { - return IsoTimeZoneMinuteDisplay.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new IsoTimeZoneMinuteDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new IsoTimeZoneMinuteDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Required = new IsoTimeZoneMinuteDisplay("Required"); - static Optional = new IsoTimeZoneMinuteDisplay("Optional"); + static Required = IsoTimeZoneMinuteDisplay.#objectValues[0]; + static Optional = IsoTimeZoneMinuteDisplay.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs b/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs index 9c08f8eb2fb..73021ea5542 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneOptions.mjs @@ -51,6 +51,17 @@ export class IsoTimeZoneOptions { return [this.#format.ffiValue, this.#minutes.ffiValue, this.#seconds.ffiValue] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#format.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#minutes.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#seconds.ffiValue, Int32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. @@ -58,10 +69,10 @@ export class IsoTimeZoneOptions { // should handle this when constructing edge arrays. #fromFFI(ptr) { const formatDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#format = IsoTimeZoneFormat[Array.from(IsoTimeZoneFormat.values.keys())[formatDeref]]; + this.#format = new IsoTimeZoneFormat(diplomatRuntime.internalConstructor, formatDeref); const minutesDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#minutes = IsoTimeZoneMinuteDisplay[Array.from(IsoTimeZoneMinuteDisplay.values.keys())[minutesDeref]]; + this.#minutes = new IsoTimeZoneMinuteDisplay(diplomatRuntime.internalConstructor, minutesDeref); const secondsDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 8); - this.#seconds = IsoTimeZoneSecondDisplay[Array.from(IsoTimeZoneSecondDisplay.values.keys())[secondsDeref]]; + this.#seconds = new IsoTimeZoneSecondDisplay(diplomatRuntime.internalConstructor, secondsDeref); } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs b/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs index b4ff8c91b9b..5f1f4665d4e 100644 --- a/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs +++ b/ffi/capi/bindings/js/IsoTimeZoneSecondDisplay.mjs @@ -8,33 +8,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class IsoTimeZoneSecondDisplay { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Optional", 0], ["Never", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return IsoTimeZoneSecondDisplay.#objectValues[arguments[1]]; + } + if (value instanceof IsoTimeZoneSecondDisplay) { - this.#value = value.value; - return; + return value; } - if (IsoTimeZoneSecondDisplay.values.has(value)) { - this.#value = value; - return; + let intVal = IsoTimeZoneSecondDisplay.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return IsoTimeZoneSecondDisplay.#objectValues[intVal]; } throw TypeError(value + " is not a IsoTimeZoneSecondDisplay and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...IsoTimeZoneSecondDisplay.#values.keys()][this.#value]; } get ffiValue() { - return IsoTimeZoneSecondDisplay.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new IsoTimeZoneSecondDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new IsoTimeZoneSecondDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Optional = new IsoTimeZoneSecondDisplay("Optional"); - static Never = new IsoTimeZoneSecondDisplay("Never"); + static Optional = IsoTimeZoneSecondDisplay.#objectValues[0]; + static Never = IsoTimeZoneSecondDisplay.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IsoWeekday.mjs b/ffi/capi/bindings/js/IsoWeekday.mjs index b113f6c9630..2ecfa25d648 100644 --- a/ffi/capi/bindings/js/IsoWeekday.mjs +++ b/ffi/capi/bindings/js/IsoWeekday.mjs @@ -6,7 +6,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class IsoWeekday { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Monday", 1], ["Tuesday", 2], ["Wednesday", 3], @@ -17,32 +17,56 @@ export class IsoWeekday { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return IsoWeekday.#objectValues[arguments[1]]; + } + if (value instanceof IsoWeekday) { - this.#value = value.value; - return; + return value; } - if (IsoWeekday.values.has(value)) { - this.#value = value; - return; + let intVal = IsoWeekday.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return IsoWeekday.#objectValues[intVal]; } throw TypeError(value + " is not a IsoWeekday and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + for (let entry of IsoWeekday.#values) { + if (entry[1] == this.#value) { + return entry[0]; + } + } } get ffiValue() { - return IsoWeekday.values.get(this.#value); + return this.#value; } + static #objectValues = { + [1]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + [2]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + [3]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + [4]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + [5]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + [6]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), + [7]: new IsoWeekday(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), + }; - static Monday = new IsoWeekday("Monday"); - static Tuesday = new IsoWeekday("Tuesday"); - static Wednesday = new IsoWeekday("Wednesday"); - static Thursday = new IsoWeekday("Thursday"); - static Friday = new IsoWeekday("Friday"); - static Saturday = new IsoWeekday("Saturday"); - static Sunday = new IsoWeekday("Sunday"); + static Monday = IsoWeekday.#objectValues[1]; + static Tuesday = IsoWeekday.#objectValues[2]; + static Wednesday = IsoWeekday.#objectValues[3]; + static Thursday = IsoWeekday.#objectValues[4]; + static Friday = IsoWeekday.#objectValues[5]; + static Saturday = IsoWeekday.#objectValues[6]; + static Sunday = IsoWeekday.#objectValues[7]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LanguageDisplay.mjs b/ffi/capi/bindings/js/LanguageDisplay.mjs index 02bd892b15a..ed86b4ff027 100644 --- a/ffi/capi/bindings/js/LanguageDisplay.mjs +++ b/ffi/capi/bindings/js/LanguageDisplay.mjs @@ -8,33 +8,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LanguageDisplay { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Dialect", 0], ["Standard", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LanguageDisplay.#objectValues[arguments[1]]; + } + if (value instanceof LanguageDisplay) { - this.#value = value.value; - return; + return value; } - if (LanguageDisplay.values.has(value)) { - this.#value = value; - return; + let intVal = LanguageDisplay.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LanguageDisplay.#objectValues[intVal]; } throw TypeError(value + " is not a LanguageDisplay and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LanguageDisplay.#values.keys()][this.#value]; } get ffiValue() { - return LanguageDisplay.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new LanguageDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LanguageDisplay(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Dialect = new LanguageDisplay("Dialect"); - static Standard = new LanguageDisplay("Standard"); + static Dialect = LanguageDisplay.#objectValues[0]; + static Standard = LanguageDisplay.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LeadingAdjustment.mjs b/ffi/capi/bindings/js/LeadingAdjustment.mjs index a2e275edd63..68b29c20201 100644 --- a/ffi/capi/bindings/js/LeadingAdjustment.mjs +++ b/ffi/capi/bindings/js/LeadingAdjustment.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LeadingAdjustment { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Auto", 0], ["None", 1], ["ToCased", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LeadingAdjustment.#objectValues[arguments[1]]; + } + if (value instanceof LeadingAdjustment) { - this.#value = value.value; - return; + return value; } - if (LeadingAdjustment.values.has(value)) { - this.#value = value; - return; + let intVal = LeadingAdjustment.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LeadingAdjustment.#objectValues[intVal]; } throw TypeError(value + " is not a LeadingAdjustment and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LeadingAdjustment.#values.keys()][this.#value]; } get ffiValue() { - return LeadingAdjustment.values.get(this.#value); + return this.#value; } - - static Auto = new LeadingAdjustment("Auto"); - static None = new LeadingAdjustment("None"); - static ToCased = new LeadingAdjustment("ToCased"); + static #objectValues = [ + new LeadingAdjustment(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LeadingAdjustment(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new LeadingAdjustment(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Auto = LeadingAdjustment.#objectValues[0]; + static None = LeadingAdjustment.#objectValues[1]; + static ToCased = LeadingAdjustment.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakOptions.mjs b/ffi/capi/bindings/js/LineBreakOptions.mjs index cc3c0fa2cd7..a4a5dd12487 100644 --- a/ffi/capi/bindings/js/LineBreakOptions.mjs +++ b/ffi/capi/bindings/js/LineBreakOptions.mjs @@ -50,7 +50,18 @@ export class LineBreakOptions { functionCleanupArena, appendArrayMap ) { - return [this.#strictness.ffiValue, this.#wordOption.ffiValue, this.#jaZh] + return [this.#strictness.ffiValue, this.#wordOption.ffiValue, this.#jaZh, /* [3 x i8] padding */ 0, 0, 0 /* end padding */] + } + + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#strictness.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#wordOption.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#jaZh, Uint8Array); } // This struct contains borrowed fields, so this takes in a list of @@ -60,9 +71,9 @@ export class LineBreakOptions { // should handle this when constructing edge arrays. #fromFFI(ptr) { const strictnessDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#strictness = LineBreakStrictness[Array.from(LineBreakStrictness.values.keys())[strictnessDeref]]; + this.#strictness = new LineBreakStrictness(diplomatRuntime.internalConstructor, strictnessDeref); const wordOptionDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#wordOption = LineBreakWordOption[Array.from(LineBreakWordOption.values.keys())[wordOptionDeref]]; + this.#wordOption = new LineBreakWordOption(diplomatRuntime.internalConstructor, wordOptionDeref); const jaZhDeref = (new Uint8Array(wasm.memory.buffer, ptr + 8, 1))[0] === 1; this.#jaZh = jaZhDeref; } diff --git a/ffi/capi/bindings/js/LineBreakStrictness.mjs b/ffi/capi/bindings/js/LineBreakStrictness.mjs index 5250f29f750..b5f73e255d7 100644 --- a/ffi/capi/bindings/js/LineBreakStrictness.mjs +++ b/ffi/capi/bindings/js/LineBreakStrictness.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LineBreakStrictness { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Loose", 0], ["Normal", 1], ["Strict", 2], @@ -16,29 +16,46 @@ export class LineBreakStrictness { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LineBreakStrictness.#objectValues[arguments[1]]; + } + if (value instanceof LineBreakStrictness) { - this.#value = value.value; - return; + return value; } - if (LineBreakStrictness.values.has(value)) { - this.#value = value; - return; + let intVal = LineBreakStrictness.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LineBreakStrictness.#objectValues[intVal]; } throw TypeError(value + " is not a LineBreakStrictness and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LineBreakStrictness.#values.keys()][this.#value]; } get ffiValue() { - return LineBreakStrictness.values.get(this.#value); + return this.#value; } - - static Loose = new LineBreakStrictness("Loose"); - static Normal = new LineBreakStrictness("Normal"); - static Strict = new LineBreakStrictness("Strict"); - static Anywhere = new LineBreakStrictness("Anywhere"); + static #objectValues = [ + new LineBreakStrictness(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LineBreakStrictness(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new LineBreakStrictness(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new LineBreakStrictness(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Loose = LineBreakStrictness.#objectValues[0]; + static Normal = LineBreakStrictness.#objectValues[1]; + static Strict = LineBreakStrictness.#objectValues[2]; + static Anywhere = LineBreakStrictness.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineBreakWordOption.mjs b/ffi/capi/bindings/js/LineBreakWordOption.mjs index b2a7b8f0da5..2eae206e854 100644 --- a/ffi/capi/bindings/js/LineBreakWordOption.mjs +++ b/ffi/capi/bindings/js/LineBreakWordOption.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LineBreakWordOption { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Normal", 0], ["BreakAll", 1], ["KeepAll", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LineBreakWordOption.#objectValues[arguments[1]]; + } + if (value instanceof LineBreakWordOption) { - this.#value = value.value; - return; + return value; } - if (LineBreakWordOption.values.has(value)) { - this.#value = value; - return; + let intVal = LineBreakWordOption.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LineBreakWordOption.#objectValues[intVal]; } throw TypeError(value + " is not a LineBreakWordOption and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LineBreakWordOption.#values.keys()][this.#value]; } get ffiValue() { - return LineBreakWordOption.values.get(this.#value); + return this.#value; } - - static Normal = new LineBreakWordOption("Normal"); - static BreakAll = new LineBreakWordOption("BreakAll"); - static KeepAll = new LineBreakWordOption("KeepAll"); + static #objectValues = [ + new LineBreakWordOption(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LineBreakWordOption(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new LineBreakWordOption(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Normal = LineBreakWordOption.#objectValues[0]; + static BreakAll = LineBreakWordOption.#objectValues[1]; + static KeepAll = LineBreakWordOption.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LineSegmenter.mjs b/ffi/capi/bindings/js/LineSegmenter.mjs index a898b8261de..4f4d5fac6b6 100644 --- a/ffi/capi/bindings/js/LineSegmenter.mjs +++ b/ffi/capi/bindings/js/LineSegmenter.mjs @@ -49,7 +49,7 @@ export class LineSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LineSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -67,7 +67,7 @@ export class LineSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LineSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -85,7 +85,7 @@ export class LineSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LineSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -105,7 +105,7 @@ export class LineSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LineSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -127,7 +127,7 @@ export class LineSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LineSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -149,7 +149,7 @@ export class LineSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LineSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -163,20 +163,20 @@ export class LineSegmenter { } segment(input) { - let functionGarbageCollector = new diplomatRuntime.GarbageCollector(); - const inputSlice = [...functionGarbageCollector.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)).splat()]; + let functionGarbageCollectorGrip = new diplomatRuntime.GarbageCollectorGrip(); + const inputSlice = functionGarbageCollectorGrip.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)); // This lifetime edge depends on lifetimes 'a let aEdges = [this, inputSlice]; - const result = wasm.icu4x_LineSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice); + const result = wasm.icu4x_LineSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice.splat()); try { return new LineBreakIteratorUtf16(diplomatRuntime.internalConstructor, result, [], aEdges); } finally { - functionGarbageCollector.garbageCollect(); + functionGarbageCollectorGrip.releaseToGarbageCollector(); } } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/ListFormatter.mjs b/ffi/capi/bindings/js/ListFormatter.mjs index da6fed8a4b5..29a398d4afc 100644 --- a/ffi/capi/bindings/js/ListFormatter.mjs +++ b/ffi/capi/bindings/js/ListFormatter.mjs @@ -47,7 +47,7 @@ export class ListFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -65,7 +65,7 @@ export class ListFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -83,7 +83,7 @@ export class ListFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new ListFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -97,10 +97,10 @@ export class ListFormatter { format(list) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const listSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.strs(wasm, list, "string16")).splat()]; + const listSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.strs(wasm, list, "string16")); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_ListFormatter_format_utf16_mv1(this.ffiValue, ...listSlice, write.buffer); + wasm.icu4x_ListFormatter_format_utf16_mv1(this.ffiValue, ...listSlice.splat(), write.buffer); try { return write.readString8(); diff --git a/ffi/capi/bindings/js/ListLength.mjs b/ffi/capi/bindings/js/ListLength.mjs index 4e55750411f..1302be70684 100644 --- a/ffi/capi/bindings/js/ListLength.mjs +++ b/ffi/capi/bindings/js/ListLength.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class ListLength { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Wide", 0], ["Short", 1], ["Narrow", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return ListLength.#objectValues[arguments[1]]; + } + if (value instanceof ListLength) { - this.#value = value.value; - return; + return value; } - if (ListLength.values.has(value)) { - this.#value = value; - return; + let intVal = ListLength.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return ListLength.#objectValues[intVal]; } throw TypeError(value + " is not a ListLength and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...ListLength.#values.keys()][this.#value]; } get ffiValue() { - return ListLength.values.get(this.#value); + return this.#value; } - - static Wide = new ListLength("Wide"); - static Short = new ListLength("Short"); - static Narrow = new ListLength("Narrow"); + static #objectValues = [ + new ListLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new ListLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new ListLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Wide = ListLength.#objectValues[0]; + static Short = ListLength.#objectValues[1]; + static Narrow = ListLength.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/Locale.mjs b/ffi/capi/bindings/js/Locale.mjs index 22bab775dd3..b35aedced72 100644 --- a/ffi/capi/bindings/js/Locale.mjs +++ b/ffi/capi/bindings/js/Locale.mjs @@ -42,15 +42,15 @@ export class Locale { static fromString(name) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const nameSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)).splat()]; + const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Locale_from_string_mv1(diplomatReceive.buffer, ...nameSlice); + const result = wasm.icu4x_Locale_from_string_mv1(diplomatReceive.buffer, ...nameSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } return new Locale(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -99,11 +99,11 @@ export class Locale { getUnicodeExtension(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_Locale_get_unicode_extension_mv1(this.ffiValue, ...sSlice, write.buffer); + const result = wasm.icu4x_Locale_get_unicode_extension_mv1(this.ffiValue, ...sSlice.splat(), write.buffer); try { return result === 0 ? null : write.readString8(); @@ -132,15 +132,15 @@ export class Locale { set language(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Locale_set_language_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice); + const result = wasm.icu4x_Locale_set_language_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } @@ -170,15 +170,15 @@ export class Locale { set region(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Locale_set_region_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice); + const result = wasm.icu4x_Locale_set_region_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } @@ -208,15 +208,15 @@ export class Locale { set script(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Locale_set_script_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice); + const result = wasm.icu4x_Locale_set_script_mv1(diplomatReceive.buffer, this.ffiValue, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } @@ -232,17 +232,17 @@ export class Locale { static canonicalize(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_Locale_canonicalize_mv1(diplomatReceive.buffer, ...sSlice, write.buffer); + const result = wasm.icu4x_Locale_canonicalize_mv1(diplomatReceive.buffer, ...sSlice.splat(), write.buffer); try { if (!diplomatReceive.resultFlag) { - const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } return write.readString8(); @@ -273,9 +273,9 @@ export class Locale { normalizingEq(other) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const otherSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, other)).splat()]; + const otherSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, other)); - const result = wasm.icu4x_Locale_normalizing_eq_mv1(this.ffiValue, ...otherSlice); + const result = wasm.icu4x_Locale_normalizing_eq_mv1(this.ffiValue, ...otherSlice.splat()); try { return result; @@ -289,9 +289,9 @@ export class Locale { compareToString(other) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const otherSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, other)).splat()]; + const otherSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, other)); - const result = wasm.icu4x_Locale_compare_to_string_mv1(this.ffiValue, ...otherSlice); + const result = wasm.icu4x_Locale_compare_to_string_mv1(this.ffiValue, ...otherSlice.splat()); try { return result; diff --git a/ffi/capi/bindings/js/LocaleCanonicalizer.mjs b/ffi/capi/bindings/js/LocaleCanonicalizer.mjs index 9997a91b58d..180c154483b 100644 --- a/ffi/capi/bindings/js/LocaleCanonicalizer.mjs +++ b/ffi/capi/bindings/js/LocaleCanonicalizer.mjs @@ -49,7 +49,7 @@ export class LocaleCanonicalizer { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new LocaleCanonicalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -67,7 +67,7 @@ export class LocaleCanonicalizer { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new LocaleCanonicalizer(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -82,7 +82,7 @@ export class LocaleCanonicalizer { const result = wasm.icu4x_LocaleCanonicalizer_canonicalize_mv1(this.ffiValue, locale.ffiValue); try { - return TransformResult[Array.from(TransformResult.values.keys())[result]]; + return new TransformResult(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/LocaleDirection.mjs b/ffi/capi/bindings/js/LocaleDirection.mjs index 7d8a5261d72..a4da19087e6 100644 --- a/ffi/capi/bindings/js/LocaleDirection.mjs +++ b/ffi/capi/bindings/js/LocaleDirection.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LocaleDirection { #value = undefined; - static values = new Map([ + static #values = new Map([ ["LeftToRight", 0], ["RightToLeft", 1], ["Unknown", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LocaleDirection.#objectValues[arguments[1]]; + } + if (value instanceof LocaleDirection) { - this.#value = value.value; - return; + return value; } - if (LocaleDirection.values.has(value)) { - this.#value = value; - return; + let intVal = LocaleDirection.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LocaleDirection.#objectValues[intVal]; } throw TypeError(value + " is not a LocaleDirection and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LocaleDirection.#values.keys()][this.#value]; } get ffiValue() { - return LocaleDirection.values.get(this.#value); + return this.#value; } - - static LeftToRight = new LocaleDirection("LeftToRight"); - static RightToLeft = new LocaleDirection("RightToLeft"); - static Unknown = new LocaleDirection("Unknown"); + static #objectValues = [ + new LocaleDirection(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LocaleDirection(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new LocaleDirection(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static LeftToRight = LocaleDirection.#objectValues[0]; + static RightToLeft = LocaleDirection.#objectValues[1]; + static Unknown = LocaleDirection.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleDirectionality.mjs b/ffi/capi/bindings/js/LocaleDirectionality.mjs index a9ea6cb33ff..7ba9b69a168 100644 --- a/ffi/capi/bindings/js/LocaleDirectionality.mjs +++ b/ffi/capi/bindings/js/LocaleDirectionality.mjs @@ -48,7 +48,7 @@ export class LocaleDirectionality { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleDirectionality(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -66,7 +66,7 @@ export class LocaleDirectionality { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleDirectionality(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -81,7 +81,7 @@ export class LocaleDirectionality { const result = wasm.icu4x_LocaleDirectionality_get_mv1(this.ffiValue, locale.ffiValue); try { - return LocaleDirection[Array.from(LocaleDirection.values.keys())[result]]; + return new LocaleDirection(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs b/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs index 3b177a2a29b..517fc405b6b 100644 --- a/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs +++ b/ffi/capi/bindings/js/LocaleDisplayNamesFormatter.mjs @@ -49,7 +49,7 @@ export class LocaleDisplayNamesFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleDisplayNamesFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/LocaleExpander.mjs b/ffi/capi/bindings/js/LocaleExpander.mjs index 39fa83b8453..b640fd2b791 100644 --- a/ffi/capi/bindings/js/LocaleExpander.mjs +++ b/ffi/capi/bindings/js/LocaleExpander.mjs @@ -49,7 +49,7 @@ export class LocaleExpander { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new LocaleExpander(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -67,7 +67,7 @@ export class LocaleExpander { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new LocaleExpander(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -82,7 +82,7 @@ export class LocaleExpander { const result = wasm.icu4x_LocaleExpander_maximize_mv1(this.ffiValue, locale.ffiValue); try { - return TransformResult[Array.from(TransformResult.values.keys())[result]]; + return new TransformResult(diplomatRuntime.internalConstructor, result); } finally {} @@ -92,7 +92,7 @@ export class LocaleExpander { const result = wasm.icu4x_LocaleExpander_minimize_mv1(this.ffiValue, locale.ffiValue); try { - return TransformResult[Array.from(TransformResult.values.keys())[result]]; + return new TransformResult(diplomatRuntime.internalConstructor, result); } finally {} @@ -102,7 +102,7 @@ export class LocaleExpander { const result = wasm.icu4x_LocaleExpander_minimize_favor_script_mv1(this.ffiValue, locale.ffiValue); try { - return TransformResult[Array.from(TransformResult.values.keys())[result]]; + return new TransformResult(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/LocaleFallbackConfig.mjs b/ffi/capi/bindings/js/LocaleFallbackConfig.mjs index 4b47d0802d6..a4404f7a2d6 100644 --- a/ffi/capi/bindings/js/LocaleFallbackConfig.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackConfig.mjs @@ -36,6 +36,15 @@ export class LocaleFallbackConfig { return [this.#priority.ffiValue] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#priority.ffiValue, Int32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. @@ -43,6 +52,6 @@ export class LocaleFallbackConfig { // should handle this when constructing edge arrays. #fromFFI(ptr) { const priorityDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#priority = LocaleFallbackPriority[Array.from(LocaleFallbackPriority.values.keys())[priorityDeref]]; + this.#priority = new LocaleFallbackPriority(diplomatRuntime.internalConstructor, priorityDeref); } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbackPriority.mjs b/ffi/capi/bindings/js/LocaleFallbackPriority.mjs index 385cdf6c95d..7f5edb59817 100644 --- a/ffi/capi/bindings/js/LocaleFallbackPriority.mjs +++ b/ffi/capi/bindings/js/LocaleFallbackPriority.mjs @@ -10,33 +10,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LocaleFallbackPriority { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Language", 0], ["Region", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LocaleFallbackPriority.#objectValues[arguments[1]]; + } + if (value instanceof LocaleFallbackPriority) { - this.#value = value.value; - return; + return value; } - if (LocaleFallbackPriority.values.has(value)) { - this.#value = value; - return; + let intVal = LocaleFallbackPriority.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LocaleFallbackPriority.#objectValues[intVal]; } throw TypeError(value + " is not a LocaleFallbackPriority and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LocaleFallbackPriority.#values.keys()][this.#value]; } get ffiValue() { - return LocaleFallbackPriority.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new LocaleFallbackPriority(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LocaleFallbackPriority(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Language = new LocaleFallbackPriority("Language"); - static Region = new LocaleFallbackPriority("Region"); + static Language = LocaleFallbackPriority.#objectValues[0]; + static Region = LocaleFallbackPriority.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/LocaleFallbacker.mjs b/ffi/capi/bindings/js/LocaleFallbacker.mjs index 64ea738a821..a2ea1cf1819 100644 --- a/ffi/capi/bindings/js/LocaleFallbacker.mjs +++ b/ffi/capi/bindings/js/LocaleFallbacker.mjs @@ -49,7 +49,7 @@ export class LocaleFallbacker { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new LocaleFallbacker(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/LocaleParseError.mjs b/ffi/capi/bindings/js/LocaleParseError.mjs index 56d05abf2e3..8217460ffff 100644 --- a/ffi/capi/bindings/js/LocaleParseError.mjs +++ b/ffi/capi/bindings/js/LocaleParseError.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class LocaleParseError { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Unknown", 0], ["Language", 1], ["Subtag", 2], @@ -16,29 +16,46 @@ export class LocaleParseError { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return LocaleParseError.#objectValues[arguments[1]]; + } + if (value instanceof LocaleParseError) { - this.#value = value.value; - return; + return value; } - if (LocaleParseError.values.has(value)) { - this.#value = value; - return; + let intVal = LocaleParseError.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return LocaleParseError.#objectValues[intVal]; } throw TypeError(value + " is not a LocaleParseError and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...LocaleParseError.#values.keys()][this.#value]; } get ffiValue() { - return LocaleParseError.values.get(this.#value); + return this.#value; } - - static Unknown = new LocaleParseError("Unknown"); - static Language = new LocaleParseError("Language"); - static Subtag = new LocaleParseError("Subtag"); - static Extension = new LocaleParseError("Extension"); + static #objectValues = [ + new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Unknown = LocaleParseError.#objectValues[0]; + static Language = LocaleParseError.#objectValues[1]; + static Subtag = LocaleParseError.#objectValues[2]; + static Extension = LocaleParseError.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/MeasureUnitParser.mjs b/ffi/capi/bindings/js/MeasureUnitParser.mjs index ff1dcaf9314..e1b3d13edbd 100644 --- a/ffi/capi/bindings/js/MeasureUnitParser.mjs +++ b/ffi/capi/bindings/js/MeasureUnitParser.mjs @@ -47,9 +47,9 @@ export class MeasureUnitParser { parse(unitId) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const unitIdSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, unitId)).splat()]; + const unitIdSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, unitId)); - const result = wasm.icu4x_MeasureUnitParser_parse_mv1(this.ffiValue, ...unitIdSlice); + const result = wasm.icu4x_MeasureUnitParser_parse_mv1(this.ffiValue, ...unitIdSlice.splat()); try { return result === 0 ? null : new MeasureUnit(diplomatRuntime.internalConstructor, result, []); diff --git a/ffi/capi/bindings/js/MetazoneCalculator.mjs b/ffi/capi/bindings/js/MetazoneCalculator.mjs index 6797459cfea..c1df099410d 100644 --- a/ffi/capi/bindings/js/MetazoneCalculator.mjs +++ b/ffi/capi/bindings/js/MetazoneCalculator.mjs @@ -51,7 +51,7 @@ export class MetazoneCalculator { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new MetazoneCalculator(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/PluralCategories.mjs b/ffi/capi/bindings/js/PluralCategories.mjs index f9e63d35b01..119279e1710 100644 --- a/ffi/capi/bindings/js/PluralCategories.mjs +++ b/ffi/capi/bindings/js/PluralCategories.mjs @@ -57,6 +57,20 @@ export class PluralCategories { return [this.#zero, this.#one, this.#two, this.#few, this.#many, this.#other] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#zero, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 1, this.#one, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 2, this.#two, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 3, this.#few, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#many, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 5, this.#other, Uint8Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. diff --git a/ffi/capi/bindings/js/PluralCategory.mjs b/ffi/capi/bindings/js/PluralCategory.mjs index 10f867f22cd..9d57b73f389 100644 --- a/ffi/capi/bindings/js/PluralCategory.mjs +++ b/ffi/capi/bindings/js/PluralCategory.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class PluralCategory { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Zero", 0], ["One", 1], ["Two", 2], @@ -18,48 +18,67 @@ export class PluralCategory { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return PluralCategory.#objectValues[arguments[1]]; + } + if (value instanceof PluralCategory) { - this.#value = value.value; - return; + return value; } - if (PluralCategory.values.has(value)) { - this.#value = value; - return; + let intVal = PluralCategory.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return PluralCategory.#objectValues[intVal]; } throw TypeError(value + " is not a PluralCategory and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...PluralCategory.#values.keys()][this.#value]; } get ffiValue() { - return PluralCategory.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), + new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), + ]; - static Zero = new PluralCategory("Zero"); - static One = new PluralCategory("One"); - static Two = new PluralCategory("Two"); - static Few = new PluralCategory("Few"); - static Many = new PluralCategory("Many"); - static Other = new PluralCategory("Other"); + static Zero = PluralCategory.#objectValues[0]; + static One = PluralCategory.#objectValues[1]; + static Two = PluralCategory.#objectValues[2]; + static Few = PluralCategory.#objectValues[3]; + static Many = PluralCategory.#objectValues[4]; + static Other = PluralCategory.#objectValues[5]; static getForCldrString(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_PluralCategory_get_for_cldr_string_mv1(diplomatReceive.buffer, ...sSlice); + const result = wasm.icu4x_PluralCategory_get_for_cldr_string_mv1(diplomatReceive.buffer, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { return null; } - return PluralCategory[Array.from(PluralCategory.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + return new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); } finally { diff --git a/ffi/capi/bindings/js/PluralOperands.mjs b/ffi/capi/bindings/js/PluralOperands.mjs index d512399ab62..66aa6d97b47 100644 --- a/ffi/capi/bindings/js/PluralOperands.mjs +++ b/ffi/capi/bindings/js/PluralOperands.mjs @@ -41,15 +41,15 @@ export class PluralOperands { static fromString(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_PluralOperands_from_string_mv1(diplomatReceive.buffer, ...sSlice); + const result = wasm.icu4x_PluralOperands_from_string_mv1(diplomatReceive.buffer, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = FixedDecimalParseError[Array.from(FixedDecimalParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new FixedDecimalParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('FixedDecimalParseError: ' + cause.value, { cause }); } return new PluralOperands(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/PluralRules.mjs b/ffi/capi/bindings/js/PluralRules.mjs index 331d50c87ba..b8cbc3d5117 100644 --- a/ffi/capi/bindings/js/PluralRules.mjs +++ b/ffi/capi/bindings/js/PluralRules.mjs @@ -49,7 +49,7 @@ export class PluralRules { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PluralRules(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -67,7 +67,7 @@ export class PluralRules { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PluralRules(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -82,7 +82,7 @@ export class PluralRules { const result = wasm.icu4x_PluralRules_category_for_mv1(this.ffiValue, op.ffiValue); try { - return PluralCategory[Array.from(PluralCategory.values.keys())[result]]; + return new PluralCategory(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs b/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs index 3ab3d6a3749..d621f35c01c 100644 --- a/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs +++ b/ffi/capi/bindings/js/PropertyValueNameToEnumMapper.mjs @@ -45,9 +45,9 @@ export class PropertyValueNameToEnumMapper { getStrict(name) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const nameSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)).splat()]; + const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); - const result = wasm.icu4x_PropertyValueNameToEnumMapper_get_strict_mv1(this.ffiValue, ...nameSlice); + const result = wasm.icu4x_PropertyValueNameToEnumMapper_get_strict_mv1(this.ffiValue, ...nameSlice.splat()); try { return result; @@ -61,9 +61,9 @@ export class PropertyValueNameToEnumMapper { getLoose(name) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const nameSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)).splat()]; + const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, name)); - const result = wasm.icu4x_PropertyValueNameToEnumMapper_get_loose_mv1(this.ffiValue, ...nameSlice); + const result = wasm.icu4x_PropertyValueNameToEnumMapper_get_loose_mv1(this.ffiValue, ...nameSlice.splat()); try { return result; @@ -81,7 +81,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -99,7 +99,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -117,7 +117,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -135,7 +135,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -153,7 +153,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -171,7 +171,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -189,7 +189,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -207,7 +207,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -225,7 +225,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -243,7 +243,7 @@ export class PropertyValueNameToEnumMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new PropertyValueNameToEnumMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/RegionDisplayNames.mjs b/ffi/capi/bindings/js/RegionDisplayNames.mjs index f2f9d44e6e5..576ce63dcb3 100644 --- a/ffi/capi/bindings/js/RegionDisplayNames.mjs +++ b/ffi/capi/bindings/js/RegionDisplayNames.mjs @@ -47,7 +47,7 @@ export class RegionDisplayNames { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new RegionDisplayNames(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -61,17 +61,17 @@ export class RegionDisplayNames { of(region) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const regionSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, region)).splat()]; + const regionSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, region)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_RegionDisplayNames_of_mv1(diplomatReceive.buffer, this.ffiValue, ...regionSlice, write.buffer); + const result = wasm.icu4x_RegionDisplayNames_of_mv1(diplomatReceive.buffer, this.ffiValue, ...regionSlice.splat(), write.buffer); try { if (!diplomatReceive.resultFlag) { - const cause = LocaleParseError[Array.from(LocaleParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new LocaleParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('LocaleParseError: ' + cause.value, { cause }); } return write.readString8(); diff --git a/ffi/capi/bindings/js/ScriptWithExtensions.mjs b/ffi/capi/bindings/js/ScriptWithExtensions.mjs index bc6844f4c6d..140564f863d 100644 --- a/ffi/capi/bindings/js/ScriptWithExtensions.mjs +++ b/ffi/capi/bindings/js/ScriptWithExtensions.mjs @@ -49,7 +49,7 @@ export class ScriptWithExtensions { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new ScriptWithExtensions(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/SegmenterWordType.mjs b/ffi/capi/bindings/js/SegmenterWordType.mjs index fcef34b898a..4c679a8c2fc 100644 --- a/ffi/capi/bindings/js/SegmenterWordType.mjs +++ b/ffi/capi/bindings/js/SegmenterWordType.mjs @@ -8,37 +8,53 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class SegmenterWordType { #value = undefined; - static values = new Map([ + static #values = new Map([ ["None", 0], ["Number", 1], ["Letter", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return SegmenterWordType.#objectValues[arguments[1]]; + } + if (value instanceof SegmenterWordType) { - this.#value = value.value; - return; + return value; } - if (SegmenterWordType.values.has(value)) { - this.#value = value; - return; + let intVal = SegmenterWordType.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return SegmenterWordType.#objectValues[intVal]; } throw TypeError(value + " is not a SegmenterWordType and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...SegmenterWordType.#values.keys()][this.#value]; } get ffiValue() { - return SegmenterWordType.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new SegmenterWordType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new SegmenterWordType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new SegmenterWordType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; - static None = new SegmenterWordType("None"); - static Number = new SegmenterWordType("Number"); - static Letter = new SegmenterWordType("Letter"); + static None = SegmenterWordType.#objectValues[0]; + static Number = SegmenterWordType.#objectValues[1]; + static Letter = SegmenterWordType.#objectValues[2]; get isWordLike() { const result = wasm.icu4x_SegmenterWordType_is_word_like_mv1(this.ffiValue); diff --git a/ffi/capi/bindings/js/SentenceSegmenter.mjs b/ffi/capi/bindings/js/SentenceSegmenter.mjs index 710af77db9d..25600c84f1b 100644 --- a/ffi/capi/bindings/js/SentenceSegmenter.mjs +++ b/ffi/capi/bindings/js/SentenceSegmenter.mjs @@ -48,7 +48,7 @@ export class SentenceSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new SentenceSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -60,20 +60,20 @@ export class SentenceSegmenter { } segment(input) { - let functionGarbageCollector = new diplomatRuntime.GarbageCollector(); - const inputSlice = [...functionGarbageCollector.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)).splat()]; + let functionGarbageCollectorGrip = new diplomatRuntime.GarbageCollectorGrip(); + const inputSlice = functionGarbageCollectorGrip.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)); // This lifetime edge depends on lifetimes 'a let aEdges = [this, inputSlice]; - const result = wasm.icu4x_SentenceSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice); + const result = wasm.icu4x_SentenceSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice.splat()); try { return new SentenceBreakIteratorUtf16(diplomatRuntime.internalConstructor, result, [], aEdges); } finally { - functionGarbageCollector.garbageCollect(); + functionGarbageCollectorGrip.releaseToGarbageCollector(); } } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/Time.mjs b/ffi/capi/bindings/js/Time.mjs index 2545713ee3b..95cb3945671 100644 --- a/ffi/capi/bindings/js/Time.mjs +++ b/ffi/capi/bindings/js/Time.mjs @@ -47,7 +47,7 @@ export class Time { try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new Time(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -61,15 +61,15 @@ export class Time { static fromString(v) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const vSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)).splat()]; + const vSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, v)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); - const result = wasm.icu4x_Time_from_string_mv1(diplomatReceive.buffer, ...vSlice); + const result = wasm.icu4x_Time_from_string_mv1(diplomatReceive.buffer, ...vSlice.splat()); try { if (!diplomatReceive.resultFlag) { - const cause = CalendarParseError[Array.from(CalendarParseError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarParseError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarParseError: ' + cause.value, { cause }); } return new Time(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -89,7 +89,7 @@ export class Time { try { if (!diplomatReceive.resultFlag) { - const cause = CalendarError[Array.from(CalendarError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new CalendarError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('CalendarError: ' + cause.value, { cause }); } return new Time(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/TimeFormatter.mjs b/ffi/capi/bindings/js/TimeFormatter.mjs index 7794516c26c..55ee3fb6f98 100644 --- a/ffi/capi/bindings/js/TimeFormatter.mjs +++ b/ffi/capi/bindings/js/TimeFormatter.mjs @@ -52,7 +52,7 @@ export class TimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new TimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/TimeLength.mjs b/ffi/capi/bindings/js/TimeLength.mjs index b95bd939b36..ed3589a23c7 100644 --- a/ffi/capi/bindings/js/TimeLength.mjs +++ b/ffi/capi/bindings/js/TimeLength.mjs @@ -8,7 +8,7 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class TimeLength { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Full", 0], ["Long", 1], ["Medium", 2], @@ -16,29 +16,46 @@ export class TimeLength { ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return TimeLength.#objectValues[arguments[1]]; + } + if (value instanceof TimeLength) { - this.#value = value.value; - return; + return value; } - if (TimeLength.values.has(value)) { - this.#value = value; - return; + let intVal = TimeLength.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return TimeLength.#objectValues[intVal]; } throw TypeError(value + " is not a TimeLength and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...TimeLength.#values.keys()][this.#value]; } get ffiValue() { - return TimeLength.values.get(this.#value); + return this.#value; } - - static Full = new TimeLength("Full"); - static Long = new TimeLength("Long"); - static Medium = new TimeLength("Medium"); - static Short = new TimeLength("Short"); + static #objectValues = [ + new TimeLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new TimeLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new TimeLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + new TimeLength(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), + ]; + + static Full = TimeLength.#objectValues[0]; + static Long = TimeLength.#objectValues[1]; + static Medium = TimeLength.#objectValues[2]; + static Short = TimeLength.#objectValues[3]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneFormatter.mjs b/ffi/capi/bindings/js/TimeZoneFormatter.mjs index e4493bb5f87..cc5b6254db0 100644 --- a/ffi/capi/bindings/js/TimeZoneFormatter.mjs +++ b/ffi/capi/bindings/js/TimeZoneFormatter.mjs @@ -50,7 +50,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -70,7 +70,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new TimeZoneFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -90,7 +90,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -108,7 +108,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -126,7 +126,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -144,7 +144,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -162,7 +162,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -180,7 +180,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -200,7 +200,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } @@ -235,7 +235,7 @@ export class TimeZoneFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); diff --git a/ffi/capi/bindings/js/TimeZoneIdMapper.mjs b/ffi/capi/bindings/js/TimeZoneIdMapper.mjs index 6c8da445152..7ad8903dc50 100644 --- a/ffi/capi/bindings/js/TimeZoneIdMapper.mjs +++ b/ffi/capi/bindings/js/TimeZoneIdMapper.mjs @@ -51,7 +51,7 @@ export class TimeZoneIdMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new TimeZoneIdMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -65,11 +65,11 @@ export class TimeZoneIdMapper { ianaToBcp47(value) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const valueSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)).splat()]; + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_TimeZoneIdMapper_iana_to_bcp47_mv1(this.ffiValue, ...valueSlice, write.buffer); + const result = wasm.icu4x_TimeZoneIdMapper_iana_to_bcp47_mv1(this.ffiValue, ...valueSlice.splat(), write.buffer); try { if (result !== 1) { @@ -89,11 +89,11 @@ export class TimeZoneIdMapper { normalizeIana(value) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const valueSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)).splat()]; + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_TimeZoneIdMapper_normalize_iana_mv1(this.ffiValue, ...valueSlice, write.buffer); + const result = wasm.icu4x_TimeZoneIdMapper_normalize_iana_mv1(this.ffiValue, ...valueSlice.splat(), write.buffer); try { if (result !== 1) { @@ -113,11 +113,11 @@ export class TimeZoneIdMapper { canonicalizeIana(value) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const valueSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)).splat()]; + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_TimeZoneIdMapper_canonicalize_iana_mv1(this.ffiValue, ...valueSlice, write.buffer); + const result = wasm.icu4x_TimeZoneIdMapper_canonicalize_iana_mv1(this.ffiValue, ...valueSlice.splat(), write.buffer); try { if (result !== 1) { @@ -137,11 +137,11 @@ export class TimeZoneIdMapper { findCanonicalIanaFromBcp47(value) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const valueSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)).splat()]; + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_TimeZoneIdMapper_find_canonical_iana_from_bcp47_mv1(this.ffiValue, ...valueSlice, write.buffer); + const result = wasm.icu4x_TimeZoneIdMapper_find_canonical_iana_from_bcp47_mv1(this.ffiValue, ...valueSlice.splat(), write.buffer); try { if (result !== 1) { diff --git a/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs b/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs index fe9aa36233c..eaba57e4d08 100644 --- a/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs +++ b/ffi/capi/bindings/js/TimeZoneIdMapperWithFastCanonicalization.mjs @@ -51,7 +51,7 @@ export class TimeZoneIdMapperWithFastCanonicalization { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new TimeZoneIdMapperWithFastCanonicalization(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -65,11 +65,11 @@ export class TimeZoneIdMapperWithFastCanonicalization { canonicalizeIana(value) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const valueSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)).splat()]; + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_TimeZoneIdMapperWithFastCanonicalization_canonicalize_iana_mv1(this.ffiValue, ...valueSlice, write.buffer); + const result = wasm.icu4x_TimeZoneIdMapperWithFastCanonicalization_canonicalize_iana_mv1(this.ffiValue, ...valueSlice.splat(), write.buffer); try { if (result !== 1) { @@ -89,11 +89,11 @@ export class TimeZoneIdMapperWithFastCanonicalization { canonicalIanaFromBcp47(value) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const valueSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)).splat()]; + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - const result = wasm.icu4x_TimeZoneIdMapperWithFastCanonicalization_canonical_iana_from_bcp47_mv1(this.ffiValue, ...valueSlice, write.buffer); + const result = wasm.icu4x_TimeZoneIdMapperWithFastCanonicalization_canonical_iana_from_bcp47_mv1(this.ffiValue, ...valueSlice.splat(), write.buffer); try { if (result !== 1) { diff --git a/ffi/capi/bindings/js/TitlecaseMapper.mjs b/ffi/capi/bindings/js/TitlecaseMapper.mjs index 0649fe6ea85..11f635c11bd 100644 --- a/ffi/capi/bindings/js/TitlecaseMapper.mjs +++ b/ffi/capi/bindings/js/TitlecaseMapper.mjs @@ -47,7 +47,7 @@ export class TitlecaseMapper { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new TitlecaseMapper(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -61,10 +61,10 @@ export class TitlecaseMapper { titlecaseSegment(s, locale, options) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const write = new diplomatRuntime.DiplomatWriteBuf(wasm); - wasm.icu4x_TitlecaseMapper_titlecase_segment_v1_mv1(this.ffiValue, ...sSlice, locale.ffiValue, ...options._intoFFI(functionCleanupArena, {}), write.buffer); + wasm.icu4x_TitlecaseMapper_titlecase_segment_v1_mv1(this.ffiValue, ...sSlice.splat(), locale.ffiValue, ...options._intoFFI(functionCleanupArena, {}), write.buffer); try { return write.readString8(); diff --git a/ffi/capi/bindings/js/TitlecaseOptions.mjs b/ffi/capi/bindings/js/TitlecaseOptions.mjs index 62ddf7d6f32..c4421a5bc67 100644 --- a/ffi/capi/bindings/js/TitlecaseOptions.mjs +++ b/ffi/capi/bindings/js/TitlecaseOptions.mjs @@ -44,6 +44,16 @@ export class TitlecaseOptions { return [this.#leadingAdjustment.ffiValue, this.#trailingCase.ffiValue] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#leadingAdjustment.ffiValue, Int32Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#trailingCase.ffiValue, Int32Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. @@ -51,9 +61,9 @@ export class TitlecaseOptions { // should handle this when constructing edge arrays. #fromFFI(ptr) { const leadingAdjustmentDeref = diplomatRuntime.enumDiscriminant(wasm, ptr); - this.#leadingAdjustment = LeadingAdjustment[Array.from(LeadingAdjustment.values.keys())[leadingAdjustmentDeref]]; + this.#leadingAdjustment = new LeadingAdjustment(diplomatRuntime.internalConstructor, leadingAdjustmentDeref); const trailingCaseDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#trailingCase = TrailingCase[Array.from(TrailingCase.values.keys())[trailingCaseDeref]]; + this.#trailingCase = new TrailingCase(diplomatRuntime.internalConstructor, trailingCaseDeref); } static defaultOptions() { diff --git a/ffi/capi/bindings/js/TrailingCase.mjs b/ffi/capi/bindings/js/TrailingCase.mjs index 3e06c9c3a34..eb99fb3d0d5 100644 --- a/ffi/capi/bindings/js/TrailingCase.mjs +++ b/ffi/capi/bindings/js/TrailingCase.mjs @@ -8,33 +8,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class TrailingCase { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Lower", 0], ["Unchanged", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return TrailingCase.#objectValues[arguments[1]]; + } + if (value instanceof TrailingCase) { - this.#value = value.value; - return; + return value; } - if (TrailingCase.values.has(value)) { - this.#value = value; - return; + let intVal = TrailingCase.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return TrailingCase.#objectValues[intVal]; } throw TypeError(value + " is not a TrailingCase and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...TrailingCase.#values.keys()][this.#value]; } get ffiValue() { - return TrailingCase.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new TrailingCase(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new TrailingCase(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Lower = new TrailingCase("Lower"); - static Unchanged = new TrailingCase("Unchanged"); + static Lower = TrailingCase.#objectValues[0]; + static Unchanged = TrailingCase.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/TransformResult.mjs b/ffi/capi/bindings/js/TransformResult.mjs index 7e5059ebe16..00a54f99109 100644 --- a/ffi/capi/bindings/js/TransformResult.mjs +++ b/ffi/capi/bindings/js/TransformResult.mjs @@ -8,33 +8,48 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class TransformResult { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Modified", 0], ["Unmodified", 1] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return TransformResult.#objectValues[arguments[1]]; + } + if (value instanceof TransformResult) { - this.#value = value.value; - return; + return value; } - if (TransformResult.values.has(value)) { - this.#value = value; - return; + let intVal = TransformResult.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return TransformResult.#objectValues[intVal]; } throw TypeError(value + " is not a TransformResult and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...TransformResult.#values.keys()][this.#value]; } get ffiValue() { - return TransformResult.values.get(this.#value); + return this.#value; } + static #objectValues = [ + new TransformResult(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new TransformResult(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + ]; - static Modified = new TransformResult("Modified"); - static Unmodified = new TransformResult("Unmodified"); + static Modified = TransformResult.#objectValues[0]; + static Unmodified = TransformResult.#objectValues[1]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/UnicodeSetData.mjs b/ffi/capi/bindings/js/UnicodeSetData.mjs index ee454d1d333..c8390b0e750 100644 --- a/ffi/capi/bindings/js/UnicodeSetData.mjs +++ b/ffi/capi/bindings/js/UnicodeSetData.mjs @@ -48,9 +48,9 @@ export class UnicodeSetData { contains(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); - const sSlice = [...functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)).splat()]; + const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); - const result = wasm.icu4x_UnicodeSetData_contains_mv1(this.ffiValue, ...sSlice); + const result = wasm.icu4x_UnicodeSetData_contains_mv1(this.ffiValue, ...sSlice.splat()); try { return result; @@ -78,7 +78,7 @@ export class UnicodeSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnicodeSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -96,7 +96,7 @@ export class UnicodeSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnicodeSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -114,7 +114,7 @@ export class UnicodeSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnicodeSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -132,7 +132,7 @@ export class UnicodeSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnicodeSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -150,7 +150,7 @@ export class UnicodeSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnicodeSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -168,7 +168,7 @@ export class UnicodeSetData { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnicodeSetData(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/UnitsConverterFactory.mjs b/ffi/capi/bindings/js/UnitsConverterFactory.mjs index ee00d5206e1..05588edc845 100644 --- a/ffi/capi/bindings/js/UnitsConverterFactory.mjs +++ b/ffi/capi/bindings/js/UnitsConverterFactory.mjs @@ -52,7 +52,7 @@ export class UnitsConverterFactory { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new UnitsConverterFactory(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); diff --git a/ffi/capi/bindings/js/WeekCalculator.mjs b/ffi/capi/bindings/js/WeekCalculator.mjs index 4747306256a..3f94d3da073 100644 --- a/ffi/capi/bindings/js/WeekCalculator.mjs +++ b/ffi/capi/bindings/js/WeekCalculator.mjs @@ -50,7 +50,7 @@ export class WeekCalculator { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new WeekCalculator(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -75,7 +75,7 @@ export class WeekCalculator { const result = wasm.icu4x_WeekCalculator_first_weekday_mv1(this.ffiValue); try { - return (() => {for (let i of IsoWeekday.values) { if(i[1] === result) return IsoWeekday[i[0]]; } return null;})(); + return new IsoWeekday(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/WeekOf.mjs b/ffi/capi/bindings/js/WeekOf.mjs index b13774d6ebc..28aa35f60ce 100644 --- a/ffi/capi/bindings/js/WeekOf.mjs +++ b/ffi/capi/bindings/js/WeekOf.mjs @@ -30,11 +30,26 @@ export class WeekOf { // Return this struct in FFI function friendly format. // Returns an array that can be expanded with spread syntax (...) + // JS structs need to be generated with or without padding depending on whether they are being passed as aggregates or splatted out into fields. + // Most of the time this is known beforehand: large structs (>2 scalar fields) always get padding, and structs passed directly in parameters omit padding + // if they are small. However small structs within large structs also get padding, and we signal that by setting forcePadding. _intoFFI( functionCleanupArena, - appendArrayMap + appendArrayMap, + forcePadding ) { - return [this.#week,/* Padding for week */ 0, 0 /* End Padding */, this.#unit.ffiValue] + return [this.#week, ...diplomatRuntime.maybePaddingFields(forcePadding, 1 /* x i16 */), this.#unit.ffiValue] + } + + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap, + forcePadding + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#week, Uint16Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#unit.ffiValue, Int32Array); } // This struct contains borrowed fields, so this takes in a list of @@ -46,6 +61,6 @@ export class WeekOf { const weekDeref = (new Uint16Array(wasm.memory.buffer, ptr, 1))[0]; this.#week = weekDeref; const unitDeref = diplomatRuntime.enumDiscriminant(wasm, ptr + 4); - this.#unit = WeekRelativeUnit[Array.from(WeekRelativeUnit.values.keys())[unitDeref]]; + this.#unit = new WeekRelativeUnit(diplomatRuntime.internalConstructor, unitDeref); } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekRelativeUnit.mjs b/ffi/capi/bindings/js/WeekRelativeUnit.mjs index c364435491b..822d3dbac30 100644 --- a/ffi/capi/bindings/js/WeekRelativeUnit.mjs +++ b/ffi/capi/bindings/js/WeekRelativeUnit.mjs @@ -8,35 +8,51 @@ import * as diplomatRuntime from "./diplomat-runtime.mjs"; export class WeekRelativeUnit { #value = undefined; - static values = new Map([ + static #values = new Map([ ["Previous", 0], ["Current", 1], ["Next", 2] ]); constructor(value) { + if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { + // We pass in two internalConstructor arguments to create *new* + // instances of this type, otherwise the enums are treated as singletons. + if (arguments[1] === diplomatRuntime.internalConstructor ) { + this.#value = arguments[2]; + return; + } + return WeekRelativeUnit.#objectValues[arguments[1]]; + } + if (value instanceof WeekRelativeUnit) { - this.#value = value.value; - return; + return value; } - if (WeekRelativeUnit.values.has(value)) { - this.#value = value; - return; + let intVal = WeekRelativeUnit.#values.get(value); + + // Nullish check, checks for null or undefined + if (intVal == null) { + return WeekRelativeUnit.#objectValues[intVal]; } throw TypeError(value + " is not a WeekRelativeUnit and does not correspond to any of its enumerator values."); } get value() { - return this.#value; + return [...WeekRelativeUnit.#values.keys()][this.#value]; } get ffiValue() { - return WeekRelativeUnit.values.get(this.#value); + return this.#value; } - - static Previous = new WeekRelativeUnit("Previous"); - static Current = new WeekRelativeUnit("Current"); - static Next = new WeekRelativeUnit("Next"); + static #objectValues = [ + new WeekRelativeUnit(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), + new WeekRelativeUnit(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), + new WeekRelativeUnit(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), + ]; + + static Previous = WeekRelativeUnit.#objectValues[0]; + static Current = WeekRelativeUnit.#objectValues[1]; + static Next = WeekRelativeUnit.#objectValues[2]; } \ No newline at end of file diff --git a/ffi/capi/bindings/js/WeekendContainsDay.mjs b/ffi/capi/bindings/js/WeekendContainsDay.mjs index a7b04c17300..2d84f2268ed 100644 --- a/ffi/capi/bindings/js/WeekendContainsDay.mjs +++ b/ffi/capi/bindings/js/WeekendContainsDay.mjs @@ -89,6 +89,21 @@ export class WeekendContainsDay { return [this.#monday, this.#tuesday, this.#wednesday, this.#thursday, this.#friday, this.#saturday, this.#sunday] } + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#monday, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 1, this.#tuesday, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 2, this.#wednesday, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 3, this.#thursday, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#friday, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 5, this.#saturday, Uint8Array); + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 6, this.#sunday, Uint8Array); + } + // This struct contains borrowed fields, so this takes in a list of // "edges" corresponding to where each lifetime's data may have been borrowed from // and passes it down to individual fields containing the borrow. diff --git a/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs b/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs index 26d30f87f00..c46cda266a4 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs +++ b/ffi/capi/bindings/js/WordBreakIteratorLatin1.mjs @@ -55,7 +55,7 @@ export class WordBreakIteratorLatin1 { const result = wasm.icu4x_WordBreakIteratorLatin1_word_type_mv1(this.ffiValue); try { - return SegmenterWordType[Array.from(SegmenterWordType.values.keys())[result]]; + return new SegmenterWordType(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs b/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs index b14f14baf6a..4c67f12c40e 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs +++ b/ffi/capi/bindings/js/WordBreakIteratorUtf16.mjs @@ -55,7 +55,7 @@ export class WordBreakIteratorUtf16 { const result = wasm.icu4x_WordBreakIteratorUtf16_word_type_mv1(this.ffiValue); try { - return SegmenterWordType[Array.from(SegmenterWordType.values.keys())[result]]; + return new SegmenterWordType(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs b/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs index ff34038654d..39f1b37f45b 100644 --- a/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs +++ b/ffi/capi/bindings/js/WordBreakIteratorUtf8.mjs @@ -55,7 +55,7 @@ export class WordBreakIteratorUtf8 { const result = wasm.icu4x_WordBreakIteratorUtf8_word_type_mv1(this.ffiValue); try { - return SegmenterWordType[Array.from(SegmenterWordType.values.keys())[result]]; + return new SegmenterWordType(diplomatRuntime.internalConstructor, result); } finally {} diff --git a/ffi/capi/bindings/js/WordSegmenter.mjs b/ffi/capi/bindings/js/WordSegmenter.mjs index 27d9fa7774a..7eabcd01b64 100644 --- a/ffi/capi/bindings/js/WordSegmenter.mjs +++ b/ffi/capi/bindings/js/WordSegmenter.mjs @@ -48,7 +48,7 @@ export class WordSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new WordSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -66,7 +66,7 @@ export class WordSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new WordSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -84,7 +84,7 @@ export class WordSegmenter { try { if (!diplomatReceive.resultFlag) { - const cause = DataError[Array.from(DataError.values.keys())[diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)]]; + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('DataError: ' + cause.value, { cause }); } return new WordSegmenter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -96,20 +96,20 @@ export class WordSegmenter { } segment(input) { - let functionGarbageCollector = new diplomatRuntime.GarbageCollector(); - const inputSlice = [...functionGarbageCollector.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)).splat()]; + let functionGarbageCollectorGrip = new diplomatRuntime.GarbageCollectorGrip(); + const inputSlice = functionGarbageCollectorGrip.alloc(diplomatRuntime.DiplomatBuf.str16(wasm, input)); // This lifetime edge depends on lifetimes 'a let aEdges = [this, inputSlice]; - const result = wasm.icu4x_WordSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice); + const result = wasm.icu4x_WordSegmenter_segment_utf16_mv1(this.ffiValue, ...inputSlice.splat()); try { return new WordBreakIteratorUtf16(diplomatRuntime.internalConstructor, result, [], aEdges); } finally { - functionGarbageCollector.garbageCollect(); + functionGarbageCollectorGrip.releaseToGarbageCollector(); } } } \ No newline at end of file diff --git a/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs b/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs index e0dc7b319c5..c4355e994e8 100644 --- a/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs +++ b/ffi/capi/bindings/js/ZonedDateTimeFormatter.mjs @@ -54,7 +54,7 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new ZonedDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -74,7 +74,7 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return new ZonedDateTimeFormatter(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); @@ -96,7 +96,7 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); @@ -118,7 +118,7 @@ export class ZonedDateTimeFormatter { try { if (!diplomatReceive.resultFlag) { - const cause = (() => {for (let i of Error.values) { if(i[1] === diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)) return Error[i[0]]; } return null;})(); + const cause = new Error(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); throw new globalThis.Error('Error: ' + cause.value, { cause }); } return write.readString8(); diff --git a/ffi/capi/bindings/js/diplomat-runtime.mjs b/ffi/capi/bindings/js/diplomat-runtime.mjs index c77c87515f6..18846dfc0da 100644 --- a/ffi/capi/bindings/js/diplomat-runtime.mjs +++ b/ffi/capi/bindings/js/diplomat-runtime.mjs @@ -59,6 +59,102 @@ export function enumDiscriminant(wasm, ptr) { return (new Int32Array(wasm.memory.buffer, ptr, 1))[0] } +/** + * Return an array of paddingCount zeroes to be spread into a function call + * if needsPaddingFields is true, else empty + */ +export function maybePaddingFields(needsPaddingFields, paddingCount) { + if (needsPaddingFields) { + return Array(paddingCount).fill(0); + } else { + return []; + } +} + +/** +* Write a value of width `width` to a an ArrayBuffer `arrayBuffer` +* at byte offset `offset`, treating it as a buffer of kind `typedArrayKind` +* (which is a `TypedArray` variant like `Uint8Array` or `Int16Array`) +*/ +export function writeToArrayBuffer(arrayBuffer, offset, value, typedArrayKind) { + let buffer = new typedArrayKind(arrayBuffer, offset); + buffer[0] = value; +} + +/** +* Take `jsValue` and write it to arrayBuffer at offset `offset` if it is non-null +* calling `writeToArrayBufferCallback(arrayBuffer, offset, jsValue)` to write to the buffer, +* also writing a tag bit. +* +* `size` and `align` are the size and alignment of T, not of Option +*/ +export function writeOptionToArrayBuffer(arrayBuffer, offset, jsValue, size, align, writeToArrayBufferCallback) { + // perform a nullish check, not a null check, + // we want identical behavior for undefined + if (jsValue != null) { + writeToArrayBufferCallback(arrayBuffer, offset, jsValue); + writeToArrayBuffer(arrayBuffer, offset + size, 1, Uint8Array); + } +} + +/** +* For Option of given size/align (of T, not the overall option type), +* return an array of fields suitable for passing down to a parameter list. +* +* Calls writeToArrayBufferCallback(arrayBuffer, offset, jsValue) for non-null jsValues +* +* This array will have size/align elements for the actual T, then one element +* for the is_ok bool, and then align - 1 elements for padding if `needsPaddingFields`` is set. +* +* See wasm_abi_quirks.md's section on Unions for understanding this ABI. +*/ +export function optionToArgsForCalling(jsValue, size, align, needsPaddingFields, writeToArrayBufferCallback) { + let args; + // perform a nullish check, not a null check, + // we want identical behavior for undefined + if (jsValue != null) { + let buffer; + // We need our originator array to be properly aligned + if (align == 8) { + buffer = new BigUint64Array(size / align); + } else if (align == 4) { + buffer = new Uint32Array(size / align); + } else if (align == 2) { + buffer = new Uint16Array(size / align); + } else { + buffer = new Uint8Array(size / align); + } + + + writeToArrayBufferCallback(buffer.buffer, 0, jsValue); + args = Array.from(buffer); + args.push(1); + } else { + args = Array(size / align).fill(0); + args.push(0); + } + + args = args.concat(maybePaddingFields(needsPaddingFields, size / align)); + return args; +} + + +/** +* Given `ptr` in Wasm memory, treat it as an Option with size for type T, +* and return the converted T (converted using `readCallback(wasm, ptr)`) if the Option is Some +* else None. +*/ +export function readOption(wasm, ptr, size, readCallback) { + // Don't need the alignment: diplomat types don't have overridden alignment, + // so the flag will immediately be after the inner struct. + let flag = resultFlag(wasm, ptr, size); + if (flag) { + return readCallback(wasm, ptr); + } else { + return null; + } +} + /** * A wrapper around a slice of WASM memory that can be freed manually or * automatically by the garbage collector. @@ -170,12 +266,20 @@ export class DiplomatBuf { this.size = size; this.free = free; this.leak = () => { }; - this.garbageCollect = () => DiplomatBufferFinalizer.register(this, this.free); + this.releaseToGarbageCollector = () => DiplomatBufferFinalizer.register(this, this.free); } splat() { return [this.ptr, this.size]; } + + /** + * Write the (ptr, len) pair to an array buffer at byte offset `offset` + */ + writePtrLenToArrayBuffer(arrayBuffer, offset) { + writeToArrayBuffer(arrayBuffer, offset, this.ptr, Uint32Array); + writeToArrayBuffer(arrayBuffer, offset + 4, this.size, Uint32Array); + } } /** @@ -199,7 +303,7 @@ export class DiplomatWriteBuf { this.#wasm.diplomat_buffer_write_destroy(this.#buffer); } - garbageCollect() { + releaseToGarbageCollector() { DiplomatBufferFinalizer.register(this, this.free); } @@ -422,8 +526,6 @@ export class DiplomatReceiveBuf { */ export class CleanupArena { #items = []; - - #edgeArray = []; constructor() { } @@ -437,10 +539,35 @@ export class CleanupArena { this.#items.push(item); return item; } + /** + * Create a new CleanupArena, append it to any edge arrays passed down, and return it. + * @param {Array} edgeArrays + * @returns {CleanupArena} + */ + createWith(...edgeArrays) { + let self = new CleanupArena(); + for (edgeArray of edgeArrays) { + if (edgeArray != null) { + edgeArray.push(self); + } + } + DiplomatBufferFinalizer.register(self, self.free); + return self; + } - createWith(edgeArray) { - this.#edgeArray = edgeArray; - DiplomatBufferFinalizer.register(this, this.free); + /** + * If given edge arrays, create a new CleanupArena, append it to any edge arrays passed down, and return it. + * Else return the function-local cleanup arena + * @param {CleanupArena} functionCleanupArena + * @param {Array} edgeArrays + * @returns {DiplomatBuf} + */ + maybeCreateWith(functionCleanupArena, ...edgeArrays) { + if (edgeArrays.length > 0) { + return CleanupArena.createWith(...edgeArrays); + } else { + return functionCleanupArena + } } free() { @@ -453,11 +580,16 @@ export class CleanupArena { } /** - * Same as {@link CleanupArena}, but for calling `garbageCollect` on {@link DiplomatBuf}s. - * + * Similar to {@link CleanupArena}, but for holding on to slices until a method is called, + * after which we rely on the GC to free them. + * * This is when you may want to use a slice longer than the body of the method. + * + * At first glance this seems unnecessary, since we will be holding these slices in edge arrays anyway, + * however, if an edge array ends up unused, then we do actually need something to hold it for the duration + * of the method call. */ -export class GarbageCollector { +export class GarbageCollectorGrip { #items = []; alloc(item) { @@ -465,9 +597,9 @@ export class GarbageCollector { return item; } - garbageCollect() { + releaseToGarbageCollector() { this.#items.forEach((i) => { - i.garbageCollect(); + i.releaseToGarbageCollector(); }); this.#items.length = 0; diff --git a/tutorials/cpp/Cargo.lock b/tutorials/cpp/Cargo.lock index a6b06a62c91..78a665085c7 100644 --- a/tutorials/cpp/Cargo.lock +++ b/tutorials/cpp/Cargo.lock @@ -41,13 +41,6 @@ dependencies = [ "libm", ] -[[package]] -name = "deduplicating_array" -version = "0.1.6" -dependencies = [ - "serde", -] - [[package]] name = "deranged" version = "0.3.11" @@ -60,7 +53,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=8744ac97162341f347b63131969ad736e1047f6d#8744ac97162341f347b63131969ad736e1047f6d" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "diplomat_core", "proc-macro2", @@ -71,7 +64,7 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.8.1" -source = "git+https://github.com/rust-diplomat/diplomat?rev=8744ac97162341f347b63131969ad736e1047f6d#8744ac97162341f347b63131969ad736e1047f6d" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "log", ] @@ -79,7 +72,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.8.0" -source = "git+https://github.com/rust-diplomat/diplomat?rev=8744ac97162341f347b63131969ad736e1047f6d#8744ac97162341f347b63131969ad736e1047f6d" +source = "git+https://github.com/rust-diplomat/diplomat?rev=9e91151698bc5df511c42d95f57ea8133478b24e#9e91151698bc5df511c42d95f57ea8133478b24e" dependencies = [ "proc-macro2", "quote", @@ -296,6 +289,7 @@ name = "icu_experimental" version = "0.1.0" dependencies = [ "displaydoc", + "either", "fixed_decimal", "icu_collections", "icu_decimal", @@ -334,7 +328,6 @@ dependencies = [ name = "icu_list" version = "1.5.0" dependencies = [ - "deduplicating_array", "displaydoc", "icu_list_data", "icu_provider", @@ -446,11 +439,11 @@ version = "1.5.0" dependencies = [ "displaydoc", "icu_collections", + "icu_locale_core", "icu_properties_data", "icu_provider", "potential_utf", "serde", - "tinystr", "unicode-bidi", "zerovec", ] @@ -1076,6 +1069,10 @@ version = "0.1.8" name = "databake-derive" version = "0.1.8" +[[patch.unused]] +name = "deduplicating_array" +version = "0.1.6" + [[patch.unused]] name = "icu" version = "1.5.0"