unable get string length

Aperta
#88 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp, node.js
Ambito
backend

Direzione di ricerca

Start with the napi_get_value_string_utf8 call in the addon method and tests/1-test.js; compare the shown invocation with the API's expected arguments. Run the hello test and confirm the echo path obtains the string length without reporting an error.

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

Descrizione

I am now testing for echo function,

for code

napi_value Method(napi_env env, napi_callback_info args)
{
  // napi_value str;
  napi_status status;
  cout << "inside method!" << endl;

  size_t argc = 0;
  napi_value argv[1];
  status = napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr);

  if (status != napi_ok)
  {
    napi_throw_error(env, NULL, "Error Get Parameters!");
    return nullptr;
  }
  cout << "before argc!" << endl;

  if (argc < 1)
  {
    cout << "" << endl;
    return nullptr;
  }
  size_t strlen;
  status = napi_get_value_string_utf8(env, argv[0], NULL, 0, &strlen);
  if (status != napi_ok)
  {
    napi_throw_error(env, NULL, "Error Get String Length!");

    return nullptr;
  }
  // status = napi_create_string_utf8(env, argv[0], NAPI_AUTO_LENGTH, res);
  // if (status != napi_ok)
  // {
  //   napi_throw_error(env, NULL, "Error Get String!");
  //   return nullptr;
  // }
  return nullptr;
}

and

  status = napi_set_named_property(env, exports, "echo", fn);

and

 echo('hello!')

,

I got:

inside method!
before argc!
before get string!
�"�d2
    1) hello


  0 passing (11ms)
  1 failing

  1) crypto
       hello:
     Error: Error Get String Length!
      at Context.it (tests/1-test.js:4:24)

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

Guida per i contributori

Apri la guida per i contributori

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.