EvalBytecode returns a js value from the given bytecode. Only load bytecode produced by a trusted source. QuickJS bytecode is not a safe interchange format for untrusted data, and loading hostile bytecode may lead to memory corruption in the underlying engine. The caller must call Free() on the Valu
(buf []byte)
| 1097 | // may lead to memory corruption in the underlying engine. |
| 1098 | // The caller must call Free() on the Value returned by EvalBytecode(). |
| 1099 | func (ctx *Context) EvalBytecode(buf []byte) *Value { |
| 1100 | if !ctx.hasValidRef() { |
| 1101 | return nil |
| 1102 | } |
| 1103 | cbuf := (*C.uint8_t)(unsafe.Pointer(unsafe.SliceData(buf))) |
| 1104 | obj := &Value{ctx: ctx, ref: C.JS_ReadObject(ctx.ref, cbuf, C.size_t(len(buf)), C.int(C.JS_READ_OBJ_BYTECODE))} |
| 1105 | if obj.IsException() { |
| 1106 | return obj |
| 1107 | } |
| 1108 | |
| 1109 | return &Value{ctx: ctx, ref: C.JS_EvalFunction(ctx.ref, obj.ref)} |
| 1110 | } |
| 1111 | |
| 1112 | // Compile returns a compiled bytecode with given code. |
| 1113 | func (ctx *Context) Compile(code string, opts ...EvalOption) ([]byte, error) { |