Skip to content

Commit 7899a86

Browse files
authored
Fix crash when executing browser with CSP script-src that don't permit unsafe-eval (#29)
1 parent 428d49f commit 7899a86

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎lib/quick-sort.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ function cloneSort(comparator) {
112112
return templateFn(comparator);
113113
}
114114

115+
let isEvalAllowed = (function () {
116+
try {
117+
new Function('return 0')();
118+
return true;
119+
} catch {
120+
return false;
121+
}
122+
})();
123+
115124
/**
116125
* Sort the given array in-place with the given comparator function.
117126
*
@@ -123,7 +132,7 @@ function cloneSort(comparator) {
123132

124133
let sortCache = new WeakMap();
125134
exports.quickSort = function (ary, comparator, start = 0) {
126-
let doQuickSort = sortCache.get(comparator);
135+
let doQuickSort = isEvalAllowed ? sortCache.get(comparator) : SortTemplate(comparator);
127136
if (doQuickSort === void 0) {
128137
doQuickSort = cloneSort(comparator);
129138
sortCache.set(comparator, doQuickSort);

0 commit comments

Comments
 (0)