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

I'm working on specifying a new exotic object type that is somewhat similar to 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?

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 and 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.

[[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).


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