当前位置: 首页>>代码示例>>Java>>正文


Java ScriptableObject类代码示例

本文整理汇总了Java中org.mozilla.javascript.ScriptableObject的典型用法代码示例。如果您正苦于以下问题:Java ScriptableObject类的具体用法?Java ScriptableObject怎么用?Java ScriptableObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScriptableObject类属于org.mozilla.javascript包,在下文中一共展示了ScriptableObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptSignature

import org.mozilla.javascript.ScriptableObject; //导入依赖的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: extractScriptablePropertiesToMap

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
/**
 * Helper to extract a map of properties from a scriptable object (generally an associative array)
 * 
 * @param scriptable    The scriptable object to extract name/value pairs from.
 * @param map           The map to add the converted name/value pairs to.
 */
private void extractScriptablePropertiesToMap(ScriptableObject scriptable, Map<QName, Serializable> map)
{
    // get all the keys to the provided properties
    // and convert them to a Map of QName to Serializable objects
    Object[] propIds = scriptable.getIds();
    for (int i = 0; i < propIds.length; i++)
    {
        // work on each key in turn
        Object propId = propIds[i];
        
        // we are only interested in keys that are formed of Strings i.e. QName.toString()
        if (propId instanceof String)
        {
            // get the value out for the specified key - it must be Serializable
            String key = (String)propId;
            Object value = scriptable.get(key, scriptable);
            if (value instanceof Serializable)
            {
                value = getValueConverter().convertValueForRepo((Serializable)value);
                map.put(createQName(key), (Serializable)value);
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:31,代码来源:JscriptWorkflowDefinition.java

示例3: extractScriptableProperties

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
/**
 * Extract a map of properties from a scriptable object (generally an associative array)
 * 
 * @param scriptable    The scriptable object to extract name/value pairs from.
 * @param map           The map to add the converted name/value pairs to.
 */
private void extractScriptableProperties(ScriptableObject scriptable, Map<QName, Serializable> map)
{
    // we need to get all the keys to the properties provided
    // and convert them to a Map of QName to Serializable objects
    Object[] propIds = scriptable.getIds();
    for (int i = 0; i < propIds.length; i++)
    {
        // work on each key in turn
        Object propId = propIds[i];
        
        // we are only interested in keys that are formed of Strings i.e. QName.toString()
        if (propId instanceof String)
        {
            // get the value out for the specified key - it must be Serializable
            String key = (String)propId;
            Object value = scriptable.get(key, scriptable);
            if (value instanceof Serializable)
            {
                value = getValueConverter().convertValueForRepo((Serializable)value);
                map.put(createQName(key), (Serializable)value);
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:31,代码来源:ScriptNode.java

示例4: getScope

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
private ScriptableObject getScope() 
{
    // 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
    ScriptableObject scope;
    Context ctx = Context.getCurrentContext();
    boolean closeContext = false;
    if (ctx == null) 
    {
        ctx = Context.enter();
        closeContext = true;
    }
    scope = ctx.initStandardObjects();
    scope.setParentScope(null);

    if (closeContext) 
    {
        Context.exit();
    }
    return scope;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:ScriptNodeTest.java

示例5: init

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
public static void init(Context cx, Scriptable scope, boolean sealed)
{

    NativeRegExp proto = new NativeRegExp();
    proto.re = compileRE(cx, "", null, false);
    proto.activatePrototypeMap(MAX_PROTOTYPE_ID);
    proto.setParentScope(scope);
    proto.setPrototype(getObjectPrototype(scope));

    NativeRegExpCtor ctor = new NativeRegExpCtor();
    // Bug #324006: ECMA-262 15.10.6.1 says "The initial value of
    // RegExp.prototype.constructor is the builtin RegExp constructor."
    proto.defineProperty("constructor", ctor, ScriptableObject.DONTENUM);

    ScriptRuntime.setFunctionProtoAndParent(ctor, scope);

    ctor.setImmunePrototypeProperty(proto);

    if (sealed) {
        proto.sealObject();
        ctor.sealObject();
    }

    defineProperty(scope, "RegExp", ctor, ScriptableObject.DONTENUM);
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:26,代码来源:NativeRegExp.java

示例6: runScript

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
/**
 * 执行JS
 * 
 * @param js js代码
 * @param functionName js方法名称
 * @param functionParams js方法参数
 * @return
 */
public static String runScript(Context context, String js, String functionName, Object[] functionParams) {
	org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
	rhino.setOptimizationLevel(-1);
	try {
		Scriptable scope = rhino.initStandardObjects();

		ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(context, scope));
		ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(context.getClass().getClassLoader(), scope));

		rhino.evaluateString(scope, js, context.getClass().getSimpleName(), 1, null);

		Function function = (Function) scope.get(functionName, scope);

		Object result = function.call(rhino, scope, scope, functionParams);
		if (result instanceof String) {
			return (String) result;
		} else if (result instanceof NativeJavaObject) {
			return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
		} else if (result instanceof NativeObject) {
			return (String) ((NativeObject) result).getDefaultValue(String.class);
		}
		return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
	} finally {
		org.mozilla.javascript.Context.exit();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:A6Util.java

示例7: init

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
public static void init(Context cx, Scriptable scope, boolean sealed)
{

    NativeRegExp proto = new NativeRegExp();
    proto.re = (RECompiled)compileRE(cx, "", null, false);
    proto.activatePrototypeMap(MAX_PROTOTYPE_ID);
    proto.setParentScope(scope);
    proto.setPrototype(getObjectPrototype(scope));

    NativeRegExpCtor ctor = new NativeRegExpCtor();
    // Bug #324006: ECMA-262 15.10.6.1 says "The initial value of
    // RegExp.prototype.constructor is the builtin RegExp constructor." 
    proto.defineProperty("constructor", ctor, ScriptableObject.DONTENUM);

    ScriptRuntime.setFunctionProtoAndParent(ctor, scope);

    ctor.setImmunePrototypeProperty(proto);

    if (sealed) {
        proto.sealObject();
        ctor.sealObject();
    }

    defineProperty(scope, "RegExp", ctor, ScriptableObject.DONTENUM);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:26,代码来源:NativeRegExp.java

示例8: testJsApi

import org.mozilla.javascript.ScriptableObject; //导入依赖的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

示例9: testJavaApi

import org.mozilla.javascript.ScriptableObject; //导入依赖的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();
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:23,代码来源:Bug482203.java

示例10: testDeletePropInPrototype

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
/**
 * delete should not delete anything in the prototype chain.
 */
@Test
public void testDeletePropInPrototype() throws Exception {
	final String script = "Array.prototype.foo = function() {};\n"
		+ "Array.prototype[1] = function() {};\n"
		+ "var t = [];\n"
		+ "[].foo();\n"
		+ "for (var i in t) delete t[i];\n"
		+ "[].foo();\n"
		+ "[][1]();\n";
	
	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);
			return null;
		}
	};

	Utils.runWithAllOptimizationLevels(action);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:26,代码来源:DeletePropertyTest.java

示例11: setUp

import org.mozilla.javascript.ScriptableObject; //导入依赖的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

示例12: testIt

import org.mozilla.javascript.ScriptableObject; //导入依赖的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

示例13: testArrayConcat

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
public void testArrayConcat() {
final String script = "var a = ['a0', 'a1'];\n"
	+ "a[3] = 'a3';\n"
	+ "var b = ['b1', 'b2'];\n"
	+ "b.concat(a)";

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("b1,b2,a0,a1,,a3", Context.toString(result));
		return null;
	}
};

Utils.runWithAllOptimizationLevels(action);
  }
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:20,代码来源:ArrayConcatTest.java

示例14: createTest

import org.mozilla.javascript.ScriptableObject; //导入依赖的package包/类
private static Test createTest(final File testDir, final String name) {
    return new TestCase(name) {
        @Override
        public int countTestCases() {
            return 1;
        }
        @Override
        public void runBare() throws Throwable {
            final Context cx = Context.enter();
            try {
                cx.setOptimizationLevel(-1);
                final Scriptable scope = cx.initStandardObjects();
                ScriptableObject.putProperty(scope, "print", new Print(scope));
                createRequire(testDir, cx, scope).requireMain(cx, "program");
            }
            finally {
                Context.exit();
            }
        }
    };
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:22,代码来源:ComplianceTest.java

示例15: testSetNullForScriptableSetter

import org.mozilla.javascript.ScriptableObject; //导入依赖的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


注:本文中的org.mozilla.javascript.ScriptableObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。