Open Sytten opened 4 months ago
IIRC the Buffer class extends Uint8Array.
Anyway. I think you can get the prototype with JS_GetPrototype and then add your custom methods.
Yes sorry Uint8Array
.
That would work for the prototype, I probably also need something for the constructor to call the parent one.
Good point. I'm not sure QuickJS provider the necessary APIs to do that... @chqrlie ?
I tried to use JS_GetClassProto
with the class id of Uint8Array
(12 at the moment), but it always returns an empty prototype for some reason. JS_GetPrototype
on the globals does return something though.
I was thinking of calling the prototype.constructor
function if that exists? I have not tested it yet.
In reality I am writing that for the rust library rquickjs so I need to massage it a bit more but I didn't want to add complexity to the example.
Calling constructor on the prototype might work indeed!
@saghul Sorry, cannot comment right now, travelling 1200 km from the North pole with very little Internet coverage :)
@chqrlie If you have time, still looking for guidance on it
Hi!
Does someone have an example of a C class extending a JS class? Essentially the inverse of the
Point
example.I am trying to re-create the node
Buffer
class in C and I want to extend theArrayBuffer
class.Thanks