Skip to content
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

Is it addon must put one parameter at least? #159

Open
webbery opened this issue Oct 3, 2020 · 6 comments
Open

Is it addon must put one parameter at least? #159

webbery opened this issue Oct 3, 2020 · 6 comments

Comments

@webbery
Copy link

webbery commented Oct 3, 2020

Hi,

I got this error when I passed none paramter in my addon function:

#
# Fatal error in , line 0
# Check failed: receiver.IsJSFunction().
#
#
#
#FailureMessage Object: 0000008C4ABCEC60
 1: 00007FF66745D1EF napi_wrap+113103
 2: 00007FF66739334F v8::internal::wasm::JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit+258639
 3: 00007FF667DD8E64 V8_Fatal+212
 4: 00007FF6679725D8 v8::internal::JSReceiver::GetCreationContext+360
 5: 00007FF667BFED00 v8::Object::CreationContext+32
 6: 00007FF66747D6C8 node::MakeCallback+40
 7: 00007FF9B44651BF Nan::AsyncResource::runInAsyncScope+175 [E:\code\nodejs\civet\caxios\node_modules\nan\nan.h]:L612
 8: 00007FF9B4465719 Nan::Callback::Call_+153 [E:\code\nodejs\civet\caxios\node_modules\nan\nan.h]:L1806
...

But if I put one parameter it was work.

await getFilesSnap()  // not work
await getFilesSnap(0) // word

My C++ code like this:

exports->Set(context, 
    String::NewFromUtf8(isolate, getFilesSnap, v8::NewStringType::kNormal) 
    .ToLocalChecked(), 
    v8::FunctionTemplate::New(isolate, getFilesSnap, external) 
    ->GetFunction(context).ToLocalChecked()).FromJust();

I google none of infomation about how to pass none parameter in my function. If you have any link, please tell me.
Thank you.

@helio-frota
Copy link
Contributor

hi @webbery I'm not sure if the example of function arguments may help?: https://github.com/nodejs/node-addon-examples/tree/master/2_function_arguments/node-addon-api

@webbery
Copy link
Author

webbery commented Oct 6, 2020

@helio-frota Thanks. That's not I need. I need function like this:

// js
getAllData();
// C++
void getAllData(const v8::FunctionCallbackInfo<v8::Value>&){
 std::cout<<"getAllData"<<std::endl;
}

But in order to work, I must call it like this:

// js
getAllData(0); // must put 0 or other value to avoid runtime error

@helio-frota
Copy link
Contributor

helio-frota commented Oct 6, 2020

That's is weird, I'm still learning n-api btw. I have a working example here: https://github.com/helio-frota/sandwich/
That is nothing but TS calling JS that calls C++ (n-api) that calls C and not using any extra function parameter in order to work.
JS calling the N-api part here: https://github.com/helio-frota/sandwich/blob/master/jsPart.js#L5

I hope this help in some way

@NickNaso
Copy link
Member

NickNaso commented Oct 6, 2020

@webbery is your code public?

@helio-frota
Copy link
Contributor

helio-frota commented Oct 7, 2020

@webbery you can also trust on the example I shared because it was double checked and fixed by @NickNaso 😎

@webbery
Copy link
Author

webbery commented Oct 8, 2020

Here is my code:
https://github.com/webbery/civet/tree/master/caxios
The problem function is getFilesSnap in interface.cpp. I want to call it with getFilesSnap() but getFilesSnap( **anything_except_void** ) can work.
Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants