MCPcopy Create free account
hub / github.com/buke/quickjs-go / EvalBytecode

Method EvalBytecode

context.go:1099–1110  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1097// may lead to memory corruption in the underlying engine.
1098// The caller must call Free() on the Value returned by EvalBytecode().
1099func (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.
1113func (ctx *Context) Compile(code string, opts ...EvalOption) ([]byte, error) {

Calls 2

hasValidRefMethod · 0.95
IsExceptionMethod · 0.95