Skip to content

fix: remove prototype mutations that cause TypeError in sandboxed environments#404

Merged
mariuz merged 3 commits into
masterfrom
copilot/fix-typeerror-assign-read-only-property
May 6, 2026
Merged

fix: remove prototype mutations that cause TypeError in sandboxed environments#404
mariuz merged 3 commits into
masterfrom
copilot/fix-typeerror-assign-read-only-property

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Summary

Fixes #403: TypeError: Cannot assign to read only property 'toString' of object '#<Object>'

In sandboxed environments that block prototype mutation (e.g. n8n 2.x Code nodes), require('node-firebird') throws a TypeError because two pieces of code try to mutate prototypes during initialization.

Root Causes

  1. long npm package — The long dependency mutates Long.prototype.toString (and other Long.prototype methods) during module initialization. In sandboxed environments where prototype mutation is blocked, this fails with TypeError: Cannot assign to read only property 'toString' of object '#<Object>'.

  2. String.prototype.padLeft polyfill in lib/index.js — Similarly mutates String.prototype, which fails in the same sandboxed environments.

Changes

lib/wire/serialize.js

  • Removed require('long')
  • addInt64: replaced Long.fromNumber(value) + writeInt32BE with Buffer.writeBigInt64BE(BigInt(Math.trunc(value))) — consistent with the existing addInt128 approach
  • readInt64: replaced new Long(low, high).toNumber() with Buffer.readBigInt64BE() — consistent with the existing readInt128 approach
  • Added comments documenting the pre-existing precision limitation for values outside Number.MAX_SAFE_INTEGER (same behaviour as the previous Long implementation)

lib/index.js

  • Removed the String.prototype.padLeft polyfill block

lib/utils.js

  • Replaced .padLeft(n, c) calls with the native .padStart(n, c) (ES2017, already used elsewhere in the codebase)

package.json / package-lock.json

  • Removed long from dependencies

Testing

All tests that passed before continue to pass. Test failures are unchanged (all pre-existing Connect error failures due to no Firebird server in CI).

@mariuz mariuz marked this pull request as ready for review May 6, 2026 22:36
@mariuz mariuz merged commit 8ea4e1d into master May 6, 2026
24 of 27 checks passed
@mariuz mariuz deleted the copilot/fix-typeerror-assign-read-only-property branch May 6, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot assign to read only property 'toString' of object '#<Long>'

2 participants