Skip to content

Instantly share code, notes, and snippets.

@iwillig
Created January 9, 2015 03:51

Revisions

  1. iwillig created this gist Jan 9, 2015.
    22 changes: 22 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title></title>

    <script src="/node_modules/source-map/dist/source-map.js"></script>
    <script src="/web-worker-report.js"></script>

    <script>
    var worker = new Worker('test.js');
    worker.onerror = function(e) {
    reportError(e);
    };
    </script>

    </head>

    <body>
    </body>

    </html>
    25 changes: 25 additions & 0 deletions reporter.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@


    fetchSourceMap = (fileName) =>
    response = null
    xhr = new XMLHttpRequest()

    xhr.onreadystatechange = () =>
    if xhr.readyState == 4 and xhr.status == 200
    response = xhr.responseText

    xhr.onerror = (error) =>
    throw error

    xhr.open('GET', fileName + '.map', false)
    xhr.send()
    response


    window.reportError = (error) =>
    lineNumber = error.lineno
    columnNumber = error.colno
    rawSourceMap = fetchSourceMap error.filename
    smc = new sourceMap.SourceMapConsumer rawSourceMap

    console.log smc.originalPositionFor { line: error.lineno, column: error.colno }
    19 changes: 19 additions & 0 deletions test.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@



    # this
    # is
    # a bunch of
    # space

    # more code

    fib = (n) =>
    if n <= 2
    1
    fib(n - 1) + fib(n - 2)


    throwError = -> throw new Error('hello world')

    throwError()