Use getOwnPropertyNames for tab completion in js testing shell

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • DevProd Correctness
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      We currently use Object.keySet() which only includes enumerable properties. Given that a lot of interesting properties, especially on built-in types, are not enumerable, we should use Object.getOwnPropertyNames() instead. We should also recursively walk the prototype chain using Object.getPrototypeOf() rather than just assuming that there is at most one prototype.

      As an example, here is what tab completion on Object.<TAB> returns today:

      > Object.
      Object.apply(                     Object.create(                    Object.freeze(                    Object.isExtensible(              Object.merge(                     Object.toLocaleString(
      Object.bind(                      Object.deepMerge(                 Object.getOwnPropertyDescriptor(  Object.isFrozen(                  Object.preventExtensions(         Object.toString(
      Object.bsonsize(                  Object.defineProperties(          Object.getOwnPropertyNames(       Object.isSealed(                  Object.propertyIsEnumerable(      Object.valueOf(
      Object.call(                      Object.defineProperty(            Object.getPrototypeOf(            Object.keySet(                    Object.prototype
      Object.constructor                Object.extend(                    Object.hasOwnProperty(            Object.keys(                      Object.seal(
      

      Note that it is missing some things including entries and fromEntries:

      > Object.getOwnPropertyNames(Object).sort()
      [
              "assign",
              "create",
              "deepMerge",
              "defineProperties",
              "defineProperty",
              "entries",
              "extend",
              "freeze",
              "fromEntries",
              "getOwnPropertyDescriptor",
              "getOwnPropertyDescriptors",
              "getOwnPropertyNames",
              "getOwnPropertySymbols",
              "getPrototypeOf",
              "groupBy",
              "hasOwn",
              "is",
              "isExtensible",
              "isFrozen",
              "isSealed",
              "keySet",
              "keys",
              "length",
              "merge",
              "name",
              "preventExtensions",
              "prototype",
              "seal",
              "setPrototypeOf",
              "values"
      ]
      > Object.getOwnPropertyNames(Object.getPrototypeOf(Object)).sort()
      [
              "apply",
              "arguments",
              "bind",
              "call",
              "caller",
              "constructor",
              "length",
              "name",
              "toString"
      ]
      

      For comparison, here is what node returns:

      > Object.
      Object.__proto__                  Object.hasOwnProperty             Object.isPrototypeOf
      Object.propertyIsEnumerable       Object.toLocaleString             Object.valueOf
      
      Object.apply                      Object.arguments                  Object.bind
      Object.call                       Object.caller                     Object.constructor
      Object.toString
      
      Object.assign                     Object.create                     Object.defineProperties
      Object.defineProperty             Object.entries                    Object.freeze
      Object.fromEntries                Object.getOwnPropertyDescriptor   Object.getOwnPropertyDescriptors
      Object.getOwnPropertyNames        Object.getOwnPropertySymbols      Object.getPrototypeOf
      Object.groupBy                    Object.hasOwn                     Object.is
      Object.isExtensible               Object.isFrozen                   Object.isSealed
      Object.keys                       Object.length                     Object.name
      Object.preventExtensions          Object.prototype                  Object.seal
      Object.setPrototypeOf             Object.values
      

      The code to implement autocomplete is here. If we used getOwnPropertyNames, we could probably get rid of the hard-coded lists of extra properties which we don't seem to be good at keeping up to date.

            Assignee:
            Unassigned
            Reporter:
            Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: