d2ec9a6d by Adam Heath

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

1 parent 3f9fa324
...@@ -89,7 +89,7 @@ public class Require { ...@@ -89,7 +89,7 @@ public class Require {
89 89
90 public Function run(Context cx, RhinoContainer<?> container) throws FileNotFoundException, IOException { 90 public Function run(Context cx, RhinoContainer<?> container) throws FileNotFoundException, IOException {
91 container.configureTopScriptable(cx, this); 91 container.configureTopScriptable(cx, this);
92 defineFunctionProperties(new String[] {"load", "print"}, Loader.class, ScriptableObject.DONTENUM); 92 defineFunctionProperties(new String[] {"load", "print"}, Interface.class, ScriptableObject.DONTENUM);
93 93
94 Scriptable argsObj = cx.newArray(this, new Object[] {}); 94 Scriptable argsObj = cx.newArray(this, new Object[] {});
95 defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); 95 defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
...@@ -101,21 +101,29 @@ public class Require { ...@@ -101,21 +101,29 @@ public class Require {
101 return (Function) cx.evaluateString(this, "require", null, -1, null); 101 return (Function) cx.evaluateString(this, "require", null, -1, null);
102 } 102 }
103 103
104 public static void print(Context cx, Scriptable thisObj, Object[] args, Function funObj) { 104 public void print(Context cx, Object[] args, Function funObj) {
105 Loader loader = (Loader) getTopLevelScope(thisObj); 105 container.print(cx, this, args, funObj);
106 loader.container.print(cx, thisObj, args, funObj);
107 } 106 }
108 107
109 public static void load(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws FileNotFoundException, IOException { 108 public void load(Context cx, Object[] args, Function funObj) throws FileNotFoundException, IOException {
110 Loader loader = (Loader) getTopLevelScope(thisObj);
111 for (int i = 0; i < args.length; i++) { 109 for (int i = 0; i < args.length; i++) {
112 String path = Context.toString(args[i]); 110 String path = Context.toString(args[i]);
113 if (path.endsWith("/jquery.js")) { 111 if (path.endsWith("/jquery.js")) {
114 loader.container.print(cx, thisObj, new Object[] {"Skipping file " + path}, funObj); 112 container.print(cx, this, new Object[] {"Skipping file " + path}, funObj);
115 continue; 113 continue;
116 } 114 }
117 loader.container.print(cx, thisObj, new Object[] {"Loading file " + path}, funObj); 115 container.print(cx, this, new Object[] {"Loading file " + path}, funObj);
118 loader.container.processSource(cx, thisObj, path); 116 container.processSource(cx, this, path);
117 }
118 }
119
120 public static final class Interface {
121 public static void load(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws FileNotFoundException, IOException {
122 ((Loader) getTopLevelScope(thisObj)).load(cx, args, funObj);
123 }
124
125 public static void print(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
126 ((Loader) getTopLevelScope(thisObj)).print(cx, args, funObj);
119 } 127 }
120 } 128 }
121 } 129 }
......