use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class DecompileTest method newObject0Arg.
/**
* As of head of trunk on 30.09.09, decompile of "new Date()" returns "new Date" without parentheses.
* @see <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=519692">Bug 519692</a>
*/
@Test
public void newObject0Arg() {
final String source = "var x = new Date().getTime();";
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
final Script script = cx.compileString(source, "my script", 0, null);
Assert.assertEquals(source, cx.decompileScript(script, 4).trim());
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of org.mozilla.javascript.Context in project cucumber-jvm by cucumber.
the class HTMLFormatterTest method writes_valid_report_js.
@Test
public void writes_valid_report_js() throws IOException {
URL reportJs = new URL(outputDir, "report.js");
Context cx = Context.enter();
Global scope = new Global(cx);
try {
cx.evaluateReader(scope, new InputStreamReader(reportJs.openStream(), "UTF-8"), reportJs.getFile(), 1, null);
fail("Should have failed");
} catch (EcmaError expected) {
assertTrue(expected.getMessage().startsWith("ReferenceError: \"document\" is not defined."));
}
}
use of org.mozilla.javascript.Context in project OpenAM by OpenRock.
the class RhinoScriptEngine method eval.
/**
* {@inheritDoc}
*/
@Override
public Object eval(final Reader reader, final ScriptContext scriptContext) throws ScriptException {
Reject.ifNull(reader, scriptContext);
Object result = null;
final Context context = factory.getContext();
try {
final Scriptable scope = getScope(context, scriptContext);
final String filename = getFilename(scriptContext);
result = context.evaluateReader(scope, reader, filename, 1, null);
} catch (RhinoException ex) {
throw convertException(ex);
} catch (IOException ex) {
throw new ScriptException(ex);
} finally {
factory.releaseContext(context);
}
return result;
}
use of org.mozilla.javascript.Context in project OpenAM by OpenRock.
the class RhinoScriptEngine method evalCompiled.
/**
* Evaluates a pre-compiled script against this script engine. This should only be called by
* {@link org.forgerock.openam.scripting.factories.RhinoCompiledScript#eval(javax.script.ScriptContext)}.
*
* @param compiledScript The compiled script. Must not be null.
* @param scriptContext The JSR 223 script context. Must not be null.
* @return the result of evaluating the compiled script.
* @throws ScriptException if an error occurs during script execution.
*/
Object evalCompiled(final Script compiledScript, final ScriptContext scriptContext) throws ScriptException {
Reject.ifNull(compiledScript, scriptContext);
Object result = null;
final Context context = factory.getContext();
try {
final Scriptable scope = getScope(context, scriptContext);
result = compiledScript.exec(context, scope);
} catch (RhinoException ex) {
throw convertException(ex);
} finally {
factory.releaseContext(context);
}
return result;
}
use of org.mozilla.javascript.Context in project sling by apache.
the class RhinoJavaScriptEngineFactory method activate.
// ---------- SCR integration
@Activate
protected void activate(final ComponentContext context, final RhinoJavaScriptEngineFactoryConfiguration configuration) {
Dictionary<?, ?> props = context.getProperties();
boolean debugging = getProperty("org.apache.sling.scripting.javascript.debug", props, context.getBundleContext(), false);
optimizationLevel = readOptimizationLevel(configuration);
// setup the wrap factory
wrapFactory = new SlingWrapFactory();
// initialize the Rhino Context Factory
SlingContextFactory.setup(this);
Context cx = Context.enter();
setEngineName(getEngineName() + " (" + cx.getImplementationVersion() + ")");
languageVersion = String.valueOf(cx.getLanguageVersion());
Context.exit();
setExtensions(ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
setMimeTypes("text/javascript", "application/ecmascript", "application/javascript");
setNames("javascript", ECMA_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
final ContextFactory contextFactory = ContextFactory.getGlobal();
if (contextFactory instanceof SlingContextFactory) {
((SlingContextFactory) contextFactory).setDebugging(debugging);
}
// set the dynamic class loader as the application class loader
final DynamicClassLoaderManager dclm = this.dynamicClassLoaderManager;
if (dclm != null) {
contextFactory.initApplicationClassLoader(dynamicClassLoaderManager.getDynamicClassLoader());
}
log.info("Activated with optimization level {}", optimizationLevel);
}
Aggregations