We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
new
Currently, when you declare a class, you can call it as a function:
// C++ v8pp::class_<MyClass> MyClass_class(isolate); MyClass_class.ctor<const FunctionCallbackInfo<Value>&>();
// JS const test1 = new addon.MyClass(10); // right way to do const test2 = addon.MyClass(10); // currently working, wrongly
test2 asssignation should cause an error:
test2
Uncaught TypeError: Class constructor MyClass cannot be invoked without 'new'
attempting to "call" a class without new will result in an error.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_classes#constructing_a_class
You can use IsConstructCall on v8::FunctionCallbackInfo to check if the class is instanciated with new here:
IsConstructCall
v8::FunctionCallbackInfo
v8pp/v8pp/class.hpp
Lines 225 to 228 in 5759d79
if(!args.IsConstructCall()) { // Throw type error: Uncaught TypeError: Class constructor %s cannot be invoked without 'new' return; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Summary
Currently, when you declare a class, you can call it as a function:
test2
asssignation should cause an error:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_classes#constructing_a_class
Possible solution
You can use
IsConstructCall
onv8::FunctionCallbackInfo
to check if the class is instanciated withnew
here:v8pp/v8pp/class.hpp
Lines 225 to 228 in 5759d79
The text was updated successfully, but these errors were encountered: