More careful impl of hiwire_bool, added test cases #1061
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.
For a jsproxy,
bool(val)
is defined as(val && (val.length === undefined || val.length))
. This seems to encode the assumption that anything with a length field is some sort of container. However, there are many things that are not a container that have a length field.window.length
is the number of elements in the window, typically zero, so it considerswindow
to be falsey. Functions also have a length field which counts their arguments, zero argument javascript functions are currently falsey.Also, this implementation doesn't know about
Set
orMap
, empty javascript sets and maps are truthy. I replaced it with a smarter implementation.I also replaced the
==
and!=
inhiwire_eq
resphiwire_neq
with===
and!==
. On the code paths that usehiwire_eq
andhiwire_neq
, these do the same thing, but===
and!==
are less confusing.There is one more
!=
operator:https://github.com/iodide-project/pyodide/blob/1cb32c304d3901a57e95226e6b528501047cff01/src/core/hiwire.c#L428
However, the one place that
!=
operator is used is inJsProxy_IterNext
:Here
iddone
is eithertrue
orfalse
andfalse !== 0
istrue
butfalse != 0
isfalse
. So if we correctedhiwire_nonzero
to be sensible it would breakJsProxy_IterNext
.