diff --git a/README.md b/README.md index 177a6b4..b3af963 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Champion: Shu-yu Guo (@syg) ## Introduction -`ArrayBuffer`s have enabled in-memory handling of binary data and have enjoyed great success. This proposal extends the `ArrayBuffer` constructors to take an additional maximum length that allows in-place growth and shrinking of buffers. Similarly, `SharedArrayBuffer` is extended to take an additional maximum length that allows in-place growth. The `transfer` method is also re-introduced here as a standard way to detach `ArrayBuffer`s, perform zero-copy moves, and to "fix" resizable `ArrayBuffer` instances to `ArrayBuffer` instances. +`ArrayBuffer`s have enabled in-memory handling of binary data and have enjoyed great success. This proposal extends the `ArrayBuffer` constructors to take an additional maximum length that allows in-place growth and shrinking of buffers. Similarly, `SharedArrayBuffer` is extended to take an additional maximum length that allows in-place growth. ## Motivation and use cases @@ -62,19 +62,6 @@ class ArrayBuffer { // - Throws a RangeError if byteLength > maxByteLength. constructor(byteLength [, options ]); - // Returns a *non*-resizable ArrayBuffer with the same byte content - // at this buffer for [0, min(this.byteLength, newByteLength)], - // then detaches this buffer. - // - // Any new memory is zeroed. - // - // If newByteLength is undefined, it is set to this.bytelength. - // - // Designed to be implementable as a copy-free move or a realloc. - // - // Throws a RangeError unless 0 <= newByteLength. - transfer(newByteLength); - // Resizes the buffer. // // Grows are designed to be implemented in-place, i.e. address space is @@ -109,30 +96,6 @@ class ArrayBuffer { } ``` -`ArrayBuffer#transfer` may be used to "fix" resizable buffers in a zero-copy move to normal `ArrayBuffer`s. - -Example: - -```javascript -let rab = new ArrayBuffer(1024, { maxByteLength: 1024 ** 2 }); -assert(rab.byteLength === 1024); -assert(rab.maxByteLength === 1024 ** 2); -assert(rab.resizable); - -rab.resize(rab.byteLength * 2); -assert(rab.byteLength === 1024 * 2); - -// Transfer the first 1024 bytes. -let ab = rab.transfer(1024); -// rab is now detached -assert(rab.byteLength === 0); -assert(rab.maxByteLength === 0); - -// The contents are moved to ab. -assert(!ab.resizable); -assert(ab.byteLength === 1024); -``` - ### `SharedArrayBuffer` ```javascript @@ -291,10 +254,6 @@ Growing a growable `SharedArrayBuffer` performs a SeqCst access on the buffer le This aligns with WebAssembly as well as enable more optimization opportunities for bounds checking codegen. It also means that other threads are not guaranteed to see the grown length without synchronizing on an explicit length access, such as by reading the `byteLength` accessor. -### Is `transfer` realloc? - -Yes, with detach semantics. - ## Open questions ### Should `resize(0)` be allowed? @@ -303,9 +262,9 @@ Yes, with detach semantics. https://github.com/tc39/proposal-resizablearraybuffer/issues/22 points out that `ArrayBuffer(0)` is already a thing. This proposal thus allows `resize(0)`. -### Should there be a `transferResizable()` that reallocs into another resizable `ArrayBuffer`? +### What happened to `transfer()`? It used to be here. -Are there compelling use cases for this? +It has been separated into its own proposal to further explore the design space. New proposal repo TBD. ## History and acknowledgment diff --git a/docs/ecmarkup.js b/docs/ecmarkup.js index 070b5c2..09338a5 100644 --- a/docs/ecmarkup.js +++ b/docs/ecmarkup.js @@ -1255,5 +1255,5 @@ document.addEventListener('DOMContentLoaded', () => { }); let sdoMap = JSON.parse(`{}`); -let biblio = JSON.parse(`{"refsByClause":{"sec-get-arraybuffer-@@species":["_ref_0"],"sec-arraybuffer.prototype.transfer":["_ref_1","_ref_9","_ref_10"],"sec-makeidempotentarraybufferbytelengthgetter":["_ref_2"],"sec-arraybuffer-length":["_ref_3","_ref_4"],"sec-get-arraybuffer.prototype.maxbytelength":["_ref_5"],"sec-get-arraybuffer.prototype.resizable":["_ref_6"],"sec-arraybuffer.prototype.slice":["_ref_7"],"sec-arraybuffer.prototype.resize":["_ref_8"],"sec-hostgrowsharedarraybuffer":["_ref_11"],"sec-sharedarraybuffer-length":["_ref_12","_ref_13"],"sec-get-sharedarraybuffer.prototype.bytelength":["_ref_14"],"sec-get-sharedarraybuffer.prototype.growable":["_ref_15"],"sec-get-sharedarraybuffer.prototype.maxbytelength":["_ref_16"],"sec-sharedarraybuffer.prototype.grow":["_ref_17"],"sec-sharedarraybuffer.prototype.slice":["_ref_18","_ref_19"],"sec-integer-indexed-exotic-objects-ownpropertykeys":["_ref_20","_ref_21"],"sec-isvalidintegerindex":["_ref_22","_ref_23"],"sec-integerindexedobjectbytelength":["_ref_24"],"sec-integerindexedobjectlength":["_ref_25","_ref_26"],"sec-isarraybufferviewoutofbounds":["_ref_27","_ref_28","_ref_29","_ref_30","_ref_31"],"sec-validatetypedarray":["_ref_32","_ref_33"],"sec-get-%typedarray%.prototype.bytelength":["_ref_34","_ref_35"],"sec-get-%typedarray%.prototype.byteoffset":["_ref_36","_ref_37"],"sec-get-%typedarray%.prototype.length":["_ref_38","_ref_39"],"sec-%typedarray%.prototype.copywithin":["_ref_40","_ref_41","_ref_42","_ref_43","_ref_44"],"sec-%typedarray%.prototype.fill":["_ref_45","_ref_46","_ref_47","_ref_48","_ref_49"],"sec-%typedarray%.prototype.slice":["_ref_50","_ref_51","_ref_52","_ref_53","_ref_54"],"sec-%typedarray%.prototype.subarray":["_ref_55","_ref_56"],"sec-settypedarrayfromtypedarray":["_ref_57","_ref_58","_ref_59","_ref_60","_ref_61"],"sec-initializetypedarrayfromtypedarray":["_ref_62","_ref_63","_ref_64","_ref_65"],"sec-initializetypedarrayfromarraybuffer":["_ref_66","_ref_67"],"sec-isviewoutofbounds":["_ref_68"],"sec-getviewvalue":["_ref_69","_ref_70","_ref_71"],"sec-setviewvalue":["_ref_72","_ref_73","_ref_74"],"sec-dataview-buffer-byteoffset-bytelength":["_ref_75","_ref_76","_ref_77"],"sec-get-dataview.prototype.bytelength":["_ref_78","_ref_79","_ref_80"],"sec-get-dataview.prototype.byteoffset":["_ref_81","_ref_82"],"sec-validateatomicaccess":["_ref_83","_ref_84"],"omitted-for-brevity":["_ref_85","_ref_86"]},"entries":[{"type":"clause","id":"intro","titleHTML":"Resizable ArrayBuffer and growable SharedArrayBuffer","number":""},{"type":"op","aoid":"DetachArrayBuffer","refId":"sec-detacharraybuffer"},{"type":"clause","id":"sec-detacharraybuffer","title":"DetachArrayBuffer ( arrayBuffer [ , key ] )","titleHTML":"DetachArrayBuffer ( arrayBuffer [ , key ] )","number":"1.1.1","referencingIds":["_ref_10"]},{"type":"op","aoid":"AllocateArrayBuffer","refId":"sec-allocatearraybuffer"},{"type":"clause","id":"sec-allocatearraybuffer","title":"AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","titleHTML":"AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","number":"1.1.2","referencingIds":["_ref_4","_ref_64"]},{"type":"op","aoid":"ArrayBufferByteLength","refId":"sec-arraybufferlength"},{"type":"clause","id":"sec-arraybufferlength","title":"ArrayBufferByteLength ( arrayBuffer, order )","titleHTML":"ArrayBufferByteLength ( arrayBuffer, order )","number":"1.1.3","referencingIds":["_ref_2","_ref_14","_ref_18","_ref_67","_ref_75","_ref_86"]},{"type":"op","aoid":"MakeIdempotentArrayBufferByteLengthGetter","refId":"sec-makeidempotentarraybufferbytelengthgetter"},{"type":"clause","id":"sec-makeidempotentarraybufferbytelengthgetter","title":"MakeIdempotentArrayBufferByteLengthGetter ( order )","titleHTML":"MakeIdempotentArrayBufferByteLengthGetter ( order )","number":"1.1.4","referencingIds":["_ref_20","_ref_22","_ref_27","_ref_32","_ref_34","_ref_36","_ref_38","_ref_41","_ref_43","_ref_46","_ref_48","_ref_51","_ref_53","_ref_55","_ref_57","_ref_59","_ref_62","_ref_69","_ref_72","_ref_77","_ref_78","_ref_81","_ref_83"]},{"type":"op","aoid":"IsResizableArrayBuffer","refId":"sec-isresizablearraybuffer"},{"type":"clause","id":"sec-isresizablearraybuffer","title":"IsResizableArrayBuffer ( arrayBuffer )","titleHTML":"IsResizableArrayBuffer ( arrayBuffer )","number":"1.1.5","referencingIds":["_ref_5","_ref_6","_ref_15","_ref_16","_ref_26","_ref_66","_ref_76"]},{"type":"op","aoid":"GetArrayBufferMaxByteLengthOption","refId":"sec-getarraybuffermaxbytelengthoption"},{"type":"clause","id":"sec-getarraybuffermaxbytelengthoption","title":"GetArrayBufferMaxByteLengthOption ( options )","titleHTML":"GetArrayBufferMaxByteLengthOption ( options )","number":"1.1.6","referencingIds":["_ref_3","_ref_12"]},{"type":"op","aoid":"HostResizeArrayBuffer","refId":"sec-hostresizearraybuffer"},{"type":"clause","id":"sec-hostresizearraybuffer","title":"HostResizeArrayBuffer ( buffer, newByteLength )","titleHTML":"HostResizeArrayBuffer ( buffer, newByteLength )","number":"1.1.7","referencingIds":["_ref_8","_ref_11"]},{"type":"clause","id":"sec-abstract-operations-for-arraybuffer-objects-mods","titleHTML":"Modifications to Abstract Operations for ArrayBuffer Objects","number":"1.1"},{"type":"clause","id":"sec-arraybuffer-length","title":"ArrayBuffer ( length [ , options ] )","titleHTML":"ArrayBuffer ( length [ , options ] )","number":"1.2.1"},{"type":"clause","id":"sec-arraybuffer-constructor","titleHTML":"The ArrayBuffer Constructor","number":"1.2","referencingIds":["_ref_7","_ref_9","_ref_65"]},{"type":"clause","id":"sec-get-arraybuffer-@@species","titleHTML":"get ArrayBuffer [ @@species ]","number":"1.3.1"},{"type":"clause","id":"sec-get-arraybuffer.prototype.maxbytelength","titleHTML":"get ArrayBuffer.prototype.maxByteLength","number":"1.3.2"},{"type":"clause","id":"sec-get-arraybuffer.prototype.resizable","titleHTML":"get ArrayBuffer.prototype.resizable","number":"1.3.3"},{"type":"clause","id":"sec-arraybuffer.prototype.slice","title":"ArrayBuffer.prototype.slice ( start, end )","titleHTML":"ArrayBuffer.prototype.slice ( start, end )","number":"1.3.4","referencingIds":["_ref_0"]},{"type":"clause","id":"sec-arraybuffer.prototype.resize","title":"ArrayBuffer.prototype.resize ( newLength )","titleHTML":"ArrayBuffer.prototype.resize ( newLength )","number":"1.3.5"},{"type":"step","id":"step-transfer-copy-bytes","referencingIds":["_ref_1"]},{"type":"clause","id":"sec-arraybuffer.prototype.transfer","title":"ArrayBuffer.prototype.transfer ( [ newLength ] )","titleHTML":"ArrayBuffer.prototype.transfer ( [ newLength ] )","number":"1.3.6"},{"type":"clause","id":"sec-properties-of-the-arraybuffer-prototype-object-mods","titleHTML":"Modifications to the Properties of the ArrayBuffer Prototype Object","number":"1.3"},{"type":"clause","id":"sec-arraybuffer-objects-mods","titleHTML":"Modifications to ArrayBuffer Objects","number":"1"},{"type":"op","aoid":"AllocateSharedArrayBuffer","refId":"sec-allocatesharedarraybuffer"},{"type":"clause","id":"sec-allocatesharedarraybuffer","title":"AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","titleHTML":"AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","number":"2.1.1","referencingIds":["_ref_13"]},{"type":"op","aoid":"HostGrowSharedArrayBuffer","refId":"sec-hostgrowsharedarraybuffer"},{"type":"clause","id":"sec-hostgrowsharedarraybuffer","title":"HostGrowSharedArrayBuffer ( buffer, newByteLength )","titleHTML":"HostGrowSharedArrayBuffer ( buffer, newByteLength )","number":"2.1.2","referencingIds":["_ref_17"]},{"type":"clause","id":"sec-abstract-operations-for-sharedarraybuffer-objects-mods","titleHTML":"Modifications to Abstract Operations for SharedArrayBuffer Objects","number":"2.1"},{"type":"clause","id":"sec-sharedarraybuffer-length","title":"SharedArrayBuffer ( length [ , options ] )","titleHTML":"SharedArrayBuffer ( length [ , options ] )","number":"2.2.1"},{"type":"clause","id":"sec-sharedarraybuffer-constructor","titleHTML":"The SharedArrayBuffer Constructor","number":"2.2","referencingIds":["_ref_19"]},{"type":"clause","id":"sec-get-sharedarraybuffer.prototype.bytelength","titleHTML":"get SharedArrayBuffer.prototype.byteLength","number":"2.3.1"},{"type":"clause","id":"sec-get-sharedarraybuffer.prototype.growable","titleHTML":"get SharedArrayBuffer.prototype.growable","number":"2.3.2"},{"type":"clause","id":"sec-get-sharedarraybuffer.prototype.maxbytelength","titleHTML":"get SharedArrayBuffer.prototype.maxByteLength","number":"2.3.3"},{"type":"clause","id":"sec-sharedarraybuffer.prototype.grow","title":"SharedArrayBuffer.prototype.grow ( newLength )","titleHTML":"SharedArrayBuffer.prototype.grow ( newLength )","number":"2.3.4"},{"type":"clause","id":"sec-sharedarraybuffer.prototype.slice","title":"SharedArrayBuffer.prototype.slice ( start, end )","titleHTML":"SharedArrayBuffer.prototype.slice ( start, end )","number":"2.3.5"},{"type":"clause","id":"sec-properties-of-the-sharedarraybuffer-prototype-object-mods","titleHTML":"Modifications to the Properties of the SharedArrayBuffer Prototype Object","number":"2.3"},{"type":"clause","id":"sec-sharedarraybuffer-objects-mods","titleHTML":"Modifications to SharedArrayBuffer Objects","number":"2"},{"type":"clause","id":"sec-integer-indexed-exotic-objects-ownpropertykeys","titleHTML":"[[OwnPropertyKeys]] ( )","number":"3.1"},{"type":"op","aoid":"IsValidIntegerIndex","refId":"sec-isvalidintegerindex"},{"type":"clause","id":"sec-isvalidintegerindex","title":"IsValidIntegerIndex ( O, index )","titleHTML":"IsValidIntegerIndex ( O, index )","number":"3.2"},{"type":"op","aoid":"IntegerIndexedObjectByteLength","refId":"sec-integerindexedobjectbytelength"},{"type":"clause","id":"sec-integerindexedobjectbytelength","title":"IntegerIndexedObjectByteLength ( O, getBufferByteLength )","titleHTML":"IntegerIndexedObjectByteLength ( O, getBufferByteLength )","number":"3.3","referencingIds":["_ref_35","_ref_61"]},{"type":"op","aoid":"IntegerIndexedObjectLength","refId":"sec-integerindexedobjectlength"},{"type":"clause","id":"sec-integerindexedobjectlength","title":"IntegerIndexedObjectLength ( O, getBufferByteLength )","titleHTML":"IntegerIndexedObjectLength ( O, getBufferByteLength )","number":"3.4","referencingIds":["_ref_21","_ref_23","_ref_24","_ref_39","_ref_42","_ref_44","_ref_47","_ref_49","_ref_52","_ref_54","_ref_56","_ref_58","_ref_60","_ref_63","_ref_84","_ref_85"]},{"type":"op","aoid":"IsIntegerIndexedObjectOutOfBounds","refId":"sec-isintegerindexedobjectoutofbounds"},{"type":"clause","id":"sec-isintegerindexedobjectoutofbounds","title":"IsIntegerIndexedObjectOutOfBounds ( O, getBufferByteLength )","titleHTML":"IsIntegerIndexedObjectOutOfBounds ( O, getBufferByteLength )","number":"3.5","referencingIds":["_ref_25","_ref_29","_ref_31","_ref_33","_ref_37"]},{"type":"op","aoid":"IsArrayBufferViewOutOfBounds","refId":"sec-isarraybufferviewoutofbounds"},{"type":"clause","id":"sec-isarraybufferviewoutofbounds","title":"IsArrayBufferViewOutOfBounds ( O )","titleHTML":"IsArrayBufferViewOutOfBounds ( O )","number":"3.6"},{"type":"clause","id":"sec-integer-indexed-exotic-objects-mods","titleHTML":"Modifications to Integer-Indexed Exotic Objects","number":"3"},{"type":"op","aoid":"ValidateTypedArray","refId":"sec-validatetypedarray"},{"type":"clause","id":"sec-validatetypedarray","title":"ValidateTypedArray ( O )","titleHTML":"ValidateTypedArray ( O )","number":"4.1.1","referencingIds":["_ref_40","_ref_45","_ref_50"]},{"type":"clause","id":"sec-get-%typedarray%.prototype.bytelength","titleHTML":"get %TypedArray%.prototype.byteLength","number":"4.1.2"},{"type":"clause","id":"sec-get-%typedarray%.prototype.byteoffset","titleHTML":"get %TypedArray%.prototype.byteOffset","number":"4.1.3"},{"type":"clause","id":"sec-get-%typedarray%.prototype.length","titleHTML":"get %TypedArray%.prototype.length","number":"4.1.4"},{"type":"clause","id":"sec-%typedarray%.prototype.copywithin","title":"%TypedArray%.prototype.copyWithin ( target, start [ , end ] )","titleHTML":"%TypedArray%.prototype.copyWithin ( target, start [ , end ] )","number":"4.1.5"},{"type":"clause","id":"sec-%typedarray%.prototype.fill","title":"%TypedArray%.prototype.fill ( value [ , start [ , end ] ] )","titleHTML":"%TypedArray%.prototype.fill ( value [ , start [ , end ] ] )","number":"4.1.6"},{"type":"clause","id":"sec-%typedarray%.prototype.slice","title":"%TypedArray%.prototype.slice ( start, end )","titleHTML":"%TypedArray%.prototype.slice ( start, end )","number":"4.1.7"},{"type":"clause","id":"sec-%typedarray%.prototype.subarray","title":"%TypedArray%.prototype.subarray ( begin, end )","titleHTML":"%TypedArray%.prototype.subarray ( begin, end )","number":"4.1.8"},{"type":"op","aoid":"SetTypedArrayFromTypedArray","refId":"sec-settypedarrayfromtypedarray"},{"type":"clause","id":"sec-settypedarrayfromtypedarray","title":"SetTypedArrayFromTypedArray ( target, targetOffset, source )","titleHTML":"SetTypedArrayFromTypedArray ( target, targetOffset, source )","number":"4.1.9"},{"type":"clause","id":"sec-properties-of-the-%typedarrayprototype%-object-mods","titleHTML":"Modifications to Properties of the %TypedArray.prototype% Object","number":"4.1"},{"type":"op","aoid":"InitializeTypedArrayFromTypedArray","refId":"sec-initializetypedarrayfromtypedarray"},{"type":"clause","id":"sec-initializetypedarrayfromtypedarray","title":"InitializeTypedArrayFromTypedArray ( O, srcArray )","titleHTML":"InitializeTypedArrayFromTypedArray ( O, srcArray )","number":"4.2.1"},{"type":"op","aoid":"InitializeTypedArrayFromArrayBuffer","refId":"sec-initializetypedarrayfromarraybuffer"},{"type":"clause","id":"sec-initializetypedarrayfromarraybuffer","title":"InitializeTypedArrayFromArrayBuffer ( O, buffer, byteOffset, length )","titleHTML":"InitializeTypedArrayFromArrayBuffer ( O, buffer, byteOffset, length )","number":"4.2.2"},{"type":"clause","id":"sec-typedarray-constructors-mods","title":"Modifications to the TypedArray Constructors","titleHTML":"Modifications to the TypedArray Constructors","number":"4.2"},{"type":"clause","id":"sec-typedarray-objects-mods","titleHTML":"Modifications to TypedArray Objects","number":"4"},{"type":"op","aoid":"GetViewByteLength","refId":"sec-getviewbytelength"},{"type":"clause","id":"sec-getviewbytelength","title":"GetViewByteLength ( view, getBufferByteLength )","titleHTML":"GetViewByteLength ( view, getBufferByteLength )","number":"5.1.1","referencingIds":["_ref_68","_ref_71","_ref_74","_ref_80"]},{"type":"op","aoid":"IsViewOutOfBounds","refId":"sec-isviewoutofbounds"},{"type":"clause","id":"sec-isviewoutofbounds","title":"IsViewOutOfBounds ( view, getBufferByteLength )","titleHTML":"IsViewOutOfBounds ( view, getBufferByteLength )","number":"5.1.2","referencingIds":["_ref_28","_ref_30","_ref_70","_ref_73","_ref_79","_ref_82"]},{"type":"op","aoid":"GetViewValue","refId":"sec-getviewvalue"},{"type":"clause","id":"sec-getviewvalue","title":"GetViewValue ( view, requestIndex, isLittleEndian, type )","titleHTML":"GetViewValue ( view, requestIndex, isLittleEndian, type )","number":"5.1.3"},{"type":"op","aoid":"SetViewValue","refId":"sec-setviewvalue"},{"type":"clause","id":"sec-setviewvalue","title":"SetViewValue ( view, requestIndex, isLittleEndian, type, value )","titleHTML":"SetViewValue ( view, requestIndex, isLittleEndian, type, value )","number":"5.1.4"},{"type":"clause","id":"sec-abstract-operations-for-dataview-objects-mods","titleHTML":"Modifications to Abstract Operations For DataView Objects","number":"5.1"},{"type":"clause","id":"sec-dataview-buffer-byteoffset-bytelength","title":"DataView ( buffer [ , byteOffset [ , byteLength ] ] )","titleHTML":"DataView ( buffer [ , byteOffset [ , byteLength ] ] )","number":"5.2.1"},{"type":"clause","id":"sec-dataview-constructor-mods","titleHTML":"Modifications to the DataView Constructor","number":"5.2"},{"type":"clause","id":"sec-get-dataview.prototype.bytelength","titleHTML":"get DataView.prototype.byteLength","number":"5.3.1"},{"type":"clause","id":"sec-get-dataview.prototype.byteoffset","titleHTML":"get DataView.prototype.byteOffset","number":"5.3.2"},{"type":"clause","id":"sec-properties-of-the-dataview-prototype-object-mods","titleHTML":"Modifications to Properties of the DataView Prototype Object","number":"5.3"},{"type":"clause","id":"sec-dataview-objects-mods","titleHTML":"Modifications to DataView Objects","number":"5"},{"type":"op","aoid":"ValidateAtomicAccess","refId":"sec-validateatomicaccess"},{"type":"clause","id":"sec-validateatomicaccess","title":"ValidateAtomicAccess ( typedArray, requestIndex )","titleHTML":"ValidateAtomicAccess ( typedArray, requestIndex )","number":"6.1"},{"type":"clause","id":"sec-abstract-operations-for-atomics-mods","titleHTML":"Modifications to Abstract Operations for Atomics","number":"6"},{"type":"clause","id":"sec-maxbytelength-guidelines","titleHTML":"Resizable ArrayBuffer and growable SharedArrayBuffer Guidelines","number":"7"},{"type":"clause","id":"omitted-for-brevity","titleHTML":"Mechanical Changes Omitted for Brevity","number":"8"}]}`); +let biblio = JSON.parse(`{"refsByClause":{"sec-get-arraybuffer-@@species":["_ref_0"],"sec-makeidempotentarraybufferbytelengthgetter":["_ref_1"],"sec-arraybuffer-length":["_ref_2","_ref_3"],"sec-get-arraybuffer.prototype.maxbytelength":["_ref_4"],"sec-get-arraybuffer.prototype.resizable":["_ref_5"],"sec-arraybuffer.prototype.slice":["_ref_6"],"sec-arraybuffer.prototype.resize":["_ref_7"],"sec-hostgrowsharedarraybuffer":["_ref_8"],"sec-sharedarraybuffer-length":["_ref_9","_ref_10"],"sec-get-sharedarraybuffer.prototype.bytelength":["_ref_11"],"sec-get-sharedarraybuffer.prototype.growable":["_ref_12"],"sec-get-sharedarraybuffer.prototype.maxbytelength":["_ref_13"],"sec-sharedarraybuffer.prototype.grow":["_ref_14"],"sec-sharedarraybuffer.prototype.slice":["_ref_15","_ref_16"],"sec-integer-indexed-exotic-objects-ownpropertykeys":["_ref_17","_ref_18"],"sec-isvalidintegerindex":["_ref_19","_ref_20"],"sec-integerindexedobjectbytelength":["_ref_21"],"sec-integerindexedobjectlength":["_ref_22","_ref_23"],"sec-isarraybufferviewoutofbounds":["_ref_24","_ref_25","_ref_26","_ref_27","_ref_28"],"sec-validatetypedarray":["_ref_29","_ref_30"],"sec-get-%typedarray%.prototype.bytelength":["_ref_31","_ref_32"],"sec-get-%typedarray%.prototype.byteoffset":["_ref_33","_ref_34"],"sec-get-%typedarray%.prototype.length":["_ref_35","_ref_36"],"sec-%typedarray%.prototype.copywithin":["_ref_37","_ref_38","_ref_39","_ref_40","_ref_41"],"sec-%typedarray%.prototype.fill":["_ref_42","_ref_43","_ref_44","_ref_45","_ref_46"],"sec-%typedarray%.prototype.slice":["_ref_47","_ref_48","_ref_49","_ref_50","_ref_51"],"sec-%typedarray%.prototype.subarray":["_ref_52","_ref_53"],"sec-settypedarrayfromtypedarray":["_ref_54","_ref_55","_ref_56","_ref_57","_ref_58"],"sec-initializetypedarrayfromtypedarray":["_ref_59","_ref_60","_ref_61","_ref_62"],"sec-initializetypedarrayfromarraybuffer":["_ref_63","_ref_64"],"sec-isviewoutofbounds":["_ref_65"],"sec-getviewvalue":["_ref_66","_ref_67","_ref_68"],"sec-setviewvalue":["_ref_69","_ref_70","_ref_71"],"sec-dataview-buffer-byteoffset-bytelength":["_ref_72","_ref_73","_ref_74"],"sec-get-dataview.prototype.bytelength":["_ref_75","_ref_76","_ref_77"],"sec-get-dataview.prototype.byteoffset":["_ref_78","_ref_79"],"sec-validateatomicaccess":["_ref_80","_ref_81"],"omitted-for-brevity":["_ref_82","_ref_83"]},"entries":[{"type":"clause","id":"intro","titleHTML":"Resizable ArrayBuffer and growable SharedArrayBuffer","number":""},{"type":"op","aoid":"DetachArrayBuffer","refId":"sec-detacharraybuffer"},{"type":"clause","id":"sec-detacharraybuffer","title":"DetachArrayBuffer ( arrayBuffer [ , key ] )","titleHTML":"DetachArrayBuffer ( arrayBuffer [ , key ] )","number":"1.1.1"},{"type":"op","aoid":"AllocateArrayBuffer","refId":"sec-allocatearraybuffer"},{"type":"clause","id":"sec-allocatearraybuffer","title":"AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","titleHTML":"AllocateArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","number":"1.1.2","referencingIds":["_ref_3","_ref_61"]},{"type":"op","aoid":"ArrayBufferByteLength","refId":"sec-arraybufferlength"},{"type":"clause","id":"sec-arraybufferlength","title":"ArrayBufferByteLength ( arrayBuffer, order )","titleHTML":"ArrayBufferByteLength ( arrayBuffer, order )","number":"1.1.3","referencingIds":["_ref_1","_ref_11","_ref_15","_ref_64","_ref_72","_ref_83"]},{"type":"op","aoid":"MakeIdempotentArrayBufferByteLengthGetter","refId":"sec-makeidempotentarraybufferbytelengthgetter"},{"type":"clause","id":"sec-makeidempotentarraybufferbytelengthgetter","title":"MakeIdempotentArrayBufferByteLengthGetter ( order )","titleHTML":"MakeIdempotentArrayBufferByteLengthGetter ( order )","number":"1.1.4","referencingIds":["_ref_17","_ref_19","_ref_24","_ref_29","_ref_31","_ref_33","_ref_35","_ref_38","_ref_40","_ref_43","_ref_45","_ref_48","_ref_50","_ref_52","_ref_54","_ref_56","_ref_59","_ref_66","_ref_69","_ref_74","_ref_75","_ref_78","_ref_80"]},{"type":"op","aoid":"IsResizableArrayBuffer","refId":"sec-isresizablearraybuffer"},{"type":"clause","id":"sec-isresizablearraybuffer","title":"IsResizableArrayBuffer ( arrayBuffer )","titleHTML":"IsResizableArrayBuffer ( arrayBuffer )","number":"1.1.5","referencingIds":["_ref_4","_ref_5","_ref_12","_ref_13","_ref_23","_ref_63","_ref_73"]},{"type":"op","aoid":"GetArrayBufferMaxByteLengthOption","refId":"sec-getarraybuffermaxbytelengthoption"},{"type":"clause","id":"sec-getarraybuffermaxbytelengthoption","title":"GetArrayBufferMaxByteLengthOption ( options )","titleHTML":"GetArrayBufferMaxByteLengthOption ( options )","number":"1.1.6","referencingIds":["_ref_2","_ref_9"]},{"type":"op","aoid":"HostResizeArrayBuffer","refId":"sec-hostresizearraybuffer"},{"type":"clause","id":"sec-hostresizearraybuffer","title":"HostResizeArrayBuffer ( buffer, newByteLength )","titleHTML":"HostResizeArrayBuffer ( buffer, newByteLength )","number":"1.1.7","referencingIds":["_ref_7","_ref_8"]},{"type":"clause","id":"sec-abstract-operations-for-arraybuffer-objects-mods","titleHTML":"Modifications to Abstract Operations for ArrayBuffer Objects","number":"1.1"},{"type":"clause","id":"sec-arraybuffer-length","title":"ArrayBuffer ( length [ , options ] )","titleHTML":"ArrayBuffer ( length [ , options ] )","number":"1.2.1"},{"type":"clause","id":"sec-arraybuffer-constructor","titleHTML":"The ArrayBuffer Constructor","number":"1.2","referencingIds":["_ref_6","_ref_62"]},{"type":"clause","id":"sec-get-arraybuffer-@@species","titleHTML":"get ArrayBuffer [ @@species ]","number":"1.3.1"},{"type":"clause","id":"sec-get-arraybuffer.prototype.maxbytelength","titleHTML":"get ArrayBuffer.prototype.maxByteLength","number":"1.3.2"},{"type":"clause","id":"sec-get-arraybuffer.prototype.resizable","titleHTML":"get ArrayBuffer.prototype.resizable","number":"1.3.3"},{"type":"clause","id":"sec-arraybuffer.prototype.slice","title":"ArrayBuffer.prototype.slice ( start, end )","titleHTML":"ArrayBuffer.prototype.slice ( start, end )","number":"1.3.4","referencingIds":["_ref_0"]},{"type":"clause","id":"sec-arraybuffer.prototype.resize","title":"ArrayBuffer.prototype.resize ( newLength )","titleHTML":"ArrayBuffer.prototype.resize ( newLength )","number":"1.3.5"},{"type":"clause","id":"sec-properties-of-the-arraybuffer-prototype-object-mods","titleHTML":"Modifications to the Properties of the ArrayBuffer Prototype Object","number":"1.3"},{"type":"clause","id":"sec-arraybuffer-objects-mods","titleHTML":"Modifications to ArrayBuffer Objects","number":"1"},{"type":"op","aoid":"AllocateSharedArrayBuffer","refId":"sec-allocatesharedarraybuffer"},{"type":"clause","id":"sec-allocatesharedarraybuffer","title":"AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","titleHTML":"AllocateSharedArrayBuffer ( constructor, byteLength [ , maxByteLength ] )","number":"2.1.1","referencingIds":["_ref_10"]},{"type":"op","aoid":"HostGrowSharedArrayBuffer","refId":"sec-hostgrowsharedarraybuffer"},{"type":"clause","id":"sec-hostgrowsharedarraybuffer","title":"HostGrowSharedArrayBuffer ( buffer, newByteLength )","titleHTML":"HostGrowSharedArrayBuffer ( buffer, newByteLength )","number":"2.1.2","referencingIds":["_ref_14"]},{"type":"clause","id":"sec-abstract-operations-for-sharedarraybuffer-objects-mods","titleHTML":"Modifications to Abstract Operations for SharedArrayBuffer Objects","number":"2.1"},{"type":"clause","id":"sec-sharedarraybuffer-length","title":"SharedArrayBuffer ( length [ , options ] )","titleHTML":"SharedArrayBuffer ( length [ , options ] )","number":"2.2.1"},{"type":"clause","id":"sec-sharedarraybuffer-constructor","titleHTML":"The SharedArrayBuffer Constructor","number":"2.2","referencingIds":["_ref_16"]},{"type":"clause","id":"sec-get-sharedarraybuffer.prototype.bytelength","titleHTML":"get SharedArrayBuffer.prototype.byteLength","number":"2.3.1"},{"type":"clause","id":"sec-get-sharedarraybuffer.prototype.growable","titleHTML":"get SharedArrayBuffer.prototype.growable","number":"2.3.2"},{"type":"clause","id":"sec-get-sharedarraybuffer.prototype.maxbytelength","titleHTML":"get SharedArrayBuffer.prototype.maxByteLength","number":"2.3.3"},{"type":"clause","id":"sec-sharedarraybuffer.prototype.grow","title":"SharedArrayBuffer.prototype.grow ( newLength )","titleHTML":"SharedArrayBuffer.prototype.grow ( newLength )","number":"2.3.4"},{"type":"clause","id":"sec-sharedarraybuffer.prototype.slice","title":"SharedArrayBuffer.prototype.slice ( start, end )","titleHTML":"SharedArrayBuffer.prototype.slice ( start, end )","number":"2.3.5"},{"type":"clause","id":"sec-properties-of-the-sharedarraybuffer-prototype-object-mods","titleHTML":"Modifications to the Properties of the SharedArrayBuffer Prototype Object","number":"2.3"},{"type":"clause","id":"sec-sharedarraybuffer-objects-mods","titleHTML":"Modifications to SharedArrayBuffer Objects","number":"2"},{"type":"clause","id":"sec-integer-indexed-exotic-objects-ownpropertykeys","titleHTML":"[[OwnPropertyKeys]] ( )","number":"3.1"},{"type":"op","aoid":"IsValidIntegerIndex","refId":"sec-isvalidintegerindex"},{"type":"clause","id":"sec-isvalidintegerindex","title":"IsValidIntegerIndex ( O, index )","titleHTML":"IsValidIntegerIndex ( O, index )","number":"3.2"},{"type":"op","aoid":"IntegerIndexedObjectByteLength","refId":"sec-integerindexedobjectbytelength"},{"type":"clause","id":"sec-integerindexedobjectbytelength","title":"IntegerIndexedObjectByteLength ( O, getBufferByteLength )","titleHTML":"IntegerIndexedObjectByteLength ( O, getBufferByteLength )","number":"3.3","referencingIds":["_ref_32","_ref_58"]},{"type":"op","aoid":"IntegerIndexedObjectLength","refId":"sec-integerindexedobjectlength"},{"type":"clause","id":"sec-integerindexedobjectlength","title":"IntegerIndexedObjectLength ( O, getBufferByteLength )","titleHTML":"IntegerIndexedObjectLength ( O, getBufferByteLength )","number":"3.4","referencingIds":["_ref_18","_ref_20","_ref_21","_ref_36","_ref_39","_ref_41","_ref_44","_ref_46","_ref_49","_ref_51","_ref_53","_ref_55","_ref_57","_ref_60","_ref_81","_ref_82"]},{"type":"op","aoid":"IsIntegerIndexedObjectOutOfBounds","refId":"sec-isintegerindexedobjectoutofbounds"},{"type":"clause","id":"sec-isintegerindexedobjectoutofbounds","title":"IsIntegerIndexedObjectOutOfBounds ( O, getBufferByteLength )","titleHTML":"IsIntegerIndexedObjectOutOfBounds ( O, getBufferByteLength )","number":"3.5","referencingIds":["_ref_22","_ref_26","_ref_28","_ref_30","_ref_34"]},{"type":"op","aoid":"IsArrayBufferViewOutOfBounds","refId":"sec-isarraybufferviewoutofbounds"},{"type":"clause","id":"sec-isarraybufferviewoutofbounds","title":"IsArrayBufferViewOutOfBounds ( O )","titleHTML":"IsArrayBufferViewOutOfBounds ( O )","number":"3.6"},{"type":"clause","id":"sec-integer-indexed-exotic-objects-mods","titleHTML":"Modifications to Integer-Indexed Exotic Objects","number":"3"},{"type":"op","aoid":"ValidateTypedArray","refId":"sec-validatetypedarray"},{"type":"clause","id":"sec-validatetypedarray","title":"ValidateTypedArray ( O )","titleHTML":"ValidateTypedArray ( O )","number":"4.1.1","referencingIds":["_ref_37","_ref_42","_ref_47"]},{"type":"clause","id":"sec-get-%typedarray%.prototype.bytelength","titleHTML":"get %TypedArray%.prototype.byteLength","number":"4.1.2"},{"type":"clause","id":"sec-get-%typedarray%.prototype.byteoffset","titleHTML":"get %TypedArray%.prototype.byteOffset","number":"4.1.3"},{"type":"clause","id":"sec-get-%typedarray%.prototype.length","titleHTML":"get %TypedArray%.prototype.length","number":"4.1.4"},{"type":"clause","id":"sec-%typedarray%.prototype.copywithin","title":"%TypedArray%.prototype.copyWithin ( target, start [ , end ] )","titleHTML":"%TypedArray%.prototype.copyWithin ( target, start [ , end ] )","number":"4.1.5"},{"type":"clause","id":"sec-%typedarray%.prototype.fill","title":"%TypedArray%.prototype.fill ( value [ , start [ , end ] ] )","titleHTML":"%TypedArray%.prototype.fill ( value [ , start [ , end ] ] )","number":"4.1.6"},{"type":"clause","id":"sec-%typedarray%.prototype.slice","title":"%TypedArray%.prototype.slice ( start, end )","titleHTML":"%TypedArray%.prototype.slice ( start, end )","number":"4.1.7"},{"type":"clause","id":"sec-%typedarray%.prototype.subarray","title":"%TypedArray%.prototype.subarray ( begin, end )","titleHTML":"%TypedArray%.prototype.subarray ( begin, end )","number":"4.1.8"},{"type":"op","aoid":"SetTypedArrayFromTypedArray","refId":"sec-settypedarrayfromtypedarray"},{"type":"clause","id":"sec-settypedarrayfromtypedarray","title":"SetTypedArrayFromTypedArray ( target, targetOffset, source )","titleHTML":"SetTypedArrayFromTypedArray ( target, targetOffset, source )","number":"4.1.9"},{"type":"clause","id":"sec-properties-of-the-%typedarrayprototype%-object-mods","titleHTML":"Modifications to Properties of the %TypedArray.prototype% Object","number":"4.1"},{"type":"op","aoid":"InitializeTypedArrayFromTypedArray","refId":"sec-initializetypedarrayfromtypedarray"},{"type":"clause","id":"sec-initializetypedarrayfromtypedarray","title":"InitializeTypedArrayFromTypedArray ( O, srcArray )","titleHTML":"InitializeTypedArrayFromTypedArray ( O, srcArray )","number":"4.2.1"},{"type":"op","aoid":"InitializeTypedArrayFromArrayBuffer","refId":"sec-initializetypedarrayfromarraybuffer"},{"type":"clause","id":"sec-initializetypedarrayfromarraybuffer","title":"InitializeTypedArrayFromArrayBuffer ( O, buffer, byteOffset, length )","titleHTML":"InitializeTypedArrayFromArrayBuffer ( O, buffer, byteOffset, length )","number":"4.2.2"},{"type":"clause","id":"sec-typedarray-constructors-mods","title":"Modifications to the TypedArray Constructors","titleHTML":"Modifications to the TypedArray Constructors","number":"4.2"},{"type":"clause","id":"sec-typedarray-objects-mods","titleHTML":"Modifications to TypedArray Objects","number":"4"},{"type":"op","aoid":"GetViewByteLength","refId":"sec-getviewbytelength"},{"type":"clause","id":"sec-getviewbytelength","title":"GetViewByteLength ( view, getBufferByteLength )","titleHTML":"GetViewByteLength ( view, getBufferByteLength )","number":"5.1.1","referencingIds":["_ref_65","_ref_68","_ref_71","_ref_77"]},{"type":"op","aoid":"IsViewOutOfBounds","refId":"sec-isviewoutofbounds"},{"type":"clause","id":"sec-isviewoutofbounds","title":"IsViewOutOfBounds ( view, getBufferByteLength )","titleHTML":"IsViewOutOfBounds ( view, getBufferByteLength )","number":"5.1.2","referencingIds":["_ref_25","_ref_27","_ref_67","_ref_70","_ref_76","_ref_79"]},{"type":"op","aoid":"GetViewValue","refId":"sec-getviewvalue"},{"type":"clause","id":"sec-getviewvalue","title":"GetViewValue ( view, requestIndex, isLittleEndian, type )","titleHTML":"GetViewValue ( view, requestIndex, isLittleEndian, type )","number":"5.1.3"},{"type":"op","aoid":"SetViewValue","refId":"sec-setviewvalue"},{"type":"clause","id":"sec-setviewvalue","title":"SetViewValue ( view, requestIndex, isLittleEndian, type, value )","titleHTML":"SetViewValue ( view, requestIndex, isLittleEndian, type, value )","number":"5.1.4"},{"type":"clause","id":"sec-abstract-operations-for-dataview-objects-mods","titleHTML":"Modifications to Abstract Operations For DataView Objects","number":"5.1"},{"type":"clause","id":"sec-dataview-buffer-byteoffset-bytelength","title":"DataView ( buffer [ , byteOffset [ , byteLength ] ] )","titleHTML":"DataView ( buffer [ , byteOffset [ , byteLength ] ] )","number":"5.2.1"},{"type":"clause","id":"sec-dataview-constructor-mods","titleHTML":"Modifications to the DataView Constructor","number":"5.2"},{"type":"clause","id":"sec-get-dataview.prototype.bytelength","titleHTML":"get DataView.prototype.byteLength","number":"5.3.1"},{"type":"clause","id":"sec-get-dataview.prototype.byteoffset","titleHTML":"get DataView.prototype.byteOffset","number":"5.3.2"},{"type":"clause","id":"sec-properties-of-the-dataview-prototype-object-mods","titleHTML":"Modifications to Properties of the DataView Prototype Object","number":"5.3"},{"type":"clause","id":"sec-dataview-objects-mods","titleHTML":"Modifications to DataView Objects","number":"5"},{"type":"op","aoid":"ValidateAtomicAccess","refId":"sec-validateatomicaccess"},{"type":"clause","id":"sec-validateatomicaccess","title":"ValidateAtomicAccess ( typedArray, requestIndex )","titleHTML":"ValidateAtomicAccess ( typedArray, requestIndex )","number":"6.1"},{"type":"clause","id":"sec-abstract-operations-for-atomics-mods","titleHTML":"Modifications to Abstract Operations for Atomics","number":"6"},{"type":"clause","id":"sec-maxbytelength-guidelines","titleHTML":"Resizable ArrayBuffer and growable SharedArrayBuffer Guidelines","number":"7"},{"type":"clause","id":"omitted-for-brevity","titleHTML":"Mechanical Changes Omitted for Brevity","number":"8"}]}`); ;let usesMultipage = false \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 387aa03..078901d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -12,10 +12,10 @@

