Skip to content

Commit fe10335

Browse files
committed
typed arrays: make DataView throw on non-ArrayBuffer
Make the DataView constructor throw an exception when the first argument is not an ArrayBuffer. Follows the spec and the browsers.
1 parent 234551a commit fe10335

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/v8_typed_array.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ class DataView {
624624
return ThrowError("Object must be an ArrayBuffer.");
625625

626626
v8::Handle<v8::Object> buffer = v8::Handle<v8::Object>::Cast(args[0]);
627-
if (!buffer->HasIndexedPropertiesInExternalArrayData())
627+
if (!ArrayBuffer::HasInstance(buffer))
628628
return ThrowError("Object must be an ArrayBuffer.");
629629

630630
unsigned int byte_length =

test/simple/test-typed-arrays.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var assert = require('assert');
4747
assert.equal(obj.toString(), expected);
4848
assert.equal(Object.prototype.toString.call(obj), expected);
4949

50-
obj = new DataView(obj);
50+
obj = new DataView(obj.buffer || obj);
5151
assert.equal(obj.toString(), '[object DataView]');
5252
assert.equal(Object.prototype.toString.call(obj), '[object DataView]');
5353
});
@@ -197,7 +197,7 @@ assert.throws(function() {
197197
// see https://github.com/joyent/node/issues/4626
198198
(function() {
199199
var buf = new Uint8Array(2);
200-
var view = new DataView(buf);
200+
var view = new DataView(buf.buffer);
201201
view.setUint16(0, 1);
202202
assert.equal(view.getUint16(0), 1);
203203
})();
@@ -239,3 +239,7 @@ assert.throws(function() {
239239
assert.equal(b[0], 1);
240240
assert.equal(a.buffer, b.buffer);
241241
})();
242+
243+
assert.throws(function() {
244+
new DataView(new Int8Array(1));
245+
});

0 commit comments

Comments
 (0)