Use _.isArray to determine whether a value is Array.

When passing arrays between child processes with node's IPC machanism,
`instance of Array` will return false for the deserialized array, we
should use the reiable way of detecting Array provided by underscore.

Read this for more:
http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/

This bug was found when moving spell-check to use ProcessTask, and the
wrong Range object was returned for the passed misspelling value.
This commit is contained in:
Cheng Zhao 2013-03-24 19:01:02 +08:00
parent 3ed35574d4
commit 3c5a79710a
2 changed files with 4 additions and 2 deletions

View File

@ -1,10 +1,12 @@
_ = require 'underscore'
module.exports =
class Point
@fromObject: (object) ->
if object instanceof Point
object
else
if object instanceof Array
if _.isArray(object)
[row, column] = object
else
{ row, column } = object

View File

@ -31,7 +31,7 @@ class Range
new Range(@start.copy(), @end.copy())
isEqual: (other) ->
if other instanceof Array and other.length == 2
if _.isArray(other) and other.length == 2
other = new Range(other...)
other.start.isEqual(@start) and other.end.isEqual(@end)