Skip to content

Change JS_IsArray to not transparently detect proxies #938

@bnoordhuis

Description

@bnoordhuis

JS_IsArray currently has this prototype:

/* return -1 if exception (proxy case) or true/false */ 
int JS_IsArray(JSContext *ctx, JSValue val)

That's jarringly different from JS_IsObject/JS_IsPromise/etc. and returning a ternary instead of a boolean like the other functions is a bug magnet.

The reason it takes a JSContext pointer as its first argument is because it transparently handles proxies and guards against stack overflow in case the proxy's target object loops back on itself.

I don't think it should try to handle proxies because that's inconsistent. Neither JS_IsObject or JS_IsPromise do that, for example.

My proposal:

  1. definitely remove proxy handling from JS_IsArray

  2. optionally add a JS_IsProxy function and maybe JS_GetProxyTarget + JS_GetProxyHandler?

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