]> git.kaiwu.me - quickjs.git/commitdiff
raise an error if a private method is added twice to an object
authorFabrice Bellard <fabrice@bellard.org>
Wed, 13 Dec 2023 17:59:47 +0000 (18:59 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Wed, 13 Dec 2023 17:59:47 +0000 (18:59 +0100)
quickjs.c
test262_errors.txt

index 4c4d27323c56044725272a500262ff037babb428..58c638a2416870dab56e60dea1142529ffe496de 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -7336,6 +7336,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)
index e9462dd498054d6a0deea97c23133929b801f982..e4f6c8b72944bc99c9c9dc6634342575e95d9abb 100644 (file)
@@ -29,13 +29,5 @@ test262/test/language/statements/async-generator/yield-star-promise-not-unwrappe
 test262/test/language/statements/async-generator/yield-star-promise-not-unwrapped.js:25: strict mode: TypeError: $DONE() not called
 test262/test/language/statements/async-generator/yield-star-return-then-getter-ticks.js:131: TypeError: $DONE() not called
 test262/test/language/statements/async-generator/yield-star-return-then-getter-ticks.js:131: strict mode: TypeError: $DONE() not called
-test262/test/language/statements/class/elements/private-method-double-initialisation-get-and-set.js:33: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation-get-and-set.js:33: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation-get.js:32: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation-get.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation-set.js:32: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation-set.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation.js:32: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
-test262/test/language/statements/class/elements/private-method-double-initialisation.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
 test262/test/language/statements/for-of/head-lhs-async-invalid.js:14: unexpected error type: Test262: This statement should not be evaluated.
 test262/test/language/statements/for-of/head-lhs-async-invalid.js:14: strict mode: unexpected error type: Test262: This statement should not be evaluated.