blob: 6dea20fb5a9182cd6b71a3044bc9e50b9336169f [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/base/base.html">
<link rel="import" href="/tracing/base/iteration_helpers.html">
<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/base/xhr.html">
<link rel="import" href="/tracing/extras/full_config.html">
<link rel="import" href="/tracing/importer/import.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/mre/failure.html">
<script>
'use strict';
tr.exportTo('tr.mre', function() {
var Failure = tr.mre.Failure;
function runAndConvertErrorsToFailures(result, job,
traceHandle, cb, opt_this) {
try {
cb.call(opt_this);
} catch (e) {
var err = tr.b.normalizeException(e);
// TODO(eakuefner): Set job once reduction is implemented.
result.addFailure(new Failure(
job, job.mapFunctionHandle.asUserFriendlyString(),
traceHandle.canonicalUrl, err.typeName, err.message, err.stack));
}
}
function mapSingleTrace(result, model, options, mapFunction) {
// Map the function.
var numPairsBeforeMapping = tr.b.dictionaryLength(result.pairs);
var numFailuresBeforeMapping = result.failures.length;
try {
mapFunction(result, model, options);
} catch (ex) {
ex.name = 'MapFunctionError';
throw ex;
}
var addedPairs = (tr.b.dictionaryLength(result.pairs) >
numPairsBeforeMapping);
var addedFailures = result.failures.length > numFailuresBeforeMapping;
if (!(addedPairs || addedFailures)) {
var err = new Error('Mapper did not add any results!');
err.name = 'NoResultsAddedError';
throw err;
}
}
return {
mapSingleTrace: mapSingleTrace,
runAndConvertErrorsToFailures: runAndConvertErrorsToFailures
};
});
</script>