d2ec9a6d by Adam Heath

Move load/print into a separate, static Interface class.

1 parent 3f9fa324
......@@ -89,7 +89,7 @@ public class Require {
public Function run(Context cx, RhinoContainer<?> container) throws FileNotFoundException, IOException {
container.configureTopScriptable(cx, this);
defineFunctionProperties(new String[] {"load", "print"}, Loader.class, ScriptableObject.DONTENUM);
defineFunctionProperties(new String[] {"load", "print"}, Interface.class, ScriptableObject.DONTENUM);
Scriptable argsObj = cx.newArray(this, new Object[] {});
defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
......@@ -101,21 +101,29 @@ public class Require {
return (Function) cx.evaluateString(this, "require", null, -1, null);
}
public static void print(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
Loader loader = (Loader) getTopLevelScope(thisObj);
loader.container.print(cx, thisObj, args, funObj);
public void print(Context cx, Object[] args, Function funObj) {
container.print(cx, this, args, funObj);
}
public static void load(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws FileNotFoundException, IOException {
Loader loader = (Loader) getTopLevelScope(thisObj);
public void load(Context cx, Object[] args, Function funObj) throws FileNotFoundException, IOException {
for (int i = 0; i < args.length; i++) {
String path = Context.toString(args[i]);
if (path.endsWith("/jquery.js")) {
loader.container.print(cx, thisObj, new Object[] {"Skipping file " + path}, funObj);
container.print(cx, this, new Object[] {"Skipping file " + path}, funObj);
continue;
}
loader.container.print(cx, thisObj, new Object[] {"Loading file " + path}, funObj);
loader.container.processSource(cx, thisObj, path);
container.print(cx, this, new Object[] {"Loading file " + path}, funObj);
container.processSource(cx, this, path);
}
}
public static final class Interface {
public static void load(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws FileNotFoundException, IOException {
((Loader) getTopLevelScope(thisObj)).load(cx, args, funObj);
}
public static void print(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
((Loader) getTopLevelScope(thisObj)).print(cx, args, funObj);
}
}
}
......