Skip to content

Commit 690821c

Browse files
committed
safer: wrap process.binding call in try-catch
This way, it won't fail in environments where process.binding is unsupported. That was used to determine kStringMaxLength on older Node.js versions. In that case, fall back to undefined - we can't determine kStringMaxLength.
1 parent 57123bc commit 690821c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

safer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ if (!Safer.alloc) {
5757
}
5858

5959
if (!safer.kStringMaxLength) {
60-
safer.kStringMaxLength = process.binding('buffer').kStringMaxLength
60+
try {
61+
safer.kStringMaxLength = process.binding('buffer').kStringMaxLength
62+
} catch (e) {
63+
// we can't determine kStringMaxLength in environments where process.binding
64+
// is unsupported
65+
safer.kStringMaxLength = undefined
66+
}
6167
}
6268

6369
if (!safer.constants) {

0 commit comments

Comments
 (0)