@Exported public final class ScriptUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Object |
convert(Object obj,
Object type)
Convert the given object to the given type.
|
static String |
format(String format,
Object[] args)
Method which converts javascript types to java types for the
String.format method (jrunscript function sprintf).
|
static Object |
makeSynchronizedFunction(Object func,
Object sync)
Create a wrapper function that calls
func synchronized on sync or, if that is undefined,
self. |
static String |
parse(String code,
String name,
boolean includeLoc)
Returns AST as JSON compatible string.
|
static Object |
unwrap(Object obj)
Unwrap a script object mirror if needed.
|
static Object[] |
unwrapArray(Object[] args)
Unwrap an array of script object mirrors if needed.
|
static ScriptObjectMirror |
wrap(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.
|
public static String parse(String code, String name, boolean includeLoc)
code - code to be parsedname - name of the code source (used for location)includeLoc - tells whether to include location information for nodes or notpublic static String format(String format, Object[] args)
format - a format stringargs - arguments referenced by the format specifiers in formatpublic static Object makeSynchronizedFunction(Object func, Object sync)
func synchronized on sync or, if that is undefined,
self. Used to implement "sync" function in resources/mozilla_compat.js.func - the function to wrapsync - the object to synchronize onIllegalArgumentException - if func does not represent a script functionpublic static ScriptObjectMirror wrap(Object obj)
obj - object to be wrappedIllegalArgumentException - if obj cannot be wrappedpublic static Object unwrap(Object obj)
obj - object to be unwrappedpublic static Object[] wrapArray(Object[] args)
args - array to be unwrappedpublic static Object[] unwrapArray(Object[] args)
args - array to be unwrappedpublic static Object convert(Object obj, Object type)
obj - object to be convertedtype - destination type to convert to. type is either a Class
or nashorn representation of a Java type returned by Java.type() call in script.
Copyright © 2014, 2016, Oracle and/or its affiliates. All rights reserved.