Stage 3 Draft / November 29, 2022

+

Stage 3 Draft / November 29, 2022

Resizable ArrayBuffer and growable SharedArrayBuffer

-

We extend the ArrayBuffer and SharedArrayBuffer constructors to take an additional maximum byte length, which would construct dynamically resizable and growable array buffers, respectively. In addition, a transfer method is added to the ArrayBuffer prototype.

+

We extend the ArrayBuffer and SharedArrayBuffer constructors to take an additional maximum byte length, which would construct dynamically resizable and growable array buffers, respectively.

@@ -49,7 +49,7 @@

1.1.3 ArrayBufferByteLength ( arrayBuffer

1.1.4 MakeIdempotentArrayBufferByteLengthGetter ( order )

The abstract operation MakeIdempotentArrayBufferByteLengthGetter takes argument order (SeqCst or Unordered) and returns an Abstract Closure with one parameter. The returned Abstract Closure helps ensure that there there is a single shared memory read event of the byte length data block in the calling operation. It performs the following steps when called:

-
  1. NOTE: The [[ArrayBuffer]] slot is used for editorial clarity only, that a getter should only be used with a single ArrayBuffer.
  2. Let lengthStorage be { [[ArrayBuffer]]: empty, [[ByteLength]]: empty }.
  3. Let getter be a new Abstract Closure with parameters (buffer) that captures lengthStorage and order and performs the following steps when called:
    1. If lengthStorage.[[ByteLength]] is empty, then
      1. Assert: lengthStorage.[[ArrayBuffer]] is empty.
      2. Set lengthStorage.[[ArrayBuffer]] to buffer.
      3. Set lengthStorage.[[ByteLength]] to ArrayBufferByteLength(buffer, order).
    2. Assert: SameValue(lengthStorage.[[ArrayBuffer]], buffer) is true.
    3. Return lengthStorage.[[ByteLength]].
  4. Return getter.
+
  1. NOTE: The [[ArrayBuffer]] slot is used for editorial clarity only, that a getter should only be used with a single ArrayBuffer.
  2. Let lengthStorage be { [[ArrayBuffer]]: empty, [[ByteLength]]: empty }.
  3. Let getter be a new Abstract Closure with parameters (buffer) that captures lengthStorage and order and performs the following steps when called:
    1. If lengthStorage.[[ByteLength]] is empty, then
      1. Assert: lengthStorage.[[ArrayBuffer]] is empty.
      2. Set lengthStorage.[[ArrayBuffer]] to buffer.
      3. Set lengthStorage.[[ByteLength]] to ArrayBufferByteLength(buffer, order).
    2. Assert: SameValue(lengthStorage.[[ArrayBuffer]], buffer) is true.
    3. Return lengthStorage.[[ByteLength]].
  4. Return getter.
@@ -86,7 +86,7 @@

1.2 The ArrayBuffer Constructor

1.2.1 ArrayBuffer ( length [ , options ] )

When the ArrayBuffer function is called with argument length and optional argument options, the following steps are taken:

-
  1. If NewTarget is undefined, throw a TypeError exception.
  2. Let byteLength be ? ToIndex(length).
  3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
  4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
+
  1. If NewTarget is undefined, throw a TypeError exception.
  2. Let byteLength be ? ToIndex(length).
  3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
  4. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
@@ -107,36 +107,27 @@

1.3.1 get ArrayBuffer [ @@species ]

1.3.2 get ArrayBuffer.prototype.maxByteLength

ArrayBuffer.prototype.maxByteLength is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, return +0𝔽.
  5. If IsResizableArrayBuffer(O) is true, then
    1. Let length be O.[[ArrayBufferMaxByteLength]].
  6. Else,
    1. Let length be O.[[ArrayBufferByteLength]].
  7. Return 𝔽(length).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, return +0𝔽.
  5. If IsResizableArrayBuffer(O) is true, then
    1. Let length be O.[[ArrayBufferMaxByteLength]].
  6. Else,
    1. Let length be O.[[ArrayBufferByteLength]].
  7. Return 𝔽(length).

1.3.3 get ArrayBuffer.prototype.resizable

ArrayBuffer.prototype.resizable is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. Return IsResizableArrayBuffer(O).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. Return IsResizableArrayBuffer(O).

1.3.4 ArrayBuffer.prototype.slice ( start, end )

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  5. Let len be O.[[ArrayBufferByteLength]].
  6. Let relativeStart be ? ToIntegerOrInfinity(start).
  7. If relativeStart is -∞, let first be 0.
  8. Else if relativeStart < 0, let first be max(len + relativeStart, 0).
  9. Else, let first be min(relativeStart, len).
  10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  11. If relativeEnd is -∞, let final be 0.
  12. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  13. Else, let final be min(relativeEnd, len).
  14. Let newLen be max(final - first, 0).
  15. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
  16. Let new be ? Construct(ctor, « 𝔽(newLen) »).
  17. Perform ? RequireInternalSlot(new, [[ArrayBufferData]]).
  18. If IsSharedArrayBuffer(new) is true, throw a TypeError exception.
  19. If IsDetachedBuffer(new) is true, throw a TypeError exception.
  20. If SameValue(new, O) is true, throw a TypeError exception.
  21. If new.[[ArrayBufferByteLength]] < newLen, throw a TypeError exception.
  22. NOTE: Side-effects of the above steps may have detached or resized O.
  23. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  24. Let fromBuf be O.[[ArrayBufferData]].
  25. Let toBuf be new.[[ArrayBufferData]].
  26. If first < O.[[ArrayBufferByteLength]], then
    1. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, min(O.[[ArrayBufferByteLength]], newLen)).
  27. Return new.
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  5. Let len be O.[[ArrayBufferByteLength]].
  6. Let relativeStart be ? ToIntegerOrInfinity(start).
  7. If relativeStart is -∞, let first be 0.
  8. Else if relativeStart < 0, let first be max(len + relativeStart, 0).
  9. Else, let first be min(relativeStart, len).
  10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  11. If relativeEnd is -∞, let final be 0.
  12. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  13. Else, let final be min(relativeEnd, len).
  14. Let newLen be max(final - first, 0).
  15. Let ctor be ? SpeciesConstructor(O, %ArrayBuffer%).
  16. Let new be ? Construct(ctor, « 𝔽(newLen) »).
  17. Perform ? RequireInternalSlot(new, [[ArrayBufferData]]).
  18. If IsSharedArrayBuffer(new) is true, throw a TypeError exception.
  19. If IsDetachedBuffer(new) is true, throw a TypeError exception.
  20. If SameValue(new, O) is true, throw a TypeError exception.
  21. If new.[[ArrayBufferByteLength]] < newLen, throw a TypeError exception.
  22. NOTE: Side-effects of the above steps may have detached or resized O.
  23. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  24. Let fromBuf be O.[[ArrayBufferData]].
  25. Let toBuf be new.[[ArrayBufferData]].
  26. If first < O.[[ArrayBufferByteLength]], then
    1. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, min(O.[[ArrayBufferByteLength]], newLen)).
  27. Return new.

