[vm] Fix incorrect is_static argument passed to expression evaluation

Previously, KernelIsolate::CompileExpressionToKernel was called
with is_static == false and klass == nullptr, which doesn't make sense:
this call requested to compile expression inside instance method context but
without enclosing class. This results in a malformed kernel AST and crash
in bytecode generator.

Fixes vm/cc/LinkedHashMap and vm/cc/Service_* tests in bytecode mode.

Change-Id: I121b0cb0e149d378d6b12e9861ef941513e1e199
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112024
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2019-08-06 17:10:50 +00:00 committed by commit-bot@chromium.org
parent 47ee568c52
commit 4a20be4816
4 changed files with 8 additions and 4 deletions

View file

@ -185,7 +185,7 @@ DART_EXPORT Dart_Handle Dart_EvaluateStaticExpr(Dart_Handle lib_handle,
/* type_defintions= */ Array::empty_array(),
String::Handle(lib.url()).ToCString(),
/* klass= */ nullptr,
/* is_static= */ false);
/* is_static= */ true);
if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
return Api::NewError("Failed to compile expression.");
}

View file

@ -892,6 +892,7 @@ Dart_KernelCompilationResult KernelIsolate::CompileExpressionToKernel(
TransitionVMToNative transition(Thread::Current());
KernelCompilationRequest request;
ASSERT(is_static || (klass != nullptr));
return request.SendAndWaitForResponse(kernel_port, expression, definitions,
type_definitions, library_url, klass,
is_static, experimental_flags_);

View file

@ -2656,11 +2656,12 @@ static bool BuildExpressionEvaluationScope(Thread* thread, JSONStream* js) {
klass_name = cls.UserVisibleName();
}
library_uri = Library::Handle(zone, cls.library()).url();
isStatic = !cls.IsTopLevel();
isStatic = true;
} else {
const Class& method_cls = Class::Handle(zone, frame->function().origin());
library_uri = Library::Handle(zone, method_cls.library()).url();
klass_name = method_cls.UserVisibleName();
isStatic = false;
}
} else {
// building scope in the context of a given object
@ -2810,7 +2811,9 @@ static bool CompileExpression(Thread* thread, JSONStream* js) {
return true;
}
bool is_static = BoolParameter::Parse(js->LookupParam("isStatic"), false);
const char* klass = js->LookupParam("klass");
bool is_static =
BoolParameter::Parse(js->LookupParam("isStatic"), (klass == nullptr));
const GrowableObjectArray& params =
GrowableObjectArray::Handle(thread->zone(), GrowableObjectArray::New());

View file

@ -680,7 +680,7 @@ Dart_Handle TestCase::EvaluateExpression(const Library& lib,
KernelIsolate::CompileExpressionToKernel(
expr.ToCString(), param_names, Array::empty_array(),
String::Handle(lib.url()).ToCString(), /* klass=*/nullptr,
/* is_static= */ false);
/* is_static= */ true);
if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
return Api::NewError("%s", compilation_result.error);
}