19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.nashorn.api.scripting; 27 28 import java.lang.invoke.MethodHandle; 29 import jdk.internal.dynalink.beans.StaticClass; 30 import jdk.internal.dynalink.linker.LinkerServices; 31 import jdk.nashorn.internal.runtime.Context; 32 import jdk.nashorn.internal.runtime.ScriptFunction; 33 import jdk.nashorn.internal.runtime.ScriptObject; 34 import jdk.nashorn.internal.runtime.ScriptRuntime; 35 import jdk.nashorn.internal.runtime.linker.Bootstrap; 36 37 /** 38 * Utilities that are to be called from script code. 39 */ 40 public final class ScriptUtils { 41 private ScriptUtils() {} 42 43 /** 44 * Returns AST as JSON compatible string. This is used to 45 * implement "parse" function in resources/parse.js script. 46 * 47 * @param code code to be parsed 48 * @param name name of the code source (used for location) 49 * @param includeLoc tells whether to include location information for nodes or not 50 * @return JSON string representation of AST of the supplied code 51 */ 52 public static String parse(final String code, final String name, final boolean includeLoc) { 53 return ScriptRuntime.parse(code, name, includeLoc); 54 } 55 56 /** 57 * Method which converts javascript types to java types for the 58 * String.format method (jrunscript function sprintf). 59 * | 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.nashorn.api.scripting; 27 28 import java.lang.invoke.MethodHandle; 29 import jdk.internal.dynalink.beans.StaticClass; 30 import jdk.internal.dynalink.linker.LinkerServices; 31 import jdk.nashorn.internal.runtime.Context; 32 import jdk.nashorn.internal.runtime.ScriptFunction; 33 import jdk.nashorn.internal.runtime.ScriptObject; 34 import jdk.nashorn.internal.runtime.ScriptRuntime; 35 import jdk.nashorn.internal.runtime.linker.Bootstrap; 36 37 /** 38 * Utilities that are to be called from script code. 39 * 40 * @since 1.8u40 41 */ 42 @jdk.Exported 43 public final class ScriptUtils { 44 private ScriptUtils() {} 45 46 /** 47 * Returns AST as JSON compatible string. This is used to 48 * implement "parse" function in resources/parse.js script. 49 * 50 * @param code code to be parsed 51 * @param name name of the code source (used for location) 52 * @param includeLoc tells whether to include location information for nodes or not 53 * @return JSON string representation of AST of the supplied code 54 */ 55 public static String parse(final String code, final String name, final boolean includeLoc) { 56 return ScriptRuntime.parse(code, name, includeLoc); 57 } 58 59 /** 60 * Method which converts javascript types to java types for the 61 * String.format method (jrunscript function sprintf). 62 * |