use of org.mozilla.javascript.ScriptableObject in project jaggery by wso2.
the class CommandLineManager method include.
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
public static void include(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "include";
int argsCount = args.length;
if (argsCount != 1) {
HostObjectUtil.invalidNumberOfArgs(CommonManager.HOST_OBJECT_NAME, functionName, argsCount, false);
}
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(CommonManager.HOST_OBJECT_NAME, functionName, "1", "string", args[0], false);
}
JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();
Stack<String> includesCallstack = CommonManager.getCallstack(jaggeryContext);
Map<String, Boolean> includedScripts = CommonManager.getIncludes(jaggeryContext);
String parent = includesCallstack.lastElement();
String fileURL = (String) args[0];
if (CommonManager.isHTTP(fileURL) || CommonManager.isHTTP(parent)) {
CommonManager.include(cx, thisObj, args, funObj);
return;
}
ScriptableObject scope = jaggeryContext.getScope();
RhinoEngine engine = jaggeryContext.getEngine();
if (fileURL.startsWith("/")) {
fileURL = includesCallstack.firstElement() + fileURL;
} else {
fileURL = FilenameUtils.getFullPath(parent) + fileURL;
}
fileURL = FilenameUtils.normalize(fileURL);
if (includesCallstack.search(fileURL) != -1) {
return;
}
ScriptReader source = null;
try {
source = new ScriptReader(new FileInputStream(fileURL));
includedScripts.put(fileURL, true);
includesCallstack.push(fileURL);
engine.exec(source, scope, null);
includesCallstack.pop();
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
}
use of org.mozilla.javascript.ScriptableObject in project jaggery by wso2.
the class DatabaseHostObject method processResults.
private static Scriptable processResults(Context cx, Scriptable scope, DatabaseHostObject db, ResultSet results, boolean keyed) throws SQLException, ScriptException {
List<ScriptableObject> rows = new ArrayList<ScriptableObject>();
while (results.next()) {
ScriptableObject row;
ResultSetMetaData rsmd = results.getMetaData();
if (keyed) {
row = (ScriptableObject) db.context.newObject(db);
for (int i = 0; i < rsmd.getColumnCount(); i++) {
String columnName = rsmd.getColumnLabel(i + 1);
Object columnValue = getValue(db, results, i + 1, rsmd.getColumnType(i + 1));
row.put(columnName, row, columnValue);
}
} else {
row = (ScriptableObject) cx.newArray(scope, rsmd.getColumnCount());
for (int i = 0; i < rsmd.getColumnCount(); i++) {
Object columnValue = getValue(db, results, i + 1, rsmd.getColumnType(i + 1));
row.put(i + 1, row, columnValue);
}
}
rows.add(row);
}
return db.context.newArray(db, rows.toArray());
}
use of org.mozilla.javascript.ScriptableObject in project OpenAM by OpenRock.
the class RhinoScriptEngine method getScope.
/**
* Builds a Rhino variable scope that includes all of the scopes defined in the given script context as well as
* the standard Rhino top-level environment. Also binds the variable {@code context} to point to the JSR 223
* ScriptContext object, as per the JSR 223 spec.
*
* @param context the Rhino context to build the scope for.
* @param scriptContext the JSR 223 script context.
* @return a Rhino scope containing the given ScriptContext bindings and standard Rhino top-level bindings.
*/
private Scriptable getScope(final Context context, final ScriptContext scriptContext) {
final Scriptable scope = new ScriptContextScope(scriptContext);
final ScriptableObject topLevel = context.initStandardObjects();
scope.setPrototype(topLevel);
scope.put("context", scope, scriptContext);
return scope;
}
use of org.mozilla.javascript.ScriptableObject in project quorrabot by GloriousEggroll.
the class Script method load.
public void load() throws IOException {
if (killed) {
return;
}
context = Context.enter();
ScriptableObject scope = context.initStandardObjects(global, false);
scope.defineProperty("$", global, 0);
scope.defineProperty("$api", ScriptApi.instance(), 0);
scope.defineProperty("$script", this, 0);
scope.defineProperty("$var", vars, 0);
context.evaluateString(scope, FileUtils.readFileToString(file), file.getName(), 1, null);
}
use of org.mozilla.javascript.ScriptableObject in project sling by apache.
the class AsyncExtractor method extract.
public void extract(Object jsObj, UnaryCallback unaryCallback) {
if (!isPromise(jsObj)) {
unaryCallback.invoke(jsObj);
}
if (jsObj instanceof AsyncContainer) {
((AsyncContainer) jsObj).addListener(unaryCallback);
}
if (jsObj instanceof ScriptableObject) {
ScriptableObject scriptableObject = (ScriptableObject) jsObj;
decodeJSPromise(scriptableObject, unaryCallback);
}
}
Aggregations