archives

« Bugzilla Issues Index

#4516 — 24.2.2.1 DataView: "byteOffset" argument should be optional


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


Per steps 4-7, calling `new DataView(new ArrayBuffer(0))` throws a RangeError since ToNumber(undefined)=NaN and ToInteger(NaN)=0 and Nan!=0.


In addition, the handling of byteOffset for
DataView (buffer [ , byteOffset [ , byteLength ] ] )
is different from its handling for
%TypedArray% (buffer [ , byteOffset [ , byteLength ] ] )

this seems like an undesirable inconsistency that should be fixed.

The fix in 24.2.2.1:

Remove the current step 4.
Replace current step 5 with:
Let /offset/ be ToInteger(/byteoffset/).
Replace current step 7 with:
If /offset/ < 0, throw a *RangeError* exception.


If 24.2.2.1 DataView(...) gets changed to match 22.2.1.5 %TypedArray%(...), the offset checks in 24.2.1.1 GetViewValue and 24.2.1.2 SetViewValue should probably be changed, too.