Java Code Examples for jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator#hasNext()

The following examples show how to use jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator#hasNext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 2
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 3
Source File: NativeArray.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 4
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 5
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 6
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 7
Source File: NativeArray.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 8
Source File: NativeArray.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 9
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 10
Source File: NativeArray.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Object reduceInner(final ArrayLikeIterator<Object> iter, final Object self, final Object... args) {
    final Object  callbackfn          = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final boolean initialValuePresent = args.length > 1;

    Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;

    if (callbackfn == ScriptRuntime.UNDEFINED) {
        throw typeError("not.a.function", "undefined");
    }

    if (!initialValuePresent) {
        if (iter.hasNext()) {
            initialValue = iter.next();
        } else {
            throw typeError("array.reduce.invalid.init");
        }
    }

    //if initial value is ScriptRuntime.UNDEFINED - step forward once.
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) {
        private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            // TODO: why can't I declare the second arg as Undefined.class?
            result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self);
            return true;
        }
    }.apply();
}