ToNumber returns the numeric value as a new JavaScript Number.
()
| 233 | |
| 234 | // ToNumber returns the numeric value as a new JavaScript Number. |
| 235 | func (v *Value) ToNumber() (*Value, error) { |
| 236 | if !v.hasValidContext() { |
| 237 | return nil, errors.New("value context is not available") |
| 238 | } |
| 239 | |
| 240 | converted := &Value{ctx: v.ctx, ref: C.JS_ToNumber(v.ctx.ref, v.ref)} |
| 241 | if converted.IsException() { |
| 242 | return nil, v.ctx.Exception() |
| 243 | } |
| 244 | |
| 245 | return converted, nil |
| 246 | } |
| 247 | |
| 248 | // ToIndex returns the value converted to a JavaScript array index. |
| 249 | func (v *Value) ToIndex() (uint64, error) { |