RangeError: Maximum call stack size exceeded
For the method: com.caoccao.javet.values.reference.IV8ValueArray.push(Object... objects), if the length of the objects array is too large, it will throw an exception: Maximum call stack size exceeded.
Test data: objects=[{"k":1},{"k":2},...,{"k":500000}]
Please post the whole code. It could be a misuse of the API.
public static void main(String[] args) throws Exception {
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime()) {
try (V8ValueObject v8ValueObject = v8Runtime.createV8ValueObject()) {
v8Runtime.getGlobalObject().set("intercept", v8ValueObject);
v8ValueObject.bind(new TestIntercept());
}
IV8Executor executor = v8Runtime.getExecutor("intercept.handle();");
// this line will throw Exception
executor.executeObject();
}
}
public static class TestIntercept {
@V8Function
public List<Integer> handle() {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < 500000; i++) {
list.add(i);
}
return list;
}
}
@caoccao Is this a bug, or am I having an issue with the API usage?
Sorry, I haven't had time evaluating your code.
Alright, totally understand... When you have time later, please don’t forget to take a look at the code, it’s basically the same as the example in the Interception section of the Javet Document Portal documentation.
The error is from V8.
Basically, Array.prototype.push() accepts multiple arguments and there is no limit to the number of arguments.
In reality, V8 has a limit. In your case, 500,000 items is way beyond V8's limit.
Suggestions:
- Reduce the number of items.
- Javet can split the
push()call into multiple calls to workaround that.