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


Java Context.evaluateString方法代碼示例

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


在下文中一共展示了Context.evaluateString方法的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: start

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void start() {
	try {
		Context ctx = Context.enter();
		scope = ctx.initStandardObjects();
		scope.put("pacMethods", scope, new PacScriptMethods());
		ctx.evaluateString(scope, getScriptContent(), "pac", 0, null);
		for (PacScriptMethods.jsFunctions function : PacScriptMethods.jsFunctions.values()) {
			ctx.evaluateString(scope,
					"function " + function.name() + " () {" + "return pacMethods." + function.name() + ".apply(pacMethods, arguments); }",
					function.name(), 0, null);
		}
	} catch (IOException e) {
		Engine.logProxyManager.error("(PacManager) Failed to declare PacScriptMethods wrapper", e);
	} finally {
		Context.exit();	
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:18,代碼來源:PacManager.java

示例3: 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

示例4: runWithExpectedStackTrace

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private void runWithExpectedStackTrace(final String _source, final String _expectedStackTrace)
{
       final ContextAction action = new ContextAction() {
       	public Object run(Context cx) {
       		final Scriptable scope = cx.initStandardObjects();
       		try {
       			cx.evaluateString(scope, _source, "test.js", 0, null);
       		}
       		catch (final JavaScriptException e)
       		{
       			assertEquals(_expectedStackTrace, e.getScriptStackTrace());
       			return null;
       		}
       		throw new RuntimeException("Exception expected!");
       	}
       };
       Utils.runWithOptimizationLevel(action, -1);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,代碼來源:StackTraceTest.java

示例5: 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

示例6: 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

示例7: testWithTwoScopes

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private void testWithTwoScopes(final String scriptScope1,
                               final String scriptScope2)
{
	final ContextAction action = new ContextAction()
	{
		public Object run(final Context cx)
		{
	        final Scriptable scope1 = cx.initStandardObjects(
	            new MySimpleScriptableObject("scope1"));
	        final Scriptable scope2 = cx.initStandardObjects(
	            new MySimpleScriptableObject("scope2"));
	        cx.evaluateString(scope2, scriptScope2, "source2", 1, null);

	        scope1.put("scope2", scope1, scope2);

	        return cx.evaluateString(scope1, scriptScope1, "source1", 1,
	                                 null);
		}
	};
	Utils.runWithAllOptimizationLevels(action);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:22,代碼來源:PrimitiveTypeScopeResolutionTest.java

示例8: decipherKey

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * After finding the decrypted code in the js html5 player code
 * run the code passing the encryptedSig parameter
 *
 * @param encryptedSig
 * @param html5player
 * @return
 * @throws Exception
 */
private static String decipherKey(String encryptedSig, String html5player)
        throws Exception {
    String decipherFunc = loadFunction(html5player);
    Context context = Context.enter();
    // Rhino interpreted mode
    context.setOptimizationLevel(-1);
    Object result = null;
    try {
        ScriptableObject scope = context.initStandardObjects();
        context.evaluateString(scope, decipherFunc, "decipherFunc", 1, null);
        Function decryptionFunc = (Function) scope.get("decrypt", scope);
        result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        Context.exit();
    }
    if (result == null) {
        return "";
    } else {
        return result.toString();
    }
}
 
開發者ID:89luca89,項目名稱:ThunderMusic,代碼行數:33,代碼來源:YoutubeLinkRetriever.java

示例9: 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

示例10: testIt

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void testIt()
{
	final String script = "var fn = function() { return this; }\n"
		+ "fn.apply(1)";

	final ContextAction action = new ContextAction()
	{
		public Object run(final Context _cx)
		{
			final ScriptableObject scope = _cx.initStandardObjects();
			final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
			assertEquals("object", ScriptRuntime.typeof(result));
			assertEquals("1", Context.toString(result));
			return null;
		}
	};
	Utils.runWithAllOptimizationLevels(action);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,代碼來源:ApplyOnPrimitiveNumberTest.java

示例11: test0

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * ECMA 11.4.3 says that typeof on host object is Implementation-dependent
 */
public void test0() throws Exception
{
       final Function f = new BaseFunction()
       {
       	@Override
       	public Object call(Context _cx, Scriptable _scope, Scriptable _thisObj,
       			Object[] _args)
       	{
       		return _args[0].getClass().getName();
       	}
       };
	final ContextAction action = new ContextAction()
	{
		public Object run(final Context context)
		{
			final Scriptable scope = context.initStandardObjects();
			scope.put("myObj", scope, f);
			return context.evaluateString(scope, "typeof myObj", "test script", 1, null);
		}
	};
	doTest("function", action);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:26,代碼來源:TypeOfTest.java

示例12: testAttributeName

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Test
public void testAttributeName() {
    Context context = Context.enter();
    Scriptable scriptable = context.initStandardObjects();
    context.setOptimizationLevel(-1);
    Object o = context.evaluateString(scriptable, "XML.ignoreProcessingInstructions = true; (<xml id=\"foo\"></xml>).attributes()[0].name()", "<e4x>", 1, null);
    System.out.println(o);
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:9,代碼來源:RhinoE4XTest.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: assertEvaluates

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private void assertEvaluates(final Object expected, final String source) {
    final ContextAction action = new ContextAction() {
        public Object run(Context cx) {
            final Scriptable scope = cx.initStandardObjects();
            final Object rep = cx.evaluateString(scope, source, "test.js",
                    0, null);
            assertEquals(expected, rep);
            return null;
        }
    };
    Utils.runWithAllOptimizationLevels(action);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:13,代碼來源:GlobalParseXTest.java

示例15: functionObjectPrimitiveToObject

import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
 * Test that FunctionObject use the right top scope to convert a primitive 
 * to an object
 */
@Test
public void functionObjectPrimitiveToObject() throws Exception {
    final String scriptScope2 = "function f() {\n"
        + "String.prototype.foo = 'from 2'; \n"
        + "var s2 = 's2';\n"
        + "var s2Foo = s2.foo;\n"
        + "var s2FooReadByFunction = myObject.readPropFoo(s2);\n"
        + "if (s2Foo != s2FooReadByFunction)\n"
        + "throw 's2 got: ' + s2FooReadByFunction;\n"
        + "}";

    // define object with custom method
    final MyObject myObject = new MyObject();
    final String[] functionNames = { "readPropFoo" };
    myObject.defineFunctionProperties(functionNames, MyObject.class,
        ScriptableObject.EMPTY);

    final String scriptScope1 = "String.prototype.foo = 'from 1'; scope2.f()";

    final ContextAction action = new ContextAction()
    {
        public Object run(final Context cx)
        {
            final Scriptable scope1 = cx.initStandardObjects(
                new MySimpleScriptableObject("scope1"));
            final Scriptable scope2 = cx.initStandardObjects(
                new MySimpleScriptableObject("scope2"));

            scope2.put("myObject", scope2, myObject);
            cx.evaluateString(scope2, scriptScope2, "source2", 1, null);

            scope1.put("scope2", scope1, scope2);

            return cx.evaluateString(scope1, scriptScope1, "source1", 1, null);
        }
    };
    Utils.runWithAllOptimizationLevels(action);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:43,代碼來源:PrimitiveTypeScopeResolutionTest.java


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