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


Java ContextAction类代码示例

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


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

示例1: testWithTwoScopes

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

示例2: testDeletePropInPrototype

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

示例3: testIt

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

示例4: testArrayConcat

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

示例5: test0

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

示例6: callOverloadedFunction

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
@Test
public void callOverloadedFunction() {
    new ContextFactory().call(new ContextAction() {
        public Object run(Context cx) {
            cx.evaluateString(
                cx.initStandardObjects(),
                "new org.mozilla.javascript.tests.Bug496585().method('one', 'two', 'three')",
                "<test>", 1, null);
            cx.evaluateString(
                cx.initStandardObjects(),
                "new org.mozilla.javascript.tests.Bug496585().method('one', function() {})",
                "<test>", 1, null);
            return null;
        }
    });
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:17,代码来源:Bug496585.java

示例7: runWithExpectedStackTrace

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

示例8: testDeletePropInPrototype

import org.mozilla.javascript.ContextAction; //导入依赖的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:F43nd1r,项目名称:rhino-android,代码行数:26,代码来源:DeletePropertyTest.java

示例9: callOverloadedFunction

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
@Test
public void callOverloadedFunction() {
    new AndroidContextFactory(new File(System.getProperty("java.io.tmpdir", "."), "classes")).call(new ContextAction() {
        public Object run(Context cx) {
            cx.getWrapFactory().setJavaPrimitiveWrap(false);
            Assert.assertEquals("string[]", cx.evaluateString(
                    cx.initStandardObjects(),
                    "new org.mozilla.javascript.tests.Bug496585Test().method('one', 'two', 'three')",
                    "<test>", 1, null));
            Assert.assertEquals("string+function", cx.evaluateString(
                cx.initStandardObjects(),
                "new org.mozilla.javascript.tests.Bug496585Test().method('one', function() {})",
                "<test>", 1, null));
            return null;
        }
    });
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:18,代码来源:Bug496585Test.java

示例10: initJavaScript

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
private void initJavaScript() {
    LogUtils.logMessage("Initialising JavaScript...");
    contextFactory.call(new ContextAction() {
        @Override
        public Object run(Context cx) {
            ImporterTopLevel importer = new ImporterTopLevel();
            importer.initStandardObjects(cx, false);
            systemScope = importer;

            Object frameworkScriptable = Context.javaToJS(Framework.this, systemScope);
            ScriptableObject.putProperty(systemScope, FRAMEWORK_VARIABLE, frameworkScriptable);
            systemScope.setAttributes(FRAMEWORK_VARIABLE, ScriptableObject.READONLY);

            globalScope = (ScriptableObject) cx.newObject(systemScope);
            globalScope.setPrototype(systemScope);
            globalScope.setParentScope(null);

            return null;
        }
    });
}
 
开发者ID:workcraft,项目名称:workcraft,代码行数:22,代码来源:Framework.java

示例11: setJavaScriptProperty

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
public void setJavaScriptProperty(final String name, final Object object,
        final ScriptableObject scope, final boolean readOnly) {

    deleteJavaScriptProperty(name, scope);

    contextFactory.call(new ContextAction() {
        @Override
        public Object run(Context arg0) {
            Object scriptable = Context.javaToJS(object, scope);
            ScriptableObject.putProperty(scope, name, scriptable);
            if (readOnly) {
                scope.setAttributes(name, ScriptableObject.READONLY);
            }
            return scriptable;
        }
    });
}
 
开发者ID:workcraft,项目名称:workcraft,代码行数:18,代码来源:Framework.java

示例12: shutdownGUI

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
public void shutdownGUI() throws OperationCancelledException {
    if (isInGuiMode()) {
        mainWindow.shutdown();
        mainWindow.dispose();
        mainWindow = null;
        inGuiMode = false;

        contextFactory.call(new ContextAction() {
            @Override
            public Object run(Context cx) {
                ScriptableObject.deleteProperty(systemScope, "mainWindow");
                return null;
            }
        });
    }
}
 
开发者ID:workcraft,项目名称:workcraft,代码行数:17,代码来源:Framework.java

示例13: bindObject

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
/**
 * This method registers a particular Java <code>Object</code> in
 * the environment of the interpreter.
 * @param name the name of the script object to create
 * @param object the Java object
 */
public void bindObject(final String name, final Object object) {
    contextFactory.call(new ContextAction() {
        public Object run(Context cx) {
            Object o = object;
            if (name.equals(BIND_NAME_WINDOW) && object instanceof Window) {
                ((WindowWrapper) globalObject).window = (Window) object;
                window = (Window) object;
                o = globalObject;
            }
            Scriptable jsObject;
            jsObject = Context.toObject(o, globalObject);
            globalObject.put(name, globalObject, jsObject);
            return null;
        }
    });
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:23,代码来源:RhinoInterpreter.java

示例14: callOverloadedFunction

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
@Test
public void callOverloadedFunction() {
    new ContextFactory().call(new ContextAction() {
        public Object run(Context cx) {
            cx.getWrapFactory().setJavaPrimitiveWrap(false);
            Assert.assertEquals("string[]", cx.evaluateString(
                    cx.initStandardObjects(),
                    "new org.mozilla.javascript.tests.Bug496585Test().method('one', 'two', 'three')",
                    "<test>", 1, null));
            Assert.assertEquals("string+function", cx.evaluateString(
                cx.initStandardObjects(),
                "new org.mozilla.javascript.tests.Bug496585Test().method('one', function() {})",
                "<test>", 1, null));
            return null;
        }
    });
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:18,代码来源:Bug496585Test.java

示例15: compile

import org.mozilla.javascript.ContextAction; //导入依赖的package包/类
@Override
public ScriptImpl compile(final Script script, final WorkflowParser parser) {
  ScriptImpl scriptImpl = new ScriptImpl();
  scriptImpl.scriptService = this;
  scriptImpl.mappings = script.getMappings();
  scriptImpl.compiledScript = contextFactory.call(new ContextAction() {
    public Object run(Context context) {
      try {
        return context.compileString(script.getScript(), "script", 1, null);
      } catch (Exception e) {
        parser.addWarning("Script doesn't compile: %s", e.getMessage());
        return null;
      }
    }
  });
  return scriptImpl;
}
 
开发者ID:effektif,项目名称:effektif,代码行数:18,代码来源:RhinoScriptService.java


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