org.mozilla.javascript.debug.DebuggableScript Java Examples

The following examples show how to use org.mozilla.javascript.debug.DebuggableScript. 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 6 votes vote down vote up
private void checkBreakable( DebuggableScript script )
{
	int[] nums = script.getLineNumbers( );

	if ( nums != null && nums.length > 0 )
	{
		for ( int i = 0; i < nums.length; i++ )
		{
			if ( nums[i] == lineNumber )
			{
				breakable = true;
				return;
			}
		}
	}

	for ( int i = 0; i < script.getFunctionCount( ); i++ )
	{
		checkBreakable( script.getFunction( i ) );

		if ( breakable )
		{
			return;
		}
	}
}
 
Example #2
Source File: JsDebugger.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public DebugFrame getFrame( Context arg0, DebuggableScript arg1 )
{
	if ( disposed )
	{
		return null;
	}

	JsFunctionSource src = (JsFunctionSource) scripts.get( arg1 );

	if ( src == null )
	{
		// this is not debuggable
		return null;
	}

	System.out.println( ">>>> Frame Source Name: " + src.getSourceName( ) ); //$NON-NLS-1$
	System.out.println( ">>>> Frame Function Name: " + src.getFunctionName( ) ); //$NON-NLS-1$

	return new JsDebugFrame( arg0, this, arg1, src );
}
 
Example #3
Source File: JsUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void handleCompilationDone( Context arg0, DebuggableScript arg1,
		String arg2 )
{
	if ( !arg1.isTopLevel( ) )
	{
		return;
	}

	breakable = false;

	checkBreakable( arg1 );
}
 
Example #4
Source File: Context.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Return DebuggableScript instance if any associated with the script.
 * If callable supports DebuggableScript implementation, the method
 * returns it. Otherwise null is returned.
 */
public static DebuggableScript getDebuggableView(Script script)
{
    if (script instanceof NativeFunction) {
        return ((NativeFunction)script).getDebuggableView();
    }
    return null;
}
 
Example #5
Source File: Context.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private static void notifyDebugger_r(Context cx, DebuggableScript dscript,
                                     String debugSource)
{
    cx.debugger.handleCompilationDone(cx, dscript, debugSource);
    for (int i = 0; i != dscript.getFunctionCount(); ++i) {
        notifyDebugger_r(cx, dscript.getFunction(i), debugSource);
    }
}
 
Example #6
Source File: JsDebugFrame.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public JsDebugFrame( Context cx, JsDebugger debugger,
		DebuggableScript script, JsFunctionSource src )
{
	this.cx = cx;
	this.debugger = debugger;
	this.script = script;
	this.src = src;
}
 
Example #7
Source File: JsDebugger.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void collectFunctions( DebuggableScript function, List holder )
{
	holder.add( function );

	for ( int i = 0; i < function.getFunctionCount( ); i++ )
	{
		collectFunctions( function.getFunction( i ), holder );
	}
}
 
Example #8
Source File: JsDebugger.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void registerFunctions( String source, List functions )
{
	for ( int i = 0; i < functions.size( ); i++ )
	{
		DebuggableScript function = (DebuggableScript) functions.get( i );

		int firstLineNumber = getMinNumber( function.getLineNumbers( ) );

		if ( firstLineNumber == -1 )
		{
			continue;
		}

		String funcName = function.getFunctionName( );

		if ( funcName == null )
		{
			funcName = ""; //$NON-NLS-1$
		}

		scripts.put( function,
				new JsFunctionSource( function.getSourceName( ),
						funcName,
						source,
						firstLineNumber ) );
	}
}
 
Example #9
Source File: JsDebugger.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void registerTopLevelScripts( DebuggableScript script, String source )
{
	List functions = new ArrayList( );
	collectFunctions( script, functions );

	registerFunctions( source, functions );
}
 
Example #10
Source File: JsDebugger.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void handleCompilationDone( Context arg0, DebuggableScript arg1,
		String arg2 )
{
	if ( disposed || !arg1.isTopLevel( ) )
	{
		return;
	}

	// check debuggable scripts
	if ( arg1.getSourceName( ) == null
			|| arg1.getSourceName( ).equals( ScriptExpression.defaultID ) )
	{
		// skip default scripts, which is only used internally.

		// System.out.println( ">>>> Skipped Source: " //$NON-NLS-1$
		// + arg1.getSourceName( )
		// + "\r\n" //$NON-NLS-1$
		// + arg2
		// + "\r\n>>>> Skipped." ); //$NON-NLS-1$

		return;
	}

	registerTopLevelScripts( arg1, arg2 );

	System.out.println( ">>>> Compiled Source: " //$NON-NLS-1$
			+ arg1.getSourceName( )
			+ "\r\n" //$NON-NLS-1$
			+ arg2
			+ "\r\n>>>> end compilation." ); //$NON-NLS-1$
}
 
