Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Add value range assertions to generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
pgriess committed Aug 21, 2010
1 parent 04b869c commit 430c7d1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/strtok.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var UINT8 = {
},
put : function(s, v) {
assert.equal(typeof v, 'number');
assert.ok(v >= 0 && v <= 255);

s.write(BYTES[v & 0xff], 'binary');
}
};
Expand All @@ -41,6 +43,8 @@ var UINT16_LE = {
},
put : function(s, v) {
assert.equal(typeof v, 'number');
assert.ok(v >= 0 && v <= 65535);

s.write(BYTES[v & 0xff] + BYTES[(v >>> 8) & 0xff], 'binary');
}
};
Expand All @@ -53,6 +57,8 @@ var UINT16_BE = {
},
put : function(s, v) {
assert.equal(typeof v, 'number');
assert.ok(v >= 0 && v <= 65535);

s.write(BYTES[(v >>> 8) & 0xff] + BYTES[v & 0xff], 'binary');
}
};
Expand All @@ -66,6 +72,8 @@ var UINT32_LE = {
},
put : function(s, v) {
assert.equal(typeof v, 'number');
assert.ok(v >= 0 && v <= 4294967295);

s.write(
BYTES[v & 0xff] + BYTES[(v >>> 8) & 0xff] +
BYTES[(v >>> 16) & 0xff] + BYTES[(v >>> 24) & 0xff],
Expand All @@ -83,6 +91,8 @@ var UINT32_BE = {
},
put : function(s, v) {
assert.equal(typeof v, 'number');
assert.ok(v >= 0 && v <= 4294967295);

s.write(
BYTES[(v >>> 24) & 0xff] + BYTES[(v >>> 16) & 0xff] +
BYTES[(v >>> 8) & 0xff] + BYTES[v & 0xff],
Expand Down

0 comments on commit 430c7d1

Please sign in to comment.