ParseJson parses given json string and returns a object value.
(v string)
| 682 | |
| 683 | // ParseJson parses given json string and returns a object value. |
| 684 | func (ctx *Context) ParseJSON(v string) *Value { |
| 685 | jsonBuf := zeroTerminatedBytes(v) |
| 686 | ptr := (*C.char)(unsafe.Pointer(&jsonBuf[0])) |
| 687 | |
| 688 | filenameBuf := []byte{0} |
| 689 | filenamePtr := (*C.char)(unsafe.Pointer(&filenameBuf[0])) |
| 690 | |
| 691 | var pinner goruntime.Pinner |
| 692 | pinner.Pin(&jsonBuf[0]) |
| 693 | pinner.Pin(&filenameBuf[0]) |
| 694 | defer pinner.Unpin() |
| 695 | |
| 696 | parsed := C.JS_ParseJSON(ctx.ref, ptr, C.size_t(len(v)), filenamePtr) |
| 697 | goruntime.KeepAlive(jsonBuf) |
| 698 | goruntime.KeepAlive(filenameBuf) |
| 699 | return &Value{ctx: ctx, ref: parsed} |
| 700 | } |
| 701 | |
| 702 | // NewFunction returns a js function value with given function template |
| 703 | // New implementation using HandleStore and JS_NewCFunction2 with magic parameter |