Example #11
Source File: Context.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private static void notifyDebugger_r(Context cx, DebuggableScript dscript,
                                     String debugSource)
{
    cx.debugger.handleCompilationDone(cx, dscript, debugSource);
    for (int i = 0; i != dscript.getFunctionCount(); ++i) {
        notifyDebugger_r(cx, dscript.getFunction(i), debugSource);
    }
}
 
Example #12
Source File: Context.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return DebuggableScript instance if any associated with the script.
 * If callable supports DebuggableScript implementation, the method
 * returns it. Otherwise null is returned.
 */
public static DebuggableScript getDebuggableView(Script script)
{
    if (script instanceof NativeFunction) {
        return ((NativeFunction)script).getDebuggableView();
    }
    return null;
}
 
Example #13
Source File: InterpreterData.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public DebuggableScript getFunction(int index)
{
    return itsNestedFunctions[index];
}
 
Example #14
Source File: JsUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public DebugFrame getFrame( Context arg0, DebuggableScript arg1 )
{
	return null;
}
 
Example #15
Source File: JsDebugFrame.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public DebuggableScript getScript( )
{
	return script;
}
 
Example #16
Source File: Context.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private Object compileImpl(Scriptable scope,
                           Reader sourceReader, String sourceString,
                           String sourceName, int lineno,
                           Object securityDomain, boolean returnFunction,
                           Evaluator compiler,
                           ErrorReporter compilationErrorReporter)
    throws IOException
{
    if(sourceName == null) {
        sourceName = "unnamed script";
    }
    if (securityDomain != null && getSecurityController() == null) {
        throw new IllegalArgumentException(
            "securityDomain should be null if setSecurityController() was never called");
    }

    // One of sourceReader or sourceString has to be null
    if (!(sourceReader == null ^ sourceString == null)) Kit.codeBug();
    // scope should be given if and only if compiling function
    if (!(scope == null ^ returnFunction)) Kit.codeBug();

    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(this);
    if (compilationErrorReporter == null) {
        compilationErrorReporter = compilerEnv.getErrorReporter();
    }

    if (debugger != null) {
        if (sourceReader != null) {
            sourceString = Kit.readReader(sourceReader);
            sourceReader = null;
        }
    }

    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    if (returnFunction) {
        p.calledByCompileFunction = true;
    }
    AstRoot ast;
    if (sourceString != null) {
        ast = p.parse(sourceString, sourceName, lineno);
    } else {
        ast = p.parse(sourceReader, sourceName, lineno);
    }
    if (returnFunction) {
        // parser no longer adds function to script node
        if (!(ast.getFirstChild() != null
              && ast.getFirstChild().getType() == Token.FUNCTION))
        {
            // XXX: the check just looks for the first child
            // and allows for more nodes after it for compatibility
            // with sources like function() {};;;
            throw new IllegalArgumentException(
                "compileFunction only accepts source with single JS function: "+sourceString);
        }
    }

    IRFactory irf = new IRFactory(compilerEnv, compilationErrorReporter);
    ScriptNode tree = irf.transformTree(ast);

    // discard everything but the IR tree
    p = null;
    ast = null;
    irf = null;

    if (compiler == null) {
        compiler = createCompiler();
    }

    Object bytecode = compiler.compile(compilerEnv,
                                       tree, tree.getEncodedSource(),
                                       returnFunction);
    if (debugger != null) {
        if (sourceString == null) Kit.codeBug();
        if (bytecode instanceof DebuggableScript) {
            DebuggableScript dscript = (DebuggableScript)bytecode;
            notifyDebugger_r(this, dscript, sourceString);
        } else {
            throw new RuntimeException("NOT SUPPORTED");
        }
    }

    Object result;
    if (returnFunction) {
        result = compiler.createFunctionObject(this, scope, bytecode, securityDomain);
    } else {
        result = compiler.createScriptObject(bytecode, securityDomain);
    }

    return result;
}
 
Example #17
Source File: InterpreterData.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public DebuggableScript getParent()
{
     return parentData;
}
 
Example #18
Source File: InterpretedFunction.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DebuggableScript getDebuggableView()
{
    return idata;
}
 
Example #19
Source File: NativeFunction.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public DebuggableScript getDebuggableView()
{
    return null;
}
 
Example #20
Source File: InterpretedFunction.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DebuggableScript getDebuggableView()
{
    return idata;
}
 
