| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/directory.h" | 6 #include "bin/directory.h" |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 static intptr_t GetHandlerPort(Dart_Handle handle) { | 10 static intptr_t GetHandlerPort(Dart_Handle handle) { |
| 11 if (Dart_IsNull(handle)) { | 11 if (Dart_IsNull(handle)) { |
| 12 return 0; | 12 return 0; |
| 13 } | 13 } |
| 14 return DartUtils::GetIntegerInstanceField(handle, DartUtils::kIdFieldName); | 14 return DartUtils::GetIntegerInstanceField(handle, DartUtils::kIdFieldName); |
| 15 } | 15 } |
| 16 | 16 |
| 17 | 17 |
| 18 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { | 18 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { |
| 19 Dart_EnterScope(); | 19 Dart_EnterScope(); |
| 20 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 20 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 21 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 2)); | 21 Dart_Handle recursive = Dart_GetNativeArgument(args, 2); |
| 22 Dart_Port dir_port = GetHandlerPort(Dart_GetNativeArgument(args, 3)); | 22 Dart_Port dir_port = GetHandlerPort(Dart_GetNativeArgument(args, 3)); |
| 23 Dart_Port file_port = GetHandlerPort(Dart_GetNativeArgument(args, 4)); | 23 Dart_Port file_port = GetHandlerPort(Dart_GetNativeArgument(args, 4)); |
| 24 Dart_Port done_port = GetHandlerPort(Dart_GetNativeArgument(args, 5)); | 24 Dart_Port done_port = GetHandlerPort(Dart_GetNativeArgument(args, 5)); |
| 25 Dart_Port error_port = | 25 Dart_Port error_port = |
| 26 GetHandlerPort(Dart_GetNativeArgument(args, 6)); | 26 GetHandlerPort(Dart_GetNativeArgument(args, 6)); |
| 27 ASSERT(Dart_IsString(path)); | 27 if (!Dart_IsString(path) || !Dart_IsBoolean(recursive)) { |
| 28 Directory::List(DartUtils::GetStringValue(path), | 28 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 29 recursive, | 29 } else { |
| 30 dir_port, | 30 Directory::List(DartUtils::GetStringValue(path), |
| 31 file_port, | 31 DartUtils::GetBooleanValue(recursive), |
| 32 done_port, | 32 dir_port, |
| 33 error_port); | 33 file_port, |
| 34 done_port, |
| 35 error_port); |
| 36 Dart_SetReturnValue(args, Dart_NewBoolean(true)); |
| 37 } |
| 34 Dart_ExitScope(); | 38 Dart_ExitScope(); |
| 35 } | 39 } |
| 36 | 40 |
| 37 | 41 |
| 38 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { | 42 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { |
| 43 static const int kError = -1; |
| 44 static const int kExists = 1; |
| 45 static const int kDoesNotExist = 0; |
| 39 Dart_EnterScope(); | 46 Dart_EnterScope(); |
| 40 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 47 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 41 ASSERT(Dart_IsString(path)); | 48 if (Dart_IsString(path)) { |
| 42 Directory::ExistsResult result = | 49 Directory::ExistsResult result = |
| 43 Directory::Exists(DartUtils::GetStringValue(path)); | 50 Directory::Exists(DartUtils::GetStringValue(path)); |
| 44 int return_value = -1; | 51 int return_value = kError; |
| 45 if (result == Directory::EXISTS) { | 52 if (result == Directory::EXISTS) { |
| 46 return_value = 1; | 53 return_value = kExists; |
| 54 } |
| 55 if (result == Directory::DOES_NOT_EXIST) { |
| 56 return_value = kDoesNotExist; |
| 57 } |
| 58 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 59 } else { |
| 60 Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist)); |
| 47 } | 61 } |
| 48 if (result == Directory::DOES_NOT_EXIST) { | |
| 49 return_value = 0; | |
| 50 } | |
| 51 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | |
| 52 Dart_ExitScope(); | 62 Dart_ExitScope(); |
| 53 } | 63 } |
| 54 | 64 |
| 55 | 65 |
| 56 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { | 66 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { |
| 57 Dart_EnterScope(); | 67 Dart_EnterScope(); |
| 58 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 68 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 59 ASSERT(Dart_IsString(path)); | 69 if (Dart_IsString(path)) { |
| 60 bool created = Directory::Create(DartUtils::GetStringValue(path)); | 70 bool created = Directory::Create(DartUtils::GetStringValue(path)); |
| 61 Dart_SetReturnValue(args, Dart_NewBoolean(created)); | 71 Dart_SetReturnValue(args, Dart_NewBoolean(created)); |
| 72 } else { |
| 73 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 74 } |
| 62 Dart_ExitScope(); | 75 Dart_ExitScope(); |
| 63 } | 76 } |
| 64 | 77 |
| 65 | 78 |
| 66 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { | 79 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { |
| 67 Dart_EnterScope(); | 80 Dart_EnterScope(); |
| 68 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 81 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 69 ASSERT(Dart_IsString(path)); | 82 if (Dart_IsString(path)) { |
| 70 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); | 83 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); |
| 71 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); | 84 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); |
| 85 } else { |
| 86 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 87 } |
| 72 Dart_ExitScope(); | 88 Dart_ExitScope(); |
| 73 } | 89 } |
| OLD | NEW |