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

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

Issue 10887024: Move print to corelib. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months 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 29 matching lines...) Expand all
40 V(File_LengthFromName, 1) \ 40 V(File_LengthFromName, 1) \
41 V(File_LastModified, 1) \ 41 V(File_LastModified, 1) \
42 V(File_Flush, 1) \ 42 V(File_Flush, 1) \
43 V(File_Create, 1) \ 43 V(File_Create, 1) \
44 V(File_Delete, 1) \ 44 V(File_Delete, 1) \
45 V(File_Directory, 1) \ 45 V(File_Directory, 1) \
46 V(File_FullPath, 1) \ 46 V(File_FullPath, 1) \
47 V(File_OpenStdio, 1) \ 47 V(File_OpenStdio, 1) \
48 V(File_GetStdioHandleType, 1) \ 48 V(File_GetStdioHandleType, 1) \
49 V(File_NewServicePort, 0) \ 49 V(File_NewServicePort, 0) \
50 V(Logger_PrintString, 1) \
51 V(Platform_NumberOfProcessors, 0) \ 50 V(Platform_NumberOfProcessors, 0) \
52 V(Platform_OperatingSystem, 0) \ 51 V(Platform_OperatingSystem, 0) \
53 V(Platform_PathSeparator, 0) \ 52 V(Platform_PathSeparator, 0) \
54 V(Platform_LocalHostname, 0) \ 53 V(Platform_LocalHostname, 0) \
55 V(Platform_Environment, 0) \ 54 V(Platform_Environment, 0) \
56 V(Process_Start, 10) \ 55 V(Process_Start, 10) \
57 V(Process_Kill, 3) \ 56 V(Process_Kill, 3) \
58 V(ServerSocket_CreateBindListen, 4) \ 57 V(ServerSocket_CreateBindListen, 4) \
59 V(ServerSocket_Accept, 2) \ 58 V(ServerSocket_Accept, 2) \
60 V(Socket_CreateConnect, 3) \ 59 V(Socket_CreateConnect, 3) \
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 92 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
94 } 93 }
95 } 94 }
96 return NULL; 95 return NULL;
97 } 96 }
98 97
99 98
100 // Implementation of native functions which are used for some 99 // Implementation of native functions which are used for some
101 // test/debug functionality in standalone dart mode. 100 // test/debug functionality in standalone dart mode.
102 101
103 void Builtin::PrintString(FILE* out, Dart_Handle str) {
104 const uint8_t* characters = NULL;
105 intptr_t length;
106 Dart_Handle result = Dart_StringToBytes(str, &characters, &length);
107 if (Dart_IsError(result)) {
108 // TODO(turnidge): Consider propagating some errors here. What if
109 // an isolate gets interrupted by the embedder in the middle of
110 // Dart_StringToBytes? We need to make sure not to swallow the
111 // interrupt.
112 fputs(Dart_GetError(result), out);
113 } else {
114 fwrite(characters, sizeof(*characters), length, out);
115 }
116 fputc('\n', out);
117 fflush(out);
118 }
119
120
121 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
122 Dart_EnterScope();
123 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0));
124 Dart_ExitScope();
125 }
126
127 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { 102 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) {
128 Dart_EnterScope(); 103 Dart_EnterScope();
129 int64_t status = 0; 104 int64_t status = 0;
130 // Ignore result if passing invalid argument and just exit 0. 105 // Ignore result if passing invalid argument and just exit 0.
131 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 106 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
132 Dart_ExitScope(); 107 Dart_ExitScope();
133 exit(status); 108 exit(status);
134 } 109 }
135 110
136 111
137 void Builtin::SetupIOLibrary(Dart_Handle io_lib) { 112 void Builtin::SetupIOLibrary(Dart_Handle io_lib) {
138 Dart_Handle url = Dart_NewString(DartUtils::kIsolateLibURL); 113 Dart_Handle url = Dart_NewString(DartUtils::kIsolateLibURL);
139 DART_CHECK_VALID(url); 114 DART_CHECK_VALID(url);
140 Dart_Handle isolate_lib = Dart_LookupLibrary(url); 115 Dart_Handle isolate_lib = Dart_LookupLibrary(url);
141 DART_CHECK_VALID(isolate_lib); 116 DART_CHECK_VALID(isolate_lib);
142 Dart_Handle timer_closure = 117 Dart_Handle timer_closure =
143 Dart_Invoke(io_lib, Dart_NewString("_getTimerFactoryClosure"), 0, NULL); 118 Dart_Invoke(io_lib, Dart_NewString("_getTimerFactoryClosure"), 0, NULL);
144 Dart_Handle args[1]; 119 Dart_Handle args[1];
145 args[0] = timer_closure; 120 args[0] = timer_closure;
146 DART_CHECK_VALID(Dart_Invoke(isolate_lib, 121 DART_CHECK_VALID(Dart_Invoke(isolate_lib,
147 Dart_NewString("_setTimerFactoryClosure"), 122 Dart_NewString("_setTimerFactoryClosure"),
148 1, args)); 123 1, args));
149 } 124 }
OLDNEW
« no previous file with comments | « runtime/bin/builtin.dart ('k') | runtime/bin/main.cc » ('j') | runtime/lib/print_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698