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 bool exists = false; | |
43 bool success = Directory::Exists(DartUtils::GetStringValue(path), &exists); | |
Søren Gjesse
2011/10/14 11:44:14
How about returning an enum Yes/No/Don't know inst
Mads Ager (google)
2011/10/14 12:22:54
Done.
| |
44 int return_value = success ? (exists ? 1 : 0) : -1; | |
45 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | |
46 Dart_ExitScope(); | |
47 } | |
48 | |
49 | |
50 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { | |
51 Dart_EnterScope(); | |
52 Dart_Handle path = Dart_GetNativeArgument(args, 1); | |
53 ASSERT(Dart_IsString(path)); | |
54 bool created = Directory::Create(DartUtils::GetStringValue(path)); | |
55 Dart_SetReturnValue(args, Dart_NewBoolean(created)); | |
56 Dart_ExitScope(); | |
57 } | |
58 | |
59 | |
60 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { | |
61 Dart_EnterScope(); | |
62 Dart_Handle path = Dart_GetNativeArgument(args, 1); | |
63 ASSERT(Dart_IsString(path)); | |
64 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); | |
65 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); | |
66 Dart_ExitScope(); | |
67 } | |
OLD | NEW |