Skip to content
Closed
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
32 changes: 32 additions & 0 deletions auto/quickjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,38 @@ if [ $NJS_TRY_QUICKJS = YES ]; then

. auto/feature

njs_feature="QuickJS sized JS_NewArrayBuffer()"
njs_feature_name=NJS_HAVE_QUICKJS_SIZED_NEW_ARRAY_BUFFER
njs_feature_test="#include <quickjs_compat.h>

static void *realloc_ab(JSRuntime *rt, void *opaque,
void *ptr, size_t size) {
(void) rt;
(void) opaque;
(void) ptr;
(void) size;
return 0;
}

int main() {
JSValue ab;
JSRuntime *rt;
JSContext *ctx;
uint8_t b;

b = 0;
rt = JS_NewRuntime();
ctx = JS_NewContext(rt);
ab = JS_NewArrayBuffer(ctx, &b, 1, 1, realloc_ab,
NULL, 0);
JS_FreeValue(ctx, ab);
JS_FreeContext(ctx);
JS_FreeRuntime(rt);
return 0;
}"

. auto/feature

njs_feature="QuickJS JS_NewError() attaches stack"
njs_feature_run=value
njs_feature_name=NJS_HAVE_QUICKJS_NEW_ERROR_STACK
Expand Down
7 changes: 7 additions & 0 deletions external/njs_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,9 +2081,16 @@ njs_qjs_agent(void *arg)
pthread_cond_signal(&console->agent_cond);
pthread_mutex_unlock(&console->agent_mutex);

#ifdef NJS_HAVE_QUICKJS_SIZED_NEW_ARRAY_BUFFER
args[0] = JS_NewArrayBuffer(ctx, agent->broadcast_sab_buf,
agent->broadcast_sab_size,
agent->broadcast_sab_size,
NULL, NULL, 1);
#else
args[0] = JS_NewArrayBuffer(ctx, agent->broadcast_sab_buf,
agent->broadcast_sab_size,
NULL, NULL, 1);
#endif
args[1] = JS_NewInt32(ctx, agent->broadcast_val);

ret_val = JS_Call(ctx, agent->broadcast_func, JS_UNDEFINED,
Expand Down
16 changes: 16 additions & 0 deletions src/qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,21 @@ qjs_typed_array_data(JSContext *ctx, JSValueConst value, njs_str_t *data)
}


#ifdef NJS_HAVE_QUICKJS_SIZED_NEW_ARRAY_BUFFER
static void *
js_array_buffer_realloc(JSRuntime *rt, void *opaque, void *ptr, size_t size)
{
return js_realloc_rt(rt, ptr, size);
}


JSValue
qjs_new_array_buffer(JSContext *cx, uint8_t *src, size_t len)
{
return JS_NewArrayBuffer(cx, src, len, len, js_array_buffer_realloc,
NULL, 0);
}
#else
static void
js_array_buffer_free(JSRuntime *rt, void *opaque, void *ptr)
{
Expand All @@ -1264,6 +1279,7 @@ qjs_new_array_buffer(JSContext *cx, uint8_t *src, size_t len)
{
return JS_NewArrayBuffer(cx, src, len, js_array_buffer_free, NULL, 0);
}
#endif


JSValue
Expand Down
2 changes: 1 addition & 1 deletion src/qjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


enum {
QJS_CORE_CLASS_ID_BUFFER = 64,
QJS_CORE_CLASS_ID_BUFFER = 128,
QJS_CORE_CLASS_ID_UINT8_ARRAY_CTOR,
QJS_CORE_CLASS_ID_TEXT_DECODER,
QJS_CORE_CLASS_ID_TEXT_ENCODER,
Expand Down
Loading