Methods not returning after throwing Javascript exception

Abierto
#89 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp, nodejs
Área
api, backend

Línea de trabajo

Start in 6_object_wrap_example/node-addon-api/myobject.cc, especially the constructor path around line 28, and reproduce the no-argument call. Check the node-addon-api exception-handling guidance, then ensure the example stops after ThrowAsJavaScriptException so the documented error is preserved and the unwrapping case does not continue into a segmentation fault.

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

Descripción

In the "6_object_wrap_example/node-addon-api", I tried to test what would happen when calling the constructor without arguments and I noticed that the actual exception thrown ("A number was expected") is different from the one in the code ("Number expected").

According to node-addon-api docs, when C++ exceptions are disabled you need to return immediately after calling ThrowAsJavaScriptException. So I would expect something like:

if (length <= 0 || !info[0].IsNumber()) {
    Napi::TypeError::New(env, "Number expected").ThrowAsJavaScriptException();
    return;
}

I think that the exception thrown is not the one from line 28 of myobject.cc, but another one thrown automatically when trying to convert the parameter to a number.

I tried to move one step further (following this tutorial) and unwrapping a Javascript object, and I get a segmentation fault when using the constructor without arguments because the code is not stopping after reaching the line with ThrowAsJavaScriptException.

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.