mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-27 04:00:37 +00:00
!5204 修复自定义类型继承数组,flat和flatmap返回数组instanceof特定情况下失败的问题。
Merge pull request !5204 from 杨云飞/master
This commit is contained in:
commit
2b3518234b
@ -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).
|
||||
|
@ -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);
|
||||
|
@ -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",
|
||||
|
18
test/moduletest/arrayfindlastindex/BUILD.gn
Normal file
18
test/moduletest/arrayfindlastindex/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("arrayfindlastindex") {
|
||||
deps = []
|
||||
}
|
29
test/moduletest/arrayfindlastindex/arrayfindlastindex.js
Normal file
29
test/moduletest/arrayfindlastindex/arrayfindlastindex.js
Normal 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);
|
||||
})();
|
14
test/moduletest/arrayfindlastindex/expect_output.txt
Normal file
14
test/moduletest/arrayfindlastindex/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.
|
||||
|
||||
2
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
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 = []
|
||||
}
|
31
test/moduletest/arrayflatmap/arrayflatmap.js
Normal file
31
test/moduletest/arrayflatmap/arrayflatmap.js
Normal 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
|
||||
}
|
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