(value *Value)
| 113 | } |
| 114 | |
| 115 | func (v *VM) EncodeJSONValue(value *Value) ([]byte, error) { |
| 116 | encoded, e := v.o.Call("JSON.stringify", nil, value.v) |
| 117 | if e != nil { |
| 118 | return nil, e |
| 119 | } |
| 120 | if encoded.IsUndefined() { |
| 121 | return nil, fmt.Errorf("value is not JSON serializable") |
| 122 | } |
| 123 | return []byte(encoded.String()), nil |
| 124 | } |
| 125 | |
| 126 | func (v *VM) DecodeJSONValue(encoded []byte) (any, error) { |
| 127 | return v.o.Call("JSON.parse", nil, string(encoded)) |