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