| Index: src/debug/debug-coverage.cc
|
| diff --git a/src/debug/debug-coverage.cc b/src/debug/debug-coverage.cc
|
| index 76a88b095271869710c78341055f9520de283e0a..4fdc98c305b4944d67cb15ab80fd08b20dcaa0d1 100644
|
| --- a/src/debug/debug-coverage.cc
|
| +++ b/src/debug/debug-coverage.cc
|
| @@ -58,11 +58,6 @@ bool CompareSharedFunctionInfo(SharedFunctionInfo* a, SharedFunctionInfo* b) {
|
| }
|
| } // anonymous namespace
|
|
|
| -CoverageScript::CoverageScript(Isolate* isolate, Handle<Script> s,
|
| - int source_length)
|
| - : script(s),
|
| - toplevel(0, source_length, 1, isolate->factory()->empty_string()) {}
|
| -
|
| Coverage* Coverage::Collect(Isolate* isolate) {
|
| SharedToCounterMap counter_map;
|
|
|
| @@ -101,47 +96,39 @@ Coverage* Coverage::Collect(Isolate* isolate) {
|
| if (script->type() != Script::TYPE_NORMAL) continue;
|
|
|
| // Create and add new script data.
|
| - int source_end = String::cast(script->source())->length();
|
| Handle<Script> script_handle(script, isolate);
|
| - result->emplace_back(isolate, script_handle, source_end);
|
| + result->emplace_back(isolate, script_handle);
|
| + std::vector<CoverageFunction>* functions = &result->back().functions;
|
|
|
| std::vector<SharedFunctionInfo*> sorted;
|
| + bool has_toplevel = false;
|
|
|
| {
|
| - // Collect a list of shared function infos sorted by start position.
|
| - // Shared function infos are usually already sorted. Except for classes.
|
| - // If the start position is the same, sort from outer to inner function.
|
| + // Sort functions by start position, from outer to inner functions.
|
| SharedFunctionInfo::ScriptIterator infos(script_handle);
|
| - while (SharedFunctionInfo* info = infos.Next()) sorted.push_back(info);
|
| + while (SharedFunctionInfo* info = infos.Next()) {
|
| + has_toplevel |= info->is_toplevel();
|
| + sorted.push_back(info);
|
| + }
|
| std::sort(sorted.begin(), sorted.end(), CompareSharedFunctionInfo);
|
| }
|
|
|
| - std::vector<CoverageRange*> stack;
|
| - stack.push_back(&result->back().toplevel);
|
| + functions->reserve(sorted.size() + (has_toplevel ? 0 : 1));
|
| +
|
| + if (!has_toplevel) {
|
| + // Add a replacement toplevel function if it does not exist.
|
| + int source_end = String::cast(script->source())->length();
|
| + functions->emplace_back(0, source_end, 1u,
|
| + isolate->factory()->empty_string());
|
| + }
|
|
|
| // Use sorted list to reconstruct function nesting.
|
| for (SharedFunctionInfo* info : sorted) {
|
| int start = StartPosition(info);
|
| int end = info->end_position();
|
| uint32_t count = counter_map.Get(info);
|
| - if (info->is_toplevel()) {
|
| - // Top-level function is available.
|
| - DCHECK_EQ(1, stack.size());
|
| - result->back().toplevel.start = start;
|
| - result->back().toplevel.end = end;
|
| - result->back().toplevel.count = count;
|
| - } else {
|
| - // The shared function infos are sorted by start.
|
| - DCHECK_LE(stack.back()->start, start);
|
| - // Drop the stack to the outer function.
|
| - while (start >= stack.back()->end) stack.pop_back();
|
| - CoverageRange* outer = stack.back();
|
| - // New nested function.
|
| - DCHECK_LE(end, outer->end);
|
| - Handle<String> name(info->DebugName(), isolate);
|
| - outer->inner.emplace_back(start, end, count, name);
|
| - stack.push_back(&outer->inner.back());
|
| - }
|
| + Handle<String> name(info->DebugName(), isolate);
|
| + functions->emplace_back(start, end, count, name);
|
| }
|
| }
|
| return result;
|
|
|