當前位置: 首頁>>代碼示例>>Java>>正文


Java Script.exec方法代碼示例

本文整理匯總了Java中org.mozilla.javascript.Script.exec方法的典型用法代碼示例。如果您正苦於以下問題:Java Script.exec方法的具體用法?Java Script.exec怎麽用?Java Script.exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mozilla.javascript.Script的用法示例。


在下文中一共展示了Script.exec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: evalInlineScript

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
static void evalInlineScript(Context cx, String scriptText) {
    try {
        Script script = cx.compileString(scriptText, "<command>", 1, null);
        if (script != null) {
            script.exec(cx, getShellScope());
        }
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
                cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
                "msg.uncaughtJSException", ex.toString());
        Context.reportError(msg);
        exitCode = EXITCODE_RUNTIME_ERROR;
    }
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:20,代碼來源:Main.java

示例2: evaluateScript

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public static Object evaluateScript(Script script, Context cx,
                                    Scriptable scope)
{
    try {
        return script.exec(cx, scope);
    } catch (RhinoException rex) {
        ToolErrorReporter.reportException(
            cx.getErrorReporter(), rex);
        exitCode = EXITCODE_RUNTIME_ERROR;
    } catch (VirtualMachineError ex) {
        // Treat StackOverflow and OutOfMemory as runtime errors
        ex.printStackTrace();
        String msg = ToolErrorReporter.getMessage(
            "msg.uncaughtJSException", ex.toString());
        exitCode = EXITCODE_RUNTIME_ERROR;
        Context.reportError(msg);
    }
    return Context.getUndefinedValue();
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:20,代碼來源:Main.java

示例3: testJsApi

import org.mozilla.javascript.Script; //導入方法依賴的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 });
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,代碼來源:Bug482203.java

示例4: testJsApi

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public void testJsApi() throws Exception {
    Context cx = RhinoAndroidHelper.prepareContext();
    try {
        cx.setOptimizationLevel(-1);
        Script script = cx.compileString(TestUtils.readAsset("Bug482203.js"),
                "", 1, null);
        Scriptable scope = cx.initStandardObjects();
        script.exec(cx, scope);
        int counter = 0;
        for(;;)
        {
            Object cont = ScriptableObject.getProperty(scope, "c");
            if(cont == null)
            {
                break;
            }
            counter++;
            ((Callable)cont).call(cx, scope, scope, new Object[] { null });
        }
        assertEquals(counter, 5);
        assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
    } finally {
        Context.exit();
    }
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:26,代碼來源:Bug482203Test.java

示例5: evaluateExpression

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public Object evaluateExpression(Script expression)
{
	ensureContext();
	
	Object value = expression.exec(context, scope);
	
	Object javaValue;
	// not converting Number objects because the generic conversion call below
	// always converts to Double
	if (value == null || value instanceof Number)
	{
		javaValue = value;
	}
	else
	{
		try
		{
			javaValue = Context.jsToJava(value, Object.class);
		}
		catch (EvaluatorException e)
		{
			throw new JRRuntimeException(e);
		}
	}
	return javaValue;
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:27,代碼來源:JavaScriptEvaluatorScope.java

示例6: evaluate

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating JavaScript expression: {1}", expression);
    try {
        final Context ctx = ContextFactory.getGlobal().enterContext();
        Script script = scriptCache.get(expression);
        if (script == null) {
            ctx.setOptimizationLevel(9);
            script = ctx.compileString(expression, "<cmd>", 1, null);
            scriptCache.put(expression, script);
        }
        final Scriptable scope = ctx.newObject(parentScope);
        scope.setPrototype(parentScope);
        scope.setParentScope(null);
        for (final Entry<String, ?> entry : values.entrySet()) {
            scope.put(entry.getKey(), scope, Context.javaToJS(entry.getValue(), scope));
        }
        return script.exec(ctx, scope);
    } catch (final EvaluatorException ex) {
        throw new ExpressionEvaluationException("Evaluating JavaScript expression failed: " + expression, ex);
    } finally {
        Context.exit();
    }
}
 
開發者ID:sebthom,項目名稱:oval,代碼行數:24,代碼來源:ExpressionLanguageJavaScriptImpl.java

示例7: testJsApi

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public void testJsApi() throws Exception {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1);
        Script script = cx.compileReader(new InputStreamReader(
                Bug482203Test.class.getResourceAsStream("Bug482203.js")),
                "", 1, null);
        Scriptable scope = cx.initStandardObjects();
        script.exec(cx, scope);
        int counter = 0;
        for(;;)
        {
            Object cont = ScriptableObject.getProperty(scope, "c");
            if(cont == null)
            {
                break;
            }
            counter++;
            ((Callable)cont).call(cx, scope, scope, new Object[] { null });
        }
        assertEquals(counter, 5);
        assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
    } finally {
        Context.exit();
    }
}
 
開發者ID:CyboticCatfish,項目名稱:code404,代碼行數:27,代碼來源:Bug482203Test.java

