Skip to content

Document ownership rules of C API #944

Open
@bnoordhuis

Description

@bnoordhuis

Example: it's not really documented anywhere that JS_SetProperty(ctx, obj, key, val) takes ownership of val but not key. One must call JS_FreeAtom(ctx, key) afterwards but not JS_FreeValue(ctx, val).

Another example of an undocumented constraint: you should not JS_FreeValue the elements of the argv array to your C callback. But you should JS_FreeValue the return value of JS_GetProperty(ctx, obj, key). Here too, one must JS_FreeAtom(ctx, key).

Neither is it documented that the first length elements of argv are valid (set to undefined) when JS calls a C function with too few arguments. Or that argc can be greater than length - which makes perfect sense but is undocumented.

Should probably go into docs/docs/developer-guide/api.md?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions