Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Throw exception when adding a non-object pane item
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Sobo committed Jul 1, 2015
1 parent b1d6b79 commit 8348b2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/pane-spec.coffee
Expand Up @@ -108,6 +108,12 @@ describe "Pane", ->
pane2 = pane1.splitRight()
expect(-> pane2.addItem(item)).toThrow()

it "throws an exception if the item isn't an object", ->
pane = new Pane(items: [])
expect(-> pane.addItem(null)).toThrow()
expect(-> pane.addItem('foo')).toThrow()
expect(-> pane.addItem(1)).toThrow()

describe "::activateItem(item)", ->
pane = null

Expand Down
2 changes: 2 additions & 0 deletions src/pane.coffee
Expand Up @@ -336,6 +336,8 @@ class Pane extends Model
#
# Returns the added item.
addItem: (item, index=@getActiveItemIndex() + 1) ->
throw new Error("Pane items must be objects. Attempted to add item #{item}.") unless item? and typeof item is 'object'

return if item in @items

if typeof item.onDidDestroy is 'function'
Expand Down

0 comments on commit 8348b2c

Please sign in to comment.