Skip to content

Check for broken implementation of Uint8Array.prototype.toHex #1439

@brc-dd

Description

@brc-dd

Not sure if v8 staging features are covered, but when using deno run --v8-flags=--js-base-64 or node --js-base-64 or chrome://flags/#enable-javascript-harmony, the following code gives wrong output:

// foo.ts, run with:
// deno run --v8-flags=--js-base-64 foo.ts

import 'https://deno.land/x/corejs@v3.43.0/index.js'

console.log(new Uint8Array(8).fill(255).toHex()) // gives VfVfVfVfVfVfVfVf

Solution can be adding a check similar to:

var INCORRECT_BEHAVIOR_OR_DOESNT_EXISTS = !Uint8Array || !Uint8Array.prototype.setFromBase64 || !(function () {
var target = new Uint8Array([255, 255, 255, 255, 255]);
try {
target.setFromBase64('MjYyZg===');
} catch (error) {
return target[0] === 50 && target[1] === 54 && target[2] === 50 && target[3] === 255 && target[4] === 255;
}
})();

From denoland/deno#25051 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions