Description
Currently, ObjectWrap<T>::ConstructorCallbackWrapper
has a guard against calling the constructor as a javascript function without the "new" keyword (TypeError: Class constructors cannot be invoked without 'new'
). In a pure Javascript project, or in a non node-addon-api
native project, it is possible to trap this sort of scenario and do something special other than abort -- often simply re-call the function as a constructor and return the new object, but potentially other clever things too.
If we could change the ObjectWrap<T>::ConstructorCallbackWrapper
implementation to delegate to an overridable public static method when !isConstructCall
rather than always aborting (e.g. Value T::NonConstructFunction(const Napi::CallbackInfo& info)
with a default implementation that throws the usual TypeError
), that would allow for more flexibility in porting older modules to use node-addon-api
without changing their existing semantics.