bkr icon indicating copy to clipboard operation
bkr copied to clipboard

Conversion to native ArrayBuffer and TypedArray types is inefficient

Open pfrazee opened this issue 5 years ago • 0 comments

As far as I can tell, the nodejs vm (or vm2) does not use the ArrayBuffer or TypedDataView objects that are native to the VM's realm, causing things like v instanceof ArrayBuffer to "incorrectly" fail when running scripts in the VM.

To solve that, I'm currently converting responses to the correct type. On top of that, some functions return node's Buffer type, which we also have to convert.

To do that, I'm injecting a frontmatter/preload into the VM scripts: https://github.com/beakerbrowser/bkr/blob/master/lib/run/preload.js

I'm opening this issue because my solution sucks and it'd be much nicer if this data types correctly converted over.

(FWIW, I'm generally not pleased with having to run rollup on modules to produce a bundle because it fucks up stack traces. We might be able to solve that with some kind of source-map manipulation on stacks.)

pfrazee avatar Jul 01 '20 04:07 pfrazee