typed arrays: only share ArrayBuffer backing store
authorBen Noordhuis <info@bnoordhuis.nl>
Tue, 5 Feb 2013 13:24:43 +0000 (14:24 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Wed, 6 Feb 2013 13:21:35 +0000 (14:21 +0100)
commit01ee551e704776d8547250ac015a5463613afb45
tree8bc06a064180e2cfed0b2a4baf6c94c09ed4d0e9
parent202b5db4efd0beec788beb40ece205ce9aa79037
typed arrays: only share ArrayBuffer backing store

Follow browser behavior, only share the backing store when it's a
ArrayBuffer. That is:

  var abuf = new ArrayBuffer(32);
  var a = new Int8Array(abuf);
  var b = new Int8Array(abuf);
  a[0] = 0;
  b[0] = 1;
  assert(a[0] === b[0]);  // a and b share memory

But:

  var a = new Int8Array(32);
  var b = new Int8Array(a);
  a[0] = 0;
  b[0] = 1;
  assert(a[0] !== b[0]);  // a and b don't share memory

The typed arrays spec allows both `a[0] === b[0]` and `a[0] !=== b[0]`
but Chrome and Firefox implement the behavior where memory is not
shared.

Copying the memory is less efficient but let's do it anyway for the
sake of the Principle of Least Surprise.

Fixes #4714.
src/v8_typed_array.cc
test/simple/test-typed-arrays.js