1.3.5 ArrayBuffer.prototype.resize ( newLength )

The following steps are taken:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]], throw a RangeError exception.
  7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
  8. If hostHandled is handled, return undefined.
  9. Let oldBlock be O.[[ArrayBufferData]].
  10. Let newBlock be ? CreateByteDataBlock(newByteLength).
  11. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
  12. Perform CopyDataBlockBytes(newBlock, 0, oldBlock, 0, copyLength).
  13. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations reserve the right to implement this method as in-place growth or shrinkage.
  14. Set O.[[ArrayBufferData]] to newBlock.
  15. Set O.[[ArrayBufferByteLength]] to newLength.
  16. Return undefined.
-
- - -

1.3.6 ArrayBuffer.prototype.transfer ( [ newLength ] )

-

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If newLength is undefined, then
    1. If IsDetachedBuffer(O) is true, throw a TypeError exception.
    2. Let newByteLength be O.[[ArrayBufferByteLength]].
  5. Else,
    1. Let newByteLength be ? ToIndex(newLength).
    2. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  6. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
  7. NOTE: This method returns a fixed-length ArrayBuffer.
  8. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
  9. Let fromBlock be O.[[ArrayBufferData]].
  10. Let toBlock be new.[[ArrayBufferData]].
  11. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
  12. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations reserve the right to implement this method as a zero-copy move or a realloc.
  13. Perform ? DetachArrayBuffer(O).
  14. NOTE: This will throw if O.[[ArrayBufferDetachKey]] is not undefined. The new ArrayBuffer is not yet observable at this point. If an implementation chooses to copy, it is free to check O.[[ArrayBufferDetachKey]] and throw before performing the copy in step 11.
  15. Return new.
