• Stars
    star
    277
  • Rank 148,875 (Top 3 %)
  • Language
    JavaScript
  • Created almost 14 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Long stacktraces for V8 implemented in user-land JavaScript. [UNMAINTAINED] Use https://github.com/mattinsler/longjohn instead

Long Stacktraces

Long stacktraces for V8 implemented in user-land JavaScript. Supports Chrome/Chromium and Node.js.

NOTE: there are various issues such as memory leaks (due to very long stack traces). This should not be used in production.

Background

A common problem when debugging event-driven JavaScript is stack traces are limited to a single "event", so it's difficult to trace the code path that caused an error.

A contrived example (taken from the PDF referenced below):

function f() {
    throw new Error('foo');
}

setTimeout(f, Math.random()*1000);
setTimeout(f, Math.random()*1000);

Which one throws the first error?

Node.js intended to fix this problem with a solution called "Long Stacktraces": http://nodejs.org/illuminati0.pdf

But what if we wanted something like this in the browser? It turns out V8 already has everything needed to implement this in user-land JavaScript (although in a slightly hacky way).

V8 has a stack trace API that allows custom formatting of textual stack trace representations. By wrapping any function that registers an asynchronous event callback (e.x. setTimeout and addEventListener in the browser) we can store the stack trace at the time of callback registration, and later append it to stack traces. This also works for multiple levels of events (a timeout or event registered within a timeout or event, etc).

Usage

For Node.js install using npm install long-stack-traces.

Simply include the "long-stack-traces.js" via a script tag or other method before any event listener or timeout registrations. In Node.js call require("long-stack-traces").

Stack traces from example above:

Uncaught Error: foo
    at f (index.html:24:23)
    ----------------------------------------
    at setTimeout
    at onload (index.html:28:40)
Uncaught Error: foo
    at f (index.html:24:23)
    ----------------------------------------
    at setTimeout
    at onload (index.html:27:40)

Note one was from the timeout on line 27, the other on line 28. Events' stack traces are divided by a line of dashes.

See examples.html for more examples, and run node examples.js for a Node.js example.

Supported APIs

Currently supports the following APIs:

Chromium

  • setTimeout
  • setInterval
  • addEventListener
  • XMLHttpRequest.onreadystatechange (stack actually recorded upon send())

Node.js

  • setTimeout
  • setInterval
  • process.nextTick
  • EventEmitter.addListener
  • EventEmitter.on
  • All APIs that use EventEmitter

TODO

  • Gracefully degrade in non-V8 environments.
  • Figure out what's up with these stack frames when throwing an exception from an input's event handler: <error: TypeError: Accessing selectionEnd on an input element that cannot have a selection.>
  • Configurable stack trace length limit to prevent memory leaks (not technically a leak). Trivial example: function foo() { setTimeout(foo, 1000); } foo();

License

