Skip to content

TextEncoder.encodeInto from node:util does not throw TypeError #36373

Description

@davidebombelli

What version of Bun is running?

1.3.14+0d9b296af

What platform is your computer?

Linux 6.8.0-136-generic x86_64 x86_64

What steps can reproduce the bug?

Run the following snippet:

const assert = require('node:assert');
const util = require('util');

const selectedTextEncoder = util.TextEncoder;

(function () {

    try {
        const enc = new selectedTextEncoder();
        const dest = new Int8Array(10);

        assert.throws(() => enc.encodeInto('abc', dest), TypeError, " The \"dest\" argument must be an instance of Uint8Array. Received an instance of Int8Array");
    } 
    catch (e) {
        console.log(e);      
    }

})();

What is the expected behavior?

in Node.js, no exception or error is output. This is because the assert at line 12 is successful (encodeInto throws a TypeError).

What do you see instead?

in Bun, the following is output:

AssertionError [ERR_ASSERTION]: Missing expected exception (TypeError):  The "dest" argument must be an instance of Uint8Array. Received an instance of Int8Array
    at <anonymous> (/home/username/test.js:12:16)
    at <anonymous> (/home/username/test.js:15:22) {
  generatedMessage: false,
  actual: undefined,
  expected: [Function: TypeError],
  operator: 'throws',
  code: 'ERR_ASSERTION'
}

which means that encodeInto is not throwing, even though it should.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions