-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer: convert offset & length to int properly #9492
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
function test(size, offset, length) { | ||
const arrayBuffer = new ArrayBuffer(size); | ||
|
||
const uint8Array = new Uint8Array(arrayBuffer, offset, length); | ||
for (let i = 0; i < length; i += 1) { | ||
uint8Array[i] = 1; | ||
} | ||
|
||
const buffer = new Buffer(arrayBuffer, offset, length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jasnell Done! |
||
for (let i = 0; i < length; i += 1) { | ||
assert.strictEqual(buffer[i], 1); | ||
} | ||
} | ||
|
||
test(200, 50, 100); | ||
test(8589934592 /* 1 << 40 */, 4294967296 /* 1 << 39 */, 1000); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Flags: --expose-internals | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably test for a wider range of values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const {toInteger} = require('internal/util'); | ||
|
||
assert.strictEqual(toInteger(+0), 0); | ||
assert.strictEqual(toInteger(-0), 0); | ||
assert.strictEqual(toInteger(NaN), 0); | ||
assert.strictEqual(toInteger(Infinity), Infinity); | ||
assert.strictEqual(toInteger(-Infinity), -Infinity); | ||
|
||
assert.strictEqual(toInteger(0.1), 0); | ||
assert.strictEqual(toInteger(-0.1), 0); | ||
assert.strictEqual(toInteger(0.5), 0); | ||
assert.strictEqual(toInteger(-0.5), 0); | ||
assert.strictEqual(toInteger(0.9), 0); | ||
assert.strictEqual(toInteger(-0.9), 0); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const {toLength} = require('internal/util'); | ||
|
||
assert.strictEqual(toLength(+0), 0); | ||
assert.strictEqual(toLength(-0), 0); | ||
assert.strictEqual(toLength(NaN), 0); | ||
assert.strictEqual(toLength(Math.pow(2, 60)), 9007199254740991); | ||
assert.strictEqual(toLength(Infinity), 9007199254740991); | ||
assert.strictEqual(toLength(-Infinity), 0); | ||
|
||
assert.strictEqual(toLength(0.1), 0); | ||
assert.strictEqual(toLength(-0.1), 0); | ||
assert.strictEqual(toLength(0.5), 0); | ||
assert.strictEqual(toLength(-0.5), 0); | ||
assert.strictEqual(toLength(0.9), 0); | ||
assert.strictEqual(toLength(-0.9), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why the step
If len is +∞, return 253-1.
is in there when themin()
operation makes it seem unnecessary. I can't see any difference if that condition is left out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. In our implementation I omitted that, as
min
itself is sufficient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trevnorris I raised a PR tc39/ecma262#738. Let's see what tc39 people feel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trevnorris And it got merged :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thefourtheye excellent!