Adds experimental write support and implements on gojs (#970)

This adds writefs.FS, allowing functions to create and delete files.
This begins by implementing them on `GOARCH=js GOOS=wasm`. The current
status is a lot farther than before, even if completing write on WASI is
left for a later PR (possibly by another volunteer).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-12-28 19:49:46 +08:00
committed by GitHub
parent 921df7e7a6
commit 15dc3d7d37
19 changed files with 573 additions and 133 deletions

View File

@@ -144,8 +144,12 @@ func storeRef(ctx context.Context, v interface{}) goos.Ref { //nolint
} else if _, ok := v.(string); ok {
id := getState(ctx).values.increment(v)
return goos.ValueRef(id, goos.TypeFlagString)
} else if i32, ok := v.(int32); ok {
return toFloatRef(float64(i32))
} else if u32, ok := v.(uint32); ok {
return toFloatRef(float64(u32))
} else if i64, ok := v.(int64); ok {
return toFloatRef(float64(i64))
} else if u64, ok := v.(uint64); ok {
return toFloatRef(float64(u64))
} else if f64, ok := v.(float64); ok {
@@ -261,6 +265,15 @@ func toInt64(arg interface{}) int64 {
return int64(arg.(float64))
}
func toUint64(arg interface{}) uint64 {
if arg == goos.RefValueZero || arg == undefined {
return 0
} else if u, ok := arg.(uint64); ok {
return u
}
return uint64(arg.(float64))
}
func toUint32(arg interface{}) uint32 {
if arg == goos.RefValueZero || arg == undefined {
return 0