@@ -107,17 +107,18 @@ namespace Js
107
107
Var GetValue (Var offset, const char16* funcName, BOOL isLittleEndian = FALSE )
108
108
{
109
109
ScriptContext* scriptContext = GetScriptContext ();
110
- if (this ->GetArrayBuffer ()->IsDetached ())
111
- {
112
- JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray, funcName);
113
- }
114
110
115
111
uint32 length = GetLength ();
116
112
if (length < sizeof (TypeName))
117
113
{
118
114
JavascriptError::ThrowRangeError (scriptContext, JSERR_DataView_InvalidOffset, funcName);
119
115
}
116
+
120
117
uint32 byteOffset = ArrayBuffer::ToIndex (offset, JSERR_DataView_InvalidOffset, scriptContext, length - sizeof (TypeName), false );
118
+ if (this ->GetArrayBuffer ()->IsDetached ())
119
+ {
120
+ JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray, funcName);
121
+ }
121
122
122
123
TypeName item;
123
124
TypeName* typedBuffer = (TypeName*)(buffer + byteOffset);
@@ -142,17 +143,18 @@ namespace Js
142
143
Var GetValueWithCheck (Var offset, BOOL isLittleEndian, const char16* funcName)
143
144
{
144
145
ScriptContext* scriptContext = GetScriptContext ();
145
- if (this ->GetArrayBuffer ()->IsDetached ())
146
- {
147
- JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray, funcName);
148
- }
149
146
150
147
uint32 length = GetLength ();
151
148
if (length < sizeof (TypeName))
152
149
{
153
150
JavascriptError::ThrowRangeError (scriptContext, JSERR_DataView_InvalidOffset, funcName);
154
151
}
152
+
155
153
uint32 byteOffset = ArrayBuffer::ToIndex (offset, JSERR_DataView_InvalidOffset, scriptContext, length - sizeof (TypeName), false );
154
+ if (this ->GetArrayBuffer ()->IsDetached ())
155
+ {
156
+ JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray, funcName);
157
+ }
156
158
157
159
TypeName item;
158
160
TypeName *typedBuffer = (TypeName*)(buffer + byteOffset);
@@ -177,17 +179,18 @@ namespace Js
177
179
void SetValue (Var offset, TypeName value, BOOL isLittleEndian, const char16 *funcName)
178
180
{
179
181
ScriptContext* scriptContext = GetScriptContext ();
180
- if (this ->GetArrayBuffer ()->IsDetached ())
181
- {
182
- JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray, funcName);
183
- }
184
182
185
183
uint32 length = GetLength ();
186
184
if (length < sizeof (TypeName))
187
185
{
188
186
JavascriptError::ThrowRangeError (scriptContext, JSERR_DataView_InvalidOffset, funcName);
189
187
}
188
+
190
189
uint32 byteOffset = ArrayBuffer::ToIndex (offset, JSERR_DataView_InvalidOffset, scriptContext, length - sizeof (TypeName), false );
190
+ if (this ->GetArrayBuffer ()->IsDetached ())
191
+ {
192
+ JavascriptError::ThrowTypeError (scriptContext, JSERR_DetachedTypedArray, funcName);
193
+ }
191
194
192
195
TypeName* typedBuffer = (TypeName*)(buffer + byteOffset);
193
196
if (!isLittleEndian)
0 commit comments