- Note
-

The transfer method intentionally does not honour the @@species property when creating derived objects.

-
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
  4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
  5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]], throw a RangeError exception.
  7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
  8. If hostHandled is handled, return undefined.
  9. Let oldBlock be O.[[ArrayBufferData]].
  10. Let newBlock be ? CreateByteDataBlock(newByteLength).
  11. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
  12. Perform CopyDataBlockBytes(newBlock, 0, oldBlock, 0, copyLength).
  13. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations reserve the right to implement this method as in-place growth or shrinkage.
  14. Set O.[[ArrayBufferData]] to newBlock.
  15. Set O.[[ArrayBufferByteLength]] to newLength.
  16. Return undefined.
@@ -169,7 +160,7 @@

2.1.2 HostGrowSharedArrayBuffer ( bufferNote

The second requirement above is intentionally vague about how or when the current byte length of buffer is read. Because the byte length must be updated via an atomic read-modify-write operation on the underlying hardware, architectures that use load-link/store-conditional or load-exclusive/store-exclusive instruction pairs may wish to keep the paired instructions close in the instruction stream. As such, SharedArrayBuffer.prototype.grow itself does not perform bounds checking on newByteLength before calling HostGrowSharedArrayBuffer, nor is there a requirement on when the current byte length is read.

-

This is in contrast with HostResizeArrayBuffer, which is guaranteed that the value of newByteLength is ≥ 0 and ≤ buffer.[[ArrayBufferMaxByteLength]].

+

This is in contrast with HostResizeArrayBuffer, which is guaranteed that the value of newByteLength is ≥ 0 and ≤ buffer.[[ArrayBufferMaxByteLength]].

@@ -181,7 +172,7 @@

2.2 The SharedArrayBuffer Constructor

2.2.1 SharedArrayBuffer ( length [ , options ] )

When the SharedArrayBuffer function is called with argument length and optional argument options, the following steps are taken:

-
  1. If NewTarget is undefined, throw a TypeError exception.
  2. Let byteLength be ? ToIndex(length).
  3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
  4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
+
  1. If NewTarget is undefined, throw a TypeError exception.
  2. Let byteLength be ? ToIndex(length).
  3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
  4. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
@@ -191,26 +182,26 @@

2.3 Modifications to the Properties of the Share

2.3.1 get SharedArrayBuffer.prototype.byteLength

SharedArrayBuffer.prototype.byteLength is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Let length be O.[[ArrayBufferByteLength]]ArrayBufferByteLength(O, SeqCst).
  5. Return 𝔽(length).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Let length be O.[[ArrayBufferByteLength]]ArrayBufferByteLength(O, SeqCst).
  5. Return 𝔽(length).

2.3.2 get SharedArrayBuffer.prototype.growable

SharedArrayBuffer.prototype.growable is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Return IsResizableArrayBuffer(O).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Return IsResizableArrayBuffer(O).

2.3.3 get SharedArrayBuffer.prototype.maxByteLength

SharedArrayBuffer.prototype.maxByteLength is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. If IsResizableArrayBuffer(O) is true, then
    1. Let length be O.[[ArrayBufferMaxByteLength]].
  5. Else,
    1. Let length be O.[[ArrayBufferByteLength]].
  6. Return 𝔽(length).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. If IsResizableArrayBuffer(O) is true, then
    1. Let length be O.[[ArrayBufferMaxByteLength]].
  5. Else,
    1. Let length be O.[[ArrayBufferByteLength]].
  6. Return 𝔽(length).

2.3.4 SharedArrayBuffer.prototype.grow ( newLength )

The following steps are taken:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  5. Let hostHandled be ? HostGrowSharedArrayBuffer(O, newByteLength).
  6. If hostHandled is handled, return undefined.
  7. Let rawCurrentByteLengthBytesRead be a List of length 8 whose elements are nondeterministically chosen byte values.
  8. NOTE: In implementations, rawCurrentByteLengthBytesRead is the result of a load-link, of a load-exclusive, or of an operand of a read-modify-write instruction on the underlying hardware. The nondeterminism is a semantic prescription of the memory model to describe observable behaviour of hardware with weak consistency.
  9. Let byteLengthBlock be O.[[ArrayBufferByteLengthData]].
  10. Let isLittleEndian be the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
  11. Let currentByteLength be RawBytesToNumeric(BigUint64, rawCurrentByteLengthBytesRead, isLittleEndian).
  12. Let growFailed be false.
  13. If newByteLength < currentByteLength or newByteLength > O.[[ArrayBufferMaxByteLength]], set growFailed to true.
  14. Let byteLengthDelta be newByteLength - currentByteLength.
  15. If it is impossible to create a new Shared Data Block value consisting of byteLengthDelta bytes, set growFailed to true.
  16. NOTE: No new Shared Data Block is constructed and used here. The observable behaviour of growable SharedArrayBuffers is specified by allocating a max-sized Shared Data Block at construction time, and this step is intended to capture the requirement that implementations that run out of memory must throw a RangeError.
  17. NOTE: The above checks help ensure that concurrent calls to SharedArrayBuffer.prototype.grow are totally ordered. For example, consider two racing calls: sab.grow(10) and sab.grow(20). One of the two calls is guaranteed to win the race. The call to sab.grow(10) will never shrink sab even if sab.grow(20) happened first.
  18. If growFailed is false and newByteLengthcurrentByteLength, then
    1. NOTE: Resizes to the same length explicitly do nothing to avoid gratuitous synchronization.
    2. Let second be a new read-modify-write modification function with parameters (oldBytes, newBytes) that captures nothing and performs the following steps atomically when called:
      1. Return newBytes.
    3. Let newByteLengthBytes be NumericToRawBytes(BigUint64, (newByteLength), isLittleEndian).
    4. Let event be ReadModifyWriteSharedMemory { [[Order]]: SeqCst, [[NoTear]]: true, [[Block]]: byteLengthBlock, [[ByteIndex]]: 0, [[ElementSize]]: 8, [[Payload]]: newByteLengthBytes, [[ModifyOp]]: second }.
    5. NOTE: The new memory is already zeroed, as a O.[[ArrayBufferMaxByteLength]] sized Data Block is already allocated. This is a specification mechanism; an implementation is not required to reserve O.[[ArrayBufferMaxByteLength]] bytes of physical memory.
  19. Else,
    1. Let event be ReadSharedMemory { [[Order]]: SeqCst, [[NoTear]]: true, [[Block]]: byteLengthBlock, [[ByteIndex]]: 0, [[ElementSize]]: 8 }.
  20. Let execution be the [[CandidateExecution]] field of the surrounding agent's Agent Record.
  21. Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
  22. Append event to eventList.
  23. Append Chosen Value Record { [[Event]]: event, [[ChosenValue]]: rawCurrentByteLengthBytesRead } to execution.[[ChosenValues]].
  24. If growFailed is true, throw a RangeError exception.
  25. Return undefined.
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Let newByteLength be ? ToIntegerOrInfinity(newLength).
  5. Let hostHandled be ? HostGrowSharedArrayBuffer(O, newByteLength).
  6. If hostHandled is handled, return undefined.
  7. Let rawCurrentByteLengthBytesRead be a List of length 8 whose elements are nondeterministically chosen byte values.
  8. NOTE: In implementations, rawCurrentByteLengthBytesRead is the result of a load-link, of a load-exclusive, or of an operand of a read-modify-write instruction on the underlying hardware. The nondeterminism is a semantic prescription of the memory model to describe observable behaviour of hardware with weak consistency.
  9. Let byteLengthBlock be O.[[ArrayBufferByteLengthData]].
  10. Let isLittleEndian be the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
  11. Let currentByteLength be RawBytesToNumeric(BigUint64, rawCurrentByteLengthBytesRead, isLittleEndian).
  12. Let growFailed be false.
  13. If newByteLength < currentByteLength or newByteLength > O.[[ArrayBufferMaxByteLength]], set growFailed to true.
  14. Let byteLengthDelta be newByteLength - currentByteLength.
  15. If it is impossible to create a new Shared Data Block value consisting of byteLengthDelta bytes, set growFailed to true.
  16. NOTE: No new Shared Data Block is constructed and used here. The observable behaviour of growable SharedArrayBuffers is specified by allocating a max-sized Shared Data Block at construction time, and this step is intended to capture the requirement that implementations that run out of memory must throw a RangeError.
  17. NOTE: The above checks help ensure that concurrent calls to SharedArrayBuffer.prototype.grow are totally ordered. For example, consider two racing calls: sab.grow(10) and sab.grow(20). One of the two calls is guaranteed to win the race. The call to sab.grow(10) will never shrink sab even if sab.grow(20) happened first.
  18. If growFailed is false and newByteLengthcurrentByteLength, then
    1. NOTE: Resizes to the same length explicitly do nothing to avoid gratuitous synchronization.
    2. Let second be a new read-modify-write modification function with parameters (oldBytes, newBytes) that captures nothing and performs the following steps atomically when called:
      1. Return newBytes.
    3. Let newByteLengthBytes be NumericToRawBytes(BigUint64, (newByteLength), isLittleEndian).
    4. Let event be ReadModifyWriteSharedMemory { [[Order]]: SeqCst, [[NoTear]]: true, [[Block]]: byteLengthBlock, [[ByteIndex]]: 0, [[ElementSize]]: 8, [[Payload]]: newByteLengthBytes, [[ModifyOp]]: second }.
    5. NOTE: The new memory is already zeroed, as a O.[[ArrayBufferMaxByteLength]] sized Data Block is already allocated. This is a specification mechanism; an implementation is not required to reserve O.[[ArrayBufferMaxByteLength]] bytes of physical memory.
  19. Else,
    1. Let event be ReadSharedMemory { [[Order]]: SeqCst, [[NoTear]]: true, [[Block]]: byteLengthBlock, [[ByteIndex]]: 0, [[ElementSize]]: 8 }.
  20. Let execution be the [[CandidateExecution]] field of the surrounding agent's Agent Record.
  21. Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is AgentSignifier().
  22. Append event to eventList.
  23. Append Chosen Value Record { [[Event]]: event, [[ChosenValue]]: rawCurrentByteLengthBytesRead } to execution.[[ChosenValues]].
  24. If growFailed is true, throw a RangeError exception.
  25. Return undefined.
Note

Spurious failures of the compare-exchange to update the length are prohibited. If the bounds checking for the new length passes and the implementation is not out of memory, a ReadModifyWriteSharedMemory event (i.e. a successful compare-exchange) is always added into the candidate execution.

Many of the above steps are shared with the algorithm steps of Atomics.compareExchange and should be refactored when merged into the full specification.

@@ -221,7 +212,7 @@

2.3.4 SharedArrayBuffer.prototype.grow ( ne

2.3.5 SharedArrayBuffer.prototype.slice ( start, end )

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Let len be O.[[ArrayBufferByteLength]]ArrayBufferByteLength(O, SeqCst).
  5. Let relativeStart be ? ToIntegerOrInfinity(start).
  6. If relativeStart is -∞, let first be 0.
  7. Else if relativeStart < 0, let first be max(len + relativeStart, 0).
  8. Else, let first be min(relativeStart, len).
  9. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  10. If relativeEnd is -∞, let final be 0.
  11. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  12. Else, let final be min(relativeEnd, len).
  13. Let newLen be max(final - first, 0).
  14. Let ctor be ? SpeciesConstructor(O, %SharedArrayBuffer%).
  15. Let new be ? Construct(ctor, « 𝔽(newLen) »).
  16. Perform ? RequireInternalSlot(new, [[ArrayBufferData]]).
  17. NOTE: Unlike ArrayBuffers, SharedArrayBuffers cannot shrink, so the length does not need to be reloaded.
  18. If IsSharedArrayBuffer(new) is false, throw a TypeError exception.
  19. If new.[[ArrayBufferData]] and O.[[ArrayBufferData]] are the same Shared Data Block values, throw a TypeError exception.
  20. If new.[[ArrayBufferByteLength]] < newLen, throw a TypeError exception.
  21. Let fromBuf be O.[[ArrayBufferData]].
  22. Let toBuf be new.[[ArrayBufferData]].
  23. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLen).
  24. Return new.
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
  3. If IsSharedArrayBuffer(O) is false, throw a TypeError exception.
  4. Let len be O.[[ArrayBufferByteLength]]ArrayBufferByteLength(O, SeqCst).
  5. Let relativeStart be ? ToIntegerOrInfinity(start).
  6. If relativeStart is -∞, let first be 0.
  7. Else if relativeStart < 0, let first be max(len + relativeStart, 0).
  8. Else, let first be min(relativeStart, len).
  9. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  10. If relativeEnd is -∞, let final be 0.
  11. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  12. Else, let final be min(relativeEnd, len).
  13. Let newLen be max(final - first, 0).
  14. Let ctor be ? SpeciesConstructor(O, %SharedArrayBuffer%).
  15. Let new be ? Construct(ctor, « 𝔽(newLen) »).
  16. Perform ? RequireInternalSlot(new, [[ArrayBufferData]]).
  17. NOTE: Unlike ArrayBuffers, SharedArrayBuffers cannot shrink, so the length does not need to be reloaded.
  18. If IsSharedArrayBuffer(new) is false, throw a TypeError exception.
  19. If new.[[ArrayBufferData]] and O.[[ArrayBufferData]] are the same Shared Data Block values, throw a TypeError exception.
  20. If new.[[ArrayBufferByteLength]] < newLen, throw a TypeError exception.
  21. Let fromBuf be O.[[ArrayBufferData]].
  22. Let toBuf be new.[[ArrayBufferData]].
  23. Perform CopyDataBlockBytes(toBuf, 0, fromBuf, first, newLen).
  24. Return new.
@@ -232,26 +223,26 @@

3 Modifications to Integer-Indexed Exotic Object

3.1 [[OwnPropertyKeys]] ( )

The [[OwnPropertyKeys]] internal method of an Integer-Indexed exotic object O takes no arguments and returns a normal completion containing a List of property keys. It performs the following steps when called:

-
  1. Let keys be a new empty List.
  2. Assert: O is an Integer-Indexed exotic object.
  3. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is false, then
    1. For each integer i starting with 0 such that i < O.[[ArrayLength]], in ascending order, do
      1. Add ! ToString(𝔽(i)) as the last element of keys.
  4. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  5. Let len be IntegerIndexedObjectLength(O, getBufferByteLength).
  6. If len is not out-of-bounds, then
    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.
  7. For each own property key P of O such that Type(P) is String and P is not an integer index, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  8. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  9. Return keys.
+
  1. Let keys be a new empty List.
  2. Assert: O is an Integer-Indexed exotic object.
  3. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is false, then
    1. For each integer i starting with 0 such that i < O.[[ArrayLength]], in ascending order, do
      1. Add ! ToString(𝔽(i)) as the last element of keys.
  4. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  5. Let len be IntegerIndexedObjectLength(O, getBufferByteLength).
  6. If len is not out-of-bounds, then
    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.
  7. For each own property key P of O such that Type(P) is String and P is not an integer index, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  8. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  9. Return keys.

3.2 IsValidIntegerIndex ( O, index )

The abstract operation IsValidIntegerIndex takes arguments O (an Integer-Indexed exotic object) and index (a Number) and returns a Boolean. It performs the following steps when called:

-
  1. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false.
  2. If IsIntegralNumber(index) is false, return false.
  3. If index is -0𝔽, return false.
  4. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  5. NOTE: Bounds checking is not a synchronizing operation when O's backing buffer is a growable SharedArrayBuffer.
  6. Let length be IntegerIndexedObjectLength(O, getBufferByteLength).
  7. If length is out-of-bounds or (index) < 0 or (index) ≥ O.[[ArrayLength]]length, return false.
  8. Return true.
+
  1. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false.
  2. If IsIntegralNumber(index) is false, return false.
  3. If index is -0𝔽, return false.
  4. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  5. NOTE: Bounds checking is not a synchronizing operation when O's backing buffer is a growable SharedArrayBuffer.
  6. Let length be IntegerIndexedObjectLength(O, getBufferByteLength).
  7. If length is out-of-bounds or (index) < 0 or (index) ≥ O.[[ArrayLength]]length, return false.
  8. Return true.

3.3 IntegerIndexedObjectByteLength ( O, getBufferByteLength )

The abstract operation IntegerIndexedObjectByteLength takes arguments O (an Integer-Indexed exotic object) and getBufferByteLength (an Abstract Closure) and returns a non-negative integer. It performs the following steps when called:

-
  1. Let length be IntegerIndexedObjectLength(O, getBufferByteLength).
  2. If length is out-of-bounds or length = 0, return 0.
  3. If O.[[ByteLength]] is not auto, return O.[[ByteLength]].
  4. Let elementSize be TypedArrayElementSize(O).
  5. Return length × elementSize.
+
  1. Let length be IntegerIndexedObjectLength(O, getBufferByteLength).
  2. If length is out-of-bounds or length = 0, return 0.
  3. If O.[[ByteLength]] is not auto, return O.[[ByteLength]].
  4. Let elementSize be TypedArrayElementSize(O).
  5. Return length × elementSize.

3.4 IntegerIndexedObjectLength ( O, getBufferByteLength )

The abstract operation IntegerIndexedObjectLength takes arguments O (an Integer-Indexed exotic object) and getBufferByteLength (an Abstract Closure) and returns a non-negative integer or out-of-bounds. It performs the following steps when called:

-
  1. If IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is true, return out-of-bounds.
  2. If O.[[ArrayLength]] is not auto, return O.[[ArrayLength]].
  3. Let buffer be O.[[ViewedArrayBuffer]].
  4. Let bufferByteLength be getBufferByteLength(buffer).
  5. Assert: IsResizableArrayBuffer(buffer) is true.
  6. Let byteOffset be O.[[ByteOffset]].
  7. Let elementSize be TypedArrayElementSize(O).
  8. Return floor((bufferByteLength - byteOffset) / elementSize).
+
  1. If IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is true, return out-of-bounds.
  2. If O.[[ArrayLength]] is not auto, return O.[[ArrayLength]].
  3. Let buffer be O.[[ViewedArrayBuffer]].
  4. Let bufferByteLength be getBufferByteLength(buffer).
  5. Assert: IsResizableArrayBuffer(buffer) is true.
  6. Let byteOffset be O.[[ByteOffset]].
  7. Let elementSize be TypedArrayElementSize(O).
  8. Return floor((bufferByteLength - byteOffset) / elementSize).
@@ -263,7 +254,7 @@

3.5 IsIntegerIndexedObjectOutOfBounds ( O

3.6 IsArrayBufferViewOutOfBounds ( O )

The abstract operation IsArrayBufferViewOutOfBounds takes argument O (an Integer-Indexed exotic object or a DataView) and returns a Boolean. It checks if either any of a TypedArray's numeric properties or a DataView object's methods can reference a value at an index not contained within the underlying data block's bounds. This abstract operation exists as a convenience for upstream specifications. It performs the following steps when called:

-
  1. Let buffer be O.[[ViewedArrayBuffer]].
  2. If IsDetachedBuffer(buffer) is true, return true.
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. If IsSharedArrayBuffer(buffer) is true, then
    1. Assert: If O has a [[DataView]] internal slot, IsViewOutOfBounds(O, getBufferByteLength) is false. Else, IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is false.
    2. NOTE: SharedArrayBuffers can only grow, and views on it cannot go out of bounds after construction. This is special-cased in this operation to avoid shared memory loads of the buffer's byte length, which are not necessary for this check.
    3. Return false.
  5. If O has a [[DataView]] internal slot, return IsViewOutOfBounds(O, getBufferByteLength).
  6. Return IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength).
+
  1. Let buffer be O.[[ViewedArrayBuffer]].
  2. If IsDetachedBuffer(buffer) is true, return true.
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. If IsSharedArrayBuffer(buffer) is true, then
    1. Assert: If O has a [[DataView]] internal slot, IsViewOutOfBounds(O, getBufferByteLength) is false. Else, IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is false.
    2. NOTE: SharedArrayBuffers can only grow, and views on it cannot go out of bounds after construction. This is special-cased in this operation to avoid shared memory loads of the buffer's byte length, which are not necessary for this check.
    3. Return false.
  5. If O has a [[DataView]] internal slot, return IsViewOutOfBounds(O, getBufferByteLength).
  6. Return IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength).
