X Tutup
The Wayback Machine - https://web.archive.org/web/20201231111859/https://github.com/nodejs/node-addon-examples/issues/58
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

Make callback with buffer as argument #58

Open
g00dnatur3 opened this issue Sep 22, 2016 · 0 comments
Open

Make callback with buffer as argument #58

g00dnatur3 opened this issue Sep 22, 2016 · 0 comments

Comments

@g00dnatur3
Copy link

@g00dnatur3 g00dnatur3 commented Sep 22, 2016

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!

@g00dnatur3 g00dnatur3 changed the title Make callback with buffer as parameter Make callback with buffer as argument Sep 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup