• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/builtins/builtins_dataview.h"
17 #include "ecmascript/base/number_helper.h"
18 #include "ecmascript/builtins/builtins_arraybuffer.h"
19 #include "ecmascript/ecma_macros.h"
20 #include "ecmascript/global_env.h"
21 #include "ecmascript/js_arraybuffer.h"
22 #include "ecmascript/js_tagged_number.h"
23 #include "ecmascript/js_tagged_value-inl.h"
24 #include "ecmascript/js_tagged_value.h"
25 
26 namespace panda::ecmascript::builtins {
27 // 24.2.2.1
DataViewConstructor(EcmaRuntimeCallInfo * argv)28 JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv)
29 {
30     ASSERT(argv);
31     BUILTINS_API_TRACE(argv->GetThread(), DataView, Constructor);
32     JSThread *thread = argv->GetThread();
33     [[maybe_unused]] EcmaHandleScope handleScope(thread);
34     JSHandle<JSTaggedValue> ctor = GetConstructor(argv);
35     JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
36     // 1. If NewTarget is undefined, throw a TypeError exception.
37     if (newTarget->IsUndefined()) {
38         THROW_TYPE_ERROR_AND_RETURN(thread, "newtarget is undefined", JSTaggedValue::Exception());
39     }
40     JSHandle<JSTaggedValue> bufferHandle = GetCallArg(argv, 0);
41     // 2. If Type(buffer) is not Object, throw a TypeError exception.
42     if (!bufferHandle->IsECMAObject()) {
43         THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not Object", JSTaggedValue::Exception());
44     }
45     // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception.
46     if (!bufferHandle->IsArrayBuffer()) {
47         THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not ArrayBuffer", JSTaggedValue::Exception());
48     }
49     JSHandle<JSTaggedValue> offsetHandle = GetCallArg(argv, 1);
50     // 4. Let numberOffset be ToNumber(byteOffset).
51     JSTaggedNumber offsetNumber = JSTaggedValue::ToNumber(thread, offsetHandle);
52     // 6. ReturnIfAbrupt(offset).
53     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
54     int32_t offsetInt = base::NumberHelper::DoubleInRangeInt32(offsetNumber.GetNumber());
55     // 7. If numberOffset ≠ offset or offset < 0, throw a RangeError exception.
56     if (offsetInt < 0) {
57         THROW_RANGE_ERROR_AND_RETURN(thread, "Offset out of range", JSTaggedValue::Exception());
58     }
59     uint32_t offset = offsetInt;
60     // 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
61     if (BuiltinsArrayBuffer::IsDetachedBuffer(bufferHandle.GetTaggedValue())) {
62         THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception());
63     }
64     // 9. Let bufferByteLength be the value of buffer’s [[ArrayBufferByteLength]] internal slot.
65     JSHandle<JSArrayBuffer> arrBufHandle(bufferHandle);
66     uint32_t bufByteLen = arrBufHandle->GetArrayBufferByteLength();
67     // 10. If offset > bufferByteLength, throw a RangeError exception.
68     if (offset > bufByteLen) {
69         THROW_RANGE_ERROR_AND_RETURN(thread, "offset > bufferByteLength", JSTaggedValue::Exception());
70     }
71     uint32_t viewByteLen;
72     JSHandle<JSTaggedValue> byteLenHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
73     // 11. If byteLength is undefined, then Let viewByteLength be bufferByteLength – offset.
74     if (byteLenHandle->IsUndefined()) {
75         viewByteLen = bufByteLen - offset;
76     } else {
77         // Let viewByteLength be ToIndex(byteLength).
78         JSTaggedNumber byteLen = JSTaggedValue::ToIndex(thread, byteLenHandle);
79         // ReturnIfAbrupt(viewByteLength).
80         RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
81         viewByteLen = byteLen.ToInt32();
82         // If offset+viewByteLength > bufferByteLength, throw a RangeError exception.
83         if (offset + viewByteLen > bufByteLen) {
84             THROW_RANGE_ERROR_AND_RETURN(thread, "offset + viewByteLen > bufByteLen", JSTaggedValue::Exception());
85         }
86     }
87     // 13. Let O be OrdinaryCreateFromConstructor OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%",
88     // «[[DataView]],[[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]]» ).
89     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
90     JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), newTarget);
91     // 14. ReturnIfAbrupt(O).
92     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
93     JSHandle<JSDataView> dataView(obj);
94     // 15. Set O’s [[DataView]] internal slot to true.
95     dataView->SetDataView(thread, JSTaggedValue::True());
96     // 16. Set O’s [[ViewedArrayBuffer]] internal slot to buffer.
97     dataView->SetViewedArrayBuffer(thread, bufferHandle.GetTaggedValue());
98     // 17. Set O’s [[ByteLength]] internal slot to viewByteLength.
99     dataView->SetByteLength(viewByteLen);
100     // 18. Set O’s [[ByteOffset]] internal slot to offset.
101     dataView->SetByteOffset(offset);
102     // 19. Return O.
103     return JSTaggedValue(dataView.GetTaggedValue());
104 }
105 
106 // 24.2.4.1
GetBuffer(EcmaRuntimeCallInfo * argv)107 JSTaggedValue BuiltinsDataView::GetBuffer(EcmaRuntimeCallInfo *argv)
108 {
109     ASSERT(argv);
110     BUILTINS_API_TRACE(argv->GetThread(), DataView, GetBuffer);
111     JSThread *thread = argv->GetThread();
112     [[maybe_unused]] EcmaHandleScope handleScope(thread);
113     // 1. Let O be the this value.
114     JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
115     // 2. f Type(O) is not Object, throw a TypeError exception.
116     if (!thisHandle->IsECMAObject()) {
117         THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
118     }
119     // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception.
120     if (!thisHandle->IsDataView()) {
121         THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception());
122     }
123     JSHandle<JSDataView> dataView(thisHandle);
124     // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
125     JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
126     // 5. Return buffer.
127     return JSTaggedValue(buffer);
128 }
129 
130 // 24.2.4.2
GetByteLength(EcmaRuntimeCallInfo * argv)131 JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv)
132 {
133     ASSERT(argv);
134     BUILTINS_API_TRACE(argv->GetThread(), DataView, GetByteLength);
135     JSThread *thread = argv->GetThread();
136     [[maybe_unused]] EcmaHandleScope handleScope(thread);
137     // 1. Let O be the this value.
138     JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
139     // 2. If Type(O) is not Object, throw a TypeError exception.
140     if (!thisHandle->IsECMAObject()) {
141         THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
142     }
143     // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception.
144     if (!thisHandle->IsDataView()) {
145         THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception());
146     }
147     JSHandle<JSDataView> dataView(thisHandle);
148     // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
149     JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
150     // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
151     if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) {
152         THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
153     }
154     // 6. Let size be the value of O’s [[ByteLength]] internal slot.
155     uint32_t size = dataView->GetByteLength();
156     // 7. Return size.
157     return JSTaggedValue(size);
158 }
159 
160 // 24.2.4.3
GetOffset(EcmaRuntimeCallInfo * argv)161 JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv)
162 {
163     ASSERT(argv);
164     BUILTINS_API_TRACE(argv->GetThread(), DataView, GetOffset);
165     JSThread *thread = argv->GetThread();
166     [[maybe_unused]] EcmaHandleScope handleScope(thread);
167     // 1. Let O be the this value.
168     JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
169     // 2. If Type(O) is not Object, throw a TypeError exception.
170     if (!thisHandle->IsECMAObject()) {
171         THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
172     }
173     // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception.
174     if (!thisHandle->IsDataView()) {
175         THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception());
176     }
177     JSHandle<JSDataView> dataView(thisHandle);
178     // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot.
179     JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
180     // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
181     if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) {
182         THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
183     }
184     // 6. Let offset be the value of O’s [[ByteOffset]] internal slot.
185     uint32_t offset = dataView->GetByteOffset();
186     // 7. Return offset.
187     return JSTaggedValue(offset);
188 }
189 
190 // 24.2.4.5
GetFloat32(EcmaRuntimeCallInfo * argv)191 JSTaggedValue BuiltinsDataView::GetFloat32(EcmaRuntimeCallInfo *argv)
192 {
193     ASSERT(argv);
194     return GetTypedValue(argv, DataViewType::FLOAT32);
195 }
196 
197 // 24.2.4.6
GetFloat64(EcmaRuntimeCallInfo * argv)198 JSTaggedValue BuiltinsDataView::GetFloat64(EcmaRuntimeCallInfo *argv)
199 {
200     ASSERT(argv);
201     return GetTypedValue(argv, DataViewType::FLOAT64);
202 }
203 
204 // 24.2.4.7
GetInt8(EcmaRuntimeCallInfo * argv)205 JSTaggedValue BuiltinsDataView::GetInt8(EcmaRuntimeCallInfo *argv)
206 {
207     ASSERT(argv);
208     return GetTypedValue(argv, DataViewType::INT8);
209 }
210 
211 // 24.2.4.8
GetInt16(EcmaRuntimeCallInfo * argv)212 JSTaggedValue BuiltinsDataView::GetInt16(EcmaRuntimeCallInfo *argv)
213 {
214     ASSERT(argv);
215     return GetTypedValue(argv, DataViewType::INT16);
216 }
217 
218 // 24.2.4.9
GetInt32(EcmaRuntimeCallInfo * argv)219 JSTaggedValue BuiltinsDataView::GetInt32(EcmaRuntimeCallInfo *argv)
220 {
221     ASSERT(argv);
222     return GetTypedValue(argv, DataViewType::INT32);
223 }
224 
225 // 24.2.4.10
GetUint8(EcmaRuntimeCallInfo * argv)226 JSTaggedValue BuiltinsDataView::GetUint8(EcmaRuntimeCallInfo *argv)
227 {
228     ASSERT(argv);
229     return GetTypedValue(argv, DataViewType::UINT8);
230 }
231 
232 // 24.2.4.11
GetUint16(EcmaRuntimeCallInfo * argv)233 JSTaggedValue BuiltinsDataView::GetUint16(EcmaRuntimeCallInfo *argv)
234 {
235     ASSERT(argv);
236     return GetTypedValue(argv, DataViewType::UINT16);
237 }
238 
239 // 24.2.4.12
GetUint32(EcmaRuntimeCallInfo * argv)240 JSTaggedValue BuiltinsDataView::GetUint32(EcmaRuntimeCallInfo *argv)
241 {
242     ASSERT(argv);
243     return GetTypedValue(argv, DataViewType::UINT32);
244 }
245 
246 // 24.2.4.13
SetFloat32(EcmaRuntimeCallInfo * argv)247 JSTaggedValue BuiltinsDataView::SetFloat32(EcmaRuntimeCallInfo *argv)
248 {
249     ASSERT(argv);
250     return SetTypedValue(argv, DataViewType::FLOAT32);
251 }
252 
253 // 24.2.4.14
SetFloat64(EcmaRuntimeCallInfo * argv)254 JSTaggedValue BuiltinsDataView::SetFloat64(EcmaRuntimeCallInfo *argv)
255 {
256     ASSERT(argv);
257     return SetTypedValue(argv, DataViewType::FLOAT64);
258 }
259 
260 // 24.2.4.15
SetInt8(EcmaRuntimeCallInfo * argv)261 JSTaggedValue BuiltinsDataView::SetInt8(EcmaRuntimeCallInfo *argv)
262 {
263     ASSERT(argv);
264     return SetTypedValue(argv, DataViewType::INT8);
265 }
266 
267 // 24.2.4.16
SetInt16(EcmaRuntimeCallInfo * argv)268 JSTaggedValue BuiltinsDataView::SetInt16(EcmaRuntimeCallInfo *argv)
269 {
270     ASSERT(argv);
271     return SetTypedValue(argv, DataViewType::INT16);
272 }
273 
274 // 24.2.4.17
SetInt32(EcmaRuntimeCallInfo * argv)275 JSTaggedValue BuiltinsDataView::SetInt32(EcmaRuntimeCallInfo *argv)
276 {
277     ASSERT(argv);
278     return SetTypedValue(argv, DataViewType::INT32);
279 }
280 
281 // 24.2.4.18
SetUint8(EcmaRuntimeCallInfo * argv)282 JSTaggedValue BuiltinsDataView::SetUint8(EcmaRuntimeCallInfo *argv)
283 {
284     ASSERT(argv);
285     return SetTypedValue(argv, DataViewType::UINT8);
286 }
287 
288 // 24.2.4.19
SetUint16(EcmaRuntimeCallInfo * argv)289 JSTaggedValue BuiltinsDataView::SetUint16(EcmaRuntimeCallInfo *argv)
290 {
291     ASSERT(argv);
292     return SetTypedValue(argv, DataViewType::UINT16);
293 }
294 
295 // 24.2.4.20
SetUint32(EcmaRuntimeCallInfo * argv)296 JSTaggedValue BuiltinsDataView::SetUint32(EcmaRuntimeCallInfo *argv)
297 {
298     ASSERT(argv);
299     return SetTypedValue(argv, DataViewType::UINT32);
300 }
301 
302 // 24.2.1.1
GetViewValue(JSThread * thread,const JSHandle<JSTaggedValue> & view,const JSHandle<JSTaggedValue> & requestIndex,JSTaggedValue littleEndian,DataViewType type)303 JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
304                                              const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
305                                              DataViewType type)
306 {
307     BUILTINS_API_TRACE(thread, DataView, GetViewValue);
308     // 1. If Type(view) is not Object, throw a TypeError exception.
309     if (!view->IsECMAObject()) {
310         THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
311     }
312     // 2. If view does not have a [[DataView]] internal slot, throw a TypeError exception.
313     if (!view->IsDataView()) {
314         THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception());
315     }
316     // 3. Let numberIndex be ToNumber(requestIndex).
317     JSTaggedNumber numberIndex = JSTaggedValue::ToNumber(thread, requestIndex);
318     // 5. ReturnIfAbrupt(getIndex).
319     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
320     int32_t indexInt = base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
321     // 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
322     if (indexInt < 0) {
323         THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
324     }
325     uint32_t index = indexInt;
326     // 7. Let isLittleEndian be ToBoolean(isLittleEndian).
327     bool isLittleEndian;
328     if (littleEndian.IsUndefined()) {
329         isLittleEndian = false;
330     } else {
331         isLittleEndian = littleEndian.ToBoolean();
332     }
333     // 8. Let buffer be the value of view’s [[ViewedArrayBuffer]] internal slot.
334     JSHandle<JSDataView> dataView(view);
335     JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
336     // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
337     if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) {
338         THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
339     }
340     // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot.
341     uint32_t offset = dataView->GetByteOffset();
342     // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot.
343     uint32_t size = dataView->GetByteLength();
344     // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type.
345     uint32_t elementSize = JSDataView::GetElementSize(type);
346     // 13. If getIndex +elementSize > viewSize, throw a RangeError exception.
347     if (index + elementSize > size) {
348         THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception());
349     }
350     // 14. Let bufferIndex be getIndex + viewOffset.
351     uint32_t bufferIndex = index + offset;
352     // 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian).
353     return BuiltinsArrayBuffer::GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian);
354 }
355 
356 // 24.2.1.2
SetViewValue(JSThread * thread,const JSHandle<JSTaggedValue> & view,const JSHandle<JSTaggedValue> & requestIndex,JSTaggedValue littleEndian,DataViewType type,const JSHandle<JSTaggedValue> & value)357 JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
358                                              const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
359                                              DataViewType type, const JSHandle<JSTaggedValue> &value)
360 {
361     // 1. If Type(view) is not Object, throw a TypeError exception.
362     BUILTINS_API_TRACE(thread, DataView, SetViewValue);
363     if (!view->IsECMAObject()) {
364         THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception());
365     }
366     // 2. If view does not have a [[DataView]] internal slot, throw a TypeError exception.
367     if (!view->IsDataView()) {
368         THROW_TYPE_ERROR_AND_RETURN(thread, "view is not dataview", JSTaggedValue::Exception());
369     }
370     // 3. Let numberIndex be ToNumber(requestIndex).
371     JSTaggedNumber numberIndex = JSTaggedValue::ToIndex(thread, requestIndex);
372     // 5. ReturnIfAbrupt(getIndex).
373     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
374     int64_t index = base::NumberHelper::DoubleInRangeInt32(numberIndex.GetNumber());
375     // 6. If numberIndex ≠ getIndex or getIndex < 0, throw a RangeError exception.
376     if (index < 0) {
377         THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
378     }
379     JSTaggedNumber numVal = JSTaggedValue::ToNumber(thread, value);
380     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
381     // 7. Let isLittleEndian be ToBoolean(isLittleEndian).
382     bool isLittleEndian;
383     if (littleEndian.IsUndefined()) {
384         isLittleEndian = false;
385     } else {
386         isLittleEndian = littleEndian.ToBoolean();
387     }
388     // 8. Let buffer be the value of view’s [[ViewedArrayBuffer]] internal slot.
389     JSHandle<JSDataView> dataView(view);
390     JSTaggedValue buffer = dataView->GetViewedArrayBuffer();
391     // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
392     if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) {
393         THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
394     }
395     // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot.
396     uint32_t offset = dataView->GetByteOffset();
397     // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot.
398     uint32_t size = dataView->GetByteLength();
399     // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type.
400     uint32_t elementSize = JSDataView::GetElementSize(type);
401     // 13. If getIndex +elementSize > viewSize, throw a RangeError exception.
402     if (index + elementSize > size) {
403         THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception());
404     }
405     // 14. Let bufferIndex be getIndex + viewOffset.
406     uint32_t bufferIndex = index + offset;
407     // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian).
408     return BuiltinsArrayBuffer::SetValueInBuffer(buffer, bufferIndex, type, numVal, isLittleEndian);
409 }
410 
GetTypedValue(EcmaRuntimeCallInfo * argv,DataViewType type)411 JSTaggedValue BuiltinsDataView::GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type)
412 {
413     JSThread *thread = argv->GetThread();
414     [[maybe_unused]] EcmaHandleScope handleScope(thread);
415     JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
416     JSHandle<JSTaggedValue> offsetHandle = GetCallArg(argv, 0);
417     if (type == DataViewType::UINT8 || type == DataViewType::INT8) {
418         return GetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type);
419     }
420     JSHandle<JSTaggedValue> littleEndianHandle = GetCallArg(argv, 1);
421     return GetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type);
422 }
423 
SetTypedValue(EcmaRuntimeCallInfo * argv,DataViewType type)424 JSTaggedValue BuiltinsDataView::SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type)
425 {
426     JSThread *thread = argv->GetThread();
427     [[maybe_unused]] EcmaHandleScope handleScope(thread);
428     JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
429     JSHandle<JSTaggedValue> offsetHandle = GetCallArg(argv, 0);
430     JSHandle<JSTaggedValue> value = GetCallArg(argv, 1);
431     if (type == DataViewType::UINT8 || type == DataViewType::INT8) {
432         return SetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type, value);
433     }
434     JSHandle<JSTaggedValue> littleEndianHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
435     return SetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type, value);
436 }
437 }  // namespace panda::ecmascript::builtins
438