| OLD | NEW |
| 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 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 struct NativeEntries* entry = &(BuiltinEntries[i]); | 92 struct NativeEntries* entry = &(BuiltinEntries[i]); |
| 93 if (!strcmp(function_name, entry->name_) && | 93 if (!strcmp(function_name, entry->name_) && |
| 94 (entry->argument_count_ == argument_count)) { | 94 (entry->argument_count_ == argument_count)) { |
| 95 return reinterpret_cast<Dart_NativeFunction>(entry->function_); | 95 return reinterpret_cast<Dart_NativeFunction>(entry->function_); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 return IONativeLookup(name, argument_count, auto_setup_scope); | 98 return IONativeLookup(name, argument_count, auto_setup_scope); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 const uint8_t* Builtin::NativeSymbol(Dart_NativeFunction nf) { |
| 103 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); |
| 104 for (int i = 0; i < num_entries; i++) { |
| 105 struct NativeEntries* entry = &(BuiltinEntries[i]); |
| 106 if (reinterpret_cast<Dart_NativeFunction>(entry->function_) == nf) { |
| 107 return reinterpret_cast<const uint8_t*>(entry->name_); |
| 108 } |
| 109 } |
| 110 return IONativeSymbol(nf); |
| 111 } |
| 112 |
| 113 |
| 102 // Implementation of native functions which are used for some | 114 // Implementation of native functions which are used for some |
| 103 // test/debug functionality in standalone dart mode. | 115 // test/debug functionality in standalone dart mode. |
| 104 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { | 116 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { |
| 105 intptr_t length = 0; | 117 intptr_t length = 0; |
| 106 uint8_t* chars = NULL; | 118 uint8_t* chars = NULL; |
| 107 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 119 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 108 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); | 120 Dart_Handle result = Dart_StringToUTF8(str, &chars, &length); |
| 109 if (Dart_IsError(result)) { | 121 if (Dart_IsError(result)) { |
| 110 // TODO(turnidge): Consider propagating some errors here. What if | 122 // TODO(turnidge): Consider propagating some errors here. What if |
| 111 // an isolate gets interrupted by the embedder in the middle of | 123 // an isolate gets interrupted by the embedder in the middle of |
| 112 // Dart_StringToUTF8? We need to make sure not to swallow the | 124 // Dart_StringToUTF8? We need to make sure not to swallow the |
| 113 // interrupt. | 125 // interrupt. |
| 114 fprintf(stdout, "%s\n", Dart_GetError(result)); | 126 fprintf(stdout, "%s\n", Dart_GetError(result)); |
| 115 } else { | 127 } else { |
| 116 // Uses fwrite to support printing NUL bytes. | 128 // Uses fwrite to support printing NUL bytes. |
| 117 fwrite(chars, 1, length, stdout); | 129 fwrite(chars, 1, length, stdout); |
| 118 fputs("\n", stdout); | 130 fputs("\n", stdout); |
| 119 } | 131 } |
| 120 fflush(stdout); | 132 fflush(stdout); |
| 121 } | 133 } |
| 122 | 134 |
| 123 } // namespace bin | 135 } // namespace bin |
| 124 } // namespace dart | 136 } // namespace dart |
| OLD | NEW |