summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/runtime/command-line-api.js
blob: 16abde45e94398d5147297b705675fc29b2bb259 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

let {session, contextGroup, Protocol} = InspectorTest.start('Checks command line API.');

InspectorTest.runAsyncTestSuite([
  async function testKeys() {
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({
      expression: 'keys', includeCommandLineAPI: true}));
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({
      expression: 'keys({a : 1})', includeCommandLineAPI: true, returnByValue: true}));

    Protocol.Runtime.evaluate({expression: 'this.keys = keys', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({
      expression: 'this.keys({a : 1})', returnByValue: true}));
  },

  async function testInspect() {
    InspectorTest.log(await Protocol.Runtime.evaluate({expression: 'inspect', includeCommandLineAPI: true}));
    await Protocol.Runtime.enable();
    Protocol.Runtime.onInspectRequested(InspectorTest.logMessage);
    await Protocol.Runtime.evaluate({expression: 'inspect({})', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({expression: 'inspect(239)', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({expression: 'inspect(-0)', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({expression: 'copy(\'hello\')', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$0', includeCommandLineAPI: true}));

    Protocol.Runtime.evaluate({expression: 'this.inspect = inspect', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({expression: 'this.inspect({})'});

    Protocol.Runtime.onInspectRequested(null);
    await Protocol.Runtime.disable();
  },

  async function testEvaluationResult() {
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true}));
    await Protocol.Runtime.evaluate({expression: '42', objectGroup: 'console', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true}));
    await Protocol.Runtime.evaluate({expression: '239', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true}));
    await Protocol.Runtime.evaluate({expression: '-0', objectGroup: 'console', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true}));
    await Protocol.Runtime.evaluate({expression: '({})', objectGroup: 'console', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: '$_', includeCommandLineAPI: true, returnByValue: true}));
  },

  async function testDebug() {
    session.setupScriptMap();
    await Protocol.Debugger.enable();
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'debug', includeCommandLineAPI: true}));
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'undebug', includeCommandLineAPI: true}));
    await Protocol.Runtime.evaluate({expression: 'function foo() {}'});
    await Protocol.Runtime.evaluate({expression: 'debug(foo)', includeCommandLineAPI: true});
    Protocol.Runtime.evaluate({ expression: 'foo()'});
    let message = await Protocol.Debugger.oncePaused();
    session.logCallFrames(message.params.callFrames);
    InspectorTest.logMessage(message.params.hitBreakpoints);
    await Protocol.Debugger.resume();
    await Protocol.Runtime.evaluate({expression: 'undebug(foo)', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({ expression: 'foo()'});

    Protocol.Runtime.evaluate({
      expression: 'this.debug = debug; this.undebug = undebug;', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({expression: 'this.debug(foo)'});
    Protocol.Runtime.evaluate({ expression: 'foo()'});
    message = await Protocol.Debugger.oncePaused();
    session.logCallFrames(message.params.callFrames);
    InspectorTest.logMessage(message.params.hitBreakpoints);
    await Protocol.Debugger.resume();
    await Protocol.Runtime.evaluate({expression: 'this.undebug(foo)'});
    await Protocol.Runtime.evaluate({expression: 'foo()'});

    await Protocol.Debugger.disable();
  },

  async function testMonitor() {
    await Protocol.Debugger.enable();
    await Protocol.Runtime.enable();
    Protocol.Runtime.onConsoleAPICalled(message => InspectorTest.log(message.params.args[0].value));
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'monitor', includeCommandLineAPI: true}));
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'unmonitor', includeCommandLineAPI: true}));
    await Protocol.Runtime.evaluate({expression: 'function foo() {}'});

    await Protocol.Runtime.evaluate({expression: 'monitor(foo)', includeCommandLineAPI: true});
    Protocol.Runtime.evaluate({ expression: 'foo(); console.log(\'after first call\')'});
    await Protocol.Runtime.evaluate({expression: 'unmonitor(foo)', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({ expression: 'foo()'});

    Protocol.Runtime.evaluate({
      expression: 'console.log(\'store functions..\'); this.monitor = monitor; this.unmonitor = unmonitor;', includeCommandLineAPI: true});
    await Protocol.Runtime.evaluate({expression: 'this.monitor(foo)'});
    Protocol.Runtime.evaluate({ expression: 'foo(); console.log(\'after first call\')'});
    await Protocol.Runtime.evaluate({expression: 'this.unmonitor(foo)'});
    await Protocol.Runtime.evaluate({ expression: 'foo()'});

    Protocol.Runtime.onConsoleAPICalled(null);
    await Protocol.Debugger.disable();
    await Protocol.Runtime.disable();
  },

  async function testProfile() {
    await Protocol.Profiler.enable();
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'profile', includeCommandLineAPI: true}));
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'profileEnd', includeCommandLineAPI: true}));

    Protocol.Runtime.evaluate({expression: 'profile(42)', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Profiler.onceConsoleProfileStarted());
    Protocol.Runtime.evaluate({expression: 'profileEnd(42)', includeCommandLineAPI: true});
    let message = await Protocol.Profiler.onceConsoleProfileFinished();
    message.params.profile = '<profile>';
    InspectorTest.logMessage(message);

    Protocol.Runtime.evaluate({
      expression: 'this.profile = profile; this.profileEnd = profileEnd;', includeCommandLineAPI: true});
    Protocol.Runtime.evaluate({expression: 'this.profile(239)'});
    InspectorTest.logMessage(await Protocol.Profiler.onceConsoleProfileStarted());
    Protocol.Runtime.evaluate({expression: 'this.profileEnd(239)'});
    message = await Protocol.Profiler.onceConsoleProfileFinished();
    message.params.profile = '<profile>';
    InspectorTest.logMessage(message);

    await Protocol.Profiler.disable();
  },

  async function testDir() {
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'dir', includeCommandLineAPI: true}));

    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'dir({})', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    Protocol.Runtime.evaluate({expression: 'dir(42)', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

    Protocol.Runtime.evaluate({expression: 'this.dir = dir', includeCommandLineAPI: true});
    Protocol.Runtime.evaluate({expression: 'this.dir({})'});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    await Protocol.Runtime.disable();
  },

  async function testDirXML() {
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'dirxml', includeCommandLineAPI: true}));

    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'dirxml({})', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    Protocol.Runtime.evaluate({expression: 'dirxml(42)', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    await Protocol.Runtime.disable();
  },

  async function testTable() {
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'table', includeCommandLineAPI: true}));

    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'table({})', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    Protocol.Runtime.evaluate({expression: 'table(42)', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    await Protocol.Runtime.disable();
  },

  async function testClear() {
    InspectorTest.logMessage(await Protocol.Runtime.evaluate({expression: 'clear', includeCommandLineAPI: true}));

    await Protocol.Runtime.enable();
    Protocol.Runtime.evaluate({expression: 'clear()', includeCommandLineAPI: true});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

    Protocol.Runtime.evaluate({expression: 'this.clear = clear', includeCommandLineAPI: true});
    Protocol.Runtime.evaluate({expression: 'this.clear()'});
    InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());
    await Protocol.Runtime.disable();
  }
]);