unable get string length

Abierto
#88 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp, node.js
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)

Lenguaje dominante
C++
Estrellas
2.6k
Forks
602
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nodejs/node-addon-examples

Todos los issues de nodejs/node-addon-examples

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.