1// generated by diplomat-tool 2import wasm from "./diplomat-wasm.mjs"; 3import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6/** The outcome of non-recursive canonical decomposition of a character. 7*`second` will be NUL when the decomposition expands to a single character 8*(which may or may not be the original one) 9* 10*See the [Rust documentation for `Decomposed`](https://docs.rs/icu/latest/icu/normalizer/properties/enum.Decomposed.html) for more information. 11*/ 12 13 14export class Decomposed { 15 16 #first; 17 18 get first() { 19 return this.#first; 20 } 21 22 #second; 23 24 get second() { 25 return this.#second; 26 } 27 28 #internalConstructor(structObj, internalConstructor) { 29 if (typeof structObj !== "object") { 30 throw new Error("Decomposed's constructor takes an object of Decomposed's fields."); 31 } 32 33 if (internalConstructor !== diplomatRuntime.internalConstructor) { 34 throw new Error("Decomposed is an out struct and can only be created internally."); 35 } 36 if ("first" in structObj) { 37 this.#first = structObj.first; 38 } else { 39 throw new Error("Missing required field first."); 40 } 41 42 if ("second" in structObj) { 43 this.#second = structObj.second; 44 } else { 45 throw new Error("Missing required field second."); 46 } 47 48 return this; 49 } 50 51 // Return this struct in FFI function friendly format. 52 // Returns an array that can be expanded with spread syntax (...) 53 54 _intoFFI( 55 functionCleanupArena, 56 appendArrayMap 57 ) { 58 return [this.#first, this.#second] 59 } 60 61 static _fromSuppliedValue(internalConstructor, obj) { 62 if (internalConstructor !== diplomatRuntime.internalConstructor) { 63 throw new Error("_fromSuppliedValue cannot be called externally."); 64 } 65 66 if (obj instanceof Decomposed) { 67 return obj; 68 } 69 70 return Decomposed.fromFields(obj); 71 } 72 73 _writeToArrayBuffer( 74 arrayBuffer, 75 offset, 76 functionCleanupArena, 77 appendArrayMap 78 ) { 79 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#first, Uint32Array); 80 diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#second, Uint32Array); 81 } 82 83 // This struct contains borrowed fields, so this takes in a list of 84 // "edges" corresponding to where each lifetime's data may have been borrowed from 85 // and passes it down to individual fields containing the borrow. 86 // This method does not attempt to handle any dependencies between lifetimes, the caller 87 // should handle this when constructing edge arrays. 88 static _fromFFI(internalConstructor, ptr) { 89 if (internalConstructor !== diplomatRuntime.internalConstructor) { 90 throw new Error("Decomposed._fromFFI is not meant to be called externally. Please use the default constructor."); 91 } 92 let structObj = {}; 93 const firstDeref = (new Uint32Array(wasm.memory.buffer, ptr, 1))[0]; 94 structObj.first = firstDeref; 95 const secondDeref = (new Uint32Array(wasm.memory.buffer, ptr + 4, 1))[0]; 96 structObj.second = secondDeref; 97 98 return new Decomposed(structObj, internalConstructor); 99 } 100 101 constructor(structObj, internalConstructor) { 102 return this.#internalConstructor(...arguments) 103 } 104}