unable get string length

Đang mở
#88 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp, node.js
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)

Ngôn ngữ chính
C++
Star
2.6k
Fork
602
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nodejs/node-addon-examples

Tất cả issue của nodejs/node-addon-examples

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.