-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binds functions added in bytecodealliance/wasmtime#1654 Closes #5
- Loading branch information
1 parent
55cf565
commit 75bf9e9
Showing
2 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package wasmtime | ||
|
||
import "testing" | ||
|
||
func TestTable(t *testing.T) { | ||
store := NewStore(NewEngine()) | ||
ty := NewTableType(NewValType(KindFuncref), Limits{Min: 1, Max: 3}) | ||
table, err := NewTable(store, ty, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if table.Size() != 1 { | ||
panic("wrong size") | ||
} | ||
|
||
f, err := table.Get(0) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if f != nil { | ||
panic("expected nil") | ||
} | ||
f, err = table.Get(1) | ||
if err == nil { | ||
panic("expected error") | ||
} | ||
if f != nil { | ||
panic("expected nil") | ||
} | ||
|
||
err = table.Set(0, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
err = table.Set(1, nil) | ||
if err == nil { | ||
panic("expected error") | ||
} | ||
err = table.Set(0, WrapFunc(store, func() {})) | ||
if err != nil { | ||
panic(nil) | ||
} | ||
f, err = table.Get(0) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if f == nil { | ||
panic("expected not nil") | ||
} | ||
|
||
prev_size, err := table.Grow(1, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if prev_size != 1 { | ||
print(prev_size) | ||
panic("bad prev") | ||
} | ||
f, err = table.Get(1) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if f != nil { | ||
panic("expected nil") | ||
} | ||
|
||
called := false | ||
_, err = table.Grow(1, WrapFunc(store, func() { | ||
called = true | ||
})) | ||
if err != nil { | ||
panic(err) | ||
} | ||
f, err = table.Get(2) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if called { | ||
panic("called already?") | ||
} | ||
_, err = f.Call() | ||
if err != nil { | ||
panic(err) | ||
} | ||
if !called { | ||
panic("should have called") | ||
} | ||
} |