14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/base/builtins_base.h"
204514f5e3Sopenharmony_ci#include "ecmascript/js_dataview.h"
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_ci// List of functions in DataView, excluding the constructor and '@@' properties.
234514f5e3Sopenharmony_ci// V(name, func, length, stubIndex)
244514f5e3Sopenharmony_ci// where BuiltinsDataView::func refers to the native implementation of DataView.prototype[name].
254514f5e3Sopenharmony_ci//       kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available.
264514f5e3Sopenharmony_ci#define BUILTIN_DATA_VIEW_PROTOTYPE_FUNCTIONS(V)                                    \
274514f5e3Sopenharmony_ci    /* For %Type% of 1 byte: */                                                     \
284514f5e3Sopenharmony_ci    /*   DataView.prototype.get%Type% ( byteOffset ) */                             \
294514f5e3Sopenharmony_ci    /* For %Type% of 2 or more bytes: */                                            \
304514f5e3Sopenharmony_ci    /*   DataView.prototype.get%Type% ( byteOffset [ , littleEndian ] ) */          \
314514f5e3Sopenharmony_ci    V("getFloat32",     GetFloat32,     1, DataViewGetFloat32  )                    \
324514f5e3Sopenharmony_ci    V("getFloat64",     GetFloat64,     1, DataViewGetFloat64  )                    \
334514f5e3Sopenharmony_ci    V("getInt8",        GetInt8,        1, DataViewGetInt8     )                    \
344514f5e3Sopenharmony_ci    V("getInt16",       GetInt16,       1, DataViewGetInt16    )                    \
354514f5e3Sopenharmony_ci    V("getInt32",       GetInt32,       1, DataViewGetInt32    )                    \
364514f5e3Sopenharmony_ci    V("getBigInt64",    GetBigInt64,    1, INVALID             )                    \
374514f5e3Sopenharmony_ci    V("getUint16",      GetUint16,      1, DataViewGetUint16   )                    \
384514f5e3Sopenharmony_ci    V("getUint32",      GetUint32,      1, DataViewGetUint32   )                    \
394514f5e3Sopenharmony_ci    V("getUint8",       GetUint8,       1, DataViewGetUint8    )                    \
404514f5e3Sopenharmony_ci    V("getBigUint64",   GetBigUint64,   1, INVALID             )                    \
414514f5e3Sopenharmony_ci    /* For %Type% of 1 bytes: */                                                    \
424514f5e3Sopenharmony_ci    /*   DataView.prototype.setInt8 ( byteOffset, value ) */                        \
434514f5e3Sopenharmony_ci    /* For %Type% of 2 or more bytes: */                                            \
444514f5e3Sopenharmony_ci    /*   DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) */    \
454514f5e3Sopenharmony_ci    V("setFloat32",     SetFloat32,     2, DataViewSetFloat32)                      \
464514f5e3Sopenharmony_ci    V("setFloat64",     SetFloat64,     2, DataViewSetFloat64)                      \
474514f5e3Sopenharmony_ci    V("setInt8",        SetInt8,        2, DataViewSetInt8)                         \
484514f5e3Sopenharmony_ci    V("setInt16",       SetInt16,       2, DataViewSetInt16)                        \
494514f5e3Sopenharmony_ci    V("setInt32",       SetInt32,       2, DataViewSetInt32)                        \
504514f5e3Sopenharmony_ci    V("setBigInt64",    SetBigInt64,    2, INVALID)                                 \
514514f5e3Sopenharmony_ci    V("setUint8",       SetUint8,       2, DataViewSetUint8)                        \
524514f5e3Sopenharmony_ci    V("setUint16",      SetUint16,      2, DataViewSetUint16)                       \
534514f5e3Sopenharmony_ci    V("setUint32",      SetUint32,      2, DataViewSetUint32)                       \
544514f5e3Sopenharmony_ci    V("setBigUint64",   SetBigUint64,   2, INVALID)
554514f5e3Sopenharmony_ci
564514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
574514f5e3Sopenharmony_ciusing DataViewType = ecmascript::DataViewType;
584514f5e3Sopenharmony_ciclass BuiltinsDataView : public base::BuiltinsBase {
594514f5e3Sopenharmony_cipublic:
604514f5e3Sopenharmony_ci    // 24.2.2.1 DataView (buffer [ , byteOffset [ , byteLength ] ] )
614514f5e3Sopenharmony_ci    static JSTaggedValue DataViewConstructor(EcmaRuntimeCallInfo *argv);
624514f5e3Sopenharmony_ci    // 24.2.4.1 get DataView.prototype.buffer
634514f5e3Sopenharmony_ci    static JSTaggedValue GetBuffer(EcmaRuntimeCallInfo *argv);
644514f5e3Sopenharmony_ci    // 24.2.4.2 get DataView.prototype.byteLength
654514f5e3Sopenharmony_ci    static JSTaggedValue GetByteLength(EcmaRuntimeCallInfo *argv);
664514f5e3Sopenharmony_ci    // 24.2.4.3 get DataView.prototype.byteOffset
674514f5e3Sopenharmony_ci    static JSTaggedValue GetOffset(EcmaRuntimeCallInfo *argv);
684514f5e3Sopenharmony_ci    // 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] )
694514f5e3Sopenharmony_ci    static JSTaggedValue GetFloat32(EcmaRuntimeCallInfo *argv);
704514f5e3Sopenharmony_ci    // 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] )
714514f5e3Sopenharmony_ci    static JSTaggedValue GetFloat64(EcmaRuntimeCallInfo *argv);
724514f5e3Sopenharmony_ci    // 24.2.4.7 DataView.prototype.getInt8 ( byteOffset )
734514f5e3Sopenharmony_ci    static JSTaggedValue GetInt8(EcmaRuntimeCallInfo *argv);
744514f5e3Sopenharmony_ci    // 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] )
754514f5e3Sopenharmony_ci    static JSTaggedValue GetInt16(EcmaRuntimeCallInfo *argv);
764514f5e3Sopenharmony_ci    // 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] )
774514f5e3Sopenharmony_ci    static JSTaggedValue GetInt32(EcmaRuntimeCallInfo *argv);
784514f5e3Sopenharmony_ci    // 24.2.4.10 DataView.prototype.getUint8 ( byteOffset )
794514f5e3Sopenharmony_ci    static JSTaggedValue GetUint8(EcmaRuntimeCallInfo *argv);
804514f5e3Sopenharmony_ci    // 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] )
814514f5e3Sopenharmony_ci    static JSTaggedValue GetUint16(EcmaRuntimeCallInfo *argv);
824514f5e3Sopenharmony_ci    // 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] )
834514f5e3Sopenharmony_ci    static JSTaggedValue GetUint32(EcmaRuntimeCallInfo *argv);
844514f5e3Sopenharmony_ci    // 25.3.4.5 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] )
854514f5e3Sopenharmony_ci    static JSTaggedValue GetBigInt64(EcmaRuntimeCallInfo *argv);
864514f5e3Sopenharmony_ci    // 25.3.4.6 DataView.prototype.getBigUint64 ( byteOffset [ , littleEndian ] )
874514f5e3Sopenharmony_ci    static JSTaggedValue GetBigUint64(EcmaRuntimeCallInfo *argv);
884514f5e3Sopenharmony_ci    // 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] )
894514f5e3Sopenharmony_ci    static JSTaggedValue SetFloat32(EcmaRuntimeCallInfo *argv);
904514f5e3Sopenharmony_ci    // 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] )
914514f5e3Sopenharmony_ci    static JSTaggedValue SetFloat64(EcmaRuntimeCallInfo *argv);
924514f5e3Sopenharmony_ci    // 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value )
934514f5e3Sopenharmony_ci    static JSTaggedValue SetInt8(EcmaRuntimeCallInfo *argv);
944514f5e3Sopenharmony_ci    // 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] )
954514f5e3Sopenharmony_ci    static JSTaggedValue SetInt16(EcmaRuntimeCallInfo *argv);
964514f5e3Sopenharmony_ci    // 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] )
974514f5e3Sopenharmony_ci    static JSTaggedValue SetInt32(EcmaRuntimeCallInfo *argv);
984514f5e3Sopenharmony_ci    // 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value )
994514f5e3Sopenharmony_ci    static JSTaggedValue SetUint8(EcmaRuntimeCallInfo *argv);
1004514f5e3Sopenharmony_ci    // 24.2.4.19 DataView.prototype.setUint16( byteOffset, value [ , littleEndian ] )
1014514f5e3Sopenharmony_ci    static JSTaggedValue SetUint16(EcmaRuntimeCallInfo *argv);
1024514f5e3Sopenharmony_ci    // 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] )
1034514f5e3Sopenharmony_ci    static JSTaggedValue SetUint32(EcmaRuntimeCallInfo *argv);
1044514f5e3Sopenharmony_ci    // 25.3.4.15 DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] )
1054514f5e3Sopenharmony_ci    static JSTaggedValue SetBigInt64(EcmaRuntimeCallInfo *argv);
1064514f5e3Sopenharmony_ci    // 25.3.4.16 DataView.prototype.setBigUint64 ( byteOffset, value [ , littleEndian ] )
1074514f5e3Sopenharmony_ci    static JSTaggedValue SetBigUint64(EcmaRuntimeCallInfo *argv);
1084514f5e3Sopenharmony_ci
1094514f5e3Sopenharmony_ci    // Excluding the '@@' internal properties.
1104514f5e3Sopenharmony_ci    static Span<const base::BuiltinFunctionEntry> GetDataViewPrototypeFunctions()
1114514f5e3Sopenharmony_ci    {
1124514f5e3Sopenharmony_ci        return Span<const base::BuiltinFunctionEntry>(DATA_VIEW_PROTOTYPE_FUNCTIONS);
1134514f5e3Sopenharmony_ci    }
1144514f5e3Sopenharmony_ci
1154514f5e3Sopenharmony_ci    static size_t GetNumPrototypeInlinedProperties()
1164514f5e3Sopenharmony_ci    {
1174514f5e3Sopenharmony_ci        // 5 : 5 more inline properties in DataView.prototype:
1184514f5e3Sopenharmony_ci        //   (1) DataView.prototype.constructor
1194514f5e3Sopenharmony_ci        //   (2) DataView.prototype [ @@toStringTag ]
1204514f5e3Sopenharmony_ci        //   (3) get buffer
1214514f5e3Sopenharmony_ci        //   (4) get byteLength
1224514f5e3Sopenharmony_ci        //   (5) get byteOffset
1234514f5e3Sopenharmony_ci        return GetDataViewPrototypeFunctions().Size() + 5;
1244514f5e3Sopenharmony_ci    }
1254514f5e3Sopenharmony_ci
1264514f5e3Sopenharmony_ciprivate:
1274514f5e3Sopenharmony_ci#define BUILTIN_DATA_VIEW_FUNCTION_ENTRY(name, func, length, id) \
1284514f5e3Sopenharmony_ci    base::BuiltinFunctionEntry::Create(name, BuiltinsDataView::func, length, kungfu::BuiltinsStubCSigns::id),
1294514f5e3Sopenharmony_ci
1304514f5e3Sopenharmony_ci    static constexpr std::array DATA_VIEW_PROTOTYPE_FUNCTIONS = {
1314514f5e3Sopenharmony_ci        BUILTIN_DATA_VIEW_PROTOTYPE_FUNCTIONS(BUILTIN_DATA_VIEW_FUNCTION_ENTRY)
1324514f5e3Sopenharmony_ci    };
1334514f5e3Sopenharmony_ci
1344514f5e3Sopenharmony_ci#undef BUILTIN_DATA_VIEW_FUNCTION_ENTRY
1354514f5e3Sopenharmony_ci
1364514f5e3Sopenharmony_ci    // 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
1374514f5e3Sopenharmony_ci    static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
1384514f5e3Sopenharmony_ci                                      const JSHandle<JSTaggedValue> &requestIndex,
1394514f5e3Sopenharmony_ci                                      const JSHandle<JSTaggedValue> &littleEndian,
1404514f5e3Sopenharmony_ci                                      DataViewType type);
1414514f5e3Sopenharmony_ci    static JSTaggedValue SetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
1424514f5e3Sopenharmony_ci                                      const JSHandle<JSTaggedValue> &requestIndex,
1434514f5e3Sopenharmony_ci                                      const JSHandle<JSTaggedValue> &littleEndian,
1444514f5e3Sopenharmony_ci                                      DataViewType type, const JSHandle<JSTaggedValue> &value);
1454514f5e3Sopenharmony_ci
1464514f5e3Sopenharmony_ci    static JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type);
1474514f5e3Sopenharmony_ci    static JSTaggedValue SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type);
1484514f5e3Sopenharmony_ci};
1494514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
1504514f5e3Sopenharmony_ci
1514514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H
152