本文整理匯總了Java中org.mozilla.javascript.Context.compileReader方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.compileReader方法的具體用法?Java Context.compileReader怎麽用?Java Context.compileReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.compileReader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testJsApi
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testJsApi() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
((Callable)cont).call(cx, scope, scope, new Object[] { null });
}
}
示例2: testJavaApi
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testJavaApi() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(
Bug482203.class.getResourceAsStream("conttest.js")),
"", 1, null);
Scriptable scope = cx.initStandardObjects();
cx.executeScriptWithContinuations(script, scope);
for(;;)
{
Object cont = ScriptableObject.getProperty(scope, "c");
if(cont == null)
{
break;
}
cx.resumeContinuation(cont, scope, null);
}
} finally {
Context.exit();
}
}
示例3: getModuleScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public ModuleScript getModuleScript(Context cx, String moduleId,
URI moduleUri, URI baseUri, Scriptable paths) throws Exception
{
final CachedModuleScript cachedModule1 = getLoadedModule(moduleId);
final Object validator1 = getValidator(cachedModule1);
final ModuleSource moduleSource = (moduleUri == null)
? moduleSourceProvider.loadSource(moduleId, paths, validator1)
: moduleSourceProvider.loadSource(moduleUri, baseUri, validator1);
if(moduleSource == ModuleSourceProvider.NOT_MODIFIED) {
return cachedModule1.getModule();
}
if(moduleSource == null) {
return null;
}
final Reader reader = moduleSource.getReader();
try {
final int idHash = moduleId.hashCode();
synchronized(loadLocks[(idHash >>> loadLockShift) & loadLockMask]) {
final CachedModuleScript cachedModule2 = getLoadedModule(moduleId);
if(cachedModule2 != null) {
if(!equal(validator1, getValidator(cachedModule2))) {
return cachedModule2.getModule();
}
}
final URI sourceUri = moduleSource.getUri();
final ModuleScript moduleScript = new ModuleScript(
cx.compileReader(reader, sourceUri.toString(), 1,
moduleSource.getSecurityDomain()),
sourceUri, moduleSource.getBase());
putLoadedModule(moduleId, moduleScript,
moduleSource.getValidator());
return moduleScript;
}
}
finally {
reader.close();
}
}
示例4: getModuleScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public ModuleScript getModuleScript(Context cx, String moduleId,
URI moduleUri, Scriptable paths) throws Exception
{
final CachedModuleScript cachedModule1 = getLoadedModule(moduleId);
final Object validator1 = getValidator(cachedModule1);
final ModuleSource moduleSource = (moduleUri == null)
? moduleSourceProvider.loadSource(moduleId, paths, validator1)
: moduleSourceProvider.loadSource(moduleUri, validator1);
if(moduleSource == ModuleSourceProvider.NOT_MODIFIED) {
return cachedModule1.getModule();
}
if(moduleSource == null) {
return null;
}
final Reader reader = moduleSource.getReader();
try {
final int idHash = moduleId.hashCode();
synchronized(loadLocks[(idHash >>> loadLockShift) & loadLockMask]) {
final CachedModuleScript cachedModule2 = getLoadedModule(moduleId);
if(cachedModule2 != null) {
if(!equal(validator1, getValidator(cachedModule2))) {
return cachedModule2.getModule();
}
}
final URI sourceUri = moduleSource.getUri();
final ModuleScript moduleScript = new ModuleScript(
cx.compileReader(reader, sourceUri.toString(), 1,
moduleSource.getSecurityDomain()),
sourceUri, moduleSource.getBase());
putLoadedModule(moduleId, moduleScript,
moduleSource.getValidator());
return moduleScript;
}
}
finally {
reader.close();
}
}