Java Code Examples for jdk.nashorn.internal.runtime.arrays.IteratorAction

The following are top voted examples for showing how to use jdk.nashorn.internal.runtime.arrays.IteratorAction. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 2
Project: OpenJSharp   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 3
Project: openjdk-jdk10   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 4
Project: openjdk-jdk10   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 5
Project: openjdk9   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 6
Project: openjdk9   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 7
Project: kaziranga   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 8
Project: kaziranga   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 9
Project: lookaside_java-1.8.0-openjdk   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 10
Project: lookaside_java-1.8.0-openjdk   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 11
Project: jdk8u_nashorn   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 12
Project: jdk8u_nashorn   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 13
Project: infobip-open-jdk-8   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 14
Project: infobip-open-jdk-8   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 15
Project: OLD-OpenJDK8   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 16
Project: OLD-OpenJDK8   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 17
Project: nashorn-backport   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 18
Project: nashorn-backport   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 19
Project: nashorn   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.19 Array.prototype.map ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return array with elements transformed by map function
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object map(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) {
        private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r);
            return true;
        }

        @Override
        public void applyLoopBegin(final ArrayLikeIterator<Object> iter0) {
            // map return array should be of same length as source array
            // even if callback reduces source array length
            result = new NativeArray(iter0.getLength());
        }
    }.apply();
}
 
Example 20
Project: nashorn   File: NativeArray.java   Source Code and License 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 21
Project: OpenJSharp   File: NativeArray.java   Source Code and License 5 votes vote down vote up
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
Example 22
Project: OpenJSharp   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
Example 23
Project: OpenJSharp   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 24
Project: OpenJSharp   File: NativeArray.java   Source Code and License 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 25
Project: openjdk-jdk10   File: NativeArray.java   Source Code and License 5 votes vote down vote up
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
Example 26
Project: openjdk-jdk10   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
Example 27
Project: openjdk-jdk10   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 28
Project: openjdk-jdk10   File: NativeArray.java   Source Code and License 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 29
Project: openjdk9   File: NativeArray.java   Source Code and License 5 votes vote down vote up
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
Example 30
Project: openjdk9   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
Example 31
Project: openjdk9   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 32
Project: openjdk9   File: NativeArray.java   Source Code and License 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 33
Project: kaziranga   File: NativeArray.java   Source Code and License 5 votes vote down vote up
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
Example 34
Project: kaziranga   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
Example 35
Project: kaziranga   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final long i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 36
Project: kaziranga   File: NativeArray.java   Source Code and License 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 37
Project: lookaside_java-1.8.0-openjdk   File: NativeArray.java   Source Code and License 5 votes vote down vote up
private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) {
        private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self);
        }
    }.apply();
}
 
Example 38
Project: lookaside_java-1.8.0-openjdk   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
Example 39
Project: lookaside_java-1.8.0-openjdk   File: NativeArray.java   Source Code and License 5 votes vote down vote up
/**
 * ECMA 15.4.4.18 Array.prototype.forEach ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) {
        private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self);
            return true;
        }
    }.apply();
}
 
Example 40
Project: lookaside_java-1.8.0-openjdk   File: NativeArray.java   Source Code and License 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();
}