summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2022-12-21 18:57:24 +0100
committerTor Andersson <tor.andersson@artifex.com>2023-01-05 15:48:28 +0100
commit32f3e71169acdf4955b859f68c128b2c6c3635f5 (patch)
tree87216418e5c8ab2521f43d474593a021c74eed77
parent2e2738b2930ccb0fbd04a37f6f214f9967b33a88 (diff)
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.
-rw-r--r--jsobject.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/jsobject.c b/jsobject.c
index b93a663..832d4ba 100644
--- a/jsobject.c
+++ b/jsobject.c
@@ -361,6 +361,7 @@ static int O_keys_walk(js_State *J, js_Property *ref, int i)
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 @@ static void O_keys(js_State *J)
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++);
}
}