|
1 | | -(function() { |
2 | | - "use strict"; |
| 1 | +(function() {"use strict"; function timeout(win, f, ms) { win.__setTimeout(f, ms); }; |
| 2 | + // The above is a kludge to make sure setTimeout calls are made from |
| 3 | + // line 1, which is where FF will start counting for its line numbers. |
| 4 | + |
| 5 | + function parseStack(stack) { |
| 6 | + var found = [], m; |
| 7 | + var re = /([\w$]*)@.*?:(\d+)|\bat (?:([^\s(]+) \()?.*?:(\d+)/g; |
| 8 | + while (m = re.exec(stack)) { |
| 9 | + found.push({fn: m[1] || m[3] || null, |
| 10 | + line: m[2] || m[4]}); |
| 11 | + } |
| 12 | + console.log(stack); |
| 13 | + return found; |
| 14 | + } |
| 15 | + function frameString(frame) { |
| 16 | + return "line " + frame.line + (frame.fn ? " in function " + frame.fn : ""); |
| 17 | + } |
3 | 18 |
|
4 | 19 | var SandBox = window.SandBox = function(options) { |
5 | 20 | var frame = this.frame = document.createElement("iframe"); |
|
55 | 70 | this.startedAt = Date.now(); |
56 | 71 | this.extraSecs = 1; |
57 | 72 | this.win.__c = 0; |
58 | | - this.win.__setTimeout(preprocess(code, this), 0); |
| 73 | + timeout(this.win, preprocess(code, this), 0); |
59 | 74 | }, |
60 | 75 | show: function(html, output) { |
61 | 76 | var scriptTags = [], sandbox = this, doc = this.win.document; |
|
96 | 111 | }, |
97 | 112 | error: function(exception) { |
98 | 113 | if (!this.output) throw exception; |
99 | | - var pos = /(?:\bat |@).*?([^\/:]+):(\d+)/.exec(exception.stack); |
100 | | - if (pos && pos[1].match(/sandbox/)) pos = null; |
101 | | - this.output.out("error", [String(exception) + (pos ? " (line " + pos[2] + ")" : "")]); |
| 114 | + var stack = parseStack(exception.stack); |
| 115 | + this.output.out("error", [String(exception) + (stack.length ? " (" + frameString(stack[0]) + ")" : "")]); |
| 116 | + if (stack.length > 1) { |
| 117 | + this.output.div.lastChild.appendChild(document.createTextNode(" ")); |
| 118 | + var mark = this.output.div.lastChild.appendChild(document.createElement("span")); |
| 119 | + mark.innerHTML = "…"; |
| 120 | + mark.className = "sandbox-output-etc"; |
| 121 | + mark.addEventListener("click", function(e) { |
| 122 | + mark.className = ""; |
| 123 | + mark.innerHTML = "\n called from " + stack.slice(1).map(frameString).join("\n called from "); |
| 124 | + }); |
| 125 | + } |
102 | 126 | } |
103 | 127 | }; |
104 | 128 |
|
|
0 commit comments