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

Side by Side Diff: bin/builtin_natives.cc

Issue 11275008: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 uint8_t* characters = NULL; 106 intptr_t length = 0;
107 intptr_t length; 107 Dart_Handle result = Dart_StringLength(str, &length);
108 Dart_Handle result = Dart_StringToBytes(str, &characters, &length); 108 DART_CHECK_VALID(result);
109 uint8_t* chars = reinterpret_cast<uint8_t*>(malloc(length * sizeof(uint8_t)));
110 result = Dart_StringToUTF8(str, chars, &length);
109 if (Dart_IsError(result)) { 111 if (Dart_IsError(result)) {
110 // TODO(turnidge): Consider propagating some errors here. What if 112 // TODO(turnidge): Consider propagating some errors here. What if
111 // an isolate gets interrupted by the embedder in the middle of 113 // an isolate gets interrupted by the embedder in the middle of
112 // Dart_StringToBytes? We need to make sure not to swallow the 114 // Dart_StringToBytes? We need to make sure not to swallow the
113 // interrupt. 115 // interrupt.
114 fputs(Dart_GetError(result), out); 116 fputs(Dart_GetError(result), out);
115 } else { 117 } else {
116 fwrite(characters, sizeof(*characters), length, out); 118 fwrite(chars, sizeof(*chars), length, out);
117 } 119 }
118 fputc('\n', out); 120 fputc('\n', out);
119 fflush(out); 121 fflush(out);
122 free(chars);
120 } 123 }
121 124
122 125
123 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { 126 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
124 Dart_EnterScope(); 127 Dart_EnterScope();
125 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); 128 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0));
126 Dart_ExitScope(); 129 Dart_ExitScope();
127 } 130 }
128 131
129 132
130 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { 133 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) {
131 Dart_EnterScope(); 134 Dart_EnterScope();
132 int64_t status = 0; 135 int64_t status = 0;
133 // Ignore result if passing invalid argument and just exit 0. 136 // Ignore result if passing invalid argument and just exit 0.
134 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 137 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
135 Dart_ExitScope(); 138 Dart_ExitScope();
136 exit(status); 139 exit(status);
137 } 140 }
OLDNEW
« no previous file with comments | « bin/builtin.cc ('k') | bin/builtin_nolib.cc » ('j') | bin/dartutils.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698