Stack SetProperty Bugfix

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAZ99N
Signed-off-by: jiachong <jiachong6@huawei.com>
Change-Id: Id7bd0620829179c3bf49a29bbf44bcfcf129e4d8
This commit is contained in:
jiachong 2024-10-23 16:23:05 +08:00
parent 8a2f165ee3
commit f10d8aac7a
4 changed files with 70 additions and 1 deletions

View File

@ -213,7 +213,17 @@ bool JSAPIStack::SetProperty(JSThread *thread, const JSHandle<JSAPIStack> &obj,
const JSHandle<JSTaggedValue> &value)
{
int length = obj->GetTop() + 1;
int index = key->GetInt();
JSHandle<JSTaggedValue> indexKey = key;
if (indexKey->IsDouble()) {
// Math.floor(1) will produce TaggedDouble, we need to cast into TaggedInt
// For integer which is greater than INT32_MAX, it will remain TaggedDouble
indexKey = JSHandle<JSTaggedValue>(thread, JSTaggedValue::TryCastDoubleToInt32(indexKey->GetDouble()));
}
if (!indexKey->IsInt()) {
return false;
}
int index = indexKey->GetInt();
if (index < 0 || index >= length) {
return false;
}

View File

@ -0,0 +1,18 @@
# Copyright (c) 2024 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("stack") {
deps = []
}

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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.
[object Stack]

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 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:stack
* @tc.desc:test Stack
* @tc.type: FUNC
* @tc.require: issueIAZ99N
*/
let arkPrivate = globalThis.ArkPrivate;
var Stack = arkPrivate.Load(arkPrivate.Stack);
const v1 = new Stack();
let v2 = Math.floor([1.1]);
v1[v2] = 0;
print(v1);