jdk.nashorn.internal.objects.ScriptFunctionImpl Java Examples

The following examples show how to use jdk.nashorn.internal.objects.ScriptFunctionImpl. 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: Bootstrap.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Binds any object Nashorn can use as a [[Callable]] to a receiver and optionally arguments.
 * @param callable the callable to bind
 * @param boundThis the bound "this" value.
 * @param boundArgs the bound arguments. Can be either null or empty array to signify no arguments are bound.
 * @return a bound callable.
 * @throws ECMAException with {@code TypeError} if the object is not a callable.
 */
public static Object bindCallable(final Object callable, final Object boundThis, final Object[] boundArgs) {
    if (callable instanceof ScriptFunctionImpl) {
        return ((ScriptFunctionImpl)callable).makeBoundFunction(boundThis, boundArgs);
    } else if (callable instanceof BoundCallable) {
        return ((BoundCallable)callable).bind(boundArgs);
    } else if (isCallable(callable)) {
        return new BoundCallable(callable, boundThis, boundArgs);
    }
    throw notFunction(callable);
}
 
Example #2
Source File: NativeError.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@SuppressWarnings("unused")
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    Global.checkObject(errorObj);
    final ScriptObject sobj = (ScriptObject)errorObj;
    new ECMAException(sobj, null); //constructor has side effects
    sobj.delete("stack", false);
    final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
    final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
    sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    return UNDEFINED;
}
 
Example #3
Source File: NativeError.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@SuppressWarnings("unused")
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    Global.checkObject(errorObj);
    final ScriptObject sobj = (ScriptObject)errorObj;
    new ECMAException(sobj, null); //constructor has side effects
    sobj.delete("stack", false);
    final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
    final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
    sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    return UNDEFINED;
}