@@ -277,25 +268,25 @@

4.1 Modifications to Properties of the %TypedArr

4.1.1 ValidateTypedArray ( O )

The abstract operation ValidateTypedArray takes argument O (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

-
  1. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  2. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  3. Let buffer be O.[[ViewedArrayBuffer]].
  4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  5. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  6. If IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is true, throw a TypeError exception.
  7. Return buffer.
+
  1. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  2. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  3. Let buffer be O.[[ViewedArrayBuffer]].
  4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  5. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  6. If IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is true, throw a TypeError exception.
  7. Return buffer.

4.1.2 get %TypedArray%.prototype.byteLength

%TypedArray%.prototype.byteLength is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, return +0𝔽.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. Let size be O.[[ByteLength]]IntegerIndexedObjectByteLength(O, getBufferByteLength).
  8. Return 𝔽(size).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, return +0𝔽.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. Let size be O.[[ByteLength]]IntegerIndexedObjectByteLength(O, getBufferByteLength).
  8. Return 𝔽(size).

4.1.3 get %TypedArray%.prototype.byteOffset

%TypedArray%.prototype.byteOffset is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, return +0𝔽.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. If IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is true, return +0𝔽.
  8. Let offset be O.[[ByteOffset]].
  9. Return 𝔽(offset).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, return +0𝔽.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. If IsIntegerIndexedObjectOutOfBounds(O, getBufferByteLength) is true, return +0𝔽.
  8. Let offset be O.[[ByteOffset]].
  9. Return 𝔽(offset).

4.1.4 get %TypedArray%.prototype.length

%TypedArray%.prototype.length is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, return +0𝔽.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. Let length be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  8. If length is out-of-bounds, set length to 0.
  9. Return 𝔽(length).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, return +0𝔽.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. Let length be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  8. If length is out-of-bounds, set length to 0.
  9. Return 𝔽(length).

This function is not generic. The this value must be an object with a [[TypedArrayName]] internal slot.

@@ -303,21 +294,21 @@

4.1.4 get %TypedArray%.prototype.length

4.1.5 %TypedArray%.prototype.copyWithin ( target, start [ , end ] )

The interpretation and use of the arguments of %TypedArray%.prototype.copyWithin are the same as for Array.prototype.copyWithin as defined in 23.1.3.4.

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? ValidateTypedArray(O).
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. Let len be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  5. Assert: len is not out-of-bounds.
  6. Let relativeTarget be ? ToIntegerOrInfinity(target).
  7. If relativeTarget is -∞, let to be 0.
  8. Else if relativeTarget < 0, let to be max(len + relativeTarget, 0).
  9. Else, let to be min(relativeTarget, len).
  10. Let relativeStart be ? ToIntegerOrInfinity(start).
  11. If relativeStart is -∞, let from be 0.
  12. Else if relativeStart < 0, let from be max(len + relativeStart, 0).
  13. Else, let from be min(relativeStart, len).
  14. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  15. If relativeEnd is -∞, let final be 0.
  16. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  17. Else, let final be min(relativeEnd, len).
  18. Let count be min(final - from, len - to).
  19. If count > 0, then
    1. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data.
    2. Let buffer be O.[[ViewedArrayBuffer]].
    3. Set getBufferByteLength to MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
    4. Set len to IntegerIndexedObjectLength(O, getBufferByteLength).
    5. If IsDetachedBuffer(buffer) is truelen is out-of-bounds, throw a TypeError exception.
    6. Let typedArrayName be the String value of O.[[TypedArrayName]].
    7. Let elementSize be the Element Size value specified in Table 67 for typedArrayName.
    8. Let bufferByteLen be len × elementSize.
    9. Let byteOffset be O.[[ByteOffset]].
    10. Let toByteIndex be to × elementSize + byteOffset.
    11. Let fromByteIndex be from × elementSize + byteOffset.
    12. Let countBytes be count × elementSize.
    13. If fromByteIndex < toByteIndex and toByteIndex < fromByteIndex + countBytes, then
      1. Let direction be -1.
      2. Set fromByteIndex to fromByteIndex + countBytes - 1.
      3. Set toByteIndex to toByteIndex + countBytes - 1.
    14. Else,
      1. Let direction be 1.
    15. Repeat, while countBytes > 0,
      1. If fromByteIndex < bufferByteLen and toByteIndex < bufferByteLen, then
        1. Let value be GetValueFromBuffer(buffer, fromByteIndex, Uint8, true, Unordered).
        2. Perform SetValueInBuffer(buffer, toByteIndex, Uint8, value, true, Unordered).
        3. Set fromByteIndex to fromByteIndex + direction.
        4. Set toByteIndex to toByteIndex + direction.
      2. Set countBytes to countBytes - 1.
  20. Return O.
+
  1. Let O be the this value.
  2. Perform ? ValidateTypedArray(O).
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. Let len be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  5. Assert: len is not out-of-bounds.
  6. Let relativeTarget be ? ToIntegerOrInfinity(target).
  7. If relativeTarget is -∞, let to be 0.
  8. Else if relativeTarget < 0, let to be max(len + relativeTarget, 0).
  9. Else, let to be min(relativeTarget, len).
  10. Let relativeStart be ? ToIntegerOrInfinity(start).
  11. If relativeStart is -∞, let from be 0.
  12. Else if relativeStart < 0, let from be max(len + relativeStart, 0).
  13. Else, let from be min(relativeStart, len).
  14. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  15. If relativeEnd is -∞, let final be 0.
  16. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  17. Else, let final be min(relativeEnd, len).
  18. Let count be min(final - from, len - to).
  19. If count > 0, then
    1. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data.
    2. Let buffer be O.[[ViewedArrayBuffer]].
    3. Set getBufferByteLength to MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
    4. Set len to IntegerIndexedObjectLength(O, getBufferByteLength).
    5. If IsDetachedBuffer(buffer) is truelen is out-of-bounds, throw a TypeError exception.
    6. Let typedArrayName be the String value of O.[[TypedArrayName]].
    7. Let elementSize be the Element Size value specified in Table 67 for typedArrayName.
    8. Let bufferByteLen be len × elementSize.
    9. Let byteOffset be O.[[ByteOffset]].
    10. Let toByteIndex be to × elementSize + byteOffset.
    11. Let fromByteIndex be from × elementSize + byteOffset.
    12. Let countBytes be count × elementSize.
    13. If fromByteIndex < toByteIndex and toByteIndex < fromByteIndex + countBytes, then
      1. Let direction be -1.
      2. Set fromByteIndex to fromByteIndex + countBytes - 1.
      3. Set toByteIndex to toByteIndex + countBytes - 1.
    14. Else,
      1. Let direction be 1.
    15. Repeat, while countBytes > 0,
      1. If fromByteIndex < bufferByteLen and toByteIndex < bufferByteLen, then
        1. Let value be GetValueFromBuffer(buffer, fromByteIndex, Uint8, true, Unordered).
        2. Perform SetValueInBuffer(buffer, toByteIndex, Uint8, value, true, Unordered).
        3. Set fromByteIndex to fromByteIndex + direction.
        4. Set toByteIndex to toByteIndex + direction.
      2. Set countBytes to countBytes - 1.
  20. Return O.

4.1.6 %TypedArray%.prototype.fill ( value [ , start [ , end ] ] )

The interpretation and use of the arguments of %TypedArray%.prototype.fill are the same as for Array.prototype.fill as defined in 23.1.3.7.

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? ValidateTypedArray(O).
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. Let len be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  5. Assert: len is not out-of-bounds.
  6. If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value).
  7. Otherwise, set value to ? ToNumber(value).
  8. Let relativeStart be ? ToIntegerOrInfinity(start).
  9. If relativeStart is -∞, let k be 0.
  10. Else if relativeStart < 0, let k be max(len + relativeStart, 0).
  11. Else, let k be min(relativeStart, len).
  12. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  13. If relativeEnd is -∞, let final be 0.
  14. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  15. Else, let final be min(relativeEnd, len).
  16. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
  17. Set getBufferByteLength to MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  18. Set len to IntegerIndexedObjectLength(O, getBufferByteLength).
  19. If len is out-of-bounds, throw a TypeError exception.
  20. Set final to min(final, len).
  21. Repeat, while k < final,
    1. Let Pk be ! ToString(𝔽(k)).
    2. Perform ! Set(O, Pk, value, true).
    3. Set k to k + 1.
  22. Return O.
