runtime/js: itoa
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
package js
|
package js
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,7 +47,8 @@ func FuncOf(fn func(this Value, args []Value) any) Func {
|
|||||||
nextFuncID++
|
nextFuncID++
|
||||||
funcs[id] = fn
|
funcs[id] = fn
|
||||||
funcsMu.Unlock()
|
funcsMu.Unlock()
|
||||||
sid := strconv.Itoa(int(id))
|
var buf [20]byte
|
||||||
|
sid := string(itoa(buf[:], uint64(id)))
|
||||||
wrap := functionConstructor.New(ValueOf(`
|
wrap := functionConstructor.New(ValueOf(`
|
||||||
const event = { id:` + sid + `, this: this, args: arguments };
|
const event = { id:` + sid + `, this: this, args: arguments };
|
||||||
Module._llgo_invoke(event);
|
Module._llgo_invoke(event);
|
||||||
@@ -60,6 +60,17 @@ func FuncOf(fn func(this Value, args []Value) any) Func {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func itoa(buf []byte, val uint64) []byte {
|
||||||
|
i := len(buf) - 1
|
||||||
|
for val >= 10 {
|
||||||
|
buf[i] = byte(val%10 + '0')
|
||||||
|
i--
|
||||||
|
val /= 10
|
||||||
|
}
|
||||||
|
buf[i] = byte(val + '0')
|
||||||
|
return buf[i:]
|
||||||
|
}
|
||||||
|
|
||||||
// Release frees up resources allocated for the function.
|
// Release frees up resources allocated for the function.
|
||||||
// The function must not be invoked after calling Release.
|
// The function must not be invoked after calling Release.
|
||||||
// It is allowed to call Release while the function is still running.
|
// It is allowed to call Release while the function is still running.
|
||||||
|
|||||||
Reference in New Issue
Block a user