Fix abrupt checks in DisposableStack.prototype.use #142
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently in DisposableStack.prototype.use it calls GetDisposeMethod without checking for an abrupt completion.
This means that just checking
method
againstundefined
does not guarantee it to be a valid method.This then breaks the type of
method
for AddDisposableResource and arguably the first check.By checking for an abrupt completion on GetDisposeMethod first, we can then also gurantee that AddDisposableResource can no longer fail so we can assert this does not happen.
Just to go through the steps:
We call
AddDisposableResource
and know that:value
is not null or undefined and in fact an Object,method
is notundefined
, present and Callable (via GetDisposeMethod).So in AddDisposableResource
We take step 2.b, then 2.b.i passes as we have checked this in 4.a of DisposableStack.prototype.use.
Then in step 2.b.ii we call CreateDisposableResource.
Here we know that method is present and callable from GetDisposeMethod via GetMethod thus we go to step 2.a and pass it, returning a normal completion.