File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\main\java\org\jvnet\hudson\test\rhino\CallStackFrame.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package org.jvnet.hudson.test.rhino;
25
26 import net.sourceforge.htmlunit.corejs.javascript.Context;
27 import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
28 import net.sourceforge.htmlunit.corejs.javascript.debug.DebugFrame;
29 import net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableScript;
30
31 import java.util.SortedMap;
32 import java.util.TreeMap;
33
34 /**
35 * Stack frame.
36 *
37 * @author Kohsuke Kawaguchi
38 */
39 public class CallStackFrame implements DebugFrame {
40 /**
41 * {@link JavaScriptDebugger} that this stack frame lives in.
42 */
43 public final JavaScriptDebugger owner;
44 /**
45 * The function being executed.
46 */
47 public final DebuggableScript fnOrScript;
48
49 private Scriptable activation;
50 private Scriptable thisObj;
51 private Object[] args;
52 private int line;
53
54 public CallStackFrame(JavaScriptDebugger owner, DebuggableScript fnOrScript) {
55 this.owner = owner;
56 this.fnOrScript = fnOrScript;
57 }
58
59 public void onEnter(Context cx, Scriptable activation, Scriptable thisObj, Object[] args) {
60 this.activation = activation;
61 this.thisObj = thisObj;
62 this.args = args;
63 owner.addCallStackFrame(this);
64 }
65
66 public void onExit(Context cx, boolean byThrow, Object resultOrException) {
67 owner.removeCallStackFrame(this);
68
69 activation = null;
70 thisObj = null;
71 args = null;
72 line = -1;
73 }
74
75 public void onLineChange(Context cx, int lineNumber) {
76 this.line = lineNumber;
77 }
78
79 public void onExceptionThrown(Context cx, Throwable ex) {
80 }
81
82 public void onDebuggerStatement(Context cx) {
83 }
84
85 /**
86 * In-scope variables.
87 */
88 public SortedMap<String,Object> getVariables() {
89 SortedMap<String,Object> r = new TreeMap<String,Object>();
90 for( int i=fnOrScript.getParamAndVarCount()-1; i>=0; i-- ) {
91 String name =fnOrScript.getParamOrVarName(i);
92 r.put(name,activation.get(name,activation));
93 }
94 return r;
95 }
96
97 /**
98 * Formats this call stack, arguments, and its local variables as a human readable string.
99 */
100 public String toString() {
101 StringBuilder buf = new StringBuilder();
102 buf.append(fnOrScript.getFunctionName());
103 buf.append('(');
104 for( int i=0; i<args.length; i++ ) {
105 if(i!=0) buf.append(',');
106 buf.append(args[i]);
107 }
108 buf.append(')');
109 buf.append("\n at ").append(fnOrScript.getSourceName()).append('#').append(line);
110
111 buf.append("\n variables=").append(getVariables());
112
113 return buf.toString();
114 }
115 }
116