Java Code Examples for jdk.nashorn.internal.runtime.ScriptFunction#isStrict()
The following examples show how to use
jdk.nashorn.internal.runtime.ScriptFunction#isStrict() .
These examples are extracted from open source projects.
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 Project: TencentKona-8 File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 2
Source Project: jdk8u60 File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 3
Source Project: openjdk-jdk8u File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 4
Source Project: openjdk-jdk8u-backup File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 5
Source Project: openjdk-jdk9 File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 6
Source Project: hottub File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 7
Source Project: openjdk-8-source File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); } return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); }
Example 8
Source Project: openjdk-8-source File: NativeArray.java License: GNU General Public License v2.0 | 5 votes |
private static Object[] sort(final Object[] array, final Object comparefn) { final ScriptFunction cmp = compareFunction(comparefn); final List<Object> list = Arrays.asList(array); final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance(); 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)); } }); return list.toArray(new Object[array.length]); }
Example 9
Source Project: openjdk-8-source File: NativeRegExp.java License: GNU General Public License v2.0 | 5 votes |
private String callReplaceValue(final ScriptFunction function, final RegExpMatcher matcher, final String string) { final Object[] groups = groups(matcher); final Object[] args = Arrays.copyOf(groups, groups.length + 2); args[groups.length] = matcher.start(); args[groups.length + 1] = string; final Object self = function.isStrict() ? UNDEFINED : Global.instance(); return JSType.toString(ScriptRuntime.apply(function, self, args)); }
Example 10
Source Project: openjdk-8 File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); } return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); }
Example 11
Source Project: openjdk-8 File: NativeArray.java License: GNU General Public License v2.0 | 5 votes |
private static Object[] sort(final Object[] array, final Object comparefn) { final ScriptFunction cmp = compareFunction(comparefn); final List<Object> list = Arrays.asList(array); final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance(); 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)); } }); return list.toArray(new Object[array.length]); }
Example 12
Source Project: openjdk-8 File: NativeRegExp.java License: GNU General Public License v2.0 | 5 votes |
private String callReplaceValue(final ScriptFunction function, final RegExpMatcher matcher, final String string) { final Object[] groups = groups(matcher); final Object[] args = Arrays.copyOf(groups, groups.length + 2); args[groups.length] = matcher.start(); args[groups.length + 1] = string; final Object self = function.isStrict() ? UNDEFINED : Global.instance(); return JSType.toString(ScriptRuntime.apply(function, self, args)); }
Example 13
Source Project: jdk8u_nashorn File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap()); } return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap()); }
Example 14
Source Project: nashorn File: NativeArguments.java License: GNU General Public License v2.0 | 5 votes |
/** * Factory to create correct Arguments object based on strict mode. * * @param arguments the actual arguments array passed * @param callee the callee function that uses arguments object * @param numParams the number of declared (named) function parameters * @return Arguments Object */ public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) { // Strict functions won't always have a callee for arguments, and will pass null instead. final boolean isStrict = callee == null || callee.isStrict(); final Global global = Global.instance(); final ScriptObject proto = global.getObjectPrototype(); if (isStrict) { return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); } return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); }
Example 15
Source Project: nashorn File: NativeArray.java License: GNU General Public License v2.0 | 5 votes |
private static Object[] sort(final Object[] array, final Object comparefn) { final ScriptFunction cmp = compareFunction(comparefn); final List<Object> list = Arrays.asList(array); final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance(); 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)); } }); return list.toArray(new Object[array.length]); }
Example 16
Source Project: nashorn File: NativeRegExp.java License: GNU General Public License v2.0 | 5 votes |
private String callReplaceValue(final ScriptFunction function, final RegExpMatcher matcher, final String string) { final Object[] groups = groups(matcher); final Object[] args = Arrays.copyOf(groups, groups.length + 2); args[groups.length] = matcher.start(); args[groups.length + 1] = string; final Object self = function.isStrict() ? UNDEFINED : Global.instance(); return JSType.toString(ScriptRuntime.apply(function, self, args)); }
Example 17
Source Project: jdk8u60 File: NativeArray.java License: GNU General Public License v2.0 | 4 votes |
private static Object[] sort(final Object[] array, final Object comparefn) { final ScriptFunction cmp = compareFunction(comparefn); final List<Object> list = Arrays.asList(array); final Object cmpThis = cmp == null || cmp.isStrict() ? 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 18
Source Project: hottub File: NativeArray.java License: GNU General Public License v2.0 | 4 votes |
private static Object[] sort(final Object[] array, final Object comparefn) { final ScriptFunction cmp = compareFunction(comparefn); final List<Object> list = Arrays.asList(array); final Object cmpThis = cmp == null || cmp.isStrict() ? 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 19
Source Project: openjdk-jdk9 File: JavaAdapterServices.java License: GNU General Public License v2.0 | 2 votes |
/** * Given a script function used as a delegate for a SAM adapter, figure out * the right object to use as its "this" when called. * @param delegate the delegate function * @param global the current global of the adapter * @return either the passed global, or UNDEFINED if the function is strict. */ public static Object getCallThis(final ScriptFunction delegate, final Object global) { return delegate.isStrict() ? ScriptRuntime.UNDEFINED : global; }