|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
| 5 | +#include <include/dart_api.h> |
5 | 6 | #include "include/dart_tools_api.h" |
6 | 7 |
|
7 | 8 | #include "vm/class_finalizer.h" |
@@ -232,39 +233,50 @@ DART_EXPORT Dart_Handle Dart_SetBreakpoint(Dart_Handle script_url_in, |
232 | 233 | return Dart_NewInteger(bpt->id()); |
233 | 234 | } |
234 | 235 |
|
235 | | -DART_EXPORT Dart_Handle Dart_EvaluateExpr(Dart_Handle target_in, |
236 | | - Dart_Handle expr_in) { |
| 236 | +DART_EXPORT Dart_Handle Dart_EvaluateStaticExpr(Dart_Handle lib_handle, |
| 237 | + Dart_Handle expr_in) { |
237 | 238 | DARTSCOPE(Thread::Current()); |
238 | 239 | CHECK_DEBUGGER(T->isolate()); |
239 | 240 |
|
240 | | - const Object& target = Object::Handle(Z, Api::UnwrapHandle(target_in)); |
241 | | - if (target.IsError()) return target_in; |
| 241 | + const Object& target = Object::Handle(Z, Api::UnwrapHandle(lib_handle)); |
| 242 | + if (target.IsError()) return lib_handle; |
242 | 243 | if (target.IsNull()) { |
243 | 244 | return Api::NewError("%s expects argument 'target' to be non-null", |
244 | 245 | CURRENT_FUNC); |
245 | 246 | } |
| 247 | + const Library& lib = Library::Cast(target); |
246 | 248 | UNWRAP_AND_CHECK_PARAM(String, expr, expr_in); |
247 | | - // Type extends Instance, must check first. |
248 | | - if (target.IsType()) { |
249 | | - const Class& cls = Class::Handle(Z, Type::Cast(target).type_class()); |
250 | | - return Api::NewHandle( |
251 | | - T, cls.Evaluate(expr, Array::empty_array(), Array::empty_array())); |
252 | | - } else if (target.IsInstance()) { |
253 | | - const Instance& inst = Instance::Cast(target); |
254 | | - const Class& receiver_cls = Class::Handle(Z, inst.clazz()); |
255 | | - return Api::NewHandle( |
256 | | - T, inst.Evaluate(receiver_cls, expr, Array::empty_array(), |
257 | | - Array::empty_array())); |
258 | | - } else if (target.IsLibrary()) { |
259 | | - const Library& lib = Library::Cast(target); |
| 249 | + |
| 250 | + if (!KernelIsolate::IsRunning()) { |
260 | 251 | return Api::NewHandle( |
261 | 252 | T, lib.Evaluate(expr, Array::empty_array(), Array::empty_array())); |
262 | | - } else if (target.IsClass()) { |
263 | | - const Class& cls = Class::Cast(target); |
264 | | - return Api::NewHandle( |
265 | | - T, cls.Evaluate(expr, Array::empty_array(), Array::empty_array())); |
| 253 | + } else { |
| 254 | + Dart_KernelCompilationResult compilation_result; |
| 255 | + { |
| 256 | + TransitionVMToNative transition(T); |
| 257 | + compilation_result = KernelIsolate::CompileExpressionToKernel( |
| 258 | + expr.ToCString(), |
| 259 | + /* definitions= */ Array::empty_array(), |
| 260 | + /* type_defintions= */ Array::empty_array(), |
| 261 | + String::Handle(lib.url()).ToCString(), |
| 262 | + /* klass= */ nullptr, |
| 263 | + /* is_static= */ false); |
| 264 | + } |
| 265 | + if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { |
| 266 | + return Api::NewError("Failed to compile expression."); |
| 267 | + } |
| 268 | + |
| 269 | + const uint8_t* kernel_bytes = compilation_result.kernel; |
| 270 | + intptr_t kernel_length = compilation_result.kernel_size; |
| 271 | + return Api::NewHandle(T, lib.EvaluateCompiledExpression( |
| 272 | + kernel_bytes, kernel_length, |
| 273 | + /* type_definitions= */ |
| 274 | + Array::empty_array(), |
| 275 | + /* param_values= */ |
| 276 | + Array::empty_array(), |
| 277 | + /* type_param_values= */ |
| 278 | + TypeArguments::null_type_arguments())); |
266 | 279 | } |
267 | | - return Api::NewError("%s: unsupported target type", CURRENT_FUNC); |
268 | 280 | } |
269 | 281 |
|
270 | 282 | DART_EXPORT Dart_Handle Dart_GetLibraryIds() { |
|
0 commit comments