Java Javascript Mozilla Library evaluateJSExpression(String expr, Context cx, Scriptable scope)

Here you can find the source of evaluateJSExpression(String expr, Context cx, Scriptable scope)

Description

evaluate JS Expression

License

Open Source License

Declaration

public static boolean evaluateJSExpression(String expr, Context cx, Scriptable scope) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;

public class Main {
    public static boolean evaluateJSExpression(String expr, Context cx, Scriptable scope) {
        boolean evalResult = true;

        if ((null == expr) || (expr.isEmpty())) {
            return evalResult;
        }//from   w ww . j ava 2s  .  c o  m
        try {
            Object result = cx.evaluateString(scope, expr, "policyExpression", 1, null);
            if (result != null && Context.toString(result).equals("true")) {
                evalResult = true;
            } else {
                evalResult = false;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            evalResult = false;
        }
        return evalResult;
    }
}

Related

  1. createJavaAdapterArgs(Scriptable scope, Class[] ifaces, Object jsImpl)
  2. createNativeArray(int length, Scriptable scope)
  3. createSecurityController()
  4. ensureValid(Object obj)
  5. enterContext()
  6. from(Scriptable scriptable)
  7. functionArg(Object[] args, int pos, boolean required)
  8. getArray(Scriptable scope, NativeArray array)
  9. getClassOrObjectProto(Scriptable scope, String className)