mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
修复了自定义类型继承数组类,flat和flatmap后返回数组构造异常
Signed-off-by: 杨云飞 <yangyunfei19@h-partners.com>
This commit is contained in:
parent
3a6b687493
commit
5ac305f78a
@ -2771,7 +2771,7 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv)
|
||||
uint32_t arrayLen = 0;
|
||||
JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen));
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
|
||||
base::FlattenArgs args = { sourceLen, 0, depthNum };
|
||||
JSHandle<JSObject> newArrayHandle(thread, newArray);
|
||||
// 6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, depthNum).
|
||||
|
@ -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();
|
||||
|
@ -20,6 +20,7 @@ group("ark_js_moduletest") {
|
||||
"array",
|
||||
"arrayfindlast",
|
||||
"arrayflat",
|
||||
"arrayflatmap",
|
||||
"arrayfindindex",
|
||||
"arrayfindlastindex",
|
||||
"arrayforeach",
|
||||
@ -178,6 +179,7 @@ group("ark_asm_test") {
|
||||
"array",
|
||||
"arrayfindlast",
|
||||
"arrayflat",
|
||||
"arrayflatmap",
|
||||
"arrayfindlastindex",
|
||||
"arrayfindindex",
|
||||
"arrayforeach",
|
||||
@ -311,6 +313,7 @@ group("ark_asm_single_step_test") {
|
||||
"arrayfindindex",
|
||||
"arrayfindlast",
|
||||
"arrayflat",
|
||||
"arrayflatmap",
|
||||
"arrayfindlastindex",
|
||||
"arrayforeach",
|
||||
"arrayjoin",
|
||||
|
@ -21,4 +21,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 = []
|
||||
}
|
24
test/moduletest/arrayflatmap/arrayflatmap.js
Normal file
24
test/moduletest/arrayflatmap/arrayflatmap.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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);//t
|
||||
}
|
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