From eda269a073e33bdeb884b7c93d2fe52752ab4786 Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 2 Feb 2025 17:26:17 +0100 Subject: [PATCH] Expose JS_NewCFunction3 Useful if you want to set the prototype of a constructor to its parent constructor when creating a custom type hierarchy. (e.g. in browsers, `Text.__proto__` == `CharacterData`, and to implement this you can pass the `CharacterData` constructor as `proto_val`.) --- quickjs.c | 8 ++++---- quickjs.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/quickjs.c b/quickjs.c index bb2491d8a..71c87e85c 100644 --- a/quickjs.c +++ b/quickjs.c @@ -5242,10 +5242,10 @@ static int js_method_set_properties(JSContext *ctx, JSValue func_obj, /* Note: at least 'length' arguments will be readable in 'argv' */ /* `name` may be NULL, pure ASCII or UTF-8 encoded */ -static JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func, - const char *name, - int length, JSCFunctionEnum cproto, int magic, - JSValue proto_val) +JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func, + const char *name, + int length, JSCFunctionEnum cproto, int magic, + JSValue proto_val) { JSValue func_obj; JSObject *p; diff --git a/quickjs.h b/quickjs.h index b54154c7d..d515242ea 100644 --- a/quickjs.h +++ b/quickjs.h @@ -1006,6 +1006,10 @@ typedef union JSCFunctionType { JS_EXTERN JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func, const char *name, int length, JSCFunctionEnum cproto, int magic); +JS_EXTERN JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func, + const char *name, + int length, JSCFunctionEnum cproto, int magic, + JSValue proto_val); JS_EXTERN JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func, int length, int magic, int data_len, JSValue *data);