Index: test/codegen/async_helper.dart |
diff --git a/test/codegen/async_helper.dart b/test/codegen/async_helper.dart |
index 37496bcb76bda9156c55f57b6accd2ec6b35895f..be5014fd6efdb7e09e602a8e9a1f62bb3d66bf34 100644 |
--- a/test/codegen/async_helper.dart |
+++ b/test/codegen/async_helper.dart |
@@ -23,20 +23,29 @@ |
library async_helper; |
-// TODO(kustermann): This is problematic because we rely on a working |
-// 'dart:isolate' (i.e. it is in particular problematic with dart2js). |
-// It would be nice if we could use a different mechanism for different |
-// runtimes. |
-import 'dart:isolate'; |
- |
bool _initialized = false; |
-ReceivePort _port = null; |
+ |
+typedef void _Action0(); |
+_Action0 _onAsyncEnd; |
+ |
int _asyncLevel = 0; |
Exception _buildException(String msg) { |
return new Exception('Fatal: $msg. This is most likely a bug in your test.'); |
} |
+/// Implementation method called from language_tests.js. |
+/// Registers the callback that will be used complete the test. |
+void asyncTestInitialize(_Action0 callback) { |
+ _asyncLevel = 0; |
+ _initialized = false; |
+ _onAsyncEnd = callback; |
+} |
+ |
+/// Implementation method called from language_tests.js. |
+/// Returns true if an asyncTest was started. |
+bool get asyncTestStarted => _initialized; |
+ |
/// Call this method before an asynchronous test is created. |
void asyncStart() { |
if (_initialized && _asyncLevel == 0) { |
@@ -44,9 +53,14 @@ void asyncStart() { |
'with testing.'); |
} |
if (!_initialized) { |
+ if (_onAsyncEnd == null) { |
+ throw _buildException( |
+ 'asyncStart() was called before asyncTestInitialize()'); |
+ } |
+ |
print('unittest-suite-wait-for-done'); |
_initialized = true; |
- _port = new ReceivePort(); |
+ |
} |
_asyncLevel++; |
} |
@@ -63,8 +77,9 @@ void asyncEnd() { |
} |
_asyncLevel--; |
if (_asyncLevel == 0) { |
- _port.close(); |
- _port = null; |
+ var callback = _onAsyncEnd; |
+ _onAsyncEnd = null; |
+ callback(); |
print('unittest-suite-success'); |
} |
} |