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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8507035: Here's a template for how I plan on doing error-checking on inputs for (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 | « no previous file | 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 1409)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -27,6 +27,23 @@
namespace dart {
+#define UNWRAP_NONNULL(dart_handle, vm_handle, Type) \
+ do { \
+ const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \
+ if (tmp.Is##Type()) { \
+ (vm_handle) ^= tmp.raw(); \
+ } else if (tmp.IsNull()) { \
+ return Api::Error("%s expects argument '%s' to be non-null.", \
+ __func__, #dart_handle); \
+ } else if (tmp.IsApiFailure()) { \
+ return dart_handle; \
+ } else { \
+ return Api::Error("%s expects argument '%s' to be of type %s.", \
+ __func__, #dart_handle, #Type); \
+ } \
+ } while (0)
+
+
DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) {
ASSERT(Isolate::Current() != NULL);
Zone zone; // Setup a VM zone as we are creating some handles.
@@ -381,10 +398,12 @@
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
- const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
+ String& url_str = String::Handle();
+ UNWRAP_NONNULL(url, url_str, String);
const Library& library = Library::Handle(Library::LookupLibrary(url_str));
if (library.IsNull()) {
- return Api::Error("Unknown library");
+ return Api::Error("%s: library '%s' not found.",
+ __func__, url_str.ToCString());
} else {
return Api::NewLocalHandle(library);
}
@@ -2029,7 +2048,11 @@
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
- intptr_t len = OS::VSNPrint(NULL, 0, format, args);
+ va_list args_copy;
+ va_copy(args_copy, args);
+ intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy);
+ va_end(args_copy);
+
char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
OS::VSNPrint(buffer, (len + 1), format, args);
@@ -2038,7 +2061,6 @@
return Api::NewLocalHandle(obj);
}
-
Dart_Handle Api::Error(const char* format, ...) {
va_list args;
va_start(args, format);
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698