OLD | NEW |
1 dart_library.library('async_helper', null, /* Imports */[ | 1 dart_library.library('async_helper', null, /* Imports */[ |
2 'dart/_runtime', | 2 'dart_sdk' |
3 'dart/core' | 3 ], function(exports, dart_sdk) { |
4 ], /* Lazy imports */[ | |
5 ], function(exports, dart, core) { | |
6 'use strict'; | 4 'use strict'; |
7 let dartx = dart.dartx; | 5 const core = dart_sdk.core; |
8 exports._initialized = false; | 6 const dart = dart_sdk.dart; |
9 const _Action0 = dart.typedef('_Action0', () => dart.functionType(dart.void, [
])); | 7 const dartx = dart_sdk.dartx; |
10 exports._onAsyncEnd = null; | 8 const async_helper = Object.create(null); |
11 exports._asyncLevel = 0; | 9 async_helper._initialized = false; |
12 function _buildException(msg) { | 10 async_helper._Action0 = dart.typedef('_Action0', () => dart.functionType(dart.
void, [])); |
| 11 async_helper._onAsyncEnd = null; |
| 12 async_helper._asyncLevel = 0; |
| 13 async_helper._buildException = function(msg) { |
13 return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your
test.`); | 14 return core.Exception.new(`Fatal: ${msg}. This is most likely a bug in your
test.`); |
14 } | 15 }; |
15 dart.fn(_buildException, core.Exception, [core.String]); | 16 dart.fn(async_helper._buildException, core.Exception, [core.String]); |
16 function asyncTestInitialize(callback) { | 17 async_helper.asyncTestInitialize = function(callback) { |
17 exports._asyncLevel = 0; | 18 async_helper._asyncLevel = 0; |
18 exports._initialized = false; | 19 async_helper._initialized = false; |
19 exports._onAsyncEnd = callback; | 20 async_helper._onAsyncEnd = callback; |
20 } | 21 }; |
21 dart.fn(asyncTestInitialize, dart.void, [_Action0]); | 22 dart.fn(async_helper.asyncTestInitialize, dart.void, [async_helper._Action0]); |
22 dart.copyProperties(exports, { | 23 dart.copyProperties(async_helper, { |
23 get asyncTestStarted() { | 24 get asyncTestStarted() { |
24 return exports._initialized; | 25 return async_helper._initialized; |
25 } | 26 } |
26 }); | 27 }); |
27 function asyncStart() { | 28 async_helper.asyncStart = function() { |
28 if (dart.notNull(exports._initialized) && exports._asyncLevel == 0) { | 29 if (dart.notNull(async_helper._initialized) && async_helper._asyncLevel == 0
) { |
29 dart.throw(_buildException('asyncStart() was called even though we are don
e ' + 'with testing.')); | 30 dart.throw(async_helper._buildException('asyncStart() was called even thou
gh we are done ' + 'with testing.')); |
30 } | 31 } |
31 if (!dart.notNull(exports._initialized)) { | 32 if (!dart.notNull(async_helper._initialized)) { |
32 if (exports._onAsyncEnd == null) { | 33 if (async_helper._onAsyncEnd == null) { |
33 dart.throw(_buildException('asyncStart() was called before asyncTestInit
ialize()')); | 34 dart.throw(async_helper._buildException('asyncStart() was called before
asyncTestInitialize()')); |
34 } | 35 } |
35 core.print('unittest-suite-wait-for-done'); | 36 core.print('unittest-suite-wait-for-done'); |
36 exports._initialized = true; | 37 async_helper._initialized = true; |
37 } | 38 } |
38 exports._asyncLevel = dart.notNull(exports._asyncLevel) + 1; | 39 async_helper._asyncLevel = dart.notNull(async_helper._asyncLevel) + 1; |
39 } | 40 }; |
40 dart.fn(asyncStart, dart.void, []); | 41 dart.fn(async_helper.asyncStart, dart.void, []); |
41 function asyncEnd() { | 42 async_helper.asyncEnd = function() { |
42 if (dart.notNull(exports._asyncLevel) <= 0) { | 43 if (dart.notNull(async_helper._asyncLevel) <= 0) { |
43 if (!dart.notNull(exports._initialized)) { | 44 if (!dart.notNull(async_helper._initialized)) { |
44 dart.throw(_buildException('asyncEnd() was called before asyncStart().')
); | 45 dart.throw(async_helper._buildException('asyncEnd() was called before as
yncStart().')); |
45 } else { | 46 } else { |
46 dart.throw(_buildException('asyncEnd() was called more often than ' + 'a
syncStart().')); | 47 dart.throw(async_helper._buildException('asyncEnd() was called more ofte
n than ' + 'asyncStart().')); |
47 } | 48 } |
48 } | 49 } |
49 exports._asyncLevel = dart.notNull(exports._asyncLevel) - 1; | 50 async_helper._asyncLevel = dart.notNull(async_helper._asyncLevel) - 1; |
50 if (exports._asyncLevel == 0) { | 51 if (async_helper._asyncLevel == 0) { |
51 let callback = exports._onAsyncEnd; | 52 let callback = async_helper._onAsyncEnd; |
52 exports._onAsyncEnd = null; | 53 async_helper._onAsyncEnd = null; |
53 callback(); | 54 callback(); |
54 core.print('unittest-suite-success'); | 55 core.print('unittest-suite-success'); |
55 } | 56 } |
56 } | 57 }; |
57 dart.fn(asyncEnd, dart.void, []); | 58 dart.fn(async_helper.asyncEnd, dart.void, []); |
58 function asyncSuccess(_) { | 59 async_helper.asyncSuccess = function(_) { |
59 return asyncEnd(); | 60 return async_helper.asyncEnd(); |
60 } | 61 }; |
61 dart.fn(asyncSuccess, dart.void, [dart.dynamic]); | 62 dart.fn(async_helper.asyncSuccess, dart.void, [dart.dynamic]); |
62 function asyncTest(f) { | 63 async_helper.asyncTest = function(f) { |
63 asyncStart(); | 64 async_helper.asyncStart(); |
64 dart.dsend(f(), 'then', asyncSuccess); | 65 dart.dsend(f(), 'then', async_helper.asyncSuccess); |
65 } | 66 }; |
66 dart.fn(asyncTest, dart.void, [dart.functionType(dart.dynamic, [])]); | 67 dart.fn(async_helper.asyncTest, dart.void, [dart.functionType(dart.dynamic, []
)]); |
67 // Exports: | 68 // Exports: |
68 exports.asyncTestInitialize = asyncTestInitialize; | 69 exports.async_helper = async_helper; |
69 exports.asyncStart = asyncStart; | |
70 exports.asyncEnd = asyncEnd; | |
71 exports.asyncSuccess = asyncSuccess; | |
72 exports.asyncTest = asyncTest; | |
73 }); | 70 }); |
OLD | NEW |