mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
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:
@@ -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', ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user