]> git.kaiwu.me - quickjs.git/commitdiff
fixed Function.prototype.bind prototype inheritance
authorFabrice Bellard <fabrice@bellard.org>
Tue, 29 Sep 2026 12:00:18 +0000 (14:00 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Tue, 29 Sep 2026 12:00:18 +0000 (14:00 +0200)
quickjs.c
test262_errors.txt

index b0395d750998ab2a4a6397093e6c9c95edddedef..19c05ed109fdb4585f9e96a2fc88034689fc978f 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -41494,15 +41494,19 @@ static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val,
                                 int argc, JSValueConst *argv)
 {
     JSBoundFunction *bf;
-    JSValue func_obj, name1, len_val;
+    JSValue func_obj, name1, len_val, proto;
     JSObject *p;
     int arg_count, i, ret;
 
     if (check_function(ctx, this_val))
         return JS_EXCEPTION;
 
-    func_obj = JS_NewObjectProtoClass(ctx, ctx->function_proto,
+    proto = JS_GetPrototype(ctx, this_val);
+    if (JS_IsException(proto))
+        return JS_EXCEPTION;
+    func_obj = JS_NewObjectProtoClass(ctx, proto,
                                  JS_CLASS_BOUND_FUNCTION);
+    JS_FreeValue(ctx, proto);
     if (JS_IsException(func_obj))
         return JS_EXCEPTION;
     p = JS_VALUE_GET_OBJ(func_obj);
index 5f2b43c3bab0473dee7811e4511e7613736c3536..47a07ead01e6f4cf54ab98b243618b71f13ce58b 100644 (file)
@@ -16,7 +16,6 @@ test262/test/staging/sm/Function/constructor-binding.js:11: Test262Error: Expect
 test262/test/staging/sm/Function/function-bind.js:24: Test262Error: Conforms to NativeFunction Syntax: "function bound unbound() {\n    [native code]\n}"
 test262/test/staging/sm/Function/implicit-this-in-parameter-expression.js:12: Test262Error: Expected SameValue(«[object Object]», «undefined») to be true
 test262/test/staging/sm/Function/invalid-parameter-list.js:13: Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all
-test262/test/staging/sm/class/boundFunctionSubclassing.js:9: Test262Error: Expected SameValue(«false», «true») to be true
 test262/test/staging/sm/class/strictExecution.js:13: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
 test262/test/staging/sm/class/superPropOrdering.js:17: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
 test262/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-arguments.js:13: Test262Error: Expected SameValue(«"object"», «"function"») to be true