|
19 | 19 | import com.asual.lesscss.loader.ResourceLoader;
|
20 | 20 | import org.apache.commons.logging.Log;
|
21 | 21 | import org.apache.commons.logging.LogFactory;
|
22 |
| -import org.mozilla.javascript.*; |
| 22 | +import org.mozilla.javascript.Context; |
| 23 | +import org.mozilla.javascript.Function; |
| 24 | +import org.mozilla.javascript.JavaScriptException; |
| 25 | +import org.mozilla.javascript.NativeArray; |
| 26 | +import org.mozilla.javascript.Scriptable; |
| 27 | +import org.mozilla.javascript.ScriptableObject; |
| 28 | +import org.mozilla.javascript.UniqueTag; |
23 | 29 | import org.mozilla.javascript.tools.shell.Global;
|
24 | 30 |
|
25 | 31 | import java.io.IOException;
|
|
30 | 36 |
|
31 | 37 | public class RhinoCompiler implements LessCompiler {
|
32 | 38 |
|
33 |
| - private Scriptable scope; |
34 |
| - private final Function compile; |
35 |
| - |
36 | 39 | private final Log logger = LogFactory.getLog(getClass());
|
| 40 | + private final Scriptable scope; |
| 41 | + private final Function compile; |
37 | 42 |
|
38 | 43 | public RhinoCompiler(LessOptions options, ResourceLoader loader, URL less, URL env, URL engine, URL cssmin, URL sourceMap) throws IOException {
|
39 | 44 | Context cx = Context.enter();
|
@@ -78,24 +83,19 @@ public RhinoCompiler(LessOptions options, ResourceLoader loader, URL less, URL e
|
78 | 83 | @Override
|
79 | 84 | public String compile(String input, String location, boolean compress) throws LessException {
|
80 | 85 | try {
|
81 |
| - return call(compile, new Object[]{input, location, compress}); |
82 |
| - } |
83 |
| - catch (Exception e){ |
| 86 | + return (String) Context.call(null, compile, scope, scope, |
| 87 | + new Object[]{input, location, compress}); |
| 88 | + } catch (Exception e) { |
84 | 89 | throw new LessException(parseLessException(e));
|
85 | 90 | }
|
86 | 91 | }
|
87 | 92 |
|
88 |
| - private String call(Function fn, Object[] args) { |
89 |
| - return (String) Context.call(null, fn, scope, scope, args); |
90 |
| - } |
91 |
| - |
92 | 93 | private boolean hasProperty(Scriptable value, String name) {
|
93 | 94 | Object property = ScriptableObject.getProperty(value, name);
|
94 | 95 | return property != null && !property.equals(UniqueTag.NOT_FOUND);
|
95 | 96 | }
|
96 | 97 |
|
97 |
| - private LessException parseLessException(Exception root) |
98 |
| - throws LessException { |
| 98 | + private Exception parseLessException(Exception root) { |
99 | 99 | logger.debug("Parsing LESS Exception", root);
|
100 | 100 | if (root instanceof JavaScriptException) {
|
101 | 101 | Scriptable value = (Scriptable) ((JavaScriptException) root)
|
@@ -130,10 +130,10 @@ private LessException parseLessException(Exception root)
|
130 | 130 | }
|
131 | 131 | }
|
132 | 132 | }
|
133 |
| - throw new LessException(message, type, filename, line, column, |
| 133 | + return new LessException(message, type, filename, line, column, |
134 | 134 | extractList);
|
135 | 135 | }
|
136 |
| - throw new LessException(root); |
| 136 | + return root; |
137 | 137 | }
|
138 | 138 |
|
139 | 139 | }
|
0 commit comments