Flutter Engine
The Flutter Engine
mirrors.cc
Go to the documentation of this file.
1// Copyright (c) 2012, 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 "lib/mirrors.h"
6
10#include "vm/dart_api_impl.h"
11#include "vm/dart_entry.h"
12#include "vm/exceptions.h"
13#include "vm/kernel.h"
14#include "vm/object_store.h"
15#include "vm/parser.h"
16#include "vm/port.h"
17#include "vm/resolver.h"
18#include "vm/symbols.h"
19
20namespace dart {
21
22#if !defined(DART_PRECOMPILED_RUNTIME)
23
24#define RETURN_OR_PROPAGATE(expr) \
25 ObjectPtr result = expr; \
26 if (IsErrorClassId(result->GetClassIdMayBeSmi())) { \
27 Exceptions::PropagateError(Error::Handle(Error::RawCast(result))); \
28 } \
29 return result;
30
31static InstancePtr CreateMirror(const String& mirror_class_name,
32 const Array& constructor_arguments) {
33 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary());
34 const String& constructor_name = Symbols::DotUnder();
35
37 mirrors_lib, mirror_class_name, constructor_name, constructor_arguments));
38 if (result.IsError()) {
40 }
41 return Instance::Cast(result).ptr();
42}
43
44// Conventions:
45// * For throwing a NSM in a class klass we use its runtime type as receiver,
46// i.e., klass.RareType().
47// * For throwing a NSM in a library, we just pass the null instance as
48// receiver.
49static void ThrowNoSuchMethod(const Instance& receiver,
50 const String& function_name,
51 const Array& arguments,
52 const Array& argument_names,
54 const InvocationMirror::Kind kind) {
55 const Smi& invocation_type =
57
59 args.SetAt(0, receiver);
60 args.SetAt(1, function_name);
61 args.SetAt(2, invocation_type);
62 args.SetAt(3, Object::smi_zero()); // Type arguments length.
63 args.SetAt(4, Object::null_type_arguments());
64 args.SetAt(5, arguments);
65 args.SetAt(6, argument_names);
66
68 const Class& cls =
69 Class::Handle(libcore.LookupClass(Symbols::NoSuchMethodError()));
70 const auto& error = cls.EnsureIsFinalized(Thread::Current());
72 const Function& throwNew =
73 Function::Handle(cls.LookupFunctionAllowPrivate(Symbols::ThrowNew()));
74 const Object& result =
76 ASSERT(result.IsError());
79}
80
81static void EnsureConstructorsAreCompiled(const Function& func) {
82 // Only generative constructors can have initializing formals.
83 if (!func.IsGenerativeConstructor()) return;
84
85 Thread* thread = Thread::Current();
86 Zone* zone = thread->zone();
87 const Class& cls = Class::Handle(zone, func.Owner());
88 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread));
89 if (!error.IsNull()) {
92 }
93 func.EnsureHasCode();
94}
95
96static InstancePtr CreateParameterMirrorList(const Function& func,
97 const FunctionType& signature,
98 const Instance& owner_mirror) {
99 Thread* const T = Thread::Current();
100 Zone* const Z = T->zone();
101 HANDLESCOPE(T);
102 const intptr_t implicit_param_count = signature.num_implicit_parameters();
103 const intptr_t non_implicit_param_count =
104 signature.NumParameters() - implicit_param_count;
105 const intptr_t index_of_first_optional_param =
106 non_implicit_param_count - signature.NumOptionalParameters();
107 const intptr_t index_of_first_named_param =
108 non_implicit_param_count - signature.NumOptionalNamedParameters();
109 const Array& results = Array::Handle(Z, Array::New(non_implicit_param_count));
110 const Array& args = Array::Handle(Z, Array::New(9));
111
112 Smi& pos = Smi::Handle(Z);
114 Instance& param = Instance::Handle(Z);
115 Bool& is_final = Bool::Handle(Z);
116 Object& default_value = Object::Handle(Z);
117 Object& metadata = Object::Handle(Z);
118
119 // We force compilation of constructors to ensure the types of initializing
120 // formals have been corrected. We do not force the compilation of all types
121 // of functions because some have no body, e.g. signature functions.
122 if (!func.IsNull()) {
124 }
125
126 bool has_extra_parameter_info = true;
127 if (non_implicit_param_count == 0) {
128 has_extra_parameter_info = false;
129 }
130 if (func.IsNull() || func.IsImplicitConstructor()) {
131 // This covers the default constructor and forwarding constructors.
132 has_extra_parameter_info = false;
133 }
134 Array& param_descriptor = Array::Handle();
135 if (has_extra_parameter_info) {
136 // Reparse the function for the following information:
137 // * The default value of a parameter.
138 // * Whether a parameters has been declared as final.
139 // * Any metadata associated with the parameter.
141 if (result.IsError()) {
143 UNREACHABLE();
144 }
145 param_descriptor ^= result.ptr();
146 ASSERT(param_descriptor.Length() ==
147 (Parser::kParameterEntrySize * non_implicit_param_count));
148 }
149
151 args.SetAt(2, owner_mirror);
152
153 if (!has_extra_parameter_info) {
154 is_final = Bool::True().ptr();
155 default_value = Object::null();
156 metadata = Object::null();
157 }
158
159 for (intptr_t i = 0; i < non_implicit_param_count; i++) {
160 pos = Smi::New(i);
161 if (i >= index_of_first_named_param) {
162 // Named parameters are stored in the signature.
163 name = signature.ParameterNameAt(implicit_param_count + i);
164 } else if (!func.IsNull()) {
165 // Positional parameters are stored in the function.
166 name = func.ParameterNameAt(implicit_param_count + i);
167 } else {
168 // We were not given a function, only the type, so create placeholder
169 // names for the positional parameters.
170 const char* const placeholder = OS::SCreate(Z, ":param%" Pd "", i);
171 name = String::New(placeholder);
172 }
173 if (has_extra_parameter_info) {
174 is_final ^= param_descriptor.At(i * Parser::kParameterEntrySize +
176 default_value = param_descriptor.At(i * Parser::kParameterEntrySize +
178 metadata = param_descriptor.At(i * Parser::kParameterEntrySize +
180 }
181 ASSERT(default_value.IsNull() || default_value.IsInstance());
182
183 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See
184 // above.
185 args.SetAt(1, name);
186 args.SetAt(3, pos);
187 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param));
188 args.SetAt(5, Bool::Get(i >= index_of_first_named_param));
189 args.SetAt(6, is_final);
190 args.SetAt(7, default_value);
191 args.SetAt(8, metadata);
192 param = CreateMirror(Symbols::_ParameterMirror(), args);
193 results.SetAt(i, param);
194 }
195 results.MakeImmutable();
196 return results.ptr();
197}
198
199static InstancePtr CreateTypeVariableMirror(const TypeParameter& param,
200 const Instance& owner_mirror) {
201 const Array& args = Array::Handle(Array::New(3));
202 args.SetAt(0, param);
203 args.SetAt(1, String::Handle(param.UserVisibleName()));
204 args.SetAt(2, owner_mirror);
205 return CreateMirror(Symbols::_TypeVariableMirror(), args);
206}
207
208// We create a list in native code and let Dart code create the type mirror
209// object and the ordered map.
210static InstancePtr CreateTypeVariableList(const Class& cls) {
211 const intptr_t num_type_params = cls.NumTypeParameters();
212 if (num_type_params == 0) {
213 return Object::empty_array().ptr();
214 }
215 const Array& result = Array::Handle(Array::New(num_type_params * 2));
218 for (intptr_t i = 0; i < num_type_params; i++) {
220 ASSERT(type.IsFinalized());
221 name = type.UserVisibleName();
222 result.SetAt(2 * i, name);
223 result.SetAt(2 * i + 1, type);
224 }
225 return result.ptr();
226}
227
228static InstancePtr CreateFunctionTypeMirror(const AbstractType& type) {
229 ASSERT(type.IsFunctionType());
230 const Class& closure_class =
231 Class::Handle(IsolateGroup::Current()->object_store()->closure_class());
232 const FunctionType& sig = FunctionType::Cast(type);
233 const Array& args = Array::Handle(Array::New(3));
234 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(closure_class)));
236 args.SetAt(2, type);
237 return CreateMirror(Symbols::_FunctionTypeMirror(), args);
238}
239
240static InstancePtr CreateMethodMirror(const Function& func,
241 const Instance& owner_mirror,
242 const AbstractType& instantiator) {
243 const Array& args = Array::Handle(Array::New(6));
245
246 String& name = String::Handle(func.name());
248 name, func.is_extension_member() || func.is_extension_type_member());
249 args.SetAt(1, name);
250 args.SetAt(2, owner_mirror);
251 args.SetAt(3, instantiator);
252 args.SetAt(4, Bool::Get(func.is_static()));
253
254 intptr_t kind_flags = 0;
255 kind_flags |=
256 (static_cast<intptr_t>(func.is_abstract()) << Mirrors::kAbstract);
257 kind_flags |=
258 (static_cast<intptr_t>(func.IsGetterFunction()) << Mirrors::kGetter);
259 kind_flags |=
260 (static_cast<intptr_t>(func.IsSetterFunction()) << Mirrors::kSetter);
261 bool is_ctor = (func.kind() == UntaggedFunction::kConstructor);
262 kind_flags |= (static_cast<intptr_t>(is_ctor) << Mirrors::kConstructor);
263 kind_flags |= (static_cast<intptr_t>(is_ctor && func.is_const())
264 << Mirrors::kConstCtor);
265 kind_flags |=
266 (static_cast<intptr_t>(is_ctor && func.IsGenerativeConstructor())
267 << Mirrors::kGenerativeCtor);
268 kind_flags |= (static_cast<intptr_t>(false) << Mirrors::kRedirectingCtor);
269 kind_flags |= (static_cast<intptr_t>(is_ctor && func.IsFactory())
270 << Mirrors::kFactoryCtor);
271 kind_flags |=
272 (static_cast<intptr_t>(func.is_external()) << Mirrors::kExternal);
273 bool is_synthetic = func.is_synthetic();
274 kind_flags |= (static_cast<intptr_t>(is_synthetic) << Mirrors::kSynthetic);
275 kind_flags |= (static_cast<intptr_t>(func.is_extension_member())
276 << Mirrors::kExtensionMember);
277 kind_flags |= (static_cast<intptr_t>(func.is_extension_type_member())
278 << Mirrors::kExtensionTypeMember);
279 args.SetAt(5, Smi::Handle(Smi::New(kind_flags)));
280
281 return CreateMirror(Symbols::_MethodMirror(), args);
282}
283
284static InstancePtr CreateVariableMirror(const Field& field,
285 const Instance& owner_mirror) {
286 const MirrorReference& field_ref =
288
289 const String& name = String::Handle(field.name());
290
291 const Array& args = Array::Handle(Array::New(9));
292 args.SetAt(0, field_ref);
293 args.SetAt(1, name);
294 args.SetAt(2, owner_mirror);
295 args.SetAt(3, Object::null_instance()); // Null for type.
296 args.SetAt(4, Bool::Get(field.is_static()));
297 args.SetAt(5, Bool::Get(field.is_final()));
298 args.SetAt(6, Bool::Get(field.is_const()));
299 args.SetAt(7, Bool::Get(field.is_extension_member()));
300 args.SetAt(8, Bool::Get(field.is_extension_type_member()));
301
302 return CreateMirror(Symbols::_VariableMirror(), args);
303}
304
305static InstancePtr CreateClassMirror(const Class& cls,
306 const AbstractType& type,
307 const Bool& is_declaration,
308 const Instance& owner_mirror) {
309 ASSERT(!cls.IsDynamicClass());
310 ASSERT(!cls.IsVoidClass());
311 ASSERT(!cls.IsNeverClass());
312 ASSERT(!type.IsNull());
313 ASSERT(type.IsFinalized());
314 ASSERT(type.IsCanonical());
315 const Array& args = Array::Handle(Array::New(9));
317 args.SetAt(1, type);
318 args.SetAt(2, String::Handle(cls.Name()));
319 args.SetAt(3, owner_mirror);
320 args.SetAt(4, Bool::Get(cls.is_abstract()));
321 args.SetAt(5, Bool::Get(cls.IsGeneric()));
323 args.SetAt(7, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration);
324 args.SetAt(8, Bool::Get(cls.is_enum_class()));
325 return CreateMirror(Symbols::_ClassMirror(), args);
326}
327
328static bool IsCensoredLibrary(const String& url) {
329 static const char* const censored_libraries[] = {
330 "dart:_builtin",
331 "dart:_vmservice",
332 "dart:vmservice_io",
333 };
334 for (const char* censored_library : censored_libraries) {
335 if (url.Equals(censored_library)) {
336 return true;
337 }
338 }
339 if (!Api::IsFfiEnabled() && url.Equals(Symbols::DartFfi())) {
340 return true;
341 }
342 return false;
343}
344
345static InstancePtr CreateLibraryMirror(Thread* thread, const Library& lib) {
346 Zone* zone = thread->zone();
347 ASSERT(!lib.IsNull());
348 const Array& args = Array::Handle(zone, Array::New(3));
350 String& str = String::Handle(zone);
351 str = lib.name();
352 args.SetAt(1, str);
353 str = lib.url();
354 if (IsCensoredLibrary(str)) {
355 // Censored library (grumble).
356 return Instance::null();
357 }
358 args.SetAt(2, str);
359 return CreateMirror(Symbols::_LibraryMirror(), args);
360}
361
362static InstancePtr CreateCombinatorMirror(const Object& identifiers,
363 bool is_show) {
364 const Array& args = Array::Handle(Array::New(2));
365 args.SetAt(0, identifiers);
366 args.SetAt(1, Bool::Get(is_show));
367 return CreateMirror(Symbols::_CombinatorMirror(), args);
368}
369
370static InstancePtr CreateLibraryDependencyMirror(Thread* thread,
371 const Instance& importer,
372 const Library& importee,
373 const Array& show_names,
374 const Array& hide_names,
375 const Object& metadata,
376 const LibraryPrefix& prefix,
377 const String& prefix_name,
378 const bool is_import,
379 const bool is_deferred) {
380 const Instance& importee_mirror =
381 Instance::Handle(CreateLibraryMirror(thread, importee));
382 if (importee_mirror.IsNull()) {
383 // Imported library is censored: censor the import.
384 return Instance::null();
385 }
386
387 intptr_t n = show_names.IsNull() ? 0 : show_names.Length();
388 intptr_t m = hide_names.IsNull() ? 0 : hide_names.Length();
389 const Array& combinators = Array::Handle(Array::New(n + m));
390 Object& t = Object::Handle();
391 intptr_t i = 0;
392 for (intptr_t j = 0; j < n; j++) {
393 t = show_names.At(j);
394 t = CreateCombinatorMirror(t, true);
395 combinators.SetAt(i++, t);
396 }
397 for (intptr_t j = 0; j < m; j++) {
398 t = hide_names.At(j);
399 t = CreateCombinatorMirror(t, false);
400 combinators.SetAt(i++, t);
401 }
402
403 const Array& args = Array::Handle(Array::New(7));
404 args.SetAt(0, importer);
405 if (importee.Loaded() || prefix.IsNull()) {
406 // A native extension is never "loaded" by the embedder. Use the fact that
407 // it doesn't have an prefix where asa deferred import does to distinguish
408 // it from a deferred import. It will appear like an empty library.
409 args.SetAt(1, importee_mirror);
410 } else {
411 args.SetAt(1, prefix);
412 }
413 args.SetAt(2, combinators);
414 args.SetAt(3, prefix_name);
415 args.SetAt(4, Bool::Get(is_import));
416 args.SetAt(5, Bool::Get(is_deferred));
417 args.SetAt(6, metadata);
418 return CreateMirror(Symbols::_LibraryDependencyMirror(), args);
419}
420
421static InstancePtr CreateLibraryDependencyMirror(Thread* thread,
422 const Instance& importer,
423 const Namespace& ns,
424 const LibraryPrefix& prefix,
425 const bool is_import,
426 const bool is_deferred) {
427 const Library& importee = Library::Handle(ns.target());
428 const Array& show_names = Array::Handle(ns.show_names());
429 const Array& hide_names = Array::Handle(ns.hide_names());
430
431 const Library& owner = Library::Handle(ns.owner());
432 Object& metadata = Object::Handle(owner.GetMetadata(ns));
433 if (metadata.IsError()) {
434 Exceptions::PropagateError(Error::Cast(metadata));
435 UNREACHABLE();
436 }
437
438 auto& prefix_name = String::Handle();
439 if (!prefix.IsNull()) {
440 prefix_name = prefix.name();
441 }
442
443 return CreateLibraryDependencyMirror(thread, importer, importee, show_names,
444 hide_names, metadata, prefix,
445 prefix_name, is_import, is_deferred);
446}
447
448DEFINE_NATIVE_ENTRY(LibraryMirror_fromPrefix, 0, 1) {
450 arguments->NativeArgAt(0));
451 const Library& deferred_lib = Library::Handle(prefix.GetLibrary(0));
452 if (!deferred_lib.Loaded()) {
453 return Instance::null();
454 }
455 return CreateLibraryMirror(thread, deferred_lib);
456}
457
458DEFINE_NATIVE_ENTRY(LibraryMirror_libraryDependencies, 0, 2) {
459 GET_NON_NULL_NATIVE_ARGUMENT(Instance, lib_mirror, arguments->NativeArgAt(0));
460 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
461 const Library& lib = Library::Handle(ref.GetLibraryReferent());
462
463 Array& ports = Array::Handle();
465 Instance& dep = Instance::Handle();
467 GrowableObjectArray& deps =
469
470 // Unprefixed imports.
471 ports = lib.imports();
472 for (intptr_t i = 0; i < ports.Length(); i++) {
473 ns ^= ports.At(i);
474 if (!ns.IsNull()) {
475 dep = CreateLibraryDependencyMirror(thread, lib_mirror, ns, prefix, true,
476 false);
477 if (!dep.IsNull()) {
478 deps.Add(dep);
479 }
480 }
481 }
482
483 // Exports.
484 ports = lib.exports();
485 for (intptr_t i = 0; i < ports.Length(); i++) {
486 ns ^= ports.At(i);
487 dep = CreateLibraryDependencyMirror(thread, lib_mirror, ns, prefix, false,
488 false);
489 if (!dep.IsNull()) {
490 deps.Add(dep);
491 }
492 }
493
494 // Prefixed imports.
495 DictionaryIterator entries(lib);
496 Object& entry = Object::Handle();
497 while (entries.HasNext()) {
498 entry = entries.GetNext();
499 if (entry.IsLibraryPrefix()) {
500 prefix ^= entry.ptr();
501 ports = prefix.imports();
502 for (intptr_t i = 0; i < ports.Length(); i++) {
503 ns ^= ports.At(i);
504 if (!ns.IsNull()) {
505 dep = CreateLibraryDependencyMirror(thread, lib_mirror, ns, prefix,
506 true, prefix.is_deferred_load());
507 if (!dep.IsNull()) {
508 deps.Add(dep);
509 }
510 }
511 }
512 }
513 }
514
515 return deps.ptr();
516}
517
518static InstancePtr CreateTypeMirror(const AbstractType& type) {
519 ASSERT(type.IsFinalized());
520 ASSERT(type.IsCanonical());
521
522 if (type.IsFunctionType()) {
524 }
525 if (type.IsRecordType()) {
526 const Class& cls =
527 Class::Handle(IsolateGroup::Current()->object_store()->record_class());
529 Bool::False(), Object::null_instance());
530 }
531 if (type.HasTypeClass()) {
532 const Class& cls = Class::Handle(type.type_class());
533 // Handle void and dynamic types.
534 if (cls.IsVoidClass()) {
536 args.SetAt(0, Symbols::Void());
537 return CreateMirror(Symbols::_SpecialTypeMirror(), args);
538 } else if (cls.IsDynamicClass()) {
540 args.SetAt(0, Symbols::Dynamic());
541 return CreateMirror(Symbols::_SpecialTypeMirror(), args);
542 } else if (cls.IsNeverClass()) {
544 args.SetAt(0, Symbols::Never());
545 return CreateMirror(Symbols::_SpecialTypeMirror(), args);
546 }
547 // TODO(regis): Until mirrors reflect nullability, force kNonNullable,
548 // except for Null type, which should remain nullable.
549 if (!type.IsNullType()) {
550 Type& legacy_type = Type::Handle(Type::Cast(type).ToNullability(
552 legacy_type ^= legacy_type.Canonicalize(Thread::Current());
553 return CreateClassMirror(cls, legacy_type, Bool::False(),
554 Object::null_instance());
555 }
556 return CreateClassMirror(cls, type, Bool::False(), Object::null_instance());
557 } else if (type.IsTypeParameter()) {
558 // TODO(regis): Until mirrors reflect nullability, force kNonNullable.
559 TypeParameter& legacy_type =
560 TypeParameter::Handle(TypeParameter::Cast(type).ToNullability(
562 legacy_type ^= legacy_type.Canonicalize(Thread::Current());
563 return CreateTypeVariableMirror(legacy_type, Object::null_instance());
564 }
565 UNREACHABLE();
566 return Instance::null();
567}
568
569static InstancePtr CreateIsolateMirror() {
570 Thread* thread = Thread::Current();
571 Isolate* isolate = thread->isolate();
572 const String& debug_name = String::Handle(String::New(isolate->name()));
573 const Library& root_library = Library::Handle(
574 thread->zone(), isolate->group()->object_store()->root_library());
575 const Instance& root_library_mirror =
576 Instance::Handle(CreateLibraryMirror(thread, root_library));
577
578 const Array& args = Array::Handle(Array::New(2));
579 args.SetAt(0, debug_name);
580 args.SetAt(1, root_library_mirror);
581 return CreateMirror(Symbols::_IsolateMirror(), args);
582}
583
585#ifdef DEBUG
586 Thread* thread = Thread::Current();
587 Zone* zone = thread->zone();
588 const Library& lib = Library::Handle(zone, Library::MirrorsLibrary());
589 const Class& cls = Class::Handle(
590 zone, lib.LookupClassAllowPrivate(Symbols::_MethodMirror()));
591 Error& error = Error::Handle(zone);
592 error ^= cls.EnsureIsFinalized(thread);
593 ASSERT(error.IsNull());
594
595 Field& field = Field::Handle(zone);
596 Smi& value = Smi::Handle(zone);
597 String& fname = String::Handle(zone);
598
599#define CHECK_KIND_SHIFT(name) \
600 fname ^= String::New(#name); \
601 field = cls.LookupField(fname); \
602 ASSERT(!field.IsNull()); \
603 if (field.IsUninitialized()) { \
604 error ^= field.InitializeStatic(); \
605 ASSERT(error.IsNull()); \
606 } \
607 value ^= field.StaticValue(); \
608 ASSERT(value.Value() == Mirrors::name);
609 MIRRORS_KIND_SHIFT_LIST(CHECK_KIND_SHIFT)
610#undef CHECK_KIND_SHIFT
611#endif
612}
613
614static AbstractTypePtr InstantiateType(const AbstractType& type,
615 const AbstractType& instantiator) {
616 // Generic function type parameters are not reified, but mapped to dynamic,
617 // i.e. all function type parameters are free with a null vector.
618 ASSERT(type.IsFinalized());
619 ASSERT(type.IsCanonical());
620 Thread* thread = Thread::Current();
621
622 if (type.IsInstantiated()) {
623 return type.Canonicalize(thread);
624 }
625 TypeArguments& instantiator_type_args = TypeArguments::Handle();
626 if (!instantiator.IsNull() && instantiator.IsType()) {
627 ASSERT(instantiator.IsFinalized());
628 if (instantiator.type_class_id() == kInstanceCid) {
629 // Handle types created in ClosureMirror_function.
630 instantiator_type_args = instantiator.arguments();
631 } else {
632 instantiator_type_args =
633 Type::Cast(instantiator)
634 .GetInstanceTypeArguments(thread, /*canonicalize=*/false);
635 }
636 }
637 AbstractType& result = AbstractType::Handle(type.InstantiateFrom(
638 instantiator_type_args, Object::null_type_arguments(), kAllFree,
639 Heap::kOld));
640 ASSERT(result.IsFinalized());
641 return result.Canonicalize(thread);
642}
643
644DEFINE_NATIVE_ENTRY(MirrorSystem_libraries, 0, 0) {
646 zone, isolate->group()->object_store()->libraries());
647
648 const intptr_t num_libraries = libraries.Length();
649 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle(
650 zone, GrowableObjectArray::New(num_libraries));
651 Library& library = Library::Handle(zone);
652 Instance& library_mirror = Instance::Handle(zone);
653
654 for (int i = 0; i < num_libraries; i++) {
655 library ^= libraries.At(i);
656 library_mirror = CreateLibraryMirror(thread, library);
657 if (!library_mirror.IsNull() && library.Loaded()) {
658 library_mirrors.Add(library_mirror);
659 }
660 }
661 return library_mirrors.ptr();
662}
663
664DEFINE_NATIVE_ENTRY(MirrorSystem_isolate, 0, 0) {
666
667 return CreateIsolateMirror();
668}
669
670static void ThrowLanguageError(const char* message) {
671 const Error& error =
672 Error::Handle(LanguageError::New(String::Handle(String::New(message))));
674}
675
676DEFINE_NATIVE_ENTRY(IsolateMirror_loadUri, 0, 1) {
677 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0));
678
679 if (!isolate->group()->HasTagHandler()) {
680 ThrowLanguageError("no library handler registered");
681 }
682
683 NoReloadScope no_reload(thread);
684
685 // Canonicalize library URI.
686 String& canonical_uri = String::Handle(zone);
687 if (uri.StartsWith(Symbols::DartScheme())) {
688 canonical_uri = uri.ptr();
689 } else {
690 isolate->BlockClassFinalization();
692 zone, isolate->group()->CallTagHandler(
695 zone, isolate->group()->object_store()->root_library()),
696 uri));
697 isolate->UnblockClassFinalization();
698 if (result.IsError()) {
699 if (result.IsLanguageError()) {
700 Exceptions::ThrowCompileTimeError(LanguageError::Cast(result));
701 }
703 } else if (!result.IsString()) {
704 ThrowLanguageError("library handler failed URI canonicalization");
705 }
706
707 canonical_uri ^= result.ptr();
708 }
709
710 // Return the existing library if it has already been loaded.
711 Library& library =
712 Library::Handle(zone, Library::LookupLibrary(thread, canonical_uri));
713 if (!library.IsNull()) {
714 return CreateLibraryMirror(thread, library);
715 }
716
717 // Request the embedder to load the library.
718 isolate->BlockClassFinalization();
720 zone, isolate->group()->CallTagHandler(
723 zone, isolate->group()->object_store()->root_library()),
724 canonical_uri));
725 isolate->UnblockClassFinalization();
726 if (result.IsError()) {
727 if (result.IsLanguageError()) {
728 Exceptions::ThrowCompileTimeError(LanguageError::Cast(result));
729 }
731 }
732
733 // This code assumes a synchronous tag handler (which dart::bin and tonic
734 // provide). Strictly though we should complete a future in response to
735 // Dart_FinalizeLoading.
736
738 Exceptions::PropagateError(Error::Handle(thread->sticky_error()));
739 }
740
741 // Prefer the tag handler's idea of which library is represented by the URI.
742 if (result.IsLibrary()) {
743 return CreateLibraryMirror(thread, Library::Cast(result));
744 }
745
746 if (result.IsNull()) {
747 library = Library::LookupLibrary(thread, canonical_uri);
748 if (!library.IsNull()) {
749 return CreateLibraryMirror(thread, library);
750 }
751 }
752
753 FATAL("Non-library from tag handler");
754}
755
756DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 0, 1) {
757 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
758 ASSERT(type.IsFinalized());
759 const Class& cls = Class::Handle(
760 type.IsFunctionType()
761 ? IsolateGroup::Current()->object_store()->closure_class()
762 : type.type_class());
763 ASSERT(!cls.IsNull());
764 if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsNeverClass()) {
766 UNREACHABLE();
767 }
769 Bool::True(), // is_declaration
770 Object::null_instance());
771}
772
773DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 0, 1) {
774 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
775 return CreateTypeMirror(type);
776}
777
778DEFINE_NATIVE_ENTRY(Mirrors_instantiateGenericType, 0, 2) {
779 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
780 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(1));
781
782 const Class& clz = Class::Handle(
783 type.IsFunctionType()
784 ? IsolateGroup::Current()->object_store()->closure_class()
785 : type.type_class());
786 if (!clz.IsGeneric()) {
787 const Array& error_args = Array::Handle(Array::New(3));
788 error_args.SetAt(0, type);
789 error_args.SetAt(1, String::Handle(String::New("key")));
790 error_args.SetAt(2, String::Handle(String::New(
791 "Type must be a generic class or function.")));
793 UNREACHABLE();
794 }
795 if (clz.NumTypeParameters() != args.Length()) {
796 const Array& error_args = Array::Handle(Array::New(3));
797 error_args.SetAt(0, args);
798 error_args.SetAt(1, String::Handle(String::New("typeArguments")));
799 error_args.SetAt(2, String::Handle(String::New(
800 "Number of type arguments does not match.")));
802 UNREACHABLE();
803 }
804
805 intptr_t num_expected_type_arguments = args.Length();
806 TypeArguments& type_args_obj = TypeArguments::Handle();
807 type_args_obj = TypeArguments::New(num_expected_type_arguments);
810 for (intptr_t i = 0; i < args.Length(); i++) {
811 instance ^= args.At(i);
812 if (!instance.IsType()) {
813 const Array& error_args = Array::Handle(Array::New(3));
814 error_args.SetAt(0, args);
815 error_args.SetAt(1, String::Handle(String::New("typeArguments")));
816 error_args.SetAt(2, String::Handle(String::New(
817 "Type arguments must be instances of Type.")));
819 UNREACHABLE();
820 }
821 type_arg ^= args.At(i);
822 type_args_obj.SetTypeAt(i, type_arg);
823 }
824
825 Type& instantiated_type = Type::Handle(Type::New(clz, type_args_obj));
826 instantiated_type ^= ClassFinalizer::FinalizeType(instantiated_type);
827 return instantiated_type.ptr();
828}
829
830DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 0, 2) {
831 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0));
832 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
833 const Library& lib = Library::Handle(ref.GetLibraryReferent());
834 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.ptr();
835}
836
837DEFINE_NATIVE_ENTRY(MirrorReference_equals, 0, 2) {
838 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0));
839 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1));
840 return Bool::Get(a.referent() == b.referent()).ptr();
841}
842
843DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 0, 1) {
844 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0));
845 Object& decl = Object::Handle();
846 if (reflectee.IsMirrorReference()) {
847 const MirrorReference& decl_ref = MirrorReference::Cast(reflectee);
848 decl = decl_ref.referent();
849 } else if (reflectee.IsTypeParameter()) {
850 decl = reflectee.ptr();
851 } else {
852 UNREACHABLE();
853 }
854
855 Class& klass = Class::Handle();
856 Library& library = Library::Handle();
857
858 if (decl.IsClass()) {
859 klass ^= decl.ptr();
860 library = klass.library();
861 } else if (decl.IsFunction()) {
862 klass = Function::Cast(decl).Owner();
863 library = klass.library();
864 } else if (decl.IsField()) {
865 klass = Field::Cast(decl).Owner();
866 library = klass.library();
867 } else if (decl.IsLibrary()) {
868 library ^= decl.ptr();
869 } else if (decl.IsTypeParameter()) {
870 // There is no reference from a canonical type parameter to its declaration.
871 return Object::empty_array().ptr();
872 } else {
873 return Object::empty_array().ptr();
874 }
875
876 const Object& metadata = Object::Handle(library.GetMetadata(decl));
877 if (metadata.IsError()) {
878 Exceptions::PropagateError(Error::Cast(metadata));
879 }
880 return metadata.ptr();
881}
882
883DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 0, 2) {
885 arguments->NativeArgAt(0));
886 // Return get:call() method on class _Closure.
887 const auto& getter_name = Symbols::GetCall();
888 const Class& closure_class =
889 Class::Handle(IsolateGroup::Current()->object_store()->closure_class());
890 const Function& get_call = Function::Handle(
891 Resolver::ResolveDynamicAnyArgs(zone, closure_class, getter_name,
892 /*allow_add=*/false));
893 ASSERT(!get_call.IsNull());
894 return CreateMethodMirror(get_call, owner_mirror, AbstractType::Handle());
895}
896
897DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 0, 2) {
898 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
899 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
900 const FunctionType& sig = FunctionType::Handle(ref.GetFunctionTypeReferent());
901 return CreateParameterMirrorList(Object::null_function(), sig, owner);
902}
903
904DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 0, 1) {
905 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
906 const FunctionType& sig = FunctionType::Handle(ref.GetFunctionTypeReferent());
907 ASSERT(!sig.IsNull());
909 // Signatures of function types are instantiated, but not canonical.
910 return type.Canonicalize(thread);
911}
912
913DEFINE_NATIVE_ENTRY(ClassMirror_libraryUri, 0, 1) {
914 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
915 const Class& klass = Class::Handle(ref.GetClassReferent());
916 const Library& library = Library::Handle(klass.library());
917 ASSERT(!library.IsNull());
918 return library.url();
919}
920
921DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 0, 1) {
922 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
923 ASSERT(type.IsFinalized());
924 const Class& cls = Class::Handle(
925 type.IsFunctionType()
926 ? IsolateGroup::Current()->object_store()->closure_class()
927 : type.type_class());
928 const AbstractType& super_type = AbstractType::Handle(cls.super_type());
929 ASSERT(super_type.IsNull() || super_type.IsFinalized());
930 return super_type.ptr();
931}
932
933DEFINE_NATIVE_ENTRY(ClassMirror_supertype_instantiated, 0, 1) {
934 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
935 ASSERT(type.IsFinalized());
936 const Class& cls = Class::Handle(
937 type.IsFunctionType()
938 ? IsolateGroup::Current()->object_store()->closure_class()
939 : type.type_class());
940 const AbstractType& super_type = AbstractType::Handle(cls.super_type());
941 return InstantiateType(super_type, type);
942}
943
944DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 0, 1) {
945 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
946 ASSERT(type.IsFinalized());
947 const Class& cls = Class::Handle(
948 type.IsFunctionType()
949 ? IsolateGroup::Current()->object_store()->closure_class()
950 : type.type_class());
951 const Error& error = Error::Handle(cls.EnsureIsFinalized(thread));
952 if (!error.IsNull()) {
954 }
955
956 return cls.interfaces();
957}
958
959DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 0, 1) {
960 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
961 ASSERT(type.IsFinalized());
962 const Class& cls = Class::Handle(
963 type.IsFunctionType()
964 ? IsolateGroup::Current()->object_store()->closure_class()
965 : type.type_class());
966 const Error& error = Error::Handle(cls.EnsureIsFinalized(thread));
967 if (!error.IsNull()) {
969 }
970
971 Array& interfaces = Array::Handle(cls.interfaces());
972 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length()));
973 AbstractType& interface = AbstractType::Handle();
974
975 for (int i = 0; i < interfaces.Length(); i++) {
976 interface ^= interfaces.At(i);
977 interface = InstantiateType(interface, type);
978 interfaces_inst.SetAt(i, interface);
979 }
980
981 return interfaces_inst.ptr();
982}
983
984DEFINE_NATIVE_ENTRY(ClassMirror_mixin, 0, 1) {
985 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
986 ASSERT(type.IsFinalized());
987 const Class& cls = Class::Handle(
988 type.IsFunctionType()
989 ? IsolateGroup::Current()->object_store()->closure_class()
990 : type.type_class());
991 AbstractType& mixin_type = AbstractType::Handle();
993 const Array& interfaces = Array::Handle(cls.interfaces());
994 mixin_type ^= interfaces.At(interfaces.Length() - 1);
995 }
996 ASSERT(mixin_type.IsNull() || mixin_type.IsFinalized());
997 return mixin_type.ptr();
998}
999
1000DEFINE_NATIVE_ENTRY(ClassMirror_mixin_instantiated, 0, 2) {
1001 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
1003 arguments->NativeArgAt(1));
1004 ASSERT(type.IsFinalized());
1005 const Class& cls = Class::Handle(
1006 type.IsFunctionType()
1007 ? IsolateGroup::Current()->object_store()->closure_class()
1008 : type.type_class());
1009 AbstractType& mixin_type = AbstractType::Handle();
1011 const Array& interfaces = Array::Handle(cls.interfaces());
1012 mixin_type ^= interfaces.At(interfaces.Length() - 1);
1013 }
1014 if (mixin_type.IsNull()) {
1015 return mixin_type.ptr();
1016 }
1017
1018 return InstantiateType(mixin_type, instantiator);
1019}
1020
1021DEFINE_NATIVE_ENTRY(ClassMirror_members, 0, 3) {
1023 arguments->NativeArgAt(0));
1024 GET_NATIVE_ARGUMENT(AbstractType, owner_instantiator,
1025 arguments->NativeArgAt(1));
1026 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2));
1027 const Class& klass = Class::Handle(ref.GetClassReferent());
1028
1029 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread));
1030 if (!error.IsNull()) {
1032 }
1033
1034 const Array& fields = Array::Handle(klass.fields());
1035 const intptr_t num_fields = fields.Length();
1036
1037 const Array& functions = Array::Handle(klass.current_functions());
1038 const intptr_t num_functions = functions.Length();
1039
1040 Instance& member_mirror = Instance::Handle();
1041 const GrowableObjectArray& member_mirrors = GrowableObjectArray::Handle(
1042 GrowableObjectArray::New(num_fields + num_functions));
1043
1044 Field& field = Field::Handle();
1045 for (intptr_t i = 0; i < num_fields; i++) {
1046 field ^= fields.At(i);
1047 if (field.is_reflectable()) {
1048 member_mirror = CreateVariableMirror(field, owner_mirror);
1049 member_mirrors.Add(member_mirror);
1050 }
1051 }
1052
1053 Function& func = Function::Handle();
1054 for (intptr_t i = 0; i < num_functions; i++) {
1055 func ^= functions.At(i);
1056 if (func.is_reflectable() &&
1057 (func.kind() == UntaggedFunction::kRegularFunction ||
1058 func.kind() == UntaggedFunction::kGetterFunction ||
1059 func.kind() == UntaggedFunction::kSetterFunction)) {
1060 member_mirror =
1061 CreateMethodMirror(func, owner_mirror, owner_instantiator);
1062 member_mirrors.Add(member_mirror);
1063 }
1064 }
1065
1066 return member_mirrors.ptr();
1067}
1068
1069DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 0, 3) {
1071 arguments->NativeArgAt(0));
1072 GET_NATIVE_ARGUMENT(AbstractType, owner_instantiator,
1073 arguments->NativeArgAt(1));
1074 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2));
1075 const Class& klass = Class::Handle(ref.GetClassReferent());
1076
1077 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread));
1078 if (!error.IsNull()) {
1080 }
1081
1082 const Array& functions = Array::Handle(klass.current_functions());
1083 const intptr_t num_functions = functions.Length();
1084
1085 Instance& constructor_mirror = Instance::Handle();
1086 const GrowableObjectArray& constructor_mirrors =
1088
1089 Function& func = Function::Handle();
1090 for (intptr_t i = 0; i < num_functions; i++) {
1091 func ^= functions.At(i);
1092 if (func.is_reflectable() &&
1093 func.kind() == UntaggedFunction::kConstructor) {
1094 constructor_mirror =
1095 CreateMethodMirror(func, owner_mirror, owner_instantiator);
1096 constructor_mirrors.Add(constructor_mirror);
1097 }
1098 }
1099
1100 return constructor_mirrors.ptr();
1101}
1102
1103DEFINE_NATIVE_ENTRY(LibraryMirror_members, 0, 2) {
1105 arguments->NativeArgAt(0));
1106 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1107 const Library& library = Library::Handle(zone, ref.GetLibraryReferent());
1108
1110
1111 Instance& member_mirror = Instance::Handle(zone);
1112 const GrowableObjectArray& member_mirrors =
1114
1115 Object& entry = Object::Handle(zone);
1116 DictionaryIterator entries(library);
1117
1118 Error& error = Error::Handle(zone);
1120
1121 while (entries.HasNext()) {
1122 entry = entries.GetNext();
1123 if (entry.IsClass()) {
1124 const Class& klass = Class::Cast(entry);
1125 ASSERT(!klass.IsDynamicClass());
1126 ASSERT(!klass.IsVoidClass());
1127 ASSERT(!klass.IsNeverClass());
1128 error = klass.EnsureIsFinalized(thread);
1129 if (!error.IsNull()) {
1131 }
1132 type = klass.DeclarationType();
1133 member_mirror = CreateClassMirror(klass, type,
1134 Bool::True(), // is_declaration
1135 owner_mirror);
1136 member_mirrors.Add(member_mirror);
1137 } else if (entry.IsField()) {
1138 const Field& field = Field::Cast(entry);
1139 if (field.is_reflectable()) {
1140 member_mirror = CreateVariableMirror(field, owner_mirror);
1141 member_mirrors.Add(member_mirror);
1142 }
1143 } else if (entry.IsFunction()) {
1144 const Function& func = Function::Cast(entry);
1145 if (func.is_reflectable() &&
1146 (func.kind() == UntaggedFunction::kRegularFunction ||
1147 func.kind() == UntaggedFunction::kGetterFunction ||
1148 func.kind() == UntaggedFunction::kSetterFunction)) {
1149 member_mirror =
1150 CreateMethodMirror(func, owner_mirror, AbstractType::Handle());
1151 member_mirrors.Add(member_mirror);
1152 }
1153 }
1154 }
1155
1156 return member_mirrors.ptr();
1157}
1158
1159DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 0, 1) {
1160 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1161 const Class& klass = Class::Handle(ref.GetClassReferent());
1162 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread));
1163 if (!error.IsNull()) {
1165 UNREACHABLE();
1166 }
1167 return CreateTypeVariableList(klass);
1168}
1169
1170DEFINE_NATIVE_ENTRY(ClassMirror_type_arguments, 0, 1) {
1171 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
1172
1173 const Class& cls = Class::Handle(
1174 type.IsFunctionType()
1175 ? IsolateGroup::Current()->object_store()->closure_class()
1176 : type.type_class());
1177 const intptr_t num_params = cls.NumTypeParameters();
1178
1179 if (num_params == 0) {
1180 return Object::empty_array().ptr();
1181 }
1182
1183 const Array& result = Array::Handle(Array::New(num_params));
1184 AbstractType& arg_type = AbstractType::Handle();
1185 Instance& type_mirror = Instance::Handle();
1186 const TypeArguments& args =
1187 TypeArguments::Handle(Type::Cast(type).arguments());
1188
1189 // Handle argument lists that have been optimized away, because either no
1190 // arguments have been provided, or all arguments are dynamic. Return a list
1191 // of typemirrors on dynamic in this case.
1192 if (args.IsNull()) {
1193 arg_type = Object::dynamic_type().ptr();
1194 type_mirror = CreateTypeMirror(arg_type);
1195 for (intptr_t i = 0; i < num_params; i++) {
1196 result.SetAt(i, type_mirror);
1197 }
1198 return result.ptr();
1199 }
1200
1201 ASSERT(args.Length() == num_params);
1202 for (intptr_t i = 0; i < num_params; i++) {
1203 arg_type = args.TypeAt(i);
1204 type_mirror = CreateTypeMirror(arg_type);
1205 result.SetAt(i, type_mirror);
1206 }
1207 return result.ptr();
1208}
1209
1210DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 0, 1) {
1211 // Type parameters do not have a reference to their owner anymore.
1213 Class& owner = Class::Handle(type.type_class());
1214 return CreateClassMirror(owner, type,
1215 Bool::True(), // is_declaration
1216 Instance::null_instance());
1217}
1218
1219DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 0, 1) {
1220 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1221 return param.bound();
1222}
1223
1224DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 0, 5) {
1225 // Argument 0 is the mirror, which is unused by the native. It exists
1226 // because this native is an instance method in order to be polymorphic
1227 // with its cousins.
1228 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1230 arguments->NativeArgAt(2));
1231 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1232 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1233 RETURN_OR_PROPAGATE(reflectee.Invoke(function_name, args, arg_names));
1234}
1235
1236DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 0, 3) {
1237 // Argument 0 is the mirror, which is unused by the native. It exists
1238 // because this native is an instance method in order to be polymorphic
1239 // with its cousins.
1240 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1241 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
1242 RETURN_OR_PROPAGATE(reflectee.InvokeGetter(getter_name));
1243}
1244
1245DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 0, 4) {
1246 // Argument 0 is the mirror, which is unused by the native. It exists
1247 // because this native is an instance method in order to be polymorphic
1248 // with its cousins.
1249 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1250 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1251 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1252 RETURN_OR_PROPAGATE(reflectee.InvokeSetter(setter_name, value));
1253}
1254
1255DEFINE_NATIVE_ENTRY(InstanceMirror_computeType, 0, 1) {
1256 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0));
1258 // The static type of null is specified to be the bottom type, however, the
1259 // runtime type of null is the Null type, which we correctly return here.
1260 return type.Canonicalize(thread);
1261}
1262
1263DEFINE_NATIVE_ENTRY(ClosureMirror_function, 0, 1) {
1264 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0));
1265 ASSERT(!closure.IsNull());
1266
1268 bool callable = closure.IsCallable(&function);
1269 if (callable) {
1270 const Function& parent = Function::Handle(function.parent_function());
1271 if (function.IsImplicitClosureFunction() || parent.is_extension_member() ||
1272 parent.is_extension_type_member()) {
1273 // The VM uses separate Functions for tear-offs, but the mirrors consider
1274 // the tear-offs to be the same as the torn-off methods. Avoid handing out
1275 // a reference to the tear-off here to avoid a special case in the
1276 // the equality test.
1277 // In the case of extension methods also we avoid handing out a reference
1278 // to the tear-off and instead get the parent function of the
1279 // anonymous closure.
1280 function = parent.ptr();
1281 }
1282
1283 Type& instantiator = Type::Handle();
1284 if (closure.IsClosure()) {
1285 const TypeArguments& arguments = TypeArguments::Handle(
1286 Closure::Cast(closure).instantiator_type_arguments());
1287 // TODO(regis): Mirrors need work to properly support generic functions.
1288 // The 'instantiator' created below should not be a type, but two type
1289 // argument vectors: instantiator_type_arguments and
1290 // function_type_arguments.
1291 const Class& cls = Class::Handle(
1292 IsolateGroup::Current()->object_store()->object_class());
1293 instantiator = Type::New(cls, arguments);
1294 instantiator.SetIsFinalized();
1295 }
1296 return CreateMethodMirror(function, Instance::null_instance(),
1297 instantiator);
1298 }
1299 return Instance::null();
1300}
1301
1302DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 0, 5) {
1303 // Argument 0 is the mirror, which is unused by the native. It exists
1304 // because this native is an instance method in order to be polymorphic
1305 // with its cousins.
1306 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1307 const Class& klass = Class::Handle(ref.GetClassReferent());
1309 arguments->NativeArgAt(2));
1310 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1311 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1312 RETURN_OR_PROPAGATE(klass.Invoke(function_name, args, arg_names));
1313}
1314
1315DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 0, 3) {
1316 // Argument 0 is the mirror, which is unused by the native. It exists
1317 // because this native is an instance method in order to be polymorphic
1318 // with its cousins.
1319 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1320 const Class& klass = Class::Handle(ref.GetClassReferent());
1321 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread));
1322 if (!error.IsNull()) {
1324 UNREACHABLE();
1325 }
1326 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
1327 RETURN_OR_PROPAGATE(klass.InvokeGetter(getter_name, true));
1328}
1329
1330DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 0, 4) {
1331 // Argument 0 is the mirror, which is unused by the native. It exists
1332 // because this native is an instance method in order to be polymorphic
1333 // with its cousins.
1334 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1335 const Class& klass = Class::Handle(ref.GetClassReferent());
1336 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1337 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1338 RETURN_OR_PROPAGATE(klass.InvokeSetter(setter_name, value));
1339}
1340
1341DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 0, 5) {
1342 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1343 const Class& klass = Class::Handle(ref.GetClassReferent());
1344 GET_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(1));
1345 GET_NON_NULL_NATIVE_ARGUMENT(String, constructor_name,
1346 arguments->NativeArgAt(2));
1347 GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(3));
1348 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1349
1350 const Error& error =
1351 Error::Handle(zone, klass.EnsureIsAllocateFinalized(thread));
1352 if (!error.IsNull()) {
1354 UNREACHABLE();
1355 }
1356
1357 // By convention, the static function implementing a named constructor 'C'
1358 // for class 'A' is labeled 'A.C', and the static function implementing the
1359 // unnamed constructor for class 'A' is labeled 'A.'.
1360 // This convention prevents users from explicitly calling constructors.
1361 const String& klass_name = String::Handle(klass.Name());
1362 String& external_constructor_name = String::Handle(klass_name.ptr());
1363 String& internal_constructor_name =
1365 if (!constructor_name.IsNull() && constructor_name.Length() > 0) {
1366 internal_constructor_name =
1367 String::Concat(internal_constructor_name, constructor_name);
1368 external_constructor_name = internal_constructor_name.ptr();
1369 }
1370
1371 Function& lookup_constructor = Function::Handle(
1372 Resolver::ResolveFunction(zone, klass, internal_constructor_name));
1373
1374 if (lookup_constructor.IsNull() ||
1375 (lookup_constructor.kind() != UntaggedFunction::kConstructor) ||
1376 !lookup_constructor.is_reflectable()) {
1378 external_constructor_name, explicit_args, arg_names,
1381 UNREACHABLE();
1382 }
1383
1384 if (klass.is_abstract() && !lookup_constructor.IsFactory()) {
1385 const Array& error_args = Array::Handle(Array::New(3));
1386 error_args.SetAt(0, klass_name);
1387 // 1 = script url
1388 // 2 = token position
1390 error_args);
1391 UNREACHABLE();
1392 }
1393
1394 ASSERT(!type.IsNull());
1395 TypeArguments& type_arguments = TypeArguments::Handle();
1396 if (!type.IsInstantiated()) {
1397 // Must have been a declaration type.
1398 const Type& rare_type = Type::Handle(klass.RareType());
1399 ASSERT(rare_type.IsInstantiated());
1400 type_arguments = rare_type.GetInstanceTypeArguments(thread);
1401 } else {
1402 type_arguments = type.GetInstanceTypeArguments(thread);
1403 }
1404
1405 Class& redirected_klass = Class::Handle(klass.ptr());
1406 const intptr_t num_explicit_args = explicit_args.Length();
1407 const intptr_t num_implicit_args = 1;
1408 const Array& args =
1409 Array::Handle(Array::New(num_implicit_args + num_explicit_args));
1410
1411 // Copy over the explicit arguments.
1412 Object& explicit_argument = Object::Handle();
1413 for (int i = 0; i < num_explicit_args; i++) {
1414 explicit_argument = explicit_args.At(i);
1415 args.SetAt(i + num_implicit_args, explicit_argument);
1416 }
1417
1418 const int kTypeArgsLen = 0;
1419 const Array& args_descriptor_array = Array::Handle(
1420 ArgumentsDescriptor::NewBoxed(kTypeArgsLen, args.Length(), arg_names));
1421
1422 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1423 if (!lookup_constructor.AreValidArguments(args_descriptor, nullptr)) {
1424 external_constructor_name = lookup_constructor.name();
1426 external_constructor_name, explicit_args, arg_names,
1429 UNREACHABLE();
1430 }
1431#if defined(DEBUG)
1432 // Make sure the receiver is the null value, so that DoArgumentTypesMatch does
1433 // not attempt to retrieve the instantiator type arguments from the receiver.
1434 explicit_argument = args.At(args_descriptor.FirstArgIndex());
1435 ASSERT(explicit_argument.IsNull());
1436#endif
1437 const Object& type_error =
1438 Object::Handle(lookup_constructor.DoArgumentTypesMatch(
1439 args, args_descriptor, type_arguments));
1440 if (!type_error.IsNull()) {
1441 Exceptions::PropagateError(Error::Cast(type_error));
1442 UNREACHABLE();
1443 }
1444
1445 Instance& new_object = Instance::Handle();
1446 if (lookup_constructor.IsGenerativeConstructor()) {
1447 // Constructors get the uninitialized object.
1448 // Note we have delayed allocation until after the function
1449 // type and argument matching checks.
1450 new_object = Instance::New(redirected_klass);
1451 if (!type_arguments.IsNull()) {
1452 // The type arguments will be null if the class has no type parameters, in
1453 // which case the following call would fail because there is no slot
1454 // reserved in the object for the type vector.
1455 new_object.SetTypeArguments(type_arguments);
1456 }
1457 args.SetAt(0, new_object);
1458 } else {
1459 // Factories get type arguments.
1460 args.SetAt(0, type_arguments);
1461 }
1462
1463 // Invoke the constructor and return the new object.
1465 lookup_constructor, args, args_descriptor_array));
1466 if (result.IsError()) {
1467 Exceptions::PropagateError(Error::Cast(result));
1468 UNREACHABLE();
1469 }
1470
1471 // Factories may return null.
1472 ASSERT(result.IsInstance() || result.IsNull());
1473
1474 if (lookup_constructor.IsGenerativeConstructor()) {
1475 return new_object.ptr();
1476 } else {
1477 return result.ptr();
1478 }
1479}
1480
1481DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 0, 5) {
1482 // Argument 0 is the mirror, which is unused by the native. It exists
1483 // because this native is an instance method in order to be polymorphic
1484 // with its cousins.
1485 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1486 const Library& library = Library::Handle(ref.GetLibraryReferent());
1488 arguments->NativeArgAt(2));
1489 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1490 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1491 RETURN_OR_PROPAGATE(library.Invoke(function_name, args, arg_names));
1492}
1493
1494DEFINE_NATIVE_ENTRY(LibraryMirror_invokeGetter, 0, 3) {
1495 // Argument 0 is the mirror, which is unused by the native. It exists
1496 // because this native is an instance method in order to be polymorphic
1497 // with its cousins.
1498 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1499 const Library& library = Library::Handle(ref.GetLibraryReferent());
1500 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
1501 RETURN_OR_PROPAGATE(library.InvokeGetter(getter_name, true));
1502}
1503
1504DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 0, 4) {
1505 // Argument 0 is the mirror, which is unused by the native. It exists
1506 // because this native is an instance method in order to be polymorphic
1507 // with its cousins.
1508 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1509 const Library& library = Library::Handle(ref.GetLibraryReferent());
1510 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1511 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1512 RETURN_OR_PROPAGATE(library.InvokeSetter(setter_name, value));
1513}
1514
1515DEFINE_NATIVE_ENTRY(MethodMirror_owner, 0, 2) {
1516 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1517 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1518 const Function& func = Function::Handle(ref.GetFunctionReferent());
1519 if (func.IsNonImplicitClosureFunction()) {
1521 Object::null_instance(), instantiator);
1522 }
1523 const Class& owner = Class::Handle(func.Owner());
1524 if (owner.IsTopLevel()) {
1525 return CreateLibraryMirror(thread, Library::Handle(owner.library()));
1526 }
1527
1529 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance());
1530}
1531
1532DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 0, 2) {
1533 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
1534 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1535 const Function& func = Function::Handle(ref.GetFunctionReferent());
1536 const FunctionType& sig = FunctionType::Handle(func.signature());
1537 return CreateParameterMirrorList(func, sig, owner);
1538}
1539
1540DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 0, 2) {
1541 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1542 const Function& func = Function::Handle(ref.GetFunctionReferent());
1543 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1544 // We handle constructors in Dart code.
1547 type =
1548 type.Canonicalize(thread); // Instantiated signatures are not canonical.
1549 return InstantiateType(type, instantiator);
1550}
1551
1552DEFINE_NATIVE_ENTRY(MethodMirror_source, 0, 1) {
1553 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1554 const Function& func = Function::Handle(ref.GetFunctionReferent());
1555 return func.GetSource();
1556}
1557
1558static InstancePtr CreateSourceLocation(const String& uri,
1559 intptr_t line,
1560 intptr_t column) {
1561 const Array& args = Array::Handle(Array::New(3));
1562 args.SetAt(0, uri);
1563 args.SetAt(1, Smi::Handle(Smi::New(line)));
1564 args.SetAt(2, Smi::Handle(Smi::New(column)));
1565 return CreateMirror(Symbols::_SourceLocation(), args);
1566}
1567
1568DEFINE_NATIVE_ENTRY(DeclarationMirror_location, 0, 1) {
1569 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0));
1570 Object& decl = Object::Handle(zone);
1571 if (reflectee.IsMirrorReference()) {
1572 const MirrorReference& decl_ref = MirrorReference::Cast(reflectee);
1573 decl = decl_ref.referent();
1574 } else if (reflectee.IsTypeParameter()) {
1575 decl = reflectee.ptr();
1576 } else {
1577 UNREACHABLE();
1578 }
1579
1580 Script& script = Script::Handle(zone);
1581 TokenPosition token_pos = TokenPosition::kNoSource;
1582
1583 if (decl.IsFunction()) {
1584 const Function& func = Function::Cast(decl);
1585 if (func.IsImplicitConstructor()) {
1586 // These are synthetic methods; they have no source.
1587 return Instance::null();
1588 }
1589 script = func.script();
1590 token_pos = func.token_pos();
1591 } else if (decl.IsClass()) {
1592 const Class& cls = Class::Cast(decl);
1593 if (cls.is_synthesized_class() && !cls.is_enum_class()) {
1594 return Instance::null(); // Synthetic.
1595 }
1596 script = cls.script();
1597 token_pos = cls.token_pos();
1598 } else if (decl.IsField()) {
1599 const Field& field = Field::Cast(decl);
1600 script = field.Script();
1601 token_pos = field.token_pos();
1602 } else if (decl.IsTypeParameter()) {
1603 return Instance::null();
1604 } else if (decl.IsLibrary()) {
1605 const Library& lib = Library::Cast(decl);
1606 if (lib.ptr() == Library::NativeWrappersLibrary()) {
1607 return Instance::null(); // No source.
1608 }
1609 const Array& scripts = Array::Handle(zone, lib.LoadedScripts());
1610 ASSERT(scripts.Length() > 0);
1611 script ^= scripts.At(scripts.Length() - 1);
1612 ASSERT(!script.IsNull());
1613 const String& uri = String::Handle(zone, script.url());
1614 return CreateSourceLocation(uri, 1, 1);
1615 } else {
1616 FATAL("Unexpected declaration type: %s", decl.ToCString());
1617 }
1618
1619 ASSERT(!script.IsNull());
1620 if (token_pos == TokenPosition::kNoSource) {
1621 return Instance::null();
1622 }
1623
1624 const String& uri = String::Handle(zone, script.url());
1625 intptr_t from_line = 0, from_col = 0;
1626 script.GetTokenLocation(token_pos, &from_line, &from_col);
1627 return CreateSourceLocation(uri, from_line, from_col);
1628}
1629
1630DEFINE_NATIVE_ENTRY(ParameterMirror_type, 0, 3) {
1631 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1632 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1));
1633 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(2));
1634 const FunctionType& signature =
1635 FunctionType::Handle(ref.GetFunctionTypeReferent());
1637 signature.num_implicit_parameters() + pos.Value()));
1638 type =
1639 type.Canonicalize(thread); // Instantiated signatures are not canonical.
1640 return InstantiateType(type, instantiator);
1641}
1642
1643DEFINE_NATIVE_ENTRY(VariableMirror_type, 0, 2) {
1644 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1645 const Field& field = Field::Handle(ref.GetFieldReferent());
1646 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1647 const AbstractType& type = AbstractType::Handle(field.type());
1648 return InstantiateType(type, instantiator);
1649}
1650
1651DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 0, 2) {
1652 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
1653 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
1654 return Bool::Get(a.IsSubtypeOf(b, Heap::kNew)).ptr();
1655}
1656
1657#endif // !DART_PRECOMPILED_RUNTIME
1658
1659} // namespace dart
SkPoint pos
#define UNREACHABLE()
Definition: assert.h:248
#define Z
GLenum type
virtual classid_t type_class_id() const
Definition: object.cc:21033
StringPtr UserVisibleName() const
Definition: object.cc:21331
bool IsFinalized() const
Definition: object.h:9053
virtual TypeArgumentsPtr arguments() const
Definition: object.cc:21051
void SetIsFinalized() const
Definition: object.cc:21161
static bool IsFfiEnabled()
static ArrayPtr NewBoxed(intptr_t type_args_len, intptr_t num_arguments, const Array &optional_arguments_names, Heap::Space space=Heap::kOld)
Definition: dart_entry.h:83
intptr_t FirstArgIndex() const
Definition: dart_entry.h:37
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
void MakeImmutable() const
Definition: object.cc:24837
ObjectPtr At(intptr_t index) const
Definition: object.h:10875
intptr_t Length() const
Definition: object.h:10829
void SetAt(intptr_t index, const Object &value) const
Definition: object.h:10880
static const Bool & False()
Definition: object.h:10799
static const Bool & Get(bool value)
Definition: object.h:10801
static const Bool & True()
Definition: object.h:10797
static AbstractTypePtr FinalizeType(const AbstractType &type, FinalizationKind finalization=kCanonicalize)
static bool ProcessPendingClasses()
FunctionPtr LookupFunctionAllowPrivate(const String &name) const
Definition: object.cc:6167
ObjectPtr InvokeSetter(const String &selector, const Instance &argument, bool respect_reflectable=true, bool check_is_entrypoint=false) const
Definition: object.cc:4577
LibraryPtr library() const
Definition: object.h:1333
ObjectPtr Invoke(const String &selector, const Array &arguments, const Array &argument_names, bool respect_reflectable=true, bool check_is_entrypoint=false) const
Definition: object.cc:4684
ObjectPtr InvokeGetter(const String &selector, bool throw_nsm_if_absent, bool respect_reflectable=true, bool check_is_entrypoint=false) const
Definition: object.cc:4517
TypePtr super_type() const
Definition: object.h:1431
TypePtr RareType() const
Definition: object.cc:3036
ArrayPtr interfaces() const
Definition: object.h:1447
ArrayPtr fields() const
Definition: object.h:1615
bool is_abstract() const
Definition: object.h:1696
bool IsDynamicClass() const
Definition: object.h:1556
bool IsGeneric() const
Definition: object.h:1358
StringPtr Name() const
Definition: object.cc:2977
TypePtr DeclarationType() const
Definition: object.cc:5827
TokenPosition token_pos() const
Definition: object.h:1279
ErrorPtr EnsureIsFinalized(Thread *thread) const
Definition: object.cc:4924
bool IsVoidClass() const
Definition: object.h:1559
ErrorPtr EnsureIsAllocateFinalized(Thread *thread) const
Definition: object.cc:4954
bool IsTopLevel() const
Definition: object.cc:6121
bool is_enum_class() const
Definition: object.h:1720
bool IsNeverClass() const
Definition: object.h:1562
TypeParameterPtr TypeParameterAt(intptr_t index, Nullability nullability=Nullability::kNonNullable) const
Definition: object.cc:3689
bool is_transformed_mixin_application() const
Definition: object.h:1754
bool is_synthesized_class() const
Definition: object.h:1714
intptr_t NumTypeParameters(Thread *thread) const
Definition: object.cc:3555
ArrayPtr current_functions() const
Definition: object.h:1641
ScriptPtr script() const
Definition: object.h:1272
static ObjectPtr InvokeFunction(const Function &function, const Array &arguments)
Definition: dart_entry.cc:31
static ObjectPtr InstanceCreate(const Library &library, const String &exception_name, const String &constructor_name, const Array &arguments)
Definition: dart_entry.cc:583
bool HasNext() const
Definition: object.h:5049
static DART_NORETURN void ThrowByType(ExceptionType type, const Array &arguments)
Definition: exceptions.cc:1052
static DART_NORETURN void ThrowArgumentError(const Instance &arg)
Definition: exceptions.cc:1082
@ kAbstractClassInstantiation
Definition: exceptions.h:69
static DART_NORETURN void ThrowCompileTimeError(const LanguageError &error)
Definition: exceptions.cc:1112
static DART_NORETURN void PropagateError(const Error &error)
Definition: exceptions.cc:1003
bool is_final() const
Definition: object.h:4442
ScriptPtr Script() const
Definition: object.cc:11871
bool is_reflectable() const
Definition: object.h:4454
bool is_static() const
Definition: object.h:4440
bool is_extension_member() const
Definition: object.h:4445
StringPtr name() const
Definition: object.h:4430
AbstractTypePtr type() const
Definition: object.h:4550
bool is_extension_type_member() const
Definition: object.h:4448
bool is_const() const
Definition: object.h:4443
TokenPosition token_pos() const
Definition: object.h:4589
intptr_t NumOptionalNamedParameters() const
Definition: object.h:9641
intptr_t num_implicit_parameters() const
Definition: object.h:9585
AbstractTypePtr ParameterTypeAt(intptr_t index) const
Definition: object.cc:8585
StringPtr ParameterNameAt(intptr_t index) const
Definition: object.cc:8645
AbstractTypePtr result_type() const
Definition: object.h:9670
intptr_t NumParameters() const
Definition: object.h:9648
intptr_t NumOptionalParameters() const
Definition: object.h:9625
StringPtr ParameterNameAt(intptr_t index) const
Definition: object.cc:8602
bool IsImplicitConstructor() const
Definition: object.cc:10218
StringPtr GetSource() const
Definition: object.cc:11119
ObjectPtr DoArgumentTypesMatch(const Array &args, const ArgumentsDescriptor &arg_names) const
Definition: object.cc:9505
FunctionPtr parent_function() const
Definition: object.cc:8167
bool IsGetterFunction() const
Definition: object.h:3857
StringPtr name() const
Definition: object.h:2992
bool AreValidArguments(intptr_t num_type_arguments, intptr_t num_arguments, const Array &argument_names, String *error_message) const
Definition: object.cc:9323
TokenPosition token_pos() const
Definition: object.h:3446
ScriptPtr script() const
Definition: object.cc:10881
bool IsNonImplicitClosureFunction() const
Definition: object.h:3911
bool IsFactory() const
Definition: object.h:3367
CodePtr EnsureHasCode() const
Definition: object.cc:11338
bool IsGenerativeConstructor() const
Definition: object.h:3363
ClassPtr Owner() const
Definition: object.cc:10841
UntaggedFunction::Kind kind() const
Definition: object.h:3349
bool IsSetterFunction() const
Definition: object.h:3873
AbstractTypePtr result_type() const
Definition: object.h:3099
void Add(const Object &value, Heap::Space space=Heap::kNew) const
Definition: object.cc:24991
static GrowableObjectArrayPtr New(Heap::Space space=Heap::kNew)
Definition: object.h:11144
intptr_t Length() const
Definition: object.h:11072
ObjectPtr At(intptr_t index) const
Definition: object.h:11085
@ kNew
Definition: heap.h:38
@ kOld
Definition: heap.h:39
virtual void SetTypeArguments(const TypeArguments &value) const
Definition: object.cc:20581
static InstancePtr New(const Class &cls, Heap::Space space=Heap::kNew)
Definition: object.cc:20935
static int EncodeType(Level level, Kind kind)
ObjectStore * object_store() const
Definition: isolate.h:510
static IsolateGroup * Current()
Definition: isolate.h:539
IsolateGroup * group() const
Definition: isolate.h:1037
const char * name() const
Definition: isolate.h:1043
static LibraryPtr CoreLibrary()
Definition: object.cc:14787
StringPtr PrivateName(const String &name) const
Definition: object.cc:14704
static LibraryPtr MirrorsLibrary()
Definition: object.cc:14816
bool Loaded() const
Definition: object.h:5111
static bool IsPrivate(const String &name)
Definition: object.cc:14619
ObjectPtr InvokeGetter(const String &selector, bool throw_nsm_if_absent, bool respect_reflectable=true, bool check_is_entrypoint=false) const
Definition: object.cc:14342
ArrayPtr LoadedScripts() const
Definition: object.cc:13940
ObjectPtr InvokeSetter(const String &selector, const Instance &argument, bool respect_reflectable=true, bool check_is_entrypoint=false) const
Definition: object.cc:14410
void EnsureTopLevelClassIsFinalized() const
Definition: object.cc:14044
ClassPtr LookupClassAllowPrivate(const String &name) const
Definition: object.cc:14113
ObjectPtr GetMetadata(const Object &declaration) const
Definition: object.cc:13654
ObjectPtr Invoke(const String &selector, const Array &arguments, const Array &argument_names, bool respect_reflectable=true, bool check_is_entrypoint=false) const
Definition: object.cc:14473
static LibraryPtr NativeWrappersLibrary()
Definition: object.cc:14821
StringPtr name() const
Definition: object.h:5094
ClassPtr LookupClass(const String &name) const
Definition: object.cc:14105
static LibraryPtr LookupLibrary(Thread *thread, const String &url)
Definition: object.cc:14599
ArrayPtr exports() const
Definition: object.h:5217
StringPtr url() const
Definition: object.h:5097
ArrayPtr imports() const
Definition: object.h:5216
ObjectPtr referent() const
Definition: object.h:13120
static MirrorReferencePtr New(const Object &referent, Heap::Space space=Heap::kNew)
Definition: object.cc:26916
ArrayPtr hide_names() const
Definition: object.h:5450
ArrayPtr show_names() const
Definition: object.h:5449
LibraryPtr target() const
Definition: object.h:5448
LibraryPtr owner() const
Definition: object.h:5451
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
static ObjectPtr null()
Definition: object.h:433
ObjectPtr ptr() const
Definition: object.h:332
virtual const char * ToCString() const
Definition: object.h:366
bool IsNull() const
Definition: object.h:363
static Object & Handle()
Definition: object.h:407
@ kParameterDefaultValueOffset
Definition: parser.h:341
@ kParameterIsFinalOffset
Definition: parser.h:340
@ kParameterMetadataOffset
Definition: parser.h:342
@ kParameterEntrySize
Definition: parser.h:343
static FunctionPtr ResolveDynamicAnyArgs(Zone *zone, const Class &receiver_class, const String &function_name, bool allow_add)
Definition: resolver.cc:185
static FunctionPtr ResolveFunction(Zone *zone, const Class &receiver_class, const String &function_name)
Definition: resolver.cc:167
static SmiPtr New(intptr_t value)
Definition: object.h:10006
static StringPtr ScrubNameRetainPrivate(const String &name, bool is_extension=false)
Definition: object.cc:427
bool Equals(const String &str) const
Definition: object.h:13337
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static StringPtr Concat(const String &str1, const String &str2, Heap::Space space=Heap::kNew)
Definition: object.cc:24037
static const String & Void()
Definition: symbols.h:694
static const String & Dot()
Definition: symbols.h:613
Zone * zone() const
Definition: thread_state.h:37
static Thread * Current()
Definition: thread.h:362
Isolate * isolate() const
Definition: thread.h:534
void SetTypeAt(intptr_t index, const AbstractType &value) const
Definition: object.cc:7323
static TypeArgumentsPtr New(intptr_t len, Heap::Space space=Heap::kOld)
Definition: object.cc:7675
virtual AbstractTypePtr Canonicalize(Thread *thread) const
Definition: object.cc:22859
TypeArgumentsPtr GetInstanceTypeArguments(Thread *thread, bool canonicalize=true) const
static TypePtr NullType()
virtual bool IsInstantiated(Genericity genericity=kAny, intptr_t num_free_fun_type_params=kAllFree) const
virtual AbstractTypePtr Canonicalize(Thread *thread) const
static TypePtr New(const Class &clazz, const TypeArguments &arguments, Nullability nullability=Nullability::kNonNullable, Heap::Space space=Heap::kOld)
@ Dart_kImportTag
Definition: dart_api.h:3421
@ Dart_kCanonicalizeUrl
Definition: dart_api.h:3420
#define ASSERT(E)
VkInstance instance
Definition: main.cc:48
static bool b
struct MyStruct a[10]
#define FATAL(error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
GAsyncResult * result
Dart_NativeFunction function
Definition: fuchsia.cc:51
#define HANDLESCOPE(thread)
Definition: handles.h:321
Win32Message message
#define RETURN_OR_PROPAGATE(expr)
Definition: mirrors.cc:24
#define MIRRORS_KIND_SHIFT_LIST(V)
Definition: mirrors.h:14
ObjectPtr BuildParameterDescriptor(const Function &function)
Definition: kernel.cc:573
Definition: dart_vm.cc:33
static AbstractTypePtr InstantiateType(const AbstractType &type, const AbstractType &instantiator)
Definition: mirrors.cc:614
static InstancePtr CreateIsolateMirror()
Definition: mirrors.cc:569
const char *const name
static InstancePtr CreateTypeMirror(const AbstractType &type)
Definition: mirrors.cc:518
static void ThrowLanguageError(const char *message)
Definition: mirrors.cc:670
static InstancePtr CreateFunctionTypeMirror(const AbstractType &type)
Definition: mirrors.cc:228
static InstancePtr CreateClassMirror(const Class &cls, const AbstractType &type, const Bool &is_declaration, const Instance &owner_mirror)
Definition: mirrors.cc:305
static InstancePtr CreateCombinatorMirror(const Object &identifiers, bool is_show)
Definition: mirrors.cc:362
static InstancePtr CreateMirror(const String &mirror_class_name, const Array &constructor_arguments)
Definition: mirrors.cc:31
static InstancePtr CreateMethodMirror(const Function &func, const Instance &owner_mirror, const AbstractType &instantiator)
Definition: mirrors.cc:240
static InstancePtr CreateParameterMirrorList(const Function &func, const FunctionType &signature, const Instance &owner_mirror)
Definition: mirrors.cc:96
static InstancePtr CreateLibraryDependencyMirror(Thread *thread, const Instance &importer, const Library &importee, const Array &show_names, const Array &hide_names, const Object &metadata, const LibraryPrefix &prefix, const String &prefix_name, const bool is_import, const bool is_deferred)
Definition: mirrors.cc:370
static InstancePtr CreateLibraryMirror(Thread *thread, const Library &lib)
Definition: mirrors.cc:345
static InstancePtr CreateVariableMirror(const Field &field, const Instance &owner_mirror)
Definition: mirrors.cc:284
DEFINE_NATIVE_ENTRY(List_allocate, 0, 2)
Definition: array.cc:13
static void ThrowNoSuchMethod(const Instance &receiver, const String &function_name, const Array &arguments, const Array &argument_names, const InvocationMirror::Level level, const InvocationMirror::Kind kind)
Definition: mirrors.cc:49
static InstancePtr CreateTypeVariableList(const Class &cls)
Definition: mirrors.cc:210
const char *const function_name
static InstancePtr CreateSourceLocation(const String &uri, intptr_t line, intptr_t column)
Definition: mirrors.cc:1558
static void EnsureConstructorsAreCompiled(const Function &func)
Definition: mirrors.cc:81
static void VerifyMethodKindShifts()
Definition: mirrors.cc:584
static bool IsCensoredLibrary(const String &url)
Definition: mirrors.cc:328
static InstancePtr CreateTypeVariableMirror(const TypeParameter &param, const Instance &owner_mirror)
Definition: mirrors.cc:199
@ kAllFree
Definition: object.h:2940
std::function< void()> closure
Definition: closure.h:14
#define GET_NATIVE_ARGUMENT(type, name, value)
Definition: native_entry.h:84
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)
Definition: native_entry.h:74
#define Pd
Definition: globals.h:408
#define T
Definition: precompiler.cc:65