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


Java Context.exit方法代碼示例

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


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

示例1: decryptSignature

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private String decryptSignature(String encryptedSig, String decryptionCode) throws DecryptException {
    Context context = Context.enter();
    context.setOptimizationLevel(-1);
    Object result;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        throw new DecryptException("could not get decrypt signature", e);
    } finally {
        Context.exit();
    }
    return result == null ? "" : result.toString();
}
 
開發者ID:TeamNewPipe,項目名稱:NewPipeExtractor,代碼行數:17,代碼來源:YoutubeStreamExtractor.java

示例2: parse

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static Scriptable parse(File source, String encoding, Action<Context> contextConfig) {
    Context context = Context.enter();
    if (contextConfig != null) {
        contextConfig.execute(context);
    }

    Scriptable scope = context.initStandardObjects();
    try {
        Reader reader = new InputStreamReader(new FileInputStream(source), encoding);
        try {
            context.evaluateReader(scope, reader, source.getName(), 0, null);
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        Context.exit();
    }

    return scope;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:23,代碼來源:RhinoWorkerUtils.java

示例3: ensureScopePresent

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private void ensureScopePresent()
{
    if (scope == null)
    {
        // Create a scope for the value conversion. This scope will be an empty scope exposing basic Object and Function, sufficient for value-conversion.
        // In case no context is active for the current thread, we can safely enter end exit one to get hold of a scope
        Context ctx = Context.getCurrentContext();
        boolean closeContext = false;
        if (ctx == null)
        {
            ctx = Context.enter();
            closeContext = true;
        }

        scope = ctx.initStandardObjects();
        scope.setParentScope(null);

        if (closeContext)
        {
            // Only an exit call should be done when context didn't exist before
            Context.exit();
        }
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:25,代碼來源:ActivitiScriptNode.java

示例4: setUp

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
    // set up a reference map
    reference = new LinkedHashMap<Object, Object>();
    reference.put("a", "a");
    reference.put("b", Boolean.TRUE);
    reference.put("c", new HashMap<Object, Object>());
    reference.put(new Integer(1), new Integer(42));
    // get a js object as map
    Context context = Context.enter();
    ScriptableObject scope = context.initStandardObjects();
    map = (Map<Object, Object>) context.evaluateString(scope,
            "({ a: 'a', b: true, c: new java.util.HashMap(), 1: 42});",
            "testsrc", 1, null);
    Context.exit();
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:18,代碼來源:Bug448816Test.java

示例5: testCustomContextFactory

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testCustomContextFactory() {
    ContextFactory factory = new MyFactory();
    Context cx = factory.enterContext();
    try {
        Scriptable globalScope = cx.initStandardObjects();
        // Test that FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME is enabled
        /* TODO(stevey): fix this functionality in parser
        Object result = cx.evaluateString(globalScope,
                "var obj = {};" +
                "function obj.foo() { return 'bar'; }" +
                "obj.foo();",
                "test source", 1, null);
        assertEquals("bar", result);
        */
    } catch (RhinoException e) {
        fail(e.toString());
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:21,代碼來源:ContextFactoryTest.java

示例6: setUp

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
    // set up a reference map
    reference = new ArrayList<Object>();
    reference.add("a");
    reference.add(Boolean.TRUE);
    reference.add(new HashMap<Object, Object>());
    reference.add(new Integer(42));
    reference.add("a");
    // get a js object as map
    Context context = Context.enter();
    ScriptableObject scope = context.initStandardObjects();
    list = (List<Object>) context.evaluateString(scope,
            "(['a', true, new java.util.HashMap(), 42, 'a']);",
            "testsrc", 1, null);
    Context.exit();
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,代碼來源:Bug466207Test.java

示例7: testFunctionWithContinuations

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testFunctionWithContinuations() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        cx.evaluateString(globalScope,
                "function f(a) { return myObject.f(a); }",
                "function test source", 1, null);
        Function f = (Function) globalScope.get("f", globalScope);
        Object[] args = { 7 };
        cx.callFunctionWithContinuations(f, globalScope, args);
        fail("Should throw ContinuationPending");
    } catch (ContinuationPending pending) {
        Object applicationState = pending.getApplicationState();
        assertEquals(7, ((Number)applicationState).intValue());
        int saved = (Integer) applicationState;
        Object result = cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
        assertEquals(8, ((Number)result).intValue());
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:22,代碼來源:ContinuationsApiTest.java

示例8: compileScript

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private Script compileScript() {
    String scriptSource = "importPackage(java.util);\n"
            + "var searchmon = 3;\n"
            + "var searchday = 10;\n"
            + "var searchyear = 2008;\n"
            + "var searchwkday = 0;\n"
            + "\n"
            + "var myDate = Calendar.getInstance();\n // this is a java.util.Calendar"
            + "myDate.set(Calendar.MONTH, searchmon);\n"
            + "myDate.set(Calendar.DATE, searchday);\n"
            + "myDate.set(Calendar.YEAR, searchyear);\n"
            + "searchwkday.value = myDate.get(Calendar.DAY_OF_WEEK);";
    Script script;
    Context context = factory.enterContext();
    try {
        script = context.compileString(scriptSource, "testScript", 1, null);
        return script;
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:22,代碼來源:Bug421071Test.java

示例9: testSetNullForScriptableSetter

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testSetNullForScriptableSetter() throws Exception {
	
	final String scriptCode = "foo.myProp = new Foo2();\n"
		+ "foo.myProp = null;";

	final ContextFactory factory = new ContextFactory();
	final Context cx = factory.enterContext();

	try {
        final ScriptableObject topScope = cx.initStandardObjects();
        final Foo foo = new Foo();

        // define custom setter method
        final Method setMyPropMethod = Foo.class.getMethod("setMyProp", Foo2.class);
        foo.defineProperty("myProp", null, null, setMyPropMethod, ScriptableObject.EMPTY);

        topScope.put("foo", topScope, foo);
        
        ScriptableObject.defineClass(topScope, Foo2.class);
		
        cx.evaluateString(topScope, scriptCode, "myScript", 1, null);
	}
	finally {
		Context.exit();
	}
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:27,代碼來源:CustomSetterAcceptNullScriptableTest.java

示例10: testErrorOnEvalCall

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * Since a continuation can only capture JavaScript frames and not Java
 * frames, ensure that Rhino throws an exception when the JavaScript frames
 * don't reach all the way to the code called by
 * executeScriptWithContinuations or callFunctionWithContinuations.
 */
public void testErrorOnEvalCall() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        Script script = cx.compileString("eval('myObject.f(3);');",
                "test source", 1, null);
        cx.executeScriptWithContinuations(script, globalScope);
        fail("Should throw IllegalStateException");
    } catch (WrappedException we) {
        Throwable t = we.getWrappedException();
        assertTrue(t instanceof IllegalStateException);
        assertTrue(t.getMessage().startsWith("Cannot capture continuation"));
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:23,代碼來源:ContinuationsApiTest.java

示例11: helper

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void helper(String source) {
    Context cx = Context.enter();
    Context.ClassShutterSetter setter = cx.getClassShutterSetter();
    try {
        Scriptable globalScope = cx.initStandardObjects();
        if (setter == null) {
            setter = classShutterSetter;
        } else {
            classShutterSetter = setter;
        }
        setter.setClassShutter(new OpaqueShutter());
        cx.evaluateString(globalScope, source, "test source", 1, null);
    } finally {
        setter.setClassShutter(null);
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:18,代碼來源:ClassShutterExceptionTest.java

示例12: setUp

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Override
public void setUp() {
    Context cx = Context.enter();
    try {
        globalScope = cx.initStandardObjects();
        cx.setOptimizationLevel(-1); // must use interpreter mode
        globalScope.put("myObject", globalScope,
                Context.javaToJS(new MyClass(), globalScope));
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:13,代碼來源:ContinuationsApiTest.java

示例13: parseRhino

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static <T> T parseRhino(File rhinoScript, ScopeOperation<T> operation) {
    Context context = Context.enter();
    try {
        operation.initContext(context);
        Scriptable scope = context.initStandardObjects();
        String printFunction = "function print(message) {}";
        context.evaluateString(scope, printFunction, "print", 1, null);
        context.evaluateString(scope, readFile(rhinoScript, "UTF-8"), rhinoScript.getName(), 1, null);
        return operation.action(scope, context);
    } finally {
        Context.exit();
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,代碼來源:RhinoWorkerUtils.java

示例14: testOverloadedVarargs

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testOverloadedVarargs() {
    Context cx = ContextFactory.getGlobal().enterContext();
    try {
        Scriptable scope = cx.initStandardObjects();
        Object result = unwrap(cx.evaluateString(scope,
                "java.lang.reflect.Array.newInstance(java.lang.Object, 1)",
                "source", 1, null));
        assertTrue(result instanceof Object[]);
        assertEquals(1, ((Object[]) result).length);
        result = unwrap(cx.evaluateString(scope,
                "java.lang.reflect.Array.newInstance(java.lang.Object, [1])",
                "source", 1, null));
        assertTrue(result instanceof Object[]);
        assertEquals(1, ((Object[]) result).length);
        result = unwrap(cx.evaluateString(scope,
                "java.lang.reflect.Array.newInstance(java.lang.Object, [1, 1])",
                "source", 1, null));
        assertTrue(result instanceof Object[][]);
        assertEquals(1, ((Object[][]) result).length);
        assertEquals(1, ((Object[][]) result)[0].length);
        result = unwrap(cx.evaluateString(scope,
                "java.lang.reflect.Array.newInstance(java.lang.Object, 1, 1)",
                "source", 1, null));
        assertTrue(result instanceof Object[][]);
        assertEquals(1, ((Object[][]) result).length);
        assertEquals(1, ((Object[][]) result)[0].length);
    } finally {
        Context.exit();
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:31,代碼來源:Bug467396Test.java

示例15: afterPropertiesSet

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * Pre initializes two scope objects (one secure and one not) with the standard objects preinitialised.
 * This saves on very expensive calls to reinitialize a new scope on every web script execution. See
 * http://www.mozilla.org/rhino/scopes.html
 * 
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */
public void afterPropertiesSet() throws Exception
{
    // Initialize the secure scope
    Context cx = Context.enter();
    try
    {
        cx.setWrapFactory(wrapFactory);
        this.secureScope = initScope(cx, false, true);
    }
    finally
    {
        Context.exit();
    }
    
    // Initialize the non-secure scope
    cx = Context.enter();
    try
    {
        cx.setWrapFactory(wrapFactory);
        this.nonSecureScope = initScope(cx, true, true);
    }
    finally
    {
        Context.exit();
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:34,代碼來源:RhinoScriptProcessor.java


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