Bugfix on BuiltinsDataView::SetViewValue and GetViewValue

Issue: https://gitee.com/open_harmony/dashboard?issue_id=I7NVPC

Signed-off-by: quiet-thought <chenjingxiang1@huawei.com>
Change-Id: I32c07c114185ba55902c54b4d25af61e1ba4b60d
This commit is contained in:
quiet-thought 2023-07-31 20:21:03 +08:00
parent 5a0f2844d2
commit 04798afdf9
5 changed files with 75 additions and 12 deletions

View File

@ -347,7 +347,8 @@ JSTaggedValue BuiltinsDataView::SetBigUint64(EcmaRuntimeCallInfo *argv)
// 24.2.1.1
JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
const JSHandle<JSTaggedValue> &requestIndex,
const JSHandle<JSTaggedValue> &littleEndian,
DataViewType type)
{
BUILTINS_API_TRACE(thread, DataView, GetViewValue);
@ -371,10 +372,10 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle<JS
uint32_t index = static_cast<uint32_t>(indexInt);
// 7. Let isLittleEndian be ToBoolean(isLittleEndian).
bool isLittleEndian = false;
if (littleEndian.IsUndefined()) {
if (littleEndian->IsUndefined()) {
isLittleEndian = false;
} else {
isLittleEndian = littleEndian.ToBoolean();
isLittleEndian = littleEndian->ToBoolean();
}
// 8. Let buffer be the value of views [[ViewedArrayBuffer]] internal slot.
JSHandle<JSDataView> dataView(view);
@ -401,7 +402,8 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle<JS
// 24.2.1.2
JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
const JSHandle<JSTaggedValue> &requestIndex,
const JSHandle<JSTaggedValue> &littleEndian,
DataViewType type, const JSHandle<JSTaggedValue> &value)
{
// 1. If Type(view) is not Object, throw a TypeError exception.
@ -426,10 +428,10 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle<JS
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 7. Let isLittleEndian be ToBoolean(isLittleEndian).
bool isLittleEndian = false;
if (littleEndian.IsUndefined()) {
if (littleEndian->IsUndefined()) {
isLittleEndian = false;
} else {
isLittleEndian = littleEndian.ToBoolean();
isLittleEndian = littleEndian->ToBoolean();
}
// 8. Let buffer be the value of views [[ViewedArrayBuffer]] internal slot.
JSHandle<JSDataView> dataView(view);
@ -461,11 +463,12 @@ JSTaggedValue BuiltinsDataView::GetTypedValue(EcmaRuntimeCallInfo *argv, DataVie
[[maybe_unused]] EcmaHandleScope handleScope(thread);
JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
JSHandle<JSTaggedValue> offsetHandle = GetCallArg(argv, 0);
JSHandle<JSTaggedValue> trueHandle(thread, JSTaggedValue::True());
if (type == DataViewType::UINT8 || type == DataViewType::INT8) {
return GetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type);
return GetViewValue(thread, thisHandle, offsetHandle, trueHandle, type);
}
JSHandle<JSTaggedValue> littleEndianHandle = GetCallArg(argv, 1);
return GetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type);
return GetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle, type);
}
JSTaggedValue BuiltinsDataView::SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type)
@ -476,10 +479,11 @@ JSTaggedValue BuiltinsDataView::SetTypedValue(EcmaRuntimeCallInfo *argv, DataVie
JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
JSHandle<JSTaggedValue> offsetHandle = GetCallArg(argv, 0);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> trueHandle(thread, JSTaggedValue::True());
if (type == DataViewType::UINT8 || type == DataViewType::INT8) {
return SetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type, value);
return SetViewValue(thread, thisHandle, offsetHandle, trueHandle, type, value);
}
JSHandle<JSTaggedValue> littleEndianHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
return SetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type, value);
return SetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle, type, value);
}
} // namespace panda::ecmascript::builtins

View File

@ -75,10 +75,12 @@ public:
private:
// 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type )
static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
const JSHandle<JSTaggedValue> &requestIndex,
const JSHandle<JSTaggedValue> &littleEndian,
DataViewType type);
static JSTaggedValue SetViewValue(JSThread *thread, const JSHandle<JSTaggedValue> &view,
const JSHandle<JSTaggedValue> &requestIndex, JSTaggedValue littleEndian,
const JSHandle<JSTaggedValue> &requestIndex,
const JSHandle<JSTaggedValue> &littleEndian,
DataViewType type, const JSHandle<JSTaggedValue> &value);
static JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type);

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 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.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("dataview") {
deps = []
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 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.
*/
/*
* @tc.name:dataview
* @tc.desc:test dataview
* @tc.type: FUNC
* @tc.require: issue#I7NUZM
*/
const buffer = new ArrayBuffer(16);
const view = new DataView(buffer);
view.setInt32({}, 0x1337, {});
print(view.getInt32({}, {}));

View File

@ -0,0 +1,14 @@
# Copyright (c) 2023 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.
4919