Permalink
Browse files

browser: now reports script src or id on error (jashkenas/coffeescrip…

  • Loading branch information...
1 parent 628b52e commit cdb7dfb5c9924468261e2453932b9a4b30b7eb8c @satyr committed Jun 4, 2012
Showing with 14 additions and 12 deletions.
  1. +2 −2 extras/coco.js
  2. +7 −5 lib/browser.js
  3. +5 −5 src/browser.co
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,7 +1,9 @@
var type, sink, script, that, __i, __ref, __len;
-Coco.stab = function(code, callback, error){
+Coco.stab = function(code, callback, filename, error){
try {
- Coco.run(code);
+ Coco.run(code, {
+ filename: filename
+ });
} catch (e) {
error = e;
}
@@ -19,7 +21,7 @@ Coco.load = function(url, callback){
var __ref;
if (xhr.readyState === 4) {
if ((__ref = xhr.status) === 200 || __ref === 0) {
- Coco.stab(xhr.responseText, callback);
+ Coco.stab(xhr.responseText, callback, url);
} else {
callback(Error(url + ": " + xhr.status + " " + xhr.statusText));
}
@@ -30,7 +32,7 @@ Coco.load = function(url, callback){
};
type = /^(?:text\/|application\/)?coco$/i;
sink = function(error){
- return error && setTimeout(function(){
+ error && setTimeout(function(){
throw error;
});
};
@@ -40,7 +42,7 @@ for (__i = 0, __len = (__ref = document.getElementsByTagName('script')).length;
if (that = script.src) {
Coco.load(that, sink);
} else {
- Coco.stab(script.innerHTML, sink);
+ Coco.stab(script.innerHTML, sink, script.id);
}
}
}
View
@@ -1,6 +1,6 @@
# `.run`s Coco code and calls back, passing error if any.
-Coco.stab = (code, callback, error) ->
- try Coco.run code catch then error = e
+Coco.stab = (code, callback, filename, error) ->
+ try Coco.run code, {filename} catch then error = e
callback error
# `.stab`s a remote script via `XMLHttpRequest`.
@@ -11,16 +11,16 @@ Coco.load = (url, callback or ->) ->
xhr.onreadystatechange = !->
if xhr.readyState is 4
if xhr.status of [200 0]
- then Coco.stab xhr.responseText, callback
+ then Coco.stab xhr.responseText, callback, url
else callback Error "#url: #{xhr.status} #{xhr.statusText}"
xhr.send null
xhr
# Execute `<script>`s with _coco_ type.
type = //^ (?: text/ | application/ )? coco $//i
-sink = (error) -> error and setTimeout -> throw error
+sink = !(error) -> error and setTimeout -> throw error
for script of document.getElementsByTagName \script
if type.test script.type
if script.src
then Coco.load that , sink
- else Coco.stab script.innerHTML, sink
+ else Coco.stab script.innerHTML, sink, script.id

0 comments on commit cdb7dfb

Please sign in to comment.