Repository: quickjs-ng/quickjs (2025-06-24T20:23:51Z)

Issue:
Cannot extend TypedArray
This should work:
```js
var TypedArray = Object.getPrototypeOf(Uint8Array)
var MyClass = class extends TypedArray {} // throws "TypeError: parent class must be constructor"
```
`TypedArray` is not expected to be instantiable (it's abstract) but it should be extendable. Upcoming test262 tests depend on that.


Discussion:

Patch:
diff --git a/quickjs.c b/quickjs.c
index 8b9a3b573..01eb10123 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -57144,6 +57144,7 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
                                js_typed_array_base_funcs,
                                countof(js_typed_array_base_funcs));
     JS_SetConstructor(ctx, typed_array_base_func, typed_array_base_proto);
+    JS_SetConstructorBit(ctx, typed_array_base_func, true);
 
     /* Used to squelch a -Wcast-function-type warning. */
     JSCFunctionType ft = { .generic_magic = js_typed_array_constructor };


Test patch:
diff --git a/tests/test_builtin.js b/tests/test_builtin.js
index 3c37f5930..2e86cb4a2 100644
--- a/tests/test_builtin.js
+++ b/tests/test_builtin.js
@@ -569,6 +569,16 @@ function test_typed_array()
     assert(a.buffer, b.buffer);
     assert(a.toString(), "0,0,0,255");
     assert(b.toString(), "0,0,255,255");
+
+    const TypedArray = class extends Object.getPrototypeOf(Uint8Array) {};
+    let caught = false;
+    try {
+        new TypedArray(); // extensible but not instantiable
+    } catch (e) {
+        assert(/cannot be called/.test(e.message));
+        caught = true;
+    }
+    assert(caught);
 }
 
 function test_json()