mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-27 12:10:47 +00:00
!5153 Bugfix on JSArray.sort when this be modified to string which length is 1
Merge pull request !5153 from chenjingxiang/bugfix_js_array_sort
This commit is contained in:
commit
7e8d47b43a
@ -397,6 +397,10 @@ JSTaggedValue JSArray::Sort(JSThread *thread, const JSHandle<JSTaggedValue> &obj
|
||||
int64_t len = ArrayHelper::GetArrayLength(thread, obj);
|
||||
// ReturnIfAbrupt(len).
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
// If len is 0 or 1, no need to sort
|
||||
if (len == 0 || len == 1) {
|
||||
return obj.GetTaggedValue();
|
||||
}
|
||||
|
||||
// 4. Let SortCompare be a new Abstract Closure with parameters (x, y) that captures comparefn and performs
|
||||
// the following steps when called:
|
||||
|
@ -207,9 +207,21 @@ Object.defineProperty(Array.prototype, "tt", {
|
||||
writable:false,
|
||||
});
|
||||
|
||||
var arr = new Array(5);
|
||||
arr[0] = 93;
|
||||
arr[2] = -45;
|
||||
arr[3] = "djs";
|
||||
arr[4] = 0;
|
||||
print(arr.sort());
|
||||
var arr6 = new Array(5);
|
||||
arr6[0] = 93;
|
||||
arr6[2] = -45;
|
||||
arr6[3] = "djs";
|
||||
arr6[4] = 0;
|
||||
print(arr6.sort());
|
||||
|
||||
var arr7 = [1];
|
||||
print(arr7.sort());
|
||||
|
||||
var res1 = Array.prototype.sort.call("m", Uint8Array);
|
||||
print(res1);
|
||||
|
||||
try {
|
||||
Array.prototype.sort.call("mm", Uint8Array);
|
||||
} catch (e) {
|
||||
print(e.name);
|
||||
}
|
@ -41,3 +41,6 @@ false
|
||||
930,93,44,0,-45
|
||||
1,3,4
|
||||
-45,0,93,djs,
|
||||
1
|
||||
m
|
||||
TypeError
|
||||
|
Loading…
Reference in New Issue
Block a user