Skip to content

NapiClass constructor cannot be subclassed #172

Description

Filing so I remember to fix this

This currently impacts @resvg/resvg-js

module.exports.Resvg = class Resvg extends _Resvg {
  constructor(svg, options) {
     super(svg, JSON.stringify(options))

The problem in Bun is this code:

   NapiClass* napi = jsDynamicCast<NapiClass*>(newTarget);
    if (UNLIKELY(!napi)) {
        JSC::throwVMError(globalObject, scope, JSC::createTypeError(globalObject, "NapiClass constructor called on an object that is not a NapiClass"_s));
        return JSC::JSValue::encode(JSC::jsUndefined());
    }

That !napi is being returned because newTarget is a subclass of NapiClass.

Maybe the prototype needs to be checked instead? I'm not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnapiCompatibility with the native layer of Node.js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions