Java Code Examples for org.mozilla.javascript.Context#setGeneratingDebug()

The following examples show how to use org.mozilla.javascript.Context#setGeneratingDebug() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
static boolean check( String source, int lineNumber )
{
	Context cx = Context.enter( );

	Debugger oldDebugger = cx.getDebugger( );
	Object oldContext = cx.getDebuggerContextData( );
	boolean oldGenerate = cx.isGeneratingDebug( );
	int oldLevel = cx.getOptimizationLevel( );

	try
	{
		BreakableSourceChecker checker = new BreakableSourceChecker( );
		checker.lineNumber = lineNumber + 2;

		cx.setDebugger( checker, null );
		cx.setGeneratingDebug( true );
		cx.setOptimizationLevel( -1 );

		cx.compileString( addHeader( source ), "<check>", 1, null ); //$NON-NLS-1$

		return checker.breakable;
	}
	catch ( Exception e )
	{
		return false;
	}
	finally
	{
		cx.setDebugger( oldDebugger, oldContext );
		cx.setGeneratingDebug( oldGenerate );
		cx.setOptimizationLevel( oldLevel );

		Context.exit( );
	}
}
 
Example 2
Source File: JavaScriptEngine.java    From commons-bsf with Apache License 2.0 5 votes vote down vote up
/**
 * This is used by an application to evaluate a string containing
 * some expression.
 */
public Object eval(String source, int lineNo, int columnNo, Object oscript)
    throws BSFException {

    String scriptText = oscript.toString();
    Object retval = null;
    Context cx;

    try {
        cx = Context.enter();

        cx.setOptimizationLevel(-1);
        cx.setGeneratingDebug(false);
        cx.setGeneratingSource(false);
        cx.setOptimizationLevel(0);
        cx.setDebugger(null, null);

        retval = cx.evaluateString(global, scriptText,
                                   source, lineNo,
                                   null);

        if (retval instanceof NativeJavaObject)
            retval = ((NativeJavaObject) retval).unwrap();

    } 
    catch (Throwable t) { // includes JavaScriptException, rethrows Errors
        handleError(t);
    } 
    finally {
        Context.exit();
    }
    return retval;
}
 
Example 3
Source File: JavaScriptEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
     * Return an object from an extension.
     * @param object Object on which to make the call (ignored).
     * @param method The name of the method to call.
     * @param args an array of arguments to be
     * passed to the extension, which may be either
     * Vectors of Nodes, or Strings.
     */
    public Object call(Object object, String method, Object[] args)
        throws BSFException {

        Object retval = null;
        Context cx;

        try {
            cx = Context.enter();

            // REMIND: convert arg list Vectors here?

            Object fun = global.get(method, global);
            // NOTE: Source and line arguments are nonsense in a call().
            //       Any way to make these arguments *sensible?
            if (fun == Scriptable.NOT_FOUND)
                throw new EvaluatorException("function " + method +
                                             " not found.", "none", 0);

            cx.setOptimizationLevel(-1);
            cx.setGeneratingDebug(false);
            cx.setGeneratingSource(false);
            cx.setOptimizationLevel(0);
            cx.setDebugger(null, null);
            
            retval =
                ((Function) fun).call(cx, global, global, args);
            
//                ScriptRuntime.call(cx, fun, global, args, global);

            if (retval instanceof Wrapper)
                retval = ((Wrapper) retval).unwrap();
        } 
        catch (Throwable t) {
            handleError(t);
        } 
        finally {
            Context.exit();
        }
        return retval;
    }