Java Javascript Mozilla Library runWithAllOptimizationLevels(final ContextAction action)

Here you can find the source of runWithAllOptimizationLevels(final ContextAction action)

Description

Runs the action successively with all available optimization levels

License

Apache License

Declaration

public static void runWithAllOptimizationLevels(final ContextAction action) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextAction;
import org.mozilla.javascript.ContextFactory;

public class Main {
    /**/*from   w  w  w  .ja v a2  s .com*/
     * Runs the action successively with all available optimization levels
     */
    public static void runWithAllOptimizationLevels(final ContextAction action) {
        runWithOptimizationLevel(action, -1);
        runWithOptimizationLevel(action, 0);
        runWithOptimizationLevel(action, 1);
    }

    /**
     * Runs the action successively with all available optimization levels
     */
    public static void runWithAllOptimizationLevels(final ContextFactory contextFactory,
            final ContextAction action) {
        runWithOptimizationLevel(contextFactory, action, -1);
        runWithOptimizationLevel(contextFactory, action, 0);
        runWithOptimizationLevel(contextFactory, action, 1);
    }

    /**
     * Runs the provided action at the given optimization level
     */
    public static void runWithOptimizationLevel(final ContextAction action, final int optimizationLevel) {
        runWithOptimizationLevel(new ContextFactory(), action, optimizationLevel);
    }

    /**
     * Runs the provided action at the given optimization level
     */
    public static void runWithOptimizationLevel(final ContextFactory contextFactory, final ContextAction action,
            final int optimizationLevel) {
        final Context cx = contextFactory.enterContext();
        try {
            cx.setOptimizationLevel(optimizationLevel);
            action.run(cx);
        } finally {
            Context.exit();
        }
    }
}

Related

  1. oneLineStringOf(AstNode node)
  2. parentOfAnyTypes(AstNode node, Set types, boolean isStrict)
  3. parentOfType(AstNode node, Class type)
  4. prototypeCast(Scriptable s, Class type)
  5. removeLinkFromXhtml(Object xhtml, String link)
  6. runWithOptimizationLevel(final ContextAction action, final int optimizationLevel)
  7. scriptableObjectToString(Object scriptObject)
  8. stringToNumber(CharSequence string)
  9. stringValue(String name, Scriptable scope)