Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
/ goja_webassembly Public archive

This library provides WebAssembly capability for goja Javascript engine

Notifications You must be signed in to change notification settings

YC-Lammy/goja_webassembly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goja_webassembly

This module provides WebAssembly functions into goja javascript engine.

example:

package main

import(
    "github.com/dop251/goja"
    "github.com/YC-Lammy/goja_webassembly"
)

func main(){
    vm := goja.New()
    webassembly.Enable(vm)
    
    wasmbytes, _ := wasmer.Wat2Wasm(`
    (module
  (type $sum_t (func (param i32 i32) (result i32)))
  (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)
    local.get $x
    local.get $y
    i32.add)
    (export "sum" (func $sum_f)))`)
    
    vm.GlobalObject().Set("wasmbytes",vm.ToValue(vm.NewArrayBuffer(wasmbytes)))
  
    vm.RunString(`
        instance = WebAssembly.instantiate(wasmbytes)
        instance.exports.sum(3,4)
    `)
}

About

This library provides WebAssembly capability for goja Javascript engine

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published