Bug fix: interceptAnyObject used in monitorAPI #259
Merged
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.
Bug Description
shell.getAPI returns empty objects for several APIs even though real implementation was contributed.
Problem
When the repluggable host is created with the
disableMonitoring
option off,monitorAPI
is used to intercept and monitor any function in the API. This is done by contributing an intercepted API object instead of the contributed API. The intercepted API object is created usinginterceptAnyObject
, that recursively intercepts all functions in the nested object and wraps them with monitoring logic.The problem is that
interceptAnyObject
assumes the API is a plain object, as can be seen by its type. When passed an API that is not a plain object (e.g. a function),_.mapValues
returns an empty object and the API implementation is lost.The assumption that API is a plain object is wrong: APIs are not obligated to be built using a plain object, and can be really anything, from objects to functions to primitives. This can be seen in the
TAPI
type that makes no assumptions of the shape of the API.Solution
inner
argument ininterceptAnyObject
to be any, and instead added a type guard to make sure we only intercept plain objects._.isObjectLike
check with_.isPlainObject
which is more restrictive (will return false for arrays, maps, etc)