Example usage for jdk.nashorn.internal.runtime ScriptFunction toSource

List of usage examples for jdk.nashorn.internal.runtime ScriptFunction toSource

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ScriptFunction toSource.

Prototype

public final String toSource() 

Source Link

Document

Get this function as a String containing its source code.

Usage

From source file:org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction.java

License:Open Source License

/**
 * This will return the converted SerializableJsFunction if the given  ScriptObjectMirror is a function.
 * @param scriptObjectMirror/* w  w  w  .  j  a v a2 s  .co m*/
 * @return null if the ScriptObjectMirror is not a function.
 */
public static SerializableJsFunction toSerializableForm(ScriptObjectMirror scriptObjectMirror) {

    if (!scriptObjectMirror.isFunction()) {
        return null;
    }

    //TODO try to get rid of ScriptFunction
    Object unwrapped = ScriptUtils.unwrap(scriptObjectMirror);
    if (unwrapped instanceof ScriptFunction) {
        ScriptFunction scriptFunction = (ScriptFunction) unwrapped;
        boolean isFunction = scriptObjectMirror.isFunction();
        String source = scriptFunction.toSource();

        return new SerializableJsFunction(source, isFunction);
    } else {
        return new SerializableJsFunction(unwrapped.toString(), true);
    }
}