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 // TODO(ager): Generalize this to Directory::kInvalidId. | |
13 return 0; | 12 return 0; |
14 } | 13 } |
15 return DartUtils::GetIntegerInstanceField(handle, DartUtils::kIdFieldName); | 14 return DartUtils::GetIntegerInstanceField(handle, DartUtils::kIdFieldName); |
16 } | 15 } |
17 | 16 |
18 | 17 |
19 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { | 18 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { |
20 Dart_EnterScope(); | 19 Dart_EnterScope(); |
21 Dart_Handle path = Dart_GetNativeArgument(args, 1); | 20 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
22 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 2)); | 21 bool recursive = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 2)); |
23 Dart_Port dir_port = GetHandlerPort(Dart_GetNativeArgument(args, 3)); | 22 Dart_Port dir_port = GetHandlerPort(Dart_GetNativeArgument(args, 3)); |
24 Dart_Port file_port = GetHandlerPort(Dart_GetNativeArgument(args, 4)); | 23 Dart_Port file_port = GetHandlerPort(Dart_GetNativeArgument(args, 4)); |
25 Dart_Port done_port = GetHandlerPort(Dart_GetNativeArgument(args, 5)); | 24 Dart_Port done_port = GetHandlerPort(Dart_GetNativeArgument(args, 5)); |
26 Dart_Port error_port = | 25 Dart_Port error_port = |
27 GetHandlerPort(Dart_GetNativeArgument(args, 6)); | 26 GetHandlerPort(Dart_GetNativeArgument(args, 6)); |
28 ASSERT(Dart_IsString(path)); | 27 ASSERT(Dart_IsString(path)); |
29 Directory::List(DartUtils::GetStringValue(path), | 28 Directory::List(DartUtils::GetStringValue(path), |
30 recursive, | 29 recursive, |
31 dir_port, | 30 dir_port, |
32 file_port, | 31 file_port, |
33 done_port, | 32 done_port, |
34 error_port); | 33 error_port); |
35 Dart_ExitScope(); | 34 Dart_ExitScope(); |
36 } | 35 } |
| 36 |
| 37 |
| 38 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { |
| 39 Dart_EnterScope(); |
| 40 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 41 ASSERT(Dart_IsString(path)); |
| 42 Directory::ExistsResult result = |
| 43 Directory::Exists(DartUtils::GetStringValue(path)); |
| 44 int return_value = -1; |
| 45 if (result == Directory::EXISTS) { |
| 46 return_value = 1; |
| 47 } |
| 48 if (result == Directory::DOES_NOT_EXIST) { |
| 49 return_value = 0; |
| 50 } |
| 51 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 52 Dart_ExitScope(); |
| 53 } |
| 54 |
| 55 |
| 56 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { |
| 57 Dart_EnterScope(); |
| 58 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 59 ASSERT(Dart_IsString(path)); |
| 60 bool created = Directory::Create(DartUtils::GetStringValue(path)); |
| 61 Dart_SetReturnValue(args, Dart_NewBoolean(created)); |
| 62 Dart_ExitScope(); |
| 63 } |
| 64 |
| 65 |
| 66 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { |
| 67 Dart_EnterScope(); |
| 68 Dart_Handle path = Dart_GetNativeArgument(args, 1); |
| 69 ASSERT(Dart_IsString(path)); |
| 70 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); |
| 71 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); |
| 72 Dart_ExitScope(); |
| 73 } |
OLD | NEW |