Chromium Code Reviews| 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 | 5 |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 | 7 |
| 8 Dart_NativeFunction ResolveName(Dart_Handle name, int argc); | 8 Dart_NativeFunction ResolveName(Dart_Handle name, int argc); |
| 9 | 9 |
| 10 DART_EXPORT Dart_Handle test_extension_Init(Dart_Handle parent_library) { | 10 DART_EXPORT Dart_Handle test_extension_Init(Dart_Handle parent_library) { |
| 11 if (Dart_IsError(parent_library)) { return parent_library; } | 11 if (Dart_IsError(parent_library)) { return parent_library; } |
| 12 | 12 |
| 13 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); | 13 Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName); |
| 14 if (Dart_IsError(result_code)) return result_code; | 14 if (Dart_IsError(result_code)) return result_code; |
| 15 | 15 |
| 16 return parent_library; | 16 return parent_library; |
| 17 } | 17 } |
| 18 | 18 |
| 19 | |
| 19 void IfNull(Dart_NativeArguments arguments) { | 20 void IfNull(Dart_NativeArguments arguments) { |
| 20 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | 21 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); |
| 21 if (Dart_IsNull(object)) { | 22 if (Dart_IsNull(object)) { |
| 22 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); | 23 Dart_SetReturnValue(arguments, Dart_GetNativeArgument(arguments, 1)); |
| 23 } else { | 24 } else { |
| 24 Dart_SetReturnValue(arguments, object); | 25 Dart_SetReturnValue(arguments, object); |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 | 28 |
| 29 | |
| 30 void ThrowMeTheBall(Dart_NativeArguments arguments) { | |
| 31 Dart_Handle object = Dart_GetNativeArgument(arguments, 0); | |
| 32 Dart_ThrowException(object); | |
| 33 } | |
| 34 | |
|
Bill Hesse
2012/12/05 12:26:07
two lines between functions
Ivan Posva
2012/12/05 13:01:29
Done.
| |
| 28 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { | 35 Dart_NativeFunction ResolveName(Dart_Handle name, int argc) { |
| 29 assert(Dart_IsString(name)); | 36 assert(Dart_IsString(name)); |
| 30 const char* cname; | 37 const char* cname; |
| 31 Dart_Handle check_error; | 38 Dart_Handle check_error; |
| 32 | 39 |
| 33 check_error = Dart_StringToCString(name, &cname); | 40 check_error = Dart_StringToCString(name, &cname); |
| 34 if (Dart_IsError(check_error)) { | 41 if (Dart_IsError(check_error)) { |
| 35 Dart_PropagateError(check_error); | 42 Dart_PropagateError(check_error); |
| 36 } | 43 } |
| 37 if (!strcmp("TestExtension_IfNull", cname) && argc == 2) { | 44 if (!strcmp("TestExtension_IfNull", cname) && argc == 2) { |
| 38 return IfNull; | 45 return IfNull; |
| 39 } | 46 } |
| 47 if ((strcmp("TestExtension_ThrowMeTheBall", cname) == 0) && argc == 1) { | |
|
Bill Hesse
2012/12/05 12:26:07
We use !strcmp above. Make the two consistent, ei
Ivan Posva
2012/12/05 13:01:29
strcmp does not return a bool. Changed the code ab
| |
| 48 return ThrowMeTheBall; | |
| 49 } | |
| 40 return NULL; | 50 return NULL; |
| 41 } | 51 } |
| OLD | NEW |