Browse Source

Fix Proxy ownKeys() postprocess array index bug

Triggered when Array.prototype has index properties, e.g. a setter.
v2.6-maintenance
Sami Vaarala 4 years ago
parent
commit
fd04aedd18
  1. 4
      src-input/duk_bi_proxy.c
  2. 17
      tests/ecmascript/test-bug-proxy-ownkeys-arridx-inherit-gh2207.js

4
src-input/duk_bi_proxy.c

@ -63,7 +63,9 @@ DUK_INTERNAL void duk_proxy_ownkeys_postprocess(duk_hthread *thr, duk_hobject *h
}
/* [ obj trap_result res_arr propname ] */
duk_put_prop_index(thr, -2, idx++);
duk_push_uarridx(thr, idx++);
duk_insert(thr, -2);
duk_def_prop(thr, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_SET_WEC);
continue;
skip_key:

17
tests/ecmascript/test-bug-proxy-ownkeys-arridx-inherit-gh2207.js

@ -0,0 +1,17 @@
// https://github.com/svaarala/duktape/issues/2207
/*===
{"foo":0,"nonEnumerable":0}
done
===*/
Object.defineProperty(Array.prototype, 0, { set: function () { } });
function jsonStringifyOwnKeysProxyTest () {
target = { foo: 0, nonEnumerable: 0 };
proxy = new Proxy(target, { $: function () { }, ownKeys: function () { return [ 'foo', 'nonEnumerable' ] } });
print(String(JSON.stringify(proxy)));
}
jsonStringifyOwnKeysProxyTest();
print('done');
Loading…
Cancel
Save