Giter Site home page Giter Site logo

Comments (2)

avih avatar avih commented on September 28, 2024

@sebras referred me to the pending patch here http://git.ghostscript.com/?p=user/tor/mujs.git;a=commitdiff;h=483bd4ffff410c828b8d87f7e08941d6bbb270ae :

--- a/jsobject.c
+++ b/jsobject.c
@@ -380,6 +380,13 @@ static void O_keys(js_State *J)
                        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_pushnumber(J, k);
+                       js_setindex(J, -2, i++);
+               }
+       }
 }
 
 static void O_preventExtensions(js_State *J)

I think this patch produces an array of numbers, e.g. [0, 1...] instead of strings ["0", "1"...].

While at it, looks like the code just above above the patch which produces keys for a string object, like Object.keys(new String("foo")), has the same issue where it returns an array of numbers instead of strings:

mujs/jsobject.c

Lines 379 to 384 in 7d9888b

if (obj->type == JS_CSTRING) {
for (k = 0; k < obj->u.s.length; ++k) {
js_pushnumber(J, k);
js_setindex(J, -2, i++);
}
}

from mujs.

avih avatar avih commented on September 28, 2024

More while at it regarding Object.keys, seems like Object.keys([1,,2]) is non-flat (OK so far), returns ["0", "1", "2"], but Firefox returns ["0", "2"].

I don't know whether that's an ES5.1 vs newer JS version, but if not, then it's another issue.

EDIT: actually, Object.keys([1,,2]) currently returns [] (empty - bug). The results above of ["0", "1", "2"] are before the flat-array commit (also a bug).

from mujs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.