!5122 array.flat(undefed)没有处理flat为undefined的情况

Merge pull request !5122 from 韩靖/master
This commit is contained in:
openharmony_ci 2023-11-04 08:25:10 +00:00 committed by Gitee
commit 97ef863363
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 64 additions and 5 deletions

View File

@ -2744,12 +2744,13 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv)
// b. If depthNum < 0, set depthNum to 0.
if (argc > 0) {
JSHandle<JSTaggedValue> msg1 = GetCallArg(argv, 0);
JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
depthNum = base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber());
depthNum = depthNum < 0 ? 0 : depthNum;
if (!msg1->IsUndefined()) {
JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
depthNum = base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber());
depthNum = depthNum < 0 ? 0 : depthNum;
}
}
// 5. Let A be ? ArraySpeciesCreate(O, 0).
uint32_t arrayLen = 0;
JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen));

View File

@ -18,6 +18,7 @@ group("ark_js_moduletest") {
"allocatearraybuffer",
"array",
"arrayfindlast",
"arrayflat",
"arrayfindindex",
"arrayforeach",
"arrayjoin",
@ -161,6 +162,7 @@ group("ark_asm_test") {
"allocatearraybuffer",
"array",
"arrayfindlast",
"arrayflat",
"arrayfindindex",
"arrayforeach",
"arrayjoin",
@ -283,6 +285,7 @@ group("ark_asm_single_step_test") {
"allocatearraybuffer",
"arrayfindindex",
"arrayfindlast",
"arrayflat",
"arrayforeach",
"arrayjoin",
"arrayprotochange",

View File

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

View File

@ -0,0 +1,23 @@
/*
* 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.
*/
/*
* @tc.name:async
* @tc.desc:test async function
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/
const input = [1, [2], [[3]]];
print(input.flat(undefined));

View File

@ -0,0 +1,14 @@
# 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.
1,2,3