Fix JSTaggedValue::Equal Bug

Fix JSTaggedValue::Equal() according to ECMA 262.

Issue: #I71K7H

Signed-off-by: lichenshuai <lichenshuai@huawei.com>
Change-Id: Ib3b8aff72bf0a6bb9d1b687fd4a9bfba0307f527
This commit is contained in:
lichenshuai 2023-05-09 15:20:41 +08:00
parent e8759479a3
commit 1898e054fc
7 changed files with 133 additions and 5 deletions

View File

@ -190,11 +190,12 @@ void CrashCallback(char *buf __attribute__((unused)), size_t len __attribute__((
FrameIterator frame(reinterpret_cast<JSTaggedType *>(fp));
bool isBuiltinStub = (frame.GetFrameType() == FrameType::OPTIMIZED_FRAME);
Method *method = frame.CheckAndGetMethod();
while (method == nullptr && !frame.Done()) {
while (method == nullptr) {
frame.Advance();
if (!frame.Done()) {
method = frame.CheckAndGetMethod();
if (frame.Done()) {
break;
}
method = frame.CheckAndGetMethod();
}
std::string faultInfo;
if (method != nullptr) {

View File

@ -192,8 +192,8 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle<JSTaggedValue> &x, co
if (y->IsSymbol()) {
return x.GetTaggedValue() == y.GetTaggedValue();
}
if (y->IsBigInt()) {
return Equal(thread, y, x);
if (y->IsBigInt() || y->IsString()) {
return false;
}
if (y->IsHeapObject()) {
JSHandle<JSTaggedValue> yPrimitive(thread, ToPrimitive(thread, y));

View File

@ -1203,6 +1203,9 @@ HWTEST_F_L0(JSTaggedValueTest, Equal)
ASSERT_TRUE(JSTaggedValue::Equal(thread, JSHandle<JSTaggedValue>(thread, JSTaggedValue::True()), char1Point0));
ASSERT_FALSE(JSTaggedValue::Equal(thread, JSHandle<JSTaggedValue>(thread, JSTaggedValue::True()), char0));
ASSERT_FALSE(JSTaggedValue::Equal(thread, JSHandle<JSTaggedValue>(thread, JSTaggedValue::False()), char1));
JSHandle<JSTaggedValue> testSymbol(thread->GetEcmaVM()->GetFactory()->NewPublicSymbolWithChar("test"));
ASSERT_FALSE(JSTaggedValue::Equal(thread, testSymbol, test));
}
HWTEST_F_L0(JSTaggedValueTest, StrictEqual)

View File

@ -37,6 +37,7 @@ group("ark_js_moduletest") {
"dynamicimport",
"dyninstruction",
"ecmastringtable",
"equal",
"forawaitof",
"forin",
"fortest",
@ -129,6 +130,7 @@ group("ark_asm_test") {
"dynamicimport",
"dyninstruction",
"ecmastringtable",
"equal",
"forin",
"fortest",
"generator",

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("equal") {
deps = []
}

View File

@ -0,0 +1,27 @@
/*
* 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:equal
* @tc.desc:test equal
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/
var arr = [null, undefined, 0, "", 0n, false, Symbol(0), []];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++){
print(arr[i] == arr[j]);
}
}

View File

@ -0,0 +1,77 @@
# 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.
true
true
false
false
false
false
false
false
true
true
false
false
false
false
false
false
false
false
true
true
true
true
false
true
false
false
true
true
true
true
false
true
false
false
true
true
true
true
false
true
false
false
true
true
true
true
false
true
false
false
false
false
false
false
true
false
false
false
true
true
true
true
false
true