Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakrashim: Fixing v8::ArrayBuffer implementation detail
Browse files Browse the repository at this point in the history
v8::ArrayBuffer was returning raw internal pointers to ArrayBuffers.
This is fine in general, but in v8 in particular these pointers are
guaranteed to be non-null. For chakracore in the case of empty ArrayBuffers
this implicit assumption was broken, which showed up in one test scenario

We now explicitly check for this case and return a valid (if useless) pointer
instead.
  • Loading branch information
MSLaguana committed Feb 5, 2018
1 parent ad994dd commit 2d7d72f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions deps/chakrashim/src/v8arraybuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ ArrayBuffer::Contents ArrayBuffer::GetContents() {
}

Contents contents;
if (buffer == nullptr)
{
CHAKRA_ASSERT(bufferLength == 0);
// v8's version of ArrayBuffer will return a non-null pointer even in the case of
// an empty ArrayBuffer, and this behavior is relied upon by some of the i18n code.
// To support that, if we would otherwise return a null buffer, as long as the
// length is 0 we instead return a valid pointer to something, on the understanding
// that nobody will actually try to read it.
buffer = (BYTE*)this;
}
contents.data_ = buffer;
contents.byte_length_ = bufferLength;
return contents;
Expand Down

0 comments on commit 2d7d72f

Please sign in to comment.