示例8: execute

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public void execute( ExecutionContext executionContext ) throws ParsingException, ExecutionException
{
	Context context = adapter.enterContext( executionContext );
	try
	{
		ScriptableObject scope = adapter.getScope( executable, executionContext, context, startLineNumber );
		Script script = this.script;
		if( script != null )
			script.exec( context, scope );
		else
			context.evaluateString( scope, sourceCode, executable.getDocumentName(), startLineNumber, null );
	}
	catch( Exception x )
	{
		throw RhinoAdapter.createExecutionException( executable, x );
	}
	finally
	{
		Context.exit();
	}
}
 
開發者ID:tliron,項目名稱:scripturian,代碼行數:22,代碼來源:RhinoProgram.java

示例9: processFileSecure

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
static void processFileSecure(Context cx, Scriptable scope,
                              String path, Object securityDomain)
        throws IOException {

    boolean isClass = path.endsWith(".class");
    Object source = readFileOrUrl(path, !isClass);

    byte[] digest = getDigest(source);
    String key = path + "_" + cx.getOptimizationLevel();
    ScriptReference ref = scriptCache.get(key, digest);
    Script script = ref != null ? ref.get() : null;

    if (script == null) {
        if (isClass) {
            script = loadCompiledScript(cx, path, (byte[]) source, securityDomain);
        } else {
            String strSrc = (String) source;
            // Support the executable script #! syntax:  If
            // the first line begins with a '#', treat the whole
            // line as a comment.
            if (strSrc.length() > 0 && strSrc.charAt(0) == '#') {
                for (int i = 1; i != strSrc.length(); ++i) {
                    int c = strSrc.charAt(i);
                    if (c == '\n' || c == '\r') {
                        strSrc = strSrc.substring(i);
                        break;
                    }
                }
            }
            script = cx.compileString(strSrc, path, 1, securityDomain);
        }
        scriptCache.put(key, digest, script);
    }

    if (script != null) {
        script.exec(cx, scope);
    }
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:39,代碼來源:Main.java

示例10: jsFunction_include

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public void jsFunction_include(final Scriptable scope, String scriptName) throws Exception {
    final Context cx = Context.getCurrentContext();
    if (scriptName.charAt(0) != '/') {
        // relative script name -- resolve it against currently executing
        // script's directory
        String pathPrefix = currentScriptDirectory;
        while (scriptName.startsWith("../")) {
            final int lastSlash = pathPrefix.lastIndexOf('/');
            if (lastSlash == -1) {
                throw new FileNotFoundException("script:" + currentScriptDirectory + '/' + scriptName);
            }
            scriptName = scriptName.substring(3);
            pathPrefix = pathPrefix.substring(0, lastSlash);
        }
        scriptName = pathPrefix + '/' + scriptName;
    } else {
        // strip off leading slash
        scriptName = scriptName.substring(1);
    }
    final Script script = scriptStorage.getScript(scriptName);
    if (script == null) {
        throw new FileNotFoundException("script:" + scriptName);
    }
    try {
        final String oldScriptDirectory = currentScriptDirectory;
        currentScriptDirectory = getDirectoryForScript(scriptName);
        try {
            script.exec(cx, scope);
        } finally {
            currentScriptDirectory = oldScriptDirectory;
        }
    } finally {
    }
}
 
開發者ID:szegedi,項目名稱:spring-web-jsflow,代碼行數:35,代碼來源:HostObject.java

示例11: executeOptionalScript

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
private static void executeOptionalScript(Script script, Context cx,
        Scriptable executionScope)
{
    if(script != null) {
        script.exec(cx, executionScope);
    }
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:8,代碼來源:Require.java

示例12: executeOptionalScript

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
private static void executeOptionalScript(Script script, Context cx, 
        Scriptable executionScope)
{
    if(script != null) {
        script.exec(cx, executionScope);
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:8,代碼來源:Require.java

示例13: doTest

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public void doTest(final String scriptCode) throws Exception {
	final Context cx = ContextFactory.getGlobal().enterContext();
	try {
           Scriptable topScope = cx.initStandardObjects();
   		topScope.put("javaNameGetter", topScope, new JavaNameGetter());
   		Script script = cx.compileString(scriptCode, "myScript", 1, null);
   		script.exec(cx, topScope);
	} finally {
	    Context.exit();
	}
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:12,代碼來源:GeneratedMethodNameTest.java

示例14: runBenchmark

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
private void runBenchmark(String name, int iterations)
{
    Script s = scripts.get(name);
    for (int i = 0; i < iterations; i++) {
        s.exec(cx, scope);
    }
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:8,代碼來源:CaliperSpiderBenchmark.java

示例15: testThrowing

import org.mozilla.javascript.Script; //導入方法依賴的package包/類
public void testThrowing() throws Exception {
    cx = RhinoAndroidHelper.prepareContext();
    try {
        Script script = cx.compileString(TestUtils.readAsset("Issue176.js"),
                "Issue176.js", 1, null);
        scope = cx.initStandardObjects();
        scope.put("host", scope, this);
        script.exec(cx, scope); // calls our methods
    } finally {
        Context.exit();
    }
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:13,代碼來源:Issue176Test.java


注:本文中的org.mozilla.javascript.Script.exec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。