Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active August 29, 2015 14:01
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 WebReflection/48aecb771e61e8a3e168 to your computer and use it in GitHub Desktop.
Save WebReflection/48aecb771e61e8a3e168 to your computer and use it in GitHub Desktop.
ToPropertyDescriptor ( Obj )

proposal identical to current ES5-6 one except [[HasOwnProperty]] is used instead

ToPropertyDescriptor

When the abstract operation ToPropertyDescriptor is called with object Obj, the following steps are taken:

  1. ReturnIfAbrupt(Obj).
  2. If Type(Obj) is not Object throw a TypeError exception.
  3. Let desc be a new Property Descriptor that initially has no fields.
  4. If HasOwnProperty(Obj, "enumerable") is true, then
    1. Let enum be Get(Obj, "enumerable").
    2. ReturnIfAbrupt(enum).
    3. Set the [[Enumerable]] field of desc to ToBoolean(enum).
  5. If HasOwnProperty(Obj, "configurable") is true, then
    1. Let conf be Get(Obj, "configurable").
    2. ReturnIfAbrupt(conf).
    3. Set the [[Configurable]] field of desc to ToBoolean(conf).
  6. If HasOwnProperty(Obj, "value") is true, then
    1. Let value be Get(Obj, "value").
    2. ReturnIfAbrupt(value).
    3. Set the [[Value]] field of desc to value.
  7. If HasOwnProperty(Obj, "writable") is true, then
    1. Let writable be Get(Obj, "writable").
    2. ReturnIfAbrupt(writable).
    3. Set the [[Writable]] field of desc to ToBoolean(writable).
  8. If HasOwnProperty(Obj, "get") is true, then
    1. Let getter be Get(Obj, "get").
    2. ReturnIfAbrupt(getter).
    3. If IsCallable(getter) is false and getter is not undefined, then throw a TypeError exception.
    4. Set the [[Get]] field of desc to getter.
  9. If HasOwnProperty(Obj, "set") is true, then
    1. Let setter be Get(Obj, "set").
    2. ReturnIfAbrupt(setter).
    3. If IsCallable(setter) is false and setter is not undefined, then throw a TypeError exception.
    4. Set the [[Set]] field of desc to setter.
  10. If either desc.[[Get]] or desc.[[Set]] are present, then
    1. If either desc.[[Value]] or desc.[[Writable]] are present, then throw a TypeError exception.
  11. Set the [[Origin]] field of desc to Obj.
  12. Return desc.

The End

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