Copyright (c) 2011, Thomas Robinson [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

evil.css

Because CSS isn't evil enough already.
CSS
723
star
2

WebSaver

A WebKit-based Mac OS X screensaver. Use any webpage or JavaScript program as a screensaver.
Objective-C
509
star
3

node-jslinux

jslinux (http://bellard.org/jslinux/) compatibility layer for Node.
JavaScript
180
star
4

element-capture

A Chrome extension which will screen capture any HTML element of your choosing.
JavaScript
114
star
5

martin.sh

A simple web server and Sinatra-like microframework written in shell script. Why? WHY NOT?
Shell
94
star
6

metabase-http-driver

A proof-of-concept HTTP "driver" for Metabase
Clojure
58
star
7

programming-cappuccino

WORK IN PROGRESS. Companion to "Programming Cocoa for Mac OS X" Feedback, contributors, pull requests are all very welcome.
JavaScript
47
star
8

overrides

React Higher-Order Component and Hook implementing the "overrides" pattern with minimal boilerplate
JavaScript
41
star
9

life-gen

Game of Life pattern generator and tools
Ruby
36
star
10

tomcoin

A toy cryptocurrency that implements the core Bitcoin algorithm, the Nakamoto Consensus. For education/entertainment purposes. Very incomplete.
JavaScript
29
star
11

v8-typed-array

[UNMAINTAINED] Typed Array implementation for V8 and Node.js
C++
27
star
12

leakhelper

JavaScript memory leak finding helper thingy
JavaScript
25
star
13

cappruby

A proof-of-concept Ruby implementation on top of JavaScript and the Objective-J runtime
Ruby
24
star
14

jack-servlet

A servlet for running JSGI / Jack compatible server-side JavaScript applications and frameworks on Google AppEngine for Java or other servlet containers
Java
21
star
15

streampunk.js

An experimental "classical" Flow-based programming-like system for JavaScript
JavaScript
19
star
16

zipjs

A pure JavaScript implementation of the ZIP file format for CommonJS. Currently implements unzipping only.
JavaScript
17
star
17

satsim

A satellite simulator/visualization using WebGL: https://satsim.vercel.app/
TypeScript
16
star
18

node-repl-promised

Make any Node.js REPL support promises (Promises/A+).
JavaScript
16
star
19

xebug

JavaScript debugger written in JavaScript. Should work in nearly any JavaScript environment. Works via magic.
JavaScript
16
star
20

jack-dav

WebDAV implementation in JavaScript for Jack
JavaScript
15
star
21

skittles.py

A program to count Skittle colors. Inspired by https://possiblywrong.wordpress.com/2019/04/06/follow-up-i-found-two-identical-packs-of-skittles-among-468-packs-with-a-total-of-27740-skittles/
Python
15
star
22

tlrobinson

Miscellaneous projects found on tlrobinson.net
JavaScript
14
star
23

ropen

Remote "open" command line tool for opening remote files on OS X via command line
PHP
11
star
24

narwhal-v8

Narwhal support for V8 (incomplete)
C++
11
star
25

node-cgminer

API client for CGMiner Bitcoin miner
CoffeeScript
11
star
26

jsont

JSONT module for CommonJS
JavaScript
9
star
27

jake-old

Deprecated in favor of http://github.com/280north/jake
JavaScript
9
star
28

cacheme.php

Simple page caching for PHP
9
star
29

cappuccino-experiments

Experimental additions to Objective-J and Cappuccino
JavaScript
8
star
30

ojrpc

Very simple Objective-J RPC
Objective-J
6
star
31

xkcdplot

XKCD-style plots in Javascript using D3. Fork of http://dan.iel.fm/xkcd/
JavaScript
6
star
32

jscrypto

[Common JS] Fast symmetric cryptography in Javascript
JavaScript
6
star
33

q-proxy

A promise wrapper that proxies future method calls.
JavaScript
5
star
34

metabase-proxy-examples

Example configurations of running Metabase behind various reverse proxies
5
star
35

objc2objj

Not yet implemented Objective-C to Objective-J compiler
JavaScript
5
star
36

minibundler

Create self-contained bundles of CommonJS modules.
5
star
37

dolores.py

A stupid little script to control your Ecovacs Deebot robot vacuum with Westworld host commands
Python
4
star
38

narcissus

JavaScript
4
star
39

json-rpc

An implementation of JSON-RPC 2.0 for CommonJS
JavaScript
4
star
40

heroku-sh

Get a bash shell in your Heroku dyno
4
star
41

narwhal-johnson

Narwhal support for Johnson (incomplete)
JavaScript
4
star
42

commonjs-jdbc

JavaScript
3
star
43

vanilla

TypeScript
3
star
44

finddup

Duplicate file finding command line utility
JavaScript
3
star
45

bcomm

BCOMM (Broswer Command): Dispatch commands, tests, logs, etc to and from remote browsers.
JavaScript
3
star
46

commonjs-sqlite-jdbc

JavaScript
3
star
47

commonjs-mysql-jdbc

JavaScript
3
star
48

narwhal-photoshop

Yes, this is indeed the Narwhal engine for Photoshop's JavaScript interpreter. Work in progress.
JavaScript
3
star
49

CommonJS.tmbundle

A CommonJS TextMate bundle
2
star
50

jack-auth

JavaScript
2
star
51

tirefire.js

An asynchronous framework for implementing helper classes for reinventing the wheel. Based on promises.
2
star
52

nosh

An experimental PowerShell-esque shell based on Node.js
JavaScript
2
star
53

node-flurry

Flurry API client for Node.js and Q
JavaScript
2
star
54

DebugKit

2
star
55

helloworlds

A collection of "Hello World" programs for every language I encounter.
Makefile
2
star
56

annotate-react-dom

Annotates DOM nodes with their React component name to make them targetable by CSS selector, e.x. `[react=MyComponent]`. Useful for Selenium testing, etc.
JavaScript
2
star
57

promise-chain-decorator

A decorator which adds proxies to returned promises, allowing for promise chaining
JavaScript
2
star
58

pricebot

IRC bot for reporting Bitcoin exchange prices
CoffeeScript
2
star
59

funky.js

Helper library for asynchronous functional programming.
JavaScript
2
star
60

q-step

A simple control flow function for JavaScript promises, similar to creationix/step
CoffeeScript
2
star
61

twosixonesix

Promise-and-async-iterator-first Node.js web application framework [Experimental]
JavaScript
2
star
62

PlayaWiFi

Makefile
1
star
63

http-server-repl

JavaScript
1
star
64

mb-deploy-test

Dockerfile
1
star
65

streampunk.go

Go
1
star
66

react-observables

JavaScript
1
star
67

cafesentry

A simple tool for watching over your laptop in semi-trustworthy public places.
JavaScript
1
star
68

jack2

HTTP middleware for Node.js/Q-JSGI/JSGI2
JavaScript
1
star
69

rxvt-js

A rewrite of the rxvt terminal emulator in javascript
C
1
star
70

freebird

CoffeeScript
1
star
71

semver

Tools for managing CommonJS packages following the Semantic Versioning specifications.
1
star
72

place.js

minimal clone of r/Place
HTML
1
star
73

react-app

My React boilerplate alternative to create-react-app (+ class-properties + decorators + react-hot-loader)
JavaScript
1
star
74

dotfiles

Shell
1
star
75

tcpfork

A simple TCP server that just forks a command and pipes stdin and stdout to the client.
JavaScript
1
star
76

react-framed

Render content in iframes or popup windows with varying degrees of isolation
JavaScript
1
star