Buffer: fix use-after-free on detach during argument coercion
Several Buffer.prototype methods fetched the data pointer of the
underlying ArrayBuffer before converting their offset, length or value
arguments. The conversion may call user code (valueOf) which can
detach the buffer, for example with ArrayBuffer.prototype.transfer().
The bounds check and the memory access then used the stale pointer.
In QuickJS this affected readInt/readFloat, writeInt/writeFloat,
write(), toString(), indexOf(), compare() and copy(). In njs it
affected the range helper behind compare() and copy().
Now all arguments are converted first, and the buffer is fetched and
checked right before it is used, so a detach during the conversion is
reported as an ordinary "detached buffer" error. The order in which
the arguments are converted is preserved.
In njs, copy() now makes the target writable before computing the
target range. A target sharing external data is copied on write, so
pointers computed earlier pointed to the old data and the copy was
lost.
Similarly, toJSON() in QuickJS stored the bytes with
JS_SetPropertyUint32(), which may call a setter inherited from
Array.prototype and detach the buffer during the loop. The elements
are now defined directly on the new array.