| 1 | // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #include "vm/bootstrap_natives.h" |
| 6 | #include "vm/debugger.h" |
| 7 | #include "vm/exceptions.h" |
| 8 | #include "vm/native_entry.h" |
| 9 | #include "vm/object_store.h" |
| 10 | #include "vm/runtime_entry.h" |
| 11 | |
| 12 | namespace dart { |
| 13 | |
| 14 | DEFINE_NATIVE_ENTRY(AsyncStarMoveNext_debuggerStepCheck, 0, 1) { |
| 15 | #if !defined(PRODUCT) |
| 16 | GET_NON_NULL_NATIVE_ARGUMENT(Closure, generator, arguments->NativeArgAt(0)); |
| 17 | Debugger* debugger = isolate->debugger(); |
| 18 | if (debugger != nullptr && debugger->IsSingleStepping()) { |
| 19 | debugger->AsyncStepInto(awaiter: generator); |
| 20 | } |
| 21 | #endif |
| 22 | return Object::null(); |
| 23 | } |
| 24 | |
| 25 | // Instantiate generic [closure] using the type argument T |
| 26 | // corresponding to Future<T> in the given [future] instance |
| 27 | // (which may extend or implement Future). |
| 28 | DEFINE_NATIVE_ENTRY(SuspendState_instantiateClosureWithFutureTypeArgument, |
| 29 | 0, |
| 30 | 2) { |
| 31 | GET_NON_NULL_NATIVE_ARGUMENT(Closure, closure, arguments->NativeArgAt(0)); |
| 32 | GET_NON_NULL_NATIVE_ARGUMENT(Instance, future, arguments->NativeArgAt(1)); |
| 33 | IsolateGroup* isolate_group = thread->isolate_group(); |
| 34 | |
| 35 | const auto& future_class = |
| 36 | Class::Handle(zone, ptr: isolate_group->object_store()->future_class()); |
| 37 | ASSERT(future_class.NumTypeArguments() == 1); |
| 38 | |
| 39 | const auto& cls = Class::Handle(zone, ptr: future.clazz()); |
| 40 | auto& type = Type::Handle(zone, ptr: cls.GetInstantiationOf(zone, cls: future_class)); |
| 41 | ASSERT(!type.IsNull()); |
| 42 | if (!type.IsInstantiated()) { |
| 43 | const auto& instance_type_args = |
| 44 | TypeArguments::Handle(zone, ptr: future.GetTypeArguments()); |
| 45 | type ^= |
| 46 | type.InstantiateFrom(instantiator_type_arguments: instance_type_args, function_type_arguments: Object::null_type_arguments(), |
| 47 | num_free_fun_type_params: kNoneFree, space: Heap::kOld); |
| 48 | } |
| 49 | auto& type_args = TypeArguments::Handle(zone, ptr: type.arguments()); |
| 50 | ASSERT(type_args.IsNull() || type_args.Length() == 1); |
| 51 | type_args = type_args.Canonicalize(thread); |
| 52 | |
| 53 | ASSERT(closure.delayed_type_arguments() == |
| 54 | Object::empty_type_arguments().ptr()); |
| 55 | closure.set_delayed_type_arguments(type_args); |
| 56 | return closure.ptr(); |
| 57 | } |
| 58 | |
| 59 | } // namespace dart |
| 60 | |