Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit ba9481a

Browse files
bstreamAndreas Broström
authored and
Andreas Broström
committed
Fix fromObject when object is undefined
In [email protected] 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 ```
1 parent 4b6cbcd commit ba9481a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

spec/range-spec.coffee

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ describe "Range", ->
44
beforeEach ->
55
jasmine.addCustomEqualityTester(require("underscore-plus").isEqual)
66

7+
describe "::fromObject() when object is falsy", ->
8+
it "should not throw", ->
9+
expect(-> Range.fromObject(null)).not.toThrow()
10+
it "should get default values", ->
11+
expect(Range.fromObject(null).toString()).toBe "[(0, 0) - (0, 0)]"
12+
713
describe "::intersectsWith(other, [exclusive])", ->
814
intersectsWith = (range1, range2, exclusive) ->
915
range1 = Range.fromObject(range1)

src/range.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Range
3939
# that are already ranges.˚
4040
#
4141
# Returns: A {Range} based on the given object.
42-
@fromObject: (object, copy) ->
42+
@fromObject: (object = {}, copy) ->
4343
if Array.isArray(object)
4444
new this(object[0], object[1])
4545
else if object instanceof this

0 commit comments

Comments
 (0)