mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-06 23:54:03 +00:00
!5122 array.flat(undefed)没有处理flat为undefined的情况
Merge pull request !5122 from 韩靖/master
This commit is contained in:
commit
97ef863363
@ -2744,12 +2744,13 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv)
|
|||||||
// b. If depthNum < 0, set depthNum to 0.
|
// b. If depthNum < 0, set depthNum to 0.
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
JSHandle<JSTaggedValue> msg1 = GetCallArg(argv, 0);
|
JSHandle<JSTaggedValue> msg1 = GetCallArg(argv, 0);
|
||||||
JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1);
|
if (!msg1->IsUndefined()) {
|
||||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1);
|
||||||
depthNum = base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber());
|
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||||
depthNum = depthNum < 0 ? 0 : depthNum;
|
depthNum = base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber());
|
||||||
|
depthNum = depthNum < 0 ? 0 : depthNum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Let A be ? ArraySpeciesCreate(O, 0).
|
// 5. Let A be ? ArraySpeciesCreate(O, 0).
|
||||||
uint32_t arrayLen = 0;
|
uint32_t arrayLen = 0;
|
||||||
JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen));
|
JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen));
|
||||||
|
@ -18,6 +18,7 @@ group("ark_js_moduletest") {
|
|||||||
"allocatearraybuffer",
|
"allocatearraybuffer",
|
||||||
"array",
|
"array",
|
||||||
"arrayfindlast",
|
"arrayfindlast",
|
||||||
|
"arrayflat",
|
||||||
"arrayfindindex",
|
"arrayfindindex",
|
||||||
"arrayforeach",
|
"arrayforeach",
|
||||||
"arrayjoin",
|
"arrayjoin",
|
||||||
@ -161,6 +162,7 @@ group("ark_asm_test") {
|
|||||||
"allocatearraybuffer",
|
"allocatearraybuffer",
|
||||||
"array",
|
"array",
|
||||||
"arrayfindlast",
|
"arrayfindlast",
|
||||||
|
"arrayflat",
|
||||||
"arrayfindindex",
|
"arrayfindindex",
|
||||||
"arrayforeach",
|
"arrayforeach",
|
||||||
"arrayjoin",
|
"arrayjoin",
|
||||||
@ -283,6 +285,7 @@ group("ark_asm_single_step_test") {
|
|||||||
"allocatearraybuffer",
|
"allocatearraybuffer",
|
||||||
"arrayfindindex",
|
"arrayfindindex",
|
||||||
"arrayfindlast",
|
"arrayfindlast",
|
||||||
|
"arrayflat",
|
||||||
"arrayforeach",
|
"arrayforeach",
|
||||||
"arrayjoin",
|
"arrayjoin",
|
||||||
"arrayprotochange",
|
"arrayprotochange",
|
||||||
|
18
test/moduletest/arrayflat/BUILD.gn
Normal file
18
test/moduletest/arrayflat/BUILD.gn
Normal 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 = []
|
||||||
|
}
|
23
test/moduletest/arrayflat/arrayflat.js
Normal file
23
test/moduletest/arrayflat/arrayflat.js
Normal 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));
|
14
test/moduletest/arrayflat/expect_output.txt
Normal file
14
test/moduletest/arrayflat/expect_output.txt
Normal 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
|
Loading…
Reference in New Issue
Block a user