Use a supported project, such as Domino:
Domino is based on the work of Mozilla Andreas Gal and seems to be currently supported. Although this did not work out of the box, it was easy to pay. The modifications I made were as follows:
Change files to use AMD style loading instead of CommonJS (so I can load them in Rhino and the browser using RequireJS)
Add xmlns attribute to SVG element when serializing
Modified the CSS parser to workaround a issue in Rhino with case insensitive regular expressions
Added a SVG element type which has a style property like the HTML elements
Added SVG specific CSS properties to the CSS parser
Several bug fixes
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.tools.shell.Global; import com.google.common.base.Charsets; public abstract class RunJS { static final Log LOG = LogFactory.getLog(RunJS.class); static final int JS_VERSION = Context.VERSION_1_8; static final int OPTIMIZATION_LEVEL = 9; private static ScriptableObject ENVIRONMENT = null; static { ENVIRONMENT = createNewEnvironment(); } public static ScriptableObject createNewEnvironment() { Global global = null; Context cx = Context.enter(); try { cx.setOptimizationLevel(OPTIMIZATION_LEVEL); cx.setLanguageVersion(JS_VERSION); global = new Global(); global.setSealedStdLib(true); global.init(cx); Scriptable argsObj = cx.newArray(global, new Object[] {}); global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
References
source share