2

In the context of N-API node_api.h, what is the maining of the field code of the function napi_throw_type_error? The documentation only says "Optional error code to be set on the error.", usually what kind of data should this contain?

My function is working fine without this parameter, but I am thinking in pass the return code as a string there:

napi_value Node_GI_iDisplayScript(napi_env env, napi_callback_info info)
{
   napi_status status;
   size_t ulSize;

   size_t argc = 1;
   napi_value argv[4];

   status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
   if (status != napi_ok) RETURN_ERROR(status);

   if (argc < 1) {
      napi_throw_type_error(env, NULL, "Wrong number of arguments");
      return NULL;
   }

   char szScript[20000];
   status = napi_get_value_string_latin1(env, argv[0], szScript, sizeof(szScript), &ulSize);
   if (status != napi_ok) RETURN_ERROR(status);

   int iRet = GI_iDisplayScript(szScript);
   if (iRet) {
      // char szErrorCode[50];
      // sprintf(szErrorCode, "%d", iRet);
      napi_throw_type_error(env, NULL /* szErrorCode */, "Invalid script");
      return NULL;
   }

   napi_value value;
   unsigned char *data;
   status = napi_create_arraybuffer(env, gulSize, (void **) &data, &value);
   if (status != napi_ok) RETURN_ERROR(status);
   memcpy(data, gpvbBmp, gulSize);

   return value;
}

Is this an acceptable use?

0 Answers0