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

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

Issue 1800863002: Cleanup in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « runtime/bin/builtin_gen_snapshot.cc ('k') | runtime/bin/builtin_nolib.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdlib.h> 5 #include <stdlib.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 bool* auto_setup_scope) { 53 bool* auto_setup_scope) {
54 const char* function_name = NULL; 54 const char* function_name = NULL;
55 Dart_Handle result = Dart_StringToCString(name, &function_name); 55 Dart_Handle result = Dart_StringToCString(name, &function_name);
56 DART_CHECK_VALID(result); 56 DART_CHECK_VALID(result);
57 ASSERT(function_name != NULL); 57 ASSERT(function_name != NULL);
58 ASSERT(auto_setup_scope != NULL); 58 ASSERT(auto_setup_scope != NULL);
59 *auto_setup_scope = true; 59 *auto_setup_scope = true;
60 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); 60 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
61 for (int i = 0; i < num_entries; i++) { 61 for (int i = 0; i < num_entries; i++) {
62 struct NativeEntries* entry = &(BuiltinEntries[i]); 62 struct NativeEntries* entry = &(BuiltinEntries[i]);
63 if (!strcmp(function_name, entry->name_) && 63 if ((strcmp(function_name, entry->name_) == 0) &&
64 (entry->argument_count_ == argument_count)) { 64 (entry->argument_count_ == argument_count)) {
65 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 65 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
66 } 66 }
67 } 67 }
68 return IONativeLookup(name, argument_count, auto_setup_scope); 68 return IONativeLookup(name, argument_count, auto_setup_scope);
69 } 69 }
70 70
71 71
72 const uint8_t* Builtin::NativeSymbol(Dart_NativeFunction nf) { 72 const uint8_t* Builtin::NativeSymbol(Dart_NativeFunction nf) {
73 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); 73 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
74 for (int i = 0; i < num_entries; i++) { 74 for (int i = 0; i < num_entries; i++) {
75 struct NativeEntries* entry = &(BuiltinEntries[i]); 75 struct NativeEntries* entry = &(BuiltinEntries[i]);
76 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) { 76 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) {
77 return reinterpret_cast<const uint8_t*>(entry->name_); 77 return reinterpret_cast<const uint8_t*>(entry->name_);
78 } 78 }
79 } 79 }
80 return IONativeSymbol(nf); 80 return IONativeSymbol(nf);
81 } 81 }
82 82
83 83
84 // Implementation of native functions which are used for some 84 // Implementation of native functions which are used for some
85 // test/debug functionality in standalone dart mode. 85 // test/debug functionality in standalone dart mode.
86 void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) { 86 void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) {
87 intptr_t length = 0; 87 intptr_t length = 0;
88 uint8_t* chars = NULL; 88 uint8_t* chars = NULL;
89 Dart_Handle str = Dart_GetNativeArgument(args, 0); 89 Dart_Handle str = Dart_GetNativeArgument(args, 0);
90 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); 90 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length);
91 if (Dart_IsError(result)) Dart_PropagateError(result); 91 if (Dart_IsError(result)) {
92 Dart_PropagateError(result);
93 }
92 94
93 // Uses fwrite to support printing NUL bytes. 95 // Uses fwrite to support printing NUL bytes.
94 intptr_t res = fwrite(chars, 1, length, stdout); 96 intptr_t res = fwrite(chars, 1, length, stdout);
95 ASSERT(res == length); 97 ASSERT(res == length);
96 fputs("\n", stdout); 98 fputs("\n", stdout);
97 fflush(stdout); 99 fflush(stdout);
98 if (ShouldCaptureStdout()) { 100 if (ShouldCaptureStdout()) {
99 // For now we report print output on the Stdout stream. 101 // For now we report print output on the Stdout stream.
100 uint8_t newline[] = { '\n' }; 102 uint8_t newline[] = { '\n' };
101 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); 103 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length);
102 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", 104 Dart_ServiceSendDataEvent("Stdout", "WriteEvent",
103 newline, sizeof(newline)); 105 newline, sizeof(newline));
104 } 106 }
105 } 107 }
106 108
107 } // namespace bin 109 } // namespace bin
108 } // namespace dart 110 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin_gen_snapshot.cc ('k') | runtime/bin/builtin_nolib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698