Skip to content

Commit

Permalink
ensure that the "length" property has the same maximum as regular Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Sep 27, 2012
1 parent f2e8cec commit ddf4916
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Expand Up @@ -6,6 +6,13 @@
var util = require('util') var util = require('util')
var debug = require('debug')('array-index') var debug = require('debug')('array-index')


/**
* JavaScript Array "length" is bound to an unsigned 32-bit int.
* See: http://stackoverflow.com/a/6155063/376773
*/

var MAX_LENGTH = Math.pow(2, 32)

/** /**
* Module exports. * Module exports.
*/ */
Expand Down Expand Up @@ -127,7 +134,12 @@ function setLength (v) {
*/ */


function ensureLength (_length) { function ensureLength (_length) {
var length = _length | 0 var length
if (_length > MAX_LENGTH) {
length = MAX_LENGTH
} else {
length = _length | 0
}
var cur = ArrayIndex.prototype.__length__ | 0 var cur = ArrayIndex.prototype.__length__ | 0
var num = length - cur var num = length - cur
if (num > 0) { if (num > 0) {
Expand Down

0 comments on commit ddf4916

Please sign in to comment.