v8/test/mjsunit/code-coverage-utils.js
jgruber dc7abf3e21 [coverage] Support Yield and Async
The yield* statement when used in combination with async iterators is not
supported yet, as that is desugared into a more complex construct that doesn't
offer a good dedicated bytecode to attach the source range information yet.

Note that invocation counts of generator functions are incorrect as they count
each resumption as an individual call. See https://crbug.com/v8/6594.

Bug: v8:6000
Change-Id: I7ac7073473c9b64bb207cdbc4dab083ec1145656
Reviewed-on: https://chromium-review.googlesource.com/582690
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46890}
2017-07-26 09:04:42 +00:00

50 lines
1.3 KiB
JavaScript

// 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.
// Flags: --allow-natives-syntax
let TestCoverage;
let TestCoverageNoGC;
let nop;
let gen;
!function() {
function GetCoverage(source) {
for (var script of %DebugCollectCoverage()) {
if (script.script.source == source) return script;
}
return undefined;
};
function TestCoverageInternal(name, source, expectation, collect_garbage) {
source = source.trim();
eval(source);
if (collect_garbage) %CollectGarbage("collect dead objects");
var covfefe = GetCoverage(source);
var stringified_result = JSON.stringify(covfefe);
var stringified_expectation = JSON.stringify(expectation);
if (stringified_result != stringified_expectation) {
print(stringified_result.replace(/[}],[{]/g, "},\n {"));
}
assertEquals(stringified_expectation, stringified_result, name + " failed");
};
TestCoverage = function(name, source, expectation) {
TestCoverageInternal(name, source, expectation, true);
};
TestCoverageNoGC = function(name, source, expectation) {
TestCoverageInternal(name, source, expectation, false);
};
nop = function() {};
gen = function*() {
yield 1;
yield 2;
yield 3;
};
}();