Make callback with buffer as argument

Aperta
#58 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
cpp, nodejs
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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!

Lingua principale
C++
Stelle
2.6k
Fork
598
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/node-addon-examples

Tutte le issue di nodejs/node-addon-examples

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.