Skip to content
Snippets Groups Projects
Select Git revision
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • release default protected
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
40 results

api

  • Clone with SSH
  • Clone with HTTPS
  • user avatar
    Jake Taylor authored
    7ff1ea08
    History

    xxdk-WASM

    This repository contains the WebAssembly bindings for xxDK. It also includes a test server to serve the compiled WebAssembly module.

    Building

    The repository can only be compiled to a WebAssembly binary using GOOS=js and GOARCH=wasm.

    $ GOOS=js GOARCH=wasm go build -o xxdk.wasm

    Running Unit Tests

    Because the bindings use syscall/js, tests cannot only be run in a browser. To automate this process first install wasmbrowsertest. Then, tests can be run using the following command.

    $ GOOS=js GOARCH=wasm go test ./...

    Note, this will fail because wasm/wasm_js.s contains commands only recognized by the Go WebAssembly compiler and for some reason not recognized by the test runner. To get tests to run, temporarily delete the body of wasm/wasm_js.s during testing.

    Testing

    The test directory contains assets, a simple web page to run the Javascript, and server, which runs a simple Go HTTP server to deliver the webpage.

    To run the server, first compile the bindings and save them to the assets directory. Then run the server

    $ GOOS=js GOARCH=wasm go build -o test/assets/xxdk.wasm
    $ cd test/server/
    $ go run main.go

    Navigate to http://localhost:9090 to see the web page.

    wasm_exec.js

    wasm_exec.js is provided by Go and is used to import the WebAssembly module in the browser. It can be retrieved from Go using the following command.

    $ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" test/assets/

    Note that this repository makes edits to wasm_exec.js and you must either use the one in this repository or add the following lines in the go importObject on global.Go.

    global.Go = class {
        constructor() {
            // ...
            this.importObject = {
                go: {
                    // ...
                    // func Throw(exception string, message string)
                    'gitlab.com/elixxir/xxdk-wasm/wasm.throw': (sp) => {
                        const exception = loadString(sp + 8)
                        const message = loadString(sp + 24)
                        throw globalThis[exception](message)
                    },
                }
            }
        }
    }