-
-
Notifications
You must be signed in to change notification settings - Fork 477
v8::FunctionTemplate inherit to Napi #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
Hi everyone, |
But the method is invalid in 'super class' when I call with javascript. How can I fix it? (When I call the super method, then print error message: "TypeError: Illegal invocation") |
@iclosure can you show me the code? |
|
Hi @gabrielschulhof Exists the "clearData" function in sub-class, but cannot be called. Because of it's a native code? Why? |
@iclosure I have reproduced the problem. I'll try and find the reason. |
// ES6 notation
class SuperClass {
constructor() {
console.log("SuperClass constructor");
}
superclassMethod() {
console.log("SuperClass method");
}
}
class SubClass extends SuperClass {
constructor() {
super();
console.log("SubClass constructor");
}
}
const x = new SubClass();
x.superclassMethod();
// Old style
const OldSuperClass = function OldSuperClass() {
console.log("OldSuperClass constructor");
};
OldSuperClass.prototype.oldsuperclassMethod = function oldsuperclassMethod() {
console.log("OldSuperClass method");
};
const OldSubClass = function OldSubClass() {
OldSuperClass.apply(this, arguments);
console.log("OldSubClass constructor");
};
Object.setPrototypeOf(OldSubClass.prototype, OldSuperClass.prototype);
Object.setPrototypeOf(OldSubClass, OldSuperClass);
const y = new OldSubClass();
y.oldsuperclassMethod();
// Native
const addon = require('./build/Release/inheritance.node');
const z = new addon.Subclass();
z.superclassMethod(); // <-- Throws illegal invocation error |
I think there's a bug in
then the call from JS gets routed correctly to the native method. |
OK, so it's not retrieving the |
A link to that commit: nodejs/node@08a5b442e4 |
@gabrielschulhof Has any solution for this? :) |
@iclosure there is no easy solution, because, in order to do it properly, we'd need to be able to retrieve the Either way, implementing this without the support of the V8 folks would result in pretty limited support. |
@iclosure with V8 as it is now, we could only support inheritance if both the parent class and the child class were created using N-API. |
Get it,Thanks!😊 |
@iclosure ok if we close this issue now? |
Uh oh!
There was an error while loading. Please reload this page.
Can we implement v8::FunctionTemplate::Inherit in Napi ?
The text was updated successfully, but these errors were encountered: