| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_mirrors_api.h" | 5 #include "include/dart_mirrors_api.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // Case 4. Lookup the function with a . appended to find the | 335 // Case 4. Lookup the function with a . appended to find the |
| 336 // unnamed constructor. | 336 // unnamed constructor. |
| 337 if (func.IsNull()) { | 337 if (func.IsNull()) { |
| 338 tmp_name = String::Concat(func_name, Symbols::Dot()); | 338 tmp_name = String::Concat(func_name, Symbols::Dot()); |
| 339 func = cls.LookupFunctionAllowPrivate(tmp_name); | 339 func = cls.LookupFunctionAllowPrivate(tmp_name); |
| 340 } | 340 } |
| 341 } else if (obj.IsLibrary()) { | 341 } else if (obj.IsLibrary()) { |
| 342 const Library& lib = Library::Cast(obj); | 342 const Library& lib = Library::Cast(obj); |
| 343 | 343 |
| 344 // Case 1. Lookup the unmodified function name. | 344 // Case 1. Lookup the unmodified function name. |
| 345 func = lib.LookupFunctionAllowPrivate(func_name); | 345 String& ambiguity_error_msg = String::Handle(isolate); |
| 346 func = lib.LookupFunctionAllowPrivate(func_name, &ambiguity_error_msg); |
| 346 | 347 |
| 347 // Case 2. Lookup the function without the external setter suffix | 348 // Case 2. Lookup the function without the external setter suffix |
| 348 // '='. Make sure to do this check after the regular lookup, so | 349 // '='. Make sure to do this check after the regular lookup, so |
| 349 // that we don't interfere with operator lookups (like ==). | 350 // that we don't interfere with operator lookups (like ==). |
| 350 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { | 351 if (func.IsNull() && ambiguity_error_msg.IsNull() && |
| 352 HasExternalSetterSuffix(func_name)) { |
| 351 tmp_name = RemoveExternalSetterSuffix(func_name); | 353 tmp_name = RemoveExternalSetterSuffix(func_name); |
| 352 tmp_name = Field::SetterName(tmp_name); | 354 tmp_name = Field::SetterName(tmp_name); |
| 353 func = lib.LookupFunctionAllowPrivate(tmp_name); | 355 func = lib.LookupFunctionAllowPrivate(tmp_name, &ambiguity_error_msg); |
| 354 } | 356 } |
| 355 | 357 |
| 356 // Case 3. Lookup the function with the getter prefix prepended. | 358 // Case 3. Lookup the function with the getter prefix prepended. |
| 357 if (func.IsNull()) { | 359 if (func.IsNull() && ambiguity_error_msg.IsNull()) { |
| 358 tmp_name = Field::GetterName(func_name); | 360 tmp_name = Field::GetterName(func_name); |
| 359 func = lib.LookupFunctionAllowPrivate(tmp_name); | 361 func = lib.LookupFunctionAllowPrivate(tmp_name, &ambiguity_error_msg); |
| 362 } |
| 363 if (!ambiguity_error_msg.IsNull()) { |
| 364 return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| 360 } | 365 } |
| 361 } else { | 366 } else { |
| 362 return Api::NewError( | 367 return Api::NewError( |
| 363 "%s expects argument 'target' to be a class or library.", | 368 "%s expects argument 'target' to be a class or library.", |
| 364 CURRENT_FUNC); | 369 CURRENT_FUNC); |
| 365 } | 370 } |
| 366 | 371 |
| 367 #if defined(DEBUG) | 372 #if defined(DEBUG) |
| 368 if (!func.IsNull()) { | 373 if (!func.IsNull()) { |
| 369 // We only provide access to a subset of function kinds. | 374 // We only provide access to a subset of function kinds. |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 if (obj.IsType() || obj.IsClass()) { | 662 if (obj.IsType() || obj.IsClass()) { |
| 658 // For backwards compatibility we allow class objects to be passed in | 663 // For backwards compatibility we allow class objects to be passed in |
| 659 // for now. This needs to be removed once all code that uses class | 664 // for now. This needs to be removed once all code that uses class |
| 660 // objects to invoke Dart_Invoke is removed. | 665 // objects to invoke Dart_Invoke is removed. |
| 661 const Class& cls = (obj.IsType()) ? | 666 const Class& cls = (obj.IsType()) ? |
| 662 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); | 667 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); |
| 663 return Api::NewHandle(isolate, cls.LookupField(var_name)); | 668 return Api::NewHandle(isolate, cls.LookupField(var_name)); |
| 664 } | 669 } |
| 665 if (obj.IsLibrary()) { | 670 if (obj.IsLibrary()) { |
| 666 const Library& lib = Library::Cast(obj); | 671 const Library& lib = Library::Cast(obj); |
| 667 return Api::NewHandle(isolate, lib.LookupFieldAllowPrivate(var_name)); | 672 String& ambiguity_error_msg = String::Handle(isolate); |
| 673 const Field& variable = Field::Handle( |
| 674 lib.LookupFieldAllowPrivate(var_name, &ambiguity_error_msg)); |
| 675 if (!ambiguity_error_msg.IsNull()) { |
| 676 return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| 677 } |
| 678 return Api::NewHandle(isolate, variable.raw()); |
| 668 } | 679 } |
| 669 return Api::NewError( | 680 return Api::NewError( |
| 670 "%s expects argument 'target' to be a class or library.", | 681 "%s expects argument 'target' to be a class or library.", |
| 671 CURRENT_FUNC); | 682 CURRENT_FUNC); |
| 672 } | 683 } |
| 673 | 684 |
| 674 | 685 |
| 675 DART_EXPORT Dart_Handle Dart_VariableName(Dart_Handle variable) { | 686 DART_EXPORT Dart_Handle Dart_VariableName(Dart_Handle variable) { |
| 676 Isolate* isolate = Isolate::Current(); | 687 Isolate* isolate = Isolate::Current(); |
| 677 DARTSCOPE(isolate); | 688 DARTSCOPE(isolate); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 } else if (obj.IsField()) { | 928 } else if (obj.IsField()) { |
| 918 cls = Field::Cast(obj).origin(); | 929 cls = Field::Cast(obj).origin(); |
| 919 } else { | 930 } else { |
| 920 return Api::NewHandle(isolate, Object::empty_array().raw()); | 931 return Api::NewHandle(isolate, Object::empty_array().raw()); |
| 921 } | 932 } |
| 922 const Library& lib = Library::Handle(cls.library()); | 933 const Library& lib = Library::Handle(cls.library()); |
| 923 return Api::NewHandle(isolate, lib.GetMetadata(obj)); | 934 return Api::NewHandle(isolate, lib.GetMetadata(obj)); |
| 924 } | 935 } |
| 925 | 936 |
| 926 } // namespace dart | 937 } // namespace dart |
| OLD | NEW |