From 6a4c025e086ef2e6a99ded4c4ab9b4f047febeb4 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 28 Jan 2012 18:12:01 -0800 Subject: [PATCH] Global exception handler is not registered until the page's controller adds it. It is bad form to register this handler on definition. This would cause problems if, for instance, this module was required by our Node code. --- static/js/pad.js | 2 ++ static/js/pad_utils.js | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/static/js/pad.js b/static/js/pad.js index 172f9323..e6d8dc9a 100644 --- a/static/js/pad.js +++ b/static/js/pad.js @@ -401,6 +401,8 @@ var pad = { init: function() { + padutils.setupGlobalExceptionHandler(); + $(document).ready(function() { //start the costum js diff --git a/static/js/pad_utils.js b/static/js/pad_utils.js index 464c5058..071185a8 100644 --- a/static/js/pad_utils.js +++ b/static/js/pad_utils.js @@ -459,17 +459,25 @@ var padutils = { } }; -//send javascript errors to the server -window.onerror = function test (msg, url, linenumber) -{ - var errObj = {errorInfo: JSON.stringify({msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})}; - var loc = document.location; - var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror"; +var globalExceptionHandler = undefined; +function setupGlobalExceptionHandler() { + //send javascript errors to the server + if (!globalExceptionHandler) { + globalExceptionHandler = function test (msg, url, linenumber) + { + var errObj = {errorInfo: JSON.stringify({msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})}; + var loc = document.location; + var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror"; - $.post(url, errObj); + $.post(url, errObj); - return false; -}; + return false; + }; + window.onerror = globalExceptionHandler; + } +} + +padutils.setupGlobalExceptionHandler = setupGlobalExceptionHandler; padutils.binarySearch = require('/ace2_common').binarySearch;