Replaced <obj> instanceof Array
with Array.isArray()
#452
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.
I've been seeing a bug where at certain points in my tests, code to
retrieve elements like this:
would throw an error:
After looking into the for wd code, I could see this was happening in
callbacks.js:133
, in code that checked whether the return value was anarray, using
instanceof Array
. When I inspected what this code wasdoing at runtime the value really was an array, but
instanceof Array
was still returning false. Strangely I could reproduce the original
error when I ran my tests via Jest but not when I ran the same code in
the wd repl (where
instanceof Array
would return true at the same place).It turns out that
instanceof Array
can return false for an arraycreated in another window or frame (or process?). See
http://web.mit.edu/jwalden/www/isArray.html for a full
explanation of this.
Array.isArray()
was added to ES5 for exactly thisreason, so I have replaced
instanceof Array
withArray.isArray()
throughout the codebase.
With this change I wd behaves as I would expect both in the repl and in
Jest.