Skip to content

Commit 3a12ef6

Browse files
committed
fix a lack of error on passing a negative length to the DataView constructor polyfill
1 parent 7253f6c commit 3a12ef6

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
- Fixed possible loss of symbol enumerability in `Object.defineProperty` in `Symbol` polyfill
6161
- Fixed return value of `Object.defineProperty` in `Symbol` polyfill in Android ~ 2
6262
- Fixed order of `%TypedArray%.from` arguments validation
63-
- Fixed a lack of error on passing an `ArrayBuffer` and a negative length to the `%TypedArray%` constructor polyfill
63+
- Fixed a lack of error on passing an `ArrayBuffer` and a negative length to the `%TypedArray%` and `DataView` constructors polyfills
6464
- Fixed some cases of `@@toStringTag` on `%TypedArray%` polyfill
6565
- Fixed some cases of `ToUint8Clamp` conversion
6666
- Fixed `NaN` handling in `Date.prototype.setYear` polyfill

packages/core-js/internals/array-buffer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var defineBuiltIns = require('../internals/define-built-ins');
1010
var fails = require('../internals/fails');
1111
var anInstance = require('../internals/an-instance');
1212
var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
13-
var toLength = require('../internals/to-length');
1413
var toIndex = require('../internals/to-index');
1514
var fround = require('../internals/math-fround');
1615
var IEEE754 = require('../internals/ieee754');
@@ -126,7 +125,7 @@ if (!NATIVE_ARRAY_BUFFER) {
126125
var bufferLength = bufferState.byteLength;
127126
var offset = toIntegerOrInfinity(byteOffset);
128127
if (offset < 0 || offset > bufferLength) throw new RangeError('Wrong offset');
129-
byteLength = byteLength === undefined ? bufferLength - offset : toLength(byteLength);
128+
byteLength = byteLength === undefined ? bufferLength - offset : toIndex(byteLength);
130129
if (offset + byteLength > bufferLength) throw new RangeError(WRONG_LENGTH);
131130
setInternalState(this, {
132131
type: DATA_VIEW,

tests/unit-global/es.data-view.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ QUnit.test('DataView', assert => {
3131
assert.throws(() => new DataView(new ArrayBuffer(8), -1), RangeError, 'If offset < 0, throw a RangeError exception');
3232
assert.throws(() => new DataView(new ArrayBuffer(8), 16), RangeError, 'If newByteLength < 0, throw a RangeError exception');
3333
assert.throws(() => new DataView(new ArrayBuffer(24), 8, 24), RangeError, 'If offset+newByteLength > bufferByteLength, throw a RangeError exception');
34+
assert.throws(() => new DataView(new ArrayBuffer(8), 0, -1), RangeError, 'negative byteLength throws RangeError');
3435
// Android ~ 4.0
3536
assert.throws(() => DataView(1), TypeError, 'throws without `new`');
3637
assert.throws(() => DataView(1), 'throws without `new`');
@@ -39,6 +40,7 @@ QUnit.test('DataView', assert => {
3940
assert.throws(() => new DataView(new ArrayBuffer(8), -1), 'If offset < 0, throw a RangeError exception');
4041
assert.throws(() => new DataView(new ArrayBuffer(8), 16), 'If newByteLength < 0, throw a RangeError exception');
4142
assert.throws(() => new DataView(new ArrayBuffer(24), 8, 24), 'If offset+newByteLength > bufferByteLength, throw a RangeError exception');
43+
assert.throws(() => new DataView(new ArrayBuffer(8), 0, -1), 'negative byteLength throws');
4244
}
4345
dataview = new DataView(new ArrayBuffer(8));
4446
dataview.setUint32(0, 0x12345678);

0 commit comments

Comments
 (0)