EmNudge/watlings

009_data test fails due to improper call to `TextDecoder.decode`

fixermark opened this issue · 1 comments

At

loggedStrings.push(new TextDecoder().decode(byteSlice, "utf-8"));
and line 42, we attempt to decode a text buffer with new TextDecoder().decode(byteSlice, "utf-8"). This fails with

TypeError: The "options" argument must be of type object. Received type string ('utf-8')

As per documentation at https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode, this failure should be expected; the second argument to decode should be an options argument with the only valid key stream. To modify the behavior of the decoder, we instead should specify the label in the constructor (new TextDecoder('utf-8)). This is, however, unnecessary as utf-8 is the default decoder configuration.

Changing the line as follows allows this test to pass when the corresponding 009_data.wat file is updated to emit three different strings:

loggedStrings.push(new TextDecoder().decode(byteSlice));

Good catch! Thanks for the well written write-up!

TextDecoder.prototype.decode doesn't seem to throw errors with "utf-8" in Node, but it does in the browser. Or - at least I was unable to get it to throw in my local node instance, but I was able to verify the error in dev tools. I guess that's why the tests seemed to pass for me.

Just merged this change!