-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make second argument of UTF8ArrayToString optional. NFC #22696
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readability seems worth it, I agree, but see my question below.
* @param {number=} maxBytesToRead | ||
* @return {string} | ||
*/`, | ||
#if TEXTDECODER | ||
$UTF8ArrayToString__deps: ['$UTF8Decoder'], | ||
#endif | ||
$UTF8ArrayToString: (heapOrArray, idx, maxBytesToRead) => { | ||
$UTF8ArrayToString: (heapOrArray, idx = 0, maxBytesToRead = NaN) => { | ||
#if CAN_ADDRESS_2GB | ||
idx >>>= 0; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 41 should replace "undefined" with "NaN"
@@ -103,7 +103,7 @@ if (!isDataURI(wasmSourceMapFile)) { | |||
|
|||
function getSourceMap() { | |||
var buf = readBinary(wasmSourceMapFile); | |||
return JSON.parse(UTF8ArrayToString(buf, 0, buf.length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change NFC? Before we would read buf.length
bytes at most, but after we read without limit until the end of a UTF8 string. But is wasmSourceMapFile guaranteed to be encoded that way (including a null terminator)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third argument here is maxBytesToRead
which means will read at most buf.length
. However UTF8ArrayToString
will always stop when it reads a null byte I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is there a null byte in this input? That is what concerns me. It is reading a source map file, which I don't think is encoded that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I assumed UTF8ArrayToString would not read read past the end of the input array! I don't see that check though. That's strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait I think its fine because if you read of the end of a array or buffer in JS you get undefined
back, so every buffer is effectively null terminated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. That looks safe then.
This is mostly a wash from a code size POV but makes the call sites more readable I think.
a12cf01
to
e9dc107
Compare
This is mostly a wash from a code size POV but makes the call sites more readable I think.