| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| 11 | 11 |
| 12 #include "platform/assert.h" | 12 #include "platform/assert.h" |
| 13 | 13 |
| 14 #include "bin/builtin.h" | 14 #include "bin/builtin.h" |
| 15 #include "bin/dartutils.h" | 15 #include "bin/dartutils.h" |
| 16 #include "bin/file.h" |
| 16 #include "bin/io_natives.h" | 17 #include "bin/io_natives.h" |
| 17 #include "bin/platform.h" | 18 #include "bin/platform.h" |
| 18 | 19 |
| 19 namespace dart { | 20 namespace dart { |
| 20 namespace bin { | 21 namespace bin { |
| 21 | 22 |
| 22 // Lists the native functions implementing basic functionality in | 23 // Lists the native functions implementing basic functionality in |
| 23 // standalone dart, such as printing, file I/O, and platform information. | 24 // standalone dart, such as printing, file I/O, and platform information. |
| 24 // Advanced I/O classes like sockets and process management are implemented | 25 // Advanced I/O classes like sockets and process management are implemented |
| 25 // using functions listed in io_natives.cc. | 26 // using functions listed in io_natives.cc. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 for (int i = 0; i < num_entries; i++) { | 73 for (int i = 0; i < num_entries; i++) { |
| 73 struct NativeEntries* entry = &(BuiltinEntries[i]); | 74 struct NativeEntries* entry = &(BuiltinEntries[i]); |
| 74 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) { | 75 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) { |
| 75 return reinterpret_cast<const uint8_t*>(entry->name_); | 76 return reinterpret_cast<const uint8_t*>(entry->name_); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 return IONativeSymbol(nf); | 79 return IONativeSymbol(nf); |
| 79 } | 80 } |
| 80 | 81 |
| 81 | 82 |
| 82 extern bool capture_stdout; | |
| 83 | |
| 84 | |
| 85 // Implementation of native functions which are used for some | 83 // Implementation of native functions which are used for some |
| 86 // test/debug functionality in standalone dart mode. | 84 // test/debug functionality in standalone dart mode. |
| 87 void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) { | 85 void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) { |
| 88 intptr_t length = 0; | 86 intptr_t length = 0; |
| 89 uint8_t* chars = NULL; | 87 uint8_t* chars = NULL; |
| 90 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 88 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 91 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); | 89 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); |
| 92 if (Dart_IsError(result)) Dart_PropagateError(result); | 90 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 93 | 91 |
| 94 // Uses fwrite to support printing NUL bytes. | 92 // Uses fwrite to support printing NUL bytes. |
| 95 fwrite(chars, 1, length, stdout); | 93 fwrite(chars, 1, length, stdout); |
| 96 fputs("\n", stdout); | 94 fputs("\n", stdout); |
| 97 fflush(stdout); | 95 fflush(stdout); |
| 98 if (capture_stdout) { | 96 if (File::capture_stdout()) { |
| 99 // For now we report print output on the Stdout stream. | 97 // For now we report print output on the Stdout stream. |
| 100 uint8_t newline[] = { '\n' }; | 98 uint8_t newline[] = { '\n' }; |
| 101 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); | 99 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); |
| 102 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", | 100 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", |
| 103 newline, sizeof(newline)); | 101 newline, sizeof(newline)); |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 | 104 |
| 107 } // namespace bin | 105 } // namespace bin |
| 108 } // namespace dart | 106 } // namespace dart |
| OLD | NEW |