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)
| 1050 | // safe interchange format for untrusted data, and loading hostile bytecode |
| 1051 | // may lead to memory corruption in the underlying engine. |
| 1052 | func (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. |
| 1077 | func (ctx *Context) SetImportMeta(moduleFunc *Value, useRealPath bool, isMain bool) bool { |