[jsc-dev] Protect against modifying contents of `ArrayBuffer` in `JavaScriptCore`

Karol Szafranski karolszafranski at gmail.com
Fri Oct 19 01:56:59 PDT 2018


`ArrayBuffer` is created in JavaScript engine, and reference is passed to the "native side":


    var myBuffer = new ArrayBuffer(32);
    protectBufferMemory(myBuffer);


Now I would like to hide the contents of the `ArrayBuffer` from the JavaScript engine. It would be best if `ArrayBuffer` could suddenly return 0 for `byteLength`, stay empty and nonresizable when looking at it with any `TypedArray`.

In the same time, I need to keep the contents of the `ArrayBuffer` in memory in the same place as it was. I do not want to copy those bytes.

Note: this is exactly how `ArrayBuffer` behaves in Chrome when you `postMessage` to a `Worker` with `ArrayBuffer` instance in the "transfer" array.

If there is no way of doing this, the following alternatives would also be acceptable:

1. Removing the `ArrayBuffer` instance from the JavaScript engine, so that all variables pointing to it will return `undefined` would also be acceptable. As long as data will not be removed from memory.

2. Keeping `ArrayBuffer` data visible inside JavaScript engine but disallow modification.

Thank you very much in advance.

Karol SzafraƄski



More information about the jsc-dev mailing list