+
  1. Let O be the this value.
  2. Perform ? ValidateTypedArray(O).
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. Let len be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  5. Assert: len is not out-of-bounds.
  6. If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value).
  7. Otherwise, set value to ? ToNumber(value).
  8. Let relativeStart be ? ToIntegerOrInfinity(start).
  9. If relativeStart is -∞, let k be 0.
  10. Else if relativeStart < 0, let k be max(len + relativeStart, 0).
  11. Else, let k be min(relativeStart, len).
  12. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  13. If relativeEnd is -∞, let final be 0.
  14. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  15. Else, let final be min(relativeEnd, len).
  16. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
  17. Set getBufferByteLength to MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  18. Set len to IntegerIndexedObjectLength(O, getBufferByteLength).
  19. If len is out-of-bounds, throw a TypeError exception.
  20. Set final to min(final, len).
  21. Repeat, while k < final,
    1. Let Pk be ! ToString(𝔽(k)).
    2. Perform ! Set(O, Pk, value, true).
    3. Set k to k + 1.
  22. Return O.

4.1.7 %TypedArray%.prototype.slice ( start, end )

The interpretation and use of the arguments of %TypedArray%.prototype.slice are the same as for Array.prototype.slice as defined in 23.1.3.28. The following steps are taken:

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? ValidateTypedArray(O).
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. Let len be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  5. Let relativeStart be ? ToIntegerOrInfinity(start).
  6. If relativeStart is -∞, let k be 0.
  7. Else if relativeStart < 0, let k be max(len + relativeStart, 0).
  8. Else, let k be min(relativeStart, len).
  9. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  10. If relativeEnd is -∞, let final be 0.
  11. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  12. Else, let final be min(relativeEnd, len).
  13. Let count be max(final - k, 0).
  14. Let A be ? TypedArraySpeciesCreate(O, « 𝔽(count) »).
  15. If count > 0, then
    1. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
    2. Set getBufferByteLength to MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
    3. Set len to IntegerIndexedObjectLength(O, getBufferByteLength).
    4. If len is out-of-bounds, throw a TypeError exception.
    5. Set final to min(final, len).
    6. Let srcName be the String value of O.[[TypedArrayName]].
    7. Let srcType be the Element Type value in Table 67 for srcName.
    8. Let targetName be the String value of A.[[TypedArrayName]].
    9. Let targetType be the Element Type value in Table 67 for targetName.
    10. If srcType is different from targetType, then
      1. Let n be 0.
      2. Repeat, while k < final,
        1. Let Pk be ! ToString(𝔽(k)).
        2. Let kValue be ! Get(O, Pk).
        3. Perform ! Set(A, ! ToString(𝔽(n)), kValue, true).
        4. Set k to k + 1.
        5. Set n to n + 1.
    11. Else,
      1. Let srcBuffer be O.[[ViewedArrayBuffer]].
      2. Let targetBuffer be A.[[ViewedArrayBuffer]].
      3. Let elementSize be the Element Size value specified in Table 67 for Element Type srcType.
      4. NOTE: If srcType and targetType are the same, the transfer must be performed in a manner that preserves the bit-level encoding of the source data.
      5. Let srcByteOffset be O.[[ByteOffset]].
      6. Let targetByteIndex be A.[[ByteOffset]].
      7. Let srcByteIndex be (k × elementSize) + srcByteOffset.
      8. Let limit be min(targetByteIndex + count × elementSize, len × elementSize).
      9. Repeat, while targetByteIndex < limit,
        1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered).
        2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, Uint8, value, true, Unordered).
        3. Set srcByteIndex to srcByteIndex + 1.
        4. Set targetByteIndex to targetByteIndex + 1.
  16. Return A.
+
  1. Let O be the this value.
  2. Perform ? ValidateTypedArray(O).
  3. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  4. Let len be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getBufferByteLength).
  5. Let relativeStart be ? ToIntegerOrInfinity(start).
  6. If relativeStart is -∞, let k be 0.
  7. Else if relativeStart < 0, let k be max(len + relativeStart, 0).
  8. Else, let k be min(relativeStart, len).
  9. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end).
  10. If relativeEnd is -∞, let final be 0.
  11. Else if relativeEnd < 0, let final be max(len + relativeEnd, 0).
  12. Else, let final be min(relativeEnd, len).
  13. Let count be max(final - k, 0).
  14. Let A be ? TypedArraySpeciesCreate(O, « 𝔽(count) »).
  15. If count > 0, then
    1. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
    2. Set getBufferByteLength to MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
    3. Set len to IntegerIndexedObjectLength(O, getBufferByteLength).
    4. If len is out-of-bounds, throw a TypeError exception.
    5. Set final to min(final, len).
    6. Let srcName be the String value of O.[[TypedArrayName]].
    7. Let srcType be the Element Type value in Table 67 for srcName.
    8. Let targetName be the String value of A.[[TypedArrayName]].
    9. Let targetType be the Element Type value in Table 67 for targetName.
    10. If srcType is different from targetType, then
      1. Let n be 0.
      2. Repeat, while k < final,
        1. Let Pk be ! ToString(𝔽(k)).
        2. Let kValue be ! Get(O, Pk).
        3. Perform ! Set(A, ! ToString(𝔽(n)), kValue, true).
        4. Set k to k + 1.
        5. Set n to n + 1.
    11. Else,
      1. Let srcBuffer be O.[[ViewedArrayBuffer]].
      2. Let targetBuffer be A.[[ViewedArrayBuffer]].
      3. Let elementSize be the Element Size value specified in Table 67 for Element Type srcType.
      4. NOTE: If srcType and targetType are the same, the transfer must be performed in a manner that preserves the bit-level encoding of the source data.
      5. Let srcByteOffset be O.[[ByteOffset]].
      6. Let targetByteIndex be A.[[ByteOffset]].
      7. Let srcByteIndex be (k × elementSize) + srcByteOffset.
      8. Let limit be min(targetByteIndex + count × elementSize, len × elementSize).
      9. Repeat, while targetByteIndex < limit,
        1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered).
        2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, Uint8, value, true, Unordered).
        3. Set srcByteIndex to srcByteIndex + 1.
        4. Set targetByteIndex to targetByteIndex + 1.
  16. Return A.

This function is not generic. The this value must be an object with a [[TypedArrayName]] internal slot.

@@ -325,14 +316,14 @@

