本文整理汇总了Java中org.mozilla.javascript.commonjs.module.RequireBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RequireBuilder类的具体用法?Java RequireBuilder怎么用?Java RequireBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequireBuilder类属于org.mozilla.javascript.commonjs.module包,在下文中一共展示了RequireBuilder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runfile
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的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);
}
示例2: loadModulesFromIncludeDirs
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的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;
}
示例3: init
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的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();
}
}
示例4: initRequireBuilder
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的package包/类
void initRequireBuilder(Context context, Scriptable scope) {
List<URI> list = new ArrayList<>();
for (String path : mRequirePath) {
list.add(new File(path).toURI());
}
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(mAndroidContext, list);
new RequireBuilder()
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(provider))
.setSandboxed(true)
.createRequire(context, scope)
.install(scope);
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:13,代码来源:RhinoJavaScriptEngine.java
示例5: initRequireBuilder
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的package包/类
void initRequireBuilder(Context context, Scriptable scope) {
List<URI> list = new ArrayList<>();
for (String path : mRequirePath) {
list.add(new File(path).toURI());
}
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(mAndroidContext, list);
new RequireBuilder()
.setModuleScriptProvider(new SoftCachingModuleScriptProvider(provider))
.setSandboxed(false)
.createRequire(context, scope)
.install(scope);
}
示例6: installRequire
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的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;
}
示例7: executeInternal
import org.mozilla.javascript.commonjs.module.RequireBuilder; //导入依赖的package包/类
private Object executeInternal(final String script, final String scriptName, final ScriptContext context,
final boolean function, final Class<?> expectedResultClass) throws ScriptException
{
// never ever execute an empty script, it's just a waste of time
if( !Check.isEmpty(script) )
{
// In most cases apart from calls from birt, we can expect that
// there'll be no current context, thus one will be generated by
// this call into the ContextFactory
return ContextFactory.getGlobal().call(new ContextAction()
{
@Override
public Object run(Context cx)
{
Logger errorLogger = context.getLogger();
if( errorLogger == null )
{
errorLogger = logger;
}
Scriptable userScriptScope = ((DefaultScriptContext) context).getUserScriptScope(cx);
ScriptableModuleSourceProvider sourceProvider = new ScriptableModuleSourceProvider(userScriptScope);
ModuleScriptProvider scriptProvider = new SoftCachingModuleScriptProvider(sourceProvider);
cx.initStandardObjects();
Scriptable scope = ((DefaultScriptContext) context).getScope(cx);
RequireBuilder builder = new RequireBuilder();
// The "uri" property must not exist in a sandbox
builder.setSandboxed(false);
builder.setModuleScriptProvider(scriptProvider);
Require require = builder.createRequire(cx, scope);
cx.setOptimizationLevel(-1);
cx.setErrorReporter(new ScriptErrorReporter(errorLogger));
final String execScript = (function ? "function runScript() {\n" + script + "\n}\n runScript();"
: script);
final String execScriptName = (scriptName != null ? scriptName : "script");
try
{
context.scriptEnter();
require.install(scope);
Object result = cx.evaluateString(scope, execScript, execScriptName, 1, null);
context.scriptExit();
if( expectedResultClass == String.class )
{
return result.toString();
}
return result;
}
catch( JavaScriptException js )
{
throw new ScriptException(js);
}
catch( EcmaError ec )
{
throw new ScriptException(ec);
}
catch( EvaluatorException ev )
{
throw new ScriptException(ev);
}
}
});
}
return Boolean.TRUE;
}