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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
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 void* peer) { | |
85 Dart_Port reply_port_id = ILLEGAL_PORT; | 84 Dart_Port reply_port_id = ILLEGAL_PORT; |
86 if (message->type == Dart_CObject_kArray && | 85 if (message->type == Dart_CObject_kArray && |
87 3 == message->value.as_array.length) { | 86 3 == message->value.as_array.length) { |
88 // 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. |
89 Dart_CObject* param0 = message->value.as_array.values[0]; | 88 Dart_CObject* param0 = message->value.as_array.values[0]; |
90 Dart_CObject* param1 = message->value.as_array.values[1]; | 89 Dart_CObject* param1 = message->value.as_array.values[1]; |
91 Dart_CObject* param2 = message->value.as_array.values[2]; | 90 Dart_CObject* param2 = message->value.as_array.values[2]; |
92 if (param0->type == Dart_CObject_kInt32 && | 91 if (param0->type == Dart_CObject_kInt32 && |
93 param1->type == Dart_CObject_kInt32 && | 92 param1->type == Dart_CObject_kInt32 && |
94 param2->type == Dart_CObject_kSendPort) { | 93 param2->type == Dart_CObject_kSendPort) { |
(...skipping 19 matching lines...) Expand all Loading... |
114 Dart_CObject result; | 113 Dart_CObject result; |
115 result.type = Dart_CObject_kNull; | 114 result.type = Dart_CObject_kNull; |
116 Dart_PostCObject(reply_port_id, &result); | 115 Dart_PostCObject(reply_port_id, &result); |
117 } | 116 } |
118 | 117 |
119 | 118 |
120 void randomArrayServicePort(Dart_NativeArguments arguments) { | 119 void randomArrayServicePort(Dart_NativeArguments arguments) { |
121 Dart_EnterScope(); | 120 Dart_EnterScope(); |
122 Dart_SetReturnValue(arguments, Dart_Null()); | 121 Dart_SetReturnValue(arguments, Dart_Null()); |
123 Dart_Port service_port = | 122 Dart_Port service_port = |
124 Dart_NewNativePort("RandomArrayService", wrappedRandomArray, true, NULL); | 123 Dart_NewNativePort("RandomArrayService", wrappedRandomArray, true); |
125 if (service_port != ILLEGAL_PORT) { | 124 if (service_port != ILLEGAL_PORT) { |
126 Dart_Handle send_port = HandleError(Dart_NewSendPort(service_port)); | 125 Dart_Handle send_port = HandleError(Dart_NewSendPort(service_port)); |
127 Dart_SetReturnValue(arguments, send_port); | 126 Dart_SetReturnValue(arguments, send_port); |
128 } | 127 } |
129 Dart_ExitScope(); | 128 Dart_ExitScope(); |
130 } | 129 } |
131 | 130 |
132 | 131 |
133 struct FunctionLookup { | 132 struct FunctionLookup { |
134 const char* name; | 133 const char* name; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (strcmp(no_scope_function_list[i].name, cname) == 0) { | 179 if (strcmp(no_scope_function_list[i].name, cname) == 0) { |
181 *auto_setup_scope = false; | 180 *auto_setup_scope = false; |
182 result = no_scope_function_list[i].function; | 181 result = no_scope_function_list[i].function; |
183 break; | 182 break; |
184 } | 183 } |
185 } | 184 } |
186 | 185 |
187 Dart_ExitScope(); | 186 Dart_ExitScope(); |
188 return result; | 187 return result; |
189 } | 188 } |
OLD | NEW |