OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 #include <string.h> | |
5 | |
6 #include "include/dart_api.h" | |
7 | |
8 | |
9 namespace dart { | |
10 namespace bin { | |
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 | |
23 | |
24 void IfNull(Dart_NativeArguments arguments) { | |
25 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | |
26 if (Dart_IsNull(object)) { | |
27 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); | |
28 } else { | |
29 Dart_SetReturnValue(arguments, object); | |
30 } | |
31 } | |
32 | |
33 | |
34 void ThrowMeTheBall(Dart_NativeArguments arguments) { | |
35 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | |
36 Dart_ThrowException(object); | |
37 } | |
38 | |
39 | |
40 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | |
41 assert(Dart_IsString(name)); | |
42 const char* cname; | |
43 Dart_Handle check_error; | |
44 | |
45 check_error = Dart_StringToCString(name, &cname); | |
46 if (Dart_IsError(check_error)) { | |
47 Dart_PropagateError(check_error); | |
48 } | |
49 if ((strcmp("TestExtension_IfNull", cname) == 0) && (argc == 2)) { | |
50 return IfNull; | |
51 } | |
52 if ((strcmp("TestExtension_ThrowMeTheBall", cname) == 0) && (argc == 1)) { | |
53 return ThrowMeTheBall; | |
54 } | |
55 return NULL; | |
56 } | |
57 | |
58 } // namespace bin | |
59 } // namespace dart | |
OLD | NEW |