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 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 srand(seed); | 74 srand(seed); |
75 for (int i = 0; i < length; ++i) { | 75 for (int i = 0; i < length; ++i) { |
76 values[i] = rand() % 256; | 76 values[i] = rand() % 256; |
77 } | 77 } |
78 return values; | 78 return values; |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 void wrappedRandomArray(Dart_Port dest_port_id, | 82 void wrappedRandomArray(Dart_Port dest_port_id, |
83 Dart_CObject* message) { | 83 Dart_CObject* message) { |
84 Dart_Port reply_port_id = DART_ILLEGAL_PORT; | 84 Dart_Port reply_port_id = ILLEGAL_PORT; |
85 if (message->type == Dart_CObject_kArray && | 85 if (message->type == Dart_CObject_kArray && |
86 3 == message->value.as_array.length) { | 86 3 == message->value.as_array.length) { |
87 // Use .as_array and .as_int32 to access the data in the Dart_CObject. | 87 // Use .as_array and .as_int32 to access the data in the Dart_CObject. |
88 Dart_CObject* param0 = message->value.as_array.values[0]; | 88 Dart_CObject* param0 = message->value.as_array.values[0]; |
89 Dart_CObject* param1 = message->value.as_array.values[1]; | 89 Dart_CObject* param1 = message->value.as_array.values[1]; |
90 Dart_CObject* param2 = message->value.as_array.values[2]; | 90 Dart_CObject* param2 = message->value.as_array.values[2]; |
91 if (param0->type == Dart_CObject_kInt32 && | 91 if (param0->type == Dart_CObject_kInt32 && |
92 param1->type == Dart_CObject_kInt32 && | 92 param1->type == Dart_CObject_kInt32 && |
93 param2->type == Dart_CObject_kSendPort) { | 93 param2->type == Dart_CObject_kSendPort) { |
94 int seed = param0->value.as_int32; | 94 int seed = param0->value.as_int32; |
(...skipping 19 matching lines...) Expand all Loading... |
114 result.type = Dart_CObject_kNull; | 114 result.type = Dart_CObject_kNull; |
115 Dart_PostCObject(reply_port_id, &result); | 115 Dart_PostCObject(reply_port_id, &result); |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 void randomArrayServicePort(Dart_NativeArguments arguments) { | 119 void randomArrayServicePort(Dart_NativeArguments arguments) { |
120 Dart_EnterScope(); | 120 Dart_EnterScope(); |
121 Dart_SetReturnValue(arguments, Dart_Null()); | 121 Dart_SetReturnValue(arguments, Dart_Null()); |
122 Dart_Port service_port = | 122 Dart_Port service_port = |
123 Dart_NewNativePort("RandomArrayService", wrappedRandomArray, true); | 123 Dart_NewNativePort("RandomArrayService", wrappedRandomArray, true); |
124 if (service_port != DART_ILLEGAL_PORT) { | 124 if (service_port != ILLEGAL_PORT) { |
125 Dart_Handle send_port = HandleError(Dart_NewSendPort(service_port)); | 125 Dart_Handle send_port = HandleError(Dart_NewSendPort(service_port)); |
126 Dart_SetReturnValue(arguments, send_port); | 126 Dart_SetReturnValue(arguments, send_port); |
127 } | 127 } |
128 Dart_ExitScope(); | 128 Dart_ExitScope(); |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 struct FunctionLookup { | 132 struct FunctionLookup { |
133 const char* name; | 133 const char* name; |
134 Dart_NativeFunction function; | 134 Dart_NativeFunction function; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (strcmp(no_scope_function_list[i].name, cname) == 0) { | 179 if (strcmp(no_scope_function_list[i].name, cname) == 0) { |
180 *auto_setup_scope = false; | 180 *auto_setup_scope = false; |
181 result = no_scope_function_list[i].function; | 181 result = no_scope_function_list[i].function; |
182 break; | 182 break; |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 Dart_ExitScope(); | 186 Dart_ExitScope(); |
187 return result; | 187 return result; |
188 } | 188 } |
OLD | NEW |