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 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 6225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6236 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 6236 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
6237 | 6237 |
6238 Dart_ExitScope(); | 6238 Dart_ExitScope(); |
6239 | 6239 |
6240 // Delete the native ports. | 6240 // Delete the native ports. |
6241 EXPECT(Dart_CloseNativePort(port_id1)); | 6241 EXPECT(Dart_CloseNativePort(port_id1)); |
6242 EXPECT(Dart_CloseNativePort(port_id2)); | 6242 EXPECT(Dart_CloseNativePort(port_id2)); |
6243 } | 6243 } |
6244 | 6244 |
6245 | 6245 |
6246 static bool RunLoopTestCallback(const char* script_name, | 6246 static Dart_Isolate RunLoopTestCallback(const char* script_name, |
6247 const char* main, | 6247 const char* main, |
6248 void* data, | 6248 void* data, |
6249 char** error) { | 6249 char** error) { |
6250 const char* kScriptChars = | 6250 const char* kScriptChars = |
6251 "import 'builtin';\n" | 6251 "import 'builtin';\n" |
6252 "import 'dart:isolate';\n" | 6252 "import 'dart:isolate';\n" |
6253 "void entry() {\n" | 6253 "void entry() {\n" |
6254 " port.receive((message, replyTo) {\n" | 6254 " port.receive((message, replyTo) {\n" |
6255 " if (message) {\n" | 6255 " if (message) {\n" |
6256 " throw new Exception('MakeChildExit');\n" | 6256 " throw new Exception('MakeChildExit');\n" |
6257 " } else {\n" | 6257 " } else {\n" |
6258 " replyTo.call('hello');\n" | 6258 " replyTo.call('hello');\n" |
6259 " port.close();\n" | 6259 " port.close();\n" |
(...skipping 15 matching lines...) Expand all Loading... |
6275 Dart_Isolate isolate = TestCase::CreateTestIsolate(); | 6275 Dart_Isolate isolate = TestCase::CreateTestIsolate(); |
6276 ASSERT(isolate != NULL); | 6276 ASSERT(isolate != NULL); |
6277 Dart_EnterScope(); | 6277 Dart_EnterScope(); |
6278 Dart_Handle url = NewString(TestCase::url()); | 6278 Dart_Handle url = NewString(TestCase::url()); |
6279 Dart_Handle source = NewString(kScriptChars); | 6279 Dart_Handle source = NewString(kScriptChars); |
6280 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 6280 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
6281 EXPECT_VALID(result); | 6281 EXPECT_VALID(result); |
6282 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 6282 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); |
6283 EXPECT_VALID(lib); | 6283 EXPECT_VALID(lib); |
6284 Dart_ExitScope(); | 6284 Dart_ExitScope(); |
6285 return true; | 6285 Dart_ExitIsolate(); |
| 6286 bool retval = Dart_IsolateMakeRunnable(isolate); |
| 6287 EXPECT(retval); |
| 6288 return isolate; |
6286 } | 6289 } |
6287 | 6290 |
6288 | 6291 |
6289 // The error string from the last unhandled exception. This value is only | 6292 // The error string from the last unhandled exception. This value is only |
6290 // valid until the next Dart_ExitScope(). | 6293 // valid until the next Dart_ExitScope(). |
6291 static char* last_exception = NULL; | 6294 static char* last_exception = NULL; |
6292 | 6295 |
6293 | 6296 |
6294 static void RunLoopUnhandledExceptionCallback(Dart_Handle exception) { | 6297 static void RunLoopUnhandledExceptionCallback(Dart_Handle exception) { |
6295 Dart_Handle error_string = Dart_ToString(exception); | 6298 Dart_Handle error_string = Dart_ToString(exception); |
6296 EXPECT_VALID(error_string); | 6299 EXPECT_VALID(error_string); |
6297 const char* error_text; | 6300 const char* error_text; |
6298 Dart_Handle result = Dart_StringToCString(error_string, &error_text); | 6301 Dart_Handle result = Dart_StringToCString(error_string, &error_text); |
6299 // Duplicate the string since error text is freed when callback is finished. | 6302 // Duplicate the string since error text is freed when callback is finished. |
6300 last_exception = strdup(error_text); | 6303 last_exception = strdup(error_text); |
6301 EXPECT_VALID(result); | 6304 EXPECT_VALID(result); |
6302 } | 6305 } |
6303 | 6306 |
6304 | 6307 |
6305 // Common code for RunLoop_Success/RunLoop_Failure. | 6308 // Common code for RunLoop_Success/RunLoop_Failure. |
6306 static void RunLoopTest(bool throw_exception_child, | 6309 static void RunLoopTest(bool throw_exception_child, |
6307 bool throw_exception_parent) { | 6310 bool throw_exception_parent) { |
6308 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 6311 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
6309 Isolate::SetCreateCallback(RunLoopTestCallback); | 6312 Isolate::SetCreateCallback(RunLoopTestCallback); |
6310 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback); | 6313 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback); |
6311 RunLoopTestCallback(NULL, NULL, NULL, NULL); | 6314 Dart_Isolate isolate = RunLoopTestCallback(NULL, NULL, NULL, NULL); |
6312 | 6315 |
| 6316 Dart_EnterIsolate(isolate); |
6313 Dart_EnterScope(); | 6317 Dart_EnterScope(); |
6314 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 6318 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
6315 EXPECT_VALID(lib); | 6319 EXPECT_VALID(lib); |
6316 | 6320 |
6317 Dart_Handle result; | 6321 Dart_Handle result; |
6318 Dart_Handle args[2]; | 6322 Dart_Handle args[2]; |
6319 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); | 6323 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); |
6320 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); | 6324 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); |
6321 result = Dart_Invoke(lib, NewString("main"), 2, args); | 6325 result = Dart_Invoke(lib, NewString("main"), 2, args); |
6322 EXPECT_VALID(result); | 6326 EXPECT_VALID(result); |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7539 NULL); | 7543 NULL); |
7540 int64_t value = 0; | 7544 int64_t value = 0; |
7541 result = Dart_IntegerToInt64(result, &value); | 7545 result = Dart_IntegerToInt64(result, &value); |
7542 EXPECT_VALID(result); | 7546 EXPECT_VALID(result); |
7543 EXPECT_EQ(260, value); | 7547 EXPECT_EQ(260, value); |
7544 } | 7548 } |
7545 | 7549 |
7546 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7550 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7547 | 7551 |
7548 } // namespace dart | 7552 } // namespace dart |
OLD | NEW |