The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / test / mjsunit / debug-handle.js @ 40c0f755

History | View | Annotate | Download (6.65 KB)

1
// Copyright 2009 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
// Flags: --expose-debug-as debug
29
// Get the Debug object exposed from the debug context global object.
30
Debug = debug.Debug
31

    
32
listenerComplete = false;
33
exception = false;
34

    
35
function safeEval(code) {
36
  try {
37
    return eval('(' + code + ')');
38
  } catch (e) {
39
    assertEquals(void 0, e);
40
    return undefined;
41
  }
42
}
43

    
44

    
45
// Send an evaluation request and return the handle of the result.
46
function evaluateRequest(dcp, arguments) {
47
  // The base part of all evaluate requests.
48
  var base_request = '"seq":0,"type":"request","command":"evaluate"'
49

    
50
  // Generate request with the supplied arguments.
51
  var request;
52
  if (arguments) {
53
    request = '{' + base_request + ',"arguments":' + arguments + '}';
54
  } else {
55
    request = '{' + base_request + '}'
56
  }
57

    
58
  var response = safeEval(dcp.processDebugJSONRequest(request));
59
  assertTrue(response.success, request + ' -> ' + response.message);
60

    
61
  return response.body.handle;
62
}
63

    
64

    
65
// Send a lookup request and return the evaluated JSON response.
66
function lookupRequest(dcp, arguments, success) {
67
  // The base part of all lookup requests.
68
  var base_request = '"seq":0,"type":"request","command":"lookup"'
69
  
70
  // Generate request with the supplied arguments.
71
  var request;
72
  if (arguments) {
73
    request = '{' + base_request + ',"arguments":' + arguments + '}';
74
  } else {
75
    request = '{' + base_request + '}'
76
  }
77

    
78
  var response = safeEval(dcp.processDebugJSONRequest(request));
79
  if (success) {
80
    assertTrue(response.success, request + ' -> ' + response.message);
81
  } else {
82
    assertFalse(response.success, request + ' -> ' + response.message);
83
  }
84
  assertFalse(response.running, request + ' -> expected not running');
85

    
86
  return response;
87
}
88

    
89

    
90
function listener(event, exec_state, event_data, data) {
91
  try {
92
  if (event == Debug.DebugEvent.Break) {
93
    // Get the debug command processor.
94
    var dcp = exec_state.debugCommandProcessor();
95

    
96
    // Test some illegal lookup requests.
97
    lookupRequest(dcp, void 0, false);
98
    lookupRequest(dcp, '{"handle":"a"}', false);
99
    lookupRequest(dcp, '{"handle":-1}', false);
100

    
101
    // Evaluate and get some handles.
102
    var handle_o = evaluateRequest(dcp, '{"expression":"o"}');
103
    var handle_p = evaluateRequest(dcp, '{"expression":"p"}');
104
    var handle_b = evaluateRequest(dcp, '{"expression":"a"}');
105
    var handle_a = evaluateRequest(dcp, '{"expression":"b","frame":1}');
106
    assertEquals(handle_o, handle_a);
107
    assertEquals(handle_a, handle_b);
108
    assertFalse(handle_o == handle_p, "o and p have he same handle");
109

    
110
    var response;
111
    var count;
112
    response = lookupRequest(dcp, '{"handle":' + handle_o + '}', true);
113
    assertEquals(handle_o, response.body.handle);
114
    count = 0;
115
    for (i in response.body.properties) {
116
      switch (response.body.properties[i].name) {
117
        case 'o':
118
          response.body.properties[i].ref = handle_o;
119
          count++;
120
          break;
121
        case 'p':
122
          response.body.properties[i].ref = handle_p;
123
          count++;
124
          break;
125
      }
126
    }
127
    assertEquals(2, count, 'Either "o" or "p" not found');
128
    response = lookupRequest(dcp, '{"handle":' + handle_p + '}', true);
129
    assertEquals(handle_p, response.body.handle);
130

    
131
    // Check handles for functions on the stack.
132
    var handle_f = evaluateRequest(dcp, '{"expression":"f"}');
133
    var handle_g = evaluateRequest(dcp, '{"expression":"g"}');
134
    var handle_caller = evaluateRequest(dcp, '{"expression":"f.caller"}');
135

    
136
    assertFalse(handle_f == handle_g, "f and g have he same handle");
137
    assertEquals(handle_g, handle_caller, "caller for f should be g");
138

    
139
    response = lookupRequest(dcp, '{"handle":' + handle_f + '}', true);
140
    assertEquals(handle_f, response.body.handle);
141
    count = 0;
142
    for (i in response.body.properties) {
143
      var arguments = '{"handle":' + response.body.properties[i].ref + '}'
144
      switch (response.body.properties[i].name) {
145
        case 'name':
146
          var response_name;
147
          response_name = lookupRequest(dcp, arguments, true);
148
          assertEquals('string', response_name.body.type);
149
          assertEquals("f", response_name.body.value);
150
          count++;
151
          break;
152
        case 'length':
153
          var response_length;
154
          response_length = lookupRequest(dcp, arguments, true);
155
          assertEquals('number', response_length.body.type);
156
          assertEquals(1, response_length.body.value);
157
          count++;
158
          break;
159
        case 'caller':
160
          assertEquals(handle_g, response.body.properties[i].ref);
161
          count++;
162
          break;
163
      }
164
    }
165
    assertEquals(3, count, 'Either "name", "length" or "caller" not found');
166

    
167

    
168
    // Indicate that all was processed.
169
    listenerComplete = true;
170
  }
171
  } catch (e) {
172
    exception = e
173
  };
174
};
175

    
176
// Add the debug event listener.
177
Debug.setListener(listener);
178

    
179
function f(a) {
180
  debugger;
181
};
182

    
183
function g(b) {
184
  f(b);
185
};
186

    
187
// Set a break point at return in f and invoke g to hit the breakpoint.
188
Debug.setBreakPoint(f, 2, 0);
189
o = {};
190
p = {}
191
o.o = o;
192
o.p = p;
193
p.o = o;
194
p.p = p;
195
g(o);
196

    
197
// Make sure that the debug event listener vas invoked.
198
assertTrue(listenerComplete, "listener did not run to completion");
199
assertFalse(exception, "exception in listener")