Merge pull request #7360 from atom/iz-blow-up-on-undefined-command-callback

Throw error for commands registered with non-function callbacks
This commit is contained in:
Kevin Sawicki
2015-06-22 11:10:17 -07:00
2 changed files with 23 additions and 0 deletions

View File

@@ -158,6 +158,26 @@ describe "CommandRegistry", ->
addError = error
expect(addError.message).toContain(badSelector)
it "throws an error when called with a non-function callback and selector target", ->
badCallback = null
addError = null
try
registry.add '.selector', 'foo:bar', badCallback
catch error
addError = error
expect(addError.message).toContain("Can't register a command with non-function callback.")
it "throws an error when called with an non-function callback and object target", ->
badCallback = null
addError = null
try
registry.add document.body, 'foo:bar', badCallback
catch error
addError = error
expect(addError.message).toContain("Can't register a command with non-function callback.")
describe "::findCommands({target})", ->
it "returns commands that can be invoked on the target or its ancestors", ->
registry.add '.parent', 'namespace:command-1', ->

View File

@@ -92,6 +92,9 @@ class CommandRegistry
disposable.add @add(target, commandName, callback)
return disposable
if typeof callback isnt 'function'
throw new Error("Can't register a command with non-function callback.")
if typeof target is 'string'
validateSelector(target)
@addSelectorBasedListener(target, commandName, callback)