From: Fabrice Bellard Date: Sat, 21 Nov 2026 16:07:34 +0000 (+0100) Subject: Fix Function.prototype.toString for a revoked proxy (bardrop) X-Git-Url: https://git.kaiwu.me/http/ngx_http_access_module.html?a=commitdiff_plain;h=7e59fe807dc22177183efac1bf4a83f7f7b759aa;p=quickjs.git Fix Function.prototype.toString for a revoked proxy (bardrop) --- diff --git a/quickjs.c b/quickjs.c index 1544e4f..7d48a7d 100644 --- a/quickjs.c +++ b/quickjs.c @@ -42613,7 +42613,10 @@ static JSValue js_function_toString(JSContext *ctx, JSValueConst this_val, break; } suff = "() {\n [native code]\n}"; - name = JS_GetProperty(ctx, this_val, JS_ATOM_name); + if (p->class_id == JS_CLASS_PROXY) + name = JS_UNDEFINED; + else + name = JS_GetProperty(ctx, this_val, JS_ATOM_name); if (JS_IsUndefined(name)) name = JS_AtomToString(ctx, JS_ATOM_empty_string); return JS_ConcatString3(ctx, pref, name, suff); diff --git a/tests/test_builtin.js b/tests/test_builtin.js index 7fcc4bd..9c647d1 100644 --- a/tests/test_builtin.js +++ b/tests/test_builtin.js @@ -119,6 +119,20 @@ function test_function() g = constructor1.bind(null, 1); r = new g(); assert(r.x, 1); + + // a callable proxy stays callable after revoke, so toString works + var native = "function () {\n [native code]\n}"; + g = Proxy.revocable(function f() {}, {}); + g.revoke(); + assert(Function.prototype.toString.call(g.proxy), native); + // and it does not read "name" through the proxy + var keys = []; + g = new Proxy(function f() {}, { + get(t, k) { keys.push(k); return Reflect.get(t, k); } + }); + assert(Function.prototype.toString.call(g), native); + assert(keys.length, 0); + assert_throws(TypeError, () => Function.prototype.toString.call(new Proxy({}, {}))); } function test()