| 541 | } |
| 542 | |
| 543 | napi_value findLastAPI(napi_env env, napi_callback_info info) { |
| 544 | size_t argc = 2; |
| 545 | napi_value args[2]; |
| 546 | napi_get_cb_info(env, info, &argc, args, NULL, NULL); |
| 547 | |
| 548 | // Get buffer info for haystack (zero-copy) |
| 549 | void *haystack_data; |
| 550 | size_t haystack_length; |
| 551 | napi_status status = napi_get_buffer_info(env, args[0], &haystack_data, &haystack_length); |
| 552 | if (status != napi_ok) { |
| 553 | napi_throw_error(env, NULL, "First argument must be a Buffer"); |
| 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | // Get buffer info for needle (zero-copy) |
| 558 | void *needle_data; |
| 559 | size_t needle_length; |
| 560 | status = napi_get_buffer_info(env, args[1], &needle_data, &needle_length); |
| 561 | if (status != napi_ok) { |
| 562 | napi_throw_error(env, NULL, "Second argument must be a Buffer"); |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | // Convert the result to JavaScript BigInt and return |
| 567 | napi_value js_result; |
| 568 | if (needle_length == 0) { napi_create_bigint_int64(env, haystack_length, &js_result); } |
| 569 | else { |
| 570 | sz_cptr_t result = sz_rfind((sz_cptr_t)haystack_data, haystack_length, (sz_cptr_t)needle_data, needle_length); |
| 571 | |
| 572 | // In JavaScript, if `lastIndexOf` is unable to find the specified value, then it should return -1 |
| 573 | if (result == NULL) { napi_create_bigint_int64(env, -1, &js_result); } |
| 574 | else { napi_create_bigint_uint64(env, result - (sz_cptr_t)haystack_data, &js_result); } |
| 575 | } |
| 576 | |
| 577 | return js_result; |
| 578 | } |
| 579 | |
| 580 | napi_value findByteAPI(napi_env env, napi_callback_info info) { |
| 581 | size_t argc = 2; |
nothing calls this directly
no test coverage detected
searching dependent graphs…