Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 326345b

Browse files
committed
Layout: remove dependency on assert module
Apparently some environments where this package is being used do not support an assert API. The only use of the API was a sanity check that unnamed fields were defined with a fixed length. A comment noted, and inspection confirms, that the Structure constructor explicitly rejects attempts to define such a field. So just drop the check. Signed-off-by: Peter A. Bigot <[email protected]>
1 parent 739d75a commit 326345b

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## [1.2.2] - 2021-07-05
4+
5+
* Improve [browser compatibility][pr#26] by eliminating a dependence on
6+
the Node assert module.
7+
38
## [1.2.1] - 2021-04-29
49

510
* Improve [browser compatibility][pr#24] by using `Buffer.isBuffer` instead of
@@ -136,6 +141,7 @@
136141

137142
* Initial release.
138143

144+
[1.2.2]: https://github.com/pabigot/buffer-layout/compare/v1.2.1...v1.2.2
139145
[1.2.1]: https://github.com/pabigot/buffer-layout/compare/v1.2.0...v1.2.1
140146
[1.2.0]: https://github.com/pabigot/buffer-layout/compare/v1.1.0...v1.2.0
141147
[1.1.0]: https://github.com/pabigot/buffer-layout/compare/v1.0.0...v1.1.0
@@ -200,6 +206,7 @@
200206
[issue#20]: https://github.com/pabigot/buffer-layout/issues/20
201207
[issue#21]: https://github.com/pabigot/buffer-layout/issues/21
202208
[pr#24]: https://github.com/pabigot/buffer-layout/pull/24
209+
[pr#26]: https://github.com/pabigot/buffer-layout/pull/26
203210
[ci:travis]: https://travis-ci.org/pabigot/buffer-layout
204211
[ci:coveralls]: https://coveralls.io/github/pabigot/buffer-layout
205212
[node:issue#3992]: https://github.com/nodejs/node/issues/3992

lib/Layout.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@
132132

133133
'use strict';
134134

135-
const assert = require('assert');
136-
137135
/**
138136
* Base class for layout objects.
139137
*
@@ -715,8 +713,6 @@ const V2E32 = Math.pow(2, 32);
715713
function divmodInt64(src) {
716714
const hi32 = Math.floor(src / V2E32);
717715
const lo32 = src - (hi32 * V2E32);
718-
// assert.equal(roundedInt64(hi32, lo32), src);
719-
// assert(0 <= lo32);
720716
return {hi32, lo32};
721717
}
722718
/* Reconstruct Number from quotient and non-negative remainder */
@@ -1261,12 +1257,7 @@ class Structure extends Layout {
12611257
for (const fd of this.fields) {
12621258
let span = fd.span;
12631259
lastWrote = (0 < span) ? span : 0;
1264-
if (undefined === fd.property) {
1265-
/* By construction the field must be fixed-length (because
1266-
* unnamed variable-length fields are disallowed when
1267-
* encoding). But check it anyway. */
1268-
assert(0 < span);
1269-
} else {
1260+
if (undefined !== fd.property) {
12701261
const fv = src[fd.property];
12711262
if (undefined !== fv) {
12721263
lastWrote = fd.encode(fv, b, offset);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "buffer-layout",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Translation between JavaScript values and Buffers",
55
"keywords": [
66
"Buffer",

test/LayoutTest.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ suite('Layout', function() {
672672
assert.throws(() => new lo.Structure('stuff'), TypeError);
673673
assert.throws(() => new lo.Structure(['stuff']), TypeError);
674674
// no unnamed variable-length fields
675-
assert.throws(() => new lo.Structure([lo.cstr()]), Error);
675+
assert.throws(() => new lo.Structure([lo.cstr()]),
676+
err => checkError(err, Error, /cannot contain unnamed variable-length layout/));
676677
});
677678
test('basics', function() {
678679
const st = new lo.Structure([lo.u8('u8'),

0 commit comments

Comments
 (0)