Move installation of uncaught error handler to startEditorWindow

This commit is contained in:
Nathan Sobo
2015-09-29 20:23:51 -06:00
parent a573e1f381
commit 7d014581cf
2 changed files with 30 additions and 19 deletions

View File

@@ -61,6 +61,10 @@ describe "the `atom` global", ->
beforeEach ->
spyOn atom, 'openDevTools'
spyOn atom, 'executeJavaScriptInDevTools'
atom.installUncaughtErrorHandler()
afterEach: ->
atom.uninstallUncaughtErrorHandler()
it "will open the dev tools when an error is triggered", ->
try

View File

@@ -254,25 +254,6 @@ class Atom extends Model
#
# Call after this instance has been assigned to the `atom` global.
initialize: ->
window.onerror = =>
@lastUncaughtError = Array::slice.call(arguments)
[message, url, line, column, originalError] = @lastUncaughtError
{line, column} = mapSourcePosition({source: url, line, column})
eventObject = {message, url, line, column, originalError}
openDevTools = true
eventObject.preventDefault = -> openDevTools = false
@emitter.emit 'will-throw-error', eventObject
if openDevTools
@openDevTools()
@executeJavaScriptInDevTools('DevToolsAPI.showConsole()')
@emitter.emit 'did-throw-error', {message, url, line, column, originalError}
@displayWindow() unless @inSpecMode()
@setBodyPlatformClass()
@@ -599,6 +580,8 @@ class Atom extends Model
# Call this method when establishing a real application window.
startEditorWindow: ->
@installUncaughtErrorHandler()
{safeMode} = @getLoadSettings()
CommandInstaller = require './command-installer'
@@ -655,6 +638,30 @@ class Atom extends Model
if @getLoadSettings().initialPaths?.length is 0 and @workspace.getPaneItems().length is 0
@workspace.open(null)
installUncaughtErrorHandler: ->
@previousWindowErrorHandler = window.onerror
window.onerror = =>
@lastUncaughtError = Array::slice.call(arguments)
[message, url, line, column, originalError] = @lastUncaughtError
{line, column} = mapSourcePosition({source: url, line, column})
eventObject = {message, url, line, column, originalError}
openDevTools = true
eventObject.preventDefault = -> openDevTools = false
@emitter.emit 'will-throw-error', eventObject
if openDevTools
@openDevTools()
@executeJavaScriptInDevTools('DevToolsAPI.showConsole()')
@emitter.emit 'did-throw-error', {message, url, line, column, originalError}
uninstallUncaughtErrorHandler: ->
window.onerror = @previousWindowErrorHandler
###
Section: Messaging the User
###