Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextAction


    /**
     * To be used by <code>WindowWrapper</code>.
     */
    void callHandler(final Function handler, final Object[] args) {
        contextFactory.call(new ContextAction() {
            public Object run(Context cx) {
                handler.call(cx, globalObject, globalObject, args);
                return null;
            }
        });
View Full Code Here


    /**
     * To be used by <code>WindowWrapper</code>.
     */
    void callHandler(final Function handler, final ArgumentsBuilder ab) {
        contextFactory.call(new ContextAction() {
            public Object run(Context cx) {
                Object[] args = ab.buildArguments();
                handler.call(cx, handler.getParentScope(), globalObject, args);
                return null;
            }
View Full Code Here

        Context.exit();
    }
  }

  private Object runScript(final String scriptSourceText) {
    return this.contextFactory.call(new ContextAction() {
      public Object run(Context context) {
          return context.evaluateString(global, scriptSourceText,
                  "test source", 1, null);
      }
    });
View Full Code Here

        assertEvaluates("hello", "var x = String.toLowerCase; x.apply('HELLO')");
        assertEvaluates("hello", "String.toLowerCase('HELLO')"); // first patch proposed to #492359 was breaking this
    }

    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);
View Full Code Here

  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);
View Full Code Here

    final Foo foo = new Foo("hello");
        foo.defineProperty("myProp", null, readMethod, null, ScriptableObject.EMPTY);

    final String script = "foo.myProp = 123; foo.myProp";

    final ContextAction action = new ContextAction() {
      public Object run(final Context cx) {

        final ScriptableObject top = cx.initStandardObjects();
        ScriptableObject.putProperty(top, "foo", foo);
View Full Code Here

        return "string[]";
    }

    @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')",
View Full Code Here

  private void doTest(final String expectedName, final String scriptName)
      throws Exception
  {
      final Script script = (Script) ContextFactory.getGlobal().call(
        new ContextAction() {
          public Object run(final Context context) {
            return context.compileString("var f = 1", scriptName, 1, null);
          }
        });
View Full Code Here

    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);
View Full Code Here

        final String expectedStack = "f()@myScript.js:2" + LS + "@myScript.js:4" + LS;
        testIt("function f() {\n null.method(); \n}\n try { f() } catch (e) { e.stack }", expectedStack);
    }

    private void testIt(final String script, final Object expected) {
        final ContextAction action = new ContextAction() {
            public Object run(final Context cx) {
                try {
                    final ScriptableObject scope = cx.initStandardObjects();
                    final Object o = cx.evaluateString(scope, script,
                            "myScript.js", 1, null);
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ContextAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.