From c842af1bd5e80b40ea83edb040c864aba8c299c6 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Wed, 13 Dec 2023 18:59:47 +0100 Subject: raise an error if a private method is added twice to an object --- lib/quickjs/quickjs.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/quickjs/quickjs.c') diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c index 2dbc4914..c68a8ab3 100644 --- a/lib/quickjs/quickjs.c +++ b/lib/quickjs/quickjs.c @@ -7456,6 +7456,12 @@ static int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst home_obj) return -1; } p1 = JS_VALUE_GET_OBJ(obj); + prs = find_own_property(&pr, p1, brand_atom); + if (unlikely(prs)) { + JS_FreeAtom(ctx, brand_atom); + JS_ThrowTypeError(ctx, "private method is already present"); + return -1; + } pr = add_property(ctx, p1, brand_atom, JS_PROP_C_W_E); JS_FreeAtom(ctx, brand_atom); if (!pr) -- cgit 1.4.1-2-gfad0