Object and partial ES5 support

Posted on
  • In Espruino Pico 1v76 I've noticed that Object.getOwnPropertyDescriptor is present, and returns a descriptor object, but everything else available in ES5 to actually define properties through descriptors is missing:

    Object.defineProperty;
    Object.defineProperties;
    Object.create(null, {test: {get: function () {return 123}}}).test;
    Object.create(null, {test: {value: 456}}).test;
    

    All these are undefined and I wonder why, at this point, Object.getOwnPropertyDescriptor is available. It kinda misleads features detection.

    As summary: is there any plan to bring the ability to define properties through descriptors, or, if not, could we just drop getOwnPropertyDescriptor so no code would be confused about its presence?

    Thanks!

  • Ahh - I think I'd added getOwnPropertyDescriptor possibly to enable some of the test262 tests to work. defineProperty is something I've been meaning to add (but not with high priority), but support will never be perfect as Espruino doesn't internally store some flags (enumerable/writable) on variables. It doesn't actually do getters/setters (yet) either.

    While you might use these functions for extending the language, I'd be surprised if that kind of stuff got used when actually 'doing stuff' with the microcontroller - hence it hasn't really taken priority.

  • I personally would be already happy with a fully compliant ES3 code-base but the fact Object.getOwnPropertyDescriptor is there, together with Object.getOwnPropertyNames, mislead me because if there's no way to define enumerability or descriptors these two look like impostors.

    That being said, I agree you usually go easy with micro controllers and JS, without bringing absurd alchemies in, but since Espruino supports and promotes the usage of modules, you surely know that module and imported API + getters/setters play usually very well, and give developers the ability to create code that is more pleasant to use.

    I just wanted to understand the rational behind those methods and I got it, I also hope those methods could make it without bloating too much the core.

    Regards

  • Thanks - yes, hopefully they will, but it's not a priority right now.

    I'd love to have getters and setters though - I don't believe it would be a massive amount of work.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Object and partial ES5 support

Posted by Avatar for WebReflection @WebReflection

Actions