updated jsvm types

This commit is contained in:
Gani Georgiev 2025-06-17 21:23:19 +03:00
parent 262e78c04e
commit c8776b7cd9
4 changed files with 3031 additions and 3019 deletions

View File

@ -313,7 +313,7 @@ func baseBinds(vm *goja.Runtime) {
vm.Set("toBytes", func(raw any, maxReaderBytes int) ([]byte, error) {
switch v := raw.(type) {
case nil:
return nil, nil
return []byte{}, nil
case string:
return []byte(v), nil
case []byte:

View File

@ -128,7 +128,7 @@ func TestBaseBindsToBytes(t *testing.T) {
Value any
Expected []byte
}{
{"null", nil, nil},
{"null", nil, []byte{}},
{"string", "test", []byte("test")},
{"number", -12.4, []byte("-12.4")},
{"bool", true, []byte("true")},

File diff suppressed because it is too large Load Diff

View File

@ -186,8 +186,11 @@ declare function readerToString(reader: any, maxBytes?: number): string;
* // io.Reader
* const ex1 = toString(e.request.body)
*
* // slice of bytes ("hello")
* const ex2 = toString([104 101 108 108 111])
* // slice of bytes
* const ex2 = toString([104 101 108 108 111]) // "hello"
*
* // null
* const ex3 = toString(null) // ""
* ` + "```" + `
*
* @group PocketBase
@ -213,7 +216,10 @@ declare function toString(val: any, maxBytes?: number): string;
* const ex2 = toBytes("hello") // [104 101 108 108 111]
*
* // object (the same as the string '{"test":1}')
* const ex2 = toBytes({"test":1}) // [123 34 116 101 115 116 34 58 49 125]
* const ex3 = toBytes({"test":1}) // [123 34 116 101 115 116 34 58 49 125]
*
* // null
* const ex4 = toBytes(null) // []
* ` + "```" + `
*
* @group PocketBase