| 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/builtin.h" | 5 #include "bin/builtin.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 return NULL; | 98 return NULL; |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 // Implementation of native functions which are used for some | 102 // Implementation of native functions which are used for some |
| 103 // test/debug functionality in standalone dart mode. | 103 // test/debug functionality in standalone dart mode. |
| 104 | 104 |
| 105 void Builtin::PrintString(FILE* out, Dart_Handle str) { | 105 void Builtin::PrintString(FILE* out, Dart_Handle str) { |
| 106 const char* chars = NULL; | 106 intptr_t length = 0; |
| 107 | 107 uint8_t* chars = NULL; |
| 108 Dart_Handle result = Dart_StringToCString(str, &chars); | 108 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); |
| 109 if (Dart_IsError(result)) { | 109 if (Dart_IsError(result)) { |
| 110 // TODO(turnidge): Consider propagating some errors here. What if | 110 // TODO(turnidge): Consider propagating some errors here. What if |
| 111 // an isolate gets interrupted by the embedder in the middle of | 111 // an isolate gets interrupted by the embedder in the middle of |
| 112 // Dart_StringToBytes? We need to make sure not to swallow the | 112 // Dart_StringToUTF8? We need to make sure not to swallow the |
| 113 // interrupt. | 113 // interrupt. |
| 114 fputs(Dart_GetError(result), out); | 114 fputs(Dart_GetError(result), out); |
| 115 } else { | 115 } else { |
| 116 intptr_t length = strlen(chars); | |
| 117 fwrite(chars, sizeof(*chars), length, out); | 116 fwrite(chars, sizeof(*chars), length, out); |
| 118 } | 117 } |
| 119 fputc('\n', out); | 118 fputc('\n', out); |
| 120 fflush(out); | 119 fflush(out); |
| 121 } | 120 } |
| 122 | 121 |
| 123 | 122 |
| 124 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { | 123 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { |
| 125 Dart_EnterScope(); | 124 Dart_EnterScope(); |
| 126 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); | 125 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); |
| 127 Dart_ExitScope(); | 126 Dart_ExitScope(); |
| 128 } | 127 } |
| 129 | 128 |
| 130 | 129 |
| 131 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { | 130 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { |
| 132 Dart_EnterScope(); | 131 Dart_EnterScope(); |
| 133 int64_t status = 0; | 132 int64_t status = 0; |
| 134 // Ignore result if passing invalid argument and just exit 0. | 133 // Ignore result if passing invalid argument and just exit 0. |
| 135 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); | 134 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); |
| 136 Dart_ExitScope(); | 135 Dart_ExitScope(); |
| 137 exit(status); | 136 exit(status); |
| 138 } | 137 } |
| OLD | NEW |