Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: runtime/lib/mirrors.cc

Issue 2468093007: clang-format runtime/lib (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/lib/mirrors.h ('k') | runtime/lib/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "lib/mirrors.h" 5 #include "lib/mirrors.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/exceptions.h" 12 #include "vm/exceptions.h"
13 #include "vm/flags.h" 13 #include "vm/flags.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/parser.h" 15 #include "vm/parser.h"
16 #include "vm/port.h" 16 #include "vm/port.h"
17 #include "vm/resolver.h" 17 #include "vm/resolver.h"
18 #include "vm/symbols.h" 18 #include "vm/symbols.h"
19 19
20 namespace dart { 20 namespace dart {
21 21
22 #ifndef PRODUCT 22 #ifndef PRODUCT
23 23
24 #define PROPAGATE_IF_MALFORMED(type) \ 24 #define PROPAGATE_IF_MALFORMED(type) \
25 if (type.IsMalformed()) { \ 25 if (type.IsMalformed()) { \
26 Exceptions::PropagateError(Error::Handle(type.error())); \ 26 Exceptions::PropagateError(Error::Handle(type.error())); \
27 } \ 27 }
28 28
29 static RawInstance* CreateMirror(const String& mirror_class_name, 29 static RawInstance* CreateMirror(const String& mirror_class_name,
30 const Array& constructor_arguments) { 30 const Array& constructor_arguments) {
31 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); 31 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary());
32 const String& constructor_name = Symbols::Dot(); 32 const String& constructor_name = Symbols::Dot();
33 33
34 const Object& result = Object::Handle( 34 const Object& result = Object::Handle(DartLibraryCalls::InstanceCreate(
35 DartLibraryCalls::InstanceCreate(mirrors_lib, 35 mirrors_lib, mirror_class_name, constructor_name, constructor_arguments));
36 mirror_class_name,
37 constructor_name,
38 constructor_arguments));
39 ASSERT(!result.IsError()); 36 ASSERT(!result.IsError());
40 return Instance::Cast(result).raw(); 37 return Instance::Cast(result).raw();
41 } 38 }
42 39
43 40
44 // Conventions: 41 // Conventions:
45 // * For throwing a NSM in a class klass we use its runtime type as receiver, 42 // * For throwing a NSM in a class klass we use its runtime type as receiver,
46 // i.e., klass.RareType(). 43 // i.e., klass.RareType().
47 // * For throwing a NSM in a library, we just pass the null instance as 44 // * For throwing a NSM in a library, we just pass the null instance as
48 // receiver. 45 // receiver.
49 static void ThrowNoSuchMethod(const Instance& receiver, 46 static void ThrowNoSuchMethod(const Instance& receiver,
50 const String& function_name, 47 const String& function_name,
51 const Function& function, 48 const Function& function,
52 const Array& arguments, 49 const Array& arguments,
53 const Array& argument_names, 50 const Array& argument_names,
54 const InvocationMirror::Call call, 51 const InvocationMirror::Call call,
55 const InvocationMirror::Type type) { 52 const InvocationMirror::Type type) {
56 const Smi& invocation_type = Smi::Handle(Smi::New( 53 const Smi& invocation_type =
57 InvocationMirror::EncodeType(call, type))); 54 Smi::Handle(Smi::New(InvocationMirror::EncodeType(call, type)));
58 55
59 const Array& args = Array::Handle(Array::New(6)); 56 const Array& args = Array::Handle(Array::New(6));
60 args.SetAt(0, receiver); 57 args.SetAt(0, receiver);
61 args.SetAt(1, function_name); 58 args.SetAt(1, function_name);
62 args.SetAt(2, invocation_type); 59 args.SetAt(2, invocation_type);
63 args.SetAt(3, arguments); 60 args.SetAt(3, arguments);
64 if (!argument_names.IsNull() && (argument_names.Length() > 0)) { 61 if (!argument_names.IsNull() && (argument_names.Length() > 0)) {
65 // Empty and null are treated differently for some reason. Don't pass empty 62 // Empty and null are treated differently for some reason. Don't pass empty
66 // to match the non-reflective error. 63 // to match the non-reflective error.
67 args.SetAt(4, argument_names); 64 args.SetAt(4, argument_names);
68 } 65 }
69 if (!function.IsNull()) { 66 if (!function.IsNull()) {
70 const Array& array = Array::Handle(Array::New(1)); 67 const Array& array = Array::Handle(Array::New(1));
71 array.SetAt(0, String::Handle(function.UserVisibleFormalParameters())); 68 array.SetAt(0, String::Handle(function.UserVisibleFormalParameters()));
72 args.SetAt(5, array); 69 args.SetAt(5, array);
73 } 70 }
74 71
75 const Library& libcore = Library::Handle(Library::CoreLibrary()); 72 const Library& libcore = Library::Handle(Library::CoreLibrary());
76 const Class& NoSuchMethodError = Class::Handle( 73 const Class& NoSuchMethodError =
77 libcore.LookupClass(Symbols::NoSuchMethodError())); 74 Class::Handle(libcore.LookupClass(Symbols::NoSuchMethodError()));
78 const Function& throwNew = Function::Handle( 75 const Function& throwNew = Function::Handle(
79 NoSuchMethodError.LookupFunctionAllowPrivate(Symbols::ThrowNew())); 76 NoSuchMethodError.LookupFunctionAllowPrivate(Symbols::ThrowNew()));
80 const Object& result = Object::Handle( 77 const Object& result =
81 DartEntry::InvokeFunction(throwNew, args)); 78 Object::Handle(DartEntry::InvokeFunction(throwNew, args));
82 ASSERT(result.IsError()); 79 ASSERT(result.IsError());
83 Exceptions::PropagateError(Error::Cast(result)); 80 Exceptions::PropagateError(Error::Cast(result));
84 UNREACHABLE(); 81 UNREACHABLE();
85 } 82 }
86 83
87 84
88 static void EnsureConstructorsAreCompiled(const Function& func) { 85 static void EnsureConstructorsAreCompiled(const Function& func) {
89 // Only generative constructors can have initializing formals. 86 // Only generative constructors can have initializing formals.
90 if (!func.IsGenerativeConstructor()) return; 87 if (!func.IsGenerativeConstructor()) return;
91 88
92 Thread* thread = Thread::Current(); 89 Thread* thread = Thread::Current();
93 Zone* zone = thread->zone(); 90 Zone* zone = thread->zone();
94 const Class& cls = Class::Handle(zone, func.Owner()); 91 const Class& cls = Class::Handle(zone, func.Owner());
95 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); 92 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread));
96 if (!error.IsNull()) { 93 if (!error.IsNull()) {
97 Exceptions::PropagateError(error); 94 Exceptions::PropagateError(error);
98 UNREACHABLE(); 95 UNREACHABLE();
99 } 96 }
100 if (!func.HasCode()) { 97 if (!func.HasCode()) {
101 const Error& error = Error::Handle( 98 const Error& error =
102 zone, Compiler::CompileFunction(thread, func)); 99 Error::Handle(zone, Compiler::CompileFunction(thread, func));
103 if (!error.IsNull()) { 100 if (!error.IsNull()) {
104 Exceptions::PropagateError(error); 101 Exceptions::PropagateError(error);
105 UNREACHABLE(); 102 UNREACHABLE();
106 } 103 }
107 } 104 }
108 } 105 }
109 106
110 static RawInstance* CreateParameterMirrorList(const Function& func, 107 static RawInstance* CreateParameterMirrorList(const Function& func,
111 const Instance& owner_mirror) { 108 const Instance& owner_mirror) {
112 HANDLESCOPE(Thread::Current()); 109 HANDLESCOPE(Thread::Current());
113 const intptr_t implicit_param_count = func.NumImplicitParameters(); 110 const intptr_t implicit_param_count = func.NumImplicitParameters();
114 const intptr_t non_implicit_param_count = func.NumParameters() - 111 const intptr_t non_implicit_param_count =
115 implicit_param_count; 112 func.NumParameters() - implicit_param_count;
116 const intptr_t index_of_first_optional_param = 113 const intptr_t index_of_first_optional_param =
117 non_implicit_param_count - func.NumOptionalParameters(); 114 non_implicit_param_count - func.NumOptionalParameters();
118 const intptr_t index_of_first_named_param = 115 const intptr_t index_of_first_named_param =
119 non_implicit_param_count - func.NumOptionalNamedParameters(); 116 non_implicit_param_count - func.NumOptionalNamedParameters();
120 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); 117 const Array& results = Array::Handle(Array::New(non_implicit_param_count));
121 const Array& args = Array::Handle(Array::New(9)); 118 const Array& args = Array::Handle(Array::New(9));
122 119
123 Smi& pos = Smi::Handle(); 120 Smi& pos = Smi::Handle();
124 String& name = String::Handle(); 121 String& name = String::Handle();
125 Instance& param = Instance::Handle(); 122 Instance& param = Instance::Handle();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 is_final ^= Bool::True().raw(); 168 is_final ^= Bool::True().raw();
172 default_value = Object::null(); 169 default_value = Object::null();
173 metadata = Object::null(); 170 metadata = Object::null();
174 } 171 }
175 172
176 for (intptr_t i = 0; i < non_implicit_param_count; i++) { 173 for (intptr_t i = 0; i < non_implicit_param_count; i++) {
177 pos ^= Smi::New(i); 174 pos ^= Smi::New(i);
178 name ^= func.ParameterNameAt(implicit_param_count + i); 175 name ^= func.ParameterNameAt(implicit_param_count + i);
179 if (has_extra_parameter_info) { 176 if (has_extra_parameter_info) {
180 is_final ^= param_descriptor.At(i * Parser::kParameterEntrySize + 177 is_final ^= param_descriptor.At(i * Parser::kParameterEntrySize +
181 Parser::kParameterIsFinalOffset); 178 Parser::kParameterIsFinalOffset);
182 default_value = param_descriptor.At(i * Parser::kParameterEntrySize + 179 default_value = param_descriptor.At(i * Parser::kParameterEntrySize +
183 Parser::kParameterDefaultValueOffset); 180 Parser::kParameterDefaultValueOffset);
184 metadata = param_descriptor.At(i * Parser::kParameterEntrySize + 181 metadata = param_descriptor.At(i * Parser::kParameterEntrySize +
185 Parser::kParameterMetadataOffset); 182 Parser::kParameterMetadataOffset);
186 } 183 }
187 ASSERT(default_value.IsNull() || default_value.IsInstance()); 184 ASSERT(default_value.IsNull() || default_value.IsInstance());
188 185
189 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See 186 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See
190 // above. 187 // above.
191 args.SetAt(1, name); 188 args.SetAt(1, name);
192 args.SetAt(3, pos); 189 args.SetAt(3, pos);
193 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param)); 190 args.SetAt(4, Bool::Get(i >= index_of_first_optional_param));
194 args.SetAt(5, Bool::Get(i >= index_of_first_named_param)); 191 args.SetAt(5, Bool::Get(i >= index_of_first_named_param));
195 args.SetAt(6, is_final); 192 args.SetAt(6, is_final);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 268
272 String& name = String::Handle(func.name()); 269 String& name = String::Handle(func.name());
273 name = String::ScrubNameRetainPrivate(name); 270 name = String::ScrubNameRetainPrivate(name);
274 args.SetAt(1, name); 271 args.SetAt(1, name);
275 args.SetAt(2, owner_mirror); 272 args.SetAt(2, owner_mirror);
276 args.SetAt(3, instantiator); 273 args.SetAt(3, instantiator);
277 args.SetAt(4, Bool::Get(func.is_static())); 274 args.SetAt(4, Bool::Get(func.is_static()));
278 275
279 intptr_t kind_flags = 0; 276 intptr_t kind_flags = 0;
280 kind_flags |= (func.is_abstract() << Mirrors::kAbstract); 277 kind_flags |= (func.is_abstract() << Mirrors::kAbstract);
281 kind_flags |= (func.IsGetterFunction() << Mirrors::kGetter); 278 kind_flags |= (func.IsGetterFunction() << Mirrors::kGetter);
282 kind_flags |= (func.IsSetterFunction() << Mirrors::kSetter); 279 kind_flags |= (func.IsSetterFunction() << Mirrors::kSetter);
283 bool is_ctor = (func.kind() == RawFunction::kConstructor); 280 bool is_ctor = (func.kind() == RawFunction::kConstructor);
284 kind_flags |= (is_ctor << Mirrors::kConstructor); 281 kind_flags |= (is_ctor << Mirrors::kConstructor);
285 kind_flags |= ((is_ctor && func.is_const()) << Mirrors::kConstCtor); 282 kind_flags |= ((is_ctor && func.is_const()) << Mirrors::kConstCtor);
286 kind_flags |= ((is_ctor && func.IsGenerativeConstructor()) 283 kind_flags |=
287 << Mirrors::kGenerativeCtor); 284 ((is_ctor && func.IsGenerativeConstructor()) << Mirrors::kGenerativeCtor);
288 kind_flags |= ((is_ctor && func.is_redirecting()) 285 kind_flags |=
289 << Mirrors::kRedirectingCtor); 286 ((is_ctor && func.is_redirecting()) << Mirrors::kRedirectingCtor);
290 kind_flags |= ((is_ctor && func.IsFactory()) << Mirrors::kFactoryCtor); 287 kind_flags |= ((is_ctor && func.IsFactory()) << Mirrors::kFactoryCtor);
291 kind_flags |= (func.is_external() << Mirrors::kExternal); 288 kind_flags |= (func.is_external() << Mirrors::kExternal);
292 args.SetAt(5, Smi::Handle(Smi::New(kind_flags))); 289 args.SetAt(5, Smi::Handle(Smi::New(kind_flags)));
293 290
294 return CreateMirror(Symbols::_LocalMethodMirror(), args); 291 return CreateMirror(Symbols::_LocalMethodMirror(), args);
295 } 292 }
296 293
297 294
298 static RawInstance* CreateVariableMirror(const Field& field, 295 static RawInstance* CreateVariableMirror(const Field& field,
299 const Instance& owner_mirror) { 296 const Instance& owner_mirror) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 static RawInstance* CreateLibraryMirror(Thread* thread, const Library& lib) { 354 static RawInstance* CreateLibraryMirror(Thread* thread, const Library& lib) {
358 Zone* zone = thread->zone(); 355 Zone* zone = thread->zone();
359 ASSERT(!lib.IsNull()); 356 ASSERT(!lib.IsNull());
360 const Array& args = Array::Handle(zone, Array::New(3)); 357 const Array& args = Array::Handle(zone, Array::New(3));
361 args.SetAt(0, MirrorReference::Handle(zone, MirrorReference::New(lib))); 358 args.SetAt(0, MirrorReference::Handle(zone, MirrorReference::New(lib)));
362 String& str = String::Handle(zone); 359 String& str = String::Handle(zone);
363 str = lib.name(); 360 str = lib.name();
364 args.SetAt(1, str); 361 args.SetAt(1, str);
365 str = lib.url(); 362 str = lib.url();
366 const char* censored_libraries[] = { 363 const char* censored_libraries[] = {
367 "dart:_builtin", 364 "dart:_builtin", "dart:_blink", "dart:_vmservice", NULL,
368 "dart:_blink",
369 "dart:_vmservice",
370 NULL,
371 }; 365 };
372 for (intptr_t i = 0; censored_libraries[i] != NULL; i++) { 366 for (intptr_t i = 0; censored_libraries[i] != NULL; i++) {
373 if (str.Equals(censored_libraries[i])) { 367 if (str.Equals(censored_libraries[i])) {
374 // Censored library (grumble). 368 // Censored library (grumble).
375 return Instance::null(); 369 return Instance::null();
376 } 370 }
377 } 371 }
378 if (str.Equals("dart:io")) { 372 if (str.Equals("dart:io")) {
379 // Hack around dart:io being loaded into non-service isolates in Dartium. 373 // Hack around dart:io being loaded into non-service isolates in Dartium.
380 Isolate* isolate = thread->isolate(); 374 Isolate* isolate = thread->isolate();
381 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( 375 const GrowableObjectArray& libraries =
382 zone, isolate->object_store()->libraries()); 376 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries());
383 Library& other_lib = Library::Handle(zone); 377 Library& other_lib = Library::Handle(zone);
384 String& other_uri = String::Handle(zone); 378 String& other_uri = String::Handle(zone);
385 for (intptr_t i = 0; i < libraries.Length(); i++) { 379 for (intptr_t i = 0; i < libraries.Length(); i++) {
386 other_lib ^= libraries.At(i); 380 other_lib ^= libraries.At(i);
387 other_uri = other_lib.url(); 381 other_uri = other_lib.url();
388 if (other_uri.Equals("dart:html")) { 382 if (other_uri.Equals("dart:html")) {
389 return Instance::null(); 383 return Instance::null();
390 } 384 }
391 } 385 }
392 } 386 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 Instance& dep = Instance::Handle(); 470 Instance& dep = Instance::Handle();
477 LibraryPrefix& prefix = LibraryPrefix::Handle(); 471 LibraryPrefix& prefix = LibraryPrefix::Handle();
478 GrowableObjectArray& deps = 472 GrowableObjectArray& deps =
479 GrowableObjectArray::Handle(GrowableObjectArray::New()); 473 GrowableObjectArray::Handle(GrowableObjectArray::New());
480 474
481 // Unprefixed imports. 475 // Unprefixed imports.
482 ports = lib.imports(); 476 ports = lib.imports();
483 for (intptr_t i = 0; i < ports.Length(); i++) { 477 for (intptr_t i = 0; i < ports.Length(); i++) {
484 ns ^= ports.At(i); 478 ns ^= ports.At(i);
485 if (!ns.IsNull()) { 479 if (!ns.IsNull()) {
486 dep = CreateLibraryDependencyMirror( 480 dep = CreateLibraryDependencyMirror(thread, lib_mirror, ns, prefix, true,
487 thread, lib_mirror, ns, prefix, true, false); 481 false);
488 if (!dep.IsNull()) { 482 if (!dep.IsNull()) {
489 deps.Add(dep); 483 deps.Add(dep);
490 } 484 }
491 } 485 }
492 } 486 }
493 487
494 // Exports. 488 // Exports.
495 ports = lib.exports(); 489 ports = lib.exports();
496 for (intptr_t i = 0; i < ports.Length(); i++) { 490 for (intptr_t i = 0; i < ports.Length(); i++) {
497 ns ^= ports.At(i); 491 ns ^= ports.At(i);
498 dep = CreateLibraryDependencyMirror( 492 dep = CreateLibraryDependencyMirror(thread, lib_mirror, ns, prefix, false,
499 thread, lib_mirror, ns, prefix, false, false); 493 false);
500 if (!dep.IsNull()) { 494 if (!dep.IsNull()) {
501 deps.Add(dep); 495 deps.Add(dep);
502 } 496 }
503 } 497 }
504 498
505 // Prefixed imports. 499 // Prefixed imports.
506 DictionaryIterator entries(lib); 500 DictionaryIterator entries(lib);
507 Object& entry = Object::Handle(); 501 Object& entry = Object::Handle();
508 while (entries.HasNext()) { 502 while (entries.HasNext()) {
509 entry = entries.GetNext(); 503 entry = entries.GetNext();
510 if (entry.IsLibraryPrefix()) { 504 if (entry.IsLibraryPrefix()) {
511 prefix ^= entry.raw(); 505 prefix ^= entry.raw();
512 ports = prefix.imports(); 506 ports = prefix.imports();
513 for (intptr_t i = 0; i < ports.Length(); i++) { 507 for (intptr_t i = 0; i < ports.Length(); i++) {
514 ns ^= ports.At(i); 508 ns ^= ports.At(i);
515 if (!ns.IsNull()) { 509 if (!ns.IsNull()) {
516 dep = CreateLibraryDependencyMirror( 510 dep = CreateLibraryDependencyMirror(thread, lib_mirror, ns, prefix,
517 thread, lib_mirror, ns, prefix, true, prefix.is_deferred_load()); 511 true, prefix.is_deferred_load());
518 if (!dep.IsNull()) { 512 if (!dep.IsNull()) {
519 deps.Add(dep); 513 deps.Add(dep);
520 } 514 }
521 } 515 }
522 } 516 }
523 } 517 }
524 } 518 }
525 519
526 return deps.raw(); 520 return deps.raw();
527 } 521 }
528 522
529 523
530 static RawInstance* CreateTypeMirror(const AbstractType& type) { 524 static RawInstance* CreateTypeMirror(const AbstractType& type) {
531 if (type.IsTypeRef()) { 525 if (type.IsTypeRef()) {
532 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); 526 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type());
533 ASSERT(!ref_type.IsTypeRef()); 527 ASSERT(!ref_type.IsTypeRef());
534 ASSERT(ref_type.IsCanonical()); 528 ASSERT(ref_type.IsCanonical());
535 return CreateTypeMirror(ref_type); 529 return CreateTypeMirror(ref_type);
536 } 530 }
537 ASSERT(type.IsFinalized()); 531 ASSERT(type.IsFinalized());
538 PROPAGATE_IF_MALFORMED(type); 532 PROPAGATE_IF_MALFORMED(type);
539 ASSERT(type.IsCanonical() || type.IsTypeParameter() || type.IsBoundedType()); 533 ASSERT(type.IsCanonical() || type.IsTypeParameter() || type.IsBoundedType());
540 534
541 if (type.IsFunctionType()) { 535 if (type.IsFunctionType()) {
542 const Class& scope_class = Class::Handle(Type::Cast(type).type_class()); 536 const Class& scope_class = Class::Handle(Type::Cast(type).type_class());
543 if (scope_class.IsTypedefClass()) { 537 if (scope_class.IsTypedefClass()) {
544 return CreateTypedefMirror(scope_class, 538 return CreateTypedefMirror(scope_class, type, Bool::False(),
545 type, Bool::False(), Object::null_instance()); 539 Object::null_instance());
546 } else { 540 } else {
547 return CreateFunctionTypeMirror(type); 541 return CreateFunctionTypeMirror(type);
548 } 542 }
549 } 543 }
550 if (type.HasResolvedTypeClass()) { 544 if (type.HasResolvedTypeClass()) {
551 const Class& cls = Class::Handle(type.type_class()); 545 const Class& cls = Class::Handle(type.type_class());
552 // Handle void and dynamic types. 546 // Handle void and dynamic types.
553 if (cls.IsVoidClass()) { 547 if (cls.IsVoidClass()) {
554 Array& args = Array::Handle(Array::New(1)); 548 Array& args = Array::Handle(Array::New(1));
555 args.SetAt(0, Symbols::Void()); 549 args.SetAt(0, Symbols::Void());
(...skipping 14 matching lines...) Expand all
570 } 564 }
571 UNREACHABLE(); 565 UNREACHABLE();
572 return Instance::null(); 566 return Instance::null();
573 } 567 }
574 568
575 569
576 static RawInstance* CreateIsolateMirror() { 570 static RawInstance* CreateIsolateMirror() {
577 Thread* thread = Thread::Current(); 571 Thread* thread = Thread::Current();
578 Isolate* isolate = thread->isolate(); 572 Isolate* isolate = thread->isolate();
579 const String& debug_name = String::Handle(String::New(isolate->name())); 573 const String& debug_name = String::Handle(String::New(isolate->name()));
580 const Library& root_library = Library::Handle(thread->zone(), 574 const Library& root_library =
581 isolate->object_store()->root_library()); 575 Library::Handle(thread->zone(), isolate->object_store()->root_library());
582 const Instance& root_library_mirror = 576 const Instance& root_library_mirror =
583 Instance::Handle(CreateLibraryMirror(thread, root_library)); 577 Instance::Handle(CreateLibraryMirror(thread, root_library));
584 578
585 const Array& args = Array::Handle(Array::New(2)); 579 const Array& args = Array::Handle(Array::New(2));
586 args.SetAt(0, debug_name); 580 args.SetAt(0, debug_name);
587 args.SetAt(1, root_library_mirror); 581 args.SetAt(1, root_library_mirror);
588 return CreateMirror(Symbols::_LocalIsolateMirror(), args); 582 return CreateMirror(Symbols::_LocalIsolateMirror(), args);
589 } 583 }
590 584
591 585
592 static void VerifyMethodKindShifts() { 586 static void VerifyMethodKindShifts() {
593 #ifdef DEBUG 587 #ifdef DEBUG
594 Thread* thread = Thread::Current(); 588 Thread* thread = Thread::Current();
595 Zone* zone = thread->zone(); 589 Zone* zone = thread->zone();
596 const Library& lib = Library::Handle(zone, Library::MirrorsLibrary()); 590 const Library& lib = Library::Handle(zone, Library::MirrorsLibrary());
597 const Class& cls = Class::Handle(zone, 591 const Class& cls = Class::Handle(
598 lib.LookupClassAllowPrivate(Symbols::_LocalMethodMirror())); 592 zone, lib.LookupClassAllowPrivate(Symbols::_LocalMethodMirror()));
599 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); 593 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread));
600 ASSERT(error.IsNull()); 594 ASSERT(error.IsNull());
601 595
602 Field& field = Field::Handle(); 596 Field& field = Field::Handle();
603 Smi& value = Smi::Handle(); 597 Smi& value = Smi::Handle();
604 598
605 #define CHECK_KIND_SHIFT(name) \ 599 #define CHECK_KIND_SHIFT(name) \
606 field = cls.LookupField(String::Handle(String::New(#name))); \ 600 field = cls.LookupField(String::Handle(String::New(#name))); \
607 ASSERT(!field.IsNull()); \ 601 ASSERT(!field.IsNull()); \
608 value ^= field.StaticValue(); \ 602 value ^= field.StaticValue(); \
609 ASSERT(value.Value() == Mirrors::name); 603 ASSERT(value.Value() == Mirrors::name);
610 MIRRORS_KIND_SHIFT_LIST(CHECK_KIND_SHIFT) 604 MIRRORS_KIND_SHIFT_LIST(CHECK_KIND_SHIFT)
611 #undef CHECK_KIND_SHIFT 605 #undef CHECK_KIND_SHIFT
612 #endif 606 #endif
613 } 607 }
614 608
615 609
616 static RawInstance* ReturnResult(const Object& result) { 610 static RawInstance* ReturnResult(const Object& result) {
617 if (result.IsError()) { 611 if (result.IsError()) {
618 Exceptions::PropagateError(Error::Cast(result)); 612 Exceptions::PropagateError(Error::Cast(result));
619 UNREACHABLE(); 613 UNREACHABLE();
620 } 614 }
621 if (result.IsInstance()) { 615 if (result.IsInstance()) {
622 return Instance::Cast(result).raw(); 616 return Instance::Cast(result).raw();
623 } 617 }
624 ASSERT(result.IsNull()); 618 ASSERT(result.IsNull());
625 return Instance::null(); 619 return Instance::null();
626 } 620 }
627 621
628 622
629 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled 623 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled
630 // exceptions. Wrap and propagate any compilation errors. 624 // exceptions. Wrap and propagate any compilation errors.
631 static RawInstance* InvokeDynamicFunction( 625 static RawInstance* InvokeDynamicFunction(const Instance& receiver,
632 const Instance& receiver, 626 const Function& function,
633 const Function& function, 627 const String& target_name,
634 const String& target_name, 628 const Array& args,
635 const Array& args, 629 const Array& args_descriptor_array) {
636 const Array& args_descriptor_array) {
637 // Note "args" is already the internal arguments with the receiver as the 630 // Note "args" is already the internal arguments with the receiver as the
638 // first element. 631 // first element.
639 Object& result = Object::Handle(); 632 Object& result = Object::Handle();
640 ArgumentsDescriptor args_descriptor(args_descriptor_array); 633 ArgumentsDescriptor args_descriptor(args_descriptor_array);
641 if (function.IsNull() || 634 if (function.IsNull() || !function.is_reflectable() ||
642 !function.is_reflectable() ||
643 !function.AreValidArguments(args_descriptor, NULL)) { 635 !function.AreValidArguments(args_descriptor, NULL)) {
644 result = DartEntry::InvokeNoSuchMethod(receiver, 636 result = DartEntry::InvokeNoSuchMethod(receiver, target_name, args,
645 target_name,
646 args,
647 args_descriptor_array); 637 args_descriptor_array);
648 } else { 638 } else {
649 result = DartEntry::InvokeFunction(function, 639 result = DartEntry::InvokeFunction(function, args, args_descriptor_array);
650 args,
651 args_descriptor_array);
652 } 640 }
653 return ReturnResult(result); 641 return ReturnResult(result);
654 } 642 }
655 643
656 644
657 static RawInstance* InvokeLibraryGetter(const Library& library, 645 static RawInstance* InvokeLibraryGetter(const Library& library,
658 const String& getter_name, 646 const String& getter_name,
659 const bool throw_nsm_if_absent) { 647 const bool throw_nsm_if_absent) {
660 // To access a top-level we may need to use the Field or the getter Function. 648 // To access a top-level we may need to use the Field or the getter Function.
661 // The getter function may either be in the library or in the field's owner 649 // The getter function may either be in the library or in the field's owner
662 // class, depending on whether it was an actual getter, or an uninitialized 650 // class, depending on whether it was an actual getter, or an uninitialized
663 // field. 651 // field.
664 const Field& field = Field::Handle( 652 const Field& field = Field::Handle(library.LookupLocalField(getter_name));
665 library.LookupLocalField(getter_name));
666 Function& getter = Function::Handle(); 653 Function& getter = Function::Handle();
667 if (field.IsNull()) { 654 if (field.IsNull()) {
668 // No field found. Check for a getter in the lib. 655 // No field found. Check for a getter in the lib.
669 const String& internal_getter_name = 656 const String& internal_getter_name =
670 String::Handle(Field::GetterName(getter_name)); 657 String::Handle(Field::GetterName(getter_name));
671 getter = library.LookupLocalFunction(internal_getter_name); 658 getter = library.LookupLocalFunction(internal_getter_name);
672 if (getter.IsNull()) { 659 if (getter.IsNull()) {
673 getter = library.LookupLocalFunction(getter_name); 660 getter = library.LookupLocalFunction(getter_name);
674 if (!getter.IsNull()) { 661 if (!getter.IsNull()) {
675 // Looking for a getter but found a regular method: closurize it. 662 // Looking for a getter but found a regular method: closurize it.
(...skipping 15 matching lines...) Expand all
691 } 678 }
692 679
693 if (!getter.IsNull() && getter.is_reflectable()) { 680 if (!getter.IsNull() && getter.is_reflectable()) {
694 // Invoke the getter and return the result. 681 // Invoke the getter and return the result.
695 const Object& result = Object::Handle( 682 const Object& result = Object::Handle(
696 DartEntry::InvokeFunction(getter, Object::empty_array())); 683 DartEntry::InvokeFunction(getter, Object::empty_array()));
697 return ReturnResult(result); 684 return ReturnResult(result);
698 } 685 }
699 686
700 if (throw_nsm_if_absent) { 687 if (throw_nsm_if_absent) {
701 ThrowNoSuchMethod(Instance::null_instance(), 688 ThrowNoSuchMethod(Instance::null_instance(), getter_name, getter,
702 getter_name, 689 Object::null_array(), Object::null_array(),
703 getter, 690 InvocationMirror::kTopLevel, InvocationMirror::kGetter);
704 Object::null_array(),
705 Object::null_array(),
706 InvocationMirror::kTopLevel,
707 InvocationMirror::kGetter);
708 UNREACHABLE(); 691 UNREACHABLE();
709 } 692 }
710 693
711 // Fall through case: Indicate that we didn't find any function or field using 694 // Fall through case: Indicate that we didn't find any function or field using
712 // a special null instance. This is different from a field being null. Callers 695 // a special null instance. This is different from a field being null. Callers
713 // make sure that this null does not leak into Dartland. 696 // make sure that this null does not leak into Dartland.
714 return Object::sentinel().raw(); 697 return Object::sentinel().raw();
715 } 698 }
716 699
717 700
718 static RawInstance* InvokeClassGetter(const Class& klass, 701 static RawInstance* InvokeClassGetter(const Class& klass,
719 const String& getter_name, 702 const String& getter_name,
720 const bool throw_nsm_if_absent) { 703 const bool throw_nsm_if_absent) {
721 // Note static fields do not have implicit getters. 704 // Note static fields do not have implicit getters.
722 const Field& field = 705 const Field& field = Field::Handle(klass.LookupStaticField(getter_name));
723 Field::Handle(klass.LookupStaticField(getter_name));
724 if (field.IsNull() || field.IsUninitialized()) { 706 if (field.IsNull() || field.IsUninitialized()) {
725 const String& internal_getter_name = String::Handle( 707 const String& internal_getter_name =
726 Field::GetterName(getter_name)); 708 String::Handle(Field::GetterName(getter_name));
727 Function& getter = Function::Handle( 709 Function& getter =
728 klass.LookupStaticFunction(internal_getter_name)); 710 Function::Handle(klass.LookupStaticFunction(internal_getter_name));
729 711
730 if (getter.IsNull() || !getter.is_reflectable()) { 712 if (getter.IsNull() || !getter.is_reflectable()) {
731 if (getter.IsNull()) { 713 if (getter.IsNull()) {
732 getter = klass.LookupStaticFunction(getter_name); 714 getter = klass.LookupStaticFunction(getter_name);
733 if (!getter.IsNull()) { 715 if (!getter.IsNull()) {
734 // Looking for a getter but found a regular method: closurize it. 716 // Looking for a getter but found a regular method: closurize it.
735 const Function& closure_function = 717 const Function& closure_function =
736 Function::Handle(getter.ImplicitClosureFunction()); 718 Function::Handle(getter.ImplicitClosureFunction());
737 return closure_function.ImplicitStaticClosure(); 719 return closure_function.ImplicitStaticClosure();
738 } 720 }
739 } 721 }
740 if (throw_nsm_if_absent) { 722 if (throw_nsm_if_absent) {
741 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 723 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), getter_name,
742 getter_name, 724 getter, Object::null_array(), Object::null_array(),
743 getter, 725 InvocationMirror::kStatic, InvocationMirror::kGetter);
744 Object::null_array(),
745 Object::null_array(),
746 InvocationMirror::kStatic,
747 InvocationMirror::kGetter);
748 UNREACHABLE(); 726 UNREACHABLE();
749 } 727 }
750 // Fall through case: Indicate that we didn't find any function or field 728 // Fall through case: Indicate that we didn't find any function or field
751 // using a special null instance. This is different from a field being 729 // using a special null instance. This is different from a field being
752 // null. Callers make sure that this null does not leak into Dartland. 730 // null. Callers make sure that this null does not leak into Dartland.
753 return Object::sentinel().raw(); 731 return Object::sentinel().raw();
754 } 732 }
755 733
756 // Invoke the getter and return the result. 734 // Invoke the getter and return the result.
757 const Object& result = Object::Handle( 735 const Object& result = Object::Handle(
(...skipping 26 matching lines...) Expand all
784 if (!bound_error.IsNull()) { 762 if (!bound_error.IsNull()) {
785 Exceptions::PropagateError(bound_error); 763 Exceptions::PropagateError(bound_error);
786 UNREACHABLE(); 764 UNREACHABLE();
787 } 765 }
788 ASSERT(result.IsFinalized()); 766 ASSERT(result.IsFinalized());
789 return result.Canonicalize(); 767 return result.Canonicalize();
790 } 768 }
791 769
792 770
793 DEFINE_NATIVE_ENTRY(MirrorSystem_libraries, 0) { 771 DEFINE_NATIVE_ENTRY(MirrorSystem_libraries, 0) {
794 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( 772 const GrowableObjectArray& libraries =
795 zone, isolate->object_store()->libraries()); 773 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries());
796 774
797 const intptr_t num_libraries = libraries.Length(); 775 const intptr_t num_libraries = libraries.Length();
798 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle( 776 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle(
799 zone, GrowableObjectArray::New(num_libraries)); 777 zone, GrowableObjectArray::New(num_libraries));
800 Library& library = Library::Handle(zone); 778 Library& library = Library::Handle(zone);
801 Instance& library_mirror = Instance::Handle(zone); 779 Instance& library_mirror = Instance::Handle(zone);
802 780
803 for (int i = 0; i < num_libraries; i++) { 781 for (int i = 0; i < num_libraries; i++) {
804 library ^= libraries.At(i); 782 library ^= libraries.At(i);
805 library_mirror = CreateLibraryMirror(thread, library); 783 library_mirror = CreateLibraryMirror(thread, library);
(...skipping 16 matching lines...) Expand all
822 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 800 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
823 PROPAGATE_IF_MALFORMED(type); 801 PROPAGATE_IF_MALFORMED(type);
824 ASSERT(type.IsFinalized()); 802 ASSERT(type.IsFinalized());
825 ASSERT(type.HasResolvedTypeClass()); 803 ASSERT(type.HasResolvedTypeClass());
826 const Class& cls = Class::Handle(type.type_class()); 804 const Class& cls = Class::Handle(type.type_class());
827 ASSERT(!cls.IsNull()); 805 ASSERT(!cls.IsNull());
828 if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsTypedefClass()) { 806 if (cls.IsDynamicClass() || cls.IsVoidClass() || cls.IsTypedefClass()) {
829 Exceptions::ThrowArgumentError(type); 807 Exceptions::ThrowArgumentError(type);
830 UNREACHABLE(); 808 UNREACHABLE();
831 } 809 }
832 return CreateClassMirror(cls, 810 return CreateClassMirror(cls, AbstractType::Handle(cls.DeclarationType()),
833 AbstractType::Handle(cls.DeclarationType()),
834 Bool::True(), // is_declaration 811 Bool::True(), // is_declaration
835 Object::null_instance()); 812 Object::null_instance());
836 } 813 }
837 814
838 815
839 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { 816 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) {
840 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 817 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
841 return CreateTypeMirror(type); 818 return CreateTypeMirror(type);
842 } 819 }
843 820
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 869
893 const Object& metadata = Object::Handle(library.GetMetadata(decl)); 870 const Object& metadata = Object::Handle(library.GetMetadata(decl));
894 if (metadata.IsError()) { 871 if (metadata.IsError()) {
895 Exceptions::PropagateError(Error::Cast(metadata)); 872 Exceptions::PropagateError(Error::Cast(metadata));
896 } 873 }
897 return metadata.raw(); 874 return metadata.raw();
898 } 875 }
899 876
900 877
901 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { 878 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) {
902 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 879 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner_mirror,
903 owner_mirror,
904 arguments->NativeArgAt(0)); 880 arguments->NativeArgAt(0));
905 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 881 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
906 // TODO(rmacnak): Return get:call() method on class _Closure instead? 882 // TODO(rmacnak): Return get:call() method on class _Closure instead?
907 // This now returns the result of invoking that call getter. 883 // This now returns the result of invoking that call getter.
908 const Function& func = Function::Handle(ref.GetFunctionReferent()); 884 const Function& func = Function::Handle(ref.GetFunctionReferent());
909 ASSERT(!func.IsNull()); 885 ASSERT(!func.IsNull());
910 return CreateMethodMirror(func, owner_mirror, AbstractType::Handle()); 886 return CreateMethodMirror(func, owner_mirror, AbstractType::Handle());
911 } 887 }
912 888
913 889
914 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) { 890 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) {
915 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); 891 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
916 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 892 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
917 const Function& func = Function::Handle(ref.GetFunctionReferent()); 893 const Function& func = Function::Handle(ref.GetFunctionReferent());
918 return CreateParameterMirrorList(func, owner); 894 return CreateParameterMirrorList(func, owner);
919 } 895 }
920 896
921 897
922 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 2) { 898 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 2) {
923 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 899 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
924 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, 900 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, instantiator,
925 instantiator,
926 arguments->NativeArgAt(1)); 901 arguments->NativeArgAt(1));
927 const Function& func = Function::Handle(ref.GetFunctionReferent()); 902 const Function& func = Function::Handle(ref.GetFunctionReferent());
928 ASSERT(!func.IsNull()); 903 ASSERT(!func.IsNull());
929 AbstractType& type = AbstractType::Handle(func.result_type()); 904 AbstractType& type = AbstractType::Handle(func.result_type());
930 return InstantiateType(type, instantiator); 905 return InstantiateType(type, instantiator);
931 } 906 }
932 907
933 908
934 DEFINE_NATIVE_ENTRY(ClassMirror_libraryUri, 1) { 909 DEFINE_NATIVE_ENTRY(ClassMirror_libraryUri, 1) {
935 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 910 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 ASSERT(type.IsFinalized()); 979 ASSERT(type.IsFinalized());
1005 const Class& cls = Class::Handle(type.type_class()); 980 const Class& cls = Class::Handle(type.type_class());
1006 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); 981 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin());
1007 ASSERT(mixin_type.IsNull() || mixin_type.IsFinalized()); 982 ASSERT(mixin_type.IsNull() || mixin_type.IsFinalized());
1008 return mixin_type.raw(); 983 return mixin_type.raw();
1009 } 984 }
1010 985
1011 986
1012 DEFINE_NATIVE_ENTRY(ClassMirror_mixin_instantiated, 2) { 987 DEFINE_NATIVE_ENTRY(ClassMirror_mixin_instantiated, 2) {
1013 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 988 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
1014 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, 989 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, instantiator,
1015 instantiator,
1016 arguments->NativeArgAt(1)); 990 arguments->NativeArgAt(1));
1017 PROPAGATE_IF_MALFORMED(type); 991 PROPAGATE_IF_MALFORMED(type);
1018 ASSERT(type.IsFinalized()); 992 ASSERT(type.IsFinalized());
1019 const Class& cls = Class::Handle(type.type_class()); 993 const Class& cls = Class::Handle(type.type_class());
1020 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); 994 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin());
1021 if (mixin_type.IsNull()) { 995 if (mixin_type.IsNull()) {
1022 return mixin_type.raw(); 996 return mixin_type.raw();
1023 } 997 }
1024 998
1025 return InstantiateType(mixin_type, instantiator); 999 return InstantiateType(mixin_type, instantiator);
1026 } 1000 }
1027 1001
1028 1002
1029 DEFINE_NATIVE_ENTRY(ClassMirror_members, 3) { 1003 DEFINE_NATIVE_ENTRY(ClassMirror_members, 3) {
1030 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1004 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner_mirror,
1031 owner_mirror,
1032 arguments->NativeArgAt(0)); 1005 arguments->NativeArgAt(0));
1033 GET_NATIVE_ARGUMENT(AbstractType, 1006 GET_NATIVE_ARGUMENT(AbstractType, owner_instantiator,
1034 owner_instantiator,
1035 arguments->NativeArgAt(1)); 1007 arguments->NativeArgAt(1));
1036 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2)); 1008 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2));
1037 const Class& klass = Class::Handle(ref.GetClassReferent()); 1009 const Class& klass = Class::Handle(ref.GetClassReferent());
1038 1010
1039 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread)); 1011 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread));
1040 if (!error.IsNull()) { 1012 if (!error.IsNull()) {
1041 Exceptions::PropagateError(error); 1013 Exceptions::PropagateError(error);
1042 } 1014 }
1043 1015
1044 const Array& fields = Array::Handle(klass.fields()); 1016 const Array& fields = Array::Handle(klass.fields());
(...skipping 13 matching lines...) Expand all
1058 member_mirror = CreateVariableMirror(field, owner_mirror); 1030 member_mirror = CreateVariableMirror(field, owner_mirror);
1059 member_mirrors.Add(member_mirror); 1031 member_mirrors.Add(member_mirror);
1060 } 1032 }
1061 } 1033 }
1062 1034
1063 Function& func = Function::Handle(); 1035 Function& func = Function::Handle();
1064 for (intptr_t i = 0; i < num_functions; i++) { 1036 for (intptr_t i = 0; i < num_functions; i++) {
1065 func ^= functions.At(i); 1037 func ^= functions.At(i);
1066 if (func.is_reflectable() && 1038 if (func.is_reflectable() &&
1067 (func.kind() == RawFunction::kRegularFunction || 1039 (func.kind() == RawFunction::kRegularFunction ||
1068 func.kind() == RawFunction::kGetterFunction || 1040 func.kind() == RawFunction::kGetterFunction ||
1069 func.kind() == RawFunction::kSetterFunction)) { 1041 func.kind() == RawFunction::kSetterFunction)) {
1070 member_mirror = CreateMethodMirror(func, owner_mirror, 1042 member_mirror =
1071 owner_instantiator); 1043 CreateMethodMirror(func, owner_mirror, owner_instantiator);
1072 member_mirrors.Add(member_mirror); 1044 member_mirrors.Add(member_mirror);
1073 } 1045 }
1074 } 1046 }
1075 1047
1076 return member_mirrors.raw(); 1048 return member_mirrors.raw();
1077 } 1049 }
1078 1050
1079 1051
1080 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 3) { 1052 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 3) {
1081 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1053 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner_mirror,
1082 owner_mirror,
1083 arguments->NativeArgAt(0)); 1054 arguments->NativeArgAt(0));
1084 GET_NATIVE_ARGUMENT(AbstractType, 1055 GET_NATIVE_ARGUMENT(AbstractType, owner_instantiator,
1085 owner_instantiator,
1086 arguments->NativeArgAt(1)); 1056 arguments->NativeArgAt(1));
1087 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2)); 1057 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2));
1088 const Class& klass = Class::Handle(ref.GetClassReferent()); 1058 const Class& klass = Class::Handle(ref.GetClassReferent());
1089 1059
1090 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread)); 1060 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread));
1091 if (!error.IsNull()) { 1061 if (!error.IsNull()) {
1092 Exceptions::PropagateError(error); 1062 Exceptions::PropagateError(error);
1093 } 1063 }
1094 1064
1095 const Array& functions = Array::Handle(klass.functions()); 1065 const Array& functions = Array::Handle(klass.functions());
1096 const intptr_t num_functions = functions.Length(); 1066 const intptr_t num_functions = functions.Length();
1097 1067
1098 Instance& constructor_mirror = Instance::Handle(); 1068 Instance& constructor_mirror = Instance::Handle();
1099 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( 1069 const GrowableObjectArray& constructor_mirrors =
1100 GrowableObjectArray::New(num_functions)); 1070 GrowableObjectArray::Handle(GrowableObjectArray::New(num_functions));
1101 1071
1102 Function& func = Function::Handle(); 1072 Function& func = Function::Handle();
1103 for (intptr_t i = 0; i < num_functions; i++) { 1073 for (intptr_t i = 0; i < num_functions; i++) {
1104 func ^= functions.At(i); 1074 func ^= functions.At(i);
1105 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) { 1075 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) {
1106 constructor_mirror = CreateMethodMirror(func, owner_mirror, 1076 constructor_mirror =
1107 owner_instantiator); 1077 CreateMethodMirror(func, owner_mirror, owner_instantiator);
1108 constructor_mirrors.Add(constructor_mirror); 1078 constructor_mirrors.Add(constructor_mirror);
1109 } 1079 }
1110 } 1080 }
1111 1081
1112 return constructor_mirrors.raw(); 1082 return constructor_mirrors.raw();
1113 } 1083 }
1114 1084
1115 1085
1116 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { 1086 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) {
1117 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1087 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner_mirror,
1118 owner_mirror,
1119 arguments->NativeArgAt(0)); 1088 arguments->NativeArgAt(0));
1120 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1089 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1121 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1090 const Library& library = Library::Handle(ref.GetLibraryReferent());
1122 1091
1123 Instance& member_mirror = Instance::Handle(); 1092 Instance& member_mirror = Instance::Handle();
1124 const GrowableObjectArray& member_mirrors = 1093 const GrowableObjectArray& member_mirrors =
1125 GrowableObjectArray::Handle(GrowableObjectArray::New()); 1094 GrowableObjectArray::Handle(GrowableObjectArray::New());
1126 1095
1127 Object& entry = Object::Handle(); 1096 Object& entry = Object::Handle();
1128 DictionaryIterator entries(library); 1097 DictionaryIterator entries(library);
1129 1098
1130 AbstractType& type = AbstractType::Handle(); 1099 AbstractType& type = AbstractType::Handle();
1131 1100
1132 while (entries.HasNext()) { 1101 while (entries.HasNext()) {
1133 entry = entries.GetNext(); 1102 entry = entries.GetNext();
1134 if (entry.IsClass()) { 1103 if (entry.IsClass()) {
1135 const Class& klass = Class::Cast(entry); 1104 const Class& klass = Class::Cast(entry);
1136 // We filter out mixin application classes and dynamic. 1105 // We filter out mixin application classes and dynamic.
1137 // TODO(12478): Should not need to filter out dynamic. 1106 // TODO(12478): Should not need to filter out dynamic.
1138 // Note that the VM does not consider mixin application aliases to be 1107 // Note that the VM does not consider mixin application aliases to be
1139 // mixin applications. 1108 // mixin applications.
1140 if (!klass.IsDynamicClass() && !klass.IsMixinApplication()) { 1109 if (!klass.IsDynamicClass() && !klass.IsMixinApplication()) {
1141 type = klass.DeclarationType(); 1110 type = klass.DeclarationType();
1142 member_mirror = CreateClassMirror(klass, 1111 member_mirror = CreateClassMirror(klass, type,
1143 type,
1144 Bool::True(), // is_declaration 1112 Bool::True(), // is_declaration
1145 owner_mirror); 1113 owner_mirror);
1146 member_mirrors.Add(member_mirror); 1114 member_mirrors.Add(member_mirror);
1147 } 1115 }
1148 } else if (entry.IsField()) { 1116 } else if (entry.IsField()) {
1149 const Field& field = Field::Cast(entry); 1117 const Field& field = Field::Cast(entry);
1150 if (field.is_reflectable()) { 1118 if (field.is_reflectable()) {
1151 member_mirror = CreateVariableMirror(field, owner_mirror); 1119 member_mirror = CreateVariableMirror(field, owner_mirror);
1152 member_mirrors.Add(member_mirror); 1120 member_mirrors.Add(member_mirror);
1153 } 1121 }
1154 } else if (entry.IsFunction()) { 1122 } else if (entry.IsFunction()) {
1155 const Function& func = Function::Cast(entry); 1123 const Function& func = Function::Cast(entry);
1156 if (func.is_reflectable() && 1124 if (func.is_reflectable() &&
1157 (func.kind() == RawFunction::kRegularFunction || 1125 (func.kind() == RawFunction::kRegularFunction ||
1158 func.kind() == RawFunction::kGetterFunction || 1126 func.kind() == RawFunction::kGetterFunction ||
1159 func.kind() == RawFunction::kSetterFunction)) { 1127 func.kind() == RawFunction::kSetterFunction)) {
1160 member_mirror = CreateMethodMirror(func, owner_mirror, 1128 member_mirror =
1161 AbstractType::Handle()); 1129 CreateMethodMirror(func, owner_mirror, AbstractType::Handle());
1162 member_mirrors.Add(member_mirror); 1130 member_mirrors.Add(member_mirror);
1163 } 1131 }
1164 } 1132 }
1165 } 1133 }
1166 1134
1167 return member_mirrors.raw(); 1135 return member_mirrors.raw();
1168 } 1136 }
1169 1137
1170 1138
1171 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { 1139 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 result.SetAt(i, type_mirror); 1183 result.SetAt(i, type_mirror);
1216 } 1184 }
1217 return result.raw(); 1185 return result.raw();
1218 } 1186 }
1219 1187
1220 1188
1221 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { 1189 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) {
1222 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); 1190 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1223 const Class& owner = Class::Handle(param.parameterized_class()); 1191 const Class& owner = Class::Handle(param.parameterized_class());
1224 const AbstractType& type = AbstractType::Handle(owner.DeclarationType()); 1192 const AbstractType& type = AbstractType::Handle(owner.DeclarationType());
1225 return CreateClassMirror(owner, 1193 return CreateClassMirror(owner, type,
1226 type,
1227 Bool::True(), // is_declaration 1194 Bool::True(), // is_declaration
1228 Instance::null_instance()); 1195 Instance::null_instance());
1229 } 1196 }
1230 1197
1231 1198
1232 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { 1199 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) {
1233 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); 1200 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1234 return param.bound(); 1201 return param.bound();
1235 } 1202 }
1236 1203
(...skipping 15 matching lines...) Expand all
1252 for (int i = 0; i < num_libraries; i++) { 1219 for (int i = 0; i < num_libraries; i++) {
1253 each_library ^= libraries.At(i); 1220 each_library ^= libraries.At(i);
1254 library_key = each_library.private_key(); 1221 library_key = each_library.private_key();
1255 if (library_key.Equals(private_key)) { 1222 if (library_key.Equals(private_key)) {
1256 ctxt_library = each_library.raw(); 1223 ctxt_library = each_library.raw();
1257 break; 1224 break;
1258 } 1225 }
1259 } 1226 }
1260 } 1227 }
1261 ASSERT(!ctxt_library.IsNull()); 1228 ASSERT(!ctxt_library.IsNull());
1262 const Object& result = 1229 const Object& result = Object::Handle(ctxt_library.Evaluate(
1263 Object::Handle(ctxt_library.Evaluate(expression, 1230 expression, Array::empty_array(), Array::empty_array()));
1264 Array::empty_array(),
1265 Array::empty_array()));
1266 if (result.IsError()) { 1231 if (result.IsError()) {
1267 Exceptions::PropagateError(Error::Cast(result)); 1232 Exceptions::PropagateError(Error::Cast(result));
1268 UNREACHABLE(); 1233 UNREACHABLE();
1269 } 1234 }
1270 1235
1271 // Because we currently only use this native for building field extractors and 1236 // Because we currently only use this native for building field extractors and
1272 // setters, assume the result is a closure and mark its function as invisible, 1237 // setters, assume the result is a closure and mark its function as invisible,
1273 // so it will not appear in stack traces. Whenever we support 1238 // so it will not appear in stack traces. Whenever we support
1274 // ObjectMirror.evaluate this will need to be separated. 1239 // ObjectMirror.evaluate this will need to be separated.
1275 ASSERT(result.IsClosure()); 1240 ASSERT(result.IsClosure());
1276 const Function& func = Function::Handle(Closure::Cast(result).function()); 1241 const Function& func = Function::Handle(Closure::Cast(result).function());
1277 func.set_is_visible(false); 1242 func.set_is_visible(false);
1278 func.set_is_debuggable(false); 1243 func.set_is_debuggable(false);
1279 1244
1280 return result.raw(); 1245 return result.raw();
1281 } 1246 }
1282 1247
1283 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) { 1248 DEFINE_NATIVE_ENTRY(TypedefMirror_declaration, 1) {
1284 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 1249 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
1285 ASSERT(type.IsFunctionType()); 1250 ASSERT(type.IsFunctionType());
1286 const Class& cls = Class::Handle(type.type_class()); 1251 const Class& cls = Class::Handle(type.type_class());
1287 ASSERT(cls.IsTypedefClass()); 1252 ASSERT(cls.IsTypedefClass());
1288 return CreateTypedefMirror(cls, 1253 return CreateTypedefMirror(cls, AbstractType::Handle(cls.DeclarationType()),
1289 AbstractType::Handle(cls.DeclarationType()),
1290 Bool::True(), // is_declaration 1254 Bool::True(), // is_declaration
1291 Object::null_instance()); 1255 Object::null_instance());
1292 } 1256 }
1293 1257
1294 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 5) { 1258 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 5) {
1295 // Argument 0 is the mirror, which is unused by the native. It exists 1259 // Argument 0 is the mirror, which is unused by the native. It exists
1296 // because this native is an instance method in order to be polymorphic 1260 // because this native is an instance method in order to be polymorphic
1297 // with its cousins. 1261 // with its cousins.
1298 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 1262 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1299 GET_NON_NULL_NATIVE_ARGUMENT( 1263 GET_NON_NULL_NATIVE_ARGUMENT(String, function_name,
1300 String, function_name, arguments->NativeArgAt(2)); 1264 arguments->NativeArgAt(2));
1301 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1265 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1302 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1266 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1303 1267
1304 Class& klass = Class::Handle(reflectee.clazz()); 1268 Class& klass = Class::Handle(reflectee.clazz());
1305 Function& function = Function::Handle(zone, 1269 Function& function = Function::Handle(
1306 Resolver::ResolveDynamicAnyArgs(zone, klass, function_name)); 1270 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, function_name));
1307 1271
1308 const Array& args_descriptor = 1272 const Array& args_descriptor =
1309 Array::Handle(zone, ArgumentsDescriptor::New(args.Length(), arg_names)); 1273 Array::Handle(zone, ArgumentsDescriptor::New(args.Length(), arg_names));
1310 1274
1311 if (function.IsNull()) { 1275 if (function.IsNull()) {
1312 // Didn't find a method: try to find a getter and invoke call on its result. 1276 // Didn't find a method: try to find a getter and invoke call on its result.
1313 const String& getter_name = 1277 const String& getter_name =
1314 String::Handle(zone, Field::GetterName(function_name)); 1278 String::Handle(zone, Field::GetterName(function_name));
1315 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name); 1279 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name);
1316 if (!function.IsNull()) { 1280 if (!function.IsNull()) {
1317 ASSERT(function.kind() != RawFunction::kMethodExtractor); 1281 ASSERT(function.kind() != RawFunction::kMethodExtractor);
1318 // Invoke the getter. 1282 // Invoke the getter.
1319 const int kNumArgs = 1; 1283 const int kNumArgs = 1;
1320 const Array& getter_args = Array::Handle(zone, Array::New(kNumArgs)); 1284 const Array& getter_args = Array::Handle(zone, Array::New(kNumArgs));
1321 getter_args.SetAt(0, reflectee); 1285 getter_args.SetAt(0, reflectee);
1322 const Array& getter_args_descriptor = 1286 const Array& getter_args_descriptor =
1323 Array::Handle(zone, ArgumentsDescriptor::New(getter_args.Length())); 1287 Array::Handle(zone, ArgumentsDescriptor::New(getter_args.Length()));
1324 const Instance& getter_result = Instance::Handle(zone, 1288 const Instance& getter_result = Instance::Handle(
1325 InvokeDynamicFunction(reflectee, 1289 zone, InvokeDynamicFunction(reflectee, function, getter_name,
1326 function, 1290 getter_args, getter_args_descriptor));
1327 getter_name,
1328 getter_args,
1329 getter_args_descriptor));
1330 // Replace the closure as the receiver in the arguments list. 1291 // Replace the closure as the receiver in the arguments list.
1331 args.SetAt(0, getter_result); 1292 args.SetAt(0, getter_result);
1332 // Call the closure. 1293 // Call the closure.
1333 const Object& call_result = 1294 const Object& call_result =
1334 Object::Handle(zone, DartEntry::InvokeClosure(args, args_descriptor)); 1295 Object::Handle(zone, DartEntry::InvokeClosure(args, args_descriptor));
1335 if (call_result.IsError()) { 1296 if (call_result.IsError()) {
1336 Exceptions::PropagateError(Error::Cast(call_result)); 1297 Exceptions::PropagateError(Error::Cast(call_result));
1337 UNREACHABLE(); 1298 UNREACHABLE();
1338 } 1299 }
1339 return call_result.raw(); 1300 return call_result.raw();
1340 } 1301 }
1341 } 1302 }
1342 1303
1343 // Found an ordinary method. 1304 // Found an ordinary method.
1344 return InvokeDynamicFunction(reflectee, 1305 return InvokeDynamicFunction(reflectee, function, function_name, args,
1345 function,
1346 function_name,
1347 args,
1348 args_descriptor); 1306 args_descriptor);
1349 } 1307 }
1350 1308
1351 1309
1352 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { 1310 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) {
1353 // Argument 0 is the mirror, which is unused by the native. It exists 1311 // Argument 0 is the mirror, which is unused by the native. It exists
1354 // because this native is an instance method in order to be polymorphic 1312 // because this native is an instance method in order to be polymorphic
1355 // with its cousins. 1313 // with its cousins.
1356 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 1314 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1357 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); 1315 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
1358 Class& klass = Class::Handle(reflectee.clazz()); 1316 Class& klass = Class::Handle(reflectee.clazz());
1359 1317
1360 const String& internal_getter_name = String::Handle( 1318 const String& internal_getter_name =
1361 Field::GetterName(getter_name)); 1319 String::Handle(Field::GetterName(getter_name));
1362 Function& function = Function::Handle(zone, 1320 Function& function = Function::Handle(
1363 Resolver::ResolveDynamicAnyArgs(zone, klass, internal_getter_name)); 1321 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, internal_getter_name));
1364 1322
1365 // Check for method extraction when method extractors are not created. 1323 // Check for method extraction when method extractors are not created.
1366 if (function.IsNull() && !FLAG_lazy_dispatchers) { 1324 if (function.IsNull() && !FLAG_lazy_dispatchers) {
1367 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name); 1325 function = Resolver::ResolveDynamicAnyArgs(zone, klass, getter_name);
1368 if (!function.IsNull()) { 1326 if (!function.IsNull()) {
1369 const Function& closure_function = 1327 const Function& closure_function =
1370 Function::Handle(zone, function.ImplicitClosureFunction()); 1328 Function::Handle(zone, function.ImplicitClosureFunction());
1371 return closure_function.ImplicitInstanceClosure(reflectee); 1329 return closure_function.ImplicitInstanceClosure(reflectee);
1372 } 1330 }
1373 } 1331 }
1374 1332
1375 const int kNumArgs = 1; 1333 const int kNumArgs = 1;
1376 const Array& args = Array::Handle(zone, Array::New(kNumArgs)); 1334 const Array& args = Array::Handle(zone, Array::New(kNumArgs));
1377 args.SetAt(0, reflectee); 1335 args.SetAt(0, reflectee);
1378 const Array& args_descriptor = 1336 const Array& args_descriptor =
1379 Array::Handle(zone, ArgumentsDescriptor::New(args.Length())); 1337 Array::Handle(zone, ArgumentsDescriptor::New(args.Length()));
1380 1338
1381 // InvokeDynamic invokes NoSuchMethod if the provided function is null. 1339 // InvokeDynamic invokes NoSuchMethod if the provided function is null.
1382 return InvokeDynamicFunction(reflectee, 1340 return InvokeDynamicFunction(reflectee, function, internal_getter_name, args,
1383 function,
1384 internal_getter_name,
1385 args,
1386 args_descriptor); 1341 args_descriptor);
1387 } 1342 }
1388 1343
1389 1344
1390 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 4) { 1345 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeSetter, 4) {
1391 // Argument 0 is the mirror, which is unused by the native. It exists 1346 // Argument 0 is the mirror, which is unused by the native. It exists
1392 // because this native is an instance method in order to be polymorphic 1347 // because this native is an instance method in order to be polymorphic
1393 // with its cousins. 1348 // with its cousins.
1394 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 1349 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1395 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1350 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1396 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1351 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1397 1352
1398 const Class& klass = Class::Handle(zone, reflectee.clazz()); 1353 const Class& klass = Class::Handle(zone, reflectee.clazz());
1399 const String& internal_setter_name = 1354 const String& internal_setter_name =
1400 String::Handle(zone, Field::SetterName(setter_name)); 1355 String::Handle(zone, Field::SetterName(setter_name));
1401 const Function& setter = Function::Handle(zone, 1356 const Function& setter = Function::Handle(
1402 Resolver::ResolveDynamicAnyArgs(zone, klass, internal_setter_name)); 1357 zone, Resolver::ResolveDynamicAnyArgs(zone, klass, internal_setter_name));
1403 1358
1404 const int kNumArgs = 2; 1359 const int kNumArgs = 2;
1405 const Array& args = Array::Handle(zone, Array::New(kNumArgs)); 1360 const Array& args = Array::Handle(zone, Array::New(kNumArgs));
1406 args.SetAt(0, reflectee); 1361 args.SetAt(0, reflectee);
1407 args.SetAt(1, value); 1362 args.SetAt(1, value);
1408 const Array& args_descriptor = 1363 const Array& args_descriptor =
1409 Array::Handle(zone, ArgumentsDescriptor::New(args.Length())); 1364 Array::Handle(zone, ArgumentsDescriptor::New(args.Length()));
1410 1365
1411 return InvokeDynamicFunction(reflectee, 1366 return InvokeDynamicFunction(reflectee, setter, internal_setter_name, args,
1412 setter,
1413 internal_setter_name,
1414 args,
1415 args_descriptor); 1367 args_descriptor);
1416 } 1368 }
1417 1369
1418 1370
1419 DEFINE_NATIVE_ENTRY(InstanceMirror_computeType, 1) { 1371 DEFINE_NATIVE_ENTRY(InstanceMirror_computeType, 1) {
1420 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0)); 1372 GET_NON_NULL_NATIVE_ARGUMENT(Instance, instance, arguments->NativeArgAt(0));
1421 const AbstractType& type = AbstractType::Handle(instance.GetType()); 1373 const AbstractType& type = AbstractType::Handle(instance.GetType());
1422 // The static type of null is specified to be the bottom type, however, the 1374 // The static type of null is specified to be the bottom type, however, the
1423 // runtime type of null is the Null type, which we correctly return here. 1375 // runtime type of null is the Null type, which we correctly return here.
1424 return type.Canonicalize(); 1376 return type.Canonicalize();
(...skipping 17 matching lines...) Expand all
1442 1394
1443 Type& instantiator = Type::Handle(); 1395 Type& instantiator = Type::Handle();
1444 if (closure.IsClosure()) { 1396 if (closure.IsClosure()) {
1445 const TypeArguments& arguments = 1397 const TypeArguments& arguments =
1446 TypeArguments::Handle(closure.GetTypeArguments()); 1398 TypeArguments::Handle(closure.GetTypeArguments());
1447 const Class& cls = 1399 const Class& cls =
1448 Class::Handle(Isolate::Current()->object_store()->object_class()); 1400 Class::Handle(Isolate::Current()->object_store()->object_class());
1449 instantiator = Type::New(cls, arguments, TokenPosition::kNoSource); 1401 instantiator = Type::New(cls, arguments, TokenPosition::kNoSource);
1450 instantiator.SetIsFinalized(); 1402 instantiator.SetIsFinalized();
1451 } 1403 }
1452 return CreateMethodMirror(function, 1404 return CreateMethodMirror(function, Instance::null_instance(),
1453 Instance::null_instance(),
1454 instantiator); 1405 instantiator);
1455 } 1406 }
1456 return Instance::null(); 1407 return Instance::null();
1457 } 1408 }
1458 1409
1459 1410
1460 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) { 1411 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) {
1461 // Argument 0 is the mirror, which is unused by the native. It exists 1412 // Argument 0 is the mirror, which is unused by the native. It exists
1462 // because this native is an instance method in order to be polymorphic 1413 // because this native is an instance method in order to be polymorphic
1463 // with its cousins. 1414 // with its cousins.
1464 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1415 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1465 const Class& klass = Class::Handle(ref.GetClassReferent()); 1416 const Class& klass = Class::Handle(ref.GetClassReferent());
1466 GET_NON_NULL_NATIVE_ARGUMENT( 1417 GET_NON_NULL_NATIVE_ARGUMENT(String, function_name,
1467 String, function_name, arguments->NativeArgAt(2)); 1418 arguments->NativeArgAt(2));
1468 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1419 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1469 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1420 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1470 1421
1471 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); 1422 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread));
1472 if (!error.IsNull()) { 1423 if (!error.IsNull()) {
1473 Exceptions::PropagateError(error); 1424 Exceptions::PropagateError(error);
1474 UNREACHABLE(); 1425 UNREACHABLE();
1475 } 1426 }
1476 1427
1477 Function& function = Function::Handle( 1428 Function& function =
1478 klass.LookupStaticFunction(function_name)); 1429 Function::Handle(klass.LookupStaticFunction(function_name));
1479 1430
1480 if (function.IsNull()) { 1431 if (function.IsNull()) {
1481 // Didn't find a method: try to find a getter and invoke call on its result. 1432 // Didn't find a method: try to find a getter and invoke call on its result.
1482 const String& getter_name = 1433 const String& getter_name =
1483 String::Handle(Field::GetterName(function_name)); 1434 String::Handle(Field::GetterName(function_name));
1484 function = klass.LookupStaticFunction(getter_name); 1435 function = klass.LookupStaticFunction(getter_name);
1485 if (!function.IsNull()) { 1436 if (!function.IsNull()) {
1486 // Invoke the getter. 1437 // Invoke the getter.
1487 const Object& getter_result = Object::Handle( 1438 const Object& getter_result = Object::Handle(
1488 DartEntry::InvokeFunction(function, Object::empty_array())); 1439 DartEntry::InvokeFunction(function, Object::empty_array()));
1489 if (getter_result.IsError()) { 1440 if (getter_result.IsError()) {
1490 Exceptions::PropagateError(Error::Cast(getter_result)); 1441 Exceptions::PropagateError(Error::Cast(getter_result));
1491 UNREACHABLE(); 1442 UNREACHABLE();
1492 } 1443 }
1493 // Make room for the closure (receiver) in the argument list. 1444 // Make room for the closure (receiver) in the argument list.
1494 intptr_t numArgs = args.Length(); 1445 intptr_t numArgs = args.Length();
1495 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); 1446 const Array& call_args = Array::Handle(Array::New(numArgs + 1));
1496 Object& temp = Object::Handle(); 1447 Object& temp = Object::Handle();
1497 for (int i = 0; i < numArgs; i++) { 1448 for (int i = 0; i < numArgs; i++) {
1498 temp = args.At(i); 1449 temp = args.At(i);
1499 call_args.SetAt(i + 1, temp); 1450 call_args.SetAt(i + 1, temp);
1500 } 1451 }
1501 call_args.SetAt(0, getter_result); 1452 call_args.SetAt(0, getter_result);
1502 const Array& call_args_descriptor_array = 1453 const Array& call_args_descriptor_array = Array::Handle(
1503 Array::Handle(ArgumentsDescriptor::New(call_args.Length(), arg_names)); 1454 ArgumentsDescriptor::New(call_args.Length(), arg_names));
1504 // Call the closure. 1455 // Call the closure.
1505 const Object& call_result = Object::Handle( 1456 const Object& call_result = Object::Handle(
1506 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); 1457 DartEntry::InvokeClosure(call_args, call_args_descriptor_array));
1507 if (call_result.IsError()) { 1458 if (call_result.IsError()) {
1508 Exceptions::PropagateError(Error::Cast(call_result)); 1459 Exceptions::PropagateError(Error::Cast(call_result));
1509 UNREACHABLE(); 1460 UNREACHABLE();
1510 } 1461 }
1511 return call_result.raw(); 1462 return call_result.raw();
1512 } 1463 }
1513 } 1464 }
1514 1465
1515 const Array& args_descriptor_array = 1466 const Array& args_descriptor_array =
1516 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 1467 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1517 1468
1518 ArgumentsDescriptor args_descriptor(args_descriptor_array); 1469 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1519 1470
1520 if (function.IsNull() || 1471 if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) ||
1521 !function.AreValidArguments(args_descriptor, NULL) ||
1522 !function.is_reflectable()) { 1472 !function.is_reflectable()) {
1523 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1473 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), function_name,
1524 function_name, 1474 function, args, arg_names, InvocationMirror::kStatic,
1525 function,
1526 args,
1527 arg_names,
1528 InvocationMirror::kStatic,
1529 InvocationMirror::kMethod); 1475 InvocationMirror::kMethod);
1530 UNREACHABLE(); 1476 UNREACHABLE();
1531 } 1477 }
1532 1478
1533 Object& result = Object::Handle( 1479 Object& result = Object::Handle(
1534 DartEntry::InvokeFunction(function, args, args_descriptor_array)); 1480 DartEntry::InvokeFunction(function, args, args_descriptor_array));
1535 if (result.IsError()) { 1481 if (result.IsError()) {
1536 Exceptions::PropagateError(Error::Cast(result)); 1482 Exceptions::PropagateError(Error::Cast(result));
1537 UNREACHABLE(); 1483 UNREACHABLE();
1538 } 1484 }
(...skipping 26 matching lines...) Expand all
1565 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1511 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1566 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1512 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1567 1513
1568 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); 1514 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread));
1569 if (!error.IsNull()) { 1515 if (!error.IsNull()) {
1570 Exceptions::PropagateError(error); 1516 Exceptions::PropagateError(error);
1571 UNREACHABLE(); 1517 UNREACHABLE();
1572 } 1518 }
1573 1519
1574 // Check for real fields and user-defined setters. 1520 // Check for real fields and user-defined setters.
1575 const Field& field = 1521 const Field& field = Field::Handle(klass.LookupStaticField(setter_name));
1576 Field::Handle(klass.LookupStaticField(setter_name));
1577 Function& setter = Function::Handle(); 1522 Function& setter = Function::Handle();
1578 const String& internal_setter_name = String::Handle( 1523 const String& internal_setter_name =
1579 Field::SetterName(setter_name)); 1524 String::Handle(Field::SetterName(setter_name));
1580 1525
1581 if (field.IsNull()) { 1526 if (field.IsNull()) {
1582 setter = klass.LookupStaticFunction(internal_setter_name); 1527 setter = klass.LookupStaticFunction(internal_setter_name);
1583 1528
1584 const int kNumArgs = 1; 1529 const int kNumArgs = 1;
1585 const Array& args = Array::Handle(Array::New(kNumArgs)); 1530 const Array& args = Array::Handle(Array::New(kNumArgs));
1586 args.SetAt(0, value); 1531 args.SetAt(0, value);
1587 1532
1588 if (setter.IsNull() || !setter.is_reflectable()) { 1533 if (setter.IsNull() || !setter.is_reflectable()) {
1589 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1534 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1590 internal_setter_name, 1535 internal_setter_name, setter, args,
1591 setter, 1536 Object::null_array(), InvocationMirror::kStatic,
1592 args,
1593 Object::null_array(),
1594 InvocationMirror::kStatic,
1595 InvocationMirror::kSetter); 1537 InvocationMirror::kSetter);
1596 UNREACHABLE(); 1538 UNREACHABLE();
1597 } 1539 }
1598 1540
1599 // Invoke the setter and return the result. 1541 // Invoke the setter and return the result.
1600 Object& result = Object::Handle( 1542 Object& result = Object::Handle(DartEntry::InvokeFunction(setter, args));
1601 DartEntry::InvokeFunction(setter, args));
1602 if (result.IsError()) { 1543 if (result.IsError()) {
1603 Exceptions::PropagateError(Error::Cast(result)); 1544 Exceptions::PropagateError(Error::Cast(result));
1604 UNREACHABLE(); 1545 UNREACHABLE();
1605 } 1546 }
1606 return result.raw(); 1547 return result.raw();
1607 } 1548 }
1608 1549
1609 if (field.is_final() || !field.is_reflectable()) { 1550 if (field.is_final() || !field.is_reflectable()) {
1610 const int kNumArgs = 1; 1551 const int kNumArgs = 1;
1611 const Array& args = Array::Handle(Array::New(kNumArgs)); 1552 const Array& args = Array::Handle(Array::New(kNumArgs));
1612 args.SetAt(0, value); 1553 args.SetAt(0, value);
1613 1554
1614 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1555 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1615 internal_setter_name, 1556 internal_setter_name, setter, args, Object::null_array(),
1616 setter, 1557 InvocationMirror::kStatic, InvocationMirror::kSetter);
1617 args,
1618 Object::null_array(),
1619 InvocationMirror::kStatic,
1620 InvocationMirror::kSetter);
1621 UNREACHABLE(); 1558 UNREACHABLE();
1622 } 1559 }
1623 1560
1624 field.SetStaticValue(value); 1561 field.SetStaticValue(value);
1625 return value.raw(); 1562 return value.raw();
1626 } 1563 }
1627 1564
1628 1565
1629 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 5) { 1566 DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 5) {
1630 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1567 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1631 const Class& klass = Class::Handle(ref.GetClassReferent()); 1568 const Class& klass = Class::Handle(ref.GetClassReferent());
1632 GET_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(1)); 1569 GET_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(1));
1633 GET_NON_NULL_NATIVE_ARGUMENT( 1570 GET_NON_NULL_NATIVE_ARGUMENT(String, constructor_name,
1634 String, constructor_name, arguments->NativeArgAt(2)); 1571 arguments->NativeArgAt(2));
1635 GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(3)); 1572 GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(3));
1636 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1573 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1637 1574
1638 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread)); 1575 const Error& error = Error::Handle(zone, klass.EnsureIsFinalized(thread));
1639 if (!error.IsNull()) { 1576 if (!error.IsNull()) {
1640 Exceptions::PropagateError(error); 1577 Exceptions::PropagateError(error);
1641 UNREACHABLE(); 1578 UNREACHABLE();
1642 } 1579 }
1643 1580
1644 // By convention, the static function implementing a named constructor 'C' 1581 // By convention, the static function implementing a named constructor 'C'
1645 // for class 'A' is labeled 'A.C', and the static function implementing the 1582 // for class 'A' is labeled 'A.C', and the static function implementing the
1646 // unnamed constructor for class 'A' is labeled 'A.'. 1583 // unnamed constructor for class 'A' is labeled 'A.'.
1647 // This convention prevents users from explicitly calling constructors. 1584 // This convention prevents users from explicitly calling constructors.
1648 const String& klass_name = String::Handle(klass.Name()); 1585 const String& klass_name = String::Handle(klass.Name());
1649 String& external_constructor_name = String::Handle(klass_name.raw()); 1586 String& external_constructor_name = String::Handle(klass_name.raw());
1650 String& internal_constructor_name = 1587 String& internal_constructor_name =
1651 String::Handle(String::Concat(klass_name, Symbols::Dot())); 1588 String::Handle(String::Concat(klass_name, Symbols::Dot()));
1652 if (!constructor_name.IsNull() && constructor_name.Length() > 0) { 1589 if (!constructor_name.IsNull() && constructor_name.Length() > 0) {
1653 internal_constructor_name = 1590 internal_constructor_name =
1654 String::Concat(internal_constructor_name, constructor_name); 1591 String::Concat(internal_constructor_name, constructor_name);
1655 external_constructor_name = internal_constructor_name.raw(); 1592 external_constructor_name = internal_constructor_name.raw();
1656 } 1593 }
1657 1594
1658 Function& lookup_constructor = Function::Handle( 1595 Function& lookup_constructor =
1659 klass.LookupFunction(internal_constructor_name)); 1596 Function::Handle(klass.LookupFunction(internal_constructor_name));
1660 1597
1661 if (lookup_constructor.IsNull() || 1598 if (lookup_constructor.IsNull() ||
1662 (lookup_constructor.kind() != RawFunction::kConstructor) || 1599 (lookup_constructor.kind() != RawFunction::kConstructor) ||
1663 !lookup_constructor.is_reflectable()) { 1600 !lookup_constructor.is_reflectable()) {
1664 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1601 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1665 external_constructor_name, 1602 external_constructor_name, lookup_constructor,
1666 lookup_constructor, 1603 explicit_args, arg_names, InvocationMirror::kConstructor,
1667 explicit_args,
1668 arg_names,
1669 InvocationMirror::kConstructor,
1670 InvocationMirror::kMethod); 1604 InvocationMirror::kMethod);
1671 UNREACHABLE(); 1605 UNREACHABLE();
1672 } 1606 }
1673 1607
1674 if (klass.is_abstract() && !lookup_constructor.IsFactory()) { 1608 if (klass.is_abstract() && !lookup_constructor.IsFactory()) {
1675 const Array& error_args = Array::Handle(Array::New(3)); 1609 const Array& error_args = Array::Handle(Array::New(3));
1676 error_args.SetAt(0, klass_name); 1610 error_args.SetAt(0, klass_name);
1677 // 1 = script url 1611 // 1 = script url
1678 // 2 = token position 1612 // 2 = token position
1679 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, 1613 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 Array::Handle(Array::New(num_implicit_args + num_explicit_args)); 1657 Array::Handle(Array::New(num_implicit_args + num_explicit_args));
1724 1658
1725 // Copy over the explicit arguments. 1659 // Copy over the explicit arguments.
1726 Object& explicit_argument = Object::Handle(); 1660 Object& explicit_argument = Object::Handle();
1727 for (int i = 0; i < num_explicit_args; i++) { 1661 for (int i = 0; i < num_explicit_args; i++) {
1728 explicit_argument = explicit_args.At(i); 1662 explicit_argument = explicit_args.At(i);
1729 args.SetAt(i + num_implicit_args, explicit_argument); 1663 args.SetAt(i + num_implicit_args, explicit_argument);
1730 } 1664 }
1731 1665
1732 const Array& args_descriptor_array = 1666 const Array& args_descriptor_array =
1733 Array::Handle(ArgumentsDescriptor::New(args.Length(), 1667 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1734 arg_names));
1735 1668
1736 ArgumentsDescriptor args_descriptor(args_descriptor_array); 1669 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1737 if (!redirected_constructor.AreValidArguments(args_descriptor, NULL) || 1670 if (!redirected_constructor.AreValidArguments(args_descriptor, NULL) ||
1738 !redirected_constructor.is_reflectable()) { 1671 !redirected_constructor.is_reflectable()) {
1739 external_constructor_name = redirected_constructor.name(); 1672 external_constructor_name = redirected_constructor.name();
1740 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1673 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1741 external_constructor_name, 1674 external_constructor_name, redirected_constructor,
1742 redirected_constructor, 1675 explicit_args, arg_names, InvocationMirror::kConstructor,
1743 explicit_args,
1744 arg_names,
1745 InvocationMirror::kConstructor,
1746 InvocationMirror::kMethod); 1676 InvocationMirror::kMethod);
1747 UNREACHABLE(); 1677 UNREACHABLE();
1748 } 1678 }
1749 1679
1750 Instance& new_object = Instance::Handle(); 1680 Instance& new_object = Instance::Handle();
1751 if (redirected_constructor.IsGenerativeConstructor()) { 1681 if (redirected_constructor.IsGenerativeConstructor()) {
1752 // Constructors get the uninitialized object. 1682 // Constructors get the uninitialized object.
1753 // Note we have delayed allocation until after the function 1683 // Note we have delayed allocation until after the function
1754 // type and argument matching checks. 1684 // type and argument matching checks.
1755 new_object = Instance::New(redirected_klass); 1685 new_object = Instance::New(redirected_klass);
1756 if (!type_arguments.IsNull()) { 1686 if (!type_arguments.IsNull()) {
1757 // The type arguments will be null if the class has no type parameters, in 1687 // The type arguments will be null if the class has no type parameters, in
1758 // which case the following call would fail because there is no slot 1688 // which case the following call would fail because there is no slot
1759 // reserved in the object for the type vector. 1689 // reserved in the object for the type vector.
1760 new_object.SetTypeArguments(type_arguments); 1690 new_object.SetTypeArguments(type_arguments);
1761 } 1691 }
1762 args.SetAt(0, new_object); 1692 args.SetAt(0, new_object);
1763 } else { 1693 } else {
1764 // Factories get type arguments. 1694 // Factories get type arguments.
1765 args.SetAt(0, type_arguments); 1695 args.SetAt(0, type_arguments);
1766 } 1696 }
1767 1697
1768 // Invoke the constructor and return the new object. 1698 // Invoke the constructor and return the new object.
1769 const Object& result = 1699 const Object& result = Object::Handle(DartEntry::InvokeFunction(
1770 Object::Handle(DartEntry::InvokeFunction(redirected_constructor, 1700 redirected_constructor, args, args_descriptor_array));
1771 args,
1772 args_descriptor_array));
1773 if (result.IsError()) { 1701 if (result.IsError()) {
1774 Exceptions::PropagateError(Error::Cast(result)); 1702 Exceptions::PropagateError(Error::Cast(result));
1775 UNREACHABLE(); 1703 UNREACHABLE();
1776 } 1704 }
1777 1705
1778 // Factories may return null. 1706 // Factories may return null.
1779 ASSERT(result.IsInstance() || result.IsNull()); 1707 ASSERT(result.IsInstance() || result.IsNull());
1780 1708
1781 if (redirected_constructor.IsGenerativeConstructor()) { 1709 if (redirected_constructor.IsGenerativeConstructor()) {
1782 return new_object.raw(); 1710 return new_object.raw();
1783 } else { 1711 } else {
1784 return result.raw(); 1712 return result.raw();
1785 } 1713 }
1786 } 1714 }
1787 1715
1788 1716
1789 DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 5) { 1717 DEFINE_NATIVE_ENTRY(LibraryMirror_invoke, 5) {
1790 // Argument 0 is the mirror, which is unused by the native. It exists 1718 // Argument 0 is the mirror, which is unused by the native. It exists
1791 // because this native is an instance method in order to be polymorphic 1719 // because this native is an instance method in order to be polymorphic
1792 // with its cousins. 1720 // with its cousins.
1793 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1721 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1794 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1722 const Library& library = Library::Handle(ref.GetLibraryReferent());
1795 GET_NON_NULL_NATIVE_ARGUMENT( 1723 GET_NON_NULL_NATIVE_ARGUMENT(String, function_name,
1796 String, function_name, arguments->NativeArgAt(2)); 1724 arguments->NativeArgAt(2));
1797 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1725 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1798 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1726 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1799 1727
1800 Function& function = Function::Handle( 1728 Function& function =
1801 library.LookupLocalFunction(function_name)); 1729 Function::Handle(library.LookupLocalFunction(function_name));
1802 1730
1803 if (function.IsNull()) { 1731 if (function.IsNull()) {
1804 // Didn't find a method: try to find a getter and invoke call on its result. 1732 // Didn't find a method: try to find a getter and invoke call on its result.
1805 const Instance& getter_result = 1733 const Instance& getter_result =
1806 Instance::Handle(InvokeLibraryGetter(library, function_name, false)); 1734 Instance::Handle(InvokeLibraryGetter(library, function_name, false));
1807 if (getter_result.raw() != Object::sentinel().raw()) { 1735 if (getter_result.raw() != Object::sentinel().raw()) {
1808 // Make room for the closure (receiver) in arguments. 1736 // Make room for the closure (receiver) in arguments.
1809 intptr_t numArgs = args.Length(); 1737 intptr_t numArgs = args.Length();
1810 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); 1738 const Array& call_args = Array::Handle(Array::New(numArgs + 1));
1811 Object& temp = Object::Handle(); 1739 Object& temp = Object::Handle();
(...skipping 12 matching lines...) Expand all
1824 UNREACHABLE(); 1752 UNREACHABLE();
1825 } 1753 }
1826 return call_result.raw(); 1754 return call_result.raw();
1827 } 1755 }
1828 } 1756 }
1829 1757
1830 const Array& args_descriptor_array = 1758 const Array& args_descriptor_array =
1831 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 1759 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1832 ArgumentsDescriptor args_descriptor(args_descriptor_array); 1760 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1833 1761
1834 if (function.IsNull() || 1762 if (function.IsNull() || !function.AreValidArguments(args_descriptor, NULL) ||
1835 !function.AreValidArguments(args_descriptor, NULL) ||
1836 !function.is_reflectable()) { 1763 !function.is_reflectable()) {
1837 ThrowNoSuchMethod(Instance::null_instance(), 1764 ThrowNoSuchMethod(Instance::null_instance(), function_name, function, args,
1838 function_name, 1765 arg_names, InvocationMirror::kTopLevel,
1839 function,
1840 args,
1841 arg_names,
1842 InvocationMirror::kTopLevel,
1843 InvocationMirror::kMethod); 1766 InvocationMirror::kMethod);
1844 UNREACHABLE(); 1767 UNREACHABLE();
1845 } 1768 }
1846 1769
1847 const Object& result = Object::Handle( 1770 const Object& result = Object::Handle(
1848 DartEntry::InvokeFunction(function, args, args_descriptor_array)); 1771 DartEntry::InvokeFunction(function, args, args_descriptor_array));
1849 if (result.IsError()) { 1772 if (result.IsError()) {
1850 Exceptions::PropagateError(Error::Cast(result)); 1773 Exceptions::PropagateError(Error::Cast(result));
1851 UNREACHABLE(); 1774 UNREACHABLE();
1852 } 1775 }
(...skipping 17 matching lines...) Expand all
1870 // because this native is an instance method in order to be polymorphic 1793 // because this native is an instance method in order to be polymorphic
1871 // with its cousins. 1794 // with its cousins.
1872 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1795 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1873 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1796 const Library& library = Library::Handle(ref.GetLibraryReferent());
1874 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1797 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1875 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1798 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1876 1799
1877 // To access a top-level we may need to use the Field or the 1800 // To access a top-level we may need to use the Field or the
1878 // setter Function. The setter function may either be in the 1801 // setter Function. The setter function may either be in the
1879 // library or in the field's owner class, depending. 1802 // library or in the field's owner class, depending.
1880 const Field& field = Field::Handle( 1803 const Field& field = Field::Handle(library.LookupLocalField(setter_name));
1881 library.LookupLocalField(setter_name));
1882 Function& setter = Function::Handle(); 1804 Function& setter = Function::Handle();
1883 const String& internal_setter_name = 1805 const String& internal_setter_name =
1884 String::Handle(Field::SetterName(setter_name)); 1806 String::Handle(Field::SetterName(setter_name));
1885 1807
1886 if (field.IsNull()) { 1808 if (field.IsNull()) {
1887 setter = library.LookupLocalFunction(internal_setter_name); 1809 setter = library.LookupLocalFunction(internal_setter_name);
1888 1810
1889 const int kNumArgs = 1; 1811 const int kNumArgs = 1;
1890 const Array& args = Array::Handle(Array::New(kNumArgs)); 1812 const Array& args = Array::Handle(Array::New(kNumArgs));
1891 args.SetAt(0, value); 1813 args.SetAt(0, value);
1892 1814
1893 if (setter.IsNull() || !setter.is_reflectable()) { 1815 if (setter.IsNull() || !setter.is_reflectable()) {
1894 ThrowNoSuchMethod(Instance::null_instance(), 1816 ThrowNoSuchMethod(Instance::null_instance(), internal_setter_name, setter,
1895 internal_setter_name, 1817 args, Object::null_array(), InvocationMirror::kTopLevel,
1896 setter,
1897 args,
1898 Object::null_array(),
1899 InvocationMirror::kTopLevel,
1900 InvocationMirror::kSetter); 1818 InvocationMirror::kSetter);
1901 UNREACHABLE(); 1819 UNREACHABLE();
1902 } 1820 }
1903 1821
1904 // Invoke the setter and return the result. 1822 // Invoke the setter and return the result.
1905 const Object& result = Object::Handle( 1823 const Object& result =
1906 DartEntry::InvokeFunction(setter, args)); 1824 Object::Handle(DartEntry::InvokeFunction(setter, args));
1907 if (result.IsError()) { 1825 if (result.IsError()) {
1908 Exceptions::PropagateError(Error::Cast(result)); 1826 Exceptions::PropagateError(Error::Cast(result));
1909 UNREACHABLE(); 1827 UNREACHABLE();
1910 } 1828 }
1911 return result.raw(); 1829 return result.raw();
1912 } 1830 }
1913 1831
1914 if (field.is_final() || !field.is_reflectable()) { 1832 if (field.is_final() || !field.is_reflectable()) {
1915 const int kNumArgs = 1; 1833 const int kNumArgs = 1;
1916 const Array& args = Array::Handle(Array::New(kNumArgs)); 1834 const Array& args = Array::Handle(Array::New(kNumArgs));
1917 args.SetAt(0, value); 1835 args.SetAt(0, value);
1918 1836
1919 ThrowNoSuchMethod(Instance::null_instance(), 1837 ThrowNoSuchMethod(Instance::null_instance(), internal_setter_name, setter,
1920 internal_setter_name, 1838 args, Object::null_array(), InvocationMirror::kTopLevel,
1921 setter,
1922 args,
1923 Object::null_array(),
1924 InvocationMirror::kTopLevel,
1925 InvocationMirror::kSetter); 1839 InvocationMirror::kSetter);
1926 UNREACHABLE(); 1840 UNREACHABLE();
1927 } 1841 }
1928 1842
1929 field.SetStaticValue(value); 1843 field.SetStaticValue(value);
1930 return value.raw(); 1844 return value.raw();
1931 } 1845 }
1932 1846
1933 1847
1934 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 2) { 1848 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 2) {
1935 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1849 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1936 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); 1850 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1937 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1851 const Function& func = Function::Handle(ref.GetFunctionReferent());
1938 if (func.IsNonImplicitClosureFunction()) { 1852 if (func.IsNonImplicitClosureFunction()) {
1939 return CreateMethodMirror(Function::Handle( 1853 return CreateMethodMirror(Function::Handle(func.parent_function()),
1940 func.parent_function()), Object::null_instance(), instantiator); 1854 Object::null_instance(), instantiator);
1941 } 1855 }
1942 const Class& owner = Class::Handle(func.Owner()); 1856 const Class& owner = Class::Handle(func.Owner());
1943 if (owner.IsTopLevel()) { 1857 if (owner.IsTopLevel()) {
1944 return CreateLibraryMirror(thread, Library::Handle(owner.library())); 1858 return CreateLibraryMirror(thread, Library::Handle(owner.library()));
1945 } 1859 }
1946 1860
1947 AbstractType& type = AbstractType::Handle(owner.DeclarationType()); 1861 AbstractType& type = AbstractType::Handle(owner.DeclarationType());
1948 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance()); 1862 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance());
1949 } 1863 }
1950 1864
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 const Function& func = Function::Cast(decl); 1919 const Function& func = Function::Cast(decl);
2006 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { 1920 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) {
2007 // These are synthetic methods; they have no source. 1921 // These are synthetic methods; they have no source.
2008 return Instance::null(); 1922 return Instance::null();
2009 } 1923 }
2010 script = func.script(); 1924 script = func.script();
2011 token_pos = func.token_pos(); 1925 token_pos = func.token_pos();
2012 } else if (decl.IsClass()) { 1926 } else if (decl.IsClass()) {
2013 const Class& cls = Class::Cast(decl); 1927 const Class& cls = Class::Cast(decl);
2014 const bool is_typedef = cls.IsTypedefClass(); 1928 const bool is_typedef = cls.IsTypedefClass();
2015 if (cls.is_synthesized_class() && 1929 if (cls.is_synthesized_class() && !is_typedef &&
2016 !is_typedef && 1930 !cls.is_mixin_app_alias() && !cls.is_enum_class()) {
2017 !cls.is_mixin_app_alias() &&
2018 !cls.is_enum_class()) {
2019 return Instance::null(); // Synthetic. 1931 return Instance::null(); // Synthetic.
2020 } 1932 }
2021 script = cls.script(); 1933 script = cls.script();
2022 token_pos = cls.token_pos(); 1934 token_pos = cls.token_pos();
2023 } else if (decl.IsField()) { 1935 } else if (decl.IsField()) {
2024 const Field& field = Field::Cast(decl); 1936 const Field& field = Field::Cast(decl);
2025 script = field.Script(); 1937 script = field.Script();
2026 token_pos = field.token_pos(); 1938 token_pos = field.token_pos();
2027 } else if (decl.IsTypeParameter()) { 1939 } else if (decl.IsTypeParameter()) {
2028 const TypeParameter& type_var = TypeParameter::Cast(decl); 1940 const TypeParameter& type_var = TypeParameter::Cast(decl);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 2017
2106 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { 2018 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) {
2107 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2019 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2108 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2020 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2109 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); 2021 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw();
2110 } 2022 }
2111 2023
2112 #endif // !PRODUCT 2024 #endif // !PRODUCT
2113 2025
2114 } // namespace dart 2026 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.h ('k') | runtime/lib/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698