Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Misc cleanup

  • Loading branch information...
commit d045bc1723ac0869220133a665a9cd8f5feafefc 1 parent 1c8a1a1
@tlrobinson authored
Showing with 13 additions and 16 deletions.
  1. +1 −1  examples.html
  2. +1 −1  examples.js
  3. +11 −14 { → lib}/long-stack-traces.js
View
2  examples.html
@@ -5,7 +5,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
- <script type="text/javascript" charset="utf-8" src="long-stack-traces.js"></script>
+ <script type="text/javascript" charset="utf-8" src="lib/long-stack-traces.js"></script>
<script type="text/javascript" charset="utf-8">
function initSecondTimeout(tag) {
View
2  examples.js
@@ -1,4 +1,4 @@
-require("./long-stack-traces");
+require("./lib/long-stack-traces");
var fs = require("fs");
View
25 long-stack-traces.js → lib/long-stack-traces.js
@@ -1,11 +1,11 @@
-(function() {
+(function(LST) {
+
+ LST.rethrow = false;
- var rethrow = false;
var currentTrace = null;
var filename = new Error().stack.split("\n")[1].match(/^ at ((?:\w+:\/\/)?[^:]+)/)[1];
function filterInternalFrames(frames) {
- // return frames;
return frames.split("\n").filter(function(frame) { return frame.indexOf(filename) < 0; }).join("\n");
}
@@ -21,11 +21,11 @@
// and overwrites the function with a wrapper that captures the stack at the time of callback registration
function wrapRegistrationFunction(object, property, callbackArg) {
if (typeof object[property] !== "function") {
- console.error("(long-stack-trace) Object", object, "does not contain function", property);
+ console.error("(long-stack-traces) Object", object, "does not contain function", property);
return;
}
if (!hop.call(object, property)) {
- console.warn("(long-stack-trace) Object", object, "does not directly contain function", property);
+ console.warn("(long-stack-traces) Object", object, "does not directly contain function", property);
}
// TODO: better source position detection
@@ -43,7 +43,7 @@
// check that the registration function was indeed overwritten
if (object[property] === fn)
- console.warn("(long-stack-trace) Couldn't replace ", property, "on", object);
+ console.warn("(long-stack-traces) Couldn't replace ", property, "on", object);
}
// Takes a callback function and name, and captures a stack trace, returning a new callback that restores the stack frame
@@ -53,15 +53,15 @@
var trace = " at "+frameLocation+"\n" + filterInternalFrames(new Error().stack.split("\n").slice(1).join("\n"));
return function() {
if (currentTrace)
- console.warn("(long-stack-trace) Internal Error: currentTrace already set.");
+ console.warn("(long-stack-traces) Internal Error: currentTrace already set.");
// restore the trace
currentTrace = trace;
try {
return callback.apply(this, arguments);
} catch (e) {
console.error("Uncaught " + e.stack);
- if (rethrow)
- throw undefined; // TODO: throw the original error, or undefined?
+ if (LST.rethrow)
+ throw ""; // TODO: throw the original error, or undefined?
} finally {
// clear the trace so we can check that none is set above.
// TODO: could we remove this for slightly better performace?
@@ -125,7 +125,7 @@
}
// Node.js
else if (typeof process !== "undefined") {
- rethrow = true;
+ LST.rethrow = true;
var global = (function() { return this; })();
wrapRegistrationFunction(global, "setTimeout", 0);
@@ -134,9 +134,6 @@
var EventEmitter = require('events').EventEmitter;
wrapRegistrationFunction(EventEmitter.prototype, "addListener", 1);
wrapRegistrationFunction(EventEmitter.prototype, "on", 1);
-
- // TODO: automatically wrap APIs that accept callbacks
- // i.e. https://github.com/lm1/node-fiberize/blob/master/fiberize.js
}
// Copyright 2006-2008 the V8 project authors. All rights reserved.
@@ -247,4 +244,4 @@
}
return line;
}
-})();
+})(typeof exports !== "undefined" ? exports : {});
Please sign in to comment.
Something went wrong with that request. Please try again.