Chromium Code Reviews| Index: runtime/vm/dart_api_impl.cc |
| =================================================================== |
| --- runtime/vm/dart_api_impl.cc (revision 25291) |
| +++ runtime/vm/dart_api_impl.cc (working copy) |
| @@ -57,7 +57,7 @@ |
| if (obj.IsInstance()) { |
| const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| const Class& list_class = |
| - Class::Handle(core_lib.LookupClass(Symbols::List())); |
| + Class::Handle(core_lib.LookupClass(Symbols::List(), NULL)); |
| ASSERT(!list_class.IsNull()); |
| const Instance& instance = Instance::Cast(obj); |
| const Class& obj_class = Class::Handle(isolate, obj.clazz()); |
| @@ -1050,7 +1050,8 @@ |
| function_name, |
| kNumArguments, |
| Object::empty_array(), |
| - Resolver::kIsQualified)); |
| + Resolver::kIsQualified, |
| + NULL)); // No ambiguity error expected. |
| ASSERT(!function.IsNull()); |
| const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); |
| args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); |
| @@ -2047,8 +2048,8 @@ |
| CURRENT_FUNC, lib_url.ToCString())); |
| return ApiError::New(message); |
| } |
| - const Class& cls = Class::Handle(isolate, |
| - lib.LookupClassAllowPrivate(class_name)); |
| + const Class& cls = Class::Handle( |
| + isolate, lib.LookupClassAllowPrivate(class_name, NULL)); |
|
siva
2013/07/22 22:21:46
As discussed this should probably just ASSERT(!cls
regis
2013/07/22 23:51:27
Done.
|
| if (cls.IsNull()) { |
| const String& message = String::Handle( |
| String::NewFormatted("%s: class '%s' not found in library '%s'.", |
| @@ -2404,8 +2405,8 @@ |
| const Library& lib = |
| Library::Handle(isolate->object_store()->typed_data_library()); |
| ASSERT(!lib.IsNull()); |
| - const Class& cls = |
| - Class::Handle(isolate, lib.LookupClassAllowPrivate(Symbols::ByteData())); |
| + const Class& cls = Class::Handle( |
| + isolate, lib.LookupClassAllowPrivate(Symbols::ByteData(), NULL)); |
| ASSERT(!cls.IsNull()); |
| return ResolveConstructor(CURRENT_FUNC, |
| cls, |
| @@ -2994,9 +2995,14 @@ |
| return state; |
| } |
| + String& ambiguity_error_msg = String::Handle(isolate); |
| Function& function = Function::Handle(isolate); |
| - function = lib.LookupFunctionAllowPrivate(function_name); |
| + function = lib.LookupFunctionAllowPrivate(function_name, |
| + &ambiguity_error_msg); |
| if (function.IsNull()) { |
| + if (!ambiguity_error_msg.IsNull()) { |
| + return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| + } |
| return Api::NewError("%s: did not find top-level function '%s'.", |
| CURRENT_FUNC, |
| function_name.ToCString()); |
| @@ -3155,14 +3161,16 @@ |
| // To access a top-level we may need to use the Field or the |
| // getter Function. The getter function may either be in the |
| // library or in the field's owner class, depending. |
| + String& ambiguity_error_msg = String::Handle(isolate); |
| const Library& lib = Library::Cast(obj); |
| - field = lib.LookupFieldAllowPrivate(field_name); |
| - if (field.IsNull()) { |
| - // No field found. Check for a getter in the lib. |
| + field = lib.LookupFieldAllowPrivate(field_name, &ambiguity_error_msg); |
| + if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
| + // No field found and no ambiguity error. Check for a getter in the lib. |
| const String& getter_name = |
| String::Handle(isolate, Field::GetterName(field_name)); |
| - getter = lib.LookupFunctionAllowPrivate(getter_name); |
| - } else if (FieldIsUninitialized(isolate, field)) { |
| + getter = lib.LookupFunctionAllowPrivate(getter_name, |
| + &ambiguity_error_msg); |
| + } else if (!field.IsNull() && FieldIsUninitialized(isolate, field)) { |
| // A field was found. Check for a getter in the field's owner classs. |
| const Class& cls = Class::Handle(isolate, field.owner()); |
| const String& getter_name = |
| @@ -3174,12 +3182,15 @@ |
| // Invoke the getter and return the result. |
| return Api::NewHandle( |
| isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); |
| - } else if (!field.IsNull()) { |
| + } |
| + if (!field.IsNull()) { |
| return Api::NewHandle(isolate, field.value()); |
| - } else { |
| - return Api::NewError("%s: did not find top-level variable '%s'.", |
| - CURRENT_FUNC, field_name.ToCString()); |
| } |
| + if (!ambiguity_error_msg.IsNull()) { |
| + return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| + } |
| + return Api::NewError("%s: did not find top-level variable '%s'.", |
| + CURRENT_FUNC, field_name.ToCString()); |
| } else if (obj.IsError()) { |
| return container; |
| @@ -3307,12 +3318,14 @@ |
| // To access a top-level we may need to use the Field or the |
| // setter Function. The setter function may either be in the |
| // library or in the field's owner class, depending. |
| + String& ambiguity_error_msg = String::Handle(isolate); |
| const Library& lib = Library::Cast(obj); |
| - field = lib.LookupFieldAllowPrivate(field_name); |
| - if (field.IsNull()) { |
| + field = lib.LookupFieldAllowPrivate(field_name, &ambiguity_error_msg); |
| + if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
| const String& setter_name = |
| String::Handle(isolate, Field::SetterName(field_name)); |
| - setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
| + setter ^= lib.LookupFunctionAllowPrivate(setter_name, |
| + &ambiguity_error_msg); |
| } |
| if (!setter.IsNull()) { |
| @@ -3324,29 +3337,29 @@ |
| Object::Handle(isolate, DartEntry::InvokeFunction(setter, args)); |
| if (result.IsError()) { |
| return Api::NewHandle(isolate, result.raw()); |
| - } else { |
| - return Api::Success(); |
| } |
| - } else if (!field.IsNull()) { |
| + return Api::Success(); |
| + } |
| + if (!field.IsNull()) { |
| if (field.is_final()) { |
| return Api::NewError("%s: cannot set final top-level variable '%s'.", |
| CURRENT_FUNC, field_name.ToCString()); |
| - } else { |
| - field.set_value(value_instance); |
| - return Api::Success(); |
| } |
| - } else { |
| - return Api::NewError("%s: did not find top-level variable '%s'.", |
| - CURRENT_FUNC, field_name.ToCString()); |
| + field.set_value(value_instance); |
| + return Api::Success(); |
| } |
| + if (!ambiguity_error_msg.IsNull()) { |
| + return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| + } |
| + return Api::NewError("%s: did not find top-level variable '%s'.", |
| + CURRENT_FUNC, field_name.ToCString()); |
| } else if (obj.IsError()) { |
| - return container; |
| - } else { |
| - return Api::NewError( |
| - "%s expects argument 'container' to be an object, type, or library.", |
| - CURRENT_FUNC); |
| + return container; |
| } |
| + return Api::NewError( |
| + "%s expects argument 'container' to be an object, type, or library.", |
| + CURRENT_FUNC); |
| } |
| @@ -3693,9 +3706,13 @@ |
| if (cls_name.IsNull()) { |
| RETURN_TYPE_ERROR(isolate, class_name, String); |
| } |
| - const Class& cls = |
| - Class::Handle(isolate, lib.LookupClassAllowPrivate(cls_name)); |
| + String& ambiguity_error_msg = String::Handle(isolate); |
| + const Class& cls = Class::Handle( |
| + isolate, lib.LookupClassAllowPrivate(cls_name, &ambiguity_error_msg)); |
| if (cls.IsNull()) { |
| + if (!ambiguity_error_msg.IsNull()) { |
| + return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| + } |
| // TODO(turnidge): Return null or error in this case? |
| const String& lib_name = String::Handle(isolate, lib.name()); |
| return Api::NewError("Class '%s' not found in library '%s'.", |
| @@ -3726,9 +3743,14 @@ |
| if (::Dart_IsError(state)) { |
| return state; |
| } |
| + String& ambiguity_error_msg = String::Handle(isolate); |
| const Class& cls = |
| - Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); |
| + Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str, |
| + &ambiguity_error_msg)); |
| if (cls.IsNull()) { |
| + if (!ambiguity_error_msg.IsNull()) { |
| + return Api::NewError("%s.", ambiguity_error_msg.ToCString()); |
| + } |
| const String& lib_name = String::Handle(isolate, lib.name()); |
| return Api::NewError("Type '%s' not found in library '%s'.", |
| name_str.ToCString(), lib_name.ToCString()); |