Skip to content

API for accessing indexes on proxies of arrays #545

@jeffcharles

Description

@jeffcharles

Is there an API available where I can access an index property on an object that is not an array?

The context is we maintain a serde deserializer for RQuickJS values and we need to be able to deserialize a proxy of an array with a custom getter on the proxy.

The code looks like this:

var arrayProxy = new Proxy([], {
  get: function(_target, key) {
    if (key === 'length') return 2;
    return Number(key);
  },
});

This is part of the 262 test suite for JSON.stringify and for this particular test case, it should stringify arrayProxy as "[0, 1]".

Object does not appear to have a method that invokes JS_GetPropertyUint32 which is what Array uses for Array::get. When trying to represent arrayProxy as an Array, Value::is_array returns false and Value::as_array returns none so I can't convert arrayProxy into Array. With 0.6.1 (before the switch to quickjs-ng), is_array returned true and as_array returned an Array inside a Some.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:featureA request, idea or new functionalitytopic:interfaceRelated to safe abstractions over the primitives

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions