зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1766045 - Adding mach command to generate UniFFI files r=glandium
Added `mach uniffi generate` which executes `uniffi-bindgen-gecko-js` to generate UniFFI bindings. It's unfortunate that we need to check these files in, but I couldn't figure out a way to auto-generate them as part of the build process. Adding `#include "nsIContent.h"` to dom/base/nsINodeList.h. I think that should have been present before, but things built okay because of the way things got combined in the uniffied .cpp files. Adding these new webIDL files bumped `NodeListBinding.cpp` to a new uniffied .cpp file which caused the build to fail. Differential Revision: https://phabricator.services.mozilla.com/D144468
This commit is contained in:
Родитель
760c603bcb
Коммит
86a582c07a
|
@ -363,6 +363,9 @@ def initialize(topsrcdir):
|
|||
),
|
||||
"esmify": MachCommandReference("tools/esmify/mach_commands.py"),
|
||||
"xpcshell": MachCommandReference("js/xpconnect/mach_commands.py"),
|
||||
"uniffi": MachCommandReference(
|
||||
"toolkit/components/uniffi-bindgen-gecko-js/mach_commands.py"
|
||||
),
|
||||
}
|
||||
|
||||
# Set a reasonable limit to the number of open files.
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIContent.h"
|
||||
|
||||
// IID for the nsINodeList interface
|
||||
#define NS_INODELIST_IID \
|
||||
|
|
|
@ -143,3 +143,6 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
|
|||
EXPORTS.mozilla += [
|
||||
"!regex_ffi_generated.h",
|
||||
]
|
||||
|
||||
if CONFIG["MOZ_UNIFFI_FIXTURES"]:
|
||||
DIRS += ["uniffi-bindgen-gecko-js/fixtures"]
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
This directory contains generated code for the UniFFI examples/fixtures and JS
|
||||
unit tests for it.
|
||||
|
||||
This is only built if the `--enable-uniffi-fixtures` flag is present in
|
||||
`mozconfig`. There's no benefit to including this in a release build.
|
||||
|
||||
To add additional examples/fixtures:
|
||||
- For most of these steps, find the code for existing fixtures and use it as a template for the new code.
|
||||
- Edit `toolkit/components/uniffi-bindgen-gecko-js/mach_commands.py`
|
||||
- Add an entry to `FIXTURE_UDL_FILES`
|
||||
- Edit `toolkit/library/rust/shared/Cargo.toml`
|
||||
- Add an optional dependency for the fixture.
|
||||
- Add the feature to the list of features enabled by `uniffi_fixtures`.
|
||||
- Edit `toolkit/library/rust/shared/lib.rs`:
|
||||
- Add an `extern crate [name]` to the `uniffi_fixtures` mod
|
||||
- Note: [name] is the name from the `[lib]` section in the Cargo.toml
|
||||
for the example/fixture crate. This does not always match the package
|
||||
name for the crate.
|
||||
- Add `[name]::reexport_uniffi_scaffolding` to the `uniffi_fixtures` mod
|
||||
- Edit `toolkit/components/uniffi-bindgen-gecko-js/fixtures/moz.build` and add the fixture name to the `components`
|
||||
list.
|
||||
- Add a test module to the `toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/` directory and an entry for it
|
||||
in `toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/xpcshell.ini`
|
||||
- Run `mach vendor rust` to vendor in the Rust code.
|
||||
- Run `mach uniffi generate` to generate the scaffolding code.
|
||||
- Check in any new files
|
||||
|
||||
To run the tests:
|
||||
- Make sure you have a `mozconfig` file containing the line `ac_add_options --enable-uniffi-fixtures`
|
||||
- Run `mach uniffi generate` if:
|
||||
- You've added or updated a fixture
|
||||
- You've made changes to `uniffi-bindgen-gecko-js`
|
||||
- Run `mach build`
|
||||
- Run `mach xpcshell-test toolkit/components/uniffi-bindgen-gecko-js/fixtures/tests/`
|
||||
- You can also use a path to specific test file
|
||||
- For subsequent runs, if you only modify the test files, then you can re-run this step directly
|
|
@ -0,0 +1,401 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = [];
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class UniFFIInternalError extends UniFFIError {}
|
||||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is 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");
|
||||
|
||||
class FfiConverterU64 extends FfiConverter {
|
||||
static checkType(name, value) {
|
||||
super.checkType(name, value);
|
||||
if (!Number.isSafeInteger(value)) {
|
||||
throw TypeError(`${name} exceeds the safe integer bounds (${value})`);
|
||||
}
|
||||
if (value < 0) {
|
||||
throw TypeError(`${name} exceeds the U64 bounds (${value})`);
|
||||
}
|
||||
}
|
||||
static computeSize() {
|
||||
return 8;
|
||||
}
|
||||
static lift(value) {
|
||||
return value;
|
||||
}
|
||||
static lower(value) {
|
||||
return value;
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
dataStream.writeUint64(value)
|
||||
}
|
||||
static read(dataStream) {
|
||||
return dataStream.readUint64()
|
||||
}
|
||||
}class FfiConverterBool extends FfiConverter {
|
||||
static computeSize() {
|
||||
return 1;
|
||||
}
|
||||
static lift(value) {
|
||||
return value == 1;
|
||||
}
|
||||
static lower(value) {
|
||||
if (value) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
dataStream.writeUint8(this.lower(value))
|
||||
}
|
||||
static read(dataStream) {
|
||||
return this.lift(dataStream.readUint8())
|
||||
}
|
||||
}
|
||||
|
||||
class FfiConverterString extends FfiConverter {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ArithmeticError extends Error {}
|
||||
EXPORTED_SYMBOLS.push("ArithmeticError");
|
||||
|
||||
|
||||
class IntegerOverflow extends ArithmeticError {
|
||||
|
||||
constructor(message, ...params) {
|
||||
super(...params);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
EXPORTED_SYMBOLS.push("IntegerOverflow");
|
||||
|
||||
class FfiConverterTypeArithmeticError extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
switch (dataStream.readInt32()) {
|
||||
case 1:
|
||||
return new IntegerOverflow(FfiConverterString.read(dataStream));
|
||||
default:
|
||||
return new Error("Unknown ArithmeticError variant");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
2, // arithmetic:arithmetic_77d6_add
|
||||
FfiConverterU64.lower(a),
|
||||
FfiConverterU64.lower(b),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("add");
|
||||
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);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
3, // arithmetic:arithmetic_77d6_sub
|
||||
FfiConverterU64.lower(a),
|
||||
FfiConverterU64.lower(b),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("sub");
|
||||
function div(dividend,divisor) {
|
||||
|
||||
const liftResult = (result) => FfiConverterU64.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterU64.checkType("dividend", dividend);
|
||||
FfiConverterU64.checkType("divisor", divisor);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
4, // arithmetic:arithmetic_77d6_div
|
||||
FfiConverterU64.lower(dividend),
|
||||
FfiConverterU64.lower(divisor),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("div");
|
||||
function equal(a,b) {
|
||||
|
||||
const liftResult = (result) => FfiConverterBool.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterU64.checkType("a", a);
|
||||
FfiConverterU64.checkType("b", b);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
5, // arithmetic:arithmetic_77d6_equal
|
||||
FfiConverterU64.lower(a),
|
||||
FfiConverterU64.lower(b),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("equal");
|
|
@ -0,0 +1,427 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = [];
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class UniFFIInternalError extends UniFFIError {}
|
||||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is 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");
|
||||
|
||||
class FfiConverterF64 extends FfiConverter {
|
||||
static computeSize() {
|
||||
return 8;
|
||||
}
|
||||
static lift(value) {
|
||||
return value;
|
||||
}
|
||||
static lower(value) {
|
||||
return value;
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
dataStream.writeFloat64(value)
|
||||
}
|
||||
static read(dataStream) {
|
||||
return dataStream.readFloat64()
|
||||
}
|
||||
}
|
||||
|
||||
class FfiConverterString extends FfiConverter {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
class Line {
|
||||
constructor(start,end) {
|
||||
FfiConverterTypePoint.checkType("start", start);
|
||||
FfiConverterTypePoint.checkType("end", end);
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
equals(other) {
|
||||
return (
|
||||
this.start.equals(other.start) &&
|
||||
this.end.equals(other.end)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
static read(dataStream) {
|
||||
return new Line(
|
||||
FfiConverterTypePoint.read(dataStream),
|
||||
FfiConverterTypePoint.read(dataStream)
|
||||
);
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
FfiConverterTypePoint.write(dataStream, value.start);
|
||||
FfiConverterTypePoint.write(dataStream, value.end);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
let totalSize = 0;
|
||||
totalSize += FfiConverterTypePoint.computeSize(value.start);
|
||||
totalSize += FfiConverterTypePoint.computeSize(value.end);
|
||||
return totalSize
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Line");
|
||||
|
||||
class Point {
|
||||
constructor(coordX,coordY) {
|
||||
FfiConverterF64.checkType("coordX", coordX);
|
||||
FfiConverterF64.checkType("coordY", coordY);
|
||||
this.coordX = coordX;
|
||||
this.coordY = coordY;
|
||||
}
|
||||
equals(other) {
|
||||
return (
|
||||
this.coordX == other.coordX &&
|
||||
this.coordY == other.coordY
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
static read(dataStream) {
|
||||
return new Point(
|
||||
FfiConverterF64.read(dataStream),
|
||||
FfiConverterF64.read(dataStream)
|
||||
);
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
FfiConverterF64.write(dataStream, value.coordX);
|
||||
FfiConverterF64.write(dataStream, value.coordY);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
let totalSize = 0;
|
||||
totalSize += FfiConverterF64.computeSize(value.coordX);
|
||||
totalSize += FfiConverterF64.computeSize(value.coordY);
|
||||
return totalSize
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Point");class FfiConverterOptionalTypePoint extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypePoint.checkType(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
static read(dataStream) {
|
||||
const code = dataStream.readUint8(0);
|
||||
switch (code) {
|
||||
case 0:
|
||||
return null
|
||||
case 1:
|
||||
return FfiConverterTypePoint.read(dataStream)
|
||||
default:
|
||||
throw UniFFIError(`Unexpected code: ${code}`);
|
||||
}
|
||||
}
|
||||
|
||||
static write(dataStream, value) {
|
||||
if (value === null || value === undefined) {
|
||||
dataStream.writeUint8(0);
|
||||
return;
|
||||
}
|
||||
dataStream.writeUint8(1);
|
||||
FfiConverterTypePoint.write(dataStream, value)
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
if (value === null || value === undefined) {
|
||||
return 1;
|
||||
}
|
||||
return 1 + FfiConverterTypePoint.computeSize(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function gradient(ln) {
|
||||
|
||||
const liftResult = (result) => FfiConverterF64.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeLine.checkType("ln", ln);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
0, // geometry:geometry_ba8c_gradient
|
||||
FfiConverterTypeLine.lower(ln),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("gradient");
|
||||
function intersection(ln1,ln2) {
|
||||
|
||||
const liftResult = (result) => FfiConverterOptionalTypePoint.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeLine.checkType("ln1", ln1);
|
||||
FfiConverterTypeLine.checkType("ln2", ln2);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
1, // geometry:geometry_ba8c_intersection
|
||||
FfiConverterTypeLine.lower(ln1),
|
||||
FfiConverterTypeLine.lower(ln2),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("intersection");
|
|
@ -0,0 +1 @@
|
|||
This directory is where files generated by Uniffi will be created.
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,561 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = [];
|
||||
|
||||
// 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 Sprite pointer from the data stream
|
||||
// UniFFI Pointers are **always** 8 bytes long. That is enforced
|
||||
// by the C++ and Rust Scaffolding code.
|
||||
readPointerSprite() {
|
||||
const pointerId = 3; // sprites:Sprite
|
||||
const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos);
|
||||
this.pos += 8;
|
||||
return res;
|
||||
}
|
||||
|
||||
// Writes a Sprite pointer into the data stream
|
||||
// UniFFI Pointers are **always** 8 bytes long. That is enforced
|
||||
// by the C++ and Rust Scaffolding code.
|
||||
writePointerSprite(value) {
|
||||
const pointerId = 3; // sprites:Sprite
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class UniFFIInternalError extends UniFFIError {}
|
||||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is 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");
|
||||
|
||||
class FfiConverterF64 extends FfiConverter {
|
||||
static computeSize() {
|
||||
return 8;
|
||||
}
|
||||
static lift(value) {
|
||||
return value;
|
||||
}
|
||||
static lower(value) {
|
||||
return value;
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
dataStream.writeFloat64(value)
|
||||
}
|
||||
static read(dataStream) {
|
||||
return dataStream.readFloat64()
|
||||
}
|
||||
}
|
||||
|
||||
class FfiConverterString extends FfiConverter {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Sprite {
|
||||
// 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 Sprite.
|
||||
*
|
||||
* @returns {Promise<Sprite>}: A promise that resolves
|
||||
* to a newly constructed Sprite
|
||||
*/
|
||||
static init(initialPosition) {
|
||||
const liftResult = (result) => FfiConverterTypeSprite.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterOptionalTypePoint.checkType("initialPosition", initialPosition);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
66, // sprites:sprites_f59e_Sprite_new
|
||||
FfiConverterOptionalTypePoint.lower(initialPosition),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
/**
|
||||
* An async constructor for Sprite.
|
||||
*
|
||||
* @returns {Promise<Sprite>}: A promise that resolves
|
||||
* to a newly constructed Sprite
|
||||
*/
|
||||
static newRelativeTo(reference,direction) {
|
||||
const liftResult = (result) => FfiConverterTypeSprite.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypePoint.checkType("reference", reference);
|
||||
FfiConverterTypeVector.checkType("direction", direction);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
67, // sprites:sprites_f59e_Sprite_new_relative_to
|
||||
FfiConverterTypePoint.lower(reference),
|
||||
FfiConverterTypeVector.lower(direction),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
getPosition() {
|
||||
const liftResult = (result) => FfiConverterTypePoint.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
68, // sprites:sprites_f59e_Sprite_get_position
|
||||
FfiConverterTypeSprite.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
moveTo(position) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypePoint.checkType("position", position);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
69, // sprites:sprites_f59e_Sprite_move_to
|
||||
FfiConverterTypeSprite.lower(this),
|
||||
FfiConverterTypePoint.lower(position),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
moveBy(direction) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeVector.checkType("direction", direction);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
70, // sprites:sprites_f59e_Sprite_move_by
|
||||
FfiConverterTypeSprite.lower(this),
|
||||
FfiConverterTypeVector.lower(direction),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
class FfiConverterTypeSprite extends FfiConverter {
|
||||
static lift(value) {
|
||||
const opts = {};
|
||||
opts[constructUniffiObject] = value;
|
||||
return new Sprite(opts);
|
||||
}
|
||||
|
||||
static lower(value) {
|
||||
return value[uniffiObjectPtr];
|
||||
}
|
||||
|
||||
static read(dataStream) {
|
||||
return this.lift(dataStream.readPointerSprite());
|
||||
}
|
||||
|
||||
static write(dataStream, value) {
|
||||
dataStream.writePointerSprite(value[uniffiObjectPtr]);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Sprite");
|
||||
|
||||
class Point {
|
||||
constructor(x,y) {
|
||||
FfiConverterF64.checkType("x", x);
|
||||
FfiConverterF64.checkType("y", y);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
equals(other) {
|
||||
return (
|
||||
this.x == other.x &&
|
||||
this.y == other.y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
static read(dataStream) {
|
||||
return new Point(
|
||||
FfiConverterF64.read(dataStream),
|
||||
FfiConverterF64.read(dataStream)
|
||||
);
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
FfiConverterF64.write(dataStream, value.x);
|
||||
FfiConverterF64.write(dataStream, value.y);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
let totalSize = 0;
|
||||
totalSize += FfiConverterF64.computeSize(value.x);
|
||||
totalSize += FfiConverterF64.computeSize(value.y);
|
||||
return totalSize
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Point");
|
||||
|
||||
class Vector {
|
||||
constructor(dx,dy) {
|
||||
FfiConverterF64.checkType("dx", dx);
|
||||
FfiConverterF64.checkType("dy", dy);
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
}
|
||||
equals(other) {
|
||||
return (
|
||||
this.dx == other.dx &&
|
||||
this.dy == other.dy
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
static read(dataStream) {
|
||||
return new Vector(
|
||||
FfiConverterF64.read(dataStream),
|
||||
FfiConverterF64.read(dataStream)
|
||||
);
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
FfiConverterF64.write(dataStream, value.dx);
|
||||
FfiConverterF64.write(dataStream, value.dy);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
let totalSize = 0;
|
||||
totalSize += FfiConverterF64.computeSize(value.dx);
|
||||
totalSize += FfiConverterF64.computeSize(value.dy);
|
||||
return totalSize
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("Vector");class FfiConverterOptionalTypePoint extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypePoint.checkType(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
static read(dataStream) {
|
||||
const code = dataStream.readUint8(0);
|
||||
switch (code) {
|
||||
case 0:
|
||||
return null
|
||||
case 1:
|
||||
return FfiConverterTypePoint.read(dataStream)
|
||||
default:
|
||||
throw UniFFIError(`Unexpected code: ${code}`);
|
||||
}
|
||||
}
|
||||
|
||||
static write(dataStream, value) {
|
||||
if (value === null || value === undefined) {
|
||||
dataStream.writeUint8(0);
|
||||
return;
|
||||
}
|
||||
dataStream.writeUint8(1);
|
||||
FfiConverterTypePoint.write(dataStream, value)
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
if (value === null || value === undefined) {
|
||||
return 1;
|
||||
}
|
||||
return 1 + FfiConverterTypePoint.computeSize(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function translate(position,direction) {
|
||||
|
||||
const liftResult = (result) => FfiConverterTypePoint.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypePoint.checkType("position", position);
|
||||
FfiConverterTypeVector.checkType("direction", direction);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
71, // sprites:sprites_f59e_translate
|
||||
FfiConverterTypePoint.lower(position),
|
||||
FfiConverterTypeVector.lower(direction),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("translate");
|
|
@ -0,0 +1,737 @@
|
|||
// This file was autogenerated by the `uniffi-bindgen-gecko-js` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = [];
|
||||
|
||||
// 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 TodoList pointer from the data stream
|
||||
// UniFFI Pointers are **always** 8 bytes long. That is enforced
|
||||
// by the C++ and Rust Scaffolding code.
|
||||
readPointerTodoList() {
|
||||
const pointerId = 4; // todolist:TodoList
|
||||
const res = UniFFIScaffolding.readPointer(pointerId, this.dataView.buffer, this.pos);
|
||||
this.pos += 8;
|
||||
return res;
|
||||
}
|
||||
|
||||
// Writes a TodoList pointer into the data stream
|
||||
// UniFFI Pointers are **always** 8 bytes long. That is enforced
|
||||
// by the C++ and Rust Scaffolding code.
|
||||
writePointerTodoList(value) {
|
||||
const pointerId = 4; // todolist:TodoList
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class UniFFIInternalError extends UniFFIError {}
|
||||
|
||||
// Base class for FFI converters
|
||||
class FfiConverter {
|
||||
static checkType(name, value) {
|
||||
if (value === undefined ) {
|
||||
throw TypeError(`${name} is undefined`);
|
||||
}
|
||||
if (value === null ) {
|
||||
throw TypeError(`${name} is 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");
|
||||
|
||||
|
||||
|
||||
class FfiConverterString extends FfiConverter {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TodoList {
|
||||
// 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 TodoList.
|
||||
*
|
||||
* @returns {Promise<TodoList>}: A promise that resolves
|
||||
* to a newly constructed TodoList
|
||||
*/
|
||||
static init() {
|
||||
const liftResult = (result) => FfiConverterTypeTodoList.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
72, // todolist:todolist_9473_TodoList_new
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
addItem(todo) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("todo", todo);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
73, // todolist:todolist_9473_TodoList_add_item
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
FfiConverterString.lower(todo),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
addEntry(entry) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeTodoEntry.checkType("entry", entry);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
74, // todolist:todolist_9473_TodoList_add_entry
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
FfiConverterTypeTodoEntry.lower(entry),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
getEntries() {
|
||||
const liftResult = (result) => FfiConverterSequenceTypeTodoEntry.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
75, // todolist:todolist_9473_TodoList_get_entries
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
getItems() {
|
||||
const liftResult = (result) => FfiConverterSequencestring.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
76, // todolist:todolist_9473_TodoList_get_items
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
addEntries(entries) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterSequenceTypeTodoEntry.checkType("entries", entries);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
77, // todolist:todolist_9473_TodoList_add_entries
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
FfiConverterSequenceTypeTodoEntry.lower(entries),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
addItems(items) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterSequencestring.checkType("items", items);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
78, // todolist:todolist_9473_TodoList_add_items
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
FfiConverterSequencestring.lower(items),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
getLastEntry() {
|
||||
const liftResult = (result) => FfiConverterTypeTodoEntry.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
79, // todolist:todolist_9473_TodoList_get_last_entry
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
getLast() {
|
||||
const liftResult = (result) => FfiConverterString.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
80, // todolist:todolist_9473_TodoList_get_last
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
getFirst() {
|
||||
const liftResult = (result) => FfiConverterString.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
81, // todolist:todolist_9473_TodoList_get_first
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
clearItem(todo) {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("todo", todo);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
82, // todolist:todolist_9473_TodoList_clear_item
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
FfiConverterString.lower(todo),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
makeDefault() {
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
83, // todolist:todolist_9473_TodoList_make_default
|
||||
FfiConverterTypeTodoList.lower(this),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
class FfiConverterTypeTodoList extends FfiConverter {
|
||||
static lift(value) {
|
||||
const opts = {};
|
||||
opts[constructUniffiObject] = value;
|
||||
return new TodoList(opts);
|
||||
}
|
||||
|
||||
static lower(value) {
|
||||
return value[uniffiObjectPtr];
|
||||
}
|
||||
|
||||
static read(dataStream) {
|
||||
return this.lift(dataStream.readPointerTodoList());
|
||||
}
|
||||
|
||||
static write(dataStream, value) {
|
||||
dataStream.writePointerTodoList(value[uniffiObjectPtr]);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("TodoList");
|
||||
|
||||
class TodoEntry {
|
||||
constructor(text) {
|
||||
FfiConverterString.checkType("text", text);
|
||||
this.text = text;
|
||||
}
|
||||
equals(other) {
|
||||
return (
|
||||
this.text == other.text
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
static read(dataStream) {
|
||||
return new TodoEntry(
|
||||
FfiConverterString.read(dataStream)
|
||||
);
|
||||
}
|
||||
static write(dataStream, value) {
|
||||
FfiConverterString.write(dataStream, value.text);
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
let totalSize = 0;
|
||||
totalSize += FfiConverterString.computeSize(value.text);
|
||||
return totalSize
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("TodoEntry");
|
||||
|
||||
|
||||
class TodoError extends Error {}
|
||||
EXPORTED_SYMBOLS.push("TodoError");
|
||||
|
||||
|
||||
class TodoDoesNotExist extends TodoError {
|
||||
|
||||
constructor(message, ...params) {
|
||||
super(...params);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
EXPORTED_SYMBOLS.push("TodoDoesNotExist");
|
||||
class EmptyTodoList extends TodoError {
|
||||
|
||||
constructor(message, ...params) {
|
||||
super(...params);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
EXPORTED_SYMBOLS.push("EmptyTodoList");
|
||||
class DuplicateTodo extends TodoError {
|
||||
|
||||
constructor(message, ...params) {
|
||||
super(...params);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
EXPORTED_SYMBOLS.push("DuplicateTodo");
|
||||
class EmptyString extends TodoError {
|
||||
|
||||
constructor(message, ...params) {
|
||||
super(...params);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
EXPORTED_SYMBOLS.push("EmptyString");
|
||||
class DeligatedError extends TodoError {
|
||||
|
||||
constructor(message, ...params) {
|
||||
super(...params);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
EXPORTED_SYMBOLS.push("DeligatedError");
|
||||
|
||||
class FfiConverterTypeTodoError extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
switch (dataStream.readInt32()) {
|
||||
case 1:
|
||||
return new TodoDoesNotExist(FfiConverterString.read(dataStream));
|
||||
case 2:
|
||||
return new EmptyTodoList(FfiConverterString.read(dataStream));
|
||||
case 3:
|
||||
return new DuplicateTodo(FfiConverterString.read(dataStream));
|
||||
case 4:
|
||||
return new EmptyString(FfiConverterString.read(dataStream));
|
||||
case 5:
|
||||
return new DeligatedError(FfiConverterString.read(dataStream));
|
||||
default:
|
||||
return new Error("Unknown TodoError variant");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FfiConverterOptionalTypeTodoList extends FfiConverterArrayBuffer {
|
||||
static checkType(name, value) {
|
||||
if (value !== undefined && value !== null) {
|
||||
FfiConverterTypeTodoList.checkType(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
static read(dataStream) {
|
||||
const code = dataStream.readUint8(0);
|
||||
switch (code) {
|
||||
case 0:
|
||||
return null
|
||||
case 1:
|
||||
return FfiConverterTypeTodoList.read(dataStream)
|
||||
default:
|
||||
throw UniFFIError(`Unexpected code: ${code}`);
|
||||
}
|
||||
}
|
||||
|
||||
static write(dataStream, value) {
|
||||
if (value === null || value === undefined) {
|
||||
dataStream.writeUint8(0);
|
||||
return;
|
||||
}
|
||||
dataStream.writeUint8(1);
|
||||
FfiConverterTypeTodoList.write(dataStream, value)
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
if (value === null || value === undefined) {
|
||||
return 1;
|
||||
}
|
||||
return 1 + FfiConverterTypeTodoList.computeSize(value)
|
||||
}
|
||||
}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;
|
||||
}
|
||||
}class FfiConverterSequenceTypeTodoEntry extends FfiConverterArrayBuffer {
|
||||
static read(dataStream) {
|
||||
const len = dataStream.readInt32();
|
||||
const arr = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
arr.push(FfiConverterTypeTodoEntry.read(dataStream));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
static write(dataStream, value) {
|
||||
dataStream.writeInt32(value.length);
|
||||
value.forEach((innerValue) => {
|
||||
FfiConverterTypeTodoEntry.write(dataStream, innerValue);
|
||||
})
|
||||
}
|
||||
|
||||
static computeSize(value) {
|
||||
// The size of the length
|
||||
let size = 4;
|
||||
for (const innerValue of value) {
|
||||
size += FfiConverterTypeTodoEntry.computeSize(innerValue);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getDefaultList() {
|
||||
|
||||
const liftResult = (result) => FfiConverterOptionalTypeTodoList.lift(result);
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
return UniFFIScaffolding.callAsync(
|
||||
84, // todolist:todolist_9473_get_default_list
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("getDefaultList");
|
||||
function setDefaultList(list) {
|
||||
|
||||
const liftResult = (result) => undefined;
|
||||
const liftError = null;
|
||||
const functionCall = () => {
|
||||
FfiConverterTypeTodoList.checkType("list", list);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
85, // todolist:todolist_9473_set_default_list
|
||||
FfiConverterTypeTodoList.lower(list),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("setDefaultList");
|
||||
function createEntryWith(todo) {
|
||||
|
||||
const liftResult = (result) => FfiConverterTypeTodoEntry.lift(result);
|
||||
const liftError = (data) => FfiConverterTypeTodoError.lift(data);
|
||||
const functionCall = () => {
|
||||
FfiConverterString.checkType("todo", todo);
|
||||
return UniFFIScaffolding.callAsync(
|
||||
86, // todolist:todolist_9473_create_entry_with
|
||||
FfiConverterString.lower(todo),
|
||||
)
|
||||
}
|
||||
try {
|
||||
return functionCall().then((result) => handleRustResult(result, liftResult, liftError));
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
EXPORTED_SYMBOLS.push("createEntryWith");
|
|
@ -0,0 +1,19 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
FINAL_LIBRARY = "xul"
|
||||
|
||||
components = [
|
||||
"Arithmetic",
|
||||
"Geometry",
|
||||
"Rondpoint",
|
||||
"Sprites",
|
||||
"Todolist",
|
||||
]
|
||||
|
||||
EXTRA_JS_MODULES["components-utils"] = [
|
||||
"generated/{}.jsm".format(component) for component in components
|
||||
]
|
|
@ -0,0 +1,90 @@
|
|||
# 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/.
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from mach.decorators import (
|
||||
Command,
|
||||
SubCommand,
|
||||
)
|
||||
|
||||
# IMPORTANT: Please Request review from a DOM peer before
|
||||
# committing to using UniFFI. There are other ways to consume Rust from
|
||||
# JavaScript that might fit your use case better.
|
||||
UDL_FILES = [
|
||||
# TODO: Use UniFFI
|
||||
]
|
||||
FIXTURE_UDL_FILES = [
|
||||
"third_party/rust/uniffi-example-geometry/src/geometry.udl",
|
||||
"third_party/rust/uniffi-example-arithmetic/src/arithmetic.udl",
|
||||
"third_party/rust/uniffi-example-rondpoint/src/rondpoint.udl",
|
||||
"third_party/rust/uniffi-example-sprites/src/sprites.udl",
|
||||
"third_party/rust/uniffi-example-todolist/src/todolist.udl",
|
||||
]
|
||||
CPP_PATH = "toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp"
|
||||
JS_DIR = "toolkit/components/uniffi-bindgen-gecko-js/components/generated"
|
||||
FIXTURE_CPP_PATH = "toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp"
|
||||
FIXTURE_JS_DIR = "toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated"
|
||||
|
||||
|
||||
def build_uniffi_bindgen_gecko_js(command_context):
|
||||
uniffi_root = crate_root(command_context)
|
||||
print("Building uniffi-bindgen-gecko-js")
|
||||
cmdline = [
|
||||
"cargo",
|
||||
"build",
|
||||
"--release",
|
||||
"--manifest-path",
|
||||
os.path.join(command_context.topsrcdir, "Cargo.toml"),
|
||||
"--package",
|
||||
"uniffi-bindgen-gecko-js",
|
||||
]
|
||||
subprocess.check_call(cmdline, cwd=uniffi_root)
|
||||
print()
|
||||
return os.path.join(
|
||||
command_context.topsrcdir, "target", "release", "uniffi-bindgen-gecko-js"
|
||||
)
|
||||
|
||||
|
||||
@Command(
|
||||
"uniffi",
|
||||
category="devenv",
|
||||
description="Generate JS bindings using uniffi-bindgen-gecko-js",
|
||||
)
|
||||
def uniffi(command_context, *runargs, **lintargs):
|
||||
"""Run uniffi."""
|
||||
command_context._sub_mach(["help", "uniffi"])
|
||||
return 1
|
||||
|
||||
|
||||
@SubCommand(
|
||||
"uniffi",
|
||||
"generate",
|
||||
description="Generate/regenerate bindings",
|
||||
)
|
||||
def generate_command(command_context):
|
||||
binary_path = build_uniffi_bindgen_gecko_js(command_context)
|
||||
cmdline = [
|
||||
binary_path,
|
||||
"--js-dir",
|
||||
JS_DIR,
|
||||
"--fixture-js-dir",
|
||||
FIXTURE_JS_DIR,
|
||||
"--cpp-path",
|
||||
CPP_PATH,
|
||||
"--fixture-cpp-path",
|
||||
FIXTURE_CPP_PATH,
|
||||
]
|
||||
if UDL_FILES:
|
||||
cmdline += ["--udl-files"] + UDL_FILES
|
||||
if FIXTURE_UDL_FILES:
|
||||
cmdline += ["--fixture-udl-files"] + FIXTURE_UDL_FILES
|
||||
subprocess.check_call(cmdline, cwd=command_context.topsrcdir)
|
||||
return 0
|
||||
|
||||
|
||||
def crate_root(command_context):
|
||||
return os.path.join(
|
||||
command_context.topsrcdir, "toolkit", "components", "uniffi-bindgen-gecko-js"
|
||||
)
|
|
@ -14,6 +14,7 @@ UNIFIED_SOURCES += [
|
|||
]
|
||||
|
||||
if CONFIG["MOZ_UNIFFI_FIXTURES"]:
|
||||
DEFINES["MOZ_UNIFFI_FIXTURES"] = True
|
||||
UNIFIED_SOURCES += [
|
||||
"UniFFIFixtureScaffolding.cpp",
|
||||
]
|
||||
|
|
|
@ -3212,7 +3212,6 @@ option(
|
|||
help="Enable UniFFI Fixtures/Examples",
|
||||
)
|
||||
|
||||
|
||||
set_config("MOZ_UNIFFI_FIXTURES", True, when="--enable-uniffi-fixtures")
|
||||
|
||||
# Checks for library functions
|
||||
|
|
|
@ -11,3 +11,4 @@ intl/unicharutil/util/nsSpecialCasingData.cpp
|
|||
intl/unicharutil/util/nsUnicodePropertyData.cpp
|
||||
toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp
|
||||
toolkit/components/uniffi-js/UniFFIFixtureScaffolding.cpp
|
||||
toolkit/components/uniffi-bindgen-gecko-js/fixtures/generated
|
||||
|
|
Загрузка…
Ссылка в новой задаче