public class ScriptUtils extends Object
| Constructor and Description |
|---|
ScriptUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
assertHelper(Object condition,
Object... args)
Helper for console.assert().
|
static void |
checkArguments(Object[] args,
int min,
int max)
Make sure that number of arguments is valid.
|
static org.mozilla.javascript.Scriptable |
getClassOrObjectProto(org.mozilla.javascript.Scriptable scope,
String className)
Return a class prototype, or the object prototype if the class
is not defined.
|
static Map |
getMapArgument(Object[] args,
int pos,
boolean allowNull)
Get an argument as Map
|
static Object |
getObjectArgument(Object[] args,
int pos,
boolean allowNull)
Get an argument as object
|
static org.mozilla.javascript.ScriptableObject |
getScriptableArgument(Object[] args,
int pos,
boolean allowNull)
Get an argument as ScriptableObject
|
static String |
getStringArgument(Object[] args,
int pos,
boolean allowNull)
Get an argument as string
|
static Object |
javaToJS(Object obj,
org.mozilla.javascript.Scriptable scope)
Coerce/wrap a java object to a JS object, and mask Lists and Maps
as native JS objects.
|
static Object |
jsToJava(Object obj)
Unwrap a JS object to a java object.
|
static int |
toInt(Object obj,
int defaultValue)
Try to convert an object to an int value, returning the default value if conversion fails.
|
static void |
traceHelper(org.mozilla.javascript.Function function,
Object... args)
Get a snapshot of the current JavaScript evaluation state by creating
an Error object and invoke the function on it passing along any arguments.
|
public static Object javaToJS(Object obj, org.mozilla.javascript.Scriptable scope)
obj - the object to coerce/wrapscope - the scopepublic static Object jsToJava(Object obj)
obj - a JavaScript valuepublic static org.mozilla.javascript.Scriptable getClassOrObjectProto(org.mozilla.javascript.Scriptable scope,
String className)
scope - the scopeclassName - the class namepublic static void checkArguments(Object[] args, int min, int max)
args - the argument arraymin - the minimum number of argumentsmax - the maximum number of argumentsIllegalArgumentException - if the number of arguments is not validpublic static org.mozilla.javascript.ScriptableObject getScriptableArgument(Object[] args, int pos, boolean allowNull) throws IllegalArgumentException
args - the argument arraypos - the position of the requested argumentIllegalArgumentException - if the argument can't be converted to a mappublic static String getStringArgument(Object[] args, int pos, boolean allowNull)
args - the argument arraypos - the position of the requested argumentpublic static Map getMapArgument(Object[] args, int pos, boolean allowNull) throws IllegalArgumentException
args - the argument arraypos - the position of the requested argumentIllegalArgumentException - if the argument can't be converted to a mappublic static Object getObjectArgument(Object[] args, int pos, boolean allowNull)
args - the argument arraypos - the position of the requested argumentpublic static int toInt(Object obj, int defaultValue)
obj - the valuedefaultValue - the default valuepublic static void traceHelper(org.mozilla.javascript.Function function,
Object... args)
function - the function to callargs - optional arguments to pass to the function.Copyright © 2016. All rights reserved.