-
Notifications
You must be signed in to change notification settings - Fork 14
Editorial: Move attachedness check into bounds chk #66
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is correct, thanks for the refactoring.
I agree with your indirectness concern, since the detach check is now under IsIntegerIndexedObjectOutOfBounds. Maybe we should rename it to IsIntegerIndexedObjectDetachedOrOutOfBounds, WDYT?
spec.html
Outdated
1. If _index_ is *-0*<sub>𝔽</sub>, return *false*. | ||
1. <ins>Let _getBufferByteLength_ be ! MakeIdempotentArrayBufferByteLengthGetter(~Unordered~).</ins> | ||
1. <ins>NOTE: Bounds checking is not a synchronizing operation when _O_'s backing buffer is a growable SharedArrayBuffer.</ins> | ||
1. <ins>If IsIntegerIndexedObjectOutOfBounds(_O_, _getBufferByteLength_) is *true*, return *false*.</ins> | ||
1. If ℝ(_index_) < 0 or ℝ(_index_) ≥ <del>_O_.[[ArrayLength]]</del><ins>IntegerIndexedObjectLength(_O_, _getBufferByteLength_)</ins>, return *false*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an assert and a note:
1. Assert: IsDetachedBuffer(_O_.[[ViewedArrayBuffer]]) is *false*.
1. NOTE: When the buffer is detached, IntegerIndexedObjectLength returns 0.
Some redundancy isn't the end of the world if the alternative is really unreadable. I'd have to see the alternatives side by side to judge, though, so happy to defer to your judgment here for now. |
My pleasure!
Done
I dunno. Despite its length, the name IsIntegerIndexedObjectDetachedOrOutOfBounds is still somewhat imprecise: the integer-indexed object isn't detached, after all. It's not the out-of-bounds check that's bugging me, though. I think that the concept of attachedness fits reasonably well inside the concept of bounds checking. "Any typed array or view becomes out of bounds once its buffer is detached." I think people reading this text would presume that. I'm not confident that a reader, seeing that an array reports a length of 0, would necessarily recognize that the attachedness of its buffer had been consulted at all. What if IntegerIndexedObjectLength returned
|
Ah, but then there's this:
That makes the idea of explicit "null to zero" conversions a little harder to justify... |
I like this idea. The only suggestion I'd make is to use a sentinel like
Oh don't worry about that, the explicitness seems worth it for readability. |
Totally! A sentinel is much easier to search for, and it makes the meaning of this condition even more clear. Though I'd like to suggest For IntegerIndexedObjectLength to report a detached buffer specifically, it would need to duplicate the IsDetachedBuffer check that we're putting in IsIntegerIndexedObjectOutOfBounds. Instead, my latest commit reports the more general condition, While that feels more cohesive to me, it also underscores the fact that we're not explaining how detachedness relates to being "out of bounds." Not only that, but by my reading, the current definition is incorrect:
That seems to describe the inverse of the true behavior. After all, it's legal for a buffer to extend beyond the boundary of the array. Whether my reading is correct or not, a more explicit definition might avoid confusion and alert readers to the relevance of detached buffers:
Does that seem like an improvement to you? If so, should we add something similar to IsViewOutOfBounds?
Great! |
Any thoughts on this, @syg? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping, this had fallen off my radar.
I see the confusion about the wording for the IsIntegerIndexedObjectOutOfBounds AO.
Hm, I don't think "describe an undefined sequence of byte data block values" is that helpful for the reader. Undefined in what sense? Maybe it's not wholly out of bounds, and the reader might expect that part of the sequence should be defined. Maybe something like "It checks if any of the object's numeric properties reference a value at an index out of the underlying data block's bounds"? |
This is my fault since I forgot about this PR for so long, but could you please rebase? Thank you. |
Could we get just a little farther from the phrase "out of bounds"? How do you feel about: "It checks if any of the object's numeric properties reference a value at an index not contained within the underlying data block's bounds." I can tell I'm getting pedantic because I've also started to question what it means to have a property. Do you think anyone would argue that, due to the internal methods of the indexed-integer exotic objects, typed arrays don't actually have numeric properties?
Sure; the conflicts came from gh-62. In the interest of transparency (and under the assumption that you'll be "squash merging" this patch), I've resolved the conflicts with a merge commit. I'm happy to do the squashing and force-push the result to this branch at your request. |
Typed arrays observably have numeric properties; the internal implementation details aren’t relevant. |
Sure, that sounds fine to me.
No, I don't think anyone would argue that. This is a sentence describing at a high-level what the AO does, and it doesn't need to exactly describe what the AO does. For that, readers can read the actual algorithm steps. |
@syg This is an attempt to implement the change you suggested here.
One aspect of this that I was not expecting is the effect on the IntegerIndexObjectLength operation. With this change in place, that operation also verifies buffer attachedness. This has two implications which feel somewhat unideal to me:
What do you think?