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

Side by Side Diff: vm/dart_api_impl.cc

Issue 10433003: Make Dart_GetClass work for private classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 7 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 | « include/dart_api.h ('k') | vm/dart_api_impl_test.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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 } 2604 }
2605 2605
2606 // Invoke the getter and return the result. 2606 // Invoke the getter and return the result.
2607 GrowableArray<const Object*> args; 2607 GrowableArray<const Object*> args;
2608 const Array& kNoArgNames = Array::Handle(isolate); 2608 const Array& kNoArgNames = Array::Handle(isolate);
2609 return Api::NewHandle( 2609 return Api::NewHandle(
2610 isolate, 2610 isolate,
2611 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames)); 2611 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames));
2612 2612
2613 } else if (obj.IsClass()) { 2613 } else if (obj.IsClass()) {
2614 // Finalize all classes.
2615 const char* msg = CheckIsolateState(isolate);
2616 if (msg != NULL) {
2617 return Api::NewError(msg);
2618 }
2614 // To access a static field we may need to use the Field or the 2619 // To access a static field we may need to use the Field or the
2615 // getter Function. 2620 // getter Function.
2616 Class& cls = Class::Handle(isolate); 2621 Class& cls = Class::Handle(isolate);
2617 cls ^= obj.raw(); 2622 cls ^= obj.raw();
2618 field = cls.LookupStaticField(field_name); 2623 field = cls.LookupStaticField(field_name);
2619 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { 2624 if (field.IsNull() || FieldIsUninitialized(isolate, field)) {
2620 const String& getter_name = 2625 const String& getter_name =
2621 String::Handle(isolate, Field::GetterName(field_name)); 2626 String::Handle(isolate, Field::GetterName(field_name));
2622 getter = cls.LookupStaticFunction(getter_name); 2627 getter = cls.LookupStaticFunction(getter_name);
2623 } 2628 }
2624 2629
2625 if (!getter.IsNull()) { 2630 if (!getter.IsNull()) {
2626 // Invoke the getter and return the result. 2631 // Invoke the getter and return the result.
2627 GrowableArray<const Object*> args; 2632 GrowableArray<const Object*> args;
2628 const Array& kNoArgNames = Array::Handle(isolate); 2633 const Array& kNoArgNames = Array::Handle(isolate);
2629 return Api::NewHandle( 2634 return Api::NewHandle(
2630 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); 2635 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames));
2631 } else if (!field.IsNull()) { 2636 } else if (!field.IsNull()) {
2632 return Api::NewHandle(isolate, field.value()); 2637 return Api::NewHandle(isolate, field.value());
2633 } else { 2638 } else {
2634 return Api::NewError("%s: did not find static field '%s'.", 2639 return Api::NewError("%s: did not find static field '%s'.",
2635 CURRENT_FUNC, field_name.ToCString()); 2640 CURRENT_FUNC, field_name.ToCString());
2636 } 2641 }
2637 2642
2638 } else if (obj.IsLibrary()) { 2643 } else if (obj.IsLibrary()) {
2644 // TODO(turnidge): Do we need to call CheckIsolateState here?
2645
2639 // To access a top-level we may need to use the Field or the 2646 // To access a top-level we may need to use the Field or the
2640 // getter Function. The getter function may either be in the 2647 // getter Function. The getter function may either be in the
2641 // library or in the field's owner class, depending. 2648 // library or in the field's owner class, depending.
2642 Library& lib = Library::Handle(isolate); 2649 Library& lib = Library::Handle(isolate);
2643 lib ^= obj.raw(); 2650 lib ^= obj.raw();
2644 field = lib.LookupFieldAllowPrivate(field_name); 2651 field = lib.LookupFieldAllowPrivate(field_name);
2645 if (field.IsNull()) { 2652 if (field.IsNull()) {
2646 // No field found. Check for a getter in the lib. 2653 // No field found. Check for a getter in the lib.
2647 const String& getter_name = 2654 const String& getter_name =
2648 String::Handle(isolate, Field::GetterName(field_name)); 2655 String::Handle(isolate, Field::GetterName(field_name));
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3117 CompileAll(isolate, &result); 3124 CompileAll(isolate, &result);
3118 return result; 3125 return result;
3119 } 3126 }
3120 3127
3121 3128
3122 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { 3129 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) {
3123 return Api::ClassIndex(object) == kLibrary; 3130 return Api::ClassIndex(object) == kLibrary;
3124 } 3131 }
3125 3132
3126 3133
3127 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { 3134 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library,
3135 Dart_Handle class_name) {
3128 Isolate* isolate = Isolate::Current(); 3136 Isolate* isolate = Isolate::Current();
3129 DARTSCOPE(isolate); 3137 DARTSCOPE(isolate);
3130 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); 3138 const Library& lib = Api::UnwrapLibraryHandle(isolate, library);
3131 if (param.IsNull() || !param.IsString()) { 3139 if (lib.IsNull()) {
3132 return Api::NewError("Invalid class name specified"); 3140 RETURN_TYPE_ERROR(isolate, library, Library);
3133 } 3141 }
3134 const Library& lib = 3142 const String& cls_name = Api::UnwrapStringHandle(isolate, class_name);
3135 Library::CheckedHandle(isolate, Api::UnwrapHandle(library)); 3143 if (cls_name.IsNull()) {
3136 if (lib.IsNull()) { 3144 RETURN_TYPE_ERROR(isolate, class_name, String);
3137 return Api::NewError("Invalid parameter, Unknown library specified");
3138 } 3145 }
3139 String& cls_name = String::Handle(isolate); 3146 const Class& cls =
3140 cls_name ^= param.raw(); 3147 Class::Handle(isolate, lib.LookupClassAllowPrivate(cls_name));
3141 const Class& cls = Class::Handle(isolate, lib.LookupClass(cls_name));
3142 if (cls.IsNull()) { 3148 if (cls.IsNull()) {
3149 // TODO(turnidge): Return null or error in this case?
3143 const String& lib_name = String::Handle(isolate, lib.name()); 3150 const String& lib_name = String::Handle(isolate, lib.name());
3144 return Api::NewError("Class '%s' not found in library '%s'.", 3151 return Api::NewError("Class '%s' not found in library '%s'.",
3145 cls_name.ToCString(), lib_name.ToCString()); 3152 cls_name.ToCString(), lib_name.ToCString());
3146 } 3153 }
3147 return Api::NewHandle(isolate, cls.raw()); 3154 return Api::NewHandle(isolate, cls.raw());
3148 } 3155 }
3149 3156
3150 3157
3151 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { 3158 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
3152 Isolate* isolate = Isolate::Current(); 3159 Isolate* isolate = Isolate::Current();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 *buffer = NULL; 3313 *buffer = NULL;
3307 } 3314 }
3308 delete debug_region; 3315 delete debug_region;
3309 } else { 3316 } else {
3310 *buffer = NULL; 3317 *buffer = NULL;
3311 *buffer_size = 0; 3318 *buffer_size = 0;
3312 } 3319 }
3313 } 3320 }
3314 3321
3315 } // namespace dart 3322 } // namespace dart
OLDNEW
« no previous file with comments | « include/dart_api.h ('k') | vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698