ToStringUTF16 returns the UTF-16 code units of the string representation of the value.
()
| 317 | |
| 318 | // ToStringUTF16 returns the UTF-16 code units of the string representation of the value. |
| 319 | func (v *Value) ToStringUTF16() ([]uint16, error) { |
| 320 | if !v.hasValidContext() { |
| 321 | return nil, errors.New("value context is not available") |
| 322 | } |
| 323 | |
| 324 | length := C.size_t(0) |
| 325 | ptr := C.JS_ToCStringLenUTF16(v.ctx.ref, &length, v.ref) |
| 326 | if ptr == nil { |
| 327 | return nil, v.ctx.Exception() |
| 328 | } |
| 329 | defer C.JS_FreeCStringUTF16(v.ctx.ref, ptr) |
| 330 | |
| 331 | utf16 := unsafe.Slice((*uint16)(unsafe.Pointer(ptr)), int(length)) |
| 332 | return append([]uint16(nil), utf16...), nil |
| 333 | } |
| 334 | |
| 335 | // Len returns the length of the array. |
| 336 | func (v *Value) Len() int64 { |