Skip to content

Commit 9a83cb1

Browse files
committed
[GR-23670] Reorder check for compareFn in Array.prototype.sort to avoid creation of IsCallableNode.
PullRequest: js/1565
2 parents 138679a + ac4ba3d commit 9a83cb1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ArrayPrototypeBuiltins.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,20 +2574,21 @@ public Object sortTruffleObject(Object comparefn, Object thisObj) {
25742574
}
25752575

25762576
private void checkCompareFunction(Object compare) {
2577-
if (!(isCallable(compare) || compare == Undefined.instance)) {
2577+
if (!(compare == Undefined.instance || isCallable(compare))) {
25782578
errorBranch.enter();
25792579
throw Errors.createTypeError("The comparison function must be either a function or undefined");
25802580
}
25812581
}
25822582

25832583
private Comparator<Object> getComparator(Object thisObj, Object compare) {
2584-
if (isCallable(compare)) {
2584+
if (compare == Undefined.instance) {
2585+
noCompareFnBranch.enter();
2586+
return getDefaultComparator(thisObj);
2587+
} else {
2588+
assert isCallable(compare);
25852589
hasCompareFnBranch.enter();
25862590
DynamicObject arrayBufferObj = isTypedArrayImplementation && JSArrayBufferView.isJSArrayBufferView(thisObj) ? JSArrayBufferView.getArrayBuffer((DynamicObject) thisObj) : null;
25872591
return new SortComparator(compare, arrayBufferObj);
2588-
} else {
2589-
noCompareFnBranch.enter();
2590-
return getDefaultComparator(thisObj);
25912592
}
25922593
}
25932594

0 commit comments

Comments
 (0)