mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
修复flat和flatmap返回数组构造异常的问题。
Signed-off-by: 杨云飞 <yangyunfei19@h-partners.com>
This commit is contained in:
parent
313a711d12
commit
8f141e3211
@ -116,7 +116,8 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
|
||||
if (isArray) {
|
||||
// Let C be Get(originalArray, "constructor").
|
||||
auto *hclass = originalArray->GetJSHClass();
|
||||
if (hclass->IsJSArray() && !hclass->HasConstructor()) {
|
||||
JSTaggedValue proto = hclass->GetPrototype();
|
||||
if (hclass->IsJSArray() && !hclass->HasConstructor() && proto.IsJSArray()) {
|
||||
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue();
|
||||
}
|
||||
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
|
||||
|
@ -21,6 +21,7 @@ group("ark_js_moduletest") {
|
||||
"array",
|
||||
"arrayfindlast",
|
||||
"arrayflat",
|
||||
"arrayflatmap",
|
||||
"arrayfindindex",
|
||||
"arrayfindlastindex",
|
||||
"arrayforeach",
|
||||
@ -183,6 +184,7 @@ group("ark_asm_test") {
|
||||
"array",
|
||||
"arrayfindlast",
|
||||
"arrayflat",
|
||||
"arrayflatmap",
|
||||
"arrayfindlastindex",
|
||||
"arrayfindindex",
|
||||
"arrayforeach",
|
||||
@ -318,6 +320,7 @@ group("ark_asm_single_step_test") {
|
||||
"arrayfindindex",
|
||||
"arrayfindlast",
|
||||
"arrayflat",
|
||||
"arrayflatmap",
|
||||
"arrayfindlastindex",
|
||||
"arrayforeach",
|
||||
"arrayjoin",
|
||||
|
@ -22,3 +22,13 @@
|
||||
const input = [1, [2], [[3]]];
|
||||
print(input.flat(undefined));
|
||||
|
||||
{
|
||||
class MyArray extends Array {
|
||||
static get [Symbol.species]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
const wannabe = new MyArray();
|
||||
const flattened = wannabe.flat(Infinity);
|
||||
print(flattened instanceof MyArray);
|
||||
}
|
@ -12,3 +12,4 @@
|
||||
# limitations under the License.
|
||||
|
||||
1,2,3
|
||||
true
|
||||
|
18
test/moduletest/arrayflatmap/BUILD.gn
Normal file
18
test/moduletest/arrayflatmap/BUILD.gn
Normal 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("arrayflatmap") {
|
||||
deps = []
|
||||
}
|
25
test/moduletest/arrayflatmap/arrayflatmap.js
Normal file
25
test/moduletest/arrayflatmap/arrayflatmap.js
Normal 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.
|
||||
*/
|
||||
|
||||
{
|
||||
class MyArray extends Array {
|
||||
static get [Symbol.species]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
const wannabe = new MyArray();
|
||||
const result = wannabe.flatMap(x => [x, x]);
|
||||
print(result instanceof MyArray);
|
||||
}
|
14
test/moduletest/arrayflatmap/expect_output.txt
Normal file
14
test/moduletest/arrayflatmap/expect_output.txt
Normal 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.
|
||||
|
||||
true
|
Loading…
Reference in New Issue
Block a user