Skip to content

0.2.0

Compare
Choose a tag to compare
@Hywan Hywan released this 16 Jul 09:48
· 463 commits to master since this release

Features

  • #55 Add the Memory.Grow method (@Hywan)

  • #42 Improve error messages when instantiating (@Hywan)

  • #38 Support import descriptors (@Hywan)

    var module, _ = wasm.Compile(bytes)
    
    assert.Equal(…, "log_message", module.Imports[0].Name)
    assert.Equal(…, "env", module.Imports[0].Namespace)
  • #37 Support export descriptors (@Hywan)

    var module, _ = wasm.Compile(bytes)
    
    assert.Equal(…, "sum", module.Exports[7].Name)
  • #34 Support module serialization and deserialization (@Hywan)

    // Compiles the bytes into a WebAssembly module.
    module1, _ := wasm.Compile(GetBytes())
    defer module1.Close()
    
    // Serializes the module into a sequence of bytes.
    serialization, _ := module1.Serialize()
    
    // Do something with `serialization`.
    // Then later…
    
    // Deserializes the module.
    module2, _ := wasm.DeserializeModule(serialization)
    defer module2.Close()
    // And enjoy!
    
    // Instantiates the WebAssembly module.
    instance, _ := module2.Instantiate()
    defer instance.Close()
    
    // Gets an exported function.
    sum, functionExists := instance.Exports["sum"]
    
    fmt.Println(functionExists)
    
    // Calls the `sum` exported function with Go values.
    result, _ := sum(1, 2)
    
    fmt.Println(result)
    
    // Output:
    // true
    // 3
  • #33 Add Compile, Module.Instantiate* and Module.Close (@Hywan)

  • #30 Support instance context data (@Hywan)

    //export logMessageWithContextData
    func logMessageWithContextData(context unsafe.Pointer, pointer int32, length int32) {
            var instanceContext = wasm.IntoInstanceContext(context)
            var memory = instanceContext.Memory().Data()
            var logMessage = (*logMessageContext)(instanceContext.Data())
    
            logMessage.message = string(memory[pointer : pointer+length])
    }
    
    type logMessageContext struct {
            message string
    }
    
    func testImportInstanceContextData(t *testing.T) {
            imports, err := wasm.NewImports().Append("log_message", logMessageWithContextData, C.logMessageWithContextData)
            assert.NoError(t, err)
    
            instance, err := wasm.NewInstanceWithImports(getImportedFunctionBytes("log.wasm"), imports)
            assert.NoError(t, err)
    
            defer instance.Close()
    
            contextData := logMessageContext{message: "first"}
            instance.SetContextData(unsafe.Pointer(&contextData))
    
            doSomething := instance.Exports["do_something"]
    
            result, err := doSomething()
    
            assert.NoError(t, err)
            assert.Equal(t, wasm.TypeVoid, result.GetType())
            assert.Equal(t, "hello", contextData.message)
    }
  • #29 Add Imports.Namespace to set the current import namespace (@Hywan)

    // By default, the namespace is `"env"`. Change it to `"ns"`.
    wasm.NewImports().Namespace("ns").Append("f", f, C.f)
  • #26 Support instance context API (@Hywan)

Bug/security fixes

Documentation/Test

  • #51 Test that all Wasm types can be used in imported functions (@Hywan)
  • #36 Improve the Benchmarks Section (@Hywan)
  • #32 Move examples in the root directory for godoc.org (@Hywan)
  • #31 Fix example namespaces for godoc.org (@Hywan)
  • #30 Increase the cgocheck level (@Hywan)

Chore