ref: 32f3e71169acdf4955b859f68c128b2c6c3635f5
parent: 2e2738b2930ccb0fbd04a37f6f214f9967b33a88
author: Tor Andersson <tor.andersson@artifex.com>
date: Wed Dec 21 13:57:24 EST 2022
Issue #171: Fix Object.keys implementation for flat arrays and strings. Object.keys was not producing keys for the array part of a flat array. It was also producing an array of numbers rather than strings for string objects.
--- a/jsobject.c
+++ b/jsobject.c
@@ -361,6 +361,7 @@
static void O_keys(js_State *J)
{
js_Object *obj;
+ char name[32];
int i, k;
if (!js_isobject(J, 1))
@@ -376,7 +377,16 @@
if (obj->type == JS_CSTRING) {
for (k = 0; k < obj->u.s.length; ++k) {
- js_pushnumber(J, k);
+ js_itoa(name, k);
+ js_pushstring(J, name);
+ js_setindex(J, -2, i++);
+ }
+ }
+
+ if (obj->type == JS_CARRAY && obj->u.a.simple) {
+ for (k = 0; k < obj->u.a.flat_length; ++k) {
+ js_itoa(name, k);
+ js_pushstring(J, name);
js_setindex(J, -2, i++);
}
}