uschindler commented on code in PR #16423:
URL: https://github.com/apache/lucene/pull/16423#discussion_r3657065668


##########
lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java:
##########
@@ -155,10 +162,35 @@ public static Expression compile(String sourceText) 
throws ParseException {
    * @param functions map of String names to {@link MethodHandle}s
    * @return A new compiled expression
    * @throws ParseException on failure to compile
+   * @throws IllegalArgumentException if any of the functions does not have 
correct signature
+   * @throws IllegalStateException if the resulting expression class fails to 
link (e.g.,
+   *     complexity)
    */
   public static Expression compile(String sourceText, Map<String, 
MethodHandle> functions)
       throws ParseException {
-    return compile(sourceText, functions, false);
+    return compile(sourceText, functions, DEFAULT_MAX_NESTING_DEPTH);
+  }
+
+  /**
+   * Compiles the given expression with the supplied custom functions using a 
custom maximum nesting
+   * depth.
+   *
+   * <p>Functions must be {@code public static}, return {@code double} and can 
take from zero to 256
+   * {@code double} parameters.
+   *
+   * @param sourceText The expression to compile
+   * @param functions map of String names to {@link MethodHandle}s
+   * @param maxNestingDepth the maximum depth of nesting (function calls, 
precedence)
+   * @return A new compiled expression
+   * @throws ParseException on failure to compile
+   * @throws IllegalArgumentException if any of the functions does not have 
correct signature
+   * @throws IllegalStateException if the resulting expression class fails to 
link (e.g.,
+   *     complexity)
+   */
+  public static Expression compile(
+      String sourceText, Map<String, MethodHandle> functions, int 
maxNestingDepth)

Review Comment:
   Actually if you read the whole thing, you may notice that this not only 
affects "nesting" of expressions. Also a long "1 + 2 + 3 + 4 + ..... + 10000" 
will trigger the failure. I am not sure if 250 is enough for all cases, so I'd 
like to have it configurable (at least for a while, so people can tune it).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to