25.3 DataView Objects
25.3.1 Abstract Operations For DataView Objects
25.3.1.1 DataView With Buffer Witness Records
A DataView With Buffer Witness Record is a
DataView With Buffer Witness Records have the fields listed in
Field Name | Value | Meaning |
---|---|---|
[[Object]] | a DataView | The DataView object whose buffer's byte length is loaded. |
[[CachedBufferByteLength]] |
a non-negative |
The byte length of the object's [[ViewedArrayBuffer]] when the |
25.3.1.2 MakeDataViewWithBufferWitnessRecord ( obj, order )
The abstract operation MakeDataViewWithBufferWitnessRecord takes arguments obj (a DataView) and order (
- Let buffer be obj.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , then- Let byteLength be
detached .
- Let byteLength be
- Else,
- Let byteLength be
ArrayBufferByteLength (buffer, order).
- Let byteLength be
- Return the
DataView With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength }.
25.3.1.3 GetViewByteLength ( viewRecord )
The abstract operation GetViewByteLength takes argument viewRecord (a
Assert :IsViewOutOfBounds (viewRecord) isfalse .- Let view be viewRecord.[[Object]].
- If view.[[ByteLength]] is not
auto , return view.[[ByteLength]]. Assert :IsFixedLengthArrayBuffer (view.[[ViewedArrayBuffer]]) isfalse .- Let byteOffset be view.[[ByteOffset]].
- Let byteLength be viewRecord.[[CachedBufferByteLength]].
Assert : byteLength is notdetached .- Return byteLength - byteOffset.
25.3.1.4 IsViewOutOfBounds ( viewRecord )
The abstract operation IsViewOutOfBounds takes argument viewRecord (a
- Let view be viewRecord.[[Object]].
- Let bufferByteLength be viewRecord.[[CachedBufferByteLength]].
Assert :IsDetachedBuffer (view.[[ViewedArrayBuffer]]) istrue if and only if bufferByteLength isdetached .- If bufferByteLength is
detached , returntrue . - Let byteOffsetStart be view.[[ByteOffset]].
- If view.[[ByteLength]] is
auto , then- Let byteOffsetEnd be bufferByteLength.
- Else,
- Let byteOffsetEnd be byteOffsetStart + view.[[ByteLength]].
- If byteOffsetStart > bufferByteLength or byteOffsetEnd > bufferByteLength, return
true . - NOTE: 0-length DataViews are not considered out-of-bounds.
- Return
false .
25.3.1.5 GetViewValue ( view, requestIndex, isLittleEndian, type )
The abstract operation GetViewValue takes arguments view (an
- Perform ?
RequireInternalSlot (view, [[DataView]]). Assert : view has a [[ViewedArrayBuffer]] internal slot.- Let getIndex be ?
ToIndex (requestIndex). - Set isLittleEndian to
ToBoolean (isLittleEndian). - Let viewOffset be view.[[ByteOffset]].
- Let viewRecord be
MakeDataViewWithBufferWitnessRecord (view,unordered ). - NOTE: Bounds checking is not a synchronizing operation when view's backing buffer is a
growable SharedArrayBuffer . - If
IsViewOutOfBounds (viewRecord) istrue , throw aTypeError exception. - Let viewSize be
GetViewByteLength (viewRecord). - Let elementSize be the Element Size value specified in
Table 71 for Element Type type. - If getIndex + elementSize > viewSize, throw a
RangeError exception. - Let bufferIndex be getIndex + viewOffset.
- Return
GetValueFromBuffer (view.[[ViewedArrayBuffer]], bufferIndex, type,false ,unordered , isLittleEndian).
25.3.1.6 SetViewValue ( view, requestIndex, isLittleEndian, type, value )
The abstract operation SetViewValue takes arguments view (an
- Perform ?
RequireInternalSlot (view, [[DataView]]). Assert : view has a [[ViewedArrayBuffer]] internal slot.- Let getIndex be ?
ToIndex (requestIndex). - If
IsBigIntElementType (type) istrue , let numberValue be ?ToBigInt (value). - Otherwise, let numberValue be ?
ToNumber (value). - Set isLittleEndian to
ToBoolean (isLittleEndian). - Let viewOffset be view.[[ByteOffset]].
- Let viewRecord be
MakeDataViewWithBufferWitnessRecord (view,unordered ). - NOTE: Bounds checking is not a synchronizing operation when view's backing buffer is a
growable SharedArrayBuffer . - If
IsViewOutOfBounds (viewRecord) istrue , throw aTypeError exception. - Let viewSize be
GetViewByteLength (viewRecord). - Let elementSize be the Element Size value specified in
Table 71 for Element Type type. - If getIndex + elementSize > viewSize, throw a
RangeError exception. - Let bufferIndex be getIndex + viewOffset.
- Perform
SetValueInBuffer (view.[[ViewedArrayBuffer]], bufferIndex, type, numberValue,false ,unordered , isLittleEndian). - Return
undefined .
25.3.2 The DataView Constructor
The DataView
- is %DataView%.
- is the initial value of the
"DataView" property of theglobal object . - creates and initializes a new DataView when called as a
constructor . - is not intended to be called as a function and will throw an exception when called in that manner.
- may be used as the value of an
extends
clause of a class definition. Subclassconstructors that intend to inherit the specified DataView behaviour must include asuper
call to the DataViewconstructor to create and initialize subclass instances with the internal state necessary to support theDataView.prototype
built-in methods.
25.3.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] )
This function performs the following steps when called:
- If NewTarget is
undefined , throw aTypeError exception. - Perform ?
RequireInternalSlot (buffer, [[ArrayBufferData]]). - Let offset be ?
ToIndex (byteOffset). - If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Let bufferByteLength be
ArrayBufferByteLength (buffer,seq-cst ). - If offset > bufferByteLength, throw a
RangeError exception. - Let bufferIsFixedLength be
IsFixedLengthArrayBuffer (buffer). - If byteLength is
undefined , then- If bufferIsFixedLength is
true , then- Let viewByteLength be bufferByteLength - offset.
- Else,
- Let viewByteLength be
auto .
- Let viewByteLength be
- If bufferIsFixedLength is
- Else,
- Let viewByteLength be ?
ToIndex (byteLength). - If offset + viewByteLength > bufferByteLength, throw a
RangeError exception.
- Let viewByteLength be ?
- Let O be ?
OrdinaryCreateFromConstructor (NewTarget,"%DataView.prototype%" , « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). - If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Set bufferByteLength to
ArrayBufferByteLength (buffer,seq-cst ). - If offset > bufferByteLength, throw a
RangeError exception. - If byteLength is not
undefined , then- If offset + viewByteLength > bufferByteLength, throw a
RangeError exception.
- If offset + viewByteLength > bufferByteLength, throw a
- Set O.[[ViewedArrayBuffer]] to buffer.
- Set O.[[ByteLength]] to viewByteLength.
- Set O.[[ByteOffset]] to offset.
- Return O.
25.3.3 Properties of the DataView Constructor
The DataView
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
25.3.3.1 DataView.prototype
The initial value of DataView.prototype
is the
This property has the attributes { [[Writable]]:
25.3.4 Properties of the DataView Prototype Object
The DataView prototype object:
- is %DataView.prototype%.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% . - is an
ordinary object . - does not have a [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], or [[ByteOffset]] internal slot.
25.3.4.1 get DataView.prototype.buffer
DataView.prototype.buffer
is an
- Let O be the
this value. - Perform ?
RequireInternalSlot (O, [[DataView]]). Assert : O has a [[ViewedArrayBuffer]] internal slot.- Let buffer be O.[[ViewedArrayBuffer]].
- Return buffer.
25.3.4.2 get DataView.prototype.byteLength
DataView.prototype.byteLength
is an
- Let O be the
this value. - Perform ?
RequireInternalSlot (O, [[DataView]]). Assert : O has a [[ViewedArrayBuffer]] internal slot.- Let viewRecord be
MakeDataViewWithBufferWitnessRecord (O,seq-cst ). - If
IsViewOutOfBounds (viewRecord) istrue , throw aTypeError exception. - Let size be
GetViewByteLength (viewRecord). - Return
𝔽 (size).
25.3.4.3 get DataView.prototype.byteOffset
DataView.prototype.byteOffset
is an
- Let O be the
this value. - Perform ?
RequireInternalSlot (O, [[DataView]]). Assert : O has a [[ViewedArrayBuffer]] internal slot.- Let viewRecord be
MakeDataViewWithBufferWitnessRecord (O,seq-cst ). - If
IsViewOutOfBounds (viewRecord) istrue , throw aTypeError exception. - Let offset be O.[[ByteOffset]].
- Return
𝔽 (offset).
25.3.4.4 DataView.prototype.constructor
The initial value of DataView.prototype.constructor
is
25.3.4.5 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
GetViewValue (v, byteOffset, littleEndian,bigint64 ).
25.3.4.6 DataView.prototype.getBigUint64 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
GetViewValue (v, byteOffset, littleEndian,biguint64 ).
25.3.4.7 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
GetViewValue (v, byteOffset, littleEndian,float32 ).
25.3.4.8 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
GetViewValue (v, byteOffset, littleEndian,float64 ).
25.3.4.9 DataView.prototype.getInt8 ( byteOffset )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
GetViewValue (v, byteOffset,true ,int8 ).
25.3.4.10 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
GetViewValue (v, byteOffset, littleEndian,int16 ).
25.3.4.11 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
GetViewValue (v, byteOffset, littleEndian,int32 ).
25.3.4.12 DataView.prototype.getUint8 ( byteOffset )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
GetViewValue (v, byteOffset,true ,uint8 ).
25.3.4.13 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
GetViewValue (v, byteOffset, littleEndian,uint16 ).
25.3.4.14 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
GetViewValue (v, byteOffset, littleEndian,uint32 ).
25.3.4.15 DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
SetViewValue (v, byteOffset, littleEndian,bigint64 , value).
25.3.4.16 DataView.prototype.setBigUint64 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
SetViewValue (v, byteOffset, littleEndian,biguint64 , value).
25.3.4.17 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
SetViewValue (v, byteOffset, littleEndian,float32 , value).
25.3.4.18 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
SetViewValue (v, byteOffset, littleEndian,float64 , value).
25.3.4.19 DataView.prototype.setInt8 ( byteOffset, value )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
SetViewValue (v, byteOffset,true ,int8 , value).
25.3.4.20 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
SetViewValue (v, byteOffset, littleEndian,int16 , value).
25.3.4.21 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
SetViewValue (v, byteOffset, littleEndian,int32 , value).
25.3.4.22 DataView.prototype.setUint8 ( byteOffset, value )
This method performs the following steps when called:
- Let v be the
this value. - Return ?
SetViewValue (v, byteOffset,true ,uint8 , value).
25.3.4.23 DataView.prototype.setUint16 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
SetViewValue (v, byteOffset, littleEndian,uint16 , value).
25.3.4.24 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] )
This method performs the following steps when called:
- Let v be the
this value. - If littleEndian is not present, set littleEndian to
false . - Return ?
SetViewValue (v, byteOffset, littleEndian,uint32 , value).
25.3.4.25 DataView.prototype [ @@toStringTag ]
The initial value of the
This property has the attributes { [[Writable]]:
25.3.5 Properties of DataView Instances
DataView instances are
The value of the [[DataView]] internal slot is not used within this specification. The simple presence of that internal slot is used within the specification to identify objects created using the DataView