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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8492015: Allow printf-style arguments for Dart_Error and Api::Error. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 1265)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -67,8 +67,12 @@
}
-DART_EXPORT Dart_Handle Dart_Error(const char* error) {
- return Api::Error(error);
+DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ Dart_Handle error = Api::VError(format, args);
+ va_end(args);
+ return error;
}
@@ -527,7 +531,9 @@
cls_name ^= param.raw();
const Class& cls = Class::Handle(lib.LookupClass(cls_name));
if (cls.IsNull()) {
- return Api::Error("Specified class does not exist");
+ const String& lib_name = String::Handle(lib.name());
+ return Api::Error("Class '%s' not found in library '%s'.",
+ cls_name.ToCString(), lib_name.ToCString());
}
return Api::NewLocalHandle(cls);
}
@@ -2008,15 +2014,29 @@
}
-Dart_Handle Api::Error(const char* text) {
+Dart_Handle Api::VError(const char* format, va_list args) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
- const String& message = String::Handle(String::New(text));
+
+ intptr_t len = OS::VSNPrint(NULL, 0, format, args);
+ char* buffer = reinterpret_cast<char*>(zone.Allocate(len+1));
+ OS::VSNPrint(buffer, len+1, format, args);
Anton Muhin 2011/11/08 08:32:18 nit: space around + ?
turnidge 2011/11/08 19:02:02 Done.
+
+ const String& message = String::Handle(String::New(buffer));
const Object& obj = Object::Handle(ApiFailure::New(message));
return Api::NewLocalHandle(obj);
}
+Dart_Handle Api::Error(const char* format, ...) {
Anton Muhin 2011/11/08 08:32:18 looks pretty much like Dart_Error. Do we need bot
turnidge 2011/11/08 19:02:02 I am providing Dart_Error for external developers.
+ va_list args;
+ va_start(args, format);
+ Dart_Handle error = Api::VError(format, args);
+ va_end(args);
+ return error;
+}
+
+
Dart_Handle Api::Null() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL);
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698