4.1.7 %TypedArray%.prototype.slice ( start<

4.1.8 %TypedArray%.prototype.subarray ( begin, end )

Returns a new TypedArray whose element type is the same as this TypedArray and whose ArrayBuffer is the same as the ArrayBuffer of this TypedArray, referencing the elements at begin, inclusive, up to end, exclusive. If either begin or end is negative, it refers to an index from the end of the array, as opposed to from the beginning.

This method performs the following steps when called:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. Let getSrcBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  6. Let srcLength be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getSrcBufferByteLength).
  7. If srcLength is out-of-bounds, set srcLength to 0.
  8. Let relativeBegin be ? ToIntegerOrInfinity(begin).
  9. If relativeBegin is -∞, let beginIndex be 0.
  10. Else if relativeBegin < 0, let beginIndex be max(srcLength + relativeBegin, 0).
  11. Else, let beginIndex be min(relativeBegin, srcLength).
  12. If O.[[ArrayLength]] is auto and end is undefined, then
    1. Let newLength be undefined.
  13. Else,
    1. If end is undefined, let relativeEnd be srcLength; else let relativeEnd be ? ToIntegerOrInfinity(end).
    2. If relativeEnd is -∞, let endIndex be 0.
    3. Else if relativeEnd < 0, let endIndex be max(srcLength + relativeEnd, 0).
    4. Else, let endIndex be min(relativeEnd, srcLength).
    5. Let newLength be max(endIndex - beginIndex, 0).
  14. Let constructorName be the String value of O.[[TypedArrayName]].
  15. Let elementSize be the Element Size value specified in Table 67 for constructorName.
  16. Let srcByteOffset be O.[[ByteOffset]].
  17. Let beginByteOffset be srcByteOffset + beginIndex × elementSize.
  18. If newLength is undefined, then
    1. Let argumentsList be « buffer, 𝔽(beginByteOffset) ».
  19. Else,
    1. Let argumentsList be « buffer, 𝔽(beginByteOffset), 𝔽(newLength) ».
  20. Return ? TypedArraySpeciesCreate(O, argumentsList).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[TypedArrayName]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. Let getSrcBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  6. Let srcLength be O.[[ArrayLength]]IntegerIndexedObjectLength(O, getSrcBufferByteLength).
  7. If srcLength is out-of-bounds, set srcLength to 0.
  8. Let relativeBegin be ? ToIntegerOrInfinity(begin).
  9. If relativeBegin is -∞, let beginIndex be 0.
  10. Else if relativeBegin < 0, let beginIndex be max(srcLength + relativeBegin, 0).
  11. Else, let beginIndex be min(relativeBegin, srcLength).
  12. If O.[[ArrayLength]] is auto and end is undefined, then
    1. Let newLength be undefined.
  13. Else,
    1. If end is undefined, let relativeEnd be srcLength; else let relativeEnd be ? ToIntegerOrInfinity(end).
    2. If relativeEnd is -∞, let endIndex be 0.
    3. Else if relativeEnd < 0, let endIndex be max(srcLength + relativeEnd, 0).
    4. Else, let endIndex be min(relativeEnd, srcLength).
    5. Let newLength be max(endIndex - beginIndex, 0).
  14. Let constructorName be the String value of O.[[TypedArrayName]].
  15. Let elementSize be the Element Size value specified in Table 67 for constructorName.
  16. Let srcByteOffset be O.[[ByteOffset]].
  17. Let beginByteOffset be srcByteOffset + beginIndex × elementSize.
  18. If newLength is undefined, then
    1. Let argumentsList be « buffer, 𝔽(beginByteOffset) ».
  19. Else,
    1. Let argumentsList be « buffer, 𝔽(beginByteOffset), 𝔽(newLength) ».
  20. Return ? TypedArraySpeciesCreate(O, argumentsList).

This function is not generic. The this value must be an object with a [[TypedArrayName]] internal slot.

4.1.9 SetTypedArrayFromTypedArray ( target, targetOffset, source )

The abstract operation SetTypedArrayFromTypedArray takes arguments target (a TypedArray), targetOffset (a non-negative integer or +∞), and source (a TypedArray) and returns either a normal completion containing unused or a throw completion. It sets multiple values in target, starting at index targetOffset, reading the values from source. It performs the following steps when called:

-
  1. Assert: source is an Object that has a [[TypedArrayName]] internal slot.
  2. Let targetBuffer be target.[[ViewedArrayBuffer]].
  3. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
  4. Let getTargetBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  5. Let targetLength be target.[[ArrayLength]]IntegerIndexedObjectLength(target, getTargetBufferByteLength).
  6. If targetLength is out-of-bounds, throw a TypeError exception.
  7. Let srcBuffer be source.[[ViewedArrayBuffer]].
  8. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
  9. Let targetType be TypedArrayElementType(target).
  10. Let targetElementSize be TypedArrayElementSize(target).
  11. Let targetByteOffset be target.[[ByteOffset]].
  12. Let srcType be TypedArrayElementType(source).
  13. Let srcElementSize be TypedArrayElementSize(source).
  14. Let getSrcBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  15. Let srcLength be source.[[ArrayLength]]IntegerIndexedObjectLength(source, getSrcBufferByteLength).
  16. If srcLength is out-of-bounds, throw a TypeError exception.
  17. Let srcByteOffset be source.[[ByteOffset]].
  18. If targetOffset is +∞, throw a RangeError exception.
  19. If srcLength + targetOffset > targetLength, throw a RangeError exception.
  20. If target.[[ContentType]] ≠ source.[[ContentType]], throw a TypeError exception.
  21. If both IsSharedArrayBuffer(srcBuffer) and IsSharedArrayBuffer(targetBuffer) are true, then
    1. If srcBuffer.[[ArrayBufferData]] and targetBuffer.[[ArrayBufferData]] are the same Shared Data Block values, let same be true; else let same be false.
  22. Else, let same be SameValue(srcBuffer, targetBuffer).
  23. If same is true, then
    1. Let srcByteLength be source.[[ByteLength]]IntegerIndexedObjectByteLength(source, getSrcBufferByteLength).
    2. Set srcBuffer to ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcByteLength).
    3. Let srcByteIndex be 0.
  24. Else, let srcByteIndex be srcByteOffset.
  25. Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset.
  26. Let limit be targetByteIndex + targetElementSize × srcLength.
  27. If srcType is the same as targetType, then
    1. NOTE: If srcType and targetType are the same, the transfer must be performed in a manner that preserves the bit-level encoding of the source data.
    2. Repeat, while targetByteIndex < limit,
      1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered).
      2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, Uint8, value, true, Unordered).
      3. Set srcByteIndex to srcByteIndex + 1.
      4. Set targetByteIndex to targetByteIndex + 1.
  28. Else,
    1. Repeat, while targetByteIndex < limit,
      1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType, true, Unordered).
      2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, Unordered).
      3. Set srcByteIndex to srcByteIndex + srcElementSize.
      4. Set targetByteIndex to targetByteIndex + targetElementSize.
+
  1. Assert: source is an Object that has a [[TypedArrayName]] internal slot.
  2. Let targetBuffer be target.[[ViewedArrayBuffer]].
  3. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception.
  4. Let getTargetBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  5. Let targetLength be target.[[ArrayLength]]IntegerIndexedObjectLength(target, getTargetBufferByteLength).
  6. If targetLength is out-of-bounds, throw a TypeError exception.
  7. Let srcBuffer be source.[[ViewedArrayBuffer]].
  8. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
  9. Let targetType be TypedArrayElementType(target).
  10. Let targetElementSize be TypedArrayElementSize(target).
  11. Let targetByteOffset be target.[[ByteOffset]].
  12. Let srcType be TypedArrayElementType(source).
  13. Let srcElementSize be TypedArrayElementSize(source).
  14. Let getSrcBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  15. Let srcLength be source.[[ArrayLength]]IntegerIndexedObjectLength(source, getSrcBufferByteLength).
  16. If srcLength is out-of-bounds, throw a TypeError exception.
  17. Let srcByteOffset be source.[[ByteOffset]].
  18. If targetOffset is +∞, throw a RangeError exception.
  19. If srcLength + targetOffset > targetLength, throw a RangeError exception.
  20. If target.[[ContentType]] ≠ source.[[ContentType]], throw a TypeError exception.
  21. If both IsSharedArrayBuffer(srcBuffer) and IsSharedArrayBuffer(targetBuffer) are true, then
    1. If srcBuffer.[[ArrayBufferData]] and targetBuffer.[[ArrayBufferData]] are the same Shared Data Block values, let same be true; else let same be false.
  22. Else, let same be SameValue(srcBuffer, targetBuffer).
  23. If same is true, then
    1. Let srcByteLength be source.[[ByteLength]]IntegerIndexedObjectByteLength(source, getSrcBufferByteLength).
    2. Set srcBuffer to ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcByteLength).
    3. Let srcByteIndex be 0.
  24. Else, let srcByteIndex be srcByteOffset.
  25. Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset.
  26. Let limit be targetByteIndex + targetElementSize × srcLength.
  27. If srcType is the same as targetType, then
    1. NOTE: If srcType and targetType are the same, the transfer must be performed in a manner that preserves the bit-level encoding of the source data.
    2. Repeat, while targetByteIndex < limit,
      1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, Uint8, true, Unordered).
      2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, Uint8, value, true, Unordered).
      3. Set srcByteIndex to srcByteIndex + 1.
      4. Set targetByteIndex to targetByteIndex + 1.
  28. Else,
    1. Repeat, while targetByteIndex < limit,
      1. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType, true, Unordered).
      2. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, Unordered).
      3. Set srcByteIndex to srcByteIndex + srcElementSize.
      4. Set targetByteIndex to targetByteIndex + targetElementSize.
@@ -342,13 +333,13 @@

4.2 Modifications to the TypedArray C

4.2.1 InitializeTypedArrayFromTypedArray ( O, srcArray )

The abstract operation InitializeTypedArrayFromTypedArray takes arguments O (a TypedArray) and srcArray (a TypedArray) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

-
  1. Let srcData be srcArray.[[ViewedArrayBuffer]].
  2. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
  3. Let elementType be TypedArrayElementType(O).
  4. Let elementSize be TypedArrayElementSize(O).
  5. Let getSrcBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  6. Let elementLength be srcArray.[[ArrayLength]]IntegerIndexedObjectLength(srcArray, getSrcBufferByteLength).
  7. If elementLength is out-of-bounds, throw a TypeError exception.
  8. Let srcType be TypedArrayElementType(srcArray).
  9. Let srcElementSize be TypedArrayElementSize(srcArray).
  10. Let srcByteOffset be srcArray.[[ByteOffset]].
  11. Let byteLength be elementSize × elementLength.
  12. If elementType is the same as srcType, then
    1. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength).
  13. Else,
    1. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength).
    2. If srcArray.[[ContentType]] ≠ O.[[ContentType]], throw a TypeError exception.
    3. Let srcByteIndex be srcByteOffset.
    4. Let targetByteIndex be 0.
    5. Let count be elementLength.
    6. Repeat, while count > 0,
      1. Let value be GetValueFromBuffer(srcData, srcByteIndex, srcType, true, Unordered).
      2. Perform SetValueInBuffer(data, targetByteIndex, elementType, value, true, Unordered).
      3. Set srcByteIndex to srcByteIndex + srcElementSize.
      4. Set targetByteIndex to targetByteIndex + elementSize.
      5. Set count to count - 1.
  14. Set O.[[ViewedArrayBuffer]] to data.
  15. Set O.[[ByteLength]] to byteLength.
  16. Set O.[[ByteOffset]] to 0.
  17. Set O.[[ArrayLength]] to elementLength.
  18. Return unused.
+
  1. Let srcData be srcArray.[[ViewedArrayBuffer]].
  2. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
  3. Let elementType be TypedArrayElementType(O).
  4. Let elementSize be TypedArrayElementSize(O).
  5. Let getSrcBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  6. Let elementLength be srcArray.[[ArrayLength]]IntegerIndexedObjectLength(srcArray, getSrcBufferByteLength).
  7. If elementLength is out-of-bounds, throw a TypeError exception.
  8. Let srcType be TypedArrayElementType(srcArray).
  9. Let srcElementSize be TypedArrayElementSize(srcArray).
  10. Let srcByteOffset be srcArray.[[ByteOffset]].
  11. Let byteLength be elementSize × elementLength.
  12. If elementType is the same as srcType, then
    1. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength).
  13. Else,
    1. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength).
    2. If srcArray.[[ContentType]] ≠ O.[[ContentType]], throw a TypeError exception.
    3. Let srcByteIndex be srcByteOffset.
    4. Let targetByteIndex be 0.
    5. Let count be elementLength.
    6. Repeat, while count > 0,
      1. Let value be GetValueFromBuffer(srcData, srcByteIndex, srcType, true, Unordered).
      2. Perform SetValueInBuffer(data, targetByteIndex, elementType, value, true, Unordered).
      3. Set srcByteIndex to srcByteIndex + srcElementSize.
      4. Set targetByteIndex to targetByteIndex + elementSize.
      5. Set count to count - 1.
  14. Set O.[[ViewedArrayBuffer]] to data.
  15. Set O.[[ByteLength]] to byteLength.
  16. Set O.[[ByteOffset]] to 0.
  17. Set O.[[ArrayLength]] to elementLength.
  18. Return unused.

4.2.2 InitializeTypedArrayFromArrayBuffer ( O, buffer, byteOffset, length )

The abstract operation InitializeTypedArrayFromArrayBuffer takes arguments O (a TypedArray), buffer (an ArrayBuffer or a SharedArrayBuffer), byteOffset (an ECMAScript language value), and length (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

-
  1. Let elementSize be TypedArrayElementSize(O).
  2. Let offset be ? ToIndex(byteOffset).
  3. If offset modulo elementSize ≠ 0, throw a RangeError exception.
  4. Let bufferIsResizable be IsResizableArrayBuffer(buffer).
  5. If length is not undefined, then
    1. Let newLength be ? ToIndex(length).
  6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  7. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]ArrayBufferByteLength(buffer, SeqCst).
  8. If length is undefined and bufferIsResizable is true, then
    1. If offset > bufferByteLength, throw a RangeError exception.
    2. Set O.[[ByteLength]] to auto.
    3. Set O.[[ArrayLength]] to auto.
  9. Else,
    1. If length is undefined, then
      1. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception.
      2. Let newByteLength be bufferByteLength - offset.
      3. If newByteLength < 0, throw a RangeError exception.
    2. Else,
      1. Let newByteLength be newLength × elementSize.
      2. If offset + newByteLength > bufferByteLength, throw a RangeError exception.
    3. Set O.[[ViewedArrayBuffer]] to buffer.
    4. Set O.[[ByteLength]] to newByteLength.
    5. Set O.[[ByteOffset]] to offset.
    6. Set O.[[ArrayLength]] to newByteLength / elementSize.
  10. Set O.[[ViewedArrayBuffer]] to buffer.
  11. Set O.[[ByteOffset]] to offset.
  12. Return unused.
+
  1. Let elementSize be TypedArrayElementSize(O).
  2. Let offset be ? ToIndex(byteOffset).
  3. If offset modulo elementSize ≠ 0, throw a RangeError exception.
  4. Let bufferIsResizable be IsResizableArrayBuffer(buffer).
  5. If length is not undefined, then
    1. Let newLength be ? ToIndex(length).
  6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  7. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]ArrayBufferByteLength(buffer, SeqCst).
  8. If length is undefined and bufferIsResizable is true, then
    1. If offset > bufferByteLength, throw a RangeError exception.
    2. Set O.[[ByteLength]] to auto.
    3. Set O.[[ArrayLength]] to auto.
  9. Else,
    1. If length is undefined, then
      1. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception.
      2. Let newByteLength be bufferByteLength - offset.
      3. If newByteLength < 0, throw a RangeError exception.
    2. Else,
      1. Let newByteLength be newLength × elementSize.
      2. If offset + newByteLength > bufferByteLength, throw a RangeError exception.
    3. Set O.[[ViewedArrayBuffer]] to buffer.
    4. Set O.[[ByteLength]] to newByteLength.
    5. Set O.[[ByteOffset]] to offset.
    6. Set O.[[ArrayLength]] to newByteLength / elementSize.
  10. Set O.[[ViewedArrayBuffer]] to buffer.
  11. Set O.[[ByteOffset]] to offset.
  12. Return unused.
