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 <string.h> | 4 #include <string.h> |
6 | 5 |
7 #include "../include/dart_api.h" | 6 #include "include/dart_api.h" |
8 | 7 |
9 #define EXPORT_SYMBOL __attribute__ ((visibility ("default"))) | 8 Dart_NativeFunction ResolveName(Dart_Handle name, int argc); |
10 | 9 |
11 extern "C" Dart_NativeFunction ResolveName(Dart_Handle name, int argc); | 10 DART_EXPORT Dart_Handle test_extension_Init(Dart_Handle parent_library) { |
| 11 if (Dart_IsError(parent_library)) { return parent_library; } |
12 | 12 |
13 extern "C" EXPORT_SYMBOL Dart_Handle test_extension_Init(Dart_Handle library) { | 13 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); |
14 if (Dart_IsError(library)) return library; | 14 if (Dart_IsError(result_code)) return result_code; |
15 Dart_Handle check_return = Dart_SetNativeResolver(library, ResolveName); | 15 |
16 if (Dart_IsError(check_return)) return check_return; | 16 return parent_library; |
17 return Dart_Null(); | |
18 } | 17 } |
19 | 18 |
20 extern "C" void IfNull(Dart_NativeArguments arguments) { | 19 void IfNull(Dart_NativeArguments arguments) { |
21 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | 20 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); |
22 if (Dart_IsNull(object)) { | 21 if (Dart_IsNull(object)) { |
23 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); | 22 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); |
24 } else { | 23 } else { |
25 Dart_SetReturnValue(arguments, object); | 24 Dart_SetReturnValue(arguments, object); |
26 } | 25 } |
27 } | 26 } |
28 | 27 |
29 extern "C" Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | 28 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { |
30 assert(Dart_IsString8(name)); | 29 assert(Dart_IsString8(name)); |
31 const char* cname; | 30 const char* cname; |
32 Dart_Handle check_error; | 31 Dart_Handle check_error; |
33 | 32 |
34 check_error = Dart_StringToCString(name, &cname); | 33 check_error = Dart_StringToCString(name, &cname); |
35 if (Dart_IsError(check_error)) { | 34 if (Dart_IsError(check_error)) { |
36 Dart_PropagateError(check_error); | 35 Dart_PropagateError(check_error); |
37 } | 36 } |
38 if (!strcmp("Cat_IfNull", cname) && argc == 2) { | 37 if (!strcmp("TestExtension_IfNull", cname) && argc == 2) { |
39 return IfNull; | 38 return IfNull; |
40 } | 39 } |
41 return NULL; | 40 return NULL; |
42 } | 41 } |
OLD | NEW |