use of org.mozilla.javascript.Function in project servoy-client by Servoy.
the class JSForm method js_setOnRecordEditStartMethod.
/**
* @deprecated As of release 4.1, replaced by setOnRecordEditStart(JSMethod).
*/
@Deprecated
@ServoyClientSupport(ng = false, wc = true, sc = true)
public void js_setOnRecordEditStartMethod(Object functionOrInteger) {
checkModification();
if (functionOrInteger instanceof Function) {
Function function = (Function) functionOrInteger;
ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
if (scriptMethod != null) {
getForm().setOnRecordEditStartMethodID(scriptMethod.getID());
} else {
getForm().setOnRecordEditStartMethodID(0);
}
} else if (functionOrInteger instanceof Number) {
getForm().setOnRecordEditStartMethodID(((Number) functionOrInteger).intValue());
}
}
use of org.mozilla.javascript.Function in project kolmafia by kolmafia.
the class JavascriptRuntime method executeRun.
private Value executeRun(final String functionName, final Object[] arguments, final boolean executeTopLevel) {
Context cx = Context.getCurrentContext();
Scriptable scope = currentTopScope;
Object[] argumentsNonNull = arguments != null ? arguments : new Object[] {};
Object[] runArguments = Arrays.stream(argumentsNonNull).map(o -> o instanceof MonsterData ? EnumeratedWrapper.wrap(scope, MonsterProxy.class, DataTypes.makeMonsterValue((MonsterData) o)) : o).toArray();
return executeFunction(scope, () -> {
Scriptable exports = null;
if (executeTopLevel) {
Require require = new SafeRequire(cx, scope, currentStdLib);
if (scriptFile != null) {
exports = require.requireMain(cx, scriptFile.toURI().toString());
} else {
require.install(scope);
return cx.evaluateString(scope, scriptString, "command line", 1, null);
}
}
if (functionName != null) {
Object mainFunction = ScriptableObject.getProperty(exports != null ? exports : scope, functionName);
if (mainFunction instanceof Function) {
return ((Function) mainFunction).call(cx, scope, cx.newObject(currentTopScope), runArguments);
}
}
return null;
});
}
use of org.mozilla.javascript.Function in project kolmafia by kolmafia.
the class EnumeratedWrapperPrototype method initToScope.
public void initToScope(Context cx, Scriptable scope, Scriptable runtimeLibrary) {
setPrototype(ScriptableObject.getObjectPrototype(scope));
if (recordValueClass != null) {
for (Method method : recordValueClass.getDeclaredMethods()) {
if (method.getName().startsWith("get_")) {
ProxyRecordMethodWrapper methodWrapper = new ProxyRecordMethodWrapper(scope, ScriptableObject.getFunctionPrototype(scope), method);
String methodShortName = JavascriptRuntime.toCamelCase(method.getName().replace("get_", ""));
setGetterOrSetter(methodShortName, 0, methodWrapper, false);
}
}
}
try {
Method constructorMethod = EnumeratedWrapper.class.getDeclaredMethod("constructDefaultValue");
FunctionObject constructor = new FunctionObject(getClassName(), constructorMethod, scope);
constructor.addAsConstructor(scope, this);
if (runtimeLibrary != null) {
ScriptableObject.defineProperty(runtimeLibrary, getClassName(), constructor, DONTENUM | READONLY | PERMANENT);
}
Method getMethod = EnumeratedWrapper.class.getDeclaredMethod("genericGet", Context.class, Scriptable.class, Object[].class, Function.class);
Function getFunction = new FunctionObject("get", getMethod, scope);
ScriptableObject.defineProperty(getFunction, "typeName", getClassName(), DONTENUM | READONLY | PERMANENT);
constructor.defineProperty("get", getFunction, DONTENUM | READONLY | PERMANENT);
Method allMethod = EnumeratedWrapper.class.getDeclaredMethod("all", Context.class, Scriptable.class, Object[].class, Function.class);
Function allFunction = new FunctionObject("all", allMethod, scope);
ScriptableObject.defineProperty(allFunction, "typeName", getClassName(), DONTENUM | READONLY | PERMANENT);
constructor.defineProperty("all", allFunction, DONTENUM | READONLY | PERMANENT);
constructor.sealObject();
for (String methodName : new String[] { "toString" }) {
Method method = EnumeratedWrapper.class.getDeclaredMethod(methodName);
FunctionObject functionObject = new FunctionObject(methodName, method, scope);
defineProperty(methodName, functionObject, DONTENUM | READONLY | PERMANENT);
functionObject.sealObject();
}
} catch (NoSuchMethodException e) {
KoLmafia.updateDisplay(KoLConstants.MafiaState.ERROR, "NoSuchMethodException: " + e.getMessage());
}
sealObject();
}
use of org.mozilla.javascript.Function in project jslint4java by happygiraffe.
the class JSLintBuilder method fromReader.
/**
* Initialize the scope with an arbitrary jslint.
*
* @param reader
* an input source providing jslint.js.
* @param name
* the name of the resource backed by the reader
* @return a configured {@link JSLint}
* @throws IOException
* if there are any problems reading from {@code reader} .
*/
@NeedsContext
public JSLint fromReader(Reader reader, String name) throws IOException {
try {
Context cx = contextFactory.enterContext();
ScriptableObject scope = cx.initStandardObjects();
cx.evaluateReader(scope, reader, name, 1, null);
Function lintFunc = (Function) scope.get("JSLINT", scope);
return new JSLint(contextFactory, lintFunc);
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Function in project scriptographer by scriptographer.
the class TopLevel method mapJavaClass.
/**
* Maps a Java class to a JavaScript prototype, so this can be used
* instead for wrapping of returned java types. So far this is only
* used for java.io.File in Scriptographer.
*/
public static void mapJavaClass(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
if (args.length == 2) {
for (int i = 0; i < args.length; i++) args[i] = Context.jsToJava(args[i], Object.class);
if (args[0] instanceof Class && args[1] instanceof Function) {
Class cls = (Class) args[0];
Function proto = (Function) args[1];
RhinoWrapFactory factory = (RhinoWrapFactory) cx.getWrapFactory();
factory.mapJavaClass(cls, proto);
}
}
}
Aggregations