[wasm][debugger] Correctly handle empty, and whitespace-only strings (#41424)
authorAnkit Jain <radical@gmail.com>
Mon, 31 Aug 2020 14:21:04 +0000 (10:21 -0400)
committerGitHub <noreply@github.com>
Mon, 31 Aug 2020 14:21:04 +0000 (09:21 -0500)
commit0795094ee0002133ae499d445fdb6770c0f5e0a5
tree4274639ebddacf10b1385d5811428797f07f3eba
parenta33ad570a6a290ff6cfbd0af9b60db384949a59c
[wasm][debugger] Correctly handle empty, and whitespace-only strings (#41424)

There are two cases being fixed here:

1. str=='', or str=' '
- We check `str_value == 0`, and for the above cases JS returns
true, due to type coercion.
- So, we show the result as a null string.

2. str==null
- debugger.c adds the value for this with `mono_wasm_add_typed_value ("string", NULL, 0)`
- the second argument is converted to a string with
  `Module.UTF8ToString(..)`, but when it's `0`/NULL, we get an
  empty string. And that becomes a null string, because of (1).

Fixing this by using `===` operator to avoid type coercion.

Fixes https://github.com/dotnet/runtime/issues/41276
src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs
src/mono/wasm/debugger/tests/debugger-test.cs
src/mono/wasm/runtime/library_mono.js