/**
* Test "slow" scopes involving {@code with} and {@code eval} statements for shared script classes with multiple globals.
* @throws ScriptException
* @throws InterruptedException
*/
@Test
public static void testSlowScope() throws ScriptException, InterruptedException {
final ScriptEngineManager m = new ScriptEngineManager();
final ScriptEngine e = m.getEngineByName("nashorn");
for (int i = 0; i < 100; i++) {
final Bindings b = e.createBindings();
final ScriptContext ctxt = new SimpleScriptContext();
ctxt.setBindings(b, ScriptContext.ENGINE_SCOPE);
e.eval(new URLReader(ScopeTest.class.getResource("resources/witheval.js")), ctxt);
assertEquals(e.eval("a", ctxt), 1);
assertEquals(b.get("a"), 1);
assertEquals(e.eval("b", ctxt), 3);
assertEquals(b.get("b"), 3);
assertEquals(e.eval("c", ctxt), 10);
assertEquals(b.get("c"), 10);
}
}
ScopeTest.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:openjdk-jdk10
作者:
评论列表
文章目录