@@ -959,7 +959,7 @@ private JsValue Sort(JsValue thisObj, JsValue[] arguments)
959959 // don't eat inner exceptions
960960 try
961961 {
962- var array = obj . OrderBy ( x => x , ArrayComparer . WithFunction ( compareFn ) ) . ToArray ( ) ;
962+ var array = obj . OrderBy ( x => x , ArrayComparer . WithFunction ( _engine , compareFn ) ) . ToArray ( ) ;
963963
964964 for ( uint i = 0 ; i < ( uint ) array . Length ; ++ i )
965965 {
@@ -1399,22 +1399,25 @@ private sealed class ArrayComparer : IComparer<JsValue>
13991399 /// <summary>
14001400 /// Default instance without any compare function.
14011401 /// </summary>
1402- public static ArrayComparer Default = new ArrayComparer ( null ) ;
1403- public static ArrayComparer WithFunction ( ICallable compare )
1402+ public static readonly ArrayComparer Default = new ( null , null ) ;
1403+
1404+ public static ArrayComparer WithFunction ( Engine engine , ICallable compare )
14041405 {
14051406 if ( compare == null )
14061407 {
14071408 return Default ;
14081409 }
14091410
1410- return new ArrayComparer ( compare ) ;
1411+ return new ArrayComparer ( engine , compare ) ;
14111412 }
14121413
1414+ private readonly Engine _engine ;
14131415 private readonly ICallable _compare ;
14141416 private readonly JsValue [ ] _comparableArray = new JsValue [ 2 ] ;
14151417
1416- private ArrayComparer ( ICallable compare )
1418+ private ArrayComparer ( Engine engine , ICallable compare )
14171419 {
1420+ _engine = engine ;
14181421 _compare = compare ;
14191422 }
14201423
@@ -1459,6 +1462,8 @@ public int Compare(JsValue x, JsValue y)
14591462
14601463 if ( _compare != null )
14611464 {
1465+ _engine . RunBeforeExecuteStatementChecks ( null ) ;
1466+
14621467 _comparableArray [ 0 ] = x ;
14631468 _comparableArray [ 1 ] = y ;
14641469
0 commit comments