2021-09-04 08:06:49 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ecmascript/js_dataview.h"
|
|
|
|
|
2022-07-23 10:54:34 +00:00
|
|
|
#include "libpandabase/macros.h"
|
2022-07-15 03:36:22 +00:00
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
namespace panda::ecmascript {
|
2022-01-25 10:05:12 +00:00
|
|
|
uint32_t JSDataView::GetElementSize(DataViewType type)
|
2021-09-04 08:06:49 +00:00
|
|
|
{
|
2022-01-25 10:05:12 +00:00
|
|
|
uint32_t size;
|
2021-09-04 08:06:49 +00:00
|
|
|
switch (type) {
|
|
|
|
case DataViewType::INT8:
|
|
|
|
case DataViewType::UINT8:
|
|
|
|
case DataViewType::UINT8_CLAMPED:
|
|
|
|
size = 1;
|
|
|
|
break;
|
|
|
|
case DataViewType::INT16:
|
|
|
|
case DataViewType::UINT16:
|
|
|
|
size = 2; // 2 means the length
|
|
|
|
break;
|
|
|
|
case DataViewType::INT32:
|
|
|
|
case DataViewType::UINT32:
|
|
|
|
case DataViewType::FLOAT32:
|
|
|
|
size = 4; // 4 means the length
|
|
|
|
break;
|
|
|
|
case DataViewType::FLOAT64:
|
2022-04-07 09:33:59 +00:00
|
|
|
case DataViewType::BIGINT64:
|
|
|
|
case DataViewType::BIGUINT64:
|
|
|
|
size = 8; // 8 means the length
|
|
|
|
break;
|
2021-09-04 08:06:49 +00:00
|
|
|
default:
|
2022-12-01 07:29:41 +00:00
|
|
|
LOG_ECMA(FATAL) << "this branch is unreachable";
|
2021-09-04 08:06:49 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
} // namespace panda::ecmascript
|