| 156 | } |
| 157 | |
| 158 | func (v *Value) ToByteArray(size uint) ([]byte, error) { |
| 159 | if v.ByteLen() < int64(size) { |
| 160 | return nil, errors.New("exceeds the maximum length of the current binary array") |
| 161 | } |
| 162 | cSize := C.size_t(size) |
| 163 | outBuf := C.JS_GetArrayBuffer(v.ctx.ref, &cSize, v.ref) |
| 164 | |
| 165 | if outBuf == nil { |
| 166 | return nil, errors.New("failed to get ArrayBuffer data") |
| 167 | } |
| 168 | |
| 169 | return C.GoBytes(unsafe.Pointer(outBuf), C.int(size)), nil |
| 170 | } |
| 171 | |
| 172 | // Deprecated: Use ToInt64 instead. |
| 173 | func (v *Value) Int64() int64 { |