OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/directory.h" | 5 #include "bin/directory.h" |
6 | 6 |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "bin/thread.h" | 8 #include "bin/thread.h" |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { | 139 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { |
140 Dart_EnterScope(); | 140 Dart_EnterScope(); |
141 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 141 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
142 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 142 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
143 // Create the list to hold the directory listing here, and pass it to the | 143 // Create the list to hold the directory listing here, and pass it to the |
144 // SyncDirectoryListing object, which adds elements to it. | 144 // SyncDirectoryListing object, which adds elements to it. |
145 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); | 145 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); |
146 // Create the list to hold the directory listing here, and pass it to the | 146 // Create the list to hold the directory listing here, and pass it to the |
147 // SyncDirectoryListing object, which adds elements to it. | 147 // SyncDirectoryListing object, which adds elements to it. |
148 Dart_Handle results = | 148 Dart_Handle results = |
149 Dart_New(DartUtils::GetDartClass(DartUtils::kCoreLibURL, "List"), | 149 Dart_New(DartUtils::GetDartType(DartUtils::kCoreLibURL, "List"), |
150 Dart_Null(), | 150 Dart_Null(), |
151 0, | 151 0, |
152 NULL); | 152 NULL); |
153 SyncDirectoryListing sync_listing(results, | 153 SyncDirectoryListing sync_listing(results, |
154 DartUtils::GetStringValue(path), | 154 DartUtils::GetStringValue(path), |
155 DartUtils::GetBooleanValue(recursive), | 155 DartUtils::GetBooleanValue(recursive), |
156 DartUtils::GetBooleanValue(follow_links)); | 156 DartUtils::GetBooleanValue(follow_links)); |
157 Directory::List(&sync_listing); | 157 Directory::List(&sync_listing); |
158 Dart_SetReturnValue(args, results); | 158 Dart_SetReturnValue(args, results); |
159 Dart_ExitScope(); | 159 Dart_ExitScope(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 response->SetAt(0, new CObjectInt32(CObject::NewInt32(kListError))); | 406 response->SetAt(0, new CObjectInt32(CObject::NewInt32(kListError))); |
407 response->SetAt(1, new CObjectString(CObject::NewString(dir_name))); | 407 response->SetAt(1, new CObjectString(CObject::NewString(dir_name))); |
408 response->SetAt(2, err); | 408 response->SetAt(2, err); |
409 array_->SetAt(index_++, response); | 409 array_->SetAt(index_++, response); |
410 return index_ < length_; | 410 return index_ < length_; |
411 } | 411 } |
412 | 412 |
413 bool SyncDirectoryListing::HandleDirectory(char* dir_name) { | 413 bool SyncDirectoryListing::HandleDirectory(char* dir_name) { |
414 Dart_Handle dir_name_dart = DartUtils::NewString(dir_name); | 414 Dart_Handle dir_name_dart = DartUtils::NewString(dir_name); |
415 Dart_Handle dir = | 415 Dart_Handle dir = |
416 Dart_New(directory_class_, Dart_Null(), 1, &dir_name_dart); | 416 Dart_New(directory_type_, Dart_Null(), 1, &dir_name_dart); |
417 Dart_Invoke(results_, add_string_, 1, &dir); | 417 Dart_Invoke(results_, add_string_, 1, &dir); |
418 return true; | 418 return true; |
419 } | 419 } |
420 | 420 |
421 bool SyncDirectoryListing::HandleLink(char* link_name) { | 421 bool SyncDirectoryListing::HandleLink(char* link_name) { |
422 Dart_Handle link_name_dart = DartUtils::NewString(link_name); | 422 Dart_Handle link_name_dart = DartUtils::NewString(link_name); |
423 Dart_Handle link = | 423 Dart_Handle link = |
424 Dart_New(link_class_, Dart_Null(), 1, &link_name_dart); | 424 Dart_New(link_type_, Dart_Null(), 1, &link_name_dart); |
425 Dart_Invoke(results_, add_string_, 1, &link); | 425 Dart_Invoke(results_, add_string_, 1, &link); |
426 return true; | 426 return true; |
427 } | 427 } |
428 | 428 |
429 bool SyncDirectoryListing::HandleFile(char* file_name) { | 429 bool SyncDirectoryListing::HandleFile(char* file_name) { |
430 Dart_Handle file_name_dart = DartUtils::NewString(file_name); | 430 Dart_Handle file_name_dart = DartUtils::NewString(file_name); |
431 Dart_Handle file = | 431 Dart_Handle file = |
432 Dart_New(file_class_, Dart_Null(), 1, &file_name_dart); | 432 Dart_New(file_type_, Dart_Null(), 1, &file_name_dart); |
433 Dart_Invoke(results_, add_string_, 1, &file); | 433 Dart_Invoke(results_, add_string_, 1, &file); |
434 return true; | 434 return true; |
435 } | 435 } |
436 | 436 |
437 bool SyncDirectoryListing::HandleError(const char* dir_name) { | 437 bool SyncDirectoryListing::HandleError(const char* dir_name) { |
438 Dart_Handle dart_os_error = DartUtils::NewDartOSError(); | 438 Dart_Handle dart_os_error = DartUtils::NewDartOSError(); |
439 Dart_Handle args[3]; | 439 Dart_Handle args[3]; |
440 args[0] = DartUtils::NewString("Directory listing failed"); | 440 args[0] = DartUtils::NewString("Directory listing failed"); |
441 args[1] = DartUtils::NewString(dir_name); | 441 args[1] = DartUtils::NewString(dir_name); |
442 args[2] = dart_os_error; | 442 args[2] = dart_os_error; |
443 Dart_ThrowException(Dart_New( | 443 Dart_ThrowException(Dart_New( |
444 DartUtils::GetDartClass(DartUtils::kIOLibURL, "DirectoryException"), | 444 DartUtils::GetDartType(DartUtils::kIOLibURL, "DirectoryException"), |
445 Dart_Null(), | 445 Dart_Null(), |
446 3, | 446 3, |
447 args)); | 447 args)); |
448 return true; | 448 return true; |
449 } | 449 } |
450 | 450 |
451 | 451 |
452 static bool ListNext(DirectoryListing* listing) { | 452 static bool ListNext(DirectoryListing* listing) { |
453 switch (listing->top()->Next(listing)) { | 453 switch (listing->top()->Next(listing)) { |
454 case kListFile: | 454 case kListFile: |
(...skipping 30 matching lines...) Expand all Loading... |
485 if (listing->error()) { | 485 if (listing->error()) { |
486 listing->HandleError("Invalid path"); | 486 listing->HandleError("Invalid path"); |
487 listing->HandleDone(); | 487 listing->HandleDone(); |
488 } else { | 488 } else { |
489 while (ListNext(listing)) {} | 489 while (ListNext(listing)) {} |
490 } | 490 } |
491 } | 491 } |
492 | 492 |
493 } // namespace bin | 493 } // namespace bin |
494 } // namespace dart | 494 } // namespace dart |
OLD | NEW |