Skip to content

Instantly share code, notes, and snippets.

@anba
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anba/9352970 to your computer and use it in GitHub Desktop.
Save anba/9352970 to your computer and use it in GitHub Desktop.

Object.getOwnPropertyDescriptors(O)

When the getOwnPropertyDescriptors function is called, the following steps are taken:

  1. Let obj be ToObject(O).
  2. ReturnIfAbrupt(obj).
  3. Let keys be the result of calling the [[OwnPropertyKeys]] internal method of obj.
  4. ReturnIfAbrupt(keys).
  5. Let descriptors be the result of ObjectCreate(null).
  6. Let gotAllNames be false.
  7. Repeat while gotAllNames is false, 1. Let next be the result of IteratorStep(keys). 1. ReturnIfAbrupt( next ). 1. If next is false, then let gotAllNames be true. 1. Else,
    1. Let nextKey be IteratorValue(next).
    2. Let nextKey be ToPropertyKey(nextKey).
    3. ReturnIfAbrupt(nextKey).
    4. Let desc be the result of calling the [[GetOwnProperty]] internal method of obj with argument nextKey.
    5. ReturnIfAbrupt(desc).
    6. Let descriptor be FromPropertyDescriptor(desc).
    7. ReturnIfAbrupt(descriptor).
    8. Let status be the result of CreateDataProperty(descriptors, nextKey, descriptor).
    9. Assert: status is not an abrupt completion.
  8. Return descriptors.
@WebReflection
Copy link

yes, GetOwnPropertyKeys ( O, Type ) works perfectly for the goal, thanks !

One minor note on point 5, ObjectCreate(null) it's a nice to have but actually descriptors are accepted as generic Object and parsed through the hasOwnProperty check if enumerable, as specified here

@WebReflection
Copy link

ok, this version should be a no-brainer and the simpler I could think of for such specification. Thanks again, feel free to let me know if I forgot something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment