diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /toolkit/components/uniffi-bindgen-gecko-js | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-bindgen-gecko-js')
33 files changed, 2207 insertions, 309 deletions
diff --git a/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml b/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml index 32232c64b9..5ef165dc73 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml +++ b/toolkit/components/uniffi-bindgen-gecko-js/Cargo.toml @@ -15,7 +15,7 @@ clap = { version = "4", default-features = false, features = ["std", "derive", " extend = "1.1" heck = "0.4" uniffi = { workspace = true } -uniffi_bindgen = "0.25" +uniffi_bindgen = { workspace = true } serde = "1" toml = "0.5" camino = "1.0.8" diff --git a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRelevancy.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRelevancy.sys.mjs new file mode 100644 index 0000000000..2a4663e1cb --- /dev/null +++ b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRelevancy.sys.mjs @@ -0,0 +1,1249 @@ +// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate. +// Trust me, you don't want to mess with it! + +import { UniFFITypeError } from "resource://gre/modules/UniFFI.sys.mjs"; + + + +// Objects intended to be used in the unit tests +export var UnitTestObjs = {}; + +// Write/Read data to/from an ArrayBuffer +class ArrayBufferDataStream { + constructor(arrayBuffer) { + this.dataView = new DataView(arrayBuffer); + this.pos = 0; + } + + readUint8() { + let rv = this.dataView.getUint8(this.pos); + this.pos += 1; + return rv; + } + + writeUint8(value) { + this.dataView.setUint8(this.pos, value); + this.pos += 1; + } + + readUint16() { + let rv = this.dataView.getUint16(this.pos); + this.pos += 2; + return rv; + } + + writeUint16(value) { + this.dataView.setUint16(this.pos, value); + this.pos += 2; + } + + readUint32() { + let rv = this.dataView.getUint32(this.pos); + this.pos += 4; + return rv; + } + + writeUint32(value) { + this.dataView.setUint32(this.pos, value); + this.pos += 4; + } + + readUint64() { + let rv = this.dataView.getBigUint64(this.pos); + this.pos += 8; + return Number(rv); + } + + writeUint64(value) { + this.dataView.setBigUint64(this.pos, BigInt(value)); + this.pos += 8; + } + + + readInt8() { + let rv = this.dataView.getInt8(this.pos); + this.pos += 1; + return rv; + } + + writeInt8(value) { + this.dataView.setInt8(this.pos, value); + this.pos += 1; + } + + readInt16() { + let rv = this.dataView.getInt16(this.pos); + this.pos += 2; + return rv; + } + + writeInt16(value) { + this.dataView.setInt16(this.pos, value); + this.pos += 2; + } + + readInt32() { + let rv = this.dataView.getInt32(this.pos); + this.pos += 4; + return rv; + } + + writeInt32(value) { + this.dataView.setInt32(this.pos, value); + this.pos += 4; + } + + readInt64() { + let rv = this.dataView.getBigInt64(this.pos); + this.pos += 8; + return Number(rv); + } + + writeInt64(value) { + this.dataView.setBigInt64(this.pos, BigInt(value)); + this.pos += 8; + } + + readFloat32() { + let rv = this.dataView.getFloat32(this.pos); + this.pos += 4; + return rv; + } + + writeFloat32(value) { + this.dataView.setFloat32(this.pos, value); + this.pos += 4; + } + + readFloat64() { + let rv = this.dataView.getFloat64(this.pos); + this.pos += 8; + return rv; + } + + writeFloat64(value) { + this.dataView.setFloat64(this.pos, value); + this.pos += 8; + } + + + writeString(value) { + const encoder = new TextEncoder(); + // Note: in order to efficiently write this data, we first write the + // string data, reserving 4 bytes for the size. + const dest = new Uint8Array(this.dataView.buffer, this.pos + 4); + const encodeResult = encoder.encodeInto(value, dest); + if (encodeResult.read != value.length) { + throw new UniFFIError( + "writeString: out of space when writing to ArrayBuffer. Did the computeSize() method returned the wrong result?" + ); + } + const size = encodeResult.written; + // Next, go back and write the size before the string data + this.dataView.setUint32(this.pos, size); + // Finally, advance our position past both the size and string data + this.pos += size + 4; + } + + readString() { + const decoder = new TextDecoder(); + const size = this.readUint32(); + const source = new Uint8Array(this.dataView.buffer, this.pos, size) + const value = decoder.decode(source); + this.pos += size; + return value; + } + + // Reads a RelevancyStore pointer from the data stream + // UniFFI Pointers are **always** 8 bytes long. That is enforced + // by the C++ and Rust Scaffolding code. + readPointerRelevancyStore() { + const pointerId = 0; // relevancy:RelevancyStore + const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); + this.pos += 8; + return res; + } + + // Writes a RelevancyStore pointer into the data stream + // UniFFI Pointers are **always** 8 bytes long. That is enforced + // by the C++ and Rust Scaffolding code. + writePointerRelevancyStore(value) { + const pointerId = 0; // relevancy:RelevancyStore + UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); + this.pos += 8; + } + +} + +function handleRustResult(result, liftCallback, liftErrCallback) { + switch (result.code) { + case "success": + return liftCallback(result.data); + + case "error": + throw liftErrCallback(result.data); + + case "internal-error": + let message = result.internalErrorMessage; + if (message) { + throw new UniFFIInternalError(message); + } else { + throw new UniFFIInternalError("Unknown error"); + } + + default: + throw new UniFFIError(`Unexpected status code: ${result.code}`); + } +} + +class UniFFIError { + constructor(message) { + this.message = message; + } + + toString() { + return `UniFFIError: ${this.message}` + } +} + +class UniFFIInternalError extends UniFFIError {} + +// Base class for FFI converters +class FfiConverter { + // throw `UniFFITypeError` if a value to be converted has an invalid type + static checkType(value) { + if (value === undefined ) { + throw new UniFFITypeError(`undefined`); + } + if (value === null ) { + throw new UniFFITypeError(`null`); + } + } +} + +// Base class for FFI converters that lift/lower by reading/writing to an ArrayBuffer +class FfiConverterArrayBuffer extends FfiConverter { + static lift(buf) { + return this.read(new ArrayBufferDataStream(buf)); + } + + static lower(value) { + const buf = new ArrayBuffer(this.computeSize(value)); + const dataStream = new ArrayBufferDataStream(buf); + this.write(dataStream, value); + return buf; + } +} + +// Symbols that are used to ensure that Object constructors +// can only be used with a proper UniFFI pointer +const uniffiObjectPtr = Symbol("uniffiObjectPtr"); +const constructUniffiObject = Symbol("constructUniffiObject"); +UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr; + +// Export the FFIConverter object to make external types work. +export class FfiConverterU32 extends FfiConverter { + static checkType(value) { + super.checkType(value); + if (!Number.isInteger(value)) { + throw new UniFFITypeError(`${value} is not an integer`); + } + if (value < 0 || value > 4294967295) { + throw new UniFFITypeError(`${value} exceeds the U32 bounds`); + } + } + static computeSize() { + return 4; + } + static lift(value) { + return value; + } + static lower(value) { + return value; + } + static write(dataStream, value) { + dataStream.writeUint32(value) + } + static read(dataStream) { + return dataStream.readUint32() + } +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterString extends FfiConverter { + static checkType(value) { + super.checkType(value); + if (typeof value !== "string") { + throw new UniFFITypeError(`${value} is not a string`); + } + } + + static lift(buf) { + const decoder = new TextDecoder(); + const utf8Arr = new Uint8Array(buf); + return decoder.decode(utf8Arr); + } + static lower(value) { + const encoder = new TextEncoder(); + return encoder.encode(value).buffer; + } + + static write(dataStream, value) { + dataStream.writeString(value); + } + + static read(dataStream) { + return dataStream.readString(); + } + + static computeSize(value) { + const encoder = new TextEncoder(); + return 4 + encoder.encode(value).length + } +} + +export class RelevancyStore { + // Use `init` to instantiate this class. + // DO NOT USE THIS CONSTRUCTOR DIRECTLY + constructor(opts) { + if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) { + throw new UniFFIError("Attempting to construct an object using the JavaScript constructor directly" + + "Please use a UDL defined constructor, or the init function for the primary constructor") + } + if (!opts[constructUniffiObject] instanceof UniFFIPointer) { + throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer") + } + this[uniffiObjectPtr] = opts[constructUniffiObject]; + } + /** + * An async constructor for RelevancyStore. + * + * @returns {Promise<RelevancyStore>}: A promise that resolves + * to a newly constructed RelevancyStore + */ + static init(dbpath) { + const liftResult = (result) => FfiConverterTypeRelevancyStore.lift(result); + const liftError = (data) => FfiConverterTypeRelevancyApiError.lift(data); + const functionCall = () => { + try { + FfiConverterString.checkType(dbpath) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("dbpath"); + } + throw e; + } + return UniFFIScaffolding.callAsync( + 1, // relevancy:uniffi_relevancy_fn_constructor_relevancystore_new + FfiConverterString.lower(dbpath), + ) + } + try { + return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); + } catch (error) { + return Promise.reject(error) + }} + + calculateMetrics() { + const liftResult = (result) => FfiConverterTypeInterestMetrics.lift(result); + const liftError = (data) => FfiConverterTypeRelevancyApiError.lift(data); + const functionCall = () => { + return UniFFIScaffolding.callAsync( + 2, // relevancy:uniffi_relevancy_fn_method_relevancystore_calculate_metrics + FfiConverterTypeRelevancyStore.lower(this), + ) + } + try { + return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); + } catch (error) { + return Promise.reject(error) + } + } + + ingest(topUrls) { + const liftResult = (result) => undefined; + const liftError = (data) => FfiConverterTypeRelevancyApiError.lift(data); + const functionCall = () => { + try { + FfiConverterSequencestring.checkType(topUrls) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("topUrls"); + } + throw e; + } + return UniFFIScaffolding.callAsync( + 3, // relevancy:uniffi_relevancy_fn_method_relevancystore_ingest + FfiConverterTypeRelevancyStore.lower(this), + FfiConverterSequencestring.lower(topUrls), + ) + } + try { + return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); + } catch (error) { + return Promise.reject(error) + } + } + + userInterestVector() { + const liftResult = (result) => FfiConverterTypeInterestVector.lift(result); + const liftError = (data) => FfiConverterTypeRelevancyApiError.lift(data); + const functionCall = () => { + return UniFFIScaffolding.callAsync( + 4, // relevancy:uniffi_relevancy_fn_method_relevancystore_user_interest_vector + FfiConverterTypeRelevancyStore.lower(this), + ) + } + try { + return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); + } catch (error) { + return Promise.reject(error) + } + } + +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterTypeRelevancyStore extends FfiConverter { + static lift(value) { + const opts = {}; + opts[constructUniffiObject] = value; + return new RelevancyStore(opts); + } + + static lower(value) { + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'RelevancyStore' instance"); + } + return ptr; + } + + static read(dataStream) { + return this.lift(dataStream.readPointerRelevancyStore()); + } + + static write(dataStream, value) { + dataStream.writePointerRelevancyStore(value[uniffiObjectPtr]); + } + + static computeSize(value) { + return 8; + } +} + +export class InterestMetrics { + constructor({ topSingleInterestSimilarity, top2interestSimilarity, top3interestSimilarity } = {}) { + try { + FfiConverterU32.checkType(topSingleInterestSimilarity) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("topSingleInterestSimilarity"); + } + throw e; + } + try { + FfiConverterU32.checkType(top2interestSimilarity) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("top2interestSimilarity"); + } + throw e; + } + try { + FfiConverterU32.checkType(top3interestSimilarity) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("top3interestSimilarity"); + } + throw e; + } + this.topSingleInterestSimilarity = topSingleInterestSimilarity; + this.top2interestSimilarity = top2interestSimilarity; + this.top3interestSimilarity = top3interestSimilarity; + } + equals(other) { + return ( + this.topSingleInterestSimilarity == other.topSingleInterestSimilarity && + this.top2interestSimilarity == other.top2interestSimilarity && + this.top3interestSimilarity == other.top3interestSimilarity + ) + } +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterTypeInterestMetrics extends FfiConverterArrayBuffer { + static read(dataStream) { + return new InterestMetrics({ + topSingleInterestSimilarity: FfiConverterU32.read(dataStream), + top2interestSimilarity: FfiConverterU32.read(dataStream), + top3interestSimilarity: FfiConverterU32.read(dataStream), + }); + } + static write(dataStream, value) { + FfiConverterU32.write(dataStream, value.topSingleInterestSimilarity); + FfiConverterU32.write(dataStream, value.top2interestSimilarity); + FfiConverterU32.write(dataStream, value.top3interestSimilarity); + } + + static computeSize(value) { + let totalSize = 0; + totalSize += FfiConverterU32.computeSize(value.topSingleInterestSimilarity); + totalSize += FfiConverterU32.computeSize(value.top2interestSimilarity); + totalSize += FfiConverterU32.computeSize(value.top3interestSimilarity); + return totalSize + } + + static checkType(value) { + super.checkType(value); + if (!(value instanceof InterestMetrics)) { + throw new UniFFITypeError(`Expected 'InterestMetrics', found '${typeof value}'`); + } + try { + FfiConverterU32.checkType(value.topSingleInterestSimilarity); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".topSingleInterestSimilarity"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.top2interestSimilarity); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".top2interestSimilarity"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.top3interestSimilarity); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".top3interestSimilarity"); + } + throw e; + } + } +} + +export class InterestVector { + constructor({ animals, arts, autos, business, career, education, fashion, finance, food, government, health, hobbies, home, news, realEstate, society, sports, tech, travel, inconclusive } = {}) { + try { + FfiConverterU32.checkType(animals) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("animals"); + } + throw e; + } + try { + FfiConverterU32.checkType(arts) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("arts"); + } + throw e; + } + try { + FfiConverterU32.checkType(autos) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("autos"); + } + throw e; + } + try { + FfiConverterU32.checkType(business) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("business"); + } + throw e; + } + try { + FfiConverterU32.checkType(career) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("career"); + } + throw e; + } + try { + FfiConverterU32.checkType(education) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("education"); + } + throw e; + } + try { + FfiConverterU32.checkType(fashion) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("fashion"); + } + throw e; + } + try { + FfiConverterU32.checkType(finance) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("finance"); + } + throw e; + } + try { + FfiConverterU32.checkType(food) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("food"); + } + throw e; + } + try { + FfiConverterU32.checkType(government) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("government"); + } + throw e; + } + try { + FfiConverterU32.checkType(health) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("health"); + } + throw e; + } + try { + FfiConverterU32.checkType(hobbies) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("hobbies"); + } + throw e; + } + try { + FfiConverterU32.checkType(home) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("home"); + } + throw e; + } + try { + FfiConverterU32.checkType(news) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("news"); + } + throw e; + } + try { + FfiConverterU32.checkType(realEstate) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("realEstate"); + } + throw e; + } + try { + FfiConverterU32.checkType(society) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("society"); + } + throw e; + } + try { + FfiConverterU32.checkType(sports) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("sports"); + } + throw e; + } + try { + FfiConverterU32.checkType(tech) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("tech"); + } + throw e; + } + try { + FfiConverterU32.checkType(travel) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("travel"); + } + throw e; + } + try { + FfiConverterU32.checkType(inconclusive) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("inconclusive"); + } + throw e; + } + this.animals = animals; + this.arts = arts; + this.autos = autos; + this.business = business; + this.career = career; + this.education = education; + this.fashion = fashion; + this.finance = finance; + this.food = food; + this.government = government; + this.health = health; + this.hobbies = hobbies; + this.home = home; + this.news = news; + this.realEstate = realEstate; + this.society = society; + this.sports = sports; + this.tech = tech; + this.travel = travel; + this.inconclusive = inconclusive; + } + equals(other) { + return ( + this.animals == other.animals && + this.arts == other.arts && + this.autos == other.autos && + this.business == other.business && + this.career == other.career && + this.education == other.education && + this.fashion == other.fashion && + this.finance == other.finance && + this.food == other.food && + this.government == other.government && + this.health == other.health && + this.hobbies == other.hobbies && + this.home == other.home && + this.news == other.news && + this.realEstate == other.realEstate && + this.society == other.society && + this.sports == other.sports && + this.tech == other.tech && + this.travel == other.travel && + this.inconclusive == other.inconclusive + ) + } +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterTypeInterestVector extends FfiConverterArrayBuffer { + static read(dataStream) { + return new InterestVector({ + animals: FfiConverterU32.read(dataStream), + arts: FfiConverterU32.read(dataStream), + autos: FfiConverterU32.read(dataStream), + business: FfiConverterU32.read(dataStream), + career: FfiConverterU32.read(dataStream), + education: FfiConverterU32.read(dataStream), + fashion: FfiConverterU32.read(dataStream), + finance: FfiConverterU32.read(dataStream), + food: FfiConverterU32.read(dataStream), + government: FfiConverterU32.read(dataStream), + health: FfiConverterU32.read(dataStream), + hobbies: FfiConverterU32.read(dataStream), + home: FfiConverterU32.read(dataStream), + news: FfiConverterU32.read(dataStream), + realEstate: FfiConverterU32.read(dataStream), + society: FfiConverterU32.read(dataStream), + sports: FfiConverterU32.read(dataStream), + tech: FfiConverterU32.read(dataStream), + travel: FfiConverterU32.read(dataStream), + inconclusive: FfiConverterU32.read(dataStream), + }); + } + static write(dataStream, value) { + FfiConverterU32.write(dataStream, value.animals); + FfiConverterU32.write(dataStream, value.arts); + FfiConverterU32.write(dataStream, value.autos); + FfiConverterU32.write(dataStream, value.business); + FfiConverterU32.write(dataStream, value.career); + FfiConverterU32.write(dataStream, value.education); + FfiConverterU32.write(dataStream, value.fashion); + FfiConverterU32.write(dataStream, value.finance); + FfiConverterU32.write(dataStream, value.food); + FfiConverterU32.write(dataStream, value.government); + FfiConverterU32.write(dataStream, value.health); + FfiConverterU32.write(dataStream, value.hobbies); + FfiConverterU32.write(dataStream, value.home); + FfiConverterU32.write(dataStream, value.news); + FfiConverterU32.write(dataStream, value.realEstate); + FfiConverterU32.write(dataStream, value.society); + FfiConverterU32.write(dataStream, value.sports); + FfiConverterU32.write(dataStream, value.tech); + FfiConverterU32.write(dataStream, value.travel); + FfiConverterU32.write(dataStream, value.inconclusive); + } + + static computeSize(value) { + let totalSize = 0; + totalSize += FfiConverterU32.computeSize(value.animals); + totalSize += FfiConverterU32.computeSize(value.arts); + totalSize += FfiConverterU32.computeSize(value.autos); + totalSize += FfiConverterU32.computeSize(value.business); + totalSize += FfiConverterU32.computeSize(value.career); + totalSize += FfiConverterU32.computeSize(value.education); + totalSize += FfiConverterU32.computeSize(value.fashion); + totalSize += FfiConverterU32.computeSize(value.finance); + totalSize += FfiConverterU32.computeSize(value.food); + totalSize += FfiConverterU32.computeSize(value.government); + totalSize += FfiConverterU32.computeSize(value.health); + totalSize += FfiConverterU32.computeSize(value.hobbies); + totalSize += FfiConverterU32.computeSize(value.home); + totalSize += FfiConverterU32.computeSize(value.news); + totalSize += FfiConverterU32.computeSize(value.realEstate); + totalSize += FfiConverterU32.computeSize(value.society); + totalSize += FfiConverterU32.computeSize(value.sports); + totalSize += FfiConverterU32.computeSize(value.tech); + totalSize += FfiConverterU32.computeSize(value.travel); + totalSize += FfiConverterU32.computeSize(value.inconclusive); + return totalSize + } + + static checkType(value) { + super.checkType(value); + if (!(value instanceof InterestVector)) { + throw new UniFFITypeError(`Expected 'InterestVector', found '${typeof value}'`); + } + try { + FfiConverterU32.checkType(value.animals); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".animals"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.arts); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".arts"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.autos); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".autos"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.business); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".business"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.career); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".career"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.education); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".education"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.fashion); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".fashion"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.finance); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".finance"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.food); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".food"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.government); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".government"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.health); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".health"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.hobbies); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".hobbies"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.home); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".home"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.news); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".news"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.realEstate); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".realEstate"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.society); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".society"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.sports); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".sports"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.tech); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".tech"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.travel); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".travel"); + } + throw e; + } + try { + FfiConverterU32.checkType(value.inconclusive); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".inconclusive"); + } + throw e; + } + } +} + + +export const Interest = { + ANIMALS: 1, + ARTS: 2, + AUTOS: 3, + BUSINESS: 4, + CAREER: 5, + EDUCATION: 6, + FASHION: 7, + FINANCE: 8, + FOOD: 9, + GOVERNMENT: 10, + HEALTH: 11, + HOBBIES: 12, + HOME: 13, + NEWS: 14, + REAL_ESTATE: 15, + SOCIETY: 16, + SPORTS: 17, + TECH: 18, + TRAVEL: 19, + INCONCLUSIVE: 20, +}; + +Object.freeze(Interest); +// Export the FFIConverter object to make external types work. +export class FfiConverterTypeInterest extends FfiConverterArrayBuffer { + static read(dataStream) { + switch (dataStream.readInt32()) { + case 1: + return Interest.ANIMALS + case 2: + return Interest.ARTS + case 3: + return Interest.AUTOS + case 4: + return Interest.BUSINESS + case 5: + return Interest.CAREER + case 6: + return Interest.EDUCATION + case 7: + return Interest.FASHION + case 8: + return Interest.FINANCE + case 9: + return Interest.FOOD + case 10: + return Interest.GOVERNMENT + case 11: + return Interest.HEALTH + case 12: + return Interest.HOBBIES + case 13: + return Interest.HOME + case 14: + return Interest.NEWS + case 15: + return Interest.REAL_ESTATE + case 16: + return Interest.SOCIETY + case 17: + return Interest.SPORTS + case 18: + return Interest.TECH + case 19: + return Interest.TRAVEL + case 20: + return Interest.INCONCLUSIVE + default: + throw new UniFFITypeError("Unknown Interest variant"); + } + } + + static write(dataStream, value) { + if (value === Interest.ANIMALS) { + dataStream.writeInt32(1); + return; + } + if (value === Interest.ARTS) { + dataStream.writeInt32(2); + return; + } + if (value === Interest.AUTOS) { + dataStream.writeInt32(3); + return; + } + if (value === Interest.BUSINESS) { + dataStream.writeInt32(4); + return; + } + if (value === Interest.CAREER) { + dataStream.writeInt32(5); + return; + } + if (value === Interest.EDUCATION) { + dataStream.writeInt32(6); + return; + } + if (value === Interest.FASHION) { + dataStream.writeInt32(7); + return; + } + if (value === Interest.FINANCE) { + dataStream.writeInt32(8); + return; + } + if (value === Interest.FOOD) { + dataStream.writeInt32(9); + return; + } + if (value === Interest.GOVERNMENT) { + dataStream.writeInt32(10); + return; + } + if (value === Interest.HEALTH) { + dataStream.writeInt32(11); + return; + } + if (value === Interest.HOBBIES) { + dataStream.writeInt32(12); + return; + } + if (value === Interest.HOME) { + dataStream.writeInt32(13); + return; + } + if (value === Interest.NEWS) { + dataStream.writeInt32(14); + return; + } + if (value === Interest.REAL_ESTATE) { + dataStream.writeInt32(15); + return; + } + if (value === Interest.SOCIETY) { + dataStream.writeInt32(16); + return; + } + if (value === Interest.SPORTS) { + dataStream.writeInt32(17); + return; + } + if (value === Interest.TECH) { + dataStream.writeInt32(18); + return; + } + if (value === Interest.TRAVEL) { + dataStream.writeInt32(19); + return; + } + if (value === Interest.INCONCLUSIVE) { + dataStream.writeInt32(20); + return; + } + throw new UniFFITypeError("Unknown Interest variant"); + } + + static computeSize(value) { + return 4; + } + + static checkType(value) { + if (!Number.isInteger(value) || value < 1 || value > 20) { + throw new UniFFITypeError(`${value} is not a valid value for Interest`); + } + } +} + + + + + +export class RelevancyApiError extends Error {} + + +export class Unexpected extends RelevancyApiError { + + constructor( + reason, + ...params + ) { + super(...params); + this.reason = reason; + } + toString() { + return `Unexpected: ${super.toString()}` + } +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterTypeRelevancyApiError extends FfiConverterArrayBuffer { + static read(dataStream) { + switch (dataStream.readInt32()) { + case 1: + return new Unexpected( + FfiConverterString.read(dataStream) + ); + default: + throw new UniFFITypeError("Unknown RelevancyApiError variant"); + } + } + static computeSize(value) { + // Size of the Int indicating the variant + let totalSize = 4; + if (value instanceof Unexpected) { + totalSize += FfiConverterString.computeSize(value.reason); + return totalSize; + } + throw new UniFFITypeError("Unknown RelevancyApiError variant"); + } + static write(dataStream, value) { + if (value instanceof Unexpected) { + dataStream.writeInt32(1); + FfiConverterString.write(dataStream, value.reason); + return; + } + throw new UniFFITypeError("Unknown RelevancyApiError variant"); + } + + static errorClass = RelevancyApiError; +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterSequencestring extends FfiConverterArrayBuffer { + static read(dataStream) { + const len = dataStream.readInt32(); + const arr = []; + for (let i = 0; i < len; i++) { + arr.push(FfiConverterString.read(dataStream)); + } + return arr; + } + + static write(dataStream, value) { + dataStream.writeInt32(value.length); + value.forEach((innerValue) => { + FfiConverterString.write(dataStream, innerValue); + }) + } + + static computeSize(value) { + // The size of the length + let size = 4; + for (const innerValue of value) { + size += FfiConverterString.computeSize(innerValue); + } + return size; + } + + static checkType(value) { + if (!Array.isArray(value)) { + throw new UniFFITypeError(`${value} is not an array`); + } + value.forEach((innerValue, idx) => { + try { + FfiConverterString.checkType(innerValue); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(`[${idx}]`); + } + throw e; + } + }) + } +} + + + + diff --git a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRemoteSettings.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRemoteSettings.sys.mjs index ab35fbb1e7..e839b6f17d 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRemoteSettings.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustRemoteSettings.sys.mjs @@ -158,7 +158,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerRemoteSettings() { - const pointerId = 0; // remote_settings:RemoteSettings + const pointerId = 1; // remote_settings:RemoteSettings const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -168,7 +168,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerRemoteSettings(value) { - const pointerId = 0; // remote_settings:RemoteSettings + const pointerId = 1; // remote_settings:RemoteSettings UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -356,7 +356,7 @@ export class RemoteSettings { throw e; } return UniFFIScaffolding.callSync( - 0, // remote_settings:uniffi_remote_settings_fn_constructor_remotesettings_new + 6, // remote_settings:uniffi_remote_settings_fn_constructor_remotesettings_new FfiConverterTypeRemoteSettingsConfig.lower(remoteSettingsConfig), ) } @@ -383,7 +383,7 @@ export class RemoteSettings { throw e; } return UniFFIScaffolding.callAsync( - 1, // remote_settings:uniffi_remote_settings_fn_method_remotesettings_download_attachment_to_path + 7, // remote_settings:uniffi_remote_settings_fn_method_remotesettings_download_attachment_to_path FfiConverterTypeRemoteSettings.lower(this), FfiConverterString.lower(attachmentId), FfiConverterString.lower(path), @@ -401,7 +401,7 @@ export class RemoteSettings { const liftError = (data) => FfiConverterTypeRemoteSettingsError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 2, // remote_settings:uniffi_remote_settings_fn_method_remotesettings_get_records + 8, // remote_settings:uniffi_remote_settings_fn_method_remotesettings_get_records FfiConverterTypeRemoteSettings.lower(this), ) } @@ -425,7 +425,7 @@ export class RemoteSettings { throw e; } return UniFFIScaffolding.callAsync( - 3, // remote_settings:uniffi_remote_settings_fn_method_remotesettings_get_records_since + 9, // remote_settings:uniffi_remote_settings_fn_method_remotesettings_get_records_since FfiConverterTypeRemoteSettings.lower(this), FfiConverterU64.lower(timestamp), ) @@ -448,7 +448,11 @@ export class FfiConverterTypeRemoteSettings extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'RemoteSettings' instance"); + } + return ptr; } static read(dataStream) { @@ -555,7 +559,7 @@ export class FfiConverterTypeAttachment extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof Attachment)) { - throw new TypeError(`Expected 'Attachment', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'Attachment', found '${typeof value}'`); } try { FfiConverterString.checkType(value.filename); @@ -665,7 +669,7 @@ export class FfiConverterTypeRemoteSettingsConfig extends FfiConverterArrayBuffe static checkType(value) { super.checkType(value); if (!(value instanceof RemoteSettingsConfig)) { - throw new TypeError(`Expected 'RemoteSettingsConfig', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'RemoteSettingsConfig', found '${typeof value}'`); } try { FfiConverterString.checkType(value.collectionName); @@ -785,7 +789,7 @@ export class FfiConverterTypeRemoteSettingsRecord extends FfiConverterArrayBuffe static checkType(value) { super.checkType(value); if (!(value instanceof RemoteSettingsRecord)) { - throw new TypeError(`Expected 'RemoteSettingsRecord', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'RemoteSettingsRecord', found '${typeof value}'`); } try { FfiConverterString.checkType(value.id); @@ -882,7 +886,7 @@ export class FfiConverterTypeRemoteSettingsResponse extends FfiConverterArrayBuf static checkType(value) { super.checkType(value); if (!(value instanceof RemoteSettingsResponse)) { - throw new TypeError(`Expected 'RemoteSettingsResponse', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'RemoteSettingsResponse', found '${typeof value}'`); } try { FfiConverterSequenceTypeRemoteSettingsRecord.checkType(value.records); @@ -1005,7 +1009,7 @@ export class FfiConverterTypeRemoteSettingsError extends FfiConverterArrayBuffer case 7: return new AttachmentsUnsupportedError(FfiConverterString.read(dataStream)); default: - throw new Error("Unknown RemoteSettingsError variant"); + throw new UniFFITypeError("Unknown RemoteSettingsError variant"); } } static computeSize(value) { @@ -1032,7 +1036,7 @@ export class FfiConverterTypeRemoteSettingsError extends FfiConverterArrayBuffer if (value instanceof AttachmentsUnsupportedError) { return totalSize; } - throw new Error("Unknown RemoteSettingsError variant"); + throw new UniFFITypeError("Unknown RemoteSettingsError variant"); } static write(dataStream, value) { if (value instanceof JsonError) { @@ -1063,7 +1067,7 @@ export class FfiConverterTypeRemoteSettingsError extends FfiConverterArrayBuffer dataStream.writeInt32(7); return; } - throw new Error("Unknown RemoteSettingsError variant"); + throw new UniFFITypeError("Unknown RemoteSettingsError variant"); } static errorClass = RemoteSettingsError; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSuggest.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSuggest.sys.mjs index ff9507c520..7ab2e2d8e2 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSuggest.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSuggest.sys.mjs @@ -158,7 +158,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerSuggestStore() { - const pointerId = 1; // suggest:SuggestStore + const pointerId = 2; // suggest:SuggestStore const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -168,7 +168,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerSuggestStore(value) { - const pointerId = 1; // suggest:SuggestStore + const pointerId = 2; // suggest:SuggestStore UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -178,7 +178,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerSuggestStoreBuilder() { - const pointerId = 2; // suggest:SuggestStoreBuilder + const pointerId = 3; // suggest:SuggestStoreBuilder const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -188,7 +188,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerSuggestStoreBuilder(value) { - const pointerId = 2; // suggest:SuggestStoreBuilder + const pointerId = 3; // suggest:SuggestStoreBuilder UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -484,7 +484,7 @@ export class SuggestStore { throw e; } return UniFFIScaffolding.callSync( - 4, // suggest:uniffi_suggest_fn_constructor_suggeststore_new + 11, // suggest:uniffi_suggest_fn_constructor_suggeststore_new FfiConverterString.lower(path), FfiConverterOptionalTypeRemoteSettingsConfig.lower(settingsConfig), ) @@ -496,7 +496,7 @@ export class SuggestStore { const liftError = (data) => FfiConverterTypeSuggestApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 5, // suggest:uniffi_suggest_fn_method_suggeststore_clear + 12, // suggest:uniffi_suggest_fn_method_suggeststore_clear FfiConverterTypeSuggestStore.lower(this), ) } @@ -507,12 +507,53 @@ export class SuggestStore { } } + clearDismissedSuggestions() { + const liftResult = (result) => undefined; + const liftError = (data) => FfiConverterTypeSuggestApiError.lift(data); + const functionCall = () => { + return UniFFIScaffolding.callAsync( + 13, // suggest:uniffi_suggest_fn_method_suggeststore_clear_dismissed_suggestions + FfiConverterTypeSuggestStore.lower(this), + ) + } + try { + return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); + } catch (error) { + return Promise.reject(error) + } + } + + dismissSuggestion(rawSuggestionUrl) { + const liftResult = (result) => undefined; + const liftError = (data) => FfiConverterTypeSuggestApiError.lift(data); + const functionCall = () => { + try { + FfiConverterString.checkType(rawSuggestionUrl) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("rawSuggestionUrl"); + } + throw e; + } + return UniFFIScaffolding.callAsync( + 14, // suggest:uniffi_suggest_fn_method_suggeststore_dismiss_suggestion + FfiConverterTypeSuggestStore.lower(this), + FfiConverterString.lower(rawSuggestionUrl), + ) + } + try { + return functionCall().then((result) => handleRustResult(result, liftResult, liftError)); + } catch (error) { + return Promise.reject(error) + } + } + fetchGlobalConfig() { const liftResult = (result) => FfiConverterTypeSuggestGlobalConfig.lift(result); const liftError = (data) => FfiConverterTypeSuggestApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 6, // suggest:uniffi_suggest_fn_method_suggeststore_fetch_global_config + 15, // suggest:uniffi_suggest_fn_method_suggeststore_fetch_global_config FfiConverterTypeSuggestStore.lower(this), ) } @@ -536,7 +577,7 @@ export class SuggestStore { throw e; } return UniFFIScaffolding.callAsync( - 7, // suggest:uniffi_suggest_fn_method_suggeststore_fetch_provider_config + 16, // suggest:uniffi_suggest_fn_method_suggeststore_fetch_provider_config FfiConverterTypeSuggestStore.lower(this), FfiConverterTypeSuggestionProvider.lower(provider), ) @@ -561,7 +602,7 @@ export class SuggestStore { throw e; } return UniFFIScaffolding.callAsync( - 8, // suggest:uniffi_suggest_fn_method_suggeststore_ingest + 17, // suggest:uniffi_suggest_fn_method_suggeststore_ingest FfiConverterTypeSuggestStore.lower(this), FfiConverterTypeSuggestIngestionConstraints.lower(constraints), ) @@ -578,7 +619,7 @@ export class SuggestStore { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callSync( - 9, // suggest:uniffi_suggest_fn_method_suggeststore_interrupt + 18, // suggest:uniffi_suggest_fn_method_suggeststore_interrupt FfiConverterTypeSuggestStore.lower(this), ) } @@ -598,7 +639,7 @@ export class SuggestStore { throw e; } return UniFFIScaffolding.callAsync( - 10, // suggest:uniffi_suggest_fn_method_suggeststore_query + 19, // suggest:uniffi_suggest_fn_method_suggeststore_query FfiConverterTypeSuggestStore.lower(this), FfiConverterTypeSuggestionQuery.lower(query), ) @@ -621,7 +662,11 @@ export class FfiConverterTypeSuggestStore extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'SuggestStore' instance"); + } + return ptr; } static read(dataStream) { @@ -661,7 +706,7 @@ export class SuggestStoreBuilder { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 11, // suggest:uniffi_suggest_fn_constructor_suggeststorebuilder_new + 21, // suggest:uniffi_suggest_fn_constructor_suggeststorebuilder_new ) } try { @@ -675,7 +720,7 @@ export class SuggestStoreBuilder { const liftError = (data) => FfiConverterTypeSuggestApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 12, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_build + 22, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_build FfiConverterTypeSuggestStoreBuilder.lower(this), ) } @@ -699,7 +744,7 @@ export class SuggestStoreBuilder { throw e; } return UniFFIScaffolding.callAsync( - 13, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_cache_path + 23, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_cache_path FfiConverterTypeSuggestStoreBuilder.lower(this), FfiConverterString.lower(path), ) @@ -724,7 +769,7 @@ export class SuggestStoreBuilder { throw e; } return UniFFIScaffolding.callAsync( - 14, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_data_path + 24, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_data_path FfiConverterTypeSuggestStoreBuilder.lower(this), FfiConverterString.lower(path), ) @@ -749,7 +794,7 @@ export class SuggestStoreBuilder { throw e; } return UniFFIScaffolding.callAsync( - 15, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_remote_settings_config + 25, // suggest:uniffi_suggest_fn_method_suggeststorebuilder_remote_settings_config FfiConverterTypeSuggestStoreBuilder.lower(this), FfiConverterTypeRemoteSettingsConfig.lower(config), ) @@ -772,7 +817,11 @@ export class FfiConverterTypeSuggestStoreBuilder extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'SuggestStoreBuilder' instance"); + } + return ptr; } static read(dataStream) { @@ -827,7 +876,7 @@ export class FfiConverterTypeSuggestGlobalConfig extends FfiConverterArrayBuffer static checkType(value) { super.checkType(value); if (!(value instanceof SuggestGlobalConfig)) { - throw new TypeError(`Expected 'SuggestGlobalConfig', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'SuggestGlobalConfig', found '${typeof value}'`); } try { FfiConverterI32.checkType(value.showLessFrequentlyCap); @@ -841,7 +890,7 @@ export class FfiConverterTypeSuggestGlobalConfig extends FfiConverterArrayBuffer } export class SuggestIngestionConstraints { - constructor({ maxSuggestions = null } = {}) { + constructor({ maxSuggestions = null, providers = null } = {}) { try { FfiConverterOptionalu64.checkType(maxSuggestions) } catch (e) { @@ -850,11 +899,21 @@ export class SuggestIngestionConstraints { } throw e; } + try { + FfiConverterOptionalSequenceTypeSuggestionProvider.checkType(providers) + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart("providers"); + } + throw e; + } this.maxSuggestions = maxSuggestions; + this.providers = providers; } equals(other) { return ( - this.maxSuggestions == other.maxSuggestions + this.maxSuggestions == other.maxSuggestions && + this.providers == other.providers ) } } @@ -864,22 +923,25 @@ export class FfiConverterTypeSuggestIngestionConstraints extends FfiConverterArr static read(dataStream) { return new SuggestIngestionConstraints({ maxSuggestions: FfiConverterOptionalu64.read(dataStream), + providers: FfiConverterOptionalSequenceTypeSuggestionProvider.read(dataStream), }); } static write(dataStream, value) { FfiConverterOptionalu64.write(dataStream, value.maxSuggestions); + FfiConverterOptionalSequenceTypeSuggestionProvider.write(dataStream, value.providers); } static computeSize(value) { let totalSize = 0; totalSize += FfiConverterOptionalu64.computeSize(value.maxSuggestions); + totalSize += FfiConverterOptionalSequenceTypeSuggestionProvider.computeSize(value.providers); return totalSize } static checkType(value) { super.checkType(value); if (!(value instanceof SuggestIngestionConstraints)) { - throw new TypeError(`Expected 'SuggestIngestionConstraints', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'SuggestIngestionConstraints', found '${typeof value}'`); } try { FfiConverterOptionalu64.checkType(value.maxSuggestions); @@ -889,6 +951,14 @@ export class FfiConverterTypeSuggestIngestionConstraints extends FfiConverterArr } throw e; } + try { + FfiConverterOptionalSequenceTypeSuggestionProvider.checkType(value.providers); + } catch (e) { + if (e instanceof UniFFITypeError) { + e.addItemDescriptionPart(".providers"); + } + throw e; + } } } @@ -957,7 +1027,7 @@ export class FfiConverterTypeSuggestionQuery extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof SuggestionQuery)) { - throw new TypeError(`Expected 'SuggestionQuery', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'SuggestionQuery', found '${typeof value}'`); } try { FfiConverterString.checkType(value.keyword); @@ -1066,7 +1136,7 @@ export class FfiConverterTypeSuggestApiError extends FfiConverterArrayBuffer { FfiConverterString.read(dataStream) ); default: - throw new Error("Unknown SuggestApiError variant"); + throw new UniFFITypeError("Unknown SuggestApiError variant"); } } static computeSize(value) { @@ -1087,7 +1157,7 @@ export class FfiConverterTypeSuggestApiError extends FfiConverterArrayBuffer { totalSize += FfiConverterString.computeSize(value.reason); return totalSize; } - throw new Error("Unknown SuggestApiError variant"); + throw new UniFFITypeError("Unknown SuggestApiError variant"); } static write(dataStream, value) { if (value instanceof Interrupted) { @@ -1109,7 +1179,7 @@ export class FfiConverterTypeSuggestApiError extends FfiConverterArrayBuffer { FfiConverterString.write(dataStream, value.reason); return; } - throw new Error("Unknown SuggestApiError variant"); + throw new UniFFITypeError("Unknown SuggestApiError variant"); } static errorClass = SuggestApiError; @@ -1135,7 +1205,7 @@ export class FfiConverterTypeSuggestProviderConfig extends FfiConverterArrayBuff FfiConverterI32.read(dataStream) ); default: - return new Error("Unknown SuggestProviderConfig variant"); + throw new UniFFITypeError("Unknown SuggestProviderConfig variant"); } } @@ -1145,7 +1215,7 @@ export class FfiConverterTypeSuggestProviderConfig extends FfiConverterArrayBuff FfiConverterI32.write(dataStream, value.minKeywordLength); return; } - return new Error("Unknown SuggestProviderConfig variant"); + throw new UniFFITypeError("Unknown SuggestProviderConfig variant"); } static computeSize(value) { @@ -1155,7 +1225,7 @@ export class FfiConverterTypeSuggestProviderConfig extends FfiConverterArrayBuff totalSize += FfiConverterI32.computeSize(value.minKeywordLength); return totalSize; } - return new Error("Unknown SuggestProviderConfig variant"); + throw new UniFFITypeError("Unknown SuggestProviderConfig variant"); } static checkType(value) { @@ -1174,6 +1244,7 @@ Suggestion.Amp = class extends Suggestion{ url, rawUrl, icon, + iconMimetype, fullKeyword, blockId, advertiser, @@ -1188,6 +1259,7 @@ Suggestion.Amp = class extends Suggestion{ this.url = url; this.rawUrl = rawUrl; this.icon = icon; + this.iconMimetype = iconMimetype; this.fullKeyword = fullKeyword; this.blockId = blockId; this.advertiser = advertiser; @@ -1217,12 +1289,14 @@ Suggestion.Wikipedia = class extends Suggestion{ title, url, icon, + iconMimetype, fullKeyword ) { super(); this.title = title; this.url = url; this.icon = icon; + this.iconMimetype = iconMimetype; this.fullKeyword = fullKeyword; } } @@ -1253,6 +1327,7 @@ Suggestion.Yelp = class extends Suggestion{ url, title, icon, + iconMimetype, score, hasLocationSign, subjectExactMatch, @@ -1262,6 +1337,7 @@ Suggestion.Yelp = class extends Suggestion{ this.url = url; this.title = title; this.icon = icon; + this.iconMimetype = iconMimetype; this.score = score; this.hasLocationSign = hasLocationSign; this.subjectExactMatch = subjectExactMatch; @@ -1301,6 +1377,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterString.read(dataStream), FfiConverterString.read(dataStream), FfiConverterOptionalSequenceu8.read(dataStream), + FfiConverterOptionalstring.read(dataStream), FfiConverterString.read(dataStream), FfiConverterI64.read(dataStream), FfiConverterString.read(dataStream), @@ -1322,6 +1399,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterString.read(dataStream), FfiConverterString.read(dataStream), FfiConverterOptionalSequenceu8.read(dataStream), + FfiConverterOptionalstring.read(dataStream), FfiConverterString.read(dataStream) ); case 4: @@ -1340,6 +1418,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterString.read(dataStream), FfiConverterString.read(dataStream), FfiConverterOptionalSequenceu8.read(dataStream), + FfiConverterOptionalstring.read(dataStream), FfiConverterF64.read(dataStream), FfiConverterBool.read(dataStream), FfiConverterBool.read(dataStream), @@ -1357,7 +1436,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterF64.read(dataStream) ); default: - return new Error("Unknown Suggestion variant"); + throw new UniFFITypeError("Unknown Suggestion variant"); } } @@ -1368,6 +1447,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterString.write(dataStream, value.url); FfiConverterString.write(dataStream, value.rawUrl); FfiConverterOptionalSequenceu8.write(dataStream, value.icon); + FfiConverterOptionalstring.write(dataStream, value.iconMimetype); FfiConverterString.write(dataStream, value.fullKeyword); FfiConverterI64.write(dataStream, value.blockId); FfiConverterString.write(dataStream, value.advertiser); @@ -1391,6 +1471,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterString.write(dataStream, value.title); FfiConverterString.write(dataStream, value.url); FfiConverterOptionalSequenceu8.write(dataStream, value.icon); + FfiConverterOptionalstring.write(dataStream, value.iconMimetype); FfiConverterString.write(dataStream, value.fullKeyword); return; } @@ -1411,6 +1492,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterString.write(dataStream, value.url); FfiConverterString.write(dataStream, value.title); FfiConverterOptionalSequenceu8.write(dataStream, value.icon); + FfiConverterOptionalstring.write(dataStream, value.iconMimetype); FfiConverterF64.write(dataStream, value.score); FfiConverterBool.write(dataStream, value.hasLocationSign); FfiConverterBool.write(dataStream, value.subjectExactMatch); @@ -1430,7 +1512,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { FfiConverterF64.write(dataStream, value.score); return; } - return new Error("Unknown Suggestion variant"); + throw new UniFFITypeError("Unknown Suggestion variant"); } static computeSize(value) { @@ -1441,6 +1523,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { totalSize += FfiConverterString.computeSize(value.url); totalSize += FfiConverterString.computeSize(value.rawUrl); totalSize += FfiConverterOptionalSequenceu8.computeSize(value.icon); + totalSize += FfiConverterOptionalstring.computeSize(value.iconMimetype); totalSize += FfiConverterString.computeSize(value.fullKeyword); totalSize += FfiConverterI64.computeSize(value.blockId); totalSize += FfiConverterString.computeSize(value.advertiser); @@ -1462,6 +1545,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { totalSize += FfiConverterString.computeSize(value.title); totalSize += FfiConverterString.computeSize(value.url); totalSize += FfiConverterOptionalSequenceu8.computeSize(value.icon); + totalSize += FfiConverterOptionalstring.computeSize(value.iconMimetype); totalSize += FfiConverterString.computeSize(value.fullKeyword); return totalSize; } @@ -1480,6 +1564,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { totalSize += FfiConverterString.computeSize(value.url); totalSize += FfiConverterString.computeSize(value.title); totalSize += FfiConverterOptionalSequenceu8.computeSize(value.icon); + totalSize += FfiConverterOptionalstring.computeSize(value.iconMimetype); totalSize += FfiConverterF64.computeSize(value.score); totalSize += FfiConverterBool.computeSize(value.hasLocationSign); totalSize += FfiConverterBool.computeSize(value.subjectExactMatch); @@ -1497,7 +1582,7 @@ export class FfiConverterTypeSuggestion extends FfiConverterArrayBuffer { totalSize += FfiConverterF64.computeSize(value.score); return totalSize; } - return new Error("Unknown Suggestion variant"); + throw new UniFFITypeError("Unknown Suggestion variant"); } static checkType(value) { @@ -1542,7 +1627,7 @@ export class FfiConverterTypeSuggestionProvider extends FfiConverterArrayBuffer case 8: return SuggestionProvider.AMP_MOBILE default: - return new Error("Unknown SuggestionProvider variant"); + throw new UniFFITypeError("Unknown SuggestionProvider variant"); } } @@ -1579,7 +1664,7 @@ export class FfiConverterTypeSuggestionProvider extends FfiConverterArrayBuffer dataStream.writeInt32(8); return; } - return new Error("Unknown SuggestionProvider variant"); + throw new UniFFITypeError("Unknown SuggestionProvider variant"); } static computeSize(value) { @@ -1780,6 +1865,43 @@ export class FfiConverterOptionalSequenceu8 extends FfiConverterArrayBuffer { } // Export the FFIConverter object to make external types work. +export class FfiConverterOptionalSequenceTypeSuggestionProvider extends FfiConverterArrayBuffer { + static checkType(value) { + if (value !== undefined && value !== null) { + FfiConverterSequenceTypeSuggestionProvider.checkType(value) + } + } + + static read(dataStream) { + const code = dataStream.readUint8(0); + switch (code) { + case 0: + return null + case 1: + return FfiConverterSequenceTypeSuggestionProvider.read(dataStream) + default: + throw UniFFIError(`Unexpected code: ${code}`); + } + } + + static write(dataStream, value) { + if (value === null || value === undefined) { + dataStream.writeUint8(0); + return; + } + dataStream.writeUint8(1); + FfiConverterSequenceTypeSuggestionProvider.write(dataStream, value) + } + + static computeSize(value) { + if (value === null || value === undefined) { + return 1; + } + return 1 + FfiConverterSequenceTypeSuggestionProvider.computeSize(value) + } +} + +// Export the FFIConverter object to make external types work. export class FfiConverterOptionalTypeRemoteSettingsConfig extends FfiConverterArrayBuffer { static checkType(value) { if (value !== undefined && value !== null) { @@ -1982,7 +2104,7 @@ export function rawSuggestionUrlMatches(rawUrl,url) { throw e; } return UniFFIScaffolding.callSync( - 16, // suggest:uniffi_suggest_fn_func_raw_suggestion_url_matches + 26, // suggest:uniffi_suggest_fn_func_raw_suggestion_url_matches FfiConverterString.lower(rawUrl), FfiConverterString.lower(url), ) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSync15.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSync15.sys.mjs index fb9b06bfa7..c02bf51235 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSync15.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustSync15.sys.mjs @@ -282,7 +282,7 @@ export class FfiConverterTypeDeviceType extends FfiConverterArrayBuffer { case 6: return DeviceType.UNKNOWN default: - return new Error("Unknown DeviceType variant"); + throw new UniFFITypeError("Unknown DeviceType variant"); } } @@ -311,7 +311,7 @@ export class FfiConverterTypeDeviceType extends FfiConverterArrayBuffer { dataStream.writeInt32(6); return; } - return new Error("Unknown DeviceType variant"); + throw new UniFFITypeError("Unknown DeviceType variant"); } static computeSize(value) { diff --git a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustTabs.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustTabs.sys.mjs index 614d7fb95b..4d34a46d9e 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustTabs.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/components/generated/RustTabs.sys.mjs @@ -158,7 +158,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerTabsBridgedEngine() { - const pointerId = 3; // tabs:TabsBridgedEngine + const pointerId = 4; // tabs:TabsBridgedEngine const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -168,7 +168,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerTabsBridgedEngine(value) { - const pointerId = 3; // tabs:TabsBridgedEngine + const pointerId = 4; // tabs:TabsBridgedEngine UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -178,7 +178,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerTabsStore() { - const pointerId = 4; // tabs:TabsStore + const pointerId = 5; // tabs:TabsStore const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -188,7 +188,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerTabsStore(value) { - const pointerId = 4; // tabs:TabsStore + const pointerId = 5; // tabs:TabsStore UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -361,7 +361,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 17, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_apply + 28, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_apply FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -385,7 +385,7 @@ export class TabsBridgedEngine { throw e; } return UniFFIScaffolding.callAsync( - 18, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_ensure_current_sync_id + 29, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_ensure_current_sync_id FfiConverterTypeTabsBridgedEngine.lower(this), FfiConverterString.lower(newSyncId), ) @@ -402,7 +402,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 19, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_last_sync + 30, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_last_sync FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -426,7 +426,7 @@ export class TabsBridgedEngine { throw e; } return UniFFIScaffolding.callAsync( - 20, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_prepare_for_sync + 31, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_prepare_for_sync FfiConverterTypeTabsBridgedEngine.lower(this), FfiConverterString.lower(clientData), ) @@ -443,7 +443,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 21, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_reset + 32, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_reset FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -459,7 +459,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 22, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_reset_sync_id + 33, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_reset_sync_id FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -483,7 +483,7 @@ export class TabsBridgedEngine { throw e; } return UniFFIScaffolding.callAsync( - 23, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_set_last_sync + 34, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_set_last_sync FfiConverterTypeTabsBridgedEngine.lower(this), FfiConverterI64.lower(lastSync), ) @@ -516,7 +516,7 @@ export class TabsBridgedEngine { throw e; } return UniFFIScaffolding.callAsync( - 24, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_set_uploaded + 35, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_set_uploaded FfiConverterTypeTabsBridgedEngine.lower(this), FfiConverterI64.lower(newTimestamp), FfiConverterSequenceTypeTabsGuid.lower(uploadedIds), @@ -542,7 +542,7 @@ export class TabsBridgedEngine { throw e; } return UniFFIScaffolding.callAsync( - 25, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_store_incoming + 36, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_store_incoming FfiConverterTypeTabsBridgedEngine.lower(this), FfiConverterSequencestring.lower(incomingEnvelopesAsJson), ) @@ -559,7 +559,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 26, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_sync_finished + 37, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_sync_finished FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -575,7 +575,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 27, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_sync_id + 38, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_sync_id FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -591,7 +591,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 28, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_sync_started + 39, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_sync_started FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -607,7 +607,7 @@ export class TabsBridgedEngine { const liftError = (data) => FfiConverterTypeTabsApiError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 29, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_wipe + 40, // tabs:uniffi_tabs_fn_method_tabsbridgedengine_wipe FfiConverterTypeTabsBridgedEngine.lower(this), ) } @@ -629,7 +629,11 @@ export class FfiConverterTypeTabsBridgedEngine extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'TabsBridgedEngine' instance"); + } + return ptr; } static read(dataStream) { @@ -677,7 +681,7 @@ export class TabsStore { throw e; } return UniFFIScaffolding.callAsync( - 30, // tabs:uniffi_tabs_fn_constructor_tabsstore_new + 42, // tabs:uniffi_tabs_fn_constructor_tabsstore_new FfiConverterString.lower(path), ) } @@ -692,7 +696,7 @@ export class TabsStore { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 31, // tabs:uniffi_tabs_fn_method_tabsstore_bridged_engine + 43, // tabs:uniffi_tabs_fn_method_tabsstore_bridged_engine FfiConverterTypeTabsStore.lower(this), ) } @@ -708,7 +712,7 @@ export class TabsStore { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 32, // tabs:uniffi_tabs_fn_method_tabsstore_get_all + 44, // tabs:uniffi_tabs_fn_method_tabsstore_get_all FfiConverterTypeTabsStore.lower(this), ) } @@ -724,7 +728,7 @@ export class TabsStore { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 33, // tabs:uniffi_tabs_fn_method_tabsstore_register_with_sync_manager + 45, // tabs:uniffi_tabs_fn_method_tabsstore_register_with_sync_manager FfiConverterTypeTabsStore.lower(this), ) } @@ -748,7 +752,7 @@ export class TabsStore { throw e; } return UniFFIScaffolding.callAsync( - 34, // tabs:uniffi_tabs_fn_method_tabsstore_set_local_tabs + 46, // tabs:uniffi_tabs_fn_method_tabsstore_set_local_tabs FfiConverterTypeTabsStore.lower(this), FfiConverterSequenceTypeRemoteTabRecord.lower(remoteTabs), ) @@ -771,7 +775,11 @@ export class FfiConverterTypeTabsStore extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'TabsStore' instance"); + } + return ptr; } static read(dataStream) { @@ -878,7 +886,7 @@ export class FfiConverterTypeClientRemoteTabs extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof ClientRemoteTabs)) { - throw new TypeError(`Expected 'ClientRemoteTabs', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'ClientRemoteTabs', found '${typeof value}'`); } try { FfiConverterString.checkType(value.clientId); @@ -1014,7 +1022,7 @@ export class FfiConverterTypeRemoteTabRecord extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof RemoteTabRecord)) { - throw new TypeError(`Expected 'RemoteTabRecord', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'RemoteTabRecord', found '${typeof value}'`); } try { FfiConverterString.checkType(value.title); @@ -1124,7 +1132,7 @@ export class FfiConverterTypeTabsApiError extends FfiConverterArrayBuffer { FfiConverterString.read(dataStream) ); default: - throw new Error("Unknown TabsApiError variant"); + throw new UniFFITypeError("Unknown TabsApiError variant"); } } static computeSize(value) { @@ -1142,7 +1150,7 @@ export class FfiConverterTypeTabsApiError extends FfiConverterArrayBuffer { totalSize += FfiConverterString.computeSize(value.reason); return totalSize; } - throw new Error("Unknown TabsApiError variant"); + throw new UniFFITypeError("Unknown TabsApiError variant"); } static write(dataStream, value) { if (value instanceof SyncError) { @@ -1160,7 +1168,7 @@ export class FfiConverterTypeTabsApiError extends FfiConverterArrayBuffer { FfiConverterString.write(dataStream, value.reason); return; } - throw new Error("Unknown TabsApiError variant"); + throw new UniFFITypeError("Unknown TabsApiError variant"); } static errorClass = TabsApiError; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/components/moz.build b/toolkit/components/uniffi-bindgen-gecko-js/components/moz.build index 107745a4b8..405711db98 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/components/moz.build +++ b/toolkit/components/uniffi-bindgen-gecko-js/components/moz.build @@ -5,6 +5,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXTRA_JS_MODULES += [ + "generated/RustRelevancy.sys.mjs", "generated/RustRemoteSettings.sys.mjs", "generated/RustSuggest.sys.mjs", "generated/RustSync15.sys.mjs", diff --git a/toolkit/components/uniffi-bindgen-gecko-js/config.toml b/toolkit/components/uniffi-bindgen-gecko-js/config.toml index d59b2a69e1..d8404f5142 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/config.toml +++ b/toolkit/components/uniffi-bindgen-gecko-js/config.toml @@ -29,6 +29,14 @@ main = [ "SuggestStore.interrupt", ] +[relevancy] +crate_name = "relevancy" +udl_file = "third_party/rust/relevancy/src/relevancy.udl" + +[relevancy.receiver_thread] +default = "worker" +main = [] + [remote_settings] crate_name = "remote_settings" udl_file = "third_party/rust/remote_settings/src/remote_settings.udl" @@ -64,16 +72,27 @@ crate_name = "uniffi_todolist" udl_file = "third_party/rust/uniffi-example-todolist/src/todolist.udl" fixture = true -[fixture_callbacks] -crate_name = "uniffi_fixture_callbacks" -udl_file = "toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl" +[fixture_refcounts] +crate_name = "uniffi_fixture_refcounts" +udl_file = "toolkit/components/uniffi-fixture-refcounts/src/refcounts.udl" fixture = true -[fixture_callbacks.receiver_thread] -default = "worker" -main = [ - "log_even_numbers_main_thread", -] +[fixture_refcounts.receiver_thread] +default = "main" + +# Temporarily disabled until we can re-enable callback support +# +# I think this can be done when we implement https://bugzilla.mozilla.org/show_bug.cgi?id=1888668 +# [fixture_callbacks] +# crate_name = "uniffi_fixture_callbacks" +# udl_file = "toolkit/components/uniffi-fixture-callbacks/src/callbacks.udl" +# fixture = true +# +# [fixture_callbacks.receiver_thread] +# default = "worker" +# main = [ +# "log_even_numbers_main_thread", +# ] [custom_types] crate_name = "uniffi_custom_types" diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustArithmetic.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustArithmetic.sys.mjs index 1790f0effa..62766a45a4 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustArithmetic.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustArithmetic.sys.mjs @@ -329,7 +329,7 @@ export class FfiConverterTypeArithmeticError extends FfiConverterArrayBuffer { case 1: return new IntegerOverflow(FfiConverterString.read(dataStream)); default: - throw new Error("Unknown ArithmeticError variant"); + throw new UniFFITypeError("Unknown ArithmeticError variant"); } } static computeSize(value) { @@ -338,14 +338,14 @@ export class FfiConverterTypeArithmeticError extends FfiConverterArrayBuffer { if (value instanceof IntegerOverflow) { return totalSize; } - throw new Error("Unknown ArithmeticError variant"); + throw new UniFFITypeError("Unknown ArithmeticError variant"); } static write(dataStream, value) { if (value instanceof IntegerOverflow) { dataStream.writeInt32(1); return; } - throw new Error("Unknown ArithmeticError variant"); + throw new UniFFITypeError("Unknown ArithmeticError variant"); } static errorClass = ArithmeticError; @@ -377,7 +377,7 @@ export function add(a,b) { throw e; } return UniFFIScaffolding.callAsync( - 35, // arithmetic:uniffi_arithmetical_fn_func_add + 47, // arithmetic:uniffi_arithmetical_fn_func_add FfiConverterU64.lower(a), FfiConverterU64.lower(b), ) @@ -411,7 +411,7 @@ export function div(dividend,divisor) { throw e; } return UniFFIScaffolding.callAsync( - 36, // arithmetic:uniffi_arithmetical_fn_func_div + 48, // arithmetic:uniffi_arithmetical_fn_func_div FfiConverterU64.lower(dividend), FfiConverterU64.lower(divisor), ) @@ -445,7 +445,7 @@ export function equal(a,b) { throw e; } return UniFFIScaffolding.callAsync( - 37, // arithmetic:uniffi_arithmetical_fn_func_equal + 49, // arithmetic:uniffi_arithmetical_fn_func_equal FfiConverterU64.lower(a), FfiConverterU64.lower(b), ) @@ -479,7 +479,7 @@ export function sub(a,b) { throw e; } return UniFFIScaffolding.callAsync( - 38, // arithmetic:uniffi_arithmetical_fn_func_sub + 50, // arithmetic:uniffi_arithmetical_fn_func_sub FfiConverterU64.lower(a), FfiConverterU64.lower(b), ) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustCustomTypes.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustCustomTypes.sys.mjs index 286c046fa6..581478cc8a 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustCustomTypes.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustCustomTypes.sys.mjs @@ -331,7 +331,7 @@ export class FfiConverterTypeCustomTypesDemo extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof CustomTypesDemo)) { - throw new TypeError(`Expected 'CustomTypesDemo', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'CustomTypesDemo', found '${typeof value}'`); } try { FfiConverterTypeUrl.checkType(value.url); @@ -455,7 +455,7 @@ export function getCustomTypesDemo(demo) { throw e; } return UniFFIScaffolding.callAsync( - 39, // custom_types:uniffi_uniffi_custom_types_fn_func_get_custom_types_demo + 51, // custom_types:uniffi_uniffi_custom_types_fn_func_get_custom_types_demo FfiConverterOptionalTypeCustomTypesDemo.lower(demo), ) } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustExternalTypes.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustExternalTypes.sys.mjs index c01b1a58b3..88c9390225 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustExternalTypes.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustExternalTypes.sys.mjs @@ -381,7 +381,7 @@ export function gradient(value) { throw e; } return UniFFIScaffolding.callAsync( - 40, // external_types:uniffi_uniffi_fixture_external_types_fn_func_gradient + 52, // external_types:uniffi_uniffi_fixture_external_types_fn_func_gradient FfiConverterOptionalTypeLine.lower(value), ) } @@ -414,7 +414,7 @@ export function intersection(ln1,ln2) { throw e; } return UniFFIScaffolding.callAsync( - 41, // external_types:uniffi_uniffi_fixture_external_types_fn_func_intersection + 53, // external_types:uniffi_uniffi_fixture_external_types_fn_func_intersection FfiConverterTypeLine.lower(ln1), FfiConverterTypeLine.lower(ln2), ) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustFixtureCallbacks.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustFixtureCallbacks.sys.mjs index 75fe81a458..2b6b6b26ff 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustFixtureCallbacks.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustFixtureCallbacks.sys.mjs @@ -596,7 +596,7 @@ export function logEvenNumbers(logger,items) { throw e; } return UniFFIScaffolding.callAsync( - 42, // fixture_callbacks:uniffi_uniffi_fixture_callbacks_fn_func_log_even_numbers + 46, // fixture_callbacks:uniffi_uniffi_fixture_callbacks_fn_func_log_even_numbers FfiConverterTypeLogger.lower(logger), FfiConverterSequencei32.lower(items), ) @@ -630,7 +630,7 @@ export function logEvenNumbersMainThread(logger,items) { throw e; } return UniFFIScaffolding.callSync( - 43, // fixture_callbacks:uniffi_uniffi_fixture_callbacks_fn_func_log_even_numbers_main_thread + 47, // fixture_callbacks:uniffi_uniffi_fixture_callbacks_fn_func_log_even_numbers_main_thread FfiConverterTypeLogger.lower(logger), FfiConverterSequencei32.lower(items), ) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustGeometry.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustGeometry.sys.mjs index 1a7ebb287a..6ff9a25fa9 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustGeometry.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustGeometry.sys.mjs @@ -325,7 +325,7 @@ export class FfiConverterTypeLine extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof Line)) { - throw new TypeError(`Expected 'Line', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'Line', found '${typeof value}'`); } try { FfiConverterTypePoint.checkType(value.start); @@ -398,7 +398,7 @@ export class FfiConverterTypePoint extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof Point)) { - throw new TypeError(`Expected 'Point', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'Point', found '${typeof value}'`); } try { FfiConverterF64.checkType(value.coordX); @@ -474,7 +474,7 @@ export function gradient(ln) { throw e; } return UniFFIScaffolding.callAsync( - 44, // geometry:uniffi_uniffi_geometry_fn_func_gradient + 58, // geometry:uniffi_uniffi_geometry_fn_func_gradient FfiConverterTypeLine.lower(ln), ) } @@ -507,7 +507,7 @@ export function intersection(ln1,ln2) { throw e; } return UniFFIScaffolding.callAsync( - 45, // geometry:uniffi_uniffi_geometry_fn_func_intersection + 59, // geometry:uniffi_uniffi_geometry_fn_func_intersection FfiConverterTypeLine.lower(ln1), FfiConverterTypeLine.lower(ln2), ) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRefcounts.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRefcounts.sys.mjs new file mode 100644 index 0000000000..d8a598d150 --- /dev/null +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRefcounts.sys.mjs @@ -0,0 +1,388 @@ +// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate. +// Trust me, you don't want to mess with it! + +import { UniFFITypeError } from "resource://gre/modules/UniFFI.sys.mjs"; + + + +// Objects intended to be used in the unit tests +export var UnitTestObjs = {}; + +// Write/Read data to/from an ArrayBuffer +class ArrayBufferDataStream { + constructor(arrayBuffer) { + this.dataView = new DataView(arrayBuffer); + this.pos = 0; + } + + readUint8() { + let rv = this.dataView.getUint8(this.pos); + this.pos += 1; + return rv; + } + + writeUint8(value) { + this.dataView.setUint8(this.pos, value); + this.pos += 1; + } + + readUint16() { + let rv = this.dataView.getUint16(this.pos); + this.pos += 2; + return rv; + } + + writeUint16(value) { + this.dataView.setUint16(this.pos, value); + this.pos += 2; + } + + readUint32() { + let rv = this.dataView.getUint32(this.pos); + this.pos += 4; + return rv; + } + + writeUint32(value) { + this.dataView.setUint32(this.pos, value); + this.pos += 4; + } + + readUint64() { + let rv = this.dataView.getBigUint64(this.pos); + this.pos += 8; + return Number(rv); + } + + writeUint64(value) { + this.dataView.setBigUint64(this.pos, BigInt(value)); + this.pos += 8; + } + + + readInt8() { + let rv = this.dataView.getInt8(this.pos); + this.pos += 1; + return rv; + } + + writeInt8(value) { + this.dataView.setInt8(this.pos, value); + this.pos += 1; + } + + readInt16() { + let rv = this.dataView.getInt16(this.pos); + this.pos += 2; + return rv; + } + + writeInt16(value) { + this.dataView.setInt16(this.pos, value); + this.pos += 2; + } + + readInt32() { + let rv = this.dataView.getInt32(this.pos); + this.pos += 4; + return rv; + } + + writeInt32(value) { + this.dataView.setInt32(this.pos, value); + this.pos += 4; + } + + readInt64() { + let rv = this.dataView.getBigInt64(this.pos); + this.pos += 8; + return Number(rv); + } + + writeInt64(value) { + this.dataView.setBigInt64(this.pos, BigInt(value)); + this.pos += 8; + } + + readFloat32() { + let rv = this.dataView.getFloat32(this.pos); + this.pos += 4; + return rv; + } + + writeFloat32(value) { + this.dataView.setFloat32(this.pos, value); + this.pos += 4; + } + + readFloat64() { + let rv = this.dataView.getFloat64(this.pos); + this.pos += 8; + return rv; + } + + writeFloat64(value) { + this.dataView.setFloat64(this.pos, value); + this.pos += 8; + } + + + writeString(value) { + const encoder = new TextEncoder(); + // Note: in order to efficiently write this data, we first write the + // string data, reserving 4 bytes for the size. + const dest = new Uint8Array(this.dataView.buffer, this.pos + 4); + const encodeResult = encoder.encodeInto(value, dest); + if (encodeResult.read != value.length) { + throw new UniFFIError( + "writeString: out of space when writing to ArrayBuffer. Did the computeSize() method returned the wrong result?" + ); + } + const size = encodeResult.written; + // Next, go back and write the size before the string data + this.dataView.setUint32(this.pos, size); + // Finally, advance our position past both the size and string data + this.pos += size + 4; + } + + readString() { + const decoder = new TextDecoder(); + const size = this.readUint32(); + const source = new Uint8Array(this.dataView.buffer, this.pos, size) + const value = decoder.decode(source); + this.pos += size; + return value; + } + + // Reads a SingletonObject pointer from the data stream + // UniFFI Pointers are **always** 8 bytes long. That is enforced + // by the C++ and Rust Scaffolding code. + readPointerSingletonObject() { + const pointerId = 6; // refcounts:SingletonObject + const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); + this.pos += 8; + return res; + } + + // Writes a SingletonObject pointer into the data stream + // UniFFI Pointers are **always** 8 bytes long. That is enforced + // by the C++ and Rust Scaffolding code. + writePointerSingletonObject(value) { + const pointerId = 6; // refcounts:SingletonObject + UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); + this.pos += 8; + } + +} + +function handleRustResult(result, liftCallback, liftErrCallback) { + switch (result.code) { + case "success": + return liftCallback(result.data); + + case "error": + throw liftErrCallback(result.data); + + case "internal-error": + let message = result.internalErrorMessage; + if (message) { + throw new UniFFIInternalError(message); + } else { + throw new UniFFIInternalError("Unknown error"); + } + + default: + throw new UniFFIError(`Unexpected status code: ${result.code}`); + } +} + +class UniFFIError { + constructor(message) { + this.message = message; + } + + toString() { + return `UniFFIError: ${this.message}` + } +} + +class UniFFIInternalError extends UniFFIError {} + +// Base class for FFI converters +class FfiConverter { + // throw `UniFFITypeError` if a value to be converted has an invalid type + static checkType(value) { + if (value === undefined ) { + throw new UniFFITypeError(`undefined`); + } + if (value === null ) { + throw new UniFFITypeError(`null`); + } + } +} + +// Base class for FFI converters that lift/lower by reading/writing to an ArrayBuffer +class FfiConverterArrayBuffer extends FfiConverter { + static lift(buf) { + return this.read(new ArrayBufferDataStream(buf)); + } + + static lower(value) { + const buf = new ArrayBuffer(this.computeSize(value)); + const dataStream = new ArrayBufferDataStream(buf); + this.write(dataStream, value); + return buf; + } +} + +// Symbols that are used to ensure that Object constructors +// can only be used with a proper UniFFI pointer +const uniffiObjectPtr = Symbol("uniffiObjectPtr"); +const constructUniffiObject = Symbol("constructUniffiObject"); +UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr; + +// Export the FFIConverter object to make external types work. +export class FfiConverterI32 extends FfiConverter { + static checkType(value) { + super.checkType(value); + if (!Number.isInteger(value)) { + throw new UniFFITypeError(`${value} is not an integer`); + } + if (value < -2147483648 || value > 2147483647) { + throw new UniFFITypeError(`${value} exceeds the I32 bounds`); + } + } + static computeSize() { + return 4; + } + static lift(value) { + return value; + } + static lower(value) { + return value; + } + static write(dataStream, value) { + dataStream.writeInt32(value) + } + static read(dataStream) { + return dataStream.readInt32() + } +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterString extends FfiConverter { + static checkType(value) { + super.checkType(value); + if (typeof value !== "string") { + throw new UniFFITypeError(`${value} is not a string`); + } + } + + static lift(buf) { + const decoder = new TextDecoder(); + const utf8Arr = new Uint8Array(buf); + return decoder.decode(utf8Arr); + } + static lower(value) { + const encoder = new TextEncoder(); + return encoder.encode(value).buffer; + } + + static write(dataStream, value) { + dataStream.writeString(value); + } + + static read(dataStream) { + return dataStream.readString(); + } + + static computeSize(value) { + const encoder = new TextEncoder(); + return 4 + encoder.encode(value).length + } +} + +export class SingletonObject { + // Use `init` to instantiate this class. + // DO NOT USE THIS CONSTRUCTOR DIRECTLY + constructor(opts) { + if (!Object.prototype.hasOwnProperty.call(opts, constructUniffiObject)) { + throw new UniFFIError("Attempting to construct an object using the JavaScript constructor directly" + + "Please use a UDL defined constructor, or the init function for the primary constructor") + } + if (!opts[constructUniffiObject] instanceof UniFFIPointer) { + throw new UniFFIError("Attempting to create a UniFFI object with a pointer that is not an instance of UniFFIPointer") + } + this[uniffiObjectPtr] = opts[constructUniffiObject]; + } + + method() { + const liftResult = (result) => undefined; + const liftError = null; + const functionCall = () => { + return UniFFIScaffolding.callSync( + 55, // refcounts:uniffi_uniffi_fixture_refcounts_fn_method_singletonobject_method + FfiConverterTypeSingletonObject.lower(this), + ) + } + return handleRustResult(functionCall(), liftResult, liftError); + } + +} + +// Export the FFIConverter object to make external types work. +export class FfiConverterTypeSingletonObject extends FfiConverter { + static lift(value) { + const opts = {}; + opts[constructUniffiObject] = value; + return new SingletonObject(opts); + } + + static lower(value) { + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'SingletonObject' instance"); + } + return ptr; + } + + static read(dataStream) { + return this.lift(dataStream.readPointerSingletonObject()); + } + + static write(dataStream, value) { + dataStream.writePointerSingletonObject(value[uniffiObjectPtr]); + } + + static computeSize(value) { + return 8; + } +} + + + + + +export function getJsRefcount() { + + const liftResult = (result) => FfiConverterI32.lift(result); + const liftError = null; + const functionCall = () => { + return UniFFIScaffolding.callSync( + 56, // refcounts:uniffi_uniffi_fixture_refcounts_fn_func_get_js_refcount + ) + } + return handleRustResult(functionCall(), liftResult, liftError); +} + +export function getSingleton() { + + const liftResult = (result) => FfiConverterTypeSingletonObject.lift(result); + const liftError = null; + const functionCall = () => { + return UniFFIScaffolding.callSync( + 57, // refcounts:uniffi_uniffi_fixture_refcounts_fn_func_get_singleton + ) + } + return handleRustResult(functionCall(), liftResult, liftError); +} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRondpoint.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRondpoint.sys.mjs index 1edb7ec608..f6db36163e 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRondpoint.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustRondpoint.sys.mjs @@ -158,7 +158,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerOptionneur() { - const pointerId = 5; // rondpoint:Optionneur + const pointerId = 7; // rondpoint:Optionneur const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -168,7 +168,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerOptionneur(value) { - const pointerId = 5; // rondpoint:Optionneur + const pointerId = 7; // rondpoint:Optionneur UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -178,7 +178,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerRetourneur() { - const pointerId = 6; // rondpoint:Retourneur + const pointerId = 8; // rondpoint:Retourneur const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -188,7 +188,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerRetourneur(value) { - const pointerId = 6; // rondpoint:Retourneur + const pointerId = 8; // rondpoint:Retourneur UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -198,7 +198,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerStringifier() { - const pointerId = 7; // rondpoint:Stringifier + const pointerId = 9; // rondpoint:Stringifier const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -208,7 +208,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerStringifier(value) { - const pointerId = 7; // rondpoint:Stringifier + const pointerId = 9; // rondpoint:Stringifier UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -620,7 +620,7 @@ export class Optionneur { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 46, // rondpoint:uniffi_uniffi_rondpoint_fn_constructor_optionneur_new + 61, // rondpoint:uniffi_uniffi_rondpoint_fn_constructor_optionneur_new ) } try { @@ -642,7 +642,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 47, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_boolean + 62, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_boolean FfiConverterTypeOptionneur.lower(this), FfiConverterBool.lower(value), ) @@ -667,7 +667,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 48, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_enum + 63, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_enum FfiConverterTypeOptionneur.lower(this), FfiConverterTypeEnumeration.lower(value), ) @@ -692,7 +692,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 49, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_f32 + 64, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_f32 FfiConverterTypeOptionneur.lower(this), FfiConverterF32.lower(value), ) @@ -717,7 +717,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 50, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_f64 + 65, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_f64 FfiConverterTypeOptionneur.lower(this), FfiConverterF64.lower(value), ) @@ -742,7 +742,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 51, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i16_dec + 66, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i16_dec FfiConverterTypeOptionneur.lower(this), FfiConverterI16.lower(value), ) @@ -767,7 +767,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 52, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i16_hex + 67, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i16_hex FfiConverterTypeOptionneur.lower(this), FfiConverterI16.lower(value), ) @@ -792,7 +792,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 53, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i32_dec + 68, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i32_dec FfiConverterTypeOptionneur.lower(this), FfiConverterI32.lower(value), ) @@ -817,7 +817,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 54, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i32_hex + 69, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i32_hex FfiConverterTypeOptionneur.lower(this), FfiConverterI32.lower(value), ) @@ -842,7 +842,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 55, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i64_dec + 70, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i64_dec FfiConverterTypeOptionneur.lower(this), FfiConverterI64.lower(value), ) @@ -867,7 +867,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 56, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i64_hex + 71, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i64_hex FfiConverterTypeOptionneur.lower(this), FfiConverterI64.lower(value), ) @@ -892,7 +892,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 57, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i8_dec + 72, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i8_dec FfiConverterTypeOptionneur.lower(this), FfiConverterI8.lower(value), ) @@ -917,7 +917,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 58, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i8_hex + 73, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_i8_hex FfiConverterTypeOptionneur.lower(this), FfiConverterI8.lower(value), ) @@ -942,7 +942,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 59, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_null + 74, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_null FfiConverterTypeOptionneur.lower(this), FfiConverterOptionalstring.lower(value), ) @@ -967,7 +967,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 60, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_sequence + 75, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_sequence FfiConverterTypeOptionneur.lower(this), FfiConverterSequencestring.lower(value), ) @@ -992,7 +992,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 61, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_string + 76, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_string FfiConverterTypeOptionneur.lower(this), FfiConverterString.lower(value), ) @@ -1017,7 +1017,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 62, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u16_dec + 77, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u16_dec FfiConverterTypeOptionneur.lower(this), FfiConverterU16.lower(value), ) @@ -1042,7 +1042,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 63, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u16_hex + 78, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u16_hex FfiConverterTypeOptionneur.lower(this), FfiConverterU16.lower(value), ) @@ -1067,7 +1067,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 64, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u32_dec + 79, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u32_dec FfiConverterTypeOptionneur.lower(this), FfiConverterU32.lower(value), ) @@ -1092,7 +1092,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 65, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u32_hex + 80, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u32_hex FfiConverterTypeOptionneur.lower(this), FfiConverterU32.lower(value), ) @@ -1117,7 +1117,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 66, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u32_oct + 81, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u32_oct FfiConverterTypeOptionneur.lower(this), FfiConverterU32.lower(value), ) @@ -1142,7 +1142,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 67, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u64_dec + 82, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u64_dec FfiConverterTypeOptionneur.lower(this), FfiConverterU64.lower(value), ) @@ -1167,7 +1167,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 68, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u64_hex + 83, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u64_hex FfiConverterTypeOptionneur.lower(this), FfiConverterU64.lower(value), ) @@ -1192,7 +1192,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 69, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u8_dec + 84, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u8_dec FfiConverterTypeOptionneur.lower(this), FfiConverterU8.lower(value), ) @@ -1217,7 +1217,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 70, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u8_hex + 85, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_u8_hex FfiConverterTypeOptionneur.lower(this), FfiConverterU8.lower(value), ) @@ -1242,7 +1242,7 @@ export class Optionneur { throw e; } return UniFFIScaffolding.callAsync( - 71, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_zero + 86, // rondpoint:uniffi_uniffi_rondpoint_fn_method_optionneur_sinon_zero FfiConverterTypeOptionneur.lower(this), FfiConverterOptionali32.lower(value), ) @@ -1265,7 +1265,11 @@ export class FfiConverterTypeOptionneur extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'Optionneur' instance"); + } + return ptr; } static read(dataStream) { @@ -1305,7 +1309,7 @@ export class Retourneur { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 72, // rondpoint:uniffi_uniffi_rondpoint_fn_constructor_retourneur_new + 88, // rondpoint:uniffi_uniffi_rondpoint_fn_constructor_retourneur_new ) } try { @@ -1327,7 +1331,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 73, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_boolean + 89, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_boolean FfiConverterTypeRetourneur.lower(this), FfiConverterBool.lower(value), ) @@ -1352,7 +1356,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 74, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_double + 90, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_double FfiConverterTypeRetourneur.lower(this), FfiConverterF64.lower(value), ) @@ -1377,7 +1381,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 75, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_float + 91, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_float FfiConverterTypeRetourneur.lower(this), FfiConverterF32.lower(value), ) @@ -1402,7 +1406,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 76, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i16 + 92, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i16 FfiConverterTypeRetourneur.lower(this), FfiConverterI16.lower(value), ) @@ -1427,7 +1431,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 77, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i32 + 93, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i32 FfiConverterTypeRetourneur.lower(this), FfiConverterI32.lower(value), ) @@ -1452,7 +1456,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 78, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i64 + 94, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i64 FfiConverterTypeRetourneur.lower(this), FfiConverterI64.lower(value), ) @@ -1477,7 +1481,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 79, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i8 + 95, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_i8 FfiConverterTypeRetourneur.lower(this), FfiConverterI8.lower(value), ) @@ -1502,7 +1506,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 80, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_nombres + 96, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_nombres FfiConverterTypeRetourneur.lower(this), FfiConverterTypeDictionnaireNombres.lower(value), ) @@ -1527,7 +1531,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 81, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_nombres_signes + 97, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_nombres_signes FfiConverterTypeRetourneur.lower(this), FfiConverterTypeDictionnaireNombresSignes.lower(value), ) @@ -1552,7 +1556,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 82, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_optionneur_dictionnaire + 98, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_optionneur_dictionnaire FfiConverterTypeRetourneur.lower(this), FfiConverterTypeOptionneurDictionnaire.lower(value), ) @@ -1577,7 +1581,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 83, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_string + 99, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_string FfiConverterTypeRetourneur.lower(this), FfiConverterString.lower(value), ) @@ -1602,7 +1606,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 84, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u16 + 100, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u16 FfiConverterTypeRetourneur.lower(this), FfiConverterU16.lower(value), ) @@ -1627,7 +1631,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 85, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u32 + 101, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u32 FfiConverterTypeRetourneur.lower(this), FfiConverterU32.lower(value), ) @@ -1652,7 +1656,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 86, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u64 + 102, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u64 FfiConverterTypeRetourneur.lower(this), FfiConverterU64.lower(value), ) @@ -1677,7 +1681,7 @@ export class Retourneur { throw e; } return UniFFIScaffolding.callAsync( - 87, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u8 + 103, // rondpoint:uniffi_uniffi_rondpoint_fn_method_retourneur_identique_u8 FfiConverterTypeRetourneur.lower(this), FfiConverterU8.lower(value), ) @@ -1700,7 +1704,11 @@ export class FfiConverterTypeRetourneur extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'Retourneur' instance"); + } + return ptr; } static read(dataStream) { @@ -1740,7 +1748,7 @@ export class Stringifier { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 88, // rondpoint:uniffi_uniffi_rondpoint_fn_constructor_stringifier_new + 105, // rondpoint:uniffi_uniffi_rondpoint_fn_constructor_stringifier_new ) } try { @@ -1762,7 +1770,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 89, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_boolean + 106, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_boolean FfiConverterTypeStringifier.lower(this), FfiConverterBool.lower(value), ) @@ -1787,7 +1795,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 90, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_double + 107, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_double FfiConverterTypeStringifier.lower(this), FfiConverterF64.lower(value), ) @@ -1812,7 +1820,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 91, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_float + 108, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_float FfiConverterTypeStringifier.lower(this), FfiConverterF32.lower(value), ) @@ -1837,7 +1845,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 92, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i16 + 109, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i16 FfiConverterTypeStringifier.lower(this), FfiConverterI16.lower(value), ) @@ -1862,7 +1870,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 93, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i32 + 110, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i32 FfiConverterTypeStringifier.lower(this), FfiConverterI32.lower(value), ) @@ -1887,7 +1895,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 94, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i64 + 111, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i64 FfiConverterTypeStringifier.lower(this), FfiConverterI64.lower(value), ) @@ -1912,7 +1920,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 95, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i8 + 112, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_i8 FfiConverterTypeStringifier.lower(this), FfiConverterI8.lower(value), ) @@ -1937,7 +1945,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 96, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u16 + 113, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u16 FfiConverterTypeStringifier.lower(this), FfiConverterU16.lower(value), ) @@ -1962,7 +1970,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 97, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u32 + 114, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u32 FfiConverterTypeStringifier.lower(this), FfiConverterU32.lower(value), ) @@ -1987,7 +1995,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 98, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u64 + 115, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u64 FfiConverterTypeStringifier.lower(this), FfiConverterU64.lower(value), ) @@ -2012,7 +2020,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 99, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u8 + 116, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_to_string_u8 FfiConverterTypeStringifier.lower(this), FfiConverterU8.lower(value), ) @@ -2037,7 +2045,7 @@ export class Stringifier { throw e; } return UniFFIScaffolding.callAsync( - 100, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_well_known_string + 117, // rondpoint:uniffi_uniffi_rondpoint_fn_method_stringifier_well_known_string FfiConverterTypeStringifier.lower(this), FfiConverterString.lower(value), ) @@ -2060,7 +2068,11 @@ export class FfiConverterTypeStringifier extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'Stringifier' instance"); + } + return ptr; } static read(dataStream) { @@ -2154,7 +2166,7 @@ export class FfiConverterTypeDictionnaire extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof Dictionnaire)) { - throw new TypeError(`Expected 'Dictionnaire', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'Dictionnaire', found '${typeof value}'`); } try { FfiConverterTypeEnumeration.checkType(value.un); @@ -2269,7 +2281,7 @@ export class FfiConverterTypeDictionnaireNombres extends FfiConverterArrayBuffer static checkType(value) { super.checkType(value); if (!(value instanceof DictionnaireNombres)) { - throw new TypeError(`Expected 'DictionnaireNombres', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'DictionnaireNombres', found '${typeof value}'`); } try { FfiConverterU8.checkType(value.petitNombre); @@ -2384,7 +2396,7 @@ export class FfiConverterTypeDictionnaireNombresSignes extends FfiConverterArray static checkType(value) { super.checkType(value); if (!(value instanceof DictionnaireNombresSignes)) { - throw new TypeError(`Expected 'DictionnaireNombresSignes', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'DictionnaireNombresSignes', found '${typeof value}'`); } try { FfiConverterI8.checkType(value.petitNombre); @@ -2642,7 +2654,7 @@ export class FfiConverterTypeOptionneurDictionnaire extends FfiConverterArrayBuf static checkType(value) { super.checkType(value); if (!(value instanceof OptionneurDictionnaire)) { - throw new TypeError(`Expected 'OptionneurDictionnaire', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'OptionneurDictionnaire', found '${typeof value}'`); } try { FfiConverterI8.checkType(value.i8Var); @@ -2806,7 +2818,7 @@ export class FfiConverterTypeminusculeMajusculeDict extends FfiConverterArrayBuf static checkType(value) { super.checkType(value); if (!(value instanceof MinusculeMajusculeDict)) { - throw new TypeError(`Expected 'MinusculeMajusculeDict', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'MinusculeMajusculeDict', found '${typeof value}'`); } try { FfiConverterBool.checkType(value.minusculeMajusculeField); @@ -2838,7 +2850,7 @@ export class FfiConverterTypeEnumeration extends FfiConverterArrayBuffer { case 3: return Enumeration.TROIS default: - return new Error("Unknown Enumeration variant"); + throw new UniFFITypeError("Unknown Enumeration variant"); } } @@ -2855,7 +2867,7 @@ export class FfiConverterTypeEnumeration extends FfiConverterArrayBuffer { dataStream.writeInt32(3); return; } - return new Error("Unknown Enumeration variant"); + throw new UniFFITypeError("Unknown Enumeration variant"); } static computeSize(value) { @@ -2914,7 +2926,7 @@ export class FfiConverterTypeEnumerationAvecDonnees extends FfiConverterArrayBuf FfiConverterString.read(dataStream) ); default: - return new Error("Unknown EnumerationAvecDonnees variant"); + throw new UniFFITypeError("Unknown EnumerationAvecDonnees variant"); } } @@ -2934,7 +2946,7 @@ export class FfiConverterTypeEnumerationAvecDonnees extends FfiConverterArrayBuf FfiConverterString.write(dataStream, value.second); return; } - return new Error("Unknown EnumerationAvecDonnees variant"); + throw new UniFFITypeError("Unknown EnumerationAvecDonnees variant"); } static computeSize(value) { @@ -2952,7 +2964,7 @@ export class FfiConverterTypeEnumerationAvecDonnees extends FfiConverterArrayBuf totalSize += FfiConverterString.computeSize(value.second); return totalSize; } - return new Error("Unknown EnumerationAvecDonnees variant"); + throw new UniFFITypeError("Unknown EnumerationAvecDonnees variant"); } static checkType(value) { @@ -2976,7 +2988,7 @@ export class FfiConverterTypeminusculeMajusculeEnum extends FfiConverterArrayBuf case 1: return MinusculeMajusculeEnum.MINUSCULE_MAJUSCULE_VARIANT default: - return new Error("Unknown MinusculeMajusculeEnum variant"); + throw new UniFFITypeError("Unknown MinusculeMajusculeEnum variant"); } } @@ -2985,7 +2997,7 @@ export class FfiConverterTypeminusculeMajusculeEnum extends FfiConverterArrayBuf dataStream.writeInt32(1); return; } - return new Error("Unknown MinusculeMajusculeEnum variant"); + throw new UniFFITypeError("Unknown MinusculeMajusculeEnum variant"); } static computeSize(value) { @@ -3272,7 +3284,7 @@ export function copieCarte(c) { throw e; } return UniFFIScaffolding.callAsync( - 101, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_carte + 118, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_carte FfiConverterMapStringTypeEnumerationAvecDonnees.lower(c), ) } @@ -3297,7 +3309,7 @@ export function copieDictionnaire(d) { throw e; } return UniFFIScaffolding.callAsync( - 102, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_dictionnaire + 119, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_dictionnaire FfiConverterTypeDictionnaire.lower(d), ) } @@ -3322,7 +3334,7 @@ export function copieEnumeration(e) { throw e; } return UniFFIScaffolding.callAsync( - 103, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_enumeration + 120, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_enumeration FfiConverterTypeEnumeration.lower(e), ) } @@ -3347,7 +3359,7 @@ export function copieEnumerations(e) { throw e; } return UniFFIScaffolding.callAsync( - 104, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_enumerations + 121, // rondpoint:uniffi_uniffi_rondpoint_fn_func_copie_enumerations FfiConverterSequenceTypeEnumeration.lower(e), ) } @@ -3372,7 +3384,7 @@ export function switcheroo(b) { throw e; } return UniFFIScaffolding.callAsync( - 105, // rondpoint:uniffi_uniffi_rondpoint_fn_func_switcheroo + 122, // rondpoint:uniffi_uniffi_rondpoint_fn_func_switcheroo FfiConverterBool.lower(b), ) } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustSprites.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustSprites.sys.mjs index b404af06b1..c25a488009 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustSprites.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustSprites.sys.mjs @@ -158,7 +158,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerSprite() { - const pointerId = 8; // sprites:Sprite + const pointerId = 10; // sprites:Sprite const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -168,7 +168,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerSprite(value) { - const pointerId = 8; // sprites:Sprite + const pointerId = 10; // sprites:Sprite UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -325,7 +325,7 @@ export class Sprite { throw e; } return UniFFIScaffolding.callAsync( - 106, // sprites:uniffi_uniffi_sprites_fn_constructor_sprite_new + 124, // sprites:uniffi_uniffi_sprites_fn_constructor_sprite_new FfiConverterOptionalTypePoint.lower(initialPosition), ) } @@ -361,7 +361,7 @@ export class Sprite { throw e; } return UniFFIScaffolding.callAsync( - 107, // sprites:uniffi_uniffi_sprites_fn_constructor_sprite_new_relative_to + 125, // sprites:uniffi_uniffi_sprites_fn_constructor_sprite_new_relative_to FfiConverterTypePoint.lower(reference), FfiConverterTypeVector.lower(direction), ) @@ -377,7 +377,7 @@ export class Sprite { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 108, // sprites:uniffi_uniffi_sprites_fn_method_sprite_get_position + 126, // sprites:uniffi_uniffi_sprites_fn_method_sprite_get_position FfiConverterTypeSprite.lower(this), ) } @@ -401,7 +401,7 @@ export class Sprite { throw e; } return UniFFIScaffolding.callAsync( - 109, // sprites:uniffi_uniffi_sprites_fn_method_sprite_move_by + 127, // sprites:uniffi_uniffi_sprites_fn_method_sprite_move_by FfiConverterTypeSprite.lower(this), FfiConverterTypeVector.lower(direction), ) @@ -426,7 +426,7 @@ export class Sprite { throw e; } return UniFFIScaffolding.callAsync( - 110, // sprites:uniffi_uniffi_sprites_fn_method_sprite_move_to + 128, // sprites:uniffi_uniffi_sprites_fn_method_sprite_move_to FfiConverterTypeSprite.lower(this), FfiConverterTypePoint.lower(position), ) @@ -449,7 +449,11 @@ export class FfiConverterTypeSprite extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'Sprite' instance"); + } + return ptr; } static read(dataStream) { @@ -517,7 +521,7 @@ export class FfiConverterTypePoint extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof Point)) { - throw new TypeError(`Expected 'Point', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'Point', found '${typeof value}'`); } try { FfiConverterF64.checkType(value.x); @@ -590,7 +594,7 @@ export class FfiConverterTypeVector extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof Vector)) { - throw new TypeError(`Expected 'Vector', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'Vector', found '${typeof value}'`); } try { FfiConverterF64.checkType(value.dx); @@ -674,7 +678,7 @@ export function translate(position,direction) { throw e; } return UniFFIScaffolding.callAsync( - 111, // sprites:uniffi_uniffi_sprites_fn_func_translate + 129, // sprites:uniffi_uniffi_sprites_fn_func_translate FfiConverterTypePoint.lower(position), FfiConverterTypeVector.lower(direction), ) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustTodolist.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustTodolist.sys.mjs index 59996b78fa..ddeccc9bf2 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustTodolist.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated/RustTodolist.sys.mjs @@ -158,7 +158,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. readPointerTodoList() { - const pointerId = 9; // todolist:TodoList + const pointerId = 11; // todolist:TodoList const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos); this.pos += 8; return res; @@ -168,7 +168,7 @@ class ArrayBufferDataStream { // UniFFI Pointers are **always** 8 bytes long. That is enforced // by the C++ and Rust Scaffolding code. writePointerTodoList(value) { - const pointerId = 9; // todolist:TodoList + const pointerId = 11; // todolist:TodoList UniFFIScaffolding.writePointer(pointerId, value, this.dataView.buffer, this.pos); this.pos += 8; } @@ -298,7 +298,7 @@ export class TodoList { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 112, // todolist:uniffi_uniffi_todolist_fn_constructor_todolist_new + 131, // todolist:uniffi_uniffi_todolist_fn_constructor_todolist_new ) } try { @@ -320,7 +320,7 @@ export class TodoList { throw e; } return UniFFIScaffolding.callAsync( - 113, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_entries + 132, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_entries FfiConverterTypeTodoList.lower(this), FfiConverterSequenceTypeTodoEntry.lower(entries), ) @@ -345,7 +345,7 @@ export class TodoList { throw e; } return UniFFIScaffolding.callAsync( - 114, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_entry + 133, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_entry FfiConverterTypeTodoList.lower(this), FfiConverterTypeTodoEntry.lower(entry), ) @@ -370,7 +370,7 @@ export class TodoList { throw e; } return UniFFIScaffolding.callAsync( - 115, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_item + 134, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_item FfiConverterTypeTodoList.lower(this), FfiConverterString.lower(todo), ) @@ -395,7 +395,7 @@ export class TodoList { throw e; } return UniFFIScaffolding.callAsync( - 116, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_items + 135, // todolist:uniffi_uniffi_todolist_fn_method_todolist_add_items FfiConverterTypeTodoList.lower(this), FfiConverterSequencestring.lower(items), ) @@ -420,7 +420,7 @@ export class TodoList { throw e; } return UniFFIScaffolding.callAsync( - 117, // todolist:uniffi_uniffi_todolist_fn_method_todolist_clear_item + 136, // todolist:uniffi_uniffi_todolist_fn_method_todolist_clear_item FfiConverterTypeTodoList.lower(this), FfiConverterString.lower(todo), ) @@ -437,7 +437,7 @@ export class TodoList { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 118, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_entries + 137, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_entries FfiConverterTypeTodoList.lower(this), ) } @@ -453,7 +453,7 @@ export class TodoList { const liftError = (data) => FfiConverterTypeTodoError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 119, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_first + 138, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_first FfiConverterTypeTodoList.lower(this), ) } @@ -469,7 +469,7 @@ export class TodoList { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 120, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_items + 139, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_items FfiConverterTypeTodoList.lower(this), ) } @@ -485,7 +485,7 @@ export class TodoList { const liftError = (data) => FfiConverterTypeTodoError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 121, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_last + 140, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_last FfiConverterTypeTodoList.lower(this), ) } @@ -501,7 +501,7 @@ export class TodoList { const liftError = (data) => FfiConverterTypeTodoError.lift(data); const functionCall = () => { return UniFFIScaffolding.callAsync( - 122, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_last_entry + 141, // todolist:uniffi_uniffi_todolist_fn_method_todolist_get_last_entry FfiConverterTypeTodoList.lower(this), ) } @@ -517,7 +517,7 @@ export class TodoList { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 123, // todolist:uniffi_uniffi_todolist_fn_method_todolist_make_default + 142, // todolist:uniffi_uniffi_todolist_fn_method_todolist_make_default FfiConverterTypeTodoList.lower(this), ) } @@ -539,7 +539,11 @@ export class FfiConverterTypeTodoList extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a 'TodoList' instance"); + } + return ptr; } static read(dataStream) { @@ -594,7 +598,7 @@ export class FfiConverterTypeTodoEntry extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof TodoEntry)) { - throw new TypeError(`Expected 'TodoEntry', found '${typeof value}'`); + throw new UniFFITypeError(`Expected 'TodoEntry', found '${typeof value}'`); } try { FfiConverterString.checkType(value.text); @@ -683,7 +687,7 @@ export class FfiConverterTypeTodoError extends FfiConverterArrayBuffer { case 5: return new DeligatedError(FfiConverterString.read(dataStream)); default: - throw new Error("Unknown TodoError variant"); + throw new UniFFITypeError("Unknown TodoError variant"); } } static computeSize(value) { @@ -704,7 +708,7 @@ export class FfiConverterTypeTodoError extends FfiConverterArrayBuffer { if (value instanceof DeligatedError) { return totalSize; } - throw new Error("Unknown TodoError variant"); + throw new UniFFITypeError("Unknown TodoError variant"); } static write(dataStream, value) { if (value instanceof TodoDoesNotExist) { @@ -727,7 +731,7 @@ export class FfiConverterTypeTodoError extends FfiConverterArrayBuffer { dataStream.writeInt32(5); return; } - throw new Error("Unknown TodoError variant"); + throw new UniFFITypeError("Unknown TodoError variant"); } static errorClass = TodoError; @@ -876,7 +880,7 @@ export function createEntryWith(todo) { throw e; } return UniFFIScaffolding.callAsync( - 124, // todolist:uniffi_uniffi_todolist_fn_func_create_entry_with + 143, // todolist:uniffi_uniffi_todolist_fn_func_create_entry_with FfiConverterString.lower(todo), ) } @@ -893,7 +897,7 @@ export function getDefaultList() { const liftError = null; const functionCall = () => { return UniFFIScaffolding.callAsync( - 125, // todolist:uniffi_uniffi_todolist_fn_func_get_default_list + 144, // todolist:uniffi_uniffi_todolist_fn_func_get_default_list ) } try { @@ -917,7 +921,7 @@ export function setDefaultList(list) { throw e; } return UniFFIScaffolding.callAsync( - 126, // todolist:uniffi_uniffi_todolist_fn_func_set_default_list + 145, // todolist:uniffi_uniffi_todolist_fn_func_set_default_list FfiConverterTypeTodoList.lower(list), ) } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/moz.build b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/moz.build index d5ff2d7cb6..eed04220cb 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/moz.build +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/moz.build @@ -12,6 +12,7 @@ components = [ "ExternalTypes", "FixtureCallbacks", "Geometry", + "Refcounts", "Rondpoint", "Sprites", "Todolist", diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_external_types.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_external_types.js index e2f985cde7..699dcfe6f3 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_external_types.js +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_external_types.js @@ -6,10 +6,10 @@ const ExternalTypes = ChromeUtils.importESModule( ); add_task(async function () { - const line = new ExternalTypes.Line( - new ExternalTypes.Point(0, 0, "p1"), - new ExternalTypes.Point(2, 1, "p2") - ); + const line = new ExternalTypes.Line({ + start: await new ExternalTypes.Point({ coordX: 0, coordY: 0 }), + end: await new ExternalTypes.Point({ coordX: 2, coordY: 1 }), + }); Assert.equal(await ExternalTypes.gradient(line), 0.5); Assert.equal(await ExternalTypes.gradient(null), 0.0); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_geometry.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_geometry.js index cdb552e4ef..1028cd37c2 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_geometry.js +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_geometry.js @@ -6,24 +6,16 @@ const Geometry = ChromeUtils.importESModule( ); add_task(async function () { - const ln1 = new Geometry.Line( - new Geometry.Point({ coord_x: 0, coord_y: 0 }), - new Geometry.Point({ coord_x: 1, coord_y: 2 }) - ); - const ln2 = new Geometry.Line( - new Geometry.Point({ coord_x: 1, coord_y: 1 }), - new Geometry.Point({ coord_x: 2, coord_y: 2 }) - ); - const origin = new Geometry.Point({ coord_x: 0, coord_y: 0 }); - Assert.ok( - (await Geometry.intersection({ start: ln1, end: ln2 })).equals(origin) - ); - Assert.deepEqual( - await Geometry.intersection({ start: ln1, end: ln2 }), - origin - ); - Assert.strictEqual( - await Geometry.intersection({ start: ln1, end: ln1 }), - null - ); + const ln1 = new Geometry.Line({ + start: new Geometry.Point({ coordX: 0, coordY: 0 }), + end: new Geometry.Point({ coordX: 1, coordY: 2 }), + }); + const ln2 = new Geometry.Line({ + start: new Geometry.Point({ coordX: 1, coordY: 1 }), + end: new Geometry.Point({ coordX: 2, coordY: 2 }), + }); + const origin = new Geometry.Point({ coordX: 0, coordY: 0 }); + Assert.ok((await Geometry.intersection(ln1, ln2)).equals(origin)); + Assert.deepEqual(await Geometry.intersection(ln1, ln2), origin); + Assert.strictEqual(await Geometry.intersection(ln1, ln1), null); }); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_refcounts.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_refcounts.js new file mode 100644 index 0000000000..790d981104 --- /dev/null +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_refcounts.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { getSingleton, getJsRefcount } = ChromeUtils.importESModule( + "resource://gre/modules/RustRefcounts.sys.mjs" +); + +// Test refcounts when we call methods. +// +// Each method call requires that we clone the Arc pointer on the JS side, then pass it to Rust +// which will consumer the reference. Make sure we get this right + +function createObjectAndCallMethods() { + const obj = getSingleton(); + obj.method(); +} + +add_test(() => { + // Create an object that we'll keep around. If the ref count ends up being low, we don't want + // to reduce it below 0, since the Rust code may catch that and clamp it + const obj = getSingleton(); + createObjectAndCallMethods(); + Cu.forceGC(); + Cu.forceCC(); + do_test_pending(); + do_timeout(500, () => { + Assert.equal(getJsRefcount(), 1); + // Use `obj` to avoid unused warnings and try to ensure that JS doesn't destroy it early + obj.method(); + do_test_finished(); + run_next_test(); + }); +}); + +// Test refcounts when creating/destroying objects +function createAndDeleteObjects() { + [getSingleton(), getSingleton(), getSingleton()]; +} + +add_test(() => { + const obj = getSingleton(); + createAndDeleteObjects(); + Cu.forceGC(); + Cu.forceCC(); + do_timeout(500, () => { + Assert.equal(getJsRefcount(), 1); + obj.method(); + do_test_finished(); + run_next_test(); + }); +}); + +// As we implement more UniFFI features we should probably add refcount tests for it. +// Some features that should probably have tests: +// - Async methods +// - UniFFI builtin trait methods like 'to_string' +// - Rust trait objects diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_rondpoint.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_rondpoint.js index 8c673b2e92..4ad76074f9 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_rondpoint.js +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_rondpoint.js @@ -22,7 +22,12 @@ const { OptionneurDictionnaire, } = Rondpoint; add_task(async function () { - const dico = new Dictionnaire(Enumeration.DEUX, true, 0, 1235); + const dico = new Dictionnaire({ + un: Enumeration.DEUX, + deux: true, + petitNombre: 0, + grosNombre: 1235, + }); const copyDico = await copieDictionnaire(dico); Assert.deepEqual(dico, copyDico); @@ -127,13 +132,29 @@ add_task(async function () { ); await affirmAllerRetour( - [-1, 0, 1].map(n => new DictionnaireNombresSignes(n, n, n, n)), + [-1, 0, 1].map( + n => + new DictionnaireNombresSignes({ + petitNombre: n, + courtNombre: n, + nombreSimple: n, + grosNombre: n, + }) + ), rt.identiqueNombresSignes.bind(rt), (a, b) => Assert.deepEqual(a, b) ); await affirmAllerRetour( - [0, 1].map(n => new DictionnaireNombres(n, n, n, n)), + [0, 1].map( + n => + new DictionnaireNombres({ + petitNombre: n, + courtNombre: n, + nombreSimple: n, + grosNombre: n, + }) + ), rt.identiqueNombres.bind(rt), (a, b) => Assert.deepEqual(a, b) ); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_sprites.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_sprites.js index 3feb2fd34d..e1f29cd9c8 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_sprites.js +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_sprites.js @@ -9,20 +9,26 @@ add_task(async function () { Assert.ok(Sprites.Sprite); const sempty = await Sprites.Sprite.init(null); - Assert.deepEqual(await sempty.getPosition(), new Sprites.Point(0, 0)); + Assert.deepEqual( + await sempty.getPosition(), + new Sprites.Point({ x: 0, y: 0 }) + ); - const s = await Sprites.Sprite.init(new Sprites.Point(0, 1)); - Assert.deepEqual(await s.getPosition(), new Sprites.Point(0, 1)); + const s = await Sprites.Sprite.init(new Sprites.Point({ x: 0, y: 1 })); + Assert.deepEqual(await s.getPosition(), new Sprites.Point({ x: 0, y: 1 })); - s.moveTo(new Sprites.Point(1, 2)); - Assert.deepEqual(await s.getPosition(), new Sprites.Point(1, 2)); + s.moveTo(new Sprites.Point({ x: 1, y: 2 })); + Assert.deepEqual(await s.getPosition(), new Sprites.Point({ x: 1, y: 2 })); - s.moveBy(new Sprites.Vector(-4, 2)); - Assert.deepEqual(await s.getPosition(), new Sprites.Point(-3, 4)); + s.moveBy(new Sprites.Vector({ dx: -4, dy: 2 })); + Assert.deepEqual(await s.getPosition(), new Sprites.Point({ x: -3, y: 4 })); const srel = await Sprites.Sprite.newRelativeTo( - new Sprites.Point(0, 1), - new Sprites.Vector(1, 1.5) + new Sprites.Point({ x: 0, y: 1 }), + new Sprites.Vector({ dx: 1, dy: 1.5 }) + ); + Assert.deepEqual( + await srel.getPosition(), + new Sprites.Point({ x: 1, y: 2.5 }) ); - Assert.deepEqual(await srel.getPosition(), new Sprites.Point(1, 2.5)); }); diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_todolist.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_todolist.js index dac26d2be1..2cbd43304c 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_todolist.js +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_todolist.js @@ -6,7 +6,9 @@ const { TodoList, TodoEntry, getDefaultList, setDefaultList } = add_task(async function () { const todo = await TodoList.init(); - const entry = new TodoEntry("Write bindings for strings in records"); + const entry = new TodoEntry({ + text: "Write bindings for strings in records", + }); await todo.addItem("Write JS bindings"); Assert.equal(await todo.getLast(), "Write JS bindings"); @@ -30,9 +32,9 @@ add_task(async function () { "Test Ünicode hàndling without an entry can't believe I didn't test this at first 🤣" ); - const entry2 = new TodoEntry( - "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣" - ); + const entry2 = new TodoEntry({ + text: "Test Ünicode hàndling in an entry can't believe I didn't test this at first 🤣", + }); await todo.addEntry(entry2); Assert.equal( (await todo.getLastEntry()).text, diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_type_checking.js b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_type_checking.js index bfeb07c82b..7a5e04cea1 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_type_checking.js +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/test_type_checking.js @@ -42,6 +42,12 @@ add_task(async function testObjectPointers() { /Bad pointer type/, "getEntries() with wrong pointer type" ); + + await Assert.rejects( + TodoList.setDefaultList(1), // expecting an object + /Object is not a 'TodoList' instance/, + "attempting to lift the wrong object type" + ); }); add_task(async function testEnumTypeCheck() { @@ -68,18 +74,6 @@ add_task(async function testRecordTypeCheck() { UniFFITypeError, "gradient with non-Line object should throw" ); - - await Assert.rejects( - Geometry.gradient({ - start: { - coordX: 0.0, - coordY: 0.0, - }, - // missing the end field - }), - /ln.end/, // Ensure exception message includes the argument name - "gradient with Line object with missing end field should throw" - ); }); add_task(async function testOptionTypeCheck() { diff --git a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/xpcshell.toml b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/xpcshell.toml index 76814ff199..801e95382f 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/xpcshell.toml +++ b/toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell/xpcshell.toml @@ -2,18 +2,33 @@ ["test_arithmetic.js"] +# I think this can be re-enabled when we implement https://bugzilla.mozilla.org/show_bug.cgi?id=1888668 +lineno = "3" + ["test_callbacks.js"] +disabled = "Temporarily disabled until we can re-enable callback support" +lineno = "8" ["test_custom_types.js"] +lineno = "12" ["test_external_types.js"] +lineno = "15" ["test_geometry.js"] +lineno = "18" + +["test_refcounts.js"] +lineno = "21" ["test_rondpoint.js"] +lineno = "24" ["test_sprites.js"] +lineno = "27" ["test_todolist.js"] +lineno = "30" ["test_type_checking.js"] +lineno = "33" diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs index 685c3c2bf3..7b63e8f3af 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs @@ -136,31 +136,25 @@ pub impl FfiType { // Type for the Rust scaffolding code fn rust_type(&self) -> String { match self { - FfiType::UInt8 => "uint8_t", - FfiType::Int8 => "int8_t", - FfiType::UInt16 => "uint16_t", - FfiType::Int16 => "int16_t", - FfiType::UInt32 => "uint32_t", - FfiType::Int32 => "int32_t", - FfiType::UInt64 => "uint64_t", - FfiType::Int64 => "int64_t", - FfiType::Float32 => "float", - FfiType::Float64 => "double", - FfiType::RustBuffer(_) => "RustBuffer", - FfiType::RustArcPtr(_) => "void *", - FfiType::ForeignCallback => "ForeignCallback", + FfiType::UInt8 => "uint8_t".to_owned(), + FfiType::Int8 => "int8_t".to_owned(), + FfiType::UInt16 => "uint16_t".to_owned(), + FfiType::Int16 => "int16_t".to_owned(), + FfiType::UInt32 => "uint32_t".to_owned(), + FfiType::Int32 => "int32_t".to_owned(), + FfiType::UInt64 => "uint64_t".to_owned(), + FfiType::Int64 => "int64_t".to_owned(), + FfiType::Float32 => "float".to_owned(), + FfiType::Float64 => "double".to_owned(), + FfiType::RustBuffer(_) => "RustBuffer".to_owned(), + FfiType::RustArcPtr(_) => "void *".to_owned(), FfiType::ForeignBytes => unimplemented!("ForeignBytes not supported"), - FfiType::ForeignExecutorHandle => unimplemented!("ForeignExecutorHandle not supported"), - FfiType::ForeignExecutorCallback => { - unimplemented!("ForeignExecutorCallback not supported") - } - FfiType::RustFutureHandle - | FfiType::RustFutureContinuationCallback - | FfiType::RustFutureContinuationData => { - unimplemented!("Rust async functions not supported") - } + FfiType::Handle => "uint64_t".to_owned(), + FfiType::RustCallStatus => "RustCallStatus".to_owned(), + FfiType::Callback(name) | FfiType::Struct(name) => name.to_owned(), + FfiType::VoidPointer => "void *".to_owned(), + FfiType::Reference(_) => unimplemented!("References not supported"), } - .to_owned() } } diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs index efd7b42456..cd9af529a7 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/js.rs @@ -92,7 +92,8 @@ pub impl Literal { Literal::Enum(name, typ) => render_enum_literal(typ, name), Literal::EmptyMap => "{}".to_string(), Literal::EmptySequence => "[]".to_string(), - Literal::Null => "null".to_string(), + Literal::Some { inner } => inner.render(), + Literal::None => "null".to_string(), } } } @@ -258,7 +259,6 @@ pub impl Type { | Type::CallbackInterface { name, .. } => format!("Type{name}"), Type::Timestamp => "Timestamp".into(), Type::Duration => "Duration".into(), - Type::ForeignExecutor => "ForeignExecutor".into(), Type::Optional { inner_type } => format!("Optional{}", inner_type.canonical_name()), Type::Sequence { inner_type } => format!("Sequence{}", inner_type.canonical_name()), Type::Map { diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp index 5c4ed8c2f5..83aeae8086 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp @@ -37,7 +37,8 @@ extern "C" { {%- let pointer_type = ci.pointer_type(object) %} const static mozilla::uniffi::UniFFIPointerType {{ pointer_type }} { "{{ "{}::{}"|format(ci.namespace(), object.name()) }}"_ns, - {{ object.ffi_object_free().rust_name() }} + {{ object.ffi_object_clone().rust_name() }}, + {{ object.ffi_object_free().rust_name() }}, }; {%- endfor %} {%- endfor %} diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs index f7716ac6d8..cbcc256eb9 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Enum.sys.mjs @@ -16,7 +16,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { return {{ enum_.nm() }}.{{ variant.name().to_shouty_snake_case() }} {%- endfor %} default: - return new Error("Unknown {{ enum_.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant"); } } @@ -27,7 +27,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { return; } {%- endfor %} - return new Error("Unknown {{ enum_.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant"); } static computeSize(value) { @@ -72,7 +72,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { ); {%- endfor %} default: - return new Error("Unknown {{ enum_.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant"); } } @@ -86,7 +86,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { return; } {%- endfor %} - return new Error("Unknown {{ enum_.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant"); } static computeSize(value) { @@ -100,7 +100,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { return totalSize; } {%- endfor %} - return new Error("Unknown {{ enum_.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ enum_.nm() }} variant"); } static checkType(value) { diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs index b140d908da..c472f1a27d 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Error.sys.mjs @@ -46,7 +46,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { {%- endif %} {%- endfor %} default: - throw new Error("Unknown {{ error.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ error.nm() }} variant"); } } static computeSize(value) { @@ -60,7 +60,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { return totalSize; } {%- endfor %} - throw new Error("Unknown {{ error.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ error.nm() }} variant"); } static write(dataStream, value) { {%- for variant in error.variants() %} @@ -72,7 +72,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { return; } {%- endfor %} - throw new Error("Unknown {{ error.nm() }} variant"); + throw new UniFFITypeError("Unknown {{ error.nm() }} variant"); } static errorClass = {{ error.nm() }}; diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs index e03291089e..204bf752dd 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Object.sys.mjs @@ -51,7 +51,11 @@ export class {{ ffi_converter }} extends FfiConverter { } static lower(value) { - return value[uniffiObjectPtr]; + const ptr = value[uniffiObjectPtr]; + if (!(ptr instanceof UniFFIPointer)) { + throw new UniFFITypeError("Object is not a '{{ object.nm() }}' instance"); + } + return ptr; } static read(dataStream) { diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs index 2f54160b9e..638be5bee8 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/Record.sys.mjs @@ -51,7 +51,7 @@ export class {{ ffi_converter }} extends FfiConverterArrayBuffer { static checkType(value) { super.checkType(value); if (!(value instanceof {{ record.nm() }})) { - throw new TypeError(`Expected '{{ record.nm() }}', found '${typeof value}'`); + throw new UniFFITypeError(`Expected '{{ record.nm() }}', found '${typeof value}'`); } {%- for field in record.fields() %} try { |