25.3 DataView Objects
25.3.1 Abstract Operations For DataView Objects
25.3.1.1 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 buffer be view.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Let viewOffset be view.[[ByteOffset]].
- Let viewSize be view.[[ByteLength]].
- Let elementSize be the Element Size value specified in
Table 70 for Element Type type. - If getIndex + elementSize > viewSize, throw a
RangeError exception. - Let bufferIndex be getIndex + viewOffset.
- Return
GetValueFromBuffer (buffer, bufferIndex, type,false ,Unordered , isLittleEndian).
25.3.1.2 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 buffer be view.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Let viewOffset be view.[[ByteOffset]].
- Let viewSize be view.[[ByteLength]].
- Let elementSize be the Element Size value specified in
Table 70 for Element Type type. - If getIndex + elementSize > viewSize, throw a
RangeError exception. - Let bufferIndex be getIndex + viewOffset.
- Perform
SetValueInBuffer (buffer, 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 buffer.[[ArrayBufferByteLength]].
- If offset > bufferByteLength, throw a
RangeError exception. - If byteLength is
undefined , then- Let viewByteLength be bufferByteLength - offset.
- 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 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 buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Let size be O.[[ByteLength]].
- 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 buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) 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