| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var source = | 5 var source = |
| 6 ` | 6 ` |
| 7 function fib(x) { | 7 function fib(x) { |
| 8 if (x < 2) return 1; | 8 if (x < 2) return 1; |
| 9 return fib(x-1) + fib(x-2); | 9 return fib(x-1) + fib(x-2); |
| 10 } | 10 } |
| 11 (function iife() { | 11 (function iife() { |
| 12 return 1; | 12 return 1; |
| 13 })(); | 13 })(); |
| 14 fib(5); | 14 fib(5); |
| 15 `; | 15 `; |
| 16 | 16 |
| 17 print("Test collecting code coverage data with Runtime.collectCoverage."); | 17 print("Test collecting code coverage data with Profiler.collectCoverage."); |
| 18 | 18 |
| 19 function ClearAndGC() { | 19 function ClearAndGC() { |
| 20 return Protocol.Runtime.evaluate({ expression: "fib = null;" }) | 20 return Protocol.Runtime.evaluate({ expression: "fib = null;" }) |
| 21 .then(() => Protocol.HeapProfiler.enable()) | 21 .then(() => Protocol.HeapProfiler.enable()) |
| 22 .then(() => Protocol.HeapProfiler.collectGarbage()) | 22 .then(() => Protocol.HeapProfiler.collectGarbage()) |
| 23 .then(() => Protocol.HeapProfiler.disable()); | 23 .then(() => Protocol.HeapProfiler.disable()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 InspectorTest.runTestSuite([ | 26 InspectorTest.runTestSuite([ |
| 27 function testPreciseCoverage(next) | 27 function testPreciseCoverage(next) |
| 28 { | 28 { |
| 29 Protocol.Runtime.enable() | 29 Protocol.Runtime.enable() |
| 30 .then(Protocol.Runtime.startPreciseCoverage) | 30 .then(Protocol.Profiler.enable) |
| 31 .then(Protocol.Profiler.startPreciseCoverage) |
| 31 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "1", persistScript: true })) | 32 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "1", persistScript: true })) |
| 32 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 33 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 33 .then(ClearAndGC) | 34 .then(ClearAndGC) |
| 34 .then(InspectorTest.logMessage) | 35 .then(InspectorTest.logMessage) |
| 35 .then(Protocol.Runtime.takePreciseCoverage) | 36 .then(Protocol.Profiler.takePreciseCoverage) |
| 36 .then(InspectorTest.logMessage) | 37 .then(InspectorTest.logMessage) |
| 37 .then(Protocol.Runtime.takePreciseCoverage) | 38 .then(Protocol.Profiler.takePreciseCoverage) |
| 38 .then(InspectorTest.logMessage) | 39 .then(InspectorTest.logMessage) |
| 39 .then(ClearAndGC) | 40 .then(ClearAndGC) |
| 40 .then(Protocol.Runtime.stopPreciseCoverage) | 41 .then(Protocol.Profiler.stopPreciseCoverage) |
| 42 .then(Protocol.Profiler.disable) |
| 41 .then(Protocol.Runtime.disable) | 43 .then(Protocol.Runtime.disable) |
| 42 .then(next); | 44 .then(next); |
| 43 }, | 45 }, |
| 44 function testPreciseCoverageFail(next) | 46 function testPreciseCoverageFail(next) |
| 45 { | 47 { |
| 46 Protocol.Runtime.enable() | 48 Protocol.Runtime.enable() |
| 49 .then(Protocol.Profiler.enable) |
| 47 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "2", persistScript: true })) | 50 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "2", persistScript: true })) |
| 48 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 51 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 49 .then(InspectorTest.logMessage) | 52 .then(InspectorTest.logMessage) |
| 50 .then(ClearAndGC) | 53 .then(ClearAndGC) |
| 51 .then(Protocol.Runtime.takePreciseCoverage) | 54 .then(Protocol.Profiler.takePreciseCoverage) |
| 52 .then(InspectorTest.logMessage) | 55 .then(InspectorTest.logMessage) |
| 53 .then(ClearAndGC) | 56 .then(ClearAndGC) |
| 57 .then(Protocol.Profiler.disable) |
| 54 .then(Protocol.Runtime.disable) | 58 .then(Protocol.Runtime.disable) |
| 55 .then(next); | 59 .then(next); |
| 56 }, | 60 }, |
| 57 function testBestEffortCoverage(next) | 61 function testBestEffortCoverage(next) |
| 58 { | 62 { |
| 59 Protocol.Runtime.enable() | 63 Protocol.Runtime.enable() |
| 60 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "3", persistScript: true })) | 64 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "3", persistScript: true })) |
| 61 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 65 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 62 .then(InspectorTest.logMessage) | 66 .then(InspectorTest.logMessage) |
| 63 .then(ClearAndGC) | 67 .then(ClearAndGC) |
| 64 .then(Protocol.Runtime.getBestEffortCoverage) | 68 .then(Protocol.Profiler.getBestEffortCoverage) |
| 65 .then(InspectorTest.logMessage) | 69 .then(InspectorTest.logMessage) |
| 66 .then(Protocol.Runtime.getBestEffortCoverage) | 70 .then(Protocol.Profiler.getBestEffortCoverage) |
| 67 .then(InspectorTest.logMessage) | 71 .then(InspectorTest.logMessage) |
| 68 .then(ClearAndGC) | 72 .then(ClearAndGC) |
| 69 .then(Protocol.Runtime.disable) | 73 .then(Protocol.Runtime.disable) |
| 70 .then(next); | 74 .then(next); |
| 71 }, | 75 }, |
| 72 function testBestEffortCoveragePrecise(next) | 76 function testBestEffortCoveragePrecise(next) |
| 73 { | 77 { |
| 74 Protocol.Runtime.enable() | 78 Protocol.Runtime.enable() |
| 75 .then(Protocol.Runtime.startPreciseCoverage) | 79 .then(Protocol.Profiler.enable) |
| 80 .then(Protocol.Profiler.startPreciseCoverage) |
| 76 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "4", persistScript: true })) | 81 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "4", persistScript: true })) |
| 77 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 82 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 78 .then(InspectorTest.logMessage) | 83 .then(InspectorTest.logMessage) |
| 79 .then(ClearAndGC) | 84 .then(ClearAndGC) |
| 80 .then(Protocol.Runtime.getBestEffortCoverage) | 85 .then(Protocol.Profiler.getBestEffortCoverage) |
| 81 .then(InspectorTest.logMessage) | 86 .then(InspectorTest.logMessage) |
| 82 .then(Protocol.Runtime.getBestEffortCoverage) | 87 .then(Protocol.Profiler.getBestEffortCoverage) |
| 83 .then(InspectorTest.logMessage) | 88 .then(InspectorTest.logMessage) |
| 84 .then(ClearAndGC) | 89 .then(ClearAndGC) |
| 85 .then(Protocol.Runtime.stopPreciseCoverage) | 90 .then(Protocol.Profiler.stopPreciseCoverage) |
| 91 .then(Protocol.Profiler.disable) |
| 86 .then(Protocol.Runtime.disable) | 92 .then(Protocol.Runtime.disable) |
| 87 .then(next); | 93 .then(next); |
| 88 }, | 94 }, |
| 89 ]); | 95 ]); |
| OLD | NEW |