本文整理匯總了Java中org.mozilla.javascript.Context.evaluateReader方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.evaluateReader方法的具體用法?Java Context.evaluateReader怎麽用?Java Context.evaluateReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.evaluateReader方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static Scriptable parse(File source, String encoding, Action<Context> contextConfig) {
Context context = Context.enter();
if (contextConfig != null) {
contextConfig.execute(context);
}
Scriptable scope = context.initStandardObjects();
try {
Reader reader = new InputStreamReader(new FileInputStream(source), encoding);
try {
context.evaluateReader(scope, reader, source.getName(), 0, null);
} finally {
reader.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
Context.exit();
}
return scope;
}
示例2: testSetMainForAlreadyLoadedModule
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testSetMainForAlreadyLoadedModule() throws Exception {
final Context cx = createContext();
final Scriptable scope = cx.initStandardObjects();
final Require require = getSandboxedRequire(cx, scope, false);
require.install(scope);
cx.evaluateReader(scope, getReader("testSetMainForAlreadyLoadedModule.js"),
"testSetMainForAlreadyLoadedModule.js", 1, null);
try {
require.requireMain(cx, "assert");
fail();
}
catch(IllegalStateException e) {
assertEquals(e.getMessage(), "Attempt to set main module after it was loaded");
}
}
示例3: testRelativeId
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testRelativeId() throws Exception {
final Context cx = createContext();
final Scriptable scope = cx.initStandardObjects();
final Require require = getSandboxedRequire(cx, scope, false);
require.install(scope);
cx.evaluateReader(scope, getReader("testRelativeId.js"),
"testRelativeId.js", 1, null);
}