Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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

This comment has been minimized.

Copy link

commented Mar 4, 2014

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

This comment has been minimized.

Copy link

commented Mar 4, 2014

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
You can’t perform that action at this time.