[VM] Be more defensive against constants coming from vmservice library (if we skip it)

Change-Id: I23900daadf030dcf46cec11008ec15e43245040f
Reviewed-on: https://dart-review.googlesource.com/52804
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Martin Kustermann 2018-04-30 10:57:45 +00:00 committed by commit-bot@chromium.org
parent c164f92397
commit 690b4f793b
3 changed files with 40 additions and 18 deletions

View file

@ -10852,8 +10852,13 @@ const Array& ConstantHelper::ReadConstantTable() {
break;
}
case kInstanceConstant: {
temp_class_ =
H.LookupClassByKernelClass(builder_.ReadCanonicalNameReference());
const NameIndex index = builder_.ReadCanonicalNameReference();
if (ShouldSkipConstant(index)) {
temp_instance_ = Instance::null();
break;
}
temp_class_ = H.LookupClassByKernelClass(index);
temp_object_ = temp_class_.EnsureIsFinalized(H.thread());
ASSERT(temp_object_.IsNull());
@ -10889,16 +10894,19 @@ const Array& ConstantHelper::ReadConstantTable() {
const intptr_t entry_index = builder_.ReadUInt();
temp_object_ = constants.At(entry_index);
// Happens if the tearoff was in the vmservice library and we have
// [skip_vm_service_library] enabled.
if (temp_object_.IsNull()) {
temp_instance_ = Instance::null();
break;
}
const intptr_t number_of_type_arguments = builder_.ReadUInt();
if (temp_class_.NumTypeArguments() > 0) {
temp_type_arguments_ =
TypeArguments::New(number_of_type_arguments, Heap::kOld);
for (intptr_t j = 0; j < number_of_type_arguments; ++j) {
temp_type_arguments_.SetTypeAt(j, type_translator_.BuildType());
}
} else {
ASSERT(number_of_type_arguments == 0);
temp_type_arguments_ = TypeArguments::null();
ASSERT(number_of_type_arguments > 0);
temp_type_arguments_ =
TypeArguments::New(number_of_type_arguments, Heap::kOld);
for (intptr_t j = 0; j < number_of_type_arguments; ++j) {
temp_type_arguments_.SetTypeAt(j, type_translator_.BuildType());
}
// Make a copy of the old closure, with the delayed type arguments
@ -10916,12 +10924,7 @@ const Array& ConstantHelper::ReadConstantTable() {
}
case kTearOffConstant: {
const NameIndex index = builder_.ReadCanonicalNameReference();
NameIndex lib_index = index;
while (!H.IsLibrary(lib_index)) {
lib_index = H.CanonicalNameParent(lib_index);
}
ASSERT(H.IsLibrary(lib_index));
if (lib_index == skip_vmservice_library_) {
if (ShouldSkipConstant(index)) {
temp_instance_ = Instance::null();
break;
}
@ -10960,6 +10963,19 @@ void ConstantHelper::InstantiateTypeArguments(const Class& receiver_class,
*type_arguments = temp_type_.arguments();
}
// If [index] has `dart:vm_service` as a parent and we are skipping the VM
// service library, this method returns `true`, otherwise `false`.
bool ConstantHelper::ShouldSkipConstant(NameIndex index) {
if (index == NameIndex::kInvalidName) {
return false;
}
while (!H.IsLibrary(index)) {
index = H.CanonicalNameParent(index);
}
ASSERT(H.IsLibrary(index));
return index == skip_vmservice_library_;
}
} // namespace kernel
} // namespace dart

View file

@ -1704,6 +1704,10 @@ class ConstantHelper {
void InstantiateTypeArguments(const Class& receiver_class,
TypeArguments* type_arguments);
// If [index] has `dart:vm_service` as a parent and we are skipping the VM
// service library, this method returns `true`, otherwise `false`.
bool ShouldSkipConstant(NameIndex index);
NameIndex skip_vmservice_library_;
ActiveClass* active_class_;
StreamingFlowGraphBuilder& builder_;

View file

@ -16,7 +16,9 @@ namespace dart {
namespace kernel {
class NameIndex {
public:
NameIndex() : value_(-1) {}
static const int kInvalidName = -1;
NameIndex() : value_(kInvalidName) {}
explicit NameIndex(int value) : value_(value) {}
operator int() const { return value_; }