Files
sdk/pkg/dev_compiler/test/codegen_expected/async_helper.js
T
Jacob Richman 1f38879094 Inline source maps as part of each script.
Unfortunately this is required as even with ideal caching, performing
XHRs to load all source maps increased load times by ~5 seconds for large
applications. Performance hit is now minimal.

BUG=

Review-Url: https://codereview.chromium.org/2747513003 .
Review-Url: https://codereview.chromium.org/2746033003 .
2017-03-13 10:46:02 -07:00

78 lines
3.4 KiB
JavaScript

define(['dart_sdk'], function(dart_sdk) {
'use strict';
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const async_helper = Object.create(null);
let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.functionType(dart.dynamic, [])))();
let StringToException = () => (StringToException = dart.constFn(dart.definiteFunctionType(core.Exception, [core.String])))();
let _Action0Tovoid = () => (_Action0Tovoid = dart.constFn(dart.definiteFunctionType(dart.void, [async_helper._Action0])))();
let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [])))();
let dynamicTovoid = () => (dynamicTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [dart.dynamic])))();
let FnTovoid = () => (FnTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [VoidTodynamic()])))();
async_helper._initialized = false;
async_helper._Action0 = dart.typedef('_Action0', () => dart.functionType(dart.void, []));
async_helper._onAsyncEnd = null;
async_helper._asyncLevel = 0;
async_helper._buildException = function(msg) {
return core.Exception.new(dart.str`Fatal: ${msg}. This is most likely a bug in your test.`);
};
dart.fn(async_helper._buildException, StringToException());
async_helper.asyncTestInitialize = function(callback) {
async_helper._asyncLevel = 0;
async_helper._initialized = false;
async_helper._onAsyncEnd = callback;
};
dart.fn(async_helper.asyncTestInitialize, _Action0Tovoid());
dart.copyProperties(async_helper, {
get asyncTestStarted() {
return async_helper._initialized;
}
});
async_helper.asyncStart = function() {
if (dart.test(async_helper._initialized) && async_helper._asyncLevel == 0) {
dart.throw(async_helper._buildException('asyncStart() was called even though we are done ' + 'with testing.'));
}
if (!dart.test(async_helper._initialized)) {
if (async_helper._onAsyncEnd == null) {
dart.throw(async_helper._buildException('asyncStart() was called before asyncTestInitialize()'));
}
core.print('unittest-suite-wait-for-done');
async_helper._initialized = true;
}
async_helper._asyncLevel = dart.notNull(async_helper._asyncLevel) + 1;
};
dart.fn(async_helper.asyncStart, VoidTovoid());
async_helper.asyncEnd = function() {
if (dart.notNull(async_helper._asyncLevel) <= 0) {
if (!dart.test(async_helper._initialized)) {
dart.throw(async_helper._buildException('asyncEnd() was called before asyncStart().'));
} else {
dart.throw(async_helper._buildException('asyncEnd() was called more often than ' + 'asyncStart().'));
}
}
async_helper._asyncLevel = dart.notNull(async_helper._asyncLevel) - 1;
if (async_helper._asyncLevel == 0) {
let callback = async_helper._onAsyncEnd;
async_helper._onAsyncEnd = null;
callback();
core.print('unittest-suite-success');
}
};
dart.fn(async_helper.asyncEnd, VoidTovoid());
async_helper.asyncSuccess = function(_) {
return async_helper.asyncEnd();
};
dart.fn(async_helper.asyncSuccess, dynamicTovoid());
async_helper.asyncTest = function(f) {
async_helper.asyncStart();
dart.dsend(f(), 'then', async_helper.asyncSuccess);
};
dart.fn(async_helper.asyncTest, FnTovoid());
dart.trackLibraries("async_helper", {"async_helper.dart": async_helper}, null);
// Exports:
return {
async_helper: async_helper
};
});