Make callback with buffer as argument
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
The relevant entry points are SetCallback and do_callback in the issue snippet; start by checking the NAN/V8 callback and Buffer APIs and reproduce the segmentation fault. Done means the callback reliably receives a Buffer, including the intended existing char pointer case, without crashing.
Written by the indexing model from the issue text.
Description
Hello,
I'm having trouble making a callback and passing a Buffer as the argument.
Look at the code here:
v8::Local<v8::Function> callback;
void SetCallback(const Nan::FunctionCallbackInfo<v8::Value>& info) {
callback = info[0].As<v8::Function>();
}
void do_callback() {
int size = 100;
v8::MaybeLocal<v8::Object> obj = Nan::NewBuffer(size);
const unsigned argc = 1;
args[1] = { obj.ToLocalChecked() };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), callback, argc, args);
}
I always get "segmentation fault" and I do not know why..
To keep the code simple I am just intializing a new Buffer with size only..
However i would like to intialize the Buffer with data like so:
char* data =...
v8::MaybeLocal<v8::Object> obj = Nan::NewBuffer(data, size);
My goal is to callback a javascript function with a Buffer that is wrapped around an existing char pointer..
Please help.
Thank you!
- Dominant language
- C++
- Stars
- 2.6k
- Forks
- 602
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nodejs/node-addon-examples
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
nodejs/node-addon-examples#585 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
nodejs/node-addon-examples#530 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
nodejs/node-addon-examples#445 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 32/100
nodejs/node-addon-examples#444 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
nodejs/node-addon-examples#381 ·
All issues in nodejs/node-addon-examples
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·