Chromium Code Reviews| Index: bin/builtin_natives.cc |
| =================================================================== |
| --- bin/builtin_natives.cc (revision 14418) |
| +++ bin/builtin_natives.cc (working copy) |
| @@ -103,9 +103,17 @@ |
| // test/debug functionality in standalone dart mode. |
| void Builtin::PrintString(FILE* out, Dart_Handle str) { |
| - const char* chars = NULL; |
| - |
| - Dart_Handle result = Dart_StringToCString(str, &chars); |
| + intptr_t length = 0; |
| + Dart_Handle result = Dart_StringLength(str, &length); |
| + DART_CHECK_VALID(result); |
| + if (Dart_IsAsciiString(str)) { |
| + length = (length * sizeof(uint8_t)); |
| + } else { |
| + length = (length * sizeof(uint16_t)); |
|
Bill Hesse
2012/11/01 20:38:01
This is not enough. Some 16-bit code points are e
cshapiro
2012/11/02 17:01:56
We should be emitting UTF-8, not CESU-8.
However,
|
| + } |
| + uint8_t* chars = reinterpret_cast<uint8_t*>(malloc(length)); |
| + ASSERT(chars != NULL); |
| + result = Dart_StringToUTF8(str, chars, &length); |
|
Bill Hesse
2012/11/01 20:38:01
I don't see what the problem is with using Dart_St
siva
2012/11/01 21:23:03
Because that would mean we are assuming that the s
|
| if (Dart_IsError(result)) { |
| // TODO(turnidge): Consider propagating some errors here. What if |
| // an isolate gets interrupted by the embedder in the middle of |
| @@ -113,11 +121,11 @@ |
| // interrupt. |
| fputs(Dart_GetError(result), out); |
| } else { |
| - intptr_t length = strlen(chars); |
| fwrite(chars, sizeof(*chars), length, out); |
| } |
| fputc('\n', out); |
| fflush(out); |
| + free(chars); |
| } |