OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_native_api.h" | 6 #include "include/dart_native_api.h" |
7 | 7 |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 | 9 |
10 // Custom Isolate Test. | 10 // Custom Isolate Test. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 EXPECT_VALID(Dart_StringToCString(name, &name_str)); | 236 EXPECT_VALID(Dart_StringToCString(name, &name_str)); |
237 if (strcmp(name_str, "native_echo") == 0) { | 237 if (strcmp(name_str, "native_echo") == 0) { |
238 return &native_echo; | 238 return &native_echo; |
239 } else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) { | 239 } else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) { |
240 return &CustomIsolateImpl_start; | 240 return &CustomIsolateImpl_start; |
241 } | 241 } |
242 return NULL; | 242 return NULL; |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 const char* saved_echo = NULL; | 246 char* saved_echo = NULL; |
247 static void native_echo(Dart_NativeArguments args) { | 247 static void native_echo(Dart_NativeArguments args) { |
248 Dart_EnterScope(); | 248 Dart_EnterScope(); |
249 Dart_Handle arg = Dart_GetNativeArgument(args, 0); | 249 Dart_Handle arg = Dart_GetNativeArgument(args, 0); |
250 Dart_Handle toString = Dart_ToString(arg); | 250 Dart_Handle toString = Dart_ToString(arg); |
251 EXPECT_VALID(toString); | 251 EXPECT_VALID(toString); |
252 const char* c_str = NULL; | 252 const char* c_str = NULL; |
253 EXPECT_VALID(Dart_StringToCString(toString, &c_str)); | 253 EXPECT_VALID(Dart_StringToCString(toString, &c_str)); |
254 if (saved_echo) { | 254 if (saved_echo) { |
255 free(const_cast<char*>(saved_echo)); | 255 free(saved_echo); |
256 } | 256 } |
257 saved_echo = strdup(c_str); | 257 saved_echo = strdup(c_str); |
258 OS::Print("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str); | 258 OS::Print("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str); |
259 Dart_ExitScope(); | 259 Dart_ExitScope(); |
260 } | 260 } |
261 | 261 |
262 | 262 |
263 static void CustomIsolateImpl_start(Dart_NativeArguments args) { | 263 static void CustomIsolateImpl_start(Dart_NativeArguments args) { |
264 OS::Print("-- Enter: CustomIsolateImpl_start --\n"); | 264 OS::Print("-- Enter: CustomIsolateImpl_start --\n"); |
265 | 265 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 343 |
344 OS::Print("-- Starting event loop --\n"); | 344 OS::Print("-- Starting event loop --\n"); |
345 Event* event = event_queue->Get(); | 345 Event* event = event_queue->Get(); |
346 while (event) { | 346 while (event) { |
347 event->Process(); | 347 event->Process(); |
348 delete event; | 348 delete event; |
349 event = event_queue->Get(); | 349 event = event_queue->Get(); |
350 } | 350 } |
351 OS::Print("-- Finished event loop --\n"); | 351 OS::Print("-- Finished event loop --\n"); |
352 EXPECT_STREQ("Received: 43", saved_echo); | 352 EXPECT_STREQ("Received: 43", saved_echo); |
353 free(const_cast<char*>(saved_echo)); | 353 free(saved_echo); |
354 | 354 |
355 delete event_queue; | 355 delete event_queue; |
356 event_queue = NULL; | 356 event_queue = NULL; |
357 } | 357 } |
358 | 358 |
359 } // namespace dart | 359 } // namespace dart |
OLD | NEW |