Example usage for jdk.nashorn.internal.runtime Context getContext

List of usage examples for jdk.nashorn.internal.runtime Context getContext

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime Context getContext.

Prototype

public static Context getContext() 

Source Link

Document

Get context of the current global

Usage

From source file:net.orzo.lib.Lib.java

License:Apache License

/**
 * Measures the execution time of the provided function. Please note that in
 * case of asynchronous code you may not obtain the value you have been
 * expecting.// w  w  w.  j  a  v a  2 s.  co  m
 *
 * @param function
 * @return time in milliseconds
 */
public long measureTime(ScriptFunction function) {
    long startTime = System.currentTimeMillis();
    MethodHandle mh = function.getBoundInvokeHandle(Context.getContext());

    try {
        mh.invoke();

    } catch (Throwable e) {
        throw new LibException(e);
    }
    return System.currentTimeMillis() - startTime;
}