Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,8 @@ func main() {

### Bytecode Compiler

QuickJS bytecode should only be loaded from trusted input produced by this library or another trusted writer. It is not a safe interchange format for untrusted data, and loading hostile bytecode may lead to memory corruption in the underlying engine.

```go
package main

Expand Down
2 changes: 2 additions & 0 deletions README_zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,8 @@ func main() {

### 字节码编译器

QuickJS 字节码只应从本库生成的可信输入,或其他可信写入方生成的输入中加载。它不是面向不可信数据的安全交换格式;加载恶意字节码可能导致底层引擎发生内存破坏。

```go
package main

Expand Down
12 changes: 9 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,10 @@ func (ctx *Context) CompileModule(filePath string, moduleName string, opts ...Ev
return ctx.CompileFile(filePath, opts...)
}

// LoadModuleByteCode returns a js value with given bytecode and module name.
// 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.
Comment thread
buke marked this conversation as resolved.
func (ctx *Context) LoadModuleBytecode(buf []byte, opts ...EvalOption) *Value {
if !ctx.hasValidRef() {
return nil
Expand Down Expand Up @@ -1029,8 +1032,11 @@ func (ctx *Context) BootstrapBJSON() bool {
return C.js_init_module_bjson(ctx.ref, moduleName) != nil
}

// EvalBytecode returns a js value with given bytecode.
// Need call Free() `quickjs.Value`'s returned by `Eval()` and `EvalFile()` and `EvalBytecode()`.
// 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 Value returned by EvalBytecode().
func (ctx *Context) EvalBytecode(buf []byte) *Value {
if !ctx.hasValidRef() {
return nil
Expand Down
Loading