framework-break.js 8.02 KB
Newer Older
1 2 3
// 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.
4
// Flags: --allow-natives-syntax
5

6
let {session, contextGroup, Protocol} = InspectorTest.start('Checks that breaks in framework code correctly processed.');
7

8 9
contextGroup.addInlineScript(
    `
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
function frameworkAssert() {
  console.assert(false);
}

function throwCaughtError() {
  try {
    throw new Error();
  } catch (e) {
  }
}

function throwUncaughtError() {
  throw new Error();
}

function breakpoint() {
  return 239;
}

function debuggerStatement() {
  debugger;
}

function syncDOMBreakpoint() {
34
  inspector.breakProgram('', '');
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
}

function asyncDOMBreakpoint() {
  return 42;
}

function throwCaughtSyntaxError() {
  try {
    eval('}');
  } catch (e) {
  }
}

function throwFromJSONParse() {
  try {
    JSON.parse('ping');
  } catch (e) {
  }
}

55 56 57 58
function throwInlinedUncaughtError() {
  function inlinedWrapper() {
    throwUserException();
  }
59
  %PrepareFunctionForOptimization(inlinedWrapper);
60 61 62 63
  %OptimizeFunctionOnNextCall(inlinedWrapper);
  inlinedWrapper();
}

64 65 66 67
function syncDOMBreakpointWithInlinedUserFrame() {
  function inlinedWrapper() {
    userFunction();
  }
68
  %PrepareFunctionForOptimization(inlinedWrapper);
69 70
  %OptimizeFunctionOnNextCall(inlinedWrapper);
  inlinedWrapper();
71 72
}`,
    'framework.js');
73

74 75
contextGroup.addInlineScript(
    `
76 77 78
function throwUserException() {
  throw new Error();
}
79 80 81

function userFunction() {
  syncDOMBreakpoint();
82 83
}`,
    'user.js');
84

85
session.setupScriptMap();
86
Protocol.Debugger.onPaused(message => {
87
  session.logCallFrames(message.params.callFrames);
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
  InspectorTest.log('');
  Protocol.Debugger.resume();
});

Protocol.Debugger.enable();
Protocol.Debugger.setBlackboxPatterns({patterns: ['framework\.js']});

InspectorTest.runTestSuite([
  function testConsoleAssert(next) {
    Protocol.Debugger.setPauseOnExceptions({state: 'all'})
        .then(() => InspectorTest.log('> all frames in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'frameworkAssert()//# sourceURL=framework.js'}))
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'frameworkAssert()//# sourceURL=user.js'}))
        .then(() => Protocol.Debugger.setPauseOnExceptions({state: 'none'}))
        .then(next);
  },

  function testCaughtException(next) {
    Protocol.Debugger.setPauseOnExceptions({state: 'all'})
        .then(() => InspectorTest.log('> all frames in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'throwCaughtError()//# sourceURL=framework.js'}))
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'throwCaughtError()//# sourceURL=user.js'}))
        .then(() => Protocol.Debugger.setPauseOnExceptions({state: 'none'}))
        .then(next);
  },

  function testUncaughtException(next) {
    Protocol.Debugger.setPauseOnExceptions({state: 'all'})
        .then(() => InspectorTest.log('> all frames in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
129 130
                {expression: 'setTimeout(\'throwUncaughtError()//# sourceURL=framework.js\', 0)//# sourceURL=framework.js'}))
        .then(() => Protocol.Runtime.evaluate({ expression: "new Promise(resolve => setTimeout(resolve, 0))", awaitPromise: true}))
131 132 133
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
134 135
                {expression: 'setTimeout(\'throwUncaughtError()//# sourceURL=user.js\', 0)'}))
        .then(() => Protocol.Runtime.evaluate({ expression: "new Promise(resolve => setTimeout(resolve, 0))", awaitPromise: true}))
136 137 138 139
        .then(() => Protocol.Debugger.setPauseOnExceptions({state: 'none'}))
        .then(next);
  },

140 141 142 143 144 145 146 147 148 149
  function testUncaughtExceptionWithInlinedFrame(next) {
    Protocol.Debugger.setPauseOnExceptions({state: 'all'})
        .then(() => InspectorTest.log('> mixed top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'setTimeout(\'throwInlinedUncaughtError()//# sourceURL=framework.js\', 0)//# sourceURL=framework.js'}))
        .then(() => Protocol.Runtime.evaluate({ expression: "new Promise(resolve => setTimeout(resolve, 0))", awaitPromise: true}))
        .then(next);
  },

150
  function testBreakpoint(next) {
151
    Protocol.Debugger.setBreakpointByUrl({lineNumber: 25, url: 'framework.js'})
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
        .then(() => InspectorTest.log('> all frames in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'breakpoint()//# sourceURL=framework.js'}))
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'breakpoint()//# sourceURL=user.js'}))
        .then(next);
  },

  function testDebuggerStatement(next) {
    InspectorTest.log('> all frames in framework:');
    Protocol.Runtime
        .evaluate({expression: 'debuggerStatement()//# sourceURL=framework.js'})
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'debuggerStatement()//# sourceURL=user.js'}))
        .then(next);
  },

  function testSyncDOMBreakpoint(next) {
    InspectorTest.log('> all frames in framework:');
    Protocol.Runtime
        .evaluate({expression: 'syncDOMBreakpoint()//# sourceURL=framework.js'})
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'syncDOMBreakpoint()//# sourceURL=user.js'}))
        .then(next);
  },

185 186 187 188 189 190 191
  function testSyncDOMBreakpointWithInlinedUserFrame(next) {
    InspectorTest.log('> mixed, top frame in framework:');
    Protocol.Runtime
        .evaluate({expression: 'syncDOMBreakpointWithInlinedUserFrame()//# sourceURL=framework.js'})
        .then(next);
  },

192
  function testAsyncDOMBreakpoint(next) {
193
    contextGroup.schedulePauseOnNextStatement('', '');
194 195 196 197
    InspectorTest.log('> all frames in framework:');
    Protocol.Runtime
        .evaluate(
            {expression: 'asyncDOMBreakpoint()//# sourceURL=framework.js'})
198
        .then(() => contextGroup.cancelPauseOnNextStatement())
199 200 201
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: '42//# sourceURL=user.js'}))
202
        .then(() => contextGroup.schedulePauseOnNextStatement('', ''))
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'asyncDOMBreakpoint()//# sourceURL=user.js'}))
        .then(next);
  },

  function testCaughtSyntaxError(next) {
    Protocol.Debugger.setPauseOnExceptions({state: 'all'})
        .then(() => InspectorTest.log('> all frames in framework:'))
        .then(() => Protocol.Runtime.evaluate({
          expression: 'throwCaughtSyntaxError()//# sourceURL=framework.js'
        }))
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'throwCaughtSyntaxError()//# sourceURL=user.js'}))
        .then(() => Protocol.Debugger.setPauseOnExceptions({state: 'none'}))
        .then(next);
  },

  function testCaughtJSONParseError(next) {
    Protocol.Debugger.setPauseOnExceptions({state: 'all'})
        .then(() => InspectorTest.log('> all frames in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'throwFromJSONParse()//# sourceURL=framework.js'}))
        .then(() => InspectorTest.log('> mixed, top frame in framework:'))
        .then(
            () => Protocol.Runtime.evaluate(
                {expression: 'throwFromJSONParse()//# sourceURL=user.js'}))
        .then(() => Protocol.Debugger.setPauseOnExceptions({state: 'none'}))
        .then(next);
  }
]);