Java Code Examples for jdk.nashorn.internal.runtime.linker.Bootstrap#isStrictCallable()

The following examples show how to use jdk.nashorn.internal.runtime.linker.Bootstrap#isStrictCallable() . 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: IteratorAction.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 2
Source File: IteratorAction.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 3
Source File: IteratorAction.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 4
Source File: IteratorAction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 5
Source File: IteratorAction.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 6
Source File: IteratorAction.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 7
Source File: IteratorAction.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply action main loop.
 * @return result of apply
 */
public final T apply() {
    final boolean strict = Bootstrap.isStrictCallable(callbackfn);

    // for non-strict callback, need to translate undefined thisArg to be global object
    thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;

    applyLoopBegin(iter);
    final boolean reverse = iter.isReverse();
    while (iter.hasNext()) {

        final Object val = iter.next();
        index = iter.nextIndex() + (reverse ? 1 : -1);

        try {
            if (!forEach(val, index)) {
                return result;
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }
    }

    return result;
}
 
Example 8
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static Object[] sort(final Object[] array, final Object comparefn) {
    final Object cmp = compareFunction(comparefn);

    final List<Object> list = Arrays.asList(array);
    final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();

    try {
        Collections.sort(list, new Comparator<Object>() {
            private final MethodHandle call_cmp = getCALL_CMP();
            @Override
            public int compare(final Object x, final Object y) {
                if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
                    return 0;
                } else if (x == ScriptRuntime.UNDEFINED) {
                    return 1;
                } else if (y == ScriptRuntime.UNDEFINED) {
                    return -1;
                }

                if (cmp != null) {
                    try {
                        return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
                    } catch (final RuntimeException | Error e) {
                        throw e;
                    } catch (final Throwable t) {
                        throw new RuntimeException(t);
                    }
                }

                return JSType.toString(x).compareTo(JSType.toString(y));
            }
        });
    } catch (final IllegalArgumentException iae) {
        // Collections.sort throws IllegalArgumentException when
        // Comparison method violates its general contract

        // See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
        // If "comparefn" is not undefined and is not a consistent
        // comparison function for the elements of this array, the
        // behaviour of sort is implementation-defined.
    }

    return list.toArray(new Object[array.length]);
}
 
Example 9
Source File: NativeArray.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static Object[] sort(final Object[] array, final Object comparefn) {
    final Object cmp = compareFunction(comparefn);

    final List<Object> list = Arrays.asList(array);
    final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();

    try {
        Collections.sort(list, new Comparator<Object>() {
            private final MethodHandle call_cmp = getCALL_CMP();
            @Override
            public int compare(final Object x, final Object y) {
                if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
                    return 0;
                } else if (x == ScriptRuntime.UNDEFINED) {
                    return 1;
                } else if (y == ScriptRuntime.UNDEFINED) {
                    return -1;
                }

                if (cmp != null) {
                    try {
                        return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
                    } catch (final RuntimeException | Error e) {
                        throw e;
                    } catch (final Throwable t) {
                        throw new RuntimeException(t);
                    }
                }

                return JSType.toString(x).compareTo(JSType.toString(y));
            }
        });
    } catch (final IllegalArgumentException iae) {
        // Collections.sort throws IllegalArgumentException when
        // Comparison method violates its general contract

        // See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
        // If "comparefn" is not undefined and is not a consistent
        // comparison function for the elements of this array, the
        // behaviour of sort is implementation-defined.
    }

    return list.toArray(new Object[array.length]);
}
 
Example 10
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static Object[] sort(final Object[] array, final Object comparefn) {
    final Object cmp = compareFunction(comparefn);

    final List<Object> list = Arrays.asList(array);
    final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();

    try {
        Collections.sort(list, new Comparator<Object>() {
            private final MethodHandle call_cmp = getCALL_CMP();
            @Override
            public int compare(final Object x, final Object y) {
                if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
                    return 0;
                } else if (x == ScriptRuntime.UNDEFINED) {
                    return 1;
                } else if (y == ScriptRuntime.UNDEFINED) {
                    return -1;
                }

                if (cmp != null) {
                    try {
                        return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
                    } catch (final RuntimeException | Error e) {
                        throw e;
                    } catch (final Throwable t) {
                        throw new RuntimeException(t);
                    }
                }

                return JSType.toString(x).compareTo(JSType.toString(y));
            }
        });
    } catch (final IllegalArgumentException iae) {
        // Collections.sort throws IllegalArgumentException when
        // Comparison method violates its general contract

        // See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
        // If "comparefn" is not undefined and is not a consistent
        // comparison function for the elements of this array, the
        // behaviour of sort is implementation-defined.
    }

    return list.toArray(new Object[array.length]);
}
 
Example 11
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static Object[] sort(final Object[] array, final Object comparefn) {
    final Object cmp = compareFunction(comparefn);

    final List<Object> list = Arrays.asList(array);
    final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();

    try {
        Collections.sort(list, new Comparator<Object>() {
            private final MethodHandle call_cmp = getCALL_CMP();
            @Override
            public int compare(final Object x, final Object y) {
                if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
                    return 0;
                } else if (x == ScriptRuntime.UNDEFINED) {
                    return 1;
                } else if (y == ScriptRuntime.UNDEFINED) {
                    return -1;
                }

                if (cmp != null) {
                    try {
                        return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
                    } catch (final RuntimeException | Error e) {
                        throw e;
                    } catch (final Throwable t) {
                        throw new RuntimeException(t);
                    }
                }

                return JSType.toString(x).compareTo(JSType.toString(y));
            }
        });
    } catch (final IllegalArgumentException iae) {
        // Collections.sort throws IllegalArgumentException when
        // Comparison method violates its general contract

        // See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
        // If "comparefn" is not undefined and is not a consistent
        // comparison function for the elements of this array, the
        // behaviour of sort is implementation-defined.
    }

    return list.toArray(new Object[0]);
}
 
Example 12
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private static Object[] sort(final Object[] array, final Object comparefn) {
    final Object cmp = compareFunction(comparefn);

    final List<Object> list = Arrays.asList(array);
    final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();

    try {
        Collections.sort(list, new Comparator<Object>() {
            private final MethodHandle call_cmp = getCALL_CMP();
            @Override
            public int compare(final Object x, final Object y) {
                if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
                    return 0;
                } else if (x == ScriptRuntime.UNDEFINED) {
                    return 1;
                } else if (y == ScriptRuntime.UNDEFINED) {
                    return -1;
                }

                if (cmp != null) {
                    try {
                        return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
                    } catch (final RuntimeException | Error e) {
                        throw e;
                    } catch (final Throwable t) {
                        throw new RuntimeException(t);
                    }
                }

                return JSType.toString(x).compareTo(JSType.toString(y));
            }
        });
    } catch (final IllegalArgumentException iae) {
        // Collections.sort throws IllegalArgumentException when
        // Comparison method violates its general contract

        // See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
        // If "comparefn" is not undefined and is not a consistent
        // comparison function for the elements of this array, the
        // behaviour of sort is implementation-defined.
    }

    return list.toArray(new Object[array.length]);
}