| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 StartEvent(Dart_Isolate isolate, const char* main) | 159 StartEvent(Dart_Isolate isolate, const char* main) |
| 160 : Event(isolate), main_(main) {} | 160 : Event(isolate), main_(main) {} |
| 161 | 161 |
| 162 virtual void Process(); | 162 virtual void Process(); |
| 163 private: | 163 private: |
| 164 const char* main_; | 164 const char* main_; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 | 167 |
| 168 void StartEvent::Process() { | 168 void StartEvent::Process() { |
| 169 OS::Print(">> StartEvent with isolate(%" PRId64 ")--\n", isolate()); | 169 OS::Print(">> StartEvent with isolate(%p)--\n", isolate()); |
| 170 Dart_EnterIsolate(isolate()); | 170 Dart_EnterIsolate(isolate()); |
| 171 Dart_EnterScope(); | 171 Dart_EnterScope(); |
| 172 Dart_Handle result; | 172 Dart_Handle result; |
| 173 | 173 |
| 174 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 174 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
| 175 EXPECT_VALID(lib); | 175 EXPECT_VALID(lib); |
| 176 | 176 |
| 177 result = Dart_Invoke(lib, NewString(main_), 0, NULL); | 177 result = Dart_Invoke(lib, NewString(main_), 0, NULL); |
| 178 EXPECT_VALID(result); | 178 EXPECT_VALID(result); |
| 179 free(const_cast<char*>(main_)); | 179 free(const_cast<char*>(main_)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 190 explicit MessageEvent(Dart_Isolate isolate) : Event(isolate) {} | 190 explicit MessageEvent(Dart_Isolate isolate) : Event(isolate) {} |
| 191 | 191 |
| 192 ~MessageEvent() { | 192 ~MessageEvent() { |
| 193 } | 193 } |
| 194 | 194 |
| 195 virtual void Process(); | 195 virtual void Process(); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 | 198 |
| 199 void MessageEvent::Process() { | 199 void MessageEvent::Process() { |
| 200 OS::Print("$$ MessageEvent with isolate(%" PRId64 ")\n", isolate()); | 200 OS::Print("$$ MessageEvent with isolate(%p)\n", isolate()); |
| 201 Dart_EnterIsolate(isolate()); | 201 Dart_EnterIsolate(isolate()); |
| 202 Dart_EnterScope(); | 202 Dart_EnterScope(); |
| 203 | 203 |
| 204 Dart_Handle result = Dart_HandleMessage(); | 204 Dart_Handle result = Dart_HandleMessage(); |
| 205 EXPECT_VALID(result); | 205 EXPECT_VALID(result); |
| 206 | 206 |
| 207 if (!Dart_HasLivePorts()) { | 207 if (!Dart_HasLivePorts()) { |
| 208 OS::Print("<< Shutting down isolate(%" PRId64 ")\n", isolate()); | 208 OS::Print("<< Shutting down isolate(%p)\n", isolate()); |
| 209 event_queue->RemoveEventsForIsolate(isolate()); | 209 event_queue->RemoveEventsForIsolate(isolate()); |
| 210 Dart_ShutdownIsolate(); | 210 Dart_ShutdownIsolate(); |
| 211 } else { | 211 } else { |
| 212 Dart_ExitScope(); | 212 Dart_ExitScope(); |
| 213 Dart_ExitIsolate(); | 213 Dart_ExitIsolate(); |
| 214 } | 214 } |
| 215 ASSERT(Dart_CurrentIsolate() == DART_ILLEGAL_ISOLATE); | 215 ASSERT(Dart_CurrentIsolate() == NULL); |
| 216 } | 216 } |
| 217 | 217 |
| 218 | 218 |
| 219 static void NotifyMessage(Dart_Isolate dest_isolate) { | 219 static void NotifyMessage(Dart_Isolate dest_isolate) { |
| 220 OS::Print("-- Notify isolate(%" PRId64 ") of pending message --\n", | 220 OS::Print("-- Notify isolate(%p) of pending message --\n", dest_isolate); |
| 221 dest_isolate); | |
| 222 OS::Print("-- Adding MessageEvent to queue --\n"); | 221 OS::Print("-- Adding MessageEvent to queue --\n"); |
| 223 event_queue->Add(new MessageEvent(dest_isolate)); | 222 event_queue->Add(new MessageEvent(dest_isolate)); |
| 224 } | 223 } |
| 225 | 224 |
| 226 | 225 |
| 227 static Dart_NativeFunction NativeLookup(Dart_Handle name, | 226 static Dart_NativeFunction NativeLookup(Dart_Handle name, |
| 228 int argc, | 227 int argc, |
| 229 bool* auto_setup_scope) { | 228 bool* auto_setup_scope) { |
| 230 ASSERT(auto_setup_scope != NULL); | 229 ASSERT(auto_setup_scope != NULL); |
| 231 *auto_setup_scope = false; | 230 *auto_setup_scope = false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 246 Dart_EnterScope(); | 245 Dart_EnterScope(); |
| 247 Dart_Handle arg = Dart_GetNativeArgument(args, 0); | 246 Dart_Handle arg = Dart_GetNativeArgument(args, 0); |
| 248 Dart_Handle toString = Dart_ToString(arg); | 247 Dart_Handle toString = Dart_ToString(arg); |
| 249 EXPECT_VALID(toString); | 248 EXPECT_VALID(toString); |
| 250 const char* c_str = NULL; | 249 const char* c_str = NULL; |
| 251 EXPECT_VALID(Dart_StringToCString(toString, &c_str)); | 250 EXPECT_VALID(Dart_StringToCString(toString, &c_str)); |
| 252 if (saved_echo) { | 251 if (saved_echo) { |
| 253 free(const_cast<char*>(saved_echo)); | 252 free(const_cast<char*>(saved_echo)); |
| 254 } | 253 } |
| 255 saved_echo = strdup(c_str); | 254 saved_echo = strdup(c_str); |
| 256 OS::Print("-- (isolate=%" PRId64 ") %s\n", Dart_CurrentIsolate(), c_str); | 255 OS::Print("-- (isolate=%p) %s\n", Dart_CurrentIsolate(), c_str); |
| 257 Dart_ExitScope(); | 256 Dart_ExitScope(); |
| 258 } | 257 } |
| 259 | 258 |
| 260 | 259 |
| 261 static void CustomIsolateImpl_start(Dart_NativeArguments args) { | 260 static void CustomIsolateImpl_start(Dart_NativeArguments args) { |
| 262 OS::Print("-- Enter: CustomIsolateImpl_start --\n"); | 261 OS::Print("-- Enter: CustomIsolateImpl_start --\n"); |
| 263 | 262 |
| 264 // We would probably want to pass in the this pointer too, so we | 263 // We would probably want to pass in the this pointer too, so we |
| 265 // could associate the CustomIsolateImpl instance with the | 264 // could associate the CustomIsolateImpl instance with the |
| 266 // Dart_Isolate by storing it in a native field. | 265 // Dart_Isolate by storing it in a native field. |
| 267 EXPECT_EQ(1, Dart_GetNativeArgumentCount(args)); | 266 EXPECT_EQ(1, Dart_GetNativeArgumentCount(args)); |
| 268 Dart_Handle param = Dart_GetNativeArgument(args, 0); | 267 Dart_Handle param = Dart_GetNativeArgument(args, 0); |
| 269 EXPECT_VALID(param); | 268 EXPECT_VALID(param); |
| 270 EXPECT(Dart_IsString(param)); | 269 EXPECT(Dart_IsString(param)); |
| 271 const char* isolate_main = NULL; | 270 const char* isolate_main = NULL; |
| 272 EXPECT_VALID(Dart_StringToCString(param, &isolate_main)); | 271 EXPECT_VALID(Dart_StringToCString(param, &isolate_main)); |
| 273 isolate_main = strdup(isolate_main); | 272 isolate_main = strdup(isolate_main); |
| 274 | 273 |
| 275 // Save current isolate. | 274 // Save current isolate. |
| 276 Dart_Isolate saved_isolate = Dart_CurrentIsolate(); | 275 Dart_Isolate saved_isolate = Dart_CurrentIsolate(); |
| 277 Dart_ExitIsolate(); | 276 Dart_ExitIsolate(); |
| 278 | 277 |
| 279 // Create a new Dart_Isolate. | 278 // Create a new Dart_Isolate. |
| 280 Dart_Isolate new_isolate = TestCase::CreateTestIsolate(); | 279 Dart_Isolate new_isolate = TestCase::CreateTestIsolate(); |
| 281 EXPECT(new_isolate != DART_ILLEGAL_ISOLATE); | 280 EXPECT(new_isolate != NULL); |
| 282 Dart_SetMessageNotifyCallback(&NotifyMessage); | 281 Dart_SetMessageNotifyCallback(&NotifyMessage); |
| 283 Dart_EnterScope(); | 282 Dart_EnterScope(); |
| 284 // Reload all the test classes here. | 283 // Reload all the test classes here. |
| 285 // | 284 // |
| 286 // TODO(turnidge): Use the create isolate callback instead? | 285 // TODO(turnidge): Use the create isolate callback instead? |
| 287 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, | 286 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, |
| 288 NativeLookup); | 287 NativeLookup); |
| 289 EXPECT_VALID(lib); | 288 EXPECT_VALID(lib); |
| 290 | 289 |
| 291 Dart_Handle main_send_port = Dart_GetField(lib, NewString("mainSendPort")); | 290 Dart_Handle main_send_port = Dart_GetField(lib, NewString("mainSendPort")); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 309 | 308 |
| 310 OS::Print("-- Exit: CustomIsolateImpl_start --\n"); | 309 OS::Print("-- Exit: CustomIsolateImpl_start --\n"); |
| 311 Dart_ExitScope(); | 310 Dart_ExitScope(); |
| 312 } | 311 } |
| 313 | 312 |
| 314 | 313 |
| 315 UNIT_TEST_CASE(CustomIsolates) { | 314 UNIT_TEST_CASE(CustomIsolates) { |
| 316 event_queue = new EventQueue(); | 315 event_queue = new EventQueue(); |
| 317 | 316 |
| 318 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); | 317 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); |
| 319 EXPECT(dart_isolate != DART_ILLEGAL_ISOLATE); | 318 EXPECT(dart_isolate != NULL); |
| 320 Dart_SetMessageNotifyCallback(&NotifyMessage); | 319 Dart_SetMessageNotifyCallback(&NotifyMessage); |
| 321 Dart_EnterScope(); | 320 Dart_EnterScope(); |
| 322 Dart_Handle result; | 321 Dart_Handle result; |
| 323 | 322 |
| 324 // Create a test library. | 323 // Create a test library. |
| 325 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, | 324 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, |
| 326 NativeLookup); | 325 NativeLookup); |
| 327 EXPECT_VALID(lib); | 326 EXPECT_VALID(lib); |
| 328 | 327 |
| 329 // Run main. | 328 // Run main. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 345 event = event_queue->Get(); | 344 event = event_queue->Get(); |
| 346 } | 345 } |
| 347 OS::Print("-- Finished event loop --\n"); | 346 OS::Print("-- Finished event loop --\n"); |
| 348 EXPECT_STREQ("Received: 43", saved_echo); | 347 EXPECT_STREQ("Received: 43", saved_echo); |
| 349 free(const_cast<char*>(saved_echo)); | 348 free(const_cast<char*>(saved_echo)); |
| 350 | 349 |
| 351 delete event_queue; | 350 delete event_queue; |
| 352 } | 351 } |
| 353 | 352 |
| 354 } // namespace dart | 353 } // namespace dart |
| OLD | NEW |