4545import com .oracle .truffle .api .object .DynamicObjectLibrary ;
4646import com .oracle .truffle .js .nodes .JavaScriptBaseNode ;
4747import com .oracle .truffle .js .nodes .cast .IsNumberNode ;
48- import com .oracle .truffle .js .nodes .cast .JSToIntegerAsIntNode ;
48+ import com .oracle .truffle .js .nodes .cast .JSToIntegerAsLongNode ;
4949import com .oracle .truffle .js .runtime .JSContext ;
5050import com .oracle .truffle .js .runtime .JSErrorType ;
5151import com .oracle .truffle .js .runtime .builtins .JSError ;
@@ -57,13 +57,13 @@ public abstract class ErrorStackTraceLimitNode extends JavaScriptBaseNode {
5757 private final JSContext context ;
5858 @ Child private DynamicObjectLibrary getStackTraceLimit ;
5959 @ Child private IsNumberNode isNumber ;
60- @ Child private JSToIntegerAsIntNode toInteger ;
60+ @ Child private JSToIntegerAsLongNode toInteger ;
6161
6262 protected ErrorStackTraceLimitNode (JSContext context ) {
6363 this .context = context ;
6464 this .getStackTraceLimit = JSObjectUtil .createDispatched (JSError .STACK_TRACE_LIMIT_PROPERTY_NAME );
6565 this .isNumber = IsNumberNode .create ();
66- this .toInteger = JSToIntegerAsIntNode .create ();
66+ this .toInteger = JSToIntegerAsLongNode .create ();
6767 }
6868
6969 public static ErrorStackTraceLimitNode create (JSContext context ) {
@@ -76,7 +76,8 @@ public int doInt() {
7676 if (JSProperty .isData (getStackTraceLimit .getPropertyFlagsOrDefault (errorConstructor , JSError .STACK_TRACE_LIMIT_PROPERTY_NAME , JSProperty .ACCESSOR ))) {
7777 Object value = getStackTraceLimit .getOrDefault (errorConstructor , JSError .STACK_TRACE_LIMIT_PROPERTY_NAME , Undefined .instance );
7878 if (isNumber .execute (value )) {
79- return Math .max (0 , toInteger .executeInt (value ));
79+ long limit = toInteger .executeLong (value );
80+ return (int ) Math .max (0 , Math .min (limit , Integer .MAX_VALUE ));
8081 }
8182 }
8283 return 0 ;
0 commit comments