Created
March 24, 2011 01:30
-
-
Save rbackhouse/884396 to your computer and use it in GitHub Desktop.
Example demonstrating calling the commonjs loader via V8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.dojotoolkit.rt.v8.V8JavaBridge; | |
import org.dojotoolkit.server.util.resource.ResourceLoader; | |
public class V8CommonJSLoader extends V8JavaBridge { | |
private ResourceLoader resourceLoader = null; | |
public V8CommonJSLoader(ResourceLoader resourceLoader) { | |
super(true); | |
this.resourceLoader = resourceLoader; | |
} | |
public void run(String program) throws IOException { | |
StringBuffer sb = new StringBuffer(); | |
sb.append("loadJS('/jsutil/commonjs/loader.js');\n"); | |
sb.append("require('"+program+"');\n"); | |
sb.append("result = '{}';\n"); | |
try { | |
runScript(sb.toString()); | |
} catch (Throwable e) { | |
if (compileErrors.size() > 0) { | |
for (Throwable t : compileErrors) { | |
t.printStackTrace(); | |
} | |
} | |
throw new IOException("Exception on compress for ["+sb+"] : "+e.getMessage()); | |
} | |
} | |
public String readResource(String path, boolean useCache) throws IOException { | |
return resourceLoader.readResource(path, useCache); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment