* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H
#define ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/js_dataview.h"
#define BUILTIN_DATA_VIEW_PROTOTYPE_FUNCTIONS(V) \
\
\
\
\
V("getFloat32", GetFloat32, 1, DataViewGetFloat32 ) \
V("getFloat64", GetFloat64, 1, DataViewGetFloat64 ) \
V("getInt8", GetInt8, 1, DataViewGetInt8 ) \
V("getInt16", GetInt16, 1, DataViewGetInt16 ) \
V("getInt32", GetInt32, 1, DataViewGetInt32 ) \
V("getBigInt64", GetBigInt64, 1, INVALID ) \
V("getUint16", GetUint16, 1, DataViewGetUint16 ) \
V("getUint32", GetUint32, 1, DataViewGetUint32 ) \
V("getUint8", GetUint8, 1, DataViewGetUint8 ) \
V("getBigUint64", GetBigUint64, 1, INVALID ) \
\
\
\
\
V("setFloat32", SetFloat32, 2, DataViewSetFloat32) \
V("setFloat64", SetFloat64, 2, DataViewSetFloat64) \
V("setInt8", SetInt8, 2, DataViewSetInt8) \
V("setInt16", SetInt16, 2, DataViewSetInt16) \
V("setInt32", SetInt32, 2, DataViewSetInt32) \
V("setBigInt64", SetBigInt64, 2, INVALID) \
V("setUint8", SetUint8, 2, DataViewSetUint8) \
V("setUint16", SetUint16, 2, DataViewSetUint16) \
V("setUint32", SetUint32, 2, DataViewSetUint32) \
V("setBigUint64", SetBigUint64, 2, INVALID)
namespace panda::ecmascript::builtins {
using DataViewType = ecmascript::DataViewType;
class BuiltinsDataView : public base::BuiltinsBase {
public:
static JSTaggedValue DataViewConstructor(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetBuffer(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetByteLength(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetOffset(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetFloat32(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetFloat64(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetInt8(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetInt16(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetInt32(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetUint8(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetUint16(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetUint32(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetBigInt64(EcmaRuntimeCallInfo *argv);
static JSTaggedValue GetBigUint64(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetFloat32(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetFloat64(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetInt8(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetInt16(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetInt32(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetUint8(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetUint16(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetUint32(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetBigInt64(EcmaRuntimeCallInfo *argv);
static JSTaggedValue SetBigUint64(EcmaRuntimeCallInfo *argv);
static Span<const base::BuiltinFunctionEntry> GetDataViewPrototypeFunctions()
{
return Span<const base::BuiltinFunctionEntry>(DATA_VIEW_PROTOTYPE_FUNCTIONS);
}
static size_t GetNumPrototypeInlinedProperties()
{
return GetDataViewPrototypeFunctions().Size() + 5;
}
private:
#define BUILTIN_DATA_VIEW_FUNCTION_ENTRY(name, func, length, id) \
base::BuiltinFunctionEntry::Create(name, BuiltinsDataView::func, length, BUILTINS_STUB_ID(id)),
static constexpr std::array DATA_VIEW_PROTOTYPE_FUNCTIONS = {
BUILTIN_DATA_VIEW_PROTOTYPE_FUNCTIONS(BUILTIN_DATA_VIEW_FUNCTION_ENTRY)
};
#undef BUILTIN_DATA_VIEW_FUNCTION_ENTRY
static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
const JSHandle<JSTaggedValue> &requestIndex,
const JSHandle<JSTaggedValue> &littleEndian,
DataViewType type);
static JSTaggedValue SetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
const JSHandle<JSTaggedValue> &requestIndex,
const JSHandle<JSTaggedValue> &littleEndian,
DataViewType type, const JSHandle<JSTaggedValue> &value);
static JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type);
static JSTaggedValue SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type);
};
}
#endif