- java.lang.Object
- 
- jdk.nashorn.api.scripting.ScriptUtils
 
- 
 
 public final class ScriptUtils extends Object Utilities that are to be called from script code.- Since:
- 1.8u40
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static Objectconvert(Object obj, Object type)Convert the given object to the given type.static Stringformat(String format, Object[] args)Method which converts javascript types to java types for the String.format method (jrunscript function sprintf).static ObjectmakeSynchronizedFunction(Object func, Object sync)Create a wrapper function that callsfuncsynchronized onsyncor, if that is undefined,self.static Stringparse(String code, String name, boolean includeLoc)Returns AST as JSON compatible string.static Objectunwrap(Object obj)Unwrap a script object mirror if needed.static Object[]unwrapArray(Object[] args)Unwrap an array of script object mirrors if needed.static ScriptObjectMirrorwrap(Object obj)Make a script object mirror on given object if needed.static Object[]wrapArray(Object[] args)Wrap an array of object to script object mirrors if needed.
 
- 
- 
- 
Method Detail- 
parsepublic static String parse(String code, String name, boolean includeLoc) Returns AST as JSON compatible string. This is used to implement "parse" function in resources/parse.js script.- Parameters:
- code- code to be parsed
- name- name of the code source (used for location)
- includeLoc- tells whether to include location information for nodes or not
- Returns:
- JSON string representation of AST of the supplied code
 
 - 
formatpublic static String format(String format, Object[] args) Method which converts javascript types to java types for the String.format method (jrunscript function sprintf).- Parameters:
- format- a format string
- args- arguments referenced by the format specifiers in format
- Returns:
- a formatted string
 
 - 
makeSynchronizedFunctionpublic static Object makeSynchronizedFunction(Object func, Object sync) Create a wrapper function that callsfuncsynchronized onsyncor, if that is undefined,self. Used to implement "sync" function in resources/mozilla_compat.js.- Parameters:
- func- the function to wrap
- sync- the object to synchronize on
- Returns:
- a synchronizing wrapper function
- Throws:
- IllegalArgumentException- if func does not represent a script function
 
 - 
wrappublic static ScriptObjectMirror wrap(Object obj) Make a script object mirror on given object if needed.- Parameters:
- obj- object to be wrapped
- Returns:
- wrapped object
- Throws:
- IllegalArgumentException- if obj cannot be wrapped
 
 - 
unwrappublic static Object unwrap(Object obj) Unwrap a script object mirror if needed.- Parameters:
- obj- object to be unwrapped
- Returns:
- unwrapped object
 
 - 
wrapArraypublic static Object[] wrapArray(Object[] args) Wrap an array of object to script object mirrors if needed.- Parameters:
- args- array to be unwrapped
- Returns:
- wrapped array
 
 - 
unwrapArraypublic static Object[] unwrapArray(Object[] args) Unwrap an array of script object mirrors if needed.- Parameters:
- args- array to be unwrapped
- Returns:
- unwrapped array
 
 - 
convertpublic static Object convert(Object obj, Object type) Convert the given object to the given type.- Parameters:
- obj- object to be converted
- type- destination type to convert to. type is either a Class or nashorn representation of a Java type returned by Java.type() call in script.
- Returns:
- converted object
 
 
- 
 
-