| 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 #include <string.h> | 4 #include <string.h> |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 | 9 |
| 10 Dart_NativeFunction ResolveName(Dart_Handle name, int argc); | 10 Dart_NativeFunction ResolveName(Dart_Handle name, |
| 11 int argc, |
| 12 bool* auto_setup_scope); |
| 11 | 13 |
| 12 DART_EXPORT Dart_Handle sample_extension_Init(Dart_Handle parent_library) { | 14 DART_EXPORT Dart_Handle sample_extension_Init(Dart_Handle parent_library) { |
| 13 if (Dart_IsError(parent_library)) { return parent_library; } | 15 if (Dart_IsError(parent_library)) { return parent_library; } |
| 14 | 16 |
| 15 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); | 17 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); |
| 16 if (Dart_IsError(result_code)) return result_code; | 18 if (Dart_IsError(result_code)) return result_code; |
| 17 | 19 |
| 18 return Dart_Null(); | 20 return Dart_Null(); |
| 19 } | 21 } |
| 20 | 22 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const char* name; | 114 const char* name; |
| 113 Dart_NativeFunction function; | 115 Dart_NativeFunction function; |
| 114 }; | 116 }; |
| 115 | 117 |
| 116 FunctionLookup function_list[] = { | 118 FunctionLookup function_list[] = { |
| 117 {"SystemRand", SystemRand}, | 119 {"SystemRand", SystemRand}, |
| 118 {"SystemSrand", SystemSrand}, | 120 {"SystemSrand", SystemSrand}, |
| 119 {"RandomArray_ServicePort", randomArrayServicePort}, | 121 {"RandomArray_ServicePort", randomArrayServicePort}, |
| 120 {NULL, NULL}}; | 122 {NULL, NULL}}; |
| 121 | 123 |
| 122 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | 124 Dart_NativeFunction ResolveName(Dart_Handle name, |
| 125 int argc, |
| 126 bool* auto_setup_scope) { |
| 123 if (!Dart_IsString(name)) return NULL; | 127 if (!Dart_IsString(name)) return NULL; |
| 124 Dart_NativeFunction result = NULL; | 128 Dart_NativeFunction result = NULL; |
| 129 if (auto_setup_scope == NULL) return NULL; |
| 130 *auto_setup_scope = true; |
| 125 Dart_EnterScope(); | 131 Dart_EnterScope(); |
| 126 const char* cname; | 132 const char* cname; |
| 127 HandleError(Dart_StringToCString(name, &cname)); | 133 HandleError(Dart_StringToCString(name, &cname)); |
| 128 | 134 |
| 129 for (int i=0; function_list[i].name != NULL; ++i) { | 135 for (int i=0; function_list[i].name != NULL; ++i) { |
| 130 if (strcmp(function_list[i].name, cname) == 0) { | 136 if (strcmp(function_list[i].name, cname) == 0) { |
| 131 result = function_list[i].function; | 137 result = function_list[i].function; |
| 132 break; | 138 break; |
| 133 } | 139 } |
| 134 } | 140 } |
| 135 Dart_ExitScope(); | 141 Dart_ExitScope(); |
| 136 return result; | 142 return result; |
| 137 } | 143 } |
| OLD | NEW |