| 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 */ |
| 5 #include <assert.h> |
| 6 #include <stdio.h> |
| 7 #include <stdlib.h> |
| 4 #include <string.h> | 8 #include <string.h> |
| 5 | 9 |
| 6 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| 7 | 11 |
| 8 | 12 #if defined(ASSERT) |
| 9 namespace dart { | 13 #error ASSERT already defined! |
| 10 namespace bin { | 14 #endif |
| 11 | |
| 12 Dart_NativeFunction ResolveName(Dart_Handle name, int argc); | |
| 13 | |
| 14 DART_EXPORT Dart_Handle test_extension_Init(Dart_Handle parent_library) { | |
| 15 if (Dart_IsError(parent_library)) { return parent_library; } | |
| 16 | |
| 17 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); | |
| 18 if (Dart_IsError(result_code)) return result_code; | |
| 19 | |
| 20 return parent_library; | |
| 21 } | |
| 22 | 15 |
| 23 | 16 |
| 17 /* Native methods. */ |
| 24 void IfNull(Dart_NativeArguments arguments) { | 18 void IfNull(Dart_NativeArguments arguments) { |
| 25 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | 19 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); |
| 26 if (Dart_IsNull(object)) { | 20 if (Dart_IsNull(object)) { |
| 27 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); | 21 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); |
| 28 } else { | 22 } else { |
| 29 Dart_SetReturnValue(arguments, object); | 23 Dart_SetReturnValue(arguments, object); |
| 30 } | 24 } |
| 31 } | 25 } |
| 32 | 26 |
| 33 | 27 |
| 34 void ThrowMeTheBall(Dart_NativeArguments arguments) { | 28 void ThrowMeTheBall(Dart_NativeArguments arguments) { |
| 35 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | 29 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); |
| 36 Dart_ThrowException(object); | 30 Dart_ThrowException(object); |
| 37 } | 31 } |
| 38 | 32 |
| 39 | 33 |
| 34 /* Native resolver for the extension library. */ |
| 40 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | 35 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { |
| 41 assert(Dart_IsString(name)); | 36 assert(Dart_IsString(name)); |
| 42 const char* cname; | 37 const char* cname; |
| 43 Dart_Handle check_error; | 38 Dart_Handle check_error; |
| 44 | 39 |
| 45 check_error = Dart_StringToCString(name, &cname); | 40 check_error = Dart_StringToCString(name, &cname); |
| 46 if (Dart_IsError(check_error)) { | 41 if (Dart_IsError(check_error)) { |
| 47 Dart_PropagateError(check_error); | 42 Dart_PropagateError(check_error); |
| 48 } | 43 } |
| 49 if ((strcmp("TestExtension_IfNull", cname) == 0) && (argc == 2)) { | 44 if ((strcmp("TestExtension_IfNull", cname) == 0) && (argc == 2)) { |
| 50 return IfNull; | 45 return IfNull; |
| 51 } | 46 } |
| 52 if ((strcmp("TestExtension_ThrowMeTheBall", cname) == 0) && (argc == 1)) { | 47 if ((strcmp("TestExtension_ThrowMeTheBall", cname) == 0) && (argc == 1)) { |
| 53 return ThrowMeTheBall; | 48 return ThrowMeTheBall; |
| 54 } | 49 } |
| 55 return NULL; | 50 return NULL; |
| 56 } | 51 } |
| 57 | 52 |
| 58 } // namespace bin | 53 |
| 59 } // namespace dart | 54 /* Native entry point for the extension library. */ |
| 55 DART_EXPORT Dart_Handle test_extension_Init(Dart_Handle parent_library) { |
| 56 if (Dart_IsError(parent_library)) { return parent_library; } |
| 57 |
| 58 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); |
| 59 if (Dart_IsError(result_code)) return result_code; |
| 60 |
| 61 return parent_library; |
| 62 } |
| 63 |
| OLD | NEW |