Package org.mozilla.javascript

Examples of org.mozilla.javascript.ContextAction


      + "[].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


      assertEquals("success", result);
  }


  private Object runScript(final String scriptSourceText) {
    return 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

  /**
   * Execute the provided script in a fresh context as "myScript.js".
   * @param script the script code
   */
  static void executeScript(final String script, final int optimizationLevel) {
    final ContextAction action = new ContextAction()
    {
      public Object run(Context cx) {
        final Scriptable scope = cx.initStandardObjects();
        return cx.evaluateString(scope, script, "myScript.js", 1, null);
      }
View Full Code Here

    }

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

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

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

    doTest("function", action);
  }

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

    doTest("object", "typeof /foo/;");
  }

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

    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

    public void testFunctionWithSlashSlash() {
        assertEvaluates(true, "new Function('return true//;').call()");
    }

    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

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.