本文整理汇总了Java中org.mozilla.javascript.commonjs.module.Require.requireMain方法的典型用法代码示例。如果您正苦于以下问题:Java Require.requireMain方法的具体用法?Java Require.requireMain怎么用?Java Require.requireMain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.commonjs.module.Require
的用法示例。
在下文中一共展示了Require.requireMain方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSandboxed
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public void testSandboxed() throws Exception
{
final Context cx = createContext();
final Require require = getSandboxedRequire(cx);
require.requireMain(cx, "testSandboxed");
// Also, test idempotent double-require of same main:
require.requireMain(cx, "testSandboxed");
// Also, test failed require of different main:
try {
require.requireMain(cx, "blah");
fail();
}
catch(IllegalStateException e) {
// Expected, success
}
}
示例2: testSandboxed
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
@Override
public void testSandboxed() throws Exception
{
final Context cx = createContext();
final Require require = getSandboxedRequire(cx);
require.requireMain(cx, "testSandboxed");
// Also, test idempotent double-require of same main:
require.requireMain(cx, "testSandboxed");
// Also, test failed require of different main:
try {
require.requireMain(cx, "blah");
fail();
}
catch(IllegalStateException e) {
// Expected, success
}
}
示例3: 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");
}
}
示例4: 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);
}
示例5: init
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public void init() throws URISyntaxException {
ctx = Context.enter();
try {
RequireBuilder builder = new RequireBuilder();
builder.setModuleScriptProvider(new SoftCachingModuleScriptProvider(
new UrlModuleSourceProvider(buildModulePaths(), null)));
topLevelScope = ctx.initStandardObjects();
builder.setSandboxed(false); // allows this to load scripts
Require require = builder.createRequire(ctx, topLevelScope);
exports = require.requireMain(ctx, jsxTransformerJS);
transform = (Function) exports.get("transform", topLevelScope);
} finally {
Context.exit();
}
}
示例6: testNonSandboxed
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public void testNonSandboxed() throws Exception
{
final Context cx = createContext();
final Scriptable scope = cx.initStandardObjects();
final Require require = getSandboxedRequire(cx, scope, false);
final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm();
ScriptableObject.putProperty(scope, "moduleUri", jsFile);
require.requireMain(cx, "testNonSandboxed");
}
示例7: 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");
}
}
示例8: testSandboxed
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public void testSandboxed() throws Exception {
final Context cx = createContext();
final Require require = getSandboxedRequire(cx);
require.requireMain(cx, "testSandboxed");
// Also, test idempotent double-require of same main:
require.requireMain(cx, "testSandboxed");
// Also, test failed require of different main:
try {
require.requireMain(cx, "blah");
fail();
} catch (IllegalStateException e) {
// Expected, success
}
}
示例9: testNonSandboxed
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
public void testNonSandboxed() throws Exception {
final Context cx = createContext();
final Scriptable scope = cx.initStandardObjects();
final Require require = getSandboxedRequire(cx, scope, false);
final String jsFile = TestUtils.readAsset(dir + File.separator + "testNonSandboxed.js");
ScriptableObject.putProperty(scope, "moduleUri", jsFile);
require.requireMain(cx, "testNonSandboxed");
}
示例10: 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");
}
}
示例11: testNonSandboxed
import org.mozilla.javascript.commonjs.module.Require; //导入方法依赖的package包/类
@Override
public void testNonSandboxed() throws Exception
{
final Context cx = createContext();
final Scriptable scope = cx.initStandardObjects();
final Require require = getSandboxedRequire(cx, scope, false);
final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm();
ScriptableObject.putProperty(scope, "moduleUri", jsFile);
require.requireMain(cx, "testNonSandboxed");
}
示例12: 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");
}
}