Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: runtime/bin/builtin_natives.cc

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 } 96 }
97 return NULL; 97 return NULL;
98 } 98 }
99 99
100 100
101 // Implementation of native functions which are used for some 101 // Implementation of native functions which are used for some
102 // test/debug functionality in standalone dart mode. 102 // test/debug functionality in standalone dart mode.
103 103
104 void Builtin::PrintString(FILE* out, Dart_Handle str) { 104 void Builtin::PrintString(FILE* out, Dart_Handle str) {
105 const uint8_t* characters = NULL; 105 intptr_t length = 0;
106 intptr_t length; 106 Dart_Handle result = Dart_StringLength(str, &length);
107 Dart_Handle result = Dart_StringToBytes(str, &characters, &length); 107 DART_CHECK_VALID(result);
108 uint8_t* chars = reinterpret_cast<uint8_t*>(malloc(length * sizeof(uint8_t)));
109 result = Dart_StringToUTF8(str, chars, &length);
108 if (Dart_IsError(result)) { 110 if (Dart_IsError(result)) {
109 // TODO(turnidge): Consider propagating some errors here. What if 111 // TODO(turnidge): Consider propagating some errors here. What if
110 // an isolate gets interrupted by the embedder in the middle of 112 // an isolate gets interrupted by the embedder in the middle of
111 // Dart_StringToBytes? We need to make sure not to swallow the 113 // Dart_StringToBytes? We need to make sure not to swallow the
112 // interrupt. 114 // interrupt.
113 fputs(Dart_GetError(result), out); 115 fputs(Dart_GetError(result), out);
114 } else { 116 } else {
115 fwrite(characters, sizeof(*characters), length, out); 117 fwrite(chars, sizeof(*chars), length, out);
116 } 118 }
117 fputc('\n', out); 119 fputc('\n', out);
118 fflush(out); 120 fflush(out);
121 free(chars);
119 } 122 }
120 123
121 124
122 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { 125 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
123 Dart_EnterScope(); 126 Dart_EnterScope();
124 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); 127 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0));
125 Dart_ExitScope(); 128 Dart_ExitScope();
126 } 129 }
127 130
128 131
129 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { 132 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) {
130 Dart_EnterScope(); 133 Dart_EnterScope();
131 int64_t status = 0; 134 int64_t status = 0;
132 // Ignore result if passing invalid argument and just exit 0. 135 // Ignore result if passing invalid argument and just exit 0.
133 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 136 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
134 Dart_ExitScope(); 137 Dart_ExitScope();
135 exit(status); 138 exit(status);
136 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698