Methods not returning after throwing Javascript exception

Aberta
#89 2 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
38/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
cpp, nodejs
Domínio
api, backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
C++
Estrelas
2.6k
Forks
602
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de nodejs/node-addon-examples

Todas as issues de nodejs/node-addon-examples

Issues semelhantes

Mais issues de C++

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.