From e97c95d064750fb949b6778584702dd658cf5624 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Wed, 23 Oct 2019 17:29:11 -0700 Subject: [PATCH] Editorial: Refactor index checking for Integer-Indexed exotic objects (#1752) --- spec.html | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/spec.html b/spec.html index c8ca1c5e88..4717216dbf 100644 --- a/spec.html +++ b/spec.html @@ -9354,7 +9354,7 @@

[[GetOwnProperty]] ( _P_ )

When the [[GetOwnProperty]] internal method of an Integer-Indexed exotic object _O_ is called with property key _P_, the following steps are taken:

1. Assert: IsPropertyKey(_P_) is *true*. - 1. Assert: _O_ is an Object that has a [[ViewedArrayBuffer]] internal slot. + 1. Assert: _O_ is an Integer-Indexed exotic object. 1. If Type(_P_) is String, then 1. Let _numericIndex_ be ! CanonicalNumericIndexString(_P_). 1. If _numericIndex_ is not *undefined*, then @@ -9370,16 +9370,13 @@

[[HasProperty]] ( _P_ )

When the [[HasProperty]] internal method of an Integer-Indexed exotic object _O_ is called with property key _P_, the following steps are taken:

1. Assert: IsPropertyKey(_P_) is *true*. - 1. Assert: _O_ is an Object that has a [[ViewedArrayBuffer]] internal slot. + 1. Assert: _O_ is an Integer-Indexed exotic object. 1. If Type(_P_) is String, then 1. Let _numericIndex_ be ! CanonicalNumericIndexString(_P_). 1. If _numericIndex_ is not *undefined*, then 1. Let _buffer_ be _O_.[[ViewedArrayBuffer]]. 1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception. - 1. If IsInteger(_numericIndex_) is *false*, return *false*. - 1. If _numericIndex_ = *-0*, return *false*. - 1. If _numericIndex_ < 0, return *false*. - 1. If _numericIndex_ ≥ _O_.[[ArrayLength]], return *false*. + 1. If ! IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*. 1. Return *true*. 1. Return ? OrdinaryHasProperty(_O_, _P_). @@ -9390,15 +9387,11 @@

[[DefineOwnProperty]] ( _P_, _Desc_ )

When the [[DefineOwnProperty]] internal method of an Integer-Indexed exotic object _O_ is called with property key _P_, and Property Descriptor _Desc_, the following steps are taken:

1. Assert: IsPropertyKey(_P_) is *true*. - 1. Assert: _O_ is an Object that has a [[ViewedArrayBuffer]] internal slot. + 1. Assert: _O_ is an Integer-Indexed exotic object. 1. If Type(_P_) is String, then 1. Let _numericIndex_ be ! CanonicalNumericIndexString(_P_). 1. If _numericIndex_ is not *undefined*, then - 1. If IsInteger(_numericIndex_) is *false*, return *false*. - 1. If _numericIndex_ = *-0*, return *false*. - 1. If _numericIndex_ < 0, return *false*. - 1. Let _length_ be _O_.[[ArrayLength]]. - 1. If _numericIndex_ ≥ _length_, return *false*. + 1. If ! IsValidIntegerIndex(_O_, _numericIndex_) is *false*, return *false*. 1. If IsAccessorDescriptor(_Desc_) is *true*, return *false*. 1. If _Desc_ has a [[Configurable]] field and if _Desc_.[[Configurable]] is *true*, return *false*. 1. If _Desc_ has an [[Enumerable]] field and if _Desc_.[[Enumerable]] is *false*, return *false*. @@ -9442,7 +9435,7 @@

[[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of an Integer-Indexed exotic object _O_ is called, the following steps are taken:

1. Let _keys_ be a new empty List. - 1. Assert: _O_ is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], [[ContentType]], and [[TypedArrayName]] internal slots. + 1. Assert: _O_ is an Integer-Indexed exotic object. 1. Let _len_ be _O_.[[ArrayLength]]. 1. For each integer _i_ starting with 0 such that _i_ < _len_, in ascending order, do 1. Add ! ToString(_i_) as the last element of _keys_. @@ -9473,18 +9466,28 @@

IntegerIndexedObjectCreate ( _prototype_, _internalSlotsList_ )

+ +

IsValidIntegerIndex ( _O_, _index_ )

+

The abstract operation IsValidIntegerIndex with arguments _O_ and _index_ performs the following steps:

+ + 1. Assert: _O_ is an Integer-Indexed exotic object. + 1. Assert: Type(_index_) is Number. + 1. If ! IsInteger(_index_) is *false*, return *false*. + 1. If _index_ is *-0*, return *false*. + 1. If _index_ < 0 or _index_ ≥ _O_.[[ArrayLength]], return *false*. + 1. Return *true*. + +
+

IntegerIndexedElementGet ( _O_, _index_ )

The abstract operation IntegerIndexedElementGet with arguments _O_ and _index_ performs the following steps:

+ 1. Assert: _O_ is an Integer-Indexed exotic object. 1. Assert: Type(_index_) is Number. - 1. Assert: _O_ is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], [[ContentType]], and [[TypedArrayName]] internal slots. 1. Let _buffer_ be _O_.[[ViewedArrayBuffer]]. 1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception. - 1. If IsInteger(_index_) is *false*, return *undefined*. - 1. If _index_ = *-0*, return *undefined*. - 1. Let _length_ be _O_.[[ArrayLength]]. - 1. If _index_ < 0 or _index_ ≥ _length_, return *undefined*. + 1. If ! IsValidIntegerIndex(_O_, _index_) is *false*, return *undefined*. 1. Let _offset_ be _O_.[[ByteOffset]]. 1. Let _arrayTypeName_ be the String value of _O_.[[TypedArrayName]]. 1. Let _elementSize_ be the Element Size value specified in for _arrayTypeName_. @@ -9498,16 +9501,13 @@

IntegerIndexedElementGet ( _O_, _index_ )

IntegerIndexedElementSet ( _O_, _index_, _value_ )

The abstract operation IntegerIndexedElementSet with arguments _O_, _index_, and _value_ performs the following steps:

+ 1. Assert: _O_ is an Integer-Indexed exotic object. 1. Assert: Type(_index_) is Number. - 1. Assert: _O_ is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], [[ContentType]], and [[TypedArrayName]] internal slots. 1. If _O_.[[ContentType]] is ~BigInt~, let _numValue_ be ? ToBigInt(_value_). 1. Otherwise, let _numValue_ be ? ToNumber(_value_). 1. Let _buffer_ be _O_.[[ViewedArrayBuffer]]. 1. If IsDetachedBuffer(_buffer_) is *true*, throw a *TypeError* exception. - 1. If IsInteger(_index_) is *false*, return *false*. - 1. If _index_ = *-0*, return *false*. - 1. Let _length_ be _O_.[[ArrayLength]]. - 1. If _index_ < 0 or _index_ ≥ _length_, return *false*. + 1. If ! IsValidIntegerIndex(_O_, _index_) is *false*, return *false*. 1. Let _offset_ be _O_.[[ByteOffset]]. 1. Let _arrayTypeName_ be the String value of _O_.[[TypedArrayName]]. 1. Let _elementSize_ be the Element Size value specified in for _arrayTypeName_.