| 1 | /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | // API class |
| 8 | |
| 9 | package org.mozilla.javascript.debug; |
| 10 | |
| 11 | /** |
| 12 | * This interface exposes debugging information from executable |
| 13 | * code (either functions or top-level scripts). |
| 14 | */ |
| 15 | public interface DebuggableScript |
| 16 | { |
| 17 | public boolean isTopLevel(); |
| 18 | |
| 19 | /** |
| 20 | * Returns true if this is a function, false if it is a script. |
| 21 | */ |
| 22 | public boolean isFunction(); |
| 23 | |
| 24 | /** |
| 25 | * Get name of the function described by this script. |
| 26 | * Return null or an empty string if this script is not a function. |
| 27 | */ |
| 28 | public String getFunctionName(); |
| 29 | |
| 30 | /** |
| 31 | * Get number of declared parameters in the function. |
| 32 | * Return 0 if this script is not a function. |
| 33 | * |
| 34 | * @see #getParamAndVarCount() |
| 35 | * @see #getParamOrVarName(int index) |
| 36 | */ |
| 37 | public int getParamCount(); |
| 38 | |
| 39 | /** |
| 40 | * Get number of declared parameters and local variables. |
| 41 | * Return number of declared global variables if this script is not a |
| 42 | * function. |
| 43 | * |
| 44 | * @see #getParamCount() |
| 45 | * @see #getParamOrVarName(int index) |
| 46 | */ |
| 47 | public int getParamAndVarCount(); |
| 48 | |
| 49 | /** |
| 50 | * Get name of a declared parameter or local variable. |
| 51 | * <tt>index</tt> should be less then {@link #getParamAndVarCount()}. |
| 52 | * If <tt>index < {@link #getParamCount()}</tt>, return |
| 53 | * the name of the corresponding parameter, otherwise return the name |
| 54 | * of variable. |
| 55 | * If this script is not function, return the name of the declared |
| 56 | * global variable. |
| 57 | */ |
| 58 | public String getParamOrVarName(int index); |
| 59 | |
| 60 | /** |
| 61 | * Get the name of the source (usually filename or URL) |
| 62 | * of the script. |
| 63 | */ |
| 64 | public String getSourceName(); |
| 65 | |
| 66 | /** |
| 67 | * Returns true if this script or function were runtime-generated |
| 68 | * from JavaScript using <tt>eval</tt> function or <tt>Function</tt> |
| 69 | * or <tt>Script</tt> constructors. |
| 70 | */ |
| 71 | public boolean isGeneratedScript(); |
| 72 | |
| 73 | /** |
| 74 | * Get array containing the line numbers that |
| 75 | * that can be passed to <code>DebugFrame.onLineChange()<code>. |
| 76 | * Note that line order in the resulting array is arbitrary |
| 77 | */ |
| 78 | public int[] getLineNumbers(); |
| 79 | |
| 80 | public int getFunctionCount(); |
| 81 | |
| 82 | public DebuggableScript getFunction(int index); |
| 83 | |
| 84 | public DebuggableScript getParent(); |
| 85 | |
| 86 | } |