From 3c5a79710a8adcbace7c02258a69c9d525e740d1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 24 Mar 2013 19:01:02 +0800 Subject: [PATCH] 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. --- src/app/point.coffee | 4 +++- src/app/range.coffee | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/point.coffee b/src/app/point.coffee index e471ad6c6..6dd3eca27 100644 --- a/src/app/point.coffee +++ b/src/app/point.coffee @@ -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 diff --git a/src/app/range.coffee b/src/app/range.coffee index a3870ea66..d72ef6514 100644 --- a/src/app/range.coffee +++ b/src/app/range.coffee @@ -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)