зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1786673 - Additional UniFFI type checking r=markh,skhamis
- Implemented `checkType` on more UniFFI FFIConverters. - Updated the way we handle locating the errors. - The old system was that `checkType` inputted a `name` parameter. I think the idea was that parent types would calculate a name parameter for their children. However, this wasn't great because it meant we would need to build the strings up-front and throw them away in the vast majority of cases where there was no type error. - The new system is that we use the `UniFFITypeError` class, which has a `prependPath` method. This gets called by the parent type FFIConverter to basically do the same work, but it only needs to happen when there's actually an error. - I think the resulting error messages are pretty good. I got this when passing a list with garbage data to setLocalTabs: "TypeError: remoteTabs[0].title: undefined is not a string" - Added the `UniFFI.sys.mjs` module, which contains shared, non-generated, UniFFI JS code. This is prep-work for https://bugzilla.mozilla.org/show_bug.cgi?id=1804078. Differential Revision: https://phabricator.services.mozilla.com/D166479
This commit is contained in:
Родитель
4f4ad27c98
Коммит
bcea304dfa
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -232,12 +234,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -260,12 +263,13 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
class FfiConverterI64 extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
throw TypeError(`${name} exceeds the safe integer bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
@ -289,6 +293,13 @@ class FfiConverterI64 extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterI64");
|
||||
|
||||
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);
|
||||
|
@ -350,7 +361,14 @@ class TabsBridgedEngine {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTabsApiError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterI64.checkType("lastSync", lastSync);
|
||||
try {
|
||||
FfiConverterI64.checkType(lastSync)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("lastSync");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
8, // tabs:tabs_edc9_TabsBridgedEngine_set_last_sync
|
||||
FfiConverterTypeTabsBridgedEngine.lower(this),
|
||||
|
@ -400,7 +418,14 @@ class TabsBridgedEngine {
|
|||
const liftResult = (result) => FfiConverterString.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTabsApiError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("newSyncId", newSyncId);
|
||||
try {
|
||||
FfiConverterString.checkType(newSyncId)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("newSyncId");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
11, // tabs:tabs_edc9_TabsBridgedEngine_ensure_current_sync_id
|
||||
FfiConverterTypeTabsBridgedEngine.lower(this),
|
||||
|
@ -418,7 +443,14 @@ class TabsBridgedEngine {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTabsApiError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("clientData", clientData);
|
||||
try {
|
||||
FfiConverterString.checkType(clientData)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("clientData");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
12, // tabs:tabs_edc9_TabsBridgedEngine_prepare_for_sync
|
||||
FfiConverterTypeTabsBridgedEngine.lower(this),
|
||||
|
@ -452,7 +484,14 @@ class TabsBridgedEngine {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTabsApiError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterSequencestring.checkType("incomingEnvelopesAsJson", incomingEnvelopesAsJson);
|
||||
try {
|
||||
FfiConverterSequencestring.checkType(incomingEnvelopesAsJson)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("incomingEnvelopesAsJson");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
14, // tabs:tabs_edc9_TabsBridgedEngine_store_incoming
|
||||
FfiConverterTypeTabsBridgedEngine.lower(this),
|
||||
|
@ -486,8 +525,22 @@ class TabsBridgedEngine {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTabsApiError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterI64.checkType("newTimestamp", newTimestamp);
|
||||
FfiConverterSequenceTypeTabsGuid.checkType("uploadedIds", uploadedIds);
|
||||
try {
|
||||
FfiConverterI64.checkType(newTimestamp)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("newTimestamp");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequenceTypeTabsGuid.checkType(uploadedIds)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("uploadedIds");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
16, // tabs:tabs_edc9_TabsBridgedEngine_set_uploaded
|
||||
FfiConverterTypeTabsBridgedEngine.lower(this),
|
||||
|
@ -604,7 +657,14 @@ class TabsStore {
|
|||
const liftResult = (result) => FfiConverterTypeTabsStore.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("path", path);
|
||||
try {
|
||||
FfiConverterString.checkType(path)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("path");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
0, // tabs:tabs_edc9_TabsStore_new
|
||||
FfiConverterString.lower(path),
|
||||
|
@ -636,7 +696,14 @@ class TabsStore {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterSequenceTypeRemoteTabRecord.checkType("remoteTabs", remoteTabs);
|
||||
try {
|
||||
FfiConverterSequenceTypeRemoteTabRecord.checkType(remoteTabs)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("remoteTabs");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
2, // tabs:tabs_edc9_TabsStore_set_local_tabs
|
||||
FfiConverterTypeTabsStore.lower(this),
|
||||
|
@ -686,11 +753,46 @@ class TabsStore {
|
|||
const liftResult = (result) => FfiConverterString.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTabsApiError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("keyId", keyId);
|
||||
FfiConverterString.checkType("accessToken", accessToken);
|
||||
FfiConverterString.checkType("syncKey", syncKey);
|
||||
FfiConverterString.checkType("tokenserverUrl", tokenserverUrl);
|
||||
FfiConverterString.checkType("localId", localId);
|
||||
try {
|
||||
FfiConverterString.checkType(keyId)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("keyId");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterString.checkType(accessToken)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("accessToken");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterString.checkType(syncKey)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("syncKey");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterString.checkType(tokenserverUrl)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("tokenserverUrl");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterString.checkType(localId)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("localId");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
5, // tabs:tabs_edc9_TabsStore_sync
|
||||
FfiConverterTypeTabsStore.lower(this),
|
||||
|
@ -757,11 +859,46 @@ EXPORTED_SYMBOLS.push("FfiConverterTypeTabsStore");
|
|||
|
||||
class ClientRemoteTabs {
|
||||
constructor(clientId,clientName,deviceType,lastModified,remoteTabs) {
|
||||
FfiConverterString.checkType("clientId", clientId);
|
||||
FfiConverterString.checkType("clientName", clientName);
|
||||
FfiConverterTypeTabsDeviceType.checkType("deviceType", deviceType);
|
||||
FfiConverterI64.checkType("lastModified", lastModified);
|
||||
FfiConverterSequenceTypeRemoteTabRecord.checkType("remoteTabs", remoteTabs);
|
||||
try {
|
||||
FfiConverterString.checkType(clientId)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("clientId");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterString.checkType(clientName)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("clientName");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeTabsDeviceType.checkType(deviceType)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("deviceType");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterI64.checkType(lastModified)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("lastModified");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequenceTypeRemoteTabRecord.checkType(remoteTabs)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("remoteTabs");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.clientId = clientId;
|
||||
this.clientName = clientName;
|
||||
this.deviceType = deviceType;
|
||||
|
@ -779,16 +916,7 @@ class ClientRemoteTabs {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypeClientRemoteTabs 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;
|
||||
}
|
||||
class FfiConverterTypeClientRemoteTabs extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new ClientRemoteTabs(
|
||||
FfiConverterString.read(dataStream),
|
||||
|
@ -815,6 +943,50 @@ class FfiConverterTypeClientRemoteTabs extends FfiConverter {
|
|||
totalSize += FfiConverterSequenceTypeRemoteTabRecord.computeSize(value.remoteTabs);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterString.checkType(value.clientId);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".clientId");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterString.checkType(value.clientName);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".clientName");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeTabsDeviceType.checkType(value.deviceType);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".deviceType");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterI64.checkType(value.lastModified);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".lastModified");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequenceTypeRemoteTabRecord.checkType(value.remoteTabs);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".remoteTabs");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("ClientRemoteTabs");
|
||||
|
@ -824,10 +996,38 @@ EXPORTED_SYMBOLS.push("FfiConverterTypeClientRemoteTabs");
|
|||
|
||||
class RemoteTabRecord {
|
||||
constructor(title,urlHistory,icon,lastUsed) {
|
||||
FfiConverterString.checkType("title", title);
|
||||
FfiConverterSequencestring.checkType("urlHistory", urlHistory);
|
||||
FfiConverterOptionalstring.checkType("icon", icon);
|
||||
FfiConverterI64.checkType("lastUsed", lastUsed);
|
||||
try {
|
||||
FfiConverterString.checkType(title)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("title");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequencestring.checkType(urlHistory)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("urlHistory");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterOptionalstring.checkType(icon)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("icon");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterI64.checkType(lastUsed)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("lastUsed");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.title = title;
|
||||
this.urlHistory = urlHistory;
|
||||
this.icon = icon;
|
||||
|
@ -843,16 +1043,7 @@ class RemoteTabRecord {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypeRemoteTabRecord 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;
|
||||
}
|
||||
class FfiConverterTypeRemoteTabRecord extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new RemoteTabRecord(
|
||||
FfiConverterString.read(dataStream),
|
||||
|
@ -876,6 +1067,42 @@ class FfiConverterTypeRemoteTabRecord extends FfiConverter {
|
|||
totalSize += FfiConverterI64.computeSize(value.lastUsed);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterString.checkType(value.title);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".title");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequencestring.checkType(value.urlHistory);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".urlHistory");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterOptionalstring.checkType(value.icon);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".icon");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterI64.checkType(value.lastUsed);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".lastUsed");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("RemoteTabRecord");
|
||||
|
@ -944,6 +1171,12 @@ class FfiConverterTypeTabsDeviceType extends FfiConverterArrayBuffer {
|
|||
static computeSize(value) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Number.isInteger(value) || value < 1 || value > 6) {
|
||||
throw new UniFFITypeError(`${value} is not a valid value for TabsDeviceType`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("TabsDeviceType");
|
||||
|
@ -1062,9 +1295,9 @@ class FfiConverterTypeTabsApiError extends FfiConverterArrayBuffer {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterTypeTabsApiError");
|
||||
|
||||
class FfiConverterOptionalstring extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterString.checkType(name, value)
|
||||
FfiConverterString.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1125,6 +1358,22 @@ class FfiConverterSequencestring extends FfiConverterArrayBuffer {
|
|||
}
|
||||
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;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
@ -1155,6 +1404,22 @@ class FfiConverterSequenceTypeClientRemoteTabs extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new UniFFITypeError(`${value} is not an array`);
|
||||
}
|
||||
value.forEach((innerValue, idx) => {
|
||||
try {
|
||||
FfiConverterTypeClientRemoteTabs.checkType(innerValue);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${idx}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
@ -1185,6 +1450,22 @@ class FfiConverterSequenceTypeRemoteTabRecord extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new UniFFITypeError(`${value} is not an array`);
|
||||
}
|
||||
value.forEach((innerValue, idx) => {
|
||||
try {
|
||||
FfiConverterTypeRemoteTabRecord.checkType(innerValue);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${idx}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
@ -1215,6 +1496,22 @@ class FfiConverterSequenceTypeTabsGuid extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new UniFFITypeError(`${value} is not an array`);
|
||||
}
|
||||
value.forEach((innerValue, idx) => {
|
||||
try {
|
||||
FfiConverterTypeTabsGuid.checkType(innerValue);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${idx}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -192,12 +194,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,15 +223,16 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
class FfiConverterU64 extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
throw TypeError(`${name} exceeds the safe integer bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
|
||||
}
|
||||
if (value < 0) {
|
||||
throw TypeError(`${name} exceeds the U64 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the U64 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
@ -277,6 +281,13 @@ class FfiConverterBool extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterBool");
|
||||
|
||||
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);
|
||||
|
@ -361,8 +372,22 @@ function add(a,b) {
|
|||
const liftResult = (result) => FfiConverterU64.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeArithmeticError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterU64.checkType("a", a);
|
||||
FfiConverterU64.checkType("b", b);
|
||||
try {
|
||||
FfiConverterU64.checkType(a)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("a");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterU64.checkType(b)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("b");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
22, // arithmetic:arithmetic_906c_add
|
||||
FfiConverterU64.lower(a),
|
||||
|
@ -382,8 +407,22 @@ function sub(a,b) {
|
|||
const liftResult = (result) => FfiConverterU64.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeArithmeticError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterU64.checkType("a", a);
|
||||
FfiConverterU64.checkType("b", b);
|
||||
try {
|
||||
FfiConverterU64.checkType(a)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("a");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterU64.checkType(b)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("b");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
23, // arithmetic:arithmetic_906c_sub
|
||||
FfiConverterU64.lower(a),
|
||||
|
@ -403,8 +442,22 @@ function div(dividend,divisor) {
|
|||
const liftResult = (result) => FfiConverterU64.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterU64.checkType("dividend", dividend);
|
||||
FfiConverterU64.checkType("divisor", divisor);
|
||||
try {
|
||||
FfiConverterU64.checkType(dividend)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("dividend");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterU64.checkType(divisor)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("divisor");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
24, // arithmetic:arithmetic_906c_div
|
||||
FfiConverterU64.lower(dividend),
|
||||
|
@ -424,8 +477,22 @@ function equal(a,b) {
|
|||
const liftResult = (result) => FfiConverterBool.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterU64.checkType("a", a);
|
||||
FfiConverterU64.checkType("b", b);
|
||||
try {
|
||||
FfiConverterU64.checkType(a)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("a");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterU64.checkType(b)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("b");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
25, // arithmetic:arithmetic_906c_equal
|
||||
FfiConverterU64.lower(a),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -192,12 +194,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,12 +223,13 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
class FfiConverterI64 extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
throw TypeError(`${name} exceeds the safe integer bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
@ -249,6 +253,13 @@ class FfiConverterI64 extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterI64");
|
||||
|
||||
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);
|
||||
|
@ -278,8 +289,22 @@ EXPORTED_SYMBOLS.push("FfiConverterString");
|
|||
|
||||
class CustomTypesDemo {
|
||||
constructor(url,handle) {
|
||||
FfiConverterTypeUrl.checkType("url", url);
|
||||
FfiConverterTypeHandle.checkType("handle", handle);
|
||||
try {
|
||||
FfiConverterTypeUrl.checkType(url)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("url");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeHandle.checkType(handle)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("handle");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.url = url;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
@ -291,16 +316,7 @@ class CustomTypesDemo {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypeCustomTypesDemo 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;
|
||||
}
|
||||
class FfiConverterTypeCustomTypesDemo extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new CustomTypesDemo(
|
||||
FfiConverterTypeUrl.read(dataStream),
|
||||
|
@ -318,6 +334,26 @@ class FfiConverterTypeCustomTypesDemo extends FfiConverter {
|
|||
totalSize += FfiConverterTypeHandle.computeSize(value.handle);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterTypeUrl.checkType(value.url);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".url");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeHandle.checkType(value.handle);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".handle");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("CustomTypesDemo");
|
||||
|
@ -326,9 +362,9 @@ EXPORTED_SYMBOLS.push("CustomTypesDemo");
|
|||
EXPORTED_SYMBOLS.push("FfiConverterTypeCustomTypesDemo");
|
||||
|
||||
class FfiConverterOptionalTypeCustomTypesDemo extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypeCustomTypesDemo.checkType(name, value)
|
||||
FfiConverterTypeCustomTypesDemo.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,7 +462,14 @@ function getCustomTypesDemo(demo) {
|
|||
const liftResult = (result) => FfiConverterTypeCustomTypesDemo.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterOptionalTypeCustomTypesDemo.checkType("demo", demo);
|
||||
try {
|
||||
FfiConverterOptionalTypeCustomTypesDemo.checkType(demo)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("demo");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
109, // custom_types:custom_types_8ecd_get_custom_types_demo
|
||||
FfiConverterOptionalTypeCustomTypesDemo.lower(demo),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -192,12 +194,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +223,7 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
class FfiConverterF64 extends FfiConverter {
|
||||
static computeSize() {
|
||||
|
@ -243,6 +247,13 @@ class FfiConverterF64 extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterF64");
|
||||
|
||||
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);
|
||||
|
@ -271,9 +282,9 @@ class FfiConverterString extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterString");
|
||||
|
||||
class FfiConverterOptionalTypeLine extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypeLine.checkType(name, value)
|
||||
FfiConverterTypeLine.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,7 +344,14 @@ function gradient(value) {
|
|||
const liftResult = (result) => FfiConverterF64.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterOptionalTypeLine.checkType("value", value);
|
||||
try {
|
||||
FfiConverterOptionalTypeLine.checkType(value)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("value");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
110, // external_types:external_types_54cc_gradient
|
||||
FfiConverterOptionalTypeLine.lower(value),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -192,12 +194,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +223,7 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -418,13 +422,13 @@ class UniFFICallbackHandleMapEntry {
|
|||
}
|
||||
|
||||
class FfiConverterI32 extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < -2147483648 || value > 2147483647) {
|
||||
throw TypeError(`${name} exceeds the I32 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the I32 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
@ -448,6 +452,13 @@ class FfiConverterI32 extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterI32");
|
||||
|
||||
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);
|
||||
|
@ -526,6 +537,22 @@ class FfiConverterSequencei32 extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new UniFFITypeError(`${value} is not an array`);
|
||||
}
|
||||
value.forEach((innerValue, idx) => {
|
||||
try {
|
||||
FfiConverterI32.checkType(innerValue);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${idx}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
@ -563,8 +590,22 @@ function logEvenNumbers(logger,items) {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterCallbackInterfaceLogger.checkType("logger", logger);
|
||||
FfiConverterSequencei32.checkType("items", items);
|
||||
try {
|
||||
FfiConverterCallbackInterfaceLogger.checkType(logger)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("logger");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequencei32.checkType(items)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("items");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
107, // fixture_callbacks:fixture_callbacks_1107_log_even_numbers
|
||||
FfiConverterCallbackInterfaceLogger.lower(logger),
|
||||
|
@ -584,8 +625,22 @@ function logEvenNumbersMainThread(logger,items) {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterCallbackInterfaceLogger.checkType("logger", logger);
|
||||
FfiConverterSequencei32.checkType("items", items);
|
||||
try {
|
||||
FfiConverterCallbackInterfaceLogger.checkType(logger)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("logger");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterSequencei32.checkType(items)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("items");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callSync(
|
||||
108, // fixture_callbacks:fixture_callbacks_1107_log_even_numbers_main_thread
|
||||
FfiConverterCallbackInterfaceLogger.lower(logger),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -192,12 +194,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,6 +223,7 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
class FfiConverterF64 extends FfiConverter {
|
||||
static computeSize() {
|
||||
|
@ -243,6 +247,13 @@ class FfiConverterF64 extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterF64");
|
||||
|
||||
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);
|
||||
|
@ -272,8 +283,22 @@ EXPORTED_SYMBOLS.push("FfiConverterString");
|
|||
|
||||
class Line {
|
||||
constructor(start,end) {
|
||||
FfiConverterTypePoint.checkType("start", start);
|
||||
FfiConverterTypePoint.checkType("end", end);
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(start)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("start");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(end)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("end");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
@ -285,16 +310,7 @@ class Line {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypeLine 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;
|
||||
}
|
||||
class FfiConverterTypeLine extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new Line(
|
||||
FfiConverterTypePoint.read(dataStream),
|
||||
|
@ -312,6 +328,26 @@ class FfiConverterTypeLine extends FfiConverter {
|
|||
totalSize += FfiConverterTypePoint.computeSize(value.end);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(value.start);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".start");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(value.end);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".end");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Line");
|
||||
|
@ -321,8 +357,22 @@ EXPORTED_SYMBOLS.push("FfiConverterTypeLine");
|
|||
|
||||
class Point {
|
||||
constructor(coordX,coordY) {
|
||||
FfiConverterF64.checkType("coordX", coordX);
|
||||
FfiConverterF64.checkType("coordY", coordY);
|
||||
try {
|
||||
FfiConverterF64.checkType(coordX)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("coordX");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterF64.checkType(coordY)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("coordY");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.coordX = coordX;
|
||||
this.coordY = coordY;
|
||||
}
|
||||
|
@ -334,16 +384,7 @@ class Point {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypePoint 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;
|
||||
}
|
||||
class FfiConverterTypePoint extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new Point(
|
||||
FfiConverterF64.read(dataStream),
|
||||
|
@ -361,6 +402,26 @@ class FfiConverterTypePoint extends FfiConverter {
|
|||
totalSize += FfiConverterF64.computeSize(value.coordY);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterF64.checkType(value.coordX);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".coordX");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterF64.checkType(value.coordY);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".coordY");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Point");
|
||||
|
@ -369,9 +430,9 @@ EXPORTED_SYMBOLS.push("Point");
|
|||
EXPORTED_SYMBOLS.push("FfiConverterTypePoint");
|
||||
|
||||
class FfiConverterOptionalTypePoint extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypePoint.checkType(name, value)
|
||||
FfiConverterTypePoint.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,7 +476,14 @@ function gradient(ln) {
|
|||
const liftResult = (result) => FfiConverterF64.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeLine.checkType("ln", ln);
|
||||
try {
|
||||
FfiConverterTypeLine.checkType(ln)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("ln");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
20, // geometry:geometry_1cce_gradient
|
||||
FfiConverterTypeLine.lower(ln),
|
||||
|
@ -434,8 +502,22 @@ function intersection(ln1,ln2) {
|
|||
const liftResult = (result) => FfiConverterOptionalTypePoint.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeLine.checkType("ln1", ln1);
|
||||
FfiConverterTypeLine.checkType("ln2", ln2);
|
||||
try {
|
||||
FfiConverterTypeLine.checkType(ln1)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("ln1");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeLine.checkType(ln2)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("ln2");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
21, // geometry:geometry_1cce_intersection
|
||||
FfiConverterTypeLine.lower(ln1),
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -212,12 +214,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,6 +243,7 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
class FfiConverterF64 extends FfiConverter {
|
||||
static computeSize() {
|
||||
|
@ -263,6 +267,13 @@ class FfiConverterF64 extends FfiConverter {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterF64");
|
||||
|
||||
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);
|
||||
|
@ -313,7 +324,14 @@ class Sprite {
|
|||
const liftResult = (result) => FfiConverterTypeSprite.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterOptionalTypePoint.checkType("initialPosition", initialPosition);
|
||||
try {
|
||||
FfiConverterOptionalTypePoint.checkType(initialPosition)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("initialPosition");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
86, // sprites:sprites_accb_Sprite_new
|
||||
FfiConverterOptionalTypePoint.lower(initialPosition),
|
||||
|
@ -334,8 +352,22 @@ class Sprite {
|
|||
const liftResult = (result) => FfiConverterTypeSprite.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypePoint.checkType("reference", reference);
|
||||
FfiConverterTypeVector.checkType("direction", direction);
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(reference)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("reference");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeVector.checkType(direction)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("direction");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
87, // sprites:sprites_accb_Sprite_new_relative_to
|
||||
FfiConverterTypePoint.lower(reference),
|
||||
|
@ -368,7 +400,14 @@ class Sprite {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypePoint.checkType("position", position);
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(position)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("position");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
89, // sprites:sprites_accb_Sprite_move_to
|
||||
FfiConverterTypeSprite.lower(this),
|
||||
|
@ -386,7 +425,14 @@ class Sprite {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeVector.checkType("direction", direction);
|
||||
try {
|
||||
FfiConverterTypeVector.checkType(direction)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("direction");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
90, // sprites:sprites_accb_Sprite_move_by
|
||||
FfiConverterTypeSprite.lower(this),
|
||||
|
@ -433,8 +479,22 @@ EXPORTED_SYMBOLS.push("FfiConverterTypeSprite");
|
|||
|
||||
class Point {
|
||||
constructor(x,y) {
|
||||
FfiConverterF64.checkType("x", x);
|
||||
FfiConverterF64.checkType("y", y);
|
||||
try {
|
||||
FfiConverterF64.checkType(x)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("x");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterF64.checkType(y)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("y");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
@ -446,16 +506,7 @@ class Point {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypePoint 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;
|
||||
}
|
||||
class FfiConverterTypePoint extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new Point(
|
||||
FfiConverterF64.read(dataStream),
|
||||
|
@ -473,6 +524,26 @@ class FfiConverterTypePoint extends FfiConverter {
|
|||
totalSize += FfiConverterF64.computeSize(value.y);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterF64.checkType(value.x);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".x");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterF64.checkType(value.y);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".y");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Point");
|
||||
|
@ -482,8 +553,22 @@ EXPORTED_SYMBOLS.push("FfiConverterTypePoint");
|
|||
|
||||
class Vector {
|
||||
constructor(dx,dy) {
|
||||
FfiConverterF64.checkType("dx", dx);
|
||||
FfiConverterF64.checkType("dy", dy);
|
||||
try {
|
||||
FfiConverterF64.checkType(dx)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("dx");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterF64.checkType(dy)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("dy");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
}
|
||||
|
@ -495,16 +580,7 @@ class Vector {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypeVector 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;
|
||||
}
|
||||
class FfiConverterTypeVector extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new Vector(
|
||||
FfiConverterF64.read(dataStream),
|
||||
|
@ -522,6 +598,26 @@ class FfiConverterTypeVector extends FfiConverter {
|
|||
totalSize += FfiConverterF64.computeSize(value.dy);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterF64.checkType(value.dx);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".dx");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterF64.checkType(value.dy);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".dy");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Vector");
|
||||
|
@ -530,9 +626,9 @@ EXPORTED_SYMBOLS.push("Vector");
|
|||
EXPORTED_SYMBOLS.push("FfiConverterTypeVector");
|
||||
|
||||
class FfiConverterOptionalTypePoint extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypePoint.checkType(name, value)
|
||||
FfiConverterTypePoint.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -576,8 +672,22 @@ function translate(position,direction) {
|
|||
const liftResult = (result) => FfiConverterTypePoint.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypePoint.checkType("position", position);
|
||||
FfiConverterTypeVector.checkType("direction", direction);
|
||||
try {
|
||||
FfiConverterTypePoint.checkType(position)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("position");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
FfiConverterTypeVector.checkType(direction)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("direction");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
91, // sprites:sprites_accb_translate
|
||||
FfiConverterTypePoint.lower(position),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
@ -212,12 +214,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,8 +243,16 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
||||
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);
|
||||
|
@ -306,7 +317,14 @@ class TodoList {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("todo", todo);
|
||||
try {
|
||||
FfiConverterString.checkType(todo)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("todo");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
93, // todolist:todolist_aa33_TodoList_add_item
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
|
@ -324,7 +342,14 @@ class TodoList {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeTodoEntry.checkType("entry", entry);
|
||||
try {
|
||||
FfiConverterTypeTodoEntry.checkType(entry)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("entry");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
94, // todolist:todolist_aa33_TodoList_add_entry
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
|
@ -374,7 +399,14 @@ class TodoList {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterSequenceTypeTodoEntry.checkType("entries", entries);
|
||||
try {
|
||||
FfiConverterSequenceTypeTodoEntry.checkType(entries)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("entries");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
97, // todolist:todolist_aa33_TodoList_add_entries
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
|
@ -392,7 +424,14 @@ class TodoList {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterSequencestring.checkType("items", items);
|
||||
try {
|
||||
FfiConverterSequencestring.checkType(items)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("items");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
98, // todolist:todolist_aa33_TodoList_add_items
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
|
@ -458,7 +497,14 @@ class TodoList {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("todo", todo);
|
||||
try {
|
||||
FfiConverterString.checkType(todo)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("todo");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
102, // todolist:todolist_aa33_TodoList_clear_item
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
|
@ -521,7 +567,14 @@ EXPORTED_SYMBOLS.push("FfiConverterTypeTodoList");
|
|||
|
||||
class TodoEntry {
|
||||
constructor(text) {
|
||||
FfiConverterString.checkType("text", text);
|
||||
try {
|
||||
FfiConverterString.checkType(text)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("text");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.text = text;
|
||||
}
|
||||
equals(other) {
|
||||
|
@ -531,16 +584,7 @@ class TodoEntry {
|
|||
}
|
||||
}
|
||||
|
||||
class FfiConverterTypeTodoEntry 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;
|
||||
}
|
||||
class FfiConverterTypeTodoEntry extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new TodoEntry(
|
||||
FfiConverterString.read(dataStream)
|
||||
|
@ -555,6 +599,18 @@ class FfiConverterTypeTodoEntry extends FfiConverter {
|
|||
totalSize += FfiConverterString.computeSize(value.text);
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
try {
|
||||
FfiConverterString.checkType(value.text);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".text");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("TodoEntry");
|
||||
|
@ -692,9 +748,9 @@ class FfiConverterTypeTodoError extends FfiConverterArrayBuffer {
|
|||
EXPORTED_SYMBOLS.push("FfiConverterTypeTodoError");
|
||||
|
||||
class FfiConverterOptionalTypeTodoList extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypeTodoList.checkType(name, value)
|
||||
FfiConverterTypeTodoList.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -755,6 +811,22 @@ class FfiConverterSequencestring extends FfiConverterArrayBuffer {
|
|||
}
|
||||
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;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
@ -785,6 +857,22 @@ class FfiConverterSequenceTypeTodoEntry extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new UniFFITypeError(`${value} is not an array`);
|
||||
}
|
||||
value.forEach((innerValue, idx) => {
|
||||
try {
|
||||
FfiConverterTypeTodoEntry.checkType(innerValue);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${idx}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Export the FFIConverter object to make external types work.
|
||||
|
@ -815,7 +903,14 @@ function setDefaultList(list) {
|
|||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeTodoList.checkType("list", list);
|
||||
try {
|
||||
FfiConverterTypeTodoList.checkType(list)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("list");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
105, // todolist:todolist_aa33_set_default_list
|
||||
FfiConverterTypeTodoList.lower(list),
|
||||
|
@ -834,7 +929,14 @@ function createEntryWith(todo) {
|
|||
const liftResult = (result) => FfiConverterTypeTodoEntry.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("todo", todo);
|
||||
try {
|
||||
FfiConverterString.checkType(todo)
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("todo");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return UniFFIScaffolding.callAsync(
|
||||
106, // todolist:todolist_aa33_create_entry_with
|
||||
FfiConverterString.lower(todo),
|
||||
|
|
|
@ -6,40 +6,115 @@ const Arithmetic = ChromeUtils.import(
|
|||
);
|
||||
const Geometry = ChromeUtils.import("resource://gre/modules/RustGeometry.jsm");
|
||||
|
||||
const { TodoList } = ChromeUtils.import(
|
||||
"resource://gre/modules/RustTodolist.jsm"
|
||||
);
|
||||
const { Stringifier } = ChromeUtils.import(
|
||||
const TodoList = ChromeUtils.import("resource://gre/modules/RustTodolist.jsm");
|
||||
const Rondpoint = ChromeUtils.import(
|
||||
"resource://gre/modules/RustRondpoint.jsm"
|
||||
);
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/UniFFI.sys.mjs"
|
||||
);
|
||||
|
||||
add_task(async function() {
|
||||
// Test our "type checking", which at this point is checking that
|
||||
// the correct number of arguments are passed and that pointer
|
||||
// arguments are of the correct type.
|
||||
|
||||
add_task(async function testFunctionArguments() {
|
||||
await Assert.rejects(
|
||||
Arithmetic.add(2),
|
||||
/TypeError/,
|
||||
UniFFITypeError,
|
||||
"add() call missing argument"
|
||||
);
|
||||
Assert.throws(
|
||||
() => Geometry.Point(0.0),
|
||||
/TypeError/,
|
||||
() => new Geometry.Point(0.0),
|
||||
UniFFITypeError,
|
||||
"Point constructor missing argument"
|
||||
);
|
||||
|
||||
const todo = await TodoList.init();
|
||||
const stringifier = await Stringifier.init();
|
||||
await todo.getEntries(); // OK
|
||||
todo.ptr = stringifier.ptr;
|
||||
|
||||
try {
|
||||
await todo.getEntries(); // the pointer is incorrect, should throw
|
||||
Assert.fail("Should have thrown the pointer was an incorrect pointer");
|
||||
} catch (e) {
|
||||
// OK
|
||||
// For some reason Assert.throws() can't seem to catch the "TypeError"s thrown
|
||||
// from C++
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function testObjectPointers() {
|
||||
const todo = await TodoList.TodoList.init();
|
||||
const stringifier = await Rondpoint.Stringifier.init();
|
||||
await todo.getEntries(); // OK
|
||||
todo[TodoList.UnitTestObjs.uniffiObjectPtr] =
|
||||
stringifier[Rondpoint.UnitTestObjs.uniffiObjectPtr];
|
||||
|
||||
await Assert.rejects(
|
||||
todo.getEntries(), // the pointer is incorrect, should throw
|
||||
/Bad pointer type/,
|
||||
"getEntries() with wrong pointer type"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function testEnumTypeCheck() {
|
||||
await Assert.rejects(
|
||||
Rondpoint.copieEnumeration("invalid"), // Not an integer value
|
||||
/e:/, // Ensure exception message includes the argument name
|
||||
"copieEnumeration() with non-Enumeration value should throw"
|
||||
);
|
||||
await Assert.rejects(
|
||||
Rondpoint.copieEnumeration(0), // Integer, but doesn't map to a variant
|
||||
/e:/, // Ensure exception message includes the argument name
|
||||
"copieEnumeration() with non-Enumeration value should throw"
|
||||
);
|
||||
await Assert.rejects(
|
||||
Rondpoint.copieEnumeration(4), // Integer, but doesn't map to a variant
|
||||
/e:/, // Ensure exception message includes the argument name
|
||||
"copieEnumeration() with non-Enumeration value should throw"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function testRecordTypeCheck() {
|
||||
await Assert.rejects(
|
||||
Geometry.gradient(123), // Not a Line object
|
||||
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() {
|
||||
const optionneur = await Rondpoint.Optionneur.init();
|
||||
await Assert.rejects(
|
||||
optionneur.sinonNull(0),
|
||||
UniFFITypeError,
|
||||
"sinonNull with non-string should throw"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function testSequenceTypeCheck() {
|
||||
const todo = await TodoList.TodoList.init();
|
||||
await Assert.rejects(
|
||||
todo.addEntries("not a list"),
|
||||
UniFFITypeError,
|
||||
"addEntries with non-list should throw"
|
||||
);
|
||||
|
||||
await Assert.rejects(
|
||||
todo.addEntries(["not TodoEntry"]),
|
||||
/entries\[0]/,
|
||||
"addEntries with non TodoEntry item should throw"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function testMapTypeCheck() {
|
||||
await Assert.rejects(
|
||||
Rondpoint.copieCarte("not a map"),
|
||||
UniFFITypeError,
|
||||
"copieCarte with a non-map should throw"
|
||||
);
|
||||
|
||||
await Assert.rejects(
|
||||
Rondpoint.copieCarte({ x: 1 }),
|
||||
/c\[x]/,
|
||||
"copieCarte with a wrong value type should throw"
|
||||
);
|
||||
|
||||
// TODO: test key types once we implement https://bugzilla.mozilla.org/show_bug.cgi?id=1809459
|
||||
});
|
||||
|
|
|
@ -172,15 +172,6 @@ pub impl Field {
|
|||
fn ffi_converter(&self) -> String {
|
||||
self.type_().ffi_converter()
|
||||
}
|
||||
|
||||
fn check_type(&self) -> String {
|
||||
format!(
|
||||
"{}.checkType(\"{}\", {})",
|
||||
self.type_().ffi_converter(),
|
||||
self.nm(),
|
||||
self.nm()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[ext(name=ArgumentJSExt)]
|
||||
|
@ -212,15 +203,6 @@ pub impl Argument {
|
|||
fn ffi_converter(&self) -> String {
|
||||
self.type_().ffi_converter()
|
||||
}
|
||||
|
||||
fn check_type(&self) -> String {
|
||||
format!(
|
||||
"{}.checkType(\"{}\", {})",
|
||||
self.type_().ffi_converter(),
|
||||
self.nm(),
|
||||
self.nm()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[ext(name=TypeJSExt)]
|
||||
|
|
|
@ -34,6 +34,12 @@ class {{ ffi_converter }} extends FfiConverterArrayBuffer {
|
|||
static computeSize(value) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Number.isInteger(value) || value < 1 || value > {{ enum_.variants().len() }}) {
|
||||
throw new UniFFITypeError(`${value} is not a valid value for {{ enum_.nm() }}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{%- else -%}
|
||||
|
@ -96,6 +102,12 @@ class {{ ffi_converter }} extends FfiConverterArrayBuffer {
|
|||
{%- endfor %}
|
||||
return new Error("Unknown {{ enum_.nm() }} variant");
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!(value instanceof {{ enum_.nm() }})) {
|
||||
throw new UniFFITypeError(`${value} is not a subclass instance of {{ enum_.nm() }}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{%- endif %}
|
||||
|
|
|
@ -202,12 +202,13 @@ class UniFFIInternalError extends UniFFIError {}
|
|||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
// throw `UniFFITypeError` if a value to be converted has an invalid type
|
||||
static checkType(value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
throw new UniFFITypeError(`undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is null`);
|
||||
throw new UniFFITypeError(`null`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,3 +231,4 @@ class FfiConverterArrayBuffer extends FfiConverter {
|
|||
// can only be used with a proper UniFFI pointer
|
||||
const uniffiObjectPtr = Symbol("uniffiObjectPtr");
|
||||
const constructUniffiObject = Symbol("constructUniffiObject");
|
||||
UnitTestObjs.uniffiObjectPtr = uniffiObjectPtr;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < -32768 || value > 32767) {
|
||||
throw TypeError(`${name} exceeds the I16 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the I16 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < -2147483648 || value > 2147483647) {
|
||||
throw TypeError(`${name} exceeds the I32 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the I32 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
throw TypeError(`${name} exceeds the safe integer bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < -128 || value > 127) {
|
||||
throw TypeError(`${name} exceeds the I8 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the I8 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -28,5 +28,27 @@ class {{ ffi_converter }} extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
for (const key in value) {
|
||||
try {
|
||||
{{ key_type.ffi_converter() }}.checkType(key);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("(key)");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
{{ value_type.ffi_converter() }}.checkType(value[key]);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${key}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class {{ ffi_converter }} extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
static checkType(value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
{{ inner.ffi_converter() }}.checkType(name, value)
|
||||
{{ inner.ffi_converter() }}.checkType(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
class {{ record.nm() }} {
|
||||
constructor({{ record.constructor_field_list() }}) {
|
||||
{%- for field in record.fields() %}
|
||||
{{ field.check_type() }};
|
||||
try {
|
||||
{{ field.ffi_converter() }}.checkType({{ field.nm() }})
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("{{ field.nm() }}");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
{%- endfor %}
|
||||
|
||||
{%- for field in record.fields() %}
|
||||
|
@ -18,16 +25,7 @@ class {{ record.nm() }} {
|
|||
}
|
||||
}
|
||||
|
||||
class {{ ffi_converter }} 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;
|
||||
}
|
||||
class {{ ffi_converter }} extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
return new {{record.nm()}}(
|
||||
{%- for field in record.fields() %}
|
||||
|
@ -49,6 +47,20 @@ class {{ ffi_converter }} extends FfiConverter {
|
|||
{%- endfor %}
|
||||
return totalSize
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
{%- for field in record.fields() %}
|
||||
try {
|
||||
{{ field.ffi_converter() }}.checkType(value.{{ field.nm() }});
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(".{{ field.nm() }}");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
{%- endfor %}
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("{{ record.nm() }}");
|
||||
|
|
|
@ -23,5 +23,21 @@ class {{ ffi_converter }} extends FfiConverterArrayBuffer {
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static checkType(value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new UniFFITypeError(`${value} is not an array`);
|
||||
}
|
||||
value.forEach((innerValue, idx) => {
|
||||
try {
|
||||
{{ inner.ffi_converter() }}.checkType(innerValue);
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart(`[${idx}]`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
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);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < 0 || value > 65535) {
|
||||
throw TypeError(`${name} exceeds the U16 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the U16 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < 0 || value > 4294967295) {
|
||||
throw TypeError(`${name} exceeds the U32 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the U32 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
throw TypeError(`${name} exceeds the safe integer bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the safe integer bounds`);
|
||||
}
|
||||
if (value < 0) {
|
||||
throw TypeError(`${name} exceeds the U64 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the U64 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class {{ ffi_converter }} extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
static checkType(value) {
|
||||
super.checkType(value);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw TypeError(`${name} is not an integer(${value})`);
|
||||
throw new UniFFITypeError(`${value} is not an integer`);
|
||||
}
|
||||
if (value < 0 || value > 256) {
|
||||
throw TypeError(`${name} exceeds the U8 bounds (${value})`);
|
||||
throw new UniFFITypeError(`${value} exceeds the U8 bounds`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
|
|
|
@ -25,7 +25,14 @@
|
|||
{%- endmatch %}
|
||||
const functionCall = () => {
|
||||
{%- for arg in func.arguments() %}
|
||||
{{ arg.check_type() }};
|
||||
try {
|
||||
{{ arg.ffi_converter() }}.checkType({{ arg.nm() }})
|
||||
} catch (e) {
|
||||
if (e instanceof UniFFITypeError) {
|
||||
e.addItemDescriptionPart("{{ arg.nm() }}");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
{%- endfor %}
|
||||
|
||||
{%- if is_async %}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
const { UniFFITypeError } = ChromeUtils.importESModule("resource://gre/modules/UniFFI.sys.mjs");
|
||||
|
||||
{% import "macros.jsm" as js %}
|
||||
|
||||
"use strict";
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// This JS module contains shared functionality for the generated UniFFI JS
|
||||
// code.
|
||||
|
||||
// TypeError for UniFFI calls
|
||||
//
|
||||
// This extends TypeError to add support for recording a nice description of
|
||||
// the item that fails the type check. This is especially useful for invalid
|
||||
// values nested in objects/arrays/maps, etc.
|
||||
//
|
||||
// To accomplish this, the FfiConverter.checkType methods of records, arrays,
|
||||
// maps, etc. catch UniFFITypeError, call `addItemDescriptionPart()` with a
|
||||
// string representing the child item, then re-raise the exception. We then
|
||||
// join all the parts together, in reverse order, to create item description
|
||||
// strings like `foo.bar[123]["key"]`
|
||||
export class UniFFITypeError extends TypeError {
|
||||
constructor(reason) {
|
||||
super();
|
||||
this.reason = reason;
|
||||
this.itemDescriptionParts = [];
|
||||
}
|
||||
|
||||
addItemDescriptionPart(part) {
|
||||
this.itemDescriptionParts.push(part);
|
||||
}
|
||||
|
||||
itemDescription() {
|
||||
const itemDescriptionParts = [...this.itemDescriptionParts];
|
||||
itemDescriptionParts.reverse();
|
||||
return itemDescriptionParts.join("");
|
||||
}
|
||||
|
||||
get message() {
|
||||
return `${this.itemDescription()}: ${this.reason}`;
|
||||
}
|
||||
}
|
|
@ -30,3 +30,7 @@ EXPORTS.mozilla.dom += [
|
|||
"UniFFIRust.h",
|
||||
"UniFFIScaffolding.h",
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES += [
|
||||
"js/UniFFI.sys.mjs",
|
||||
]
|
||||
|
|
Загрузка…
Ссылка в новой задаче