script-parsed-for-runtime-evaluate.js 2.88 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5
let {session, contextGroup, Protocol} = InspectorTest.start("Checks that inspector reports script compiled in Runtime.evaluate, " +
6 7
  "Runtime.callFunctionOn and  Runtime.compileScript");

8
contextGroup.addScript(`
9 10 11 12 13 14 15 16 17
function fooTop() {
  eval(\`
    function foo() {
      eval("({})")
    }
    foo() //# sourceURL=second-frame.js\`);
}
//# sourceURL=top-frame.js`, 8, 26);

18
contextGroup.addScript(`
19 20 21 22 23 24 25 26 27
function fooTopFail() {
  eval(\`
    function fooFail() {
      eval("({}")
    }
    fooFail() //# sourceURL=second-frame-fail.js\`);
}
//# sourceURL=top-frame-fail.js`, 18, 26);

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
Promise.prototype.thenLog = function log(message) {
  return this.then(() => InspectorTest.log(message));
}

var objectId;
Protocol.Runtime.enable();
Protocol.Debugger.enable()
  .then(() => Protocol.Debugger.onScriptParsed(InspectorTest.logMessage))
  .then(() => Protocol.Debugger.onScriptFailedToParse(InspectorTest.logMessage))

  .thenLog('Runtime.evaluate with valid expression')
  .then(() => Protocol.Runtime.evaluate({
    expression: "({})//# sourceURL=evaluate.js"}))
  .then(msg => objectId = msg.result.result.objectId)

  .thenLog('Runtime.evaluate with syntax error')
  .then(() => Protocol.Runtime.evaluate({
    expression: "}//# sourceURL=evaluate-syntax-error.js"}))

  .thenLog('Runtime.callFunctionOn with valid functionDeclaration')
  .then(() => Protocol.Runtime.callFunctionOn({ objectId: objectId,
    functionDeclaration: "function foo(){}"}))

  .thenLog('Runtime.callFunctionOn with syntax error')
  .then(() => Protocol.Runtime.callFunctionOn({ objectId: objectId,
    functionDeclaration: "}"}))

  .thenLog('Runtime.compileScript with valid expression')
  .then(() => Protocol.Runtime.compileScript({ expression: "({})",
    sourceURL: "compile-script.js", persistScript: true }))

  .thenLog('Runtime.compileScript with syntax error')
  .then(() => Protocol.Runtime.compileScript({ expression: "}",
    sourceURL: "compile-script-syntax-error.js", persistScript: true }))

  .thenLog('Runtime.compileScript persistScript: false (should be no script events)')
  .then(() => Protocol.Runtime.compileScript({ expression: "({})",
    sourceURL: "compile-script-syntax-error.js", persistScript: false }))
  .then(() => Protocol.Runtime.compileScript({ expression: "}",
    sourceURL: "compile-script-syntax-error.js", persistScript: false }))

69 70 71 72 73 74 75 76 77 78
  .thenLog('Runtime.evaluate compiled script with stack trace')
  .then(() => Protocol.Runtime.evaluate({
    expression: "fooTop()"}))
  .then(msg => objectId = msg.result.result.objectId)

  .thenLog('Runtime.evaluate compile script error with stack trace')
  .then(() => Protocol.Runtime.evaluate({
    expression: "fooTopFail()"}))
  .then(msg => objectId = msg.result.result.objectId)

79
  .then(InspectorTest.completeTest);