Browse Source

typed arrays: fix DataView endianness regression

Fix an off-by-one error introduced in 9fe3734 that caused a regression
in the default endianness used for writes in DataView::setGeneric().

Fixes #4626.
v0.9.8-release
Ben Noordhuis 12 years ago
parent
commit
2dd373894f
  1. 2
      src/v8_typed_array.cc
  2. 9
      test/simple/test-typed-arrays.js

2
src/v8_typed_array.cc

@ -714,7 +714,7 @@ class DataView {
// NOTE(deanm): args[1]->BooleanValue when the argument was not passed in
// gives us the right answer, but seems to be very slow. This seems to be
// the cost of calling BooleanValue() on undefined.
bool little_endian = args.Length() > 1 ? args[1]->BooleanValue() : false;
bool little_endian = args.Length() > 2 ? args[2]->BooleanValue() : false;
// TODO(deanm): All of these things should be cacheable.
int element_size = v8_typed_array::SizeOfArrayElementForType(
args.This()->GetIndexedPropertiesExternalArrayDataType());

9
test/simple/test-typed-arrays.js

@ -192,3 +192,12 @@ assert.throws(function() {
var buf = new DataView(new ArrayBuffer(8));
buf.setFloat64(0xffffffff, 0.0, true);
}, /Index out of range/);
// DataView::setGeneric() default endianness regression test,
// see https://github.com/joyent/node/issues/4626
(function() {
var buf = new Uint8Array(2);
var view = new DataView(buf);
view.setUint16(0, 1);
assert.equal(view.getUint16(0), 1);
})();

Loading…
Cancel
Save