# I am confused with 6.2.5.4 FromPropertyDescriptor

**URL:** <https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739>\
**Category:** I have questions\
**Created:** [April 14, 2021, 6:14pm UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739 "2021-04-14T18:14:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zerosheepmoo](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/zerosheepmoo/32/765_2.png) [@zerosheepmoo](https://es.discourse.group/u/zerosheepmoo)\
**Post date:** [April 14, 2021, 6:14pm UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739/1 "2021-04-14T18:14:26Z")

</div>

To understand details, I followed whole steps.  
**Then, I faced the problem:**

6.2.5.4 [FromPropertyDescriptor](https://tc39.es/ecma262/#sec-frompropertydescriptor)  
3. Assert: obj is an extensible ordinary object with no own properties.

1. If Desc has a [[Writable]] field, then  
a. Perform ! CreateDataPropertyOrThrow(obj, "writable", Desc.[[Writable]]).

**and...following steps:**

CreateDataPropertyOrThrow(_obj_, **"writable"** , _Desc_.[[Writable]]).

_newDesc_ = PropertyDescriptor { [[Value]]: _Desc.[[Writable]]_, [[Writable]]: **true** , [[Enumerable]]: **true** , [[Configurable]]: **true** }.

_ **obj** _.[[DefineOwnProperty]]( **"writable"** , _newDesc_).

**OrdinaryDefineOwnProperty ( _obj_, "writable"**, _newDesc_ **)**

1. Let _current_ be ? _O_.[GetOwnProperty].

_ **obj** _.[GetOwnProperty]

-2. If _O_ does not have an own property with key _P_, return **undefined**.

(==_ **obj** _ does not have an own property with key **"writable" )**

Therefore, _current_ be **undefined**

1. Let _extensible_ be ? IsExtensible(_O_).

(==assume as true because of 6.2.5.4.3)

**ValidateAndApplyPropertyDescriptor ( _obj_, "writable", true|false,**_newDesc_ **, undefined )**

1. Assert: If _O_ is not **undefined** , then IsPropertyKey(_P_) is **true**.

(==Therefore, It’s **true** )

1. If _current_ is **undefined** , then

- a. If _extensible_ is **false** , return **false**. [No]
- b. Assert: _extensible_ is **true**. [Yes, assumed as true]
- c. If IsGenericDescriptor(_Desc_) is **true** or IsDataDescriptor(_Desc_) is **true** , then
  - i. If _O_ is not **undefined** , create an own [data property](https://tc39.es/ecma262/#sec-object-type) named _P_ of object _O_ whose [[Value]], [[Writable]], [[Enumerable]], and [[Configurable]] attribute values are described by _Desc_. If the value of an attribute field of _Desc_ is absent, the attribute of the newly created property is set to its default value.
  - **Because** IsDataDescriptor(_newDesc)_ is **true,** do above.

- e. Return **true**.

## conclusion...

The result would be

obj = {“writable”: true}

And getOwnDescriptor of it would be _newDesc_

What 's the fault? I am doubtful that I was really mistaken.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [April 14, 2021, 6:56pm UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739/2 "2021-04-14T18:56:40Z")

</div>

Maybe comparing to engine-262 will help?

> <https://github.com/engine262/engine262/blob/60b42df616c33a93b3152072b1af2cbef210779b/src/abstract-ops/spec-types.mjs#L74>

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [April 14, 2021, 7:24pm UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739/3 "2021-04-14T19:24:25Z")

</div>

It might be confusing as there is a mix of the internal property descriptors and creating a JS object representation of a property descriptor by using property descriptors. Very inception.

```javascript
function FromPropertyDescriptor(descriptor) {
  if (descriptor === undefined) {
    return undefined;
  }
  let obj = {};
  for (const [internalSlot, publicName] of [
    ['[[Value]]', 'value'],
    ['[[Writable]]', 'writable'],
    ['[[Get]]', 'get'],
    ['[[Set]]', 'set'],
    ['[[Enumerable]]', 'enumerable'],
    ['[[Configurable]]', 'configurable']
  ]) {
    if (internalSlot in descriptor) {
      Object.defineProperty(obj, publicName, {
        value: descriptor[internalSlot],
        writable: true,
        enumerable: true,
        configurable: true
      })
    }
  }
  return obj;
}

```

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 14, 2021, 7:31pm UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739/4 "2021-04-14T19:31:32Z")

</div>

Additionally, es-abstract: [https://github.com/ljharb/es-abstract/blob/144955764b80341bee97c1773f89142b7e507840/2020/FromPropertyDescriptor.js#L9-L36](https://github.com/ljharb/es-abstract/blob/144955764b80341bee97c1773f89142b7e507840/2020/FromPropertyDescriptor.js#L9-L36)

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [April 14, 2021, 7:43pm UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739/5 "2021-04-14T19:43:48Z")

</div>

TIL!

---

<div class="post-metadata">

**Author:** ![zerosheepmoo](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/zerosheepmoo/32/765_2.png) [@zerosheepmoo](https://es.discourse.group/u/zerosheepmoo)\
**Post date:** [April 15, 2021, 1:35am UTC](https://es.discourse.group/t/i-am-confused-with-6-2-5-4-frompropertydescriptor/739/6 "2021-04-15T01:35:15Z")

</div>

Thank you all! I was impressed.

Since now I would learn through engine262 and associated packages rather than docs 😃
