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

Unified Diff: runtime/bin/directory.cc

Issue 8417023: Add type checks to directory listing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/directory.dart » ('j') | runtime/bin/directory_impl.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory.cc
diff --git a/runtime/bin/directory.cc b/runtime/bin/directory.cc
index 5cb4296a395e510bd1da6038dbbd8466dcf23b74..24e1326cbc8f847323686302274d89dec8b4989a 100644
--- a/runtime/bin/directory.cc
+++ b/runtime/bin/directory.cc
@@ -18,37 +18,47 @@ static intptr_t GetHandlerPort(Dart_Handle handle) {
void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_Handle path = Dart_GetNativeArgument(args, 1);
- bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 2));
+ Dart_Handle recursive = Dart_GetNativeArgument(args, 2);
Dart_Port dir_port = GetHandlerPort(Dart_GetNativeArgument(args, 3));
Dart_Port file_port = GetHandlerPort(Dart_GetNativeArgument(args, 4));
Dart_Port done_port = GetHandlerPort(Dart_GetNativeArgument(args, 5));
Dart_Port error_port =
GetHandlerPort(Dart_GetNativeArgument(args, 6));
- ASSERT(Dart_IsString(path));
- Directory::List(DartUtils::GetStringValue(path),
- recursive,
- dir_port,
- file_port,
- done_port,
- error_port);
+ if (!Dart_IsString(path) || !Dart_IsBoolean(recursive)) {
+ Dart_SetReturnValue(args, Dart_NewBoolean(false));
+ } else {
+ Directory::List(DartUtils::GetStringValue(path),
+ DartUtils::GetBooleanValue(recursive),
+ dir_port,
+ file_port,
+ done_port,
+ error_port);
+ Dart_SetReturnValue(args, Dart_NewBoolean(true));
+ }
Dart_ExitScope();
}
void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) {
+ static const int kError = -1;
+ static const int kExists = 1;
+ static const int kDoesNotExist = 0;
Dart_EnterScope();
Dart_Handle path = Dart_GetNativeArgument(args, 1);
- ASSERT(Dart_IsString(path));
- Directory::ExistsResult result =
- Directory::Exists(DartUtils::GetStringValue(path));
- int return_value = -1;
- if (result == Directory::EXISTS) {
- return_value = 1;
- }
- if (result == Directory::DOES_NOT_EXIST) {
- return_value = 0;
+ if (Dart_IsString(path)) {
+ Directory::ExistsResult result =
+ Directory::Exists(DartUtils::GetStringValue(path));
+ int return_value = kError;
+ if (result == Directory::EXISTS) {
+ return_value = kExists;
+ }
+ if (result == Directory::DOES_NOT_EXIST) {
+ return_value = kDoesNotExist;
+ }
+ Dart_SetReturnValue(args, Dart_NewInteger(return_value));
+ } else {
+ Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist));
}
- Dart_SetReturnValue(args, Dart_NewInteger(return_value));
Dart_ExitScope();
}
@@ -56,9 +66,12 @@ void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) {
void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_Handle path = Dart_GetNativeArgument(args, 1);
- ASSERT(Dart_IsString(path));
- bool created = Directory::Create(DartUtils::GetStringValue(path));
- Dart_SetReturnValue(args, Dart_NewBoolean(created));
+ if (Dart_IsString(path)) {
+ bool created = Directory::Create(DartUtils::GetStringValue(path));
+ Dart_SetReturnValue(args, Dart_NewBoolean(created));
+ } else {
+ Dart_SetReturnValue(args, Dart_NewBoolean(false));
+ }
Dart_ExitScope();
}
@@ -66,8 +79,11 @@ void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) {
void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_Handle path = Dart_GetNativeArgument(args, 1);
- ASSERT(Dart_IsString(path));
- bool deleted = Directory::Delete(DartUtils::GetStringValue(path));
- Dart_SetReturnValue(args, Dart_NewBoolean(deleted));
+ if (Dart_IsString(path)) {
+ bool deleted = Directory::Delete(DartUtils::GetStringValue(path));
+ Dart_SetReturnValue(args, Dart_NewBoolean(deleted));
+ } else {
+ Dart_SetReturnValue(args, Dart_NewBoolean(false));
+ }
Dart_ExitScope();
}
« no previous file with comments | « no previous file | runtime/bin/directory.dart » ('j') | runtime/bin/directory_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698