quickjs-go icon indicating copy to clipboard operation
quickjs-go copied to clipboard

Returning an empty `ArrayBuffer` crashes

Open vshymanskyy opened this issue 9 months ago • 1 comments

For example:

func myfunc(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
    return ctx.ArrayBuffer([]byte{})
}

Calling this function Results in:

jsrunner: quickjs.c:1998: JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed.
SIGABRT: abort

Any ideas welcome!

vshymanskyy avatar Feb 10 '25 16:02 vshymanskyy

@buke it would be also nice to expose the functions like JS_NewTypedArray, JS_GetTypedArrayBuffer, Value.globalInstanceof (or an alternative)

vshymanskyy avatar Feb 10 '25 16:02 vshymanskyy

fixed empty ArrayBuffer crashes & exposed Value.globalInstanceof in https://github.com/buke/quickjs-go/commit/fcd91bd28d7837483c3172a3c7db7bc5ce742d76

quickjs TypedArray api did not have like JS_NewArrayBufferCopy for now , if we implement the Context.TypeArrayBuffer , it will have many unsafe copy operation. I suggest using ArrayBuffer and Eval api to instead , like as :

typeArrayFn, _ := ctx.Eval(`
(data) => {

return new Int32Array(data);

}
`)

binaryData := []uint8{1, 2, 3, 4, 5}
value := ctx.ArrayBuffer(binaryData)
typeArrayFn.Execute(ctx.Null(), value)


buke avatar May 19 '25 16:05 buke

pls see TypeArray support at https://github.com/buke/quickjs-go/pull/457

buke avatar Jun 02 '25 10:06 buke

I'm going to close this issue. If there are any problems, please feel free to reopen it.

buke avatar Jun 06 '25 16:06 buke