diff --git a/loader.js b/loader.js index cb0f3eac..05e9273e 100644 --- a/loader.js +++ b/loader.js @@ -845,9 +845,16 @@ // carefully scoped eval with given global var __scopedEval = function(__source, global, __sourceURL, __sourceMappingURL) { - eval('with(global) { (function() { ' + __source + ' \n }).call(global); }' - + (__sourceURL && !__source.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=(.+)/) - ? '\n//# sourceURL=' + __sourceURL : '')); + try { + eval('with(global) { (function() { ' + __source + ' \n }).call(global); }' + + (__sourceURL && !__source.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=(.+)/) + ? '\n//# sourceURL=' + __sourceURL : '')); + } + catch(e) { + if (e.name == 'SyntaxError') + e.message = 'Evaluating ' + __sourceURL + '\n\t' + e.message; + throw e; + } } })(); diff --git a/test/test.html b/test/test.html index ed0fbd49..b17d3fce 100644 --- a/test/test.html +++ b/test/test.html @@ -71,6 +71,15 @@ return 'Error defining module'; } }, + { + name: 'Error handling', + run: function(complete) { + jspm.import('./tests/error', complete); + }, + confirm: function() { + return; + } + }, { name: 'Global script loading', run: function(complete) { diff --git a/test/tests/error.js b/test/tests/error.js new file mode 100644 index 00000000..2b5ef6c5 --- /dev/null +++ b/test/tests/error.js @@ -0,0 +1,3 @@ +setTimeout(function() { + throw 'error'; +}, 1000); \ No newline at end of file