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