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

Method LoadModuleBytecode

context.go:1052–1074  ·  view source on GitHub ↗

LoadModuleBytecode 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.

(buf []byte, opts ...EvalOption)

Source from the content-addressed store, hash-verified

1050// safe interchange format for untrusted data, and loading hostile bytecode
1051// may lead to memory corruption in the underlying engine.
1052func (ctx *Context) LoadModuleBytecode(buf []byte, opts ...EvalOption) *Value {
1053 if !ctx.hasValidRef() {
1054 return nil
1055 }
1056 if len(buf) == 0 {
1057 return ctx.ThrowSyntaxError("empty bytecode")
1058 }
1059
1060 options := EvalOptions{}
1061 for _, fn := range opts {
1062 fn(&options)
1063 }
1064
1065 var cLoadOnlyFlag C.int = 0
1066 if options.load_only {
1067 cLoadOnlyFlag = 1
1068 }
1069
1070 // Use our custom LoadModuleBytecode function instead of js_std_eval_binary
1071 cVal := C.LoadModuleBytecode(ctx.ref, (*C.uint8_t)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)), cLoadOnlyFlag)
1072
1073 return &Value{ctx: ctx, ref: cVal}
1074}
1075
1076// SetImportMeta sets import.meta for a compiled module function.
1077func (ctx *Context) SetImportMeta(moduleFunc *Value, useRealPath bool, isMain bool) bool {

Callers 3

TestContextModulesFunction · 0.95
LoadModuleMethod · 0.95

Calls 2

hasValidRefMethod · 0.95
ThrowSyntaxErrorMethod · 0.95