@@ -369,20 +360,20 @@

5.1.1 GetViewByteLength ( view,

5.1.2 IsViewOutOfBounds ( view, getBufferByteLength )

The abstract operation IsViewOutOfBounds takes arguments view (a DataView) and getBufferByteLength (an Abstract Closure) and returns a Boolean. It performs the following steps when called:

-
  1. Assert: Type(view) is Object and view has a [[DataView]] internal slot.
  2. Let buffer be view.[[ViewedArrayBuffer]].
  3. If IsDetachedBuffer(buffer) is true, return true.
  4. Let byteLength be GetViewByteLength(view, getBufferByteLength).
  5. If byteLength < 0, return true.
  6. Return false.
+
  1. Assert: Type(view) is Object and view has a [[DataView]] internal slot.
  2. Let buffer be view.[[ViewedArrayBuffer]].
  3. If IsDetachedBuffer(buffer) is true, return true.
  4. Let byteLength be GetViewByteLength(view, getBufferByteLength).
  5. If byteLength < 0, return true.
  6. Return false.

5.1.3 GetViewValue ( view, requestIndex, isLittleEndian, type )

The abstract operation GetViewValue takes arguments view (an ECMAScript language value), requestIndex (an ECMAScript language value), isLittleEndian (an ECMAScript language value), and type (a TypedArray element type) and returns either a normal completion containing either a Number or a BigInt, or a throw completion. It is used by functions on DataView instances to retrieve values from the view's buffer. It performs the following steps when called:

-
  1. Perform ? RequireInternalSlot(view, [[DataView]]).
  2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
  3. Let getIndex be ? ToIndex(requestIndex).
  4. Set isLittleEndian to ToBoolean(isLittleEndian).
  5. Let buffer be view.[[ViewedArrayBuffer]].
  6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  7. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  8. NOTE: Bounds checking is not a synchronizing operation when view's backing buffer is a growable SharedArrayBuffer.
  9. If IsViewOutOfBounds(view, getBufferByteLength) is true, throw a TypeError exception.
  10. Let viewOffset be view.[[ByteOffset]].
  11. Let viewSize be view.[[ByteLength]]GetViewByteLength(view, getBufferByteLength).
  12. Let elementSize be the Element Size value specified in Table 67 for Element Type type.
  13. If getIndex + elementSize > viewSize, throw a RangeError exception.
  14. Let bufferIndex be getIndex + viewOffset.
  15. Return GetValueFromBuffer(buffer, bufferIndex, type, false, Unordered, isLittleEndian).
+
  1. Perform ? RequireInternalSlot(view, [[DataView]]).
  2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
  3. Let getIndex be ? ToIndex(requestIndex).
  4. Set isLittleEndian to ToBoolean(isLittleEndian).
  5. Let buffer be view.[[ViewedArrayBuffer]].
  6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  7. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  8. NOTE: Bounds checking is not a synchronizing operation when view's backing buffer is a growable SharedArrayBuffer.
  9. If IsViewOutOfBounds(view, getBufferByteLength) is true, throw a TypeError exception.
  10. Let viewOffset be view.[[ByteOffset]].
  11. Let viewSize be view.[[ByteLength]]GetViewByteLength(view, getBufferByteLength).
  12. Let elementSize be the Element Size value specified in Table 67 for Element Type type.
  13. If getIndex + elementSize > viewSize, throw a RangeError exception.
  14. Let bufferIndex be getIndex + viewOffset.
  15. Return GetValueFromBuffer(buffer, bufferIndex, type, false, Unordered, isLittleEndian).

5.1.4 SetViewValue ( view, requestIndex, isLittleEndian, type, value )

The abstract operation SetViewValue takes arguments view (an ECMAScript language value), requestIndex (an ECMAScript language value), isLittleEndian (an ECMAScript language value), type (a TypedArray element type), and value (an ECMAScript language value) and returns either a normal completion containing undefined or a throw completion. It is used by functions on DataView instances to store values into the view's buffer. It performs the following steps when called:

-
  1. Perform ? RequireInternalSlot(view, [[DataView]]).
  2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
  3. Let getIndex be ? ToIndex(requestIndex).
  4. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
  5. Otherwise, let numberValue be ? ToNumber(value).
  6. Set isLittleEndian to ToBoolean(isLittleEndian).
  7. Let buffer be view.[[ViewedArrayBuffer]].
  8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  9. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  10. NOTE: Bounds checking is not a synchronizing operation when view's backing buffer is a growable SharedArrayBuffer.
  11. If IsViewOutOfBounds(view, getBufferByteLength) is true, throw a TypeError exception.
  12. Let viewOffset be view.[[ByteOffset]].
  13. Let viewSize be view.[[ByteLength]]GetViewByteLength(view, getBufferByteLength).
  14. Let elementSize be the Element Size value specified in Table 67 for Element Type type.
  15. If getIndex + elementSize > viewSize, throw a RangeError exception.
  16. Let bufferIndex be getIndex + viewOffset.
  17. Perform SetValueInBuffer(buffer, bufferIndex, type, numberValue, false, Unordered, isLittleEndian).
+
  1. Perform ? RequireInternalSlot(view, [[DataView]]).
  2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
  3. Let getIndex be ? ToIndex(requestIndex).
  4. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
  5. Otherwise, let numberValue be ? ToNumber(value).
  6. Set isLittleEndian to ToBoolean(isLittleEndian).
  7. Let buffer be view.[[ViewedArrayBuffer]].
  8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  9. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  10. NOTE: Bounds checking is not a synchronizing operation when view's backing buffer is a growable SharedArrayBuffer.
  11. If IsViewOutOfBounds(view, getBufferByteLength) is true, throw a TypeError exception.
  12. Let viewOffset be view.[[ByteOffset]].
  13. Let viewSize be view.[[ByteLength]]GetViewByteLength(view, getBufferByteLength).
  14. Let elementSize be the Element Size value specified in Table 67 for Element Type type.
  15. If getIndex + elementSize > viewSize, throw a RangeError exception.
  16. Let bufferIndex be getIndex + viewOffset.
  17. Perform SetValueInBuffer(buffer, bufferIndex, type, numberValue, false, Unordered, isLittleEndian).
@@ -392,7 +383,7 @@

5.2 Modifications to the DataView Constructor

5.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] )

When the DataView function is called with at least one argument buffer, the following steps are taken:

-
  1. If NewTarget is undefined, throw a TypeError exception.
  2. Perform ? RequireInternalSlot(buffer, [[ArrayBufferData]]).
  3. Let offset be ? ToIndex(byteOffset).
  4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  5. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]ArrayBufferByteLength(buffer, SeqCst).
  6. If offset > bufferByteLength, throw a RangeError exception.
  7. Let bufferIsResizable be IsResizableArrayBuffer(buffer).
  8. Let byteLengthChecked be empty.
  9. If bufferIsResizable is true and byteLength is undefined, then
    1. Let viewByteLength be auto.
  10. IfElse if byteLength is undefined, then
    1. Let viewByteLength be bufferByteLength - offset.
  11. Else,
    1. Set byteLengthChecked to ? ToIndex(byteLength).
    2. Let viewByteLength be ToIndex(byteLength)byteLengthChecked.
    3. If offset + viewByteLength > bufferByteLength, throw a RangeError exception.
  12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataView.prototype%", « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
  13. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  14. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  15. Set bufferByteLength be getBufferByteLength(buffer).
  16. If offset > bufferByteLength, throw a RangeError exception.
  17. If byteLengthChecked is not empty, then
    1. If offset + viewByteLength > bufferByteLength, throw a RangeError exception.
  18. Set O.[[ViewedArrayBuffer]] to buffer.
  19. Set O.[[ByteLength]] to viewByteLength.
  20. Set O.[[ByteOffset]] to offset.
  21. Return O.
+
  1. If NewTarget is undefined, throw a TypeError exception.
  2. Perform ? RequireInternalSlot(buffer, [[ArrayBufferData]]).
  3. Let offset be ? ToIndex(byteOffset).
  4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  5. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]ArrayBufferByteLength(buffer, SeqCst).
  6. If offset > bufferByteLength, throw a RangeError exception.
  7. Let bufferIsResizable be IsResizableArrayBuffer(buffer).
  8. Let byteLengthChecked be empty.
  9. If bufferIsResizable is true and byteLength is undefined, then
    1. Let viewByteLength be auto.
  10. IfElse if byteLength is undefined, then
    1. Let viewByteLength be bufferByteLength - offset.
  11. Else,
    1. Set byteLengthChecked to ? ToIndex(byteLength).
    2. Let viewByteLength be ToIndex(byteLength)byteLengthChecked.
    3. If offset + viewByteLength > bufferByteLength, throw a RangeError exception.
  12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataView.prototype%", « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
  13. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  14. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  15. Set bufferByteLength be getBufferByteLength(buffer).
  16. If offset > bufferByteLength, throw a RangeError exception.
  17. If byteLengthChecked is not empty, then
    1. If offset + viewByteLength > bufferByteLength, throw a RangeError exception.
  18. Set O.[[ViewedArrayBuffer]] to buffer.
  19. Set O.[[ByteLength]] to viewByteLength.
  20. Set O.[[ByteOffset]] to offset.
  21. Return O.
@@ -402,13 +393,13 @@

5.3 Modifications to Properties of the DataView

5.3.1 get DataView.prototype.byteLength

DataView.prototype.byteLength is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[DataView]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. If IsViewOutOfBounds(O, getBufferByteLength) is true, throw a TypeError exception.
  8. Let size be O.[[ByteLength]]GetViewByteLength(O, getBufferByteLength).
  9. Return 𝔽(size).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[DataView]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. If IsViewOutOfBounds(O, getBufferByteLength) is true, throw a TypeError exception.
  8. Let size be O.[[ByteLength]]GetViewByteLength(O, getBufferByteLength).
  9. Return 𝔽(size).

5.3.2 get DataView.prototype.byteOffset

DataView.prototype.byteOffset is an accessor property whose set accessor function is undefined. Its get accessor function performs the following steps:

-
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[DataView]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. If IsViewOutOfBounds(O, getBufferByteLength) is true, throw a TypeError exception.
  8. Let offset be O.[[ByteOffset]].
  9. Return 𝔽(offset).
+
  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[DataView]]).
  3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  6. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(SeqCst).
  7. If IsViewOutOfBounds(O, getBufferByteLength) is true, throw a TypeError exception.
  8. Let offset be O.[[ByteOffset]].
  9. Return 𝔽(offset).
@@ -419,7 +410,7 @@

6 Modifications to Abstract Operations for Atomi

6.1 ValidateAtomicAccess ( typedArray, requestIndex )

The abstract operation ValidateAtomicAccess takes arguments typedArray (a TypedArray) and requestIndex (an ECMAScript language value) and returns either a normal completion containing an integer or a throw completion. It performs the following steps when called:

-
  1. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  2. Let length be typedArray.[[ArrayLength]]IntegerIndexedObjectLength(typedArray, getBufferByteLength).
  3. Assert: length is not out-of-bounds.
  4. Let accessIndex be ? ToIndex(requestIndex).
  5. Assert: accessIndex ≥ 0.
  6. If accessIndexlength, throw a RangeError exception.
  7. Let arrayTypeName be typedArray.[[TypedArrayName]].
  8. Let elementSize be the Element Size value specified in Table 67 for arrayTypeName.
  9. Let offset be typedArray.[[ByteOffset]].
  10. Return (accessIndex × elementSize) + offset.
+
  1. Let getBufferByteLength be MakeIdempotentArrayBufferByteLengthGetter(Unordered).
  2. Let length be typedArray.[[ArrayLength]]IntegerIndexedObjectLength(typedArray, getBufferByteLength).
  3. Assert: length is not out-of-bounds.
  4. Let accessIndex be ? ToIndex(requestIndex).
  5. Assert: accessIndex ≥ 0.
  6. If accessIndexlength, throw a RangeError exception.
  7. Let arrayTypeName be typedArray.[[TypedArrayName]].
  8. Let elementSize be the Element Size value specified in Table 67 for arrayTypeName.
  9. Let offset be typedArray.[[ByteOffset]].
  10. Return (accessIndex × elementSize) + offset.
@@ -451,9 +442,9 @@

7 Resizable ArrayBuffer and growable SharedArray

8 Mechanical Changes Omitted for Brevity

\ No newline at end of file diff --git a/spec.html b/spec.html index fdcb42d..947476e 100644 --- a/spec.html +++ b/spec.html @@ -14,7 +14,7 @@

Resizable ArrayBuffer and growable SharedArrayBuffer

-

We extend the `ArrayBuffer` and `SharedArrayBuffer` constructors to take an additional maximum byte length, which would construct dynamically resizable and growable array buffers, respectively. In addition, a `transfer` method is added to the `ArrayBuffer` prototype.

+

We extend the `ArrayBuffer` and `SharedArrayBuffer` constructors to take an additional maximum byte length, which would construct dynamically resizable and growable array buffers, respectively.

@@ -288,35 +288,6 @@

ArrayBuffer.prototype.resize ( _newLength_ )

1. Return *undefined*.
- - -

ArrayBuffer.prototype.transfer ( [ _newLength_ ] )

-

This method performs the following steps when called:

- - 1. Let _O_ be the *this* value. - 1. Perform ? RequireInternalSlot(_O_, [[ArrayBufferData]]). - 1. If IsSharedArrayBuffer(_O_) is *true*, throw a *TypeError* exception. - 1. If _newLength_ is *undefined*, then - 1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception. - 1. Let _newByteLength_ be _O_.[[ArrayBufferByteLength]]. - 1. Else, - 1. Let _newByteLength_ be ? ToIndex(_newLength_). - 1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception. - 1. Let _new_ be ? Construct(%ArrayBuffer%, « 𝔽(_newByteLength_) »). - 1. NOTE: This method returns a fixed-length ArrayBuffer. - 1. Let _copyLength_ be min(_newByteLength_, _O_.[[ArrayBufferByteLength]]). - 1. Let _fromBlock_ be _O_.[[ArrayBufferData]]. - 1. Let _toBlock_ be _new_.[[ArrayBufferData]]. - 1. [id="step-transfer-copy-bytes"] Perform CopyDataBlockBytes(_toBlock_, 0, _fromBlock_, 0, _copyLength_). - 1. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations reserve the right to implement this method as a zero-copy move or a `realloc`. - 1. Perform ? DetachArrayBuffer(_O_). - 1. NOTE: This will throw if _O_.[[ArrayBufferDetachKey]] is not undefined. The new ArrayBuffer is not yet observable at this point. If an implementation chooses to copy, it is free to check _O_.[[ArrayBufferDetachKey]] and throw before performing the copy in step . - 1. Return _new_. - - -

The `transfer` method intentionally does not honour the @@species property when creating derived objects.

-
-