本文整理汇总了Java中org.mozilla.javascript.commonjs.module.Require.install方法的典型用法代码示例。如果您正苦于以下问题:Java Require.install方法的具体用法?Java Require.install怎么用?Java Require.install使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.commonjs.module.Require
的用法示例。
在下文中一共展示了Require.install方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetMainForAlreadyLoadedModule
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
@Override
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");
}
}
示例2: runfile
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public static void runfile(File file,
String filename,
boolean enableRetry,
String retryFile) throws Exception {
Context ctx = Context.enter();
ctx.putThreadLocal("SCRIPT_PATH", file.getAbsoluteFile().getParent());
ScriptableObject scope = ctx.initStandardObjects();
NativeExecutionContext executionContext = initializeNativeExecutionContext(
file,
enableRetry,
retryFile,
ctx);
scope.putConst("context", scope, javaToJS(executionContext, scope));
ctx.setLanguageVersion(VERSION_1_8);
Require require = new RequireBuilder()
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(new NativeModuleSourceProvider()))
.createRequire(ctx, scope);
require.install(scope);
require.requireMain(ctx, filename);
}
示例3: loadModulesFromIncludeDirs
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
private static void loadModulesFromIncludeDirs(Context cx, Scriptable scope, List<File> requireDirList)
{
List<URI> uris = new ArrayList<URI>();
for (File dir : requireDirList) {
URI uri = dir.toURI();
uris.add(uri);
continue;
}
if (uris.isEmpty()) {
return;
}
RequireBuilder rb = new RequireBuilder();
rb.setModuleScriptProvider(new SoftCachingModuleScriptProvider(
new UrlModuleSourceProvider(uris, null)));
Require require = rb.createRequire(cx, scope);
require.install(scope);
return;
}
示例4: installRequire
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public Require installRequire(Context cx, List<String> modulePath,
boolean sandboxed) {
RequireBuilder rb = new RequireBuilder();
rb.setSandboxed(sandboxed);
List<URI> uris = new ArrayList<URI>();
if (modulePath != null) {
for (String path : modulePath) {
try {
URI uri = new URI(path);
if (!uri.isAbsolute()) {
// call resolve("") to canonify the path
uri = new File(path).toURI().resolve("");
}
if (!uri.toString().endsWith("/")) {
// make sure URI always terminates with slash to
// avoid loading from unintended locations
uri = new URI(uri + "/");
}
uris.add(uri);
} catch (URISyntaxException usx) {
throw new RuntimeException(usx);
}
}
}
rb.setModuleScriptProvider(
new SoftCachingModuleScriptProvider(
new UrlModuleSourceProvider(uris, null)));
Require require = rb.createRequire(cx, this);
require.install(this);
return require;
}
示例5: testRelativeId
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的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);
}
示例6: testSetMainForAlreadyLoadedModule
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的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");
}
}
示例7: testRelativeId
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的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.evaluateString(scope, TestUtils.readAsset(dir + File.separator + "testRelativeId.js"),
"testRelativeId.js", 1, null);
}
示例8: testSetMainForAlreadyLoadedModule
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的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.evaluateString(scope, TestUtils.readAsset(dir + File.separator + "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");
}
}
示例9: testRelativeId
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
@Override
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);
}
示例10: testRelativeId
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的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);
}
示例11: testSetMainForAlreadyLoadedModule
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的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");
}
}