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

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

Issue 22633005: Make reflectClass(dynamic) throw an illegal argument exception. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/mirrors/mirrors.dart » ('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/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return call_function.raw(); 180 return call_function.raw();
181 } 181 }
182 lookup_cls = lookup_cls.SuperClass(); 182 lookup_cls = lookup_cls.SuperClass();
183 } while (!lookup_cls.IsNull()); 183 } while (!lookup_cls.IsNull());
184 return Function::null(); 184 return Function::null();
185 } 185 }
186 186
187 static RawInstance* CreateClassMirror(const Class& cls, 187 static RawInstance* CreateClassMirror(const Class& cls,
188 const AbstractType& type, 188 const AbstractType& type,
189 const Instance& owner_mirror) { 189 const Instance& owner_mirror) {
190 ASSERT(!cls.IsDynamicClass() && !cls.IsVoidClass());
191
190 if (cls.IsSignatureClass()) { 192 if (cls.IsSignatureClass()) {
191 if (cls.IsCanonicalSignatureClass()) { 193 if (cls.IsCanonicalSignatureClass()) {
192 // We represent function types as canonical signature classes. 194 // We represent function types as canonical signature classes.
193 return CreateFunctionTypeMirror(cls, type); 195 return CreateFunctionTypeMirror(cls, type);
194 } else { 196 } else {
195 // We represent typedefs as non-canonical signature classes. 197 // We represent typedefs as non-canonical signature classes.
196 return CreateTypedefMirror(cls, owner_mirror); 198 return CreateTypedefMirror(cls, owner_mirror);
197 } 199 }
198 } 200 }
199 201
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 300
299 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { 301 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) {
300 return CreateMirrorSystem(); 302 return CreateMirrorSystem();
301 } 303 }
302 304
303 305
304 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { 306 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) {
305 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 307 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
306 const Class& cls = Class::Handle(type.type_class()); 308 const Class& cls = Class::Handle(type.type_class());
307 ASSERT(!cls.IsNull()); 309 ASSERT(!cls.IsNull());
310 if (cls.IsDynamicClass() || cls.IsVoidClass()) {
311 const Array& args = Array::Handle(Array::New(1));
312 args.SetAt(0, type);
313 Exceptions::ThrowByType(Exceptions::kArgument, args);
314 UNREACHABLE();
315 }
308 // Strip the type for generics only. 316 // Strip the type for generics only.
309 if (cls.NumTypeParameters() == 0) { 317 if (cls.NumTypeParameters() == 0) {
310 return CreateClassMirror(cls, 318 return CreateClassMirror(cls,
311 type, 319 type,
312 Object::null_instance()); 320 Object::null_instance());
313 } else { 321 } else {
314 return CreateClassMirror(cls, 322 return CreateClassMirror(cls,
315 AbstractType::Handle(), 323 AbstractType::Handle(),
316 Object::null_instance()); 324 Object::null_instance());
317 } 325 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 const GrowableObjectArray& member_mirrors = 562 const GrowableObjectArray& member_mirrors =
555 GrowableObjectArray::Handle(GrowableObjectArray::New()); 563 GrowableObjectArray::Handle(GrowableObjectArray::New());
556 564
557 Object& entry = Object::Handle(); 565 Object& entry = Object::Handle();
558 DictionaryIterator entries(library); 566 DictionaryIterator entries(library);
559 567
560 while (entries.HasNext()) { 568 while (entries.HasNext()) {
561 entry = entries.GetNext(); 569 entry = entries.GetNext();
562 if (entry.IsClass()) { 570 if (entry.IsClass()) {
563 const Class& klass = Class::Cast(entry); 571 const Class& klass = Class::Cast(entry);
564 if (!klass.IsCanonicalSignatureClass()) { 572 // We filter out implementation classes like Smi, Mint, Bignum,
565 // The various implementations of public classes don't always have the 573 // OneByteString; function signature classes; and dynamic.
566 // expected superinterfaces or other properties, so we filter them out. 574 if (!klass.IsCanonicalSignatureClass() &&
567 if (!RawObject::IsImplementationClassId(klass.id())) { 575 !klass.IsDynamicClass() &&
568 member_mirror = CreateClassMirror(klass, 576 !RawObject::IsImplementationClassId(klass.id())) {
569 AbstractType::Handle(), 577 member_mirror = CreateClassMirror(klass,
570 owner_mirror); 578 AbstractType::Handle(),
571 member_mirrors.Add(member_mirror); 579 owner_mirror);
572 } 580 member_mirrors.Add(member_mirror);
573 } 581 }
574 } else if (entry.IsField()) { 582 } else if (entry.IsField()) {
575 const Field& field = Field::Cast(entry); 583 const Field& field = Field::Cast(entry);
576 member_mirror = CreateVariableMirror(field, owner_mirror); 584 member_mirror = CreateVariableMirror(field, owner_mirror);
577 member_mirrors.Add(member_mirror); 585 member_mirrors.Add(member_mirror);
578 } else if (entry.IsFunction()) { 586 } else if (entry.IsFunction()) {
579 const Function& func = Function::Cast(entry); 587 const Function& func = Function::Cast(entry);
580 if (func.kind() == RawFunction::kRegularFunction || 588 if (func.kind() == RawFunction::kRegularFunction ||
581 func.kind() == RawFunction::kGetterFunction || 589 func.kind() == RawFunction::kGetterFunction ||
582 func.kind() == RawFunction::kSetterFunction) { 590 func.kind() == RawFunction::kSetterFunction) {
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 } 1309 }
1302 1310
1303 1311
1304 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1312 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1305 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1313 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1306 const Field& field = Field::Handle(ref.GetFieldReferent()); 1314 const Field& field = Field::Handle(ref.GetFieldReferent());
1307 return field.type(); 1315 return field.type();
1308 } 1316 }
1309 1317
1310 } // namespace dart 1318 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/mirrors/mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698