[ VM ] Fix crash when accessing metrics page when no metrics have been

logged

Fixes https://github.com/dart-lang/sdk/issues/44859.

TEST=regress_44859_test.dart

Change-Id: I7aa6b54f8f8d04b630d0ffe64d5414a6a9e56de2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183041
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Ben Konyi 2021-02-05 00:31:47 +00:00 committed by commit-bot@chromium.org
parent a7f84dc626
commit c039ff268f
3 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,18 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:observatory/service_io.dart';
import 'package:test/test.dart';
import 'test_helper.dart';
void script() {}
var tests = <IsolateTest>[
(Isolate isolate) async {
Map metrics = await isolate.refreshDartMetrics();
expect(metrics.length, 0);
},
];
main(args) => runIsolateTests(args, tests, testeeBefore: script);

View file

@ -0,0 +1,18 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:observatory_2/service_io.dart';
import 'package:test/test.dart';
import 'test_helper.dart';
void script() {}
var tests = <IsolateTest>[
(Isolate isolate) async {
Map metrics = await isolate.refreshDartMetrics();
expect(metrics.length, 0);
},
];
main(args) => runIsolateTests(args, tests, testeeBefore: script);

View file

@ -3584,6 +3584,8 @@ static bool HandleNativeMetric(Thread* thread, JSONStream* js, const char* id) {
static bool HandleDartMetricsList(Thread* thread, JSONStream* js) {
Zone* zone = thread->zone();
const Class& metrics_cls = Class::Handle(zone, GetMetricsClass(thread));
const auto& error = metrics_cls.EnsureIsFinalized(Thread::Current());
ASSERT(error == Error::null());
const String& print_metrics_name =
String::Handle(String::New("_printMetrics"));
ASSERT(!print_metrics_name.IsNull());