From 8512cbdf15e65583042e83f87cb4f11703c95984 Mon Sep 17 00:00:00 2001 From: Samir Date: Sun, 20 Sep 2026 13:04:39 -0400 Subject: [PATCH] Ensure function prototype is propagated when bound --- quickjs.c | 10 +++++++++- tests/bug1732.js | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/bug1732.js diff --git a/quickjs.c b/quickjs.c index 6ca030b9f..0e2791f8b 100644 --- a/quickjs.c +++ b/quickjs.c @@ -42574,8 +42574,16 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val, if (check_function(ctx, this_val)) return JS_EXCEPTION; - func_obj = JS_NewObjectProtoClass(ctx, ctx->function_proto, + JSValue prototype = JS_GetPrototype(ctx, this_val); + + if (JS_IsException(prototype)) + return JS_EXCEPTION; + + func_obj = JS_NewObjectProtoClass(ctx, prototype, JS_CLASS_BOUND_FUNCTION); + + JS_FreeValue(ctx, prototype); + if (JS_IsException(func_obj)) return JS_EXCEPTION; p = JS_VALUE_GET_OBJ(func_obj); diff --git a/tests/bug1732.js b/tests/bug1732.js new file mode 100644 index 000000000..c9d755e68 --- /dev/null +++ b/tests/bug1732.js @@ -0,0 +1,3 @@ +import { assert } from "./assert.js"; +const f = (function* () {}).constructor("aa").bind() +assert(Object.prototype.toString.call(f) === "[object GeneratorFunction]", true); \ No newline at end of file