Object callbackArg = args.length > 0 ? args[0] : Undefined.instance;
if (callbackArg == null || !(callbackArg instanceof Function)) {
throw ScriptRuntime.notFunctionError(
ScriptRuntime.toString(callbackArg));
}
final Function f = (Function) callbackArg;
return new QueryArray(null){
long sizeEstimate = ((QueryArray)thisObj).estimatedSize(0);
int lastSizeEstimateIndex = -1;
@Override
public Iterator iterator() {
final Iterator sourceIterator = ((List)thisObj).iterator();
return new Iterator(){
int i = -1;
Object next;
private void getNext(){
do{
next = Scriptable.NOT_FOUND;
if(!sourceIterator.hasNext())
return;
i++;
if(i % 100 == 0){
if(i > maxIterations && PersistableObject.isSecurityEnabled() && !UserSecurity.hasPermission(SystemPermission.runLongQueries)){
throw ScriptRuntime.constructError("AccessError", "Query has taken too much computation, and the user is not allowed to execute resource-intense queries. Increase maxIterations in your config file to allow longer running non-indexed queries to be processed.");
}
}
next = sourceIterator.next();
if(ScriptRuntime.toBoolean(f.call(cx, scope, thisObj, new Object[]{next, i, thisObj})))
return;
if(i > lastSizeEstimateIndex){
lastSizeEstimateIndex = i;
sizeEstimate--;
}