mirror of https://github.com/nodejs/node.git
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.pull/24504/head
parent
234551a22a
commit
fe103357ae
|
@ -624,7 +624,7 @@ class DataView {
|
|||
return ThrowError("Object must be an ArrayBuffer.");
|
||||
|
||||
v8::Handle<v8::Object> buffer = v8::Handle<v8::Object>::Cast(args[0]);
|
||||
if (!buffer->HasIndexedPropertiesInExternalArrayData())
|
||||
if (!ArrayBuffer::HasInstance(buffer))
|
||||
return ThrowError("Object must be an ArrayBuffer.");
|
||||
|
||||
unsigned int byte_length =
|
||||
|
|
|
@ -47,7 +47,7 @@ var assert = require('assert');
|
|||
assert.equal(obj.toString(), expected);
|
||||
assert.equal(Object.prototype.toString.call(obj), expected);
|
||||
|
||||
obj = new DataView(obj);
|
||||
obj = new DataView(obj.buffer || obj);
|
||||
assert.equal(obj.toString(), '[object DataView]');
|
||||
assert.equal(Object.prototype.toString.call(obj), '[object DataView]');
|
||||
});
|
||||
|
@ -197,7 +197,7 @@ assert.throws(function() {
|
|||
// see https://github.com/joyent/node/issues/4626
|
||||
(function() {
|
||||
var buf = new Uint8Array(2);
|
||||
var view = new DataView(buf);
|
||||
var view = new DataView(buf.buffer);
|
||||
view.setUint16(0, 1);
|
||||
assert.equal(view.getUint16(0), 1);
|
||||
})();
|
||||
|
@ -239,3 +239,7 @@ assert.throws(function() {
|
|||
assert.equal(b[0], 1);
|
||||
assert.equal(a.buffer, b.buffer);
|
||||
})();
|
||||
|
||||
assert.throws(function() {
|
||||
new DataView(new Int8Array(1));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue