Skip to content

About to create a external iterator for array and object #408

Closed
@Icemic

Description

@Icemic

I'm in the midst of implementing an external iterator for Arrays and Objects in JavaScript. As I'm diving into the code, I've noticed a couple of areas where we could use some enhancements by adding a few methods.

For Objects:
When working with Objects, I've been relying on JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab, uint32_t *plen, JSValue obj, int flags) to fetch the property list. However, there's currently no way to clean up the memory for ptab once we're done. So, I propose adding a method like this:

void JS_FreePropertyEnum(JSContext* ctx, JSPropertyEnum* tab, uint32_t len) {
    js_free_prop_enum(ctx, tab, len);
}

For Arrays:
Now, when it comes to Arrays, there's no direct method to retrieve the array's length without accessing the length property by string. It would be beneficial to introduce a method like this:

int JS_GetLength(JSContext* ctx, int64_t* pres, JSValueConst obj) {
    return js_get_length64(ctx, pres, obj);
}

And I've tested them using valgrind, no memory leak remained.

If it is ok, I'll make a pull request. Let me know if there's anything else you'd like to adjust!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions