Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextAction


    doTest(1, expected, action);
  }

  private void doTest(final int optimizationLevel, final String expected, final ContextAction action)
  {
    Object o = new ContextFactory().call(new ContextAction()
      {
        public Object run(final Context context)
        {
          context.setOptimizationLevel(optimizationLevel);
          return Context.toString(action.run(context));
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

      + "[].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);
View Full Code Here

        assertEvaluates("789", "String(parseInt('" + prefix + "789 '))");
        assertEvaluates("7.89", "String(parseFloat('" + prefix + "7.89 '))");
    }

    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

        runWithExpectedStackTrace(source2, "  at test.js (f2)\n\tat test.js\n"); // fails
    }

  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);
            }
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

      "var x = new PrivateAccessClass(); x.javaBeanProperty = 4; x.javaBeanProperty + ' ' + x.setterCalled;");
      assertEquals("4 true", result);
  }

  private Object runScript(final String scriptSourceText) {
    return this.contextFactory.call(new ContextAction() {
      public Object run(Context context) {
        Script script = context.compileString(scriptSourceText, "", 1, null);
        return script.exec(context, global);
      }
    });
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.