Skip to content

Initial nodejs string wrap #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main-dev
Choose a base branch
from

Conversation

MarkReedZ
Copy link
Contributor

I've created a Str object wrapper for Node.js

    const a = new stringzilla.Str('hello world');
    const b = new stringzilla.Str('hi');

    const result_1 = a.count(b);

And implemented a few functions with tests.

        {"indexOf", NULL, str_find, NULL, NULL, NULL, napi_default, NULL},
        {"find", NULL, str_find, NULL, NULL, NULL, napi_default, NULL},
        {"rfind", NULL, str_rfind, NULL, NULL, NULL, napi_default, NULL},
        {"startswith", NULL, str_startswith, NULL, NULL, NULL, napi_default, NULL},
        {"endswith", NULL, str_endswith, NULL, NULL, NULL, napi_default, NULL},
        {"count", NULL, str_count, NULL, NULL, NULL, napi_default, NULL}

@ashvardanian ashvardanian force-pushed the main-dev branch 2 times, most recently from 430f05e to f7e4c05 Compare August 5, 2024 21:01
@ashvardanian ashvardanian force-pushed the main-dev branch 4 times, most recently from 19e6998 to 4e33434 Compare October 17, 2024 06:39
sz_wrapper_t *this;
sz_wrapper_t *arg;

napi_get_cb_info(env, info, &argc, args, &jsthis, NULL);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for napi_get_cb_info call. The function returns napi_status which should be checked. If it fails, the function could proceed with invalid args/jsthis values. Should check return value and handle error cases.

📚 Relevant Docs


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

size_t argc = 1;
napi_value args[1];
napi_value jsthis;
sz_wrapper_t *obj = malloc(sizeof(sz_wrapper_t));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No NULL check after malloc. If allocation fails, the function continues with an invalid pointer which could cause a crash. Should check if obj is NULL and handle the error case appropriately.


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

@@ -2,7 +2,7 @@ import test from 'node:test';
import bindings from 'bindings';
import assert from 'node:assert';

const stringzilla = bindings('stringzilla');
const stringzilla = bindings('../../build/Release/stringzilla');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a relative path ('../../build/Release/stringzilla') with the 'bindings' module is incorrect and could cause module resolution failures. The 'bindings' module is designed to automatically locate native addons and should be used with just the module name. The original code using bindings('stringzilla') was correct. The change to a relative path breaks the standard module resolution mechanism and could fail when the package is installed in different locations.

📚 Relevant Docs


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

Copy link

recurseml bot commented May 2, 2025

😱 Found 3 issues. Time to roll up your sleeves! 😱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant