Skip to content

JS_AddIntrinsicBigInt regression #1669

Closed

Description

@bnoordhuis

The test below currently fails like this:

Object leaks:
       ADDRESS REFS SHRF          PROTO      CLASS PROPS
    0x29d3d650    1   0      0x29d59410     Object { toString: [autoinit 0x29d3f068 2 0x96da70], valueOf: [autoinit 0x29d3f068 2 0x96da90], Symbol.toStringTag: [autoinit 0x29d3f068 2 0x96dab0], constructor: [Function 0x29d3d6a0] }
api-test: /home/bnoordhuis/src/quickjs/quickjs.c:2704: JS_FreeRuntime: Assertion `list_empty(&rt->gc_obj_list)' failed.

JS_AddIntrinsicBaseObjects calls JS_AddIntrinsicBigInt.

if (JS_HasProperty(ctx, ctx->global_obj, JS_ATOM_BigInt)) return 0; before the JS_NewCConstructor call in JS_AddIntrinsicBigInt makes the problem go away.

It suggests JS_NewCConstructor leaks something when the property already exists, although it's not immediately obvious what.

diff --git a/api-test.c b/api-test.c
index ff722d4..d2d2598 100644
--- a/api-test.c
+++ b/api-test.c
@@ -1849,6 +1849,16 @@ void object_from(void)
     JS_FreeRuntime(rt);
 }
 
+void add_intrinsic_bigint(void)
+{
+    JSRuntime *rt = new_runtime();
+    JSContext *ctx = JS_NewContextRaw(rt);
+    JS_AddIntrinsicBaseObjects(ctx);
+    JS_AddIntrinsicBigInt(ctx);
+    JS_FreeContext(ctx);
+    JS_FreeRuntime(rt);
+}
+
 int main(void)
 {
     cfunctions();
@@ -1883,5 +1893,6 @@ int main(void)
     resize_external_array_buffer();
     transfer_default_managed_array_buffer();
     object_from();
+    add_intrinsic_bigint();
     return 0;
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions