[vm] Fixes for flaky crashes when querying source or source location

There were no checks for missing source or source position, which
caused flaky crashes while running test mirrors/mirrors_reader_test.

Change-Id: I73497414ebe7b030ba308851038e0ef9e133aa48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/100781
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2019-04-29 22:10:38 +00:00 committed by commit-bot@chromium.org
parent c944328528
commit 0b9060ec1d
3 changed files with 15 additions and 8 deletions

View file

@ -1580,7 +1580,9 @@ DEFINE_NATIVE_ENTRY(DeclarationMirror_location, 0, 1) {
}
ASSERT(!script.IsNull());
ASSERT(token_pos != TokenPosition::kNoSource);
if (token_pos == TokenPosition::kNoSource) {
return Instance::null();
}
const String& uri = String::Handle(zone, script.url());
intptr_t from_line = 0;

View file

@ -7908,6 +7908,9 @@ RawString* Function::GetSource() const {
// (3) "var foo = () => null;": End token is `;', but in this case the
// token semicolon belongs to the assignment so we skip it.
const String& src = String::Handle(func_script.Source());
if (src.IsNull()) {
return Symbols::OptimizedOut().raw();
}
uint16_t end_char = src.CharAt(end_token_pos().value());
if ((end_char == ',') || // Case 1.
(end_char == ')') || // Case 2.
@ -9491,15 +9494,18 @@ void Script::GetTokenLocation(TokenPosition token_pos,
kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
line_starts_reader.LocationForPosition(token_pos.value(), line, column);
if (token_len != NULL) {
*token_len = 1;
// We don't explicitly save this data: Load the source
// and find it from there.
const String& source = String::Handle(zone, Source());
intptr_t offset = token_pos.value();
*token_len = 1;
if (offset < source.Length() && IsIdentStartChar(source.CharAt(offset))) {
for (intptr_t i = offset + 1;
i < source.Length() && IsIdentChar(source.CharAt(i)); ++i) {
++*token_len;
if (!source.IsNull()) {
intptr_t offset = token_pos.value();
if (offset < source.Length() &&
IsIdentStartChar(source.CharAt(offset))) {
for (intptr_t i = offset + 1;
i < source.Length() && IsIdentChar(source.CharAt(i)); ++i) {
++*token_len;
}
}
}
}

View file

@ -172,7 +172,6 @@ mirrors/method_mirror_source_test: RuntimeError # Issue 33041
mirrors/mirrors_nsm_mismatch_test: CompileTimeError # Issue 31533
mirrors/mirrors_nsm_test/dart2js: CompileTimeError # Issue 31533
mirrors/mirrors_nsm_test/none: CompileTimeError # Issue 31533
mirrors/mirrors_reader_test: Crash
mirrors/mirrors_test: RuntimeError
mirrors/mirrors_used*: SkipByDesign # Invalid tests. MirrorsUsed does not have a specification, and dart:mirrors is not required to hide declarations that are not covered by any MirrorsUsed annotation.
mirrors/mirrors_used_inheritance_test: RuntimeError