Example #21
Source File: ObservingDebugger.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleCompilationDone(Context arg0, DebuggableScript arg1, String arg2) {
}
 
Example #22
Source File: ObservingDebugger.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
    if (debugFrame == null) {
        debugFrame = new ObservingDebugFrame(isDisconnected);
    }
    return debugFrame;
}
 
Example #23
Source File: JsDebug.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {

	return debugFrame;
}
 
Example #24
Source File: JsDebug.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void handleCompilationDone(Context cx, DebuggableScript fnOrScript,
		String source) {

}
 
Example #25
Source File: Context.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
private Object compileImpl(Scriptable scope,
                           Reader sourceReader, String sourceString,
                           String sourceName, int lineno,
                           Object securityDomain, boolean returnFunction,
                           Evaluator compiler,
                           ErrorReporter compilationErrorReporter)
    throws IOException
{
    if(sourceName == null) {
        sourceName = "unnamed script";
    }
    if (securityDomain != null && getSecurityController() == null) {
        throw new IllegalArgumentException(
            "securityDomain should be null if setSecurityController() was never called");
    }

    // One of sourceReader or sourceString has to be null
    if (!(sourceReader == null ^ sourceString == null)) Kit.codeBug();
    // scope should be given if and only if compiling function
    if (!(scope == null ^ returnFunction)) Kit.codeBug();

    CompilerEnvirons compilerEnv = new CompilerEnvirons();
    compilerEnv.initFromContext(this);
    if (compilationErrorReporter == null) {
        compilationErrorReporter = compilerEnv.getErrorReporter();
    }

    if (debugger != null) {
        if (sourceReader != null) {
            sourceString = Kit.readReader(sourceReader);
            sourceReader = null;
        }
    }

    Parser p = new Parser(compilerEnv, compilationErrorReporter);
    if (returnFunction) {
        p.calledByCompileFunction = true;
    }
    if (isStrictMode()) {
        p.setDefaultUseStrictDirective(true);
    }
    AstRoot ast;
    if (sourceString != null) {
        ast = p.parse(sourceString, sourceName, lineno);
    } else {
        ast = p.parse(sourceReader, sourceName, lineno);
    }
    if (returnFunction) {
        // parser no longer adds function to script node
        if (!(ast.getFirstChild() != null
              && ast.getFirstChild().getType() == Token.FUNCTION))
        {
            // XXX: the check just looks for the first child
            // and allows for more nodes after it for compatibility
            // with sources like function() {};;;
            throw new IllegalArgumentException(
                "compileFunction only accepts source with single JS function: "+sourceString);
        }
    }

    IRFactory irf = new IRFactory(compilerEnv, compilationErrorReporter);
    ScriptNode tree = irf.transformTree(ast);

    // discard everything but the IR tree
    p = null;
    ast = null;
    irf = null;

    if (compiler == null) {
        compiler = createCompiler();
    }

    Object bytecode = compiler.compile(compilerEnv,
                                       tree, tree.getEncodedSource(),
                                       returnFunction);
    if (debugger != null) {
        if (sourceString == null) Kit.codeBug();
        if (bytecode instanceof DebuggableScript) {
            DebuggableScript dscript = (DebuggableScript)bytecode;
            notifyDebugger_r(this, dscript, sourceString);
        } else {
            throw new RuntimeException("NOT SUPPORTED");
        }
    }

    Object result;
    if (returnFunction) {
        result = compiler.createFunctionObject(this, scope, bytecode, securityDomain);
    } else {
        result = compiler.createScriptObject(bytecode, securityDomain);
    }

    return result;
}
 
Example #26
Source File: InterpreterData.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public DebuggableScript getParent()
{
     return parentData;
}
 
Example #27
Source File: InterpreterData.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public DebuggableScript getFunction(int index)
{
    return itsNestedFunctions[index];
}
 
Example #28
Source File: NativeFunction.java    From JsDroidCmd with Mozilla Public License 2.0 4 votes vote down vote up
public DebuggableScript getDebuggableView()
{
    return null;
}
 
Example #29
Source File: SourceProvider.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the source of the script.
 * @param script the script object
 * @return the source code of the script, or null if it can not be provided
 * (the provider is not expected to decompile the script, so if it doesn't
 * have a readily available source text, it is free to return null).
 */
String getSource(DebuggableScript script);
 
Example #30
Source File: SourceProvider.java    From JsDroidCmd with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Returns the source of the script.
 * @param script the script object
 * @return the source code of the script, or null if it can not be provided
 * (the provider is not expected to decompile the script, so if it doesn't
 * have a readily available source text, it is free to return null).
 */
String getSource(DebuggableScript script);