# Are integer indexed exotic object \[\[Get\]\], \[\[Set\]\], and \[\[HasProperty\]\] "just" optimizations?

**URL:** <https://es.discourse.group/t/are-integer-indexed-exotic-object-get-set-and-hasproperty-just-optimizations/228>\
**Category:** I have questions\
**Created:** [February 19, 2020, 9:36pm UTC](https://es.discourse.group/t/are-integer-indexed-exotic-object-get-set-and-hasproperty-just-optimizations/228 "2020-02-19T21:36:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![domenic](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/domenic/32/72_2.png) [@domenic](https://es.discourse.group/u/domenic)\
**Post date:** [February 19, 2020, 9:36pm UTC](https://es.discourse.group/t/are-integer-indexed-exotic-object-get-set-and-hasproperty-just-optimizations/228/1 "2020-02-19T21:36:52Z")

</div>

I'm working on specifying a new exotic object type that is somewhat similar to [integer-indexed exotic objects](https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects). One interesting thing I am wondering is whether I need to define [[Get]], [[Set]], and [[HasProperty]] too, or whether defining only [[GetOwnProperty]] and [[DefineOwnProperty]] would suffice.

My suspicion is that only defining the more fundamental traps would suffice. However, I noticed that integer-indexed exotic objects define all five. Is there any observable reason for this, or is it a spec-level optimization?

---

<div class="post-metadata">

**Author:** ![bakkot](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bakkot/32/22_2.png) [@bakkot](https://es.discourse.group/u/bakkot)\
**Post date:** [February 20, 2020, 3:00am UTC](https://es.discourse.group/t/are-integer-indexed-exotic-object-get-set-and-hasproperty-just-optimizations/228/2 "2020-02-20T03:00:04Z")

</div>

My suspicion is that at least [[Get]] and [[Set]] need to be defined explicitly to get the "correct" (or at least currently specified) interaction with the prototype chain, although note that the currently specified behavior (at least for [[Set]]) is not web compatible. See [https://github.com/tc39/ecma262/issues/1339](https://github.com/tc39/ecma262/issues/1339) and [https://github.com/tc39/ecma262/issues/1541](https://github.com/tc39/ecma262/issues/1541). I'll try to come up with more concrete examples to illustrate when I have time; feel free to ping me if I haven't gotten back to this in a few days.

---

<div class="post-metadata">

**Author:** ![devsnek](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/devsnek/32/100_2.png) [@devsnek](https://es.discourse.group/u/devsnek)\
**Post date:** [February 21, 2020, 8:08pm UTC](https://es.discourse.group/t/are-integer-indexed-exotic-object-get-set-and-hasproperty-just-optimizations/228/3 "2020-02-21T20:08:10Z")

</div>

[[Get]], [[Set]], and [[HasProperty]] being overridden prevents the property lookup from walking up the prototype chain when the index is out of bounds. (step 3 of OrdinaryGet, step 2 of OrdinarySetWithOwnDescriptor, step 4 of OrdinaryHas).

Trivially:

```javascript
Uint8Array.prototype[-1] = 42;
new Uint8Array()[-1]; // should be `undefined`, OrdinaryGet would return `42`

```
