summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-bindgen-gecko-js/src/templates/js/CallbackInterface.sys.mjs
blob: 0b24cbbe0b5ea54e27d7a89b8852a3fe05b36e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{%- let cbi = ci.get_callback_interface_definition(name).unwrap() %}
{#- See CallbackInterfaceRuntime.sys.mjs and CallbackInterfaceHandler.sys.mjs for the callback interface handler definition, referenced here as `{{ cbi.handler() }}` #}
// Export the FFIConverter object to make external types work.
export class {{ ffi_converter }} extends FfiConverter {
    static lower(callbackObj) {
        return {{ cbi.handler() }}.storeCallbackObj(callbackObj)
    }

    static lift(handleId) {
        return {{ cbi.handler() }}.getCallbackObj(handleId)
    }

    static read(dataStream) {
        return this.lift(dataStream.readInt64())
    }

    static write(dataStream, callbackObj) {
        dataStream.writeInt64(this.lower(callbackObj))
    }

    static computeSize(callbackObj) {
        return 8;
    }
}