From bf1ff79c3e634efd92ee32e0b984cfcfcedab03c Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 22 Apr 2020 15:29:25 -0500 Subject: [PATCH] Don't crash when an operation returns a null value We need to check for resources on return values of operations in order to link them to the parent context. To do this, we check that the object can receive property access. However, `typeof null` is actually `"object"`. This adjusts the check to cover both undefined and null (as well as any other object type) --- packages/effection/src/resource.js | 2 +- packages/effection/tests/resources.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/effection/src/resource.js b/packages/effection/src/resource.js index 6390d6017..69c78d71d 100644 --- a/packages/effection/src/resource.js +++ b/packages/effection/src/resource.js @@ -5,7 +5,7 @@ let symbol = Symbol("resource"); export function contextOf(resource) { if(resource instanceof ExecutionContext) { return resource; - } else if(typeof(resource) === "object" || typeof(resource) === "function") { + } else if(resource != null) { return resource[symbol]; } } diff --git a/packages/effection/tests/resources.test.js b/packages/effection/tests/resources.test.js index 4f8470d33..1cbfc0ed1 100644 --- a/packages/effection/tests/resources.test.js +++ b/packages/effection/tests/resources.test.js @@ -107,4 +107,16 @@ describe('Returning resources', () => { }); }); }); + + describe('null operations', () => { + beforeEach(() => { + return execution = main(function*() { + yield Promise.resolve(null); + }); + }); + it('completes', () => { + expect(execution.state).toEqual('completed'); + }); + }); + });