!5204 修复自定义类型继承数组,flat和flatmap返回数组instanceof特定情况下失败的问题。

Merge pull request !5204 from 杨云飞/master
This commit is contained in:
openharmony_ci 2023-11-13 09:11:34 +00:00 committed by Gitee
commit 2b3518234b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 157 additions and 9 deletions

View File

@ -115,10 +115,6 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
JSHandle<JSTaggedValue> constructor(thread, JSTaggedValue::Undefined());
if (isArray) {
// Let C be Get(originalArray, "constructor").
auto *hclass = originalArray->GetJSHClass();
if (hclass->IsJSArray() && !hclass->HasConstructor()) {
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue();
}
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue();
// ReturnIfAbrupt(C).

View File

@ -379,7 +379,17 @@ JSTaggedValue JSStableArray::HandleFindLastIndexOfStable(JSThread *thread, JSHan
while (k >= 0) {
// Elements of thisObjHandle may change.
array.Update(thisObjHandle->GetElements());
kValue.Update(array->Get(k));
JSTaggedValue val = array->Get(k);
if (val.IsHole()) {
auto res = JSArray::FastGetPropertyByValue(thread, thisObjVal, k).GetTaggedValue();
if (res.IsHole()) {
kValue.Update(JSTaggedValue::Undefined());
} else {
kValue.Update(res);
}
} else {
kValue.Update(val);
}
EcmaRuntimeCallInfo *info =
EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);

View File

@ -20,7 +20,9 @@ group("ark_js_moduletest") {
"array",
"arrayfindlast",
"arrayflat",
"arrayflatmap",
"arrayfindindex",
"arrayfindlastindex",
"arrayforeach",
"arrayjoin",
"arraypop",
@ -167,6 +169,8 @@ group("ark_asm_test") {
"array",
"arrayfindlast",
"arrayflat",
"arrayflatmap",
"arrayfindlastindex",
"arrayfindindex",
"arrayforeach",
"arrayjoin",
@ -292,6 +296,8 @@ group("ark_asm_single_step_test") {
"arrayfindindex",
"arrayfindlast",
"arrayflat",
"arrayflatmap",
"arrayfindlastindex",
"arrayforeach",
"arrayjoin",
"arraypop",

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

View File

@ -0,0 +1,29 @@
/*
* 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:arrayfindIndex
* @tc.desc:test Array.findlastIndex
* @tc.type: FUNC
* @tc.require: issueI8FBM3
*/
(function() {
var a = [0, 1,,3];
var index = a.findLastIndex(function(val){
return val === undefined;
});
print(index);
})();

View 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.
2

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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
@ -17,7 +17,18 @@
* @tc.name:async
* @tc.desc:test async function
* @tc.type: FUNC
* @tc.require: issueI5NO8G
* @tc.require: issueI5NO8G issueI8FBM3
*/
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);
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# 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
@ -12,3 +12,4 @@
# limitations under the License.
1,2,3
true

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

View File

@ -0,0 +1,31 @@
/*
* 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:async
* @tc.desc:array.flatmap
* @tc.type: FUNC
* @tc.require:issueI8FBM3
*/
{
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
}

View 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