You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm virtualizing an object as a duktape Proxy object but can't iterate or get all the keys in this object. When I try to get the object keys, I always get an empty array. Is there a solution or even a workaround to this?
duk_ret_tgetKeyFn(duk_context* ctx)
{
// Any key returns 1 just for the sake of the test.duk_idx_t arr_idx = duk_push_array(ctx); // [target] [key] [recv]duk_push_int(ctx, 1); // [target] [key] [recv] [int]return1;
}
When I try to get or iterate the keys, I get an empty array. I tried many ways of iterating these values (scripts, from C, etc), including the following:
duk_enum(ctx, -1, DUK_ENUM_OWN_PROPERTIES_ONLY); // this triggers ownKeysFnwhile (duk_next(ctx, -1, 1))
{
// This never executes:constchar * key = duk_get_string(ctx, -2); // [proxy] [key] [value]do_something_with_key(key);
duk_pop_2(ctx); // [proxy]
}
duk_pop(ctx);
I guess this issue could be related to #2153 but I'm not sure if the use cases are the same because I honestly don't completely understand that discussion since I'm not as fluent in JavaScript. If I understand that discussion correctly, do I need either to define getOwnPropertyDescriptor (which duktape doesn't support) or somehow define the keys explicitly (which breaks virtualization)? Is there a workaround to achieve virtualization somehow with duktape? #2153 issue is from 2019 so maybe some things have changed?
The text was updated successfully, but these errors were encountered:
Update: I tried another version where the target stores a "keys" property containing an array with the keys and ownKeysFn returns that array instead of creating it. Unfortunately, this doesn't work either.
It's an unreasonable solution anyway, but I thought ownKeysFn could update the keys in target whenever it's called. It would be a last-resort workaround.
I'm virtualizing an object as a duktape Proxy object but can't iterate or get all the keys in this object. When I try to get the object keys, I always get an empty array. Is there a solution or even a workaround to this?
I created a minimal example just in case:
where
and
When I try to get or iterate the keys, I get an empty array. I tried many ways of iterating these values (scripts, from C, etc), including the following:
I guess this issue could be related to #2153 but I'm not sure if the use cases are the same because I honestly don't completely understand that discussion since I'm not as fluent in JavaScript. If I understand that discussion correctly, do I need either to define getOwnPropertyDescriptor (which duktape doesn't support) or somehow define the keys explicitly (which breaks virtualization)? Is there a workaround to achieve virtualization somehow with duktape? #2153 issue is from 2019 so maybe some things have changed?
The text was updated successfully, but these errors were encountered: