java continuations_Java Context.evaluateString方法代碼示例

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

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

示例1: decryptSignature

​點讚 3

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,

示例2: start

​點讚 3

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,

示例3: testSetNullForScriptableSetter

​點讚 3

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,

示例4: runWithExpectedStackTrace

​點讚 3

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,

示例5: helper

​點讚 3

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,

示例6: testFunctionWithContinuations

​點讚 3

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,

示例7: testWithTwoScopes

​點讚 3

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,

示例8: decipherKey

​點讚 3

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,

示例9: setUp

​點讚 3

import org.mozilla.javascript.Context; //導入方法依賴的package包/類

@SuppressWarnings("unchecked")

@Override

protected void setUp() {

// set up a reference map

reference = new ArrayList();

reference.add("a");

reference.add(Boolean.TRUE);

reference.add(new HashMap());

reference.add(new Integer(42));

reference.add("a");

// get a js object as map

Context context = Context.enter();

ScriptableObject scope = context.initStandardObjects();

list = (List) context.evaluateString(scope,

"(['a', true, new java.util.HashMap(), 42, 'a']);",

"testsrc", 1, null);

Context.exit();

}

開發者ID:middle2tw,項目名稱:whackpad,代碼行數:19,

示例10: testIt

​點讚 3

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,

示例11: test0

​點讚 3

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,

示例12: testAttributeName

​點讚 2

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; ().attributes()[0].name()", "", 1, null);

System.out.println(o);

}

開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:9,

示例13: parseRhino

​點讚 2

import org.mozilla.javascript.Context; //導入方法依賴的package包/類

public static T parseRhino(File rhinoScript, ScopeOperation 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,

示例14: assertEvaluates

​點讚 2

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,

示例15: functionObjectPrimitiveToObject

​點讚 2

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,

示例16: testCustomizeTypeOf

​點讚 2

import org.mozilla.javascript.Context; //導入方法依賴的package包/類

private void testCustomizeTypeOf(final String expected, final Scriptable obj)

{

final ContextAction action = new ContextAction()

{

public Object run(final Context context)

{

final Scriptable scope = context.initStandardObjects();

scope.put("myObj", scope, obj);

return context.evaluateString(scope, "typeof myObj", "test script", 1, null);

}

};

doTest(expected, action);

}

開發者ID:middle2tw,項目名稱:whackpad,代碼行數:14,

示例17: doTest

​點讚 2

import org.mozilla.javascript.Context; //導入方法依賴的package包/類

private void doTest(String expected, final String script)

{

final ContextAction action = new ContextAction()

{

public Object run(final Context context)

{

final Scriptable scope = context.initStandardObjects();

return context.evaluateString(scope, script, "test script", 1, null);

}

};

doTest(expected, action);

}

開發者ID:middle2tw,項目名稱:whackpad,代碼行數:13,

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值