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. |
11 // | 11 // |
12 // This mid-size test uses the Dart Embedding Api to create a custom | 12 // This mid-size test uses the Dart Embedding Api to create a custom |
13 // isolate abstraction. Instead of having a dedicated thread for each | 13 // isolate abstraction. Instead of having a dedicated thread for each |
14 // isolate, as is the case normally, this implementation shares a | 14 // isolate, as is the case normally, this implementation shares a |
15 // single thread among the isolates using an event queue. | 15 // single thread among the isolates using an event queue. |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 | 18 |
19 static void native_echo(Dart_NativeArguments args); | 19 static void native_echo(Dart_NativeArguments args); |
20 static void CustomIsolateImpl_start(Dart_NativeArguments args); | 20 static void CustomIsolateImpl_start(Dart_NativeArguments args); |
21 static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc); | 21 static Dart_NativeFunction NativeLookup(Dart_Handle name, |
| 22 int argc, |
| 23 bool* auto_setup_scope); |
22 | 24 |
23 | 25 |
24 static const char* kCustomIsolateScriptChars = | 26 static const char* kCustomIsolateScriptChars = |
25 "import 'dart:isolate';\n" | 27 "import 'dart:isolate';\n" |
26 "\n" | 28 "\n" |
27 "RawReceivePort mainPort;\n" | 29 "RawReceivePort mainPort;\n" |
28 "\n" | 30 "\n" |
29 "echo(arg) native \"native_echo\";\n" | 31 "echo(arg) native \"native_echo\";\n" |
30 "\n" | 32 "\n" |
31 "class CustomIsolateImpl implements CustomIsolate {\n" | 33 "class CustomIsolateImpl implements CustomIsolate {\n" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 224 } |
223 | 225 |
224 | 226 |
225 static void NotifyMessage(Dart_Isolate dest_isolate) { | 227 static void NotifyMessage(Dart_Isolate dest_isolate) { |
226 OS::Print("-- Notify isolate(%p) of pending message --\n", dest_isolate); | 228 OS::Print("-- Notify isolate(%p) of pending message --\n", dest_isolate); |
227 OS::Print("-- Adding MessageEvent to queue --\n"); | 229 OS::Print("-- Adding MessageEvent to queue --\n"); |
228 event_queue->Add(new MessageEvent(dest_isolate)); | 230 event_queue->Add(new MessageEvent(dest_isolate)); |
229 } | 231 } |
230 | 232 |
231 | 233 |
232 static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc) { | 234 static Dart_NativeFunction NativeLookup(Dart_Handle name, |
| 235 int argc, |
| 236 bool* auto_setup_scope) { |
| 237 ASSERT(auto_setup_scope != NULL); |
| 238 *auto_setup_scope = false; |
233 const char* name_str = NULL; | 239 const char* name_str = NULL; |
234 EXPECT(Dart_IsString(name)); | 240 EXPECT(Dart_IsString(name)); |
235 EXPECT_VALID(Dart_StringToCString(name, &name_str)); | 241 EXPECT_VALID(Dart_StringToCString(name, &name_str)); |
236 if (strcmp(name_str, "native_echo") == 0) { | 242 if (strcmp(name_str, "native_echo") == 0) { |
237 return &native_echo; | 243 return &native_echo; |
238 } else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) { | 244 } else if (strcmp(name_str, "CustomIsolateImpl_start") == 0) { |
239 return &CustomIsolateImpl_start; | 245 return &CustomIsolateImpl_start; |
240 } | 246 } |
241 return NULL; | 247 return NULL; |
242 } | 248 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 event = event_queue->Get(); | 339 event = event_queue->Get(); |
334 } | 340 } |
335 OS::Print("-- Finished event loop --\n"); | 341 OS::Print("-- Finished event loop --\n"); |
336 EXPECT_STREQ("Received: 43", saved_echo); | 342 EXPECT_STREQ("Received: 43", saved_echo); |
337 free(const_cast<char*>(saved_echo)); | 343 free(const_cast<char*>(saved_echo)); |
338 | 344 |
339 delete event_queue; | 345 delete event_queue; |
340 } | 346 } |
341 | 347 |
342 } // namespace dart | 348 } // namespace dart |
OLD | NEW |