From ba9481aff42d892aef7745a6269d45dae13d846e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Brostr=C3=B6m?= Date: Mon, 18 Sep 2017 10:29:24 +0200 Subject: [PATCH] Fix fromObject when `object` is undefined In atom@1.20.0 there is an unrecoverable error occurring when parameter `object` is undefined. ``` Uncaught (in promise) TypeError: Cannot read property 'start' of undefined at Function.module.exports.Range.fromObject (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/range.js:33:37) at Function.module.exports.MarkerLayer.deserializeSnapshot (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/marker-layer.js:39:57) at History.module.exports.History.deserializeStack (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/history.js:427:60) at History.module.exports.History.deserialize (/Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/history.js:361:35) at /Applications/Atom.app/Contents/Resources/app/node_modules/text-buffer/lib/text-buffer.js:264:30 ``` --- spec/range-spec.coffee | 6 ++++++ src/range.coffee | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/range-spec.coffee b/spec/range-spec.coffee index ea4caf07a3..bf3a1d3ccc 100644 --- a/spec/range-spec.coffee +++ b/spec/range-spec.coffee @@ -4,6 +4,12 @@ describe "Range", -> beforeEach -> jasmine.addCustomEqualityTester(require("underscore-plus").isEqual) + describe "::fromObject() when object is falsy", -> + it "should not throw", -> + expect(-> Range.fromObject(null)).not.toThrow() + it "should get default values", -> + expect(Range.fromObject(null).toString()).toBe "[(0, 0) - (0, 0)]" + describe "::intersectsWith(other, [exclusive])", -> intersectsWith = (range1, range2, exclusive) -> range1 = Range.fromObject(range1) diff --git a/src/range.coffee b/src/range.coffee index f7ed5d72ae..6fa419c2ef 100644 --- a/src/range.coffee +++ b/src/range.coffee @@ -39,7 +39,7 @@ class Range # that are already ranges.˚ # # Returns: A {Range} based on the given object. - @fromObject: (object, copy) -> + @fromObject: (object = {}, copy) -> if Array.isArray(object) new this(object[0], object[